Skip to content

Commit 07d831a

Browse files
committed
Darwin: Support embedded runpaths.
1. Driver : Provide a spec to insert rpaths for compiler lib dirs. This provides a spec to insert "-rpath DDD" for each DDD corresponding to a compiler startfile directory. This allows a target to use @rpath as the install path for libraries, and have the compiler provide the necessary rpath to handle this. gcc/ChangeLog: * gcc.c (RUNPATH_OPTION): New. (do_spec_1): Provide '%P' as a spec to insert rpaths for each compiler startfile path. 2. Darwin : Handle rpaths given on the command line. We want to produce a situation where a default rpath can be added to each executable (or dylib), but that can be overridden by any specific rpath provided by the user. gcc/ChangeLog: * config.gcc: Include rpath.opt * config/darwin-driver.c (darwin_driver_init): Detect cases where the user has added rpaths via a -Wl or -Xlinker command and suppress default rpaths in that case. * config/darwin.h (DRIVER_SELF_SPECS): Handle -rpath. (DARWIN_RPATH_SPEC): New. * config/darwin.opt: Add nodefaultrpath option. 3. Darwin : Allow for configuring Darwin to use embedded runpath. Recent Darwin versions place contraints on the use of run paths specified in environment variables. This breaks some assumptions in the GCC build. This change allows the user to configure a Darwin build to use '@rpath/libraryname.dylib' in library names and then to add an embedded runpath to executables (and libraries with dependents). The embedded runpath is added by default unless the user adds '-nodefaultrpaths' to the link line. For an installed compiler, it means that any executable built with that compiler will reference the runtimes installed with the compiler (equivalent to hard-coding the library path into the name of the library). During build-time configurations any "-B" entries will be added to the runpath thus the newly-built libraries will be found by exes. Since the install name is set in libtool, that decision needs to be available here (but might also cause dependent ones in Makefiles, so we need to export a conditional). This facility is not available for Darwin 8 or earlier, however the existing environment variable runpath does work there. We default this on for systems where the external DYLD_LIBRARY_PATH does not work and off for Darwin 8 or earlier. For systems that can use either method, if the value is unset, we use the default (which is currently DYLD_LIBRARY_PATH). ChangeLog: * configure: Regenerate. * configure.ac: Do not add default runpaths to GCC exes when we are building -static-libstdc++/-static-libgcc (the default). * libtool.m4: Add 'enable-darwin-at-runpath'. Act on the enable flag to alter Darwin libraries to use @rpath names. gcc/ChangeLog: * aclocal.m4: Regenerate. * configure: Regenerate. libatomic/ChangeLog: * Makefile.am: Handle Darwin rpaths. * Makefile.in: Regenerate. * configure: Regenerate. * testsuite/Makefile.in: Regenerate. libcc1/ChangeLog: * Makefile.am: Handle Darwin rpaths. * Makefile.in: Regenerate. * configure: Regenerate. libffi/ChangeLog: * Makefile.am: Handle Darwin rpaths. * Makefile.in: Regenerate. * configure: Regenerate. libgcc/ChangeLog: * config/t-slibgcc-darwin: Generate libgcc_s with an @rpath name. libgfortran/ChangeLog: * Makefile.am: Handle Darwin rpaths. * Makefile.in: Regenerate. * configure: Regenerate. * configure.ac: Handle Darwin rpaths libgomp/ChangeLog: * Makefile.am: Handle Darwin rpaths. * Makefile.in: Regenerate. * configure: Regenerate. libitm/ChangeLog: * Makefile.am: Handle Darwin rpaths. * Makefile.in: Regenerate. * configure: Regenerate. libobjc/ChangeLog: * configure: Regenerate. * configure.ac: Handle Darwin rpaths. liboffloadmic/ChangeLog: * configure: Regenerate. * plugin/Makefile.in: Regenerate. * plugin/aclocal.m4: Regenerate. * plugin/configure: Regenerate. libphobos/ChangeLog: * configure: Regenerate. * libdruntime/Makefile.am: Handle Darwin rpaths. * libdruntime/Makefile.in: Regenerate. * src/Makefile.am: Handle Darwin rpaths. * src/Makefile.in: Regenerate. libquadmath/ChangeLog: * Makefile.am: Handle Darwin rpaths. * Makefile.in: Regenerate. * configure: Regenerate. * configure.ac: Handle Darwin rpaths. libsanitizer/ChangeLog: * asan/Makefile.am: Handle Darwin rpaths. * asan/Makefile.in: Regenerate. * configure: Regenerate. * hwasan/Makefile.am: Handle Darwin rpaths. * hwasan/Makefile.in: Regenerate. * lsan/Makefile.am: Handle Darwin rpaths. * lsan/Makefile.in: Regenerate. * tsan/Makefile.am: Handle Darwin rpaths. * tsan/Makefile.in: Regenerate. * ubsan/Makefile.am: Handle Darwin rpaths. * ubsan/Makefile.in: Regenerate. libssp/ChangeLog: * Makefile.am: Handle Darwin rpaths. * Makefile.in: Regenerate. * configure: Regenerate. libstdc++-v3/ChangeLog: * configure: Regenerate. * src/Makefile.am: Handle Darwin rpaths. * src/Makefile.in: Regenerate. Ada changes: add paths relative to @loader-path JIT changes: This patch expects DARWIN_RPATH to be computed and available; which means that we will use @rpath or ${libdir} as the name prefix depending on the system version and the setting of --enable-darwin-at-rpath. For branches that do not have this available, the value should be set to ${libdir}. 4. WIP for @path testsuite non-installed. 5. Embed real paths, not relative ones. We embed a runpath for every path in which libraries might be found. This change ensures that we embed the actual real path and not a relative one from the compiler's version-specific directory. e.g. /opt/distro/gcc-11-3Dr0/lib instead of: /opt/distro/gcc-11-3Dr0/lib/gcc/x86_64-apple-darwin19/11.3.0/../../.. This ensures that if we install, for example, 11.4.0 (and delete the 11.3.0 installation) exes built by 11.3 would continue to function (providing, of course that 11.4 does not bump any SO names). 6. Update enable-darwin-at-rpath to support macOS 13+. An earlier patch added 'enable-darwin-at-runpath' and enabled it by default on macOS versions from 10.11 through 12 inclusive, but was not future-proof. macOS 13 is expected for public release later this year. This change extends support through macOS 19, which is expected to be good for 7 more years under the current OS versioning scheme. ChangeLog: * libtool.m4: Future-proof default setting of 'enable-darwin-at-runpath'. gcc/ChangeLog: * configure: Regenerate. libatomic/ChangeLog: * configure: Regenerate. libcc1/ChangeLog: * configure: Regenerate. libffi/ChangeLog: * configure: Regenerate. libgfortran/ChangeLog: * configure: Regenerate. libgomp/ChangeLog: * configure: Regenerate. libitm/ChangeLog: * configure: Regenerate. libobjc/ChangeLog: * configure: Regenerate. liboffloadmic/ChangeLog: * configure: Regenerate. libphobos/ChangeLog: * configure: Regenerate. libquadmath/ChangeLog: * configure: Regenerate. libsanitizer/ChangeLog: * configure: Regenerate. libssp/ChangeLog: * configure: Regenerate. libstdc++-v3/ChangeLog: * configure: Regenerate. libvtv/ChangeLog: * configure: Regenerate. lto-plugin/ChangeLog: * configure: Regenerate. zlib/ChangeLog: * configure: Regenerate. Signed-off-by: Mark Mentovai <[email protected]> 7. Fix up (i.e. remove) build-time rpaths in libraries. We have code in the library builds to avoid embedding the runpaths for the build directories and also to add @loader_path so that libraries can find their dependent libs. There was a mistake in specifying params that avoid installing the runpaths for the build (essentially, libtool silently ignored them - we have to prepend '-Wc' to get them passed to the compiler driver). 8. Add loader path to libgcc_s.1.dylib
1 parent 510d6ec commit 07d831a

