Skip to content

Commit

Permalink
Newer macOS deprecates -force_flat_namespace for -flat_namespace
Browse files Browse the repository at this point in the history
The linker warns about -force-flat_namespace and uses -flat_namespace
instead.  Check for -flat_namespace if -force-flat_namespace is not
found.
  • Loading branch information
millert committed Jan 4, 2025
1 parent 46831d6 commit 103af8c
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 5 deletions.
85 changes: 83 additions & 2 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -18747,8 +18747,9 @@ fi

done

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


if test ${SUDO_LDFLAGS+y}
then :

Expand Down Expand Up @@ -18819,11 +18821,90 @@ else case e in #(
esac
fi


else case e in #(
e)
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the linker accepts -Wl,-flat_namespace" >&5
printf %s "checking whether the linker accepts -Wl,-flat_namespace... " >&6; }
if test ${ax_cv_check_ldflags___Wl__flat_namespace+y}
then :
printf %s "(cached) " >&6
else case e in #(
e)
ax_check_save_flags=$LDFLAGS
LDFLAGS="$LDFLAGS -Wl,-flat_namespace"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */

int
main (void)
{

;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
then :
ax_cv_check_ldflags___Wl__flat_namespace=yes
else case e in #(
e) ax_cv_check_ldflags___Wl__flat_namespace=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
conftest$ac_exeext conftest.$ac_ext
LDFLAGS=$ax_check_save_flags ;;
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_ldflags___Wl__flat_namespace" >&5
printf "%s\n" "$ax_cv_check_ldflags___Wl__flat_namespace" >&6; }
if test x"$ax_cv_check_ldflags___Wl__flat_namespace" = xyes
then :


if test ${SUDO_LDFLAGS+y}
then :

case " $SUDO_LDFLAGS " in #(
*" -Wl,-flat_namespace "*) :
{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : SUDO_LDFLAGS already contains -Wl,-flat_namespace"; } >&5
(: SUDO_LDFLAGS already contains -Wl,-flat_namespace) 2>&5
ac_status=$?
printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; } ;; #(
*) :

as_fn_append SUDO_LDFLAGS " -Wl,-flat_namespace"
{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : SUDO_LDFLAGS=\"\$SUDO_LDFLAGS\""; } >&5
(: SUDO_LDFLAGS="$SUDO_LDFLAGS") 2>&5
ac_status=$?
printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }
;;
esac

else case e in #(
e)
SUDO_LDFLAGS=-Wl,-flat_namespace
{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : SUDO_LDFLAGS=\"\$SUDO_LDFLAGS\""; } >&5
(: SUDO_LDFLAGS="$SUDO_LDFLAGS") 2>&5
ac_status=$?
printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }
;;
esac
fi


else case e in #(
e) : ;;
esac
fi

;;
esac
fi


# Examples go in share/examples/sudo
if test X"$with_exampledir" = X""
Expand Down
13 changes: 10 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2234,9 +2234,16 @@ case "$host" in
# We cannot directly access environ from a shared object
AC_CHECK_HEADERS([crt_externs.h], [AC_CHECK_FUNCS([_NSGetEnviron])])

# We need to force a flat namespace to make libc
# symbol hooking work like it does on ELF.
AX_CHECK_LINK_FLAG([-Wl,-force_flat_namespace], [AX_APPEND_FLAG([-Wl,-force_flat_namespace], [SUDO_LDFLAGS])])
# We need to force a flat namespace on macOS to make libc
# symbol hooking work like it does on ELF. Newer versions of
# macOS treat -force_flat_namespace as -flat_namespace.
AX_CHECK_LINK_FLAG([-Wl,-force_flat_namespace], [
AX_APPEND_FLAG([-Wl,-force_flat_namespace], [SUDO_LDFLAGS])
], [
AX_CHECK_LINK_FLAG([-Wl,-flat_namespace], [
AX_APPEND_FLAG([-Wl,-flat_namespace], [SUDO_LDFLAGS])
])
])

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

0 comments on commit 103af8c

Please sign in to comment.