rev |
line source |
al@21060
|
1 # DP: On linux targets pass --as-needed by default to the linker, but always
|
al@21060
|
2 # DP: link the sanitizer libraries with --no-as-needed.
|
al@21060
|
3
|
al@21060
|
4 Index: b/gcc/gcc.c
|
al@21060
|
5 ===================================================================
|
al@21060
|
6 --- a/gcc/gcc.c
|
al@21060
|
7 +++ b/gcc/gcc.c
|
al@21060
|
8 @@ -692,8 +692,11 @@ proper position among the other output f
|
al@21060
|
9 #ifdef LIBASAN_EARLY_SPEC
|
al@21060
|
10 #define LIBASAN_SPEC STATIC_LIBASAN_LIBS
|
al@21060
|
11 #elif defined(HAVE_LD_STATIC_DYNAMIC)
|
al@21060
|
12 -#define LIBASAN_SPEC "%{static-libasan:" LD_STATIC_OPTION \
|
al@21060
|
13 - "} -lasan %{static-libasan:" LD_DYNAMIC_OPTION "}" \
|
al@21060
|
14 +#define LIBASAN_SPEC "%{static-libasan:" LD_STATIC_OPTION "}" \
|
al@21060
|
15 + " %{!static-libasan:%{!fuse-ld=gold:--push-state }--no-as-needed}" \
|
al@21060
|
16 + " -lasan " \
|
al@21060
|
17 + " %{static-libasan:" LD_DYNAMIC_OPTION "}" \
|
al@21060
|
18 + " %{!static-libasan:%{fuse-ld=gold:--as-needed;:--pop-state}}" \
|
al@21060
|
19 STATIC_LIBASAN_LIBS
|
al@21060
|
20 #else
|
al@21060
|
21 #define LIBASAN_SPEC "-lasan" STATIC_LIBASAN_LIBS
|
al@21060
|
22 @@ -710,8 +713,11 @@ proper position among the other output f
|
al@21060
|
23 #ifdef LIBTSAN_EARLY_SPEC
|
al@21060
|
24 #define LIBTSAN_SPEC STATIC_LIBTSAN_LIBS
|
al@21060
|
25 #elif defined(HAVE_LD_STATIC_DYNAMIC)
|
al@21060
|
26 -#define LIBTSAN_SPEC "%{static-libtsan:" LD_STATIC_OPTION \
|
al@21060
|
27 - "} -ltsan %{static-libtsan:" LD_DYNAMIC_OPTION "}" \
|
al@21060
|
28 +#define LIBTSAN_SPEC "%{static-libtsan:" LD_STATIC_OPTION "}" \
|
al@21060
|
29 + " %{!static-libtsan:%{!fuse-ld=gold:--push-state }--no-as-needed}" \
|
al@21060
|
30 + " -ltsan " \
|
al@21060
|
31 + " %{static-libtsan:" LD_DYNAMIC_OPTION "}" \
|
al@21060
|
32 + " %{!static-libtsan:%{fuse-ld=gold:--as-needed;:--pop-state}}" \
|
al@21060
|
33 STATIC_LIBTSAN_LIBS
|
al@21060
|
34 #else
|
al@21060
|
35 #define LIBTSAN_SPEC "-ltsan" STATIC_LIBTSAN_LIBS
|
al@21060
|
36 @@ -728,8 +734,11 @@ proper position among the other output f
|
al@21060
|
37 #ifdef LIBLSAN_EARLY_SPEC
|
al@21060
|
38 #define LIBLSAN_SPEC STATIC_LIBLSAN_LIBS
|
al@21060
|
39 #elif defined(HAVE_LD_STATIC_DYNAMIC)
|
al@21060
|
40 -#define LIBLSAN_SPEC "%{static-liblsan:" LD_STATIC_OPTION \
|
al@21060
|
41 - "} -llsan %{static-liblsan:" LD_DYNAMIC_OPTION "}" \
|
al@21060
|
42 +#define LIBLSAN_SPEC "%{static-liblsan:" LD_STATIC_OPTION "}" \
|
al@21060
|
43 + " %{!static-liblsan:%{!fuse-ld=gold:--push-state }--no-as-needed}" \
|
al@21060
|
44 + " -llsan " \
|
al@21060
|
45 + " %{static-liblsan:" LD_DYNAMIC_OPTION "}" \
|
al@21060
|
46 + " %{!static-liblsan:%{fuse-ld=gold:--as-needed;:--pop-state}}" \
|
al@21060
|
47 STATIC_LIBLSAN_LIBS
|
al@21060
|
48 #else
|
al@21060
|
49 #define LIBLSAN_SPEC "-llsan" STATIC_LIBLSAN_LIBS
|
al@21060
|
50 @@ -744,8 +753,11 @@ proper position among the other output f
|
al@21060
|
51 #define STATIC_LIBUBSAN_LIBS \
|
al@21060
|
52 " %{static-libubsan|static:%:include(libsanitizer.spec)%(link_libubsan)}"
|
al@21060
|
53 #ifdef HAVE_LD_STATIC_DYNAMIC
|
al@21060
|
54 -#define LIBUBSAN_SPEC "%{static-libubsan:" LD_STATIC_OPTION \
|
al@21060
|
55 - "} -lubsan %{static-libubsan:" LD_DYNAMIC_OPTION "}" \
|
al@21060
|
56 +#define LIBUBSAN_SPEC "%{static-libubsan:" LD_STATIC_OPTION "}" \
|
al@21060
|
57 + " %{!static-libubsan:%{!fuse-ld=gold:--push-state }--no-as-needed}" \
|
al@21060
|
58 + " -lubsan " \
|
al@21060
|
59 + " %{static-libubsan:" LD_DYNAMIC_OPTION "}" \
|
al@21060
|
60 + " %{!static-libubsan:%{fuse-ld=gold:--as-needed;:--pop-state}}" \
|
al@21060
|
61 STATIC_LIBUBSAN_LIBS
|
al@21060
|
62 #else
|
al@21060
|
63 #define LIBUBSAN_SPEC "-lubsan" STATIC_LIBUBSAN_LIBS
|
al@21060
|
64 Index: b/gcc/config/gnu-user.h
|
al@21060
|
65 ===================================================================
|
al@21060
|
66 --- a/gcc/config/gnu-user.h
|
al@21060
|
67 +++ b/gcc/config/gnu-user.h
|
al@21060
|
68 @@ -161,15 +161,15 @@ see the files COPYING3 and COPYING.RUNTI
|
al@21060
|
69 #define LIBASAN_EARLY_SPEC "%{!shared:libasan_preinit%O%s} " \
|
al@21060
|
70 "%{static-libasan:%{!shared:" \
|
al@21060
|
71 LD_STATIC_OPTION " --whole-archive -lasan --no-whole-archive " \
|
al@21060
|
72 - LD_DYNAMIC_OPTION "}}%{!static-libasan:-lasan}"
|
al@21060
|
73 + LD_DYNAMIC_OPTION "}}%{!static-libasan:%{!fuse-ld=gold:--push-state} --no-as-needed -lasan %{fuse-ld=gold:--as-needed;:--pop-state}}"
|
al@21060
|
74 #undef LIBTSAN_EARLY_SPEC
|
al@21060
|
75 #define LIBTSAN_EARLY_SPEC "%{!shared:libtsan_preinit%O%s} " \
|
al@21060
|
76 "%{static-libtsan:%{!shared:" \
|
al@21060
|
77 LD_STATIC_OPTION " --whole-archive -ltsan --no-whole-archive " \
|
al@21060
|
78 - LD_DYNAMIC_OPTION "}}%{!static-libtsan:-ltsan}"
|
al@21060
|
79 + LD_DYNAMIC_OPTION "}}%{!static-libtsan:%{!fuse-ld=gold:--push-state} --no-as-needed -ltsan %{fuse-ld=gold:--as-needed;:--pop-state}}"
|
al@21060
|
80 #undef LIBLSAN_EARLY_SPEC
|
al@21060
|
81 #define LIBLSAN_EARLY_SPEC "%{!shared:liblsan_preinit%O%s} " \
|
al@21060
|
82 "%{static-liblsan:%{!shared:" \
|
al@21060
|
83 LD_STATIC_OPTION " --whole-archive -llsan --no-whole-archive " \
|
al@21060
|
84 - LD_DYNAMIC_OPTION "}}%{!static-liblsan:-llsan}"
|
al@21060
|
85 + LD_DYNAMIC_OPTION "}}%{!static-liblsan:%{!fuse-ld=gold:--push-state} --no-as-needed -llsan %{fuse-ld=gold:--as-needed;:--pop-state}}"
|
al@21060
|
86 #endif
|
al@21060
|
87 Index: b/gcc/config/aarch64/aarch64-linux.h
|
al@21060
|
88 ===================================================================
|
al@21060
|
89 --- a/gcc/config/aarch64/aarch64-linux.h
|
al@21060
|
90 +++ b/gcc/config/aarch64/aarch64-linux.h
|
al@21060
|
91 @@ -35,6 +35,7 @@
|
al@21060
|
92 #define CPP_SPEC "%{pthread:-D_REENTRANT}"
|
al@21060
|
93
|
al@21060
|
94 #define LINUX_TARGET_LINK_SPEC "%{h*} \
|
al@21060
|
95 + --as-needed \
|
al@21060
|
96 %{static:-Bstatic} \
|
al@21060
|
97 %{shared:-shared} \
|
al@21060
|
98 %{symbolic:-Bsymbolic} \
|
al@21060
|
99 Index: b/gcc/config/ia64/linux.h
|
al@21060
|
100 ===================================================================
|
al@21060
|
101 --- a/gcc/config/ia64/linux.h
|
al@21060
|
102 +++ b/gcc/config/ia64/linux.h
|
al@21060
|
103 @@ -58,7 +58,7 @@ do { \
|
al@21060
|
104 #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux-ia64.so.2"
|
al@21060
|
105
|
al@21060
|
106 #undef LINK_SPEC
|
al@21060
|
107 -#define LINK_SPEC "\
|
al@21060
|
108 +#define LINK_SPEC " --as-needed \
|
al@21060
|
109 %{shared:-shared} \
|
al@21060
|
110 %{!shared: \
|
al@21060
|
111 %{!static: \
|
al@21060
|
112 Index: b/gcc/config/sparc/linux.h
|
al@21060
|
113 ===================================================================
|
al@21060
|
114 --- a/gcc/config/sparc/linux.h
|
al@21060
|
115 +++ b/gcc/config/sparc/linux.h
|
al@21060
|
116 @@ -86,7 +86,7 @@ extern const char *host_detect_local_cpu
|
al@21060
|
117 #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
|
al@21060
|
118
|
al@21060
|
119 #undef LINK_SPEC
|
al@21060
|
120 -#define LINK_SPEC "-m elf32_sparc %{shared:-shared} \
|
al@21060
|
121 +#define LINK_SPEC "-m elf32_sparc --as-needed %{shared:-shared} \
|
al@21060
|
122 %{!mno-relax:%{!r:-relax}} \
|
al@21060
|
123 %{!shared: \
|
al@21060
|
124 %{!static: \
|
al@21060
|
125 Index: b/gcc/config/s390/linux.h
|
al@21060
|
126 ===================================================================
|
al@21060
|
127 --- a/gcc/config/s390/linux.h
|
al@21060
|
128 +++ b/gcc/config/s390/linux.h
|
al@21060
|
129 @@ -78,7 +78,7 @@ along with GCC; see the file COPYING3.
|
al@21060
|
130
|
al@21060
|
131 #undef LINK_SPEC
|
al@21060
|
132 #define LINK_SPEC \
|
al@21060
|
133 - "%{m31:-m elf_s390}%{m64:-m elf64_s390} \
|
al@21060
|
134 + "%{m31:-m elf_s390}%{m64:-m elf64_s390} --as-needed \
|
al@21060
|
135 %{shared:-shared} \
|
al@21060
|
136 %{!shared: \
|
al@21060
|
137 %{static:-static} \
|
al@21060
|
138 Index: b/gcc/config/rs6000/linux64.h
|
al@21060
|
139 ===================================================================
|
al@21060
|
140 --- a/gcc/config/rs6000/linux64.h
|
al@21060
|
141 +++ b/gcc/config/rs6000/linux64.h
|
al@21060
|
142 @@ -490,13 +490,13 @@ extern int dot_symbols;
|
al@21060
|
143 " -m elf64ppc")
|
al@21060
|
144 #endif
|
al@21060
|
145
|
al@21060
|
146 -#define LINK_OS_LINUX_SPEC32 LINK_OS_LINUX_EMUL32 " %{!shared: %{!static: \
|
al@21060
|
147 +#define LINK_OS_LINUX_SPEC32 LINK_OS_LINUX_EMUL32 " --as-needed %{!shared: %{!static: \
|
al@21060
|
148 %{!static-pie: \
|
al@21060
|
149 %{rdynamic:-export-dynamic} \
|
al@21060
|
150 -dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "}}} \
|
al@21060
|
151 %(link_os_extra_spec32)"
|
al@21060
|
152
|
al@21060
|
153 -#define LINK_OS_LINUX_SPEC64 LINK_OS_LINUX_EMUL64 " %{!shared: %{!static: \
|
al@21060
|
154 +#define LINK_OS_LINUX_SPEC64 LINK_OS_LINUX_EMUL64 " --as-needed %{!shared: %{!static: \
|
al@21060
|
155 %{!static-pie: \
|
al@21060
|
156 %{rdynamic:-export-dynamic} \
|
al@21060
|
157 -dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "}}} \
|
al@21060
|
158 Index: b/gcc/config/rs6000/sysv4.h
|
al@21060
|
159 ===================================================================
|
al@21060
|
160 --- a/gcc/config/rs6000/sysv4.h
|
al@21060
|
161 +++ b/gcc/config/rs6000/sysv4.h
|
al@21060
|
162 @@ -811,7 +811,7 @@ ENDIAN_SELECT(" -mbig", " -mlittle", DEF
|
al@21060
|
163 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, \
|
al@21060
|
164 MUSL_DYNAMIC_LINKER)
|
al@21060
|
165
|
al@21060
|
166 -#define LINK_OS_LINUX_SPEC "-m elf32ppclinux %{!shared: %{!static: \
|
al@21060
|
167 +#define LINK_OS_LINUX_SPEC "-m elf32ppclinux --as-needed %{!shared: %{!static: \
|
al@21060
|
168 %{rdynamic:-export-dynamic} \
|
al@21060
|
169 -dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}"
|
al@21060
|
170
|
al@21060
|
171 Index: b/gcc/config/i386/gnu-user64.h
|
al@21060
|
172 ===================================================================
|
al@21060
|
173 --- a/gcc/config/i386/gnu-user64.h
|
al@21060
|
174 +++ b/gcc/config/i386/gnu-user64.h
|
al@21060
|
175 @@ -56,6 +56,7 @@
|
al@21060
|
176 "%{" SPEC_64 ":-m " GNU_USER_LINK_EMULATION64 "} \
|
al@21060
|
177 %{" SPEC_32 ":-m " GNU_USER_LINK_EMULATION32 "} \
|
al@21060
|
178 %{" SPEC_X32 ":-m " GNU_USER_LINK_EMULATIONX32 "} \
|
al@21060
|
179 + --as-needed \
|
al@21060
|
180 %{shared:-shared} \
|
al@21060
|
181 %{!shared: \
|
al@21060
|
182 %{!static: \
|
al@21060
|
183 Index: b/gcc/config/i386/gnu-user.h
|
al@21060
|
184 ===================================================================
|
al@21060
|
185 --- a/gcc/config/i386/gnu-user.h
|
al@21060
|
186 +++ b/gcc/config/i386/gnu-user.h
|
al@21060
|
187 @@ -74,7 +74,7 @@ along with GCC; see the file COPYING3.
|
al@21060
|
188 { "link_emulation", GNU_USER_LINK_EMULATION },\
|
al@21060
|
189 { "dynamic_linker", GNU_USER_DYNAMIC_LINKER }
|
al@21060
|
190
|
al@21060
|
191 -#define GNU_USER_TARGET_LINK_SPEC "-m %(link_emulation) %{shared:-shared} \
|
al@21060
|
192 +#define GNU_USER_TARGET_LINK_SPEC "-m %(link_emulation) --as-needed %{shared:-shared} \
|
al@21060
|
193 %{!shared: \
|
al@21060
|
194 %{!static: \
|
al@21060
|
195 %{!static-pie: \
|
al@21060
|
196 Index: b/gcc/config/alpha/linux-elf.h
|
al@21060
|
197 ===================================================================
|
al@21060
|
198 --- a/gcc/config/alpha/linux-elf.h
|
al@21060
|
199 +++ b/gcc/config/alpha/linux-elf.h
|
al@21060
|
200 @@ -37,7 +37,7 @@ along with GCC; see the file COPYING3.
|
al@21060
|
201
|
al@21060
|
202 #define ELF_DYNAMIC_LINKER GNU_USER_DYNAMIC_LINKER
|
al@21060
|
203
|
al@21060
|
204 -#define LINK_SPEC "-m elf64alpha %{G*} %{relax:-relax} \
|
al@21060
|
205 +#define LINK_SPEC "-m elf64alpha --as-needed %{G*} %{relax:-relax} \
|
al@21060
|
206 %{O*:-O3} %{!O*:-O1} \
|
al@21060
|
207 %{shared:-shared} \
|
al@21060
|
208 %{!shared: \
|
al@21060
|
209 Index: b/gcc/config/arm/linux-elf.h
|
al@21060
|
210 ===================================================================
|
al@21060
|
211 --- a/gcc/config/arm/linux-elf.h
|
al@21060
|
212 +++ b/gcc/config/arm/linux-elf.h
|
al@21060
|
213 @@ -70,6 +70,7 @@
|
al@21060
|
214 %{rdynamic:-export-dynamic} \
|
al@21060
|
215 %{!shared:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}} \
|
al@21060
|
216 -X \
|
al@21060
|
217 + --as-needed \
|
al@21060
|
218 %{mbig-endian:-EB} %{mlittle-endian:-EL}" \
|
al@21060
|
219 SUBTARGET_EXTRA_LINK_SPEC
|
al@21060
|
220
|
al@21060
|
221 Index: b/gcc/config/mips/gnu-user.h
|
al@21060
|
222 ===================================================================
|
al@21060
|
223 --- a/gcc/config/mips/gnu-user.h
|
al@21060
|
224 +++ b/gcc/config/mips/gnu-user.h
|
al@21060
|
225 @@ -55,6 +55,7 @@ along with GCC; see the file COPYING3.
|
al@21060
|
226 #undef GNU_USER_TARGET_LINK_SPEC
|
al@21060
|
227 #define GNU_USER_TARGET_LINK_SPEC "\
|
al@21060
|
228 %{G*} %{EB} %{EL} %{mips*} %{shared} \
|
al@21060
|
229 + -as-needed \
|
al@21060
|
230 %{!shared: \
|
al@21060
|
231 %{!static: \
|
al@21060
|
232 %{rdynamic:-export-dynamic} \
|
al@21060
|
233 Index: b/gcc/config/riscv/linux.h
|
al@21060
|
234 ===================================================================
|
al@21060
|
235 --- a/gcc/config/riscv/linux.h
|
al@21060
|
236 +++ b/gcc/config/riscv/linux.h
|
al@21060
|
237 @@ -50,6 +50,7 @@
|
al@21060
|
238 #define CPP_SPEC "%{pthread:-D_REENTRANT}"
|
al@21060
|
239
|
al@21060
|
240 #define LINK_SPEC "\
|
al@21060
|
241 +-as-needed \
|
al@21060
|
242 -melf" XLEN_SPEC "lriscv \
|
al@21060
|
243 %{mno-relax:--no-relax} \
|
al@21060
|
244 %{shared} \
|