File tree

108 files changed

+2991
-375
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+2991
-375
lines changed

configure

+14
Original file line numberDiff line numberDiff line change
@@ -8414,6 +8414,20 @@ else
84148414
fi
84158415
fi
84168416

8417+
case $target in
8418+
*-darwin2* | *-darwin1[56789]*)
8419+
# For these versions, we default to using embedded rpaths.
8420+
if test "x$enable_darwin_at_rpath" != "xno"; then
8421+
poststage1_ldflags="$poststage1_ldflags -nodefaultrpaths"
8422+
fi
8423+
;;
8424+
*-darwin*)
8425+
# For these versions, we only use embedded rpaths on demand.
8426+
if test "x$enable_darwin_at_rpath" = "xyes"; then
8427+
poststage1_ldflags="$poststage1_ldflags -nodefaultrpaths"
8428+
fi
8429+
;;
8430+
esac
84178431

84188432

84198433
# GCC GRAPHITE dependency isl.

configure.ac

+14
Original file line numberDiff line numberDiff line change
@@ -1827,6 +1827,20 @@ AC_ARG_WITH(boot-ldflags,
18271827
if test "$poststage1_libs" = ""; then
18281828
poststage1_ldflags="-static-libstdc++ -static-libgcc"
18291829
fi])
1830+
case $target in
1831+
*-darwin2* | *-darwin1[[56789]]*)
1832+
# For these versions, we default to using embedded rpaths.
1833+
if test "x$enable_darwin_at_rpath" != "xno"; then
1834+
poststage1_ldflags="$poststage1_ldflags -nodefaultrpaths"
1835+
fi
1836+
;;
1837+
*-darwin*)
1838+
# For these versions, we only use embedded rpaths on demand.
1839+
if test "x$enable_darwin_at_rpath" = "xyes"; then
1840+
poststage1_ldflags="$poststage1_ldflags -nodefaultrpaths"
1841+
fi
1842+
;;
1843+
esac
18301844
AC_SUBST(poststage1_ldflags)
18311845

