Skip to content

Commit 94d401b

Browse files
committed
ld: Set non_ir_ref_regular for --undefined SYMBOL
Set non_ir_ref_regular to TRUE for symbols forced into the output file so that they won't be removed by garbage collection with LTO. PR ld/23309 * ldlang.c (insert_undefined): Set non_ir_ref_regular to TRUE. * plugin.c (is_visible_from_outside): Don't scan entry_symbol. * testsuite/ld-plugin/pr23309.c: New file. * testsuite/ld-plugin/pr23309.d: Likewise.
1 parent b14b7ff commit 94d401b

File tree

6 files changed

+26
-7
lines changed

6 files changed

+26
-7
lines changed

ld/ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2018-07-04 H.J. Lu <[email protected]>
2+
3+
PR ld/23309
4+
* ldlang.c (insert_undefined): Set non_ir_ref_regular to TRUE.
5+
* plugin.c (is_visible_from_outside): Don't scan entry_symbol.
6+
* testsuite/ld-plugin/pr23309.c: New file.
7+
* testsuite/ld-plugin/pr23309.d: Likewise.
8+
19
2018-07-04 H.J. Lu <[email protected]>
210

311
PR ld/23358

ld/ldlang.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3413,6 +3413,7 @@ insert_undefined (const char *name)
34133413
{
34143414
h->type = bfd_link_hash_undefined;
34153415
h->u.undef.abfd = NULL;
3416+
h->non_ir_ref_regular = TRUE;
34163417
if (is_elf_hash_table (link_info.hash))
34173418
((struct elf_link_hash_entry *) h)->mark = 1;
34183419
bfd_link_add_undef (link_info.hash, h);

ld/plugin.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,6 @@ static inline bfd_boolean
625625
is_visible_from_outside (struct ld_plugin_symbol *lsym,
626626
struct bfd_link_hash_entry *blhe)
627627
{
628-
struct bfd_sym_chain *sym;
629-
630628
if (bfd_link_relocatable (&link_info))
631629
return TRUE;
632630
if (blhe->non_ir_ref_dynamic
@@ -658,11 +656,6 @@ is_visible_from_outside (struct ld_plugin_symbol *lsym,
658656
|| lsym->visibility == LDPV_PROTECTED);
659657
}
660658

661-
for (sym = &entry_symbol; sym != NULL; sym = sym->next)
662-
if (sym->name
663-
&& strcmp (sym->name, blhe->root.string) == 0)
664-
return TRUE;
665-
666659
return FALSE;
667660
}
668661

ld/testsuite/ld-plugin/lto.exp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ set lto_compile_elf_tests [list \
242242
[list "Compile 8b" \
243243
"" "-flto -O2" \
244244
{lto-8b.c} {} ""] \
245+
[list "PR ld/23309" \
246+
"-O2 -flto -fuse-linker-plugin -fvisibility=hidden -ffunction-sections -Wl,--gc-sections,-u,KeepMe" \
247+
"-O2 -flto -fuse-linker-plugin -fvisibility=hidden -ffunction-sections" \
248+
{pr23309.c} {{"nm" {} "pr23309.d"}} "pr23309.exe" "c"] \
245249
]
246250

247251
# Generate input files for complex LTO tests for ELF.

ld/testsuite/ld-plugin/pr23309.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
int
2+
main (void)
3+
{
4+
return 0;
5+
}
6+
7+
void
8+
KeepMe (void)
9+
{
10+
}

ld/testsuite/ld-plugin/pr23309.d

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#...
2+
[0-9a-f]+ . _?KeepMe
3+
#pass

0 commit comments

Comments
 (0)