Skip to content

Commit d1851ed

Browse files
committed
binutils: Don't complain plugin with all LTO sections removed
When all LTO sections have been removed, the BFD lto_type is set to lto_non_ir_object by bfd_set_lto_type. In this case, don't complain needing a plugin when seeing a LTO slim symbol. bfd/ PR binutils/32967 * archive.c (_bfd_compute_and_write_armap): Call bfd_lto_slim_symbol_p to check LTO slim symbol. * bfd-in2.h: Generated. * bfd.c (bfd_lto_slim_symbol_p): New. binutils/ PR binutils/32967 * nm.c (filter_symbols): Call bfd_lto_slim_symbol_p to check LTO slim symbol. ld/ PR binutils/32967 * testsuite/ld-plugin/lto-binutils.exp: Run PR binutils/32967 tests. * testsuite/ld-plugin/strip-1a-s-all.nd: New file. Signed-off-by: H.J. Lu <[email protected]>
1 parent 11e2fe8 commit d1851ed

File tree

6 files changed

+45
-10
lines changed

6 files changed

+45
-10
lines changed

bfd/archive.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2399,12 +2399,8 @@ _bfd_compute_and_write_armap (bfd *arch, unsigned int elength)
23992399
map = new_map;
24002400
}
24012401

2402-
if (syms[src_count]->name != NULL
2403-
&& syms[src_count]->name[0] == '_'
2404-
&& syms[src_count]->name[1] == '_'
2405-
&& strcmp (syms[src_count]->name
2406-
+ (syms[src_count]->name[2] == '_'),
2407-
"__gnu_lto_slim") == 0
2402+
if (bfd_lto_slim_symbol_p (current,
2403+
syms[src_count]->name)
24082404
&& report_plugin_err)
24092405
{
24102406
report_plugin_err = false;

bfd/bfd-in2.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,6 +2302,16 @@ bfd_get_lto_type (const bfd *abfd)
23022302
return abfd->lto_type;
23032303
}
23042304

2305+
static inline bool
2306+
bfd_lto_slim_symbol_p (const bfd *abfd, const char *name)
2307+
{
2308+
return (bfd_get_lto_type (abfd) != lto_non_ir_object
2309+
&& name != NULL
2310+
&& name[0] == '_'
2311+
&& name[1] == '_'
2312+
&& strcmp (name + (name[2] == '_'), "__gnu_lto_slim") == 0);
2313+
}
2314+
23052315
static inline flagword
23062316
bfd_get_file_flags (const bfd *abfd)
23072317
{

bfd/bfd.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,16 @@ EXTERNAL
470470
. return abfd->lto_type;
471471
.}
472472
.
473+
.static inline bool
474+
.bfd_lto_slim_symbol_p (const bfd *abfd, const char *name)
475+
.{
476+
. return (bfd_get_lto_type (abfd) != lto_non_ir_object
477+
. && name != NULL
478+
. && name[0] == '_'
479+
. && name[1] == '_'
480+
. && strcmp (name + (name[2] == '_'), "__gnu_lto_slim") == 0);
481+
.}
482+
.
473483
.static inline flagword
474484
.bfd_get_file_flags (const bfd *abfd)
475485
.{

binutils/nm.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -801,10 +801,7 @@ filter_symbols (bfd *abfd, bool is_dynamic, void *minisyms,
801801
if (sym == NULL)
802802
continue;
803803

804-
if (sym->name != NULL
805-
&& sym->name[0] == '_'
806-
&& sym->name[1] == '_'
807-
&& strcmp (sym->name + (sym->name[2] == '_'), "__gnu_lto_slim") == 0
804+
if (bfd_lto_slim_symbol_p (abfd, sym->name)
808805
&& report_plugin_err)
809806
{
810807
report_plugin_err = false;

ld/testsuite/ld-plugin/lto-binutils.exp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,25 @@ run_lto_binutils_test [list \
255255
] \
256256
]
257257

258+
if { [check_lto_fat_available] } {
259+
run_lto_binutils_test [list \
260+
[list \
261+
"strip" \
262+
"-R .gnu.*lto_* -N __gnu_lto_v1" \
263+
"strip-1a.o" \
264+
"strip-1a-s-all.o" \
265+
{{nm -n strip-1a-s-all.nd}} \
266+
] \
267+
[list \
268+
"strip" \
269+
"-R .gnu.*lto_* -N __gnu_lto_v1" \
270+
"libstrip-1a.a" \
271+
"libstrip-1a-s-all.a" \
272+
{{nm -n strip-1a-s-all.nd}} \
273+
] \
274+
]
275+
}
276+
258277
run_cc_link_tests [list \
259278
[list \
260279
"Build strip-1a (strip-1a.o)" \
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#...
2+
[0-9a-f]* C _?__gnu_lto_slim
3+
#pass

0 commit comments

Comments
 (0)