18321846
# GCC GRAPHITE dependency isl.

fixincludes/configure

+1-1
Original file line numberDiff line numberDiff line change
@@ -2644,7 +2644,7 @@ ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var.
26442644
26452645
# _LT_DARWIN_LINKER_FEATURES
26462646
# --------------------------
2647-
# Checks for linker and compiler features on darwin
2647+
# Checks for linker and compiler features on Darwin / macOS / iOS
26482648
26492649
26502650
# _LT_SYS_MODULE_PATH_AIX

gcc/Makefile.in

+11-3
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,8 @@ LANG_MAKEFRAGS = @all_lang_makefrags@
11581158
# Used by gcc/jit/Make-lang.in
11591159
LD_VERSION_SCRIPT_OPTION = @ld_version_script_option@
11601160
LD_SONAME_OPTION = @ld_soname_option@
1161+
@ENABLE_DARWIN_AT_RPATH_TRUE@DARWIN_RPATH = @rpath
1162+
@ENABLE_DARWIN_AT_RPATH_FALSE@DARWIN_RPATH = ${libdir}
11611163

11621164
# Flags to pass to recursive makes.
11631165
# CC is set by configure.
@@ -1947,9 +1949,12 @@ cs-tconfig.h: Makefile
19471949
$(SHELL) $(srcdir)/mkconfig.sh tconfig.h
19481950

