2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-22 09:57:41 +00:00

Try to link a simple shared object with -Wl,--no-undefined.

This only works for gcc-style compilers, which should not be a
problem.  The source uses environ (FreeBSD) and errno (OpenBSD).
This commit is contained in:
Todd C. Miller 2023-01-20 12:30:33 -07:00
parent 0010c98613
commit f65a51afdf
3 changed files with 56 additions and 56 deletions

59
configure vendored
View File

@ -19828,54 +19828,51 @@ fi
# but is incompatible with the sanitizers/fuzzers. # but is incompatible with the sanitizers/fuzzers.
# We must set this *before* the library tests. # We must set this *before* the library tests.
# #
if test X"${enable_sanitizer}{enable_fuzzer}" = X"nono"; then if test -n "$GCC" -a X"${enable_sanitizer}${enable_fuzzer}" = X"nono"; then
case "$host_os" in # On FreeBSD and Dragonfly, environ is filled in by the dynamic loader
freebsd*|dragonfly*|openbsd*) # so -Wl,--no-undefined causes a link error when environ is used.
# On FreeBSD and Dragonfly, environ is filled in by the
# dynamic loader so we cannot use -Wl,--no-undefined.
# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=263265 # https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=263265
# OpenBSD shared libraries don't link explicitly with libc # We use errno because OpenBSD shared libraries don't explicitly
# which results in undefined references errors. # link with libc, which can result in undefined reference errors.
# Ideally we would link a shared object with -Wl,--no-undefined { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking the linker accepts -Wl,--no-undefined" >&5
# and see if it works but this is not easy in a libtool world. printf %s "checking the linker accepts -Wl,--no-undefined... " >&6; }
;; if test ${sudo_cv_var_ld___no_undefined+y}
*)
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the linker accepts -Wl,--no-undefined" >&5
printf %s "checking whether the linker accepts -Wl,--no-undefined... " >&6; }
if test ${ax_cv_check_ldflags___Wl___no_undefined+y}
then : then :
printf %s "(cached) " >&6 printf %s "(cached) " >&6
else case e in #( else case e in #(
e) e)
ax_check_save_flags=$LDFLAGS sudo_cv_var_ld___no_undefined=no
LDFLAGS="$LDFLAGS -Wl,--no-undefined" _CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $lt_prog_compiler_pic"
_LDFLAGS="$LDFLAGS"
LDFLAGS="$LDFLAGS $lt_prog_compiler_pic -shared -Wl,--no-undefined"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */ /* end confdefs.h. */
#include <errno.h>
extern char **environ;
int int
main (void) main (void)
{ {
int ret = ((long)environ & 0xff) + errno; return ret;
; ;
return 0; return 0;
} }
_ACEOF _ACEOF
if ac_fn_c_try_link "$LINENO" if ac_fn_c_try_link "$LINENO"
then : then :
ax_cv_check_ldflags___Wl___no_undefined=yes sudo_cv_var_ld___no_undefined=yes
else case e in #(
e) ax_cv_check_ldflags___Wl___no_undefined=no ;;
esac
fi fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \ rm -f core conftest.err conftest.$ac_objext conftest.beam \
conftest$ac_exeext conftest.$ac_ext conftest$ac_exeext conftest.$ac_ext
LDFLAGS=$ax_check_save_flags ;; CFLAGS="$_CFLAGS"
LDFLAGS="$_LDFLAGS"
;;
esac esac
fi fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_ldflags___Wl___no_undefined" >&5 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $sudo_cv_var_ld___no_undefined" >&5
printf "%s\n" "$ax_cv_check_ldflags___Wl___no_undefined" >&6; } printf "%s\n" "$sudo_cv_var_ld___no_undefined" >&6; }
if test x"$ax_cv_check_ldflags___Wl___no_undefined" = xyes if test "$sudo_cv_var_ld___no_undefined" = "yes"; then
then :
if test ${LDFLAGS+y} if test ${LDFLAGS+y}
then : then :
@ -19910,13 +19907,7 @@ else case e in #(
esac esac
fi fi
else case e in #(
e) : ;;
esac
fi fi
;;
esac
fi fi
# #
@ -32523,7 +32514,7 @@ else case e in #(
_CFLAGS="$CFLAGS" _CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $lt_prog_compiler_pic" CFLAGS="$CFLAGS $lt_prog_compiler_pic"
_LDFLAGS="$LDFLAGS" _LDFLAGS="$LDFLAGS"
LDFLAGS="$LDFLAGS -fpic -shared -Wl,--version-script,./conftest.map" LDFLAGS="$LDFLAGS $lt_prog_compiler_pic -shared -Wl,--version-script,./conftest.map"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */ /* end confdefs.h. */
int foo; int foo;

