aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorIain Sandoe <iain@sandoe.co.uk>2024-01-28 13:31:56 +0000
committerIain Sandoe <iain@sandoe.co.uk>2024-01-30 09:33:09 +0000
commit506e74f53a5e4f607284d3c41da17cdd3eca4fb8 (patch)
tree2164d58210734142c354fbc6b0ce9a9c25e54fdb /gcc
parent7b3b3788c579856abcfdc6eed589c64dc7e88cdb (diff)
downloadgcc-506e74f53a5e4f607284d3c41da17cdd3eca4fb8.zip
gcc-506e74f53a5e4f607284d3c41da17cdd3eca4fb8.tar.gz
gcc-506e74f53a5e4f607284d3c41da17cdd3eca4fb8.tar.bz2
libgcc: Make heap trampoline support dynamic [PR113403].
In order to handle system security constraints during GCC build and test and that most platform versions cannot link to libgcc_eh since the unwinder there is incompatible with the system one. 1. We make the support functions weak definitions. 2. We include them as a CRT for platform conditions that do not allow libgcc_eh. 3. We ensure that the weak symbols are exported from DSOs (which includes exes on Darwin) so that the dynamic linker will pick one instance (which avoids duplication of trampoline caches). PR libgcc/113403 gcc/ChangeLog: * config/darwin.h (DARWIN_SHARED_WEAK_ADDS, DARWIN_WEAK_CRTS): New. (REAL_LIBGCC_SPEC): Move weak CRT handling to separate spec. * config/i386/darwin.h (DARWIN_HEAP_T_LIB): New. * config/i386/darwin32-biarch.h (DARWIN_HEAP_T_LIB): New. * config/i386/darwin64-biarch.h (DARWIN_HEAP_T_LIB): New. * config/rs6000/darwin.h (DARWIN_HEAP_T_LIB): New. libgcc/ChangeLog: * config.host: Build libheap_t.a for i686/x86_64 Darwin. * config/aarch64/heap-trampoline.c (HEAP_T_ATTR): New. (allocate_tramp_ctrl): Allow a target to build this as a weak def. (__gcc_nested_func_ptr_created): Likewise. * config/i386/heap-trampoline.c (HEAP_T_ATTR): New. (allocate_tramp_ctrl): Allow a target to build this as a weak def. (__gcc_nested_func_ptr_created): Likewise. * config/t-darwin: Build libheap_t.a (a CRT with heap trampoline support).
Diffstat (limited to 'gcc')
-rw-r--r--gcc/config/darwin.h43
-rw-r--r--gcc/config/i386/darwin.h2
-rw-r--r--gcc/config/i386/darwin32-biarch.h3
-rw-r--r--gcc/config/i386/darwin64-biarch.h3
-rw-r--r--gcc/config/rs6000/darwin.h3
5 files changed, 38 insertions, 16 deletions
diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h
index cb96d67..31019a0 100644
--- a/gcc/config/darwin.h
+++ b/gcc/config/darwin.h
@@ -314,13 +314,17 @@ extern GTY(()) int darwin_ms_struct;
# define DARWIN_RPATH_LINK \
"%{!r:%{!nostdlib:%{!nodefaultrpaths:%(darwin_rpaths)}}}"
# define DARWIN_SHARED_LIBGCC "-lgcc_s.1.1"
+# define DARWIN_SHARED_WEAK_ADDS " "
#else
# define DARWIN_RPATH_LINK ""
# define DARWIN_SHARED_LIBGCC \
-"%:version-compare(!> 10.11 mmacosx-version-min= -lgcc_s.1.1) \
- %:version-compare(>= 10.11 mmacosx-version-min= -lemutls_w) "
+"%:version-compare(!> 10.11 mmacosx-version-min= -lgcc_s.1.1)"
+# define DARWIN_SHARED_WEAK_ADDS \
+"%{%:version-compare(>= 10.11 mmacosx-version-min= -lemutls_w): \
+ " DARWIN_HEAP_T_LIB "}"
#endif
+
/* We might elect to add a path even when this compiler does not use embedded
run paths, so that we can use libraries from an alternate compiler that is
using embedded runpaths. */
@@ -398,7 +402,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): \
@@ -412,15 +418,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*} "\
@@ -542,16 +548,21 @@ 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: \
" DARWIN_SHARED_LIBGCC " \
%: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): \
+ " DARWIN_HEAP_T_LIB "} ; \
+ : -lemutls_w " DARWIN_HEAP_T_LIB " \
+ }"
+
/* We specify crt0.o as -lcrt0.o so that ld will search the library path. */
#undef STARTFILE_SPEC
diff --git a/gcc/config/i386/darwin.h b/gcc/config/i386/darwin.h
index b7814f7..8e64b4e 100644
--- a/gcc/config/i386/darwin.h
+++ b/gcc/config/i386/darwin.h
@@ -119,6 +119,8 @@ along with GCC; see the file COPYING3. If not see
/* We default to x86_64 for single-arch builds, bi-arch overrides. */
#define DARWIN_ARCH_SPEC "x86_64"
#define DARWIN_SUBARCH_SPEC DARWIN_ARCH_SPEC
+#undef DARWIN_HEAP_T_LIB
+#define DARWIN_HEAP_T_LIB " -lheapt_w "
#endif
#undef SUBTARGET_EXTRA_SPECS
diff --git a/gcc/config/i386/darwin32-biarch.h b/gcc/config/i386/darwin32-biarch.h
index 051ad12..2180f5a 100644
--- a/gcc/config/i386/darwin32-biarch.h
+++ b/gcc/config/i386/darwin32-biarch.h
@@ -27,6 +27,9 @@ along with GCC; see the file COPYING3. If not see
#undef DARWIN_SUBARCH_SPEC
#define DARWIN_SUBARCH_SPEC DARWIN_ARCH_SPEC
+#undef DARWIN_HEAP_T_LIB
+#define DARWIN_HEAP_T_LIB " %{m64:-lheapt_w}"
+
#undef SUBTARGET_EXTRA_SPECS
#define SUBTARGET_EXTRA_SPECS \
DARWIN_EXTRA_SPECS \
diff --git a/gcc/config/i386/darwin64-biarch.h b/gcc/config/i386/darwin64-biarch.h
index 8543679..6208007 100644
--- a/gcc/config/i386/darwin64-biarch.h
+++ b/gcc/config/i386/darwin64-biarch.h
@@ -28,6 +28,9 @@ along with GCC; see the file COPYING3. If not see
#undef DARWIN_SUBARCH_SPEC
#define DARWIN_SUBARCH_SPEC DARWIN_ARCH_SPEC
+#undef DARWIN_HEAP_T_LIB
+#define DARWIN_HEAP_T_LIB "%{!m32:-lheapt_w}"
+
#undef SUBTARGET_EXTRA_SPECS
#define SUBTARGET_EXTRA_SPECS \
DARWIN_EXTRA_SPECS \
diff --git a/gcc/config/rs6000/darwin.h b/gcc/config/rs6000/darwin.h
index b264284..e8b1949 100644
--- a/gcc/config/rs6000/darwin.h
+++ b/gcc/config/rs6000/darwin.h
@@ -113,6 +113,9 @@
-lSystem \
}"
+#undef DARWIN_HEAP_T_LIB
+#define DARWIN_HEAP_T_LIB " "
+
/* We want -fPIC by default, unless we're using -static to compile for
the kernel or some such. The "-faltivec" option should have been
called "-maltivec" all along. */