https://gcc.gnu.org/g:edab001c63dcd83589b0375e689f14a5da73bfb4
commit r13-8546-gedab001c63dcd83589b0375e689f14a5da73bfb4 Author: Iain Sandoe <i...@sandoe.co.uk> Date: Thu Mar 21 14:34:44 2024 +0000 Darwin: Correct handling of weak crts. Backport part of 506e74f53a5 from trunk. We need the weak crts to be considered ahead of GCC target libraries (except libgcc_s) to avoid spurious dependencies on otherwise unused libs. gcc/ChangeLog: * config/darwin.h (LINK_COMMAND_SPEC_A): Handle weak crts before other objects. (REAL_LIBGCC_SPEC): Remove weak crts from here. (DARWIN_WEAK_CRTS): New. Signed-off-by: Iain Sandoe <i...@sandoe.co.uk> Diff: --- gcc/config/darwin.h | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h index 8620c006ca8..5c6c38ddc63 100644 --- a/gcc/config/darwin.h +++ b/gcc/config/darwin.h @@ -366,7 +366,9 @@ extern GTY(()) int darwin_ms_struct; %{e*} %{r} \ %{o*}%{!o:-o a.out} \ %{!r:%{!nostdlib:%{!nostartfiles:%S}}} \ - %{L*} %(link_libgcc) %o \ + %{L*} %(link_libgcc) \ + %{!r:%{!nostdlib:%{!nodefaultlibs: " DARWIN_WEAK_CRTS "}}} \ + %o \ %{!r:%{!nostdlib:%{!nodefaultlibs:\ %{fprofile-arcs|fprofile-generate*|coverage:-lgcov} \ %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1): \ @@ -380,15 +382,15 @@ extern GTY(()) int darwin_ms_struct; %(link_ssp) \ %:version-compare(>< 10.6 10.7 mmacosx-version-min= -ld10-uwfef) \ %(link_gcc_c_sequence) \ - %{!nodefaultexport:%{dylib|dynamiclib|bundle: \ - %:version-compare(>= 10.11 asm_macosx_version_min= -U) \ - %:version-compare(>= 10.11 asm_macosx_version_min= ___emutls_get_address) \ - %:version-compare(>= 10.11 asm_macosx_version_min= -exported_symbol) \ - %:version-compare(>= 10.11 asm_macosx_version_min= ___emutls_get_address) \ - %:version-compare(>= 10.11 asm_macosx_version_min= -U) \ - %:version-compare(>= 10.11 asm_macosx_version_min= ___emutls_register_common) \ - %:version-compare(>= 10.11 asm_macosx_version_min= -exported_symbol) \ - %:version-compare(>= 10.11 asm_macosx_version_min= ___emutls_register_common) \ + %{!nodefaultexport: \ + %{%:version-compare(>= 10.11 asm_macosx_version_min= -U): \ + ___emutls_get_address -exported_symbol ___emutls_get_address \ + -U ___emutls_register_common \ + -exported_symbol ___emutls_register_common \ + -U ___gcc_nested_func_ptr_created \ + -exported_symbol ___gcc_nested_func_ptr_created \ + -U ___gcc_nested_func_ptr_deleted \ + -exported_symbol ___gcc_nested_func_ptr_deleted \ }} \ }}}\ %{!r:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} %{F*} "\ @@ -508,17 +510,22 @@ extern GTY(()) int darwin_ms_struct; #undef REAL_LIBGCC_SPEC #define REAL_LIBGCC_SPEC \ "%{static-libgcc|static: \ - %:version-compare(!> 10.6 mmacosx-version-min= -lgcc_eh) \ - %:version-compare(>= 10.6 mmacosx-version-min= -lemutls_w); \ + %:version-compare(!> 10.6 mmacosx-version-min= -lgcc_eh); \ shared-libgcc|fexceptions|fobjc-exceptions|fgnu-runtime: \ %:version-compare(!> 10.11 mmacosx-version-min= -lgcc_s.1.1) \ - %:version-compare(>= 10.11 mmacosx-version-min= -lemutls_w) \ %:version-compare(!> 10.3.9 mmacosx-version-min= -lgcc_eh) \ %:version-compare(>< 10.3.9 10.5 mmacosx-version-min= -lgcc_s.10.4) \ - %:version-compare(>< 10.5 10.6 mmacosx-version-min= -lgcc_s.10.5); \ - : -lemutls_w \ + %:version-compare(>< 10.5 10.6 mmacosx-version-min= -lgcc_s.10.5) \ } -lgcc " +#define DARWIN_WEAK_CRTS \ +"%{static-libgcc|static: \ + %:version-compare(>= 10.6 mmacosx-version-min= -lemutls_w) ; \ + shared-libgcc|fexceptions|fobjc-exceptions|fgnu-runtime: \ + %:version-compare(>= 10.11 mmacosx-version-min= -lemutls_w) ; \ + : -lemutls_w \ + }" + /* We specify crt0.o as -lcrt0.o so that ld will search the library path. */ #undef STARTFILE_SPEC