Start mass upgrade
[dragora.git] / patches / gcc / 10 / 0004-static-pie.patch
blob32f48a9d373d4478c28d36b1f1ec403b35228cb9
1 From f98d6d0809c020b547d45755f68b0d997607292a Mon Sep 17 00:00:00 2001
2 From: Szabolcs Nagy <nsz@port70.net>
3 Date: Sat, 18 Aug 2018 23:58:45 +0000
4 Subject: [PATCH 4/6] static-pie
6 in gcc-8 -static means static non-pie, even if -pie or -static-pie
7 are specified, -static-pie can be used to build static pie.
9 in musl toolchains -static -pie always meant static pie, so this
10 patch fixes the link specs accordingly, the new -static-pie is just
11 an alias to -static -pie.
12 ---
13 gcc/common.opt | 4 ++--
14 gcc/config/gnu-user.h | 17 ++++++++---------
15 gcc/gcc.c | 6 +++---
16 3 files changed, 13 insertions(+), 14 deletions(-)
18 diff --git a/gcc/common.opt b/gcc/common.opt
19 index ec5235c3a41..dcee05500ba 100644
20 --- a/gcc/common.opt
21 +++ b/gcc/common.opt
22 @@ -3401,11 +3401,11 @@ Driver
24 no-pie
25 Driver RejectNegative Negative(shared)
26 -Don't create a dynamically linked position independent executable.
27 +Don't create a position independent executable.
29 pie
30 Driver RejectNegative Negative(no-pie)
31 -Create a dynamically linked position independent executable.
32 +Create a position independent executable.
34 static-pie
35 Driver RejectNegative Negative(pie)
36 diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h
37 index ff2e880b1fa..bafde149202 100644
38 --- a/gcc/config/gnu-user.h
39 +++ b/gcc/config/gnu-user.h
40 @@ -51,13 +51,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
41 #define GNU_USER_TARGET_STARTFILE_SPEC \
42 "%{shared:; \
43 pg|p|profile:%{static-pie:grcrt1.o%s;:gcrt1.o%s}; \
44 - static:crt1.o%s; \
45 - static-pie:rcrt1.o%s; \
46 + static|static-pie:%{" PIE_SPEC ":rcrt1.o%s;:crt1.o%s}; \
47 " PIE_SPEC ":Scrt1.o%s; \
48 :crt1.o%s} " \
49 GNU_USER_TARGET_CRTI " \
50 - %{static:crtbeginT.o%s; \
51 - shared|static-pie|" PIE_SPEC ":crtbeginS.o%s; \
52 + %{shared|" PIE_SPEC ":crtbeginS.o%s; \
53 + static:crtbeginT.o%s; \
54 :crtbegin.o%s} \
55 %{fvtable-verify=none:%s; \
56 fvtable-verify=preinit:vtv_start_preinit.o%s; \
57 @@ -73,11 +72,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
58 GNU userspace "finalizer" file, `crtn.o'. */
60 #define GNU_USER_TARGET_ENDFILE_SPEC \
61 - "%{!static:%{fvtable-verify=none:%s; \
62 + "%{static|static-pie:; \
63 + fvtable-verify=none:%s; \
64 fvtable-verify=preinit:vtv_end_preinit.o%s; \
65 - fvtable-verify=std:vtv_end.o%s}} \
66 - %{static:crtend.o%s; \
67 - shared|static-pie|" PIE_SPEC ":crtendS.o%s; \
68 + fvtable-verify=std:vtv_end.o%s} \
69 + %{shared|" PIE_SPEC ":crtendS.o%s; \
70 :crtend.o%s} " \
71 GNU_USER_TARGET_CRTN " " \
72 CRTOFFLOADEND
73 @@ -106,7 +105,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
74 #define LIB_SPEC GNU_USER_TARGET_LIB_SPEC
76 #if defined(HAVE_LD_EH_FRAME_HDR)
77 -#define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} "
78 +#define LINK_EH_SPEC "%{!static|" PIE_SPEC ":--eh-frame-hdr} "
79 #endif
81 #define GNU_USER_TARGET_LINK_GCC_C_SEQUENCE_SPEC \
82 diff --git a/gcc/gcc.c b/gcc/gcc.c
83 index e6887590ae2..df6e3965f13 100644
84 --- a/gcc/gcc.c
85 +++ b/gcc/gcc.c
86 @@ -907,7 +907,7 @@ proper position among the other output files. */
87 #define NO_FPIE_AND_FPIC_SPEC NO_FPIE_SPEC "|" NO_FPIC_SPEC
88 #define FPIE_OR_FPIC_SPEC NO_FPIE_AND_FPIC_SPEC ":;"
89 #else
90 -#define PIE_SPEC "pie"
91 +#define PIE_SPEC "pie|static-pie"
92 #define FPIE1_SPEC "fpie"
93 #define NO_FPIE1_SPEC FPIE1_SPEC ":;"
94 #define FPIE2_SPEC "fPIE"
95 @@ -931,12 +931,12 @@ proper position among the other output files. */
96 #ifndef LINK_PIE_SPEC
97 #ifdef HAVE_LD_PIE
98 #ifndef LD_PIE_SPEC
99 -#define LD_PIE_SPEC "-pie"
100 +#define LD_PIE_SPEC "-pie %{static|static-pie:--no-dynamic-linker -z text -Bsymbolic}"
101 #endif
102 #else
103 #define LD_PIE_SPEC ""
104 #endif
105 -#define LINK_PIE_SPEC "%{static|shared|r:;" PIE_SPEC ":" LD_PIE_SPEC "} "
106 +#define LINK_PIE_SPEC "%{shared|r:;" PIE_SPEC ":" LD_PIE_SPEC "} "
107 #endif
109 #ifndef LINK_BUILDID_SPEC
111 2.31.1