Skip to content

Commit

Permalink
[darwin, config] Revise linker specs to bring the PIE and unwind spec…
Browse files Browse the repository at this point in the history
…s into darwin.h.
  • Loading branch information
iains committed Apr 1, 2019
1 parent c74bdda commit f43e323
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 30 deletions.
57 changes: 36 additions & 21 deletions gcc/config/darwin.h
Expand Up @@ -168,13 +168,29 @@ extern GTY(()) int darwin_ms_struct;
linkers, and for positional arguments like libraries. */

#if LD64_HAS_EXPORT_DYNAMIC
#define DARWIN_EXPORT_DYNAMIC " %{rdynamic:-export_dynamic}"
# define DARWIN_EXPORT_DYNAMIC " %{rdynamic:-export_dynamic}"
#else
#define DARWIN_EXPORT_DYNAMIC " %{rdynamic: %nrdynamic is not supported}"
# define DARWIN_EXPORT_DYNAMIC " %{rdynamic: %nrdynamic is not supported}"
#endif

#define DARWIN_PIE_SPEC \
" %{fpie|pie|fPIE: \
%{mdynamic-no-pic: %n'-mdynamic-no-pic' overrides '-pie', '-fpie' or '-fPIE'; \
:%:version-compare(>= 10.5 mmacosx-version-min= -pie)}} "

/* Darwin requires PIC to support PIE exes. */
#define DARWIN_NOPIE_SPEC \
" %{fno-pic|fno-PIC|fno-pie|fno-PIE|no-pie|fapple-kext|mkernel|static|mdynamic-no-pic: \
%:version-compare(>= 10.7 mmacosx-version-min= -no_pie) } "

/* Fix PR41260 by passing -no_compact_unwind on darwin10 and later until the
system unwinder can handle the relevant output. */

#define DARWIN_NOCOMPACT_UNWIND \
" %:version-compare(>= 10.6 mmacosx-version-min= -no_compact_unwind) "

#define LINK_COMMAND_SPEC_A \
"%{!fdump=*:%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
"%{!fdump=*:%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
%(linker)" \
LINK_PLUGIN_SPEC \
"%{flto*:%<fcompare-debug*} \
Expand All @@ -183,26 +199,28 @@ extern GTY(()) int darwin_ms_struct;
"%X %{s} %{t} %{Z} %{u*} \
%{e*} %{r} \
%{o*}%{!o:-o a.out} \
%{!nostdlib:%{!nostartfiles:%S}} \
%{L*} %(link_libgcc) %o %{fprofile-arcs|fprofile-generate*|coverage:-lgcov} \
%{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1): \
%{static|static-libgcc|static-libstdc++|static-libgfortran: libgomp.a%s; : -lgomp } } \
%{fgnu-tm: \
%{static|static-libgcc|static-libstdc++|static-libgfortran: libitm.a%s; : -litm } } \
%{!nostdlib:%{!nodefaultlibs:\
%{!nostdlib:%{!r:%{!nostartfiles:%S}}} \
%{L*} %(link_libgcc) %o \
%{!nostdlib:%{!nodefaultlibs:%{!r: \
%{fprofile-arcs|fprofile-generate*|coverage:-lgcov} \
%{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1): \
%{static|static-libgcc|static-libstdc++|static-libgfortran: libgomp.a%s; : -lgomp } } \
%{fgnu-tm: \
%{static|static-libgcc|static-libstdc++|static-libgfortran: libitm.a%s; : -litm } } \
%{%:sanitize(address): -lasan } \
%{%:sanitize(undefined): -lubsan } \
%(link_ssp) \
" DARWIN_EXPORT_DYNAMIC " %<rdynamic \
%{Zdynamiclib|Zbundle: -lemutls_w } \
%{!Zdynamiclib:%{!Zbundle: -lemutls_s.o }} \
%:version-compare(>< 10.6 10.7 mmacosx-version-min= -ld10-uwfef.o) \
%(link_gcc_c_sequence) \
%{fno-pic|fno-PIC|fno-pie|fno-PIE|no-pie|fapple-kext|mkernel|static|mdynamic-no-pic: \
%:version-compare(>= 10.7 mmacosx-version-min= -no_pie) } \
%:version-compare(>= 10.6 mmacosx-version-min= -no_compact_unwind) \
}}\
%{!nostdlib:%{!nostartfiles:%E}} %{T*} %{F*} }}}}}}}"
}}}\
%{!nostdlib:%{!r:%{!nostartfiles:%E}}} %{T*} %{F*} " \
DARWIN_EXPORT_DYNAMIC \
DARWIN_PIE_SPEC \
DARWIN_NOPIE_SPEC \
DARWIN_NOCOMPACT_UNWIND \
"}}}}}}}"