19491951
cs-tm.h: Makefile
1950-
TARGET_CPU_DEFAULT="$(target_cpu_default)" \
1951-
HEADERS="$(tm_include_list)" DEFINES="$(tm_defines)" \
1952-
$(SHELL) $(srcdir)/mkconfig.sh tm.h
1952+
@ENABLE_DARWIN_AT_RPATH_FALSE@ TARGET_CPU_DEFAULT="$(target_cpu_default)" \
1953+
@ENABLE_DARWIN_AT_RPATH_FALSE@ HEADERS="$(tm_include_list)" DEFINES="$(tm_defines)" \
1954+
@ENABLE_DARWIN_AT_RPATH_FALSE@ $(SHELL) $(srcdir)/mkconfig.sh tm.h
1955+
@ENABLE_DARWIN_AT_RPATH_TRUE@ TARGET_CPU_DEFAULT="$(target_cpu_default)" \
1956+
@ENABLE_DARWIN_AT_RPATH_TRUE@ HEADERS="$(tm_include_list)" DEFINES="$(tm_defines) DARWIN_AT_RPATH=1" \
1957+
@ENABLE_DARWIN_AT_RPATH_TRUE@ $(SHELL) $(srcdir)/mkconfig.sh tm.h
19531958

19541959
cs-tm_p.h: Makefile
19551960
TARGET_CPU_DEFAULT="" \
@@ -4121,6 +4126,9 @@ site.exp: ./config.status Makefile
41214126
echo "set COMPAT_OPTIONS \"$(COMPAT_OPTIONS)\"" >> ./site.tmp; \
41224127
else true; \
41234128
fi
4129+
@if test "x@enable_darwin_at_rpath@" = "xyes" ; then \
4130+
echo "set ENABLE_DARWIN_AT_RPATH 1" >> ./site.tmp; \
4131+
fi
41244132
@echo "## All variables above are generated by configure. Do Not Edit ##" >> ./site.tmp
41254133
@cat ./site.tmp > site.exp
41264134
@cat site.bak | sed \

gcc/aclocal.m4

+50
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,56 @@
1212
# PARTICULAR PURPOSE.
1313

1414
m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])])
15+
# AM_CONDITIONAL -*- Autoconf -*-
16+
17+
# Copyright (C) 1997-2017 Free Software Foundation, Inc.
18+
#
19+
# This file is free software; the Free Software Foundation
20+
# gives unlimited permission to copy and/or distribute it,
21+
# with or without modifications, as long as this notice is preserved.
22+
23+
# AM_CONDITIONAL(NAME, SHELL-CONDITION)
24+
# -------------------------------------
25+
# Define a conditional.
26+
AC_DEFUN([AM_CONDITIONAL],
27+
[AC_PREREQ([2.52])dnl
28+
m4_if([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])],
29+
[$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl
30+
AC_SUBST([$1_TRUE])dnl
31+
AC_SUBST([$1_FALSE])dnl
32+
_AM_SUBST_NOTMAKE([$1_TRUE])dnl
33+
_AM_SUBST_NOTMAKE([$1_FALSE])dnl
34+
m4_define([_AM_COND_VALUE_$1], [$2])dnl
35+
if $2; then
36+
$1_TRUE=
37+
$1_FALSE='#'
38+
else
39+
$1_TRUE='#'
40+
$1_FALSE=
41+
fi
42+
AC_CONFIG_COMMANDS_PRE(
43+
[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then
44+
AC_MSG_ERROR([[conditional "$1" was never defined.
45+
Usually this means the macro was only invoked conditionally.]])
46+
fi])])
47+
48+
# Copyright (C) 2006-2017 Free Software Foundation, Inc.
49+
#
50+
# This file is free software; the Free Software Foundation
51+
# gives unlimited permission to copy and/or distribute it,
52+
# with or without modifications, as long as this notice is preserved.
53+
54+
# _AM_SUBST_NOTMAKE(VARIABLE)
55+
# ---------------------------
56+
# Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in.
57+
# This macro is traced by Automake.
58+
AC_DEFUN([_AM_SUBST_NOTMAKE])
59+
60+
# AM_SUBST_NOTMAKE(VARIABLE)
61+
# --------------------------
62+
# Public sister of _AM_SUBST_NOTMAKE.
63+
AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
64+
1565
m4_include([../libtool.m4])
1666
m4_include([../ltoptions.m4])
1767
m4_include([../ltsugar.m4])

gcc/ada/gcc-interface/Makefile.in

