]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Darwin: Amend pie options when linking mdynamic-no-pic.
authorIain Sandoe <iain@sandoe.co.uk>
Mon, 6 Dec 2021 13:17:10 +0000 (13:17 +0000)
committerIain Sandoe <iain@sandoe.co.uk>
Wed, 8 Dec 2021 19:47:17 +0000 (19:47 +0000)
On i686 Darwin from macOS 10.7 onwards the default is to
link executables as PIE, which conflicts with code generated
using mdynamic-no-pic.  Rather than warn about this and then
get the user to add -Wl,-no_pie, we can inject this in the
link specs.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/ChangeLog:

* config/darwin.h (DARWIN_PIE_SPEC): Add -no_pie when
linking mdynamic-no-pic code on macOS > 10.7.

gcc/config/darwin.h

index 9895e7f99ecefd7bf42cd7a8bd17547807520a08..0ce13207ad644bff394cff192228ea8e72f9f67b 100644 (file)
@@ -288,13 +288,17 @@ extern GTY(()) int darwin_ms_struct;
 #define DARWIN_RDYNAMIC "%{rdynamic:%nrdynamic is not supported}"
 #endif
 
-/* FIXME: we should check that the linker supports the -pie and -no_pie.
+/* Code built with mdynamic-no-pic does not support PIE/PIC, so  we disallow
+   these combinations; we also ensure that the no_pie option is passed to
+   ld64 on system versions that default to PIE when mdynamic-no-pic is given.
+   FIXME: we should check that the linker supports the -pie and -no_pie.
    options.  */
 #define DARWIN_PIE_SPEC \
 "%{pie|fpie|fPIE:\
    %{mdynamic-no-pic: \
      %n'-mdynamic-no-pic' overrides '-pie', '-fpie' or '-fPIE'; \
-     :%:version-compare(>= 10.5 mmacosx-version-min= -pie) }} "
+     :%:version-compare(>= 10.5 mmacosx-version-min= -pie) }; \
+   mdynamic-no-pic:%:version-compare(>= 10.7 mmacosx-version-min= -no_pie) } "
 
 #define DARWIN_NOPIE_SPEC \
 "%{no-pie|fno-pie|fno-PIE: \