#define DSYMUTIL "\ndsymutil"

Expand Down Expand Up @@ -239,8 +257,6 @@ extern GTY(()) int darwin_ms_struct;
#define STANDARD_STARTFILE_PREFIX_1 ""
#define STANDARD_STARTFILE_PREFIX_2 ""

#define DARWIN_PIE_SPEC "%{fpie|pie|fPIE:}"

/* Please keep the random linker options in alphabetical order (modulo
'Z' and 'no' prefixes). Note that options taking arguments may appear
multiple times on a command line with different arguments each time,
Expand Down Expand Up @@ -304,7 +320,6 @@ extern GTY(()) int darwin_ms_struct;
%:version-compare(< 10.5 mmacosx-version-min= -multiply_defined) \
%:version-compare(< 10.5 mmacosx-version-min= suppress)}} \
%{Zmultiplydefinedunused*:-multiply_defined_unused %*} \
" DARWIN_PIE_SPEC " \
%{prebind} %{noprebind} %{nofixprebinding} %{prebind_all_twolevel_modules} \
%{read_only_relocs} \
%{sectcreate*} %{sectorder*} %{seg1addr*} %{segprot*} \
Expand All @@ -329,7 +344,6 @@ extern GTY(()) int darwin_ms_struct;
%{whatsloaded} %{dylinker_install_name*} \
%{dylinker} %{Mach} "


/* Machine dependent libraries. */

#define LIB_SPEC "%{!static:-lSystem}"
Expand Down Expand Up @@ -418,7 +432,8 @@ extern GTY(()) int darwin_ms_struct;

#define ASM_DEBUG_SPEC "%{g*:%{%:debug-level-gt(0):%{!gdwarf*:--gstabs}}}"
#define ASM_FINAL_SPEC \
"%{gsplit-dwarf:%ngsplit-dwarf is not supported on this platform } %<gsplit-dwarf"
"%{gsplit-dwarf:%ngsplit-dwarf is not supported on this platform } \
%<gsplit-dwarf "

/* We still allow output of STABS if the assembler supports it. */
#ifdef HAVE_AS_STABS_DIRECTIVE
Expand Down
9 changes: 0 additions & 9 deletions gcc/config/darwin9.h
Expand Up @@ -32,15 +32,6 @@ along with GCC; see the file COPYING3. If not see
%{.c|.cc|.C|.cpp|.cp|.c++|.cxx|.CPP|.m|.mm|.s|.f|.f90|.f95|.f03|.f77|.for|.F|.F90|.F95|.F03: \
%{g*:%{!gstabs*:%{%:debug-level-gt(0): -dsym}}}}}}}}}}}"

/* Tell collect2 to run dsymutil for us as necessary. */
#define COLLECT_RUN_DSYMUTIL 1

#undef DARWIN_PIE_SPEC
#define DARWIN_PIE_SPEC \
"%{fpie|pie|fPIE: \
%{mdynamic-no-pic: %n'-mdynamic-no-pic' overrides '-pie', '-fpie' or '-fPIE'; \
:-pie}}"

/* Only ask as for debug data if the debug style is stabs (since as doesn't
yet generate dwarf.) */

Expand Down

0 comments on commit f43e323

Please sign in to comment.