View File

@ -2455,21 +2455,30 @@ AC_SYS_YEAR2038
# but is incompatible with the sanitizers/fuzzers. # but is incompatible with the sanitizers/fuzzers.
# We must set this *before* the library tests. # We must set this *before* the library tests.
# #
if test X"${enable_sanitizer}{enable_fuzzer}" = X"nono"; then if test -n "$GCC" -a X"${enable_sanitizer}${enable_fuzzer}" = X"nono"; then
case "$host_os" in # On FreeBSD and Dragonfly, environ is filled in by the dynamic loader
freebsd*|dragonfly*|openbsd*) # so -Wl,--no-undefined causes a link error when environ is used.
# On FreeBSD and Dragonfly, environ is filled in by the
# dynamic loader so we cannot use -Wl,--no-undefined.
# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=263265 # https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=263265
# OpenBSD shared libraries don't link explicitly with libc # We use errno because OpenBSD shared libraries don't explicitly
# which results in undefined references errors. # link with libc, which can result in undefined reference errors.
# Ideally we would link a shared object with -Wl,--no-undefined AC_CACHE_CHECK([the linker accepts -Wl,--no-undefined],
# and see if it works but this is not easy in a libtool world. [sudo_cv_var_ld___no_undefined],
;; [
*) sudo_cv_var_ld___no_undefined=no
AX_CHECK_LINK_FLAG([-Wl,--no-undefined], [AX_APPEND_FLAG([-Wl,--no-undefined], [LDFLAGS])]) _CFLAGS="$CFLAGS"
;; CFLAGS="$CFLAGS $lt_prog_compiler_pic"
esac _LDFLAGS="$LDFLAGS"
LDFLAGS="$LDFLAGS $lt_prog_compiler_pic -shared -Wl,--no-undefined"
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <errno.h>
extern char **environ;]], [[int ret = ((long)environ & 0xff) + errno; return ret;]])],
[sudo_cv_var_ld___no_undefined=yes])
CFLAGS="$_CFLAGS"
LDFLAGS="$_LDFLAGS"
]
)
if test "$sudo_cv_var_ld___no_undefined" = "yes"; then
AX_APPEND_FLAG([-Wl,--no-undefined], [LDFLAGS])
fi
fi fi
# #
@ -2482,12 +2491,12 @@ case "$host_os" in
hpux*) hpux*)
AC_CACHE_CHECK([whether sys/socket.h needs _XOPEN_SOURCE_EXTENDED for MSG_WAITALL], [sudo_cv_xopen_source_extended], AC_CACHE_CHECK([whether sys/socket.h needs _XOPEN_SOURCE_EXTENDED for MSG_WAITALL], [sudo_cv_xopen_source_extended],
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
# include <sys/socket.h>], [int a = MSG_WAITALL; return a;])], [# include <sys/socket.h>]], [[int a = MSG_WAITALL; return a;]])],
[sudo_cv_xopen_source_extended=no], [ [sudo_cv_xopen_source_extended=no], [
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#define _XOPEN_SOURCE_EXTENDED AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#define _XOPEN_SOURCE_EXTENDED
AC_INCLUDES_DEFAULT AC_INCLUDES_DEFAULT
# include <sys/socket.h> [# include <sys/socket.h>
# include <net/if.h>], [int a = MSG_WAITALL; return a;])], # include <net/if.h>]], [[int a = MSG_WAITALL; return a;]])],
[sudo_cv_xopen_source_extended=yes], [sudo_cv_xopen_source_extended=yes],
[sudo_cv_xopen_source_extended=error]) [sudo_cv_xopen_source_extended=error])
])]) ])])

View File

@ -71,7 +71,7 @@ AC_DEFUN([SUDO_SYMBOL_VISIBILITY], [
_CFLAGS="$CFLAGS" _CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $lt_prog_compiler_pic" CFLAGS="$CFLAGS $lt_prog_compiler_pic"
_LDFLAGS="$LDFLAGS" _LDFLAGS="$LDFLAGS"
LDFLAGS="$LDFLAGS -fpic -shared -Wl,--version-script,./conftest.map" LDFLAGS="$LDFLAGS $lt_prog_compiler_pic -shared -Wl,--version-script,./conftest.map"
AC_LINK_IFELSE([AC_LANG_PROGRAM([[int foo;]], [[]])], AC_LINK_IFELSE([AC_LANG_PROGRAM([[int foo;]], [[]])],
[sudo_cv_var_gnu_ld_anon_map=yes]) [sudo_cv_var_gnu_ld_anon_map=yes])
CFLAGS="$_CFLAGS" CFLAGS="$_CFLAGS"