@@ -162,16 +162,16 @@ def _is_compiler_option_supported(repository_ctx, cc, option):
162
162
])
163
163
return result .stderr .find (option ) == - 1
164
164
165
- def _is_linker_option_supported (repository_ctx , cc , option ):
166
- """Checks that `option` is supported by the C compiler . Doesn't %-escape the option."""
165
+ def _is_linker_option_supported (repository_ctx , cc , option , pattern ):
166
+ """Checks that `option` is supported by the C linker . Doesn't %-escape the option."""
167
167
result = repository_ctx .execute ([
168
168
cc ,
169
169
option ,
170
170
"-o" ,
171
171
"/dev/null" ,
172
172
str (repository_ctx .path ("tools/cpp/empty.cc" )),
173
173
])
174
- return result .stderr .find (option ) == - 1
174
+ return result .stderr .find (pattern ) == - 1
175
175
176
176
def _is_gold_supported (repository_ctx , cc ):
177
177
"""Checks that `gold` is supported by the C compiler."""
@@ -193,9 +193,9 @@ def _add_compiler_option_if_supported(repository_ctx, cc, option):
193
193
"""Returns `[option]` if supported, `[]` otherwise. Doesn't %-escape the option."""
194
194
return [option ] if _is_compiler_option_supported (repository_ctx , cc , option ) else []
195
195
196
- def _add_linker_option_if_supported (repository_ctx , cc , option ):
196
+ def _add_linker_option_if_supported (repository_ctx , cc , option , pattern ):
197
197
"""Returns `[option]` if supported, `[]` otherwise. Doesn't %-escape the option."""
198
- return [option ] if _is_linker_option_supported (repository_ctx , cc , option ) else []
198
+ return [option ] if _is_linker_option_supported (repository_ctx , cc , option , pattern ) else []
199
199
200
200
def _get_no_canonical_prefixes_opt (repository_ctx , cc ):
201
201
# If the compiler sometimes rewrites paths in the .d files without symlinks
@@ -270,10 +270,12 @@ def _crosstool_content(repository_ctx, cc, cpu_value, darwin):
270
270
repository_ctx ,
271
271
cc ,
272
272
"-Wl,-no-as-needed" ,
273
+ "-no-as-needed" ,
273
274
) + _add_linker_option_if_supported (
274
275
repository_ctx ,
275
276
cc ,
276
277
"-Wl,-z,relro,-z,now" ,
278
+ "-z,relro,-z,now" ,
277
279
) + (
278
280
[
279
281
"-undefined" ,
@@ -360,7 +362,12 @@ def _opt_content(repository_ctx, cc, darwin):
360
362
"-fdata-sections" ,
361
363
],
362
364
"linker_flag" : (
363
- [] if darwin else _add_linker_option_if_supported (repository_ctx , cc , "-Wl,--gc-sections" )
365
+ [] if darwin else _add_linker_option_if_supported (
366
+ repository_ctx ,
367
+ cc ,
368
+ "-Wl,--gc-sections" ,
369
+ "-gc-sections" ,
370
+ )
364
371
),
365
372
}
366
373
0 commit comments