+4-1
Original file line numberDiff line numberDiff line change
@@ -796,13 +796,16 @@ gnatlib-shared-darwin:
796796
$(GNATRTL_NONTASKING_OBJS) $(LIBGNAT_OBJS) \
797797
$(SO_OPTS) \
798798
-Wl,-install_name,@rpath/libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) \
799-
$(MISCLIB)
799+
-nodefaultrpaths -Wl,-rpath,@loader_path/,-rpath,@loader_path/.. \
800+
-Wl,-rpath,@loader_path/../../../../ $(MISCLIB)
800801
cd $(RTSDIR); `echo "$(GCC_FOR_TARGET)" \
801802
| sed -e 's,\./xgcc,../../xgcc,' -e 's,-B\./,-B../../,'` -dynamiclib $(PICFLAG_FOR_TARGET) \
802803
-o libgnarl$(hyphen)$(LIBRARY_VERSION)$(soext) \
803804
$(GNATRTL_TASKING_OBJS) \
804805
$(SO_OPTS) \
805806
-Wl,-install_name,@rpath/libgnarl$(hyphen)$(LIBRARY_VERSION)$(soext) \
807+
-nodefaultrpaths -Wl,-rpath,@loader_path/,-rpath,@loader_path/.. \
808+
-Wl,-rpath,@loader_path/../../../../ \
806809
$(THREADSLIB) -Wl,libgnat$(hyphen)$(LIBRARY_VERSION)$(soext)
807810
cd $(RTSDIR); $(LN_S) libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) \
808811
libgnat$(soext)

gcc/config/darwin-driver.cc

+24
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ darwin_driver_init (unsigned int *decoded_options_count,
276276
bool seen_version_min = false;
277277
bool seen_sysroot_p = false;
278278
bool noexport_p = true;
279+
#ifdef RPATH_SETS_NODEFAULT
280+
bool seen_rpath_p = false;
281+
bool seen_nodefaultrpaths_p = false;
282+
#endif
279283

280284
for (i = 1; i < *decoded_options_count; i++)
281285
{
@@ -349,8 +353,16 @@ darwin_driver_init (unsigned int *decoded_options_count,
349353
gcc_checking_assert ((*decoded_options)[i].arg);
350354
if (startswith ((*decoded_options)[i].arg, "-exported_symbol"))
351355
noexport_p = false;
356+
#ifdef RPATH_SETS_NODEFAULT
357+
else if (strncmp ((*decoded_options)[i].arg, "-rpath", 6) == 0)
358+
seen_rpath_p = true;
359+
#endif
352360
break;
353361

362+
#ifdef RPATH_SETS_NODEFAULT
363+
case OPT_nodefaultrpaths:
364+
seen_nodefaultrpaths_p = true;
365+
#endif
354366
default:
355367
break;
356368
}
@@ -490,4 +502,16 @@ darwin_driver_init (unsigned int *decoded_options_count,
490502
generate_option (OPT_nodefaultexport, NULL, 1, CL_DRIVER,
491503
&(*decoded_options)[*decoded_options_count - 1]);
492504
}
505+
506+
#ifdef RPATH_SETS_NODEFAULT
507+
if (seen_rpath_p && !seen_nodefaultrpaths_p)
508+
{
509+
++*decoded_options_count;
510+
*decoded_options = XRESIZEVEC (struct cl_decoded_option,
511+
*decoded_options,
512+
*decoded_options_count);
513+
generate_option (OPT_nodefaultrpaths, NULL, 1, CL_DRIVER,
514+
&(*decoded_options)[*decoded_options_count - 1]);
515+
}
516+
#endif
493517
}

gcc/config/darwin.h

+23-4
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,13 @@ extern GTY(()) int darwin_ms_struct;
296296
#define DARWIN_CC1_SPEC \
297297
"%<dynamic %<dynamiclib %<force_cpusubtype_ALL "
298298

299+
#if DARWIN_AT_RPATH
300+
#define DARWIN_RPATH_LINK \
301+
"%{!r:%{!nostdlib:%{!nodefaultrpaths:%(darwin_rpaths)}}}"
302+
#else
303+
#define DARWIN_RPATH_LINK ""
304+
#endif
305+
299306
#define SUBSUBTARGET_OVERRIDE_OPTIONS \
300307
do { \
301308
darwin_override_options (); \
@@ -387,7 +394,8 @@ extern GTY(()) int darwin_ms_struct;
387394
DARWIN_NOPIE_SPEC \
388395
DARWIN_RDYNAMIC \
389396
DARWIN_NOCOMPACT_UNWIND \
390-
"}}}}}}} %<pie %<no-pie %<rdynamic %<X %<rpath "
397+
DARWIN_RPATH_LINK \
398+
"}}}}}}} %<pie %<no-pie %<rdynamic %<X %<rpath %<nodefaultrpaths "
391399

392400
/* Spec that controls whether the debug linker is run automatically for
393401
a link step. This needs to be done if there is a source file on the
@@ -509,8 +517,7 @@ extern GTY(()) int darwin_ms_struct;
509517
%:version-compare(!> 10.6 mmacosx-version-min= -lgcc_eh) \
510518
%:version-compare(>= 10.6 mmacosx-version-min= -lemutls_w); \
511519
shared-libgcc|fexceptions|fobjc-exceptions|fgnu-runtime: \
512-
%:version-compare(!> 10.11 mmacosx-version-min= -lgcc_s.1.1) \
513-
%:version-compare(>= 10.11 mmacosx-version-min= -lemutls_w) \
520+
-lgcc_s.1.1 \
514521
%:version-compare(!> 10.3.9 mmacosx-version-min= -lgcc_eh) \
515522
%:version-compare(>< 10.3.9 10.5 mmacosx-version-min= -lgcc_s.10.4) \
516523
%:version-compare(>< 10.5 10.6 mmacosx-version-min= -lgcc_s.10.5); \
@@ -545,7 +552,8 @@ extern GTY(()) int darwin_ms_struct;
545552
{ "darwin_crt2", DARWIN_CRT2_SPEC }, \
546553
{ "darwin_crt3", DARWIN_CRT3_SPEC }, \
547554
{ "darwin_dylib1", DARWIN_DYLIB1_SPEC }, \
548-
{ "darwin_bundle1", DARWIN_BUNDLE1_SPEC },
555+
{ "darwin_bundle1", DARWIN_BUNDLE1_SPEC }, \
556+
{ "darwin_rpaths", DARWIN_RPATH_SPEC },
549557

550558
#define DARWIN_CRT1_SPEC \
551559
"%:version-compare(!> 10.5 mmacosx-version-min= -lcrt1.o) \
@@ -571,6 +579,17 @@ extern GTY(()) int darwin_ms_struct;
571579
"%{!static:%:version-compare(< 10.6 mmacosx-version-min= -lbundle1.o) \
572580
%{fgnu-tm: -lcrttms.o}}"
573581

582+
#if DARWIN_AT_RPATH
583+
/* A default rpath, that picks up dependent libraries installed in the same
584+
director as one being loaded. */
585+
#define DARWIN_RPATH_SPEC \
586+
"%:version-compare(>= 10.5 mmacosx-version-min= -rpath) \
587+
%:version-compare(>= 10.5 mmacosx-version-min= @loader_path) \
588+
%P "
589+
#else
590+
#define DARWIN_RPATH_SPEC ""
591+
#endif
592+
574593
#ifdef HAVE_AS_MMACOSX_VERSION_MIN_OPTION
575594
/* Emit macosx version (but only major). */
576595
#define ASM_MMACOSX_VERSION_MIN_SPEC \

gcc/config/darwin.opt

+4
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ nodefaultexport
237237
Driver RejectNegative
238238
Do not add a default symbol exports to modules or dynamic libraries.
239239

240+
nodefaultrpaths
241+
Driver RejectNegative
242+
Do not add default run paths (for the compiler library directories) to executables, modules or dynamic libraries.
243+
240244
nofixprebinding
241245
Driver RejectNegative
242246
(Obsolete after 10.3.9) Set MH_NOPREFIXBINDING, in an executable.

0 commit comments

Comments
 (0)