Skip to content

Commit 103af8c

Browse files
committed
Newer macOS deprecates -force_flat_namespace for -flat_namespace
The linker warns about -force-flat_namespace and uses -flat_namespace instead. Check for -flat_namespace if -force-flat_namespace is not found.
1 parent 46831d6 commit 103af8c

File tree

2 files changed

+93
-5
lines changed

2 files changed

+93
-5
lines changed

configure

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18747,8 +18747,9 @@ fi
1874718747

1874818748
done
1874918749

18750-
# We need to force a flat namespace to make libc
18751-
# symbol hooking work like it does on ELF.
18750+
# We need to force a flat namespace on macOS to make libc
18751+
# symbol hooking work like it does on ELF. Newer versions of
18752+
# macOS treat -force_flat_namespace as -flat_namespace.
1875218753
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the linker accepts -Wl,-force_flat_namespace" >&5
1875318754
printf %s "checking whether the linker accepts -Wl,-force_flat_namespace... " >&6; }
1875418755
if test ${ax_cv_check_ldflags___Wl__force_flat_namespace+y}
@@ -18786,6 +18787,7 @@ printf "%s\n" "$ax_cv_check_ldflags___Wl__force_flat_namespace" >&6; }
1878618787
if test x"$ax_cv_check_ldflags___Wl__force_flat_namespace" = xyes
1878718788
then :
1878818789

18790+
1878918791
if test ${SUDO_LDFLAGS+y}
1879018792
then :
1879118793

@@ -18819,11 +18821,90 @@ else case e in #(
1881918821
esac
1882018822
fi
1882118823

18824+
18825+
else case e in #(
18826+
e)
18827+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the linker accepts -Wl,-flat_namespace" >&5
18828+
printf %s "checking whether the linker accepts -Wl,-flat_namespace... " >&6; }
18829+
if test ${ax_cv_check_ldflags___Wl__flat_namespace+y}
18830+
then :
18831+
printf %s "(cached) " >&6
18832+
else case e in #(
18833+
e)
18834+
ax_check_save_flags=$LDFLAGS
18835+
LDFLAGS="$LDFLAGS -Wl,-flat_namespace"
18836+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
18837+
/* end confdefs.h. */
18838+
18839+
int
18840+
main (void)
18841+
{
18842+
18843+
;
18844+
return 0;
18845+
}
18846+
_ACEOF
18847+
if ac_fn_c_try_link "$LINENO"
18848+
then :
18849+
ax_cv_check_ldflags___Wl__flat_namespace=yes
18850+
else case e in #(
18851+
e) ax_cv_check_ldflags___Wl__flat_namespace=no ;;
18852+
esac
18853+
fi
18854+
rm -f core conftest.err conftest.$ac_objext conftest.beam \
18855+
conftest$ac_exeext conftest.$ac_ext
18856+
LDFLAGS=$ax_check_save_flags ;;
18857+
esac
18858+
fi
18859+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_ldflags___Wl__flat_namespace" >&5
18860+
printf "%s\n" "$ax_cv_check_ldflags___Wl__flat_namespace" >&6; }
18861+
if test x"$ax_cv_check_ldflags___Wl__flat_namespace" = xyes
18862+
then :
18863+
18864+
18865+
if test ${SUDO_LDFLAGS+y}
18866+
then :
18867+
18868+
case " $SUDO_LDFLAGS " in #(
18869+
*" -Wl,-flat_namespace "*) :
18870+
{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : SUDO_LDFLAGS already contains -Wl,-flat_namespace"; } >&5
18871+
(: SUDO_LDFLAGS already contains -Wl,-flat_namespace) 2>&5
18872+
ac_status=$?
18873+
printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
18874+
test $ac_status = 0; } ;; #(
18875+
*) :
18876+
18877+
as_fn_append SUDO_LDFLAGS " -Wl,-flat_namespace"
18878+
{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : SUDO_LDFLAGS=\"\$SUDO_LDFLAGS\""; } >&5
18879+
(: SUDO_LDFLAGS="$SUDO_LDFLAGS") 2>&5
18880+
ac_status=$?
18881+
printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
18882+
test $ac_status = 0; }
18883+
;;
18884+
esac
18885+
18886+
else case e in #(
18887+
e)
18888+
SUDO_LDFLAGS=-Wl,-flat_namespace
18889+
{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : SUDO_LDFLAGS=\"\$SUDO_LDFLAGS\""; } >&5
18890+
(: SUDO_LDFLAGS="$SUDO_LDFLAGS") 2>&5
18891+
ac_status=$?
18892+
printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
18893+
test $ac_status = 0; }
18894+
;;
18895+
esac
18896+
fi
18897+
18898+
1882218899
else case e in #(
1882318900
e) : ;;
1882418901
esac
1882518902
fi
1882618903

18904+
;;
18905+
esac
18906+
fi
18907+
1882718908

1882818909
# Examples go in share/examples/sudo
1882918910
if test X"$with_exampledir" = X""

configure.ac

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,9 +2234,16 @@ case "$host" in
22342234
# We cannot directly access environ from a shared object
22352235
AC_CHECK_HEADERS([crt_externs.h], [AC_CHECK_FUNCS([_NSGetEnviron])])
22362236

2237-
# We need to force a flat namespace to make libc
2238-
# symbol hooking work like it does on ELF.
2239-
AX_CHECK_LINK_FLAG([-Wl,-force_flat_namespace], [AX_APPEND_FLAG([-Wl,-force_flat_namespace], [SUDO_LDFLAGS])])
2237+
# We need to force a flat namespace on macOS to make libc
2238+
# symbol hooking work like it does on ELF. Newer versions of
2239+
# macOS treat -force_flat_namespace as -flat_namespace.
2240+
AX_CHECK_LINK_FLAG([-Wl,-force_flat_namespace], [
2241+
AX_APPEND_FLAG([-Wl,-force_flat_namespace], [SUDO_LDFLAGS])
2242+
], [
2243+
AX_CHECK_LINK_FLAG([-Wl,-flat_namespace], [
2244+
AX_APPEND_FLAG([-Wl,-flat_namespace], [SUDO_LDFLAGS])
2245+
])
2246+
])
22402247

22412248
# Examples go in share/examples/sudo
22422249
AS_IF([test X"$with_exampledir" = X""], [

0 commit comments

Comments
 (0)