Strip global symbol defined in discarded section
When a global symbol is defined in COMDAT group, we shouldn't leave an undefined symbol in symbol table when the symbol section is discarded unless there is a reference to the symbol outside of COMDAT group. bfd/ PR ld/17550 * elf-bfd.h (elf_link_hash_entry): Update comments for indx, documenting that indx == -3 if symbol is defined in a discarded section. * elflink.c (elf_link_add_object_symbols): Set indx to -3 if symbol is defined in a discarded section. (elf_link_output_extsym): Strip a global symbol defined in a discarded section. ld/ PR ld/17550 * testsuite/ld-elf/pr17550-1.s: New file. * testsuite/ld-elf/pr17550-2.s: Likewise. * testsuite/ld-elf/pr17550-3.s: Likewise. * testsuite/ld-elf/pr17550-4.s: Likewise. * testsuite/ld-elf/pr17550a.d: Likewise. * testsuite/ld-elf/pr17550b.d: Likewise. * testsuite/ld-elf/pr17550c.d: Likewise. * testsuite/ld-elf/pr17550d.d: Likewise.
This commit is contained in:
parent
030e823caf
commit
97196564c7
12 changed files with 131 additions and 1 deletions
|
@ -1,3 +1,14 @@
|
||||||
|
2016-05-06 H.J. Lu <hongjiu.lu@intel.com>
|
||||||
|
|
||||||
|
PR ld/17550
|
||||||
|
* elf-bfd.h (elf_link_hash_entry): Update comments for indx,
|
||||||
|
documenting that indx == -3 if symbol is defined in a discarded
|
||||||
|
section.
|
||||||
|
* elflink.c (elf_link_add_object_symbols): Set indx to -3 if
|
||||||
|
symbol is defined in a discarded section.
|
||||||
|
(elf_link_output_extsym): Strip a global symbol defined in a
|
||||||
|
discarded section.
|
||||||
|
|
||||||
2016-05-06 H.J. Lu <hongjiu.lu@intel.com>
|
2016-05-06 H.J. Lu <hongjiu.lu@intel.com>
|
||||||
|
|
||||||
* elf32-i386.c (elf_backend_add_symbol_hook): Defined for Intel
|
* elf32-i386.c (elf_backend_add_symbol_hook): Defined for Intel
|
||||||
|
|
|
@ -124,7 +124,8 @@ struct elf_link_hash_entry
|
||||||
struct bfd_link_hash_entry root;
|
struct bfd_link_hash_entry root;
|
||||||
|
|
||||||
/* Symbol index in output file. This is initialized to -1. It is
|
/* Symbol index in output file. This is initialized to -1. It is
|
||||||
set to -2 if the symbol is used by a reloc. */
|
set to -2 if the symbol is used by a reloc. It is set to -3 if
|
||||||
|
this symbol is defined in a discarded section. */
|
||||||
long indx;
|
long indx;
|
||||||
|
|
||||||
/* Symbol index as a dynamic symbol. Initialized to -1, and remains
|
/* Symbol index as a dynamic symbol. Initialized to -1, and remains
|
||||||
|
|
|
@ -4082,6 +4082,7 @@ error_free_dyn:
|
||||||
bfd_boolean old_weak;
|
bfd_boolean old_weak;
|
||||||
bfd_boolean override;
|
bfd_boolean override;
|
||||||
bfd_boolean common;
|
bfd_boolean common;
|
||||||
|
bfd_boolean discarded;
|
||||||
unsigned int old_alignment;
|
unsigned int old_alignment;
|
||||||
bfd *old_bfd;
|
bfd *old_bfd;
|
||||||
bfd_boolean matched;
|
bfd_boolean matched;
|
||||||
|
@ -4092,6 +4093,7 @@ error_free_dyn:
|
||||||
sec = NULL;
|
sec = NULL;
|
||||||
value = isym->st_value;
|
value = isym->st_value;
|
||||||
common = bed->common_definition (isym);
|
common = bed->common_definition (isym);
|
||||||
|
discarded = FALSE;
|
||||||
|
|
||||||
bind = ELF_ST_BIND (isym->st_info);
|
bind = ELF_ST_BIND (isym->st_info);
|
||||||
switch (bind)
|
switch (bind)
|
||||||
|
@ -4142,6 +4144,7 @@ error_free_dyn:
|
||||||
/* Symbols from discarded section are undefined. We keep
|
/* Symbols from discarded section are undefined. We keep
|
||||||
its visibility. */
|
its visibility. */
|
||||||
sec = bfd_und_section_ptr;
|
sec = bfd_und_section_ptr;
|
||||||
|
discarded = TRUE;
|
||||||
isym->st_shndx = SHN_UNDEF;
|
isym->st_shndx = SHN_UNDEF;
|
||||||
}
|
}
|
||||||
else if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0)
|
else if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0)
|
||||||
|
@ -4385,6 +4388,11 @@ error_free_dyn:
|
||||||
|| h->root.type == bfd_link_hash_warning)
|
|| h->root.type == bfd_link_hash_warning)
|
||||||
h = (struct elf_link_hash_entry *) h->root.u.i.link;
|
h = (struct elf_link_hash_entry *) h->root.u.i.link;
|
||||||
|
|
||||||
|
/* Setting the index to -3 tells elf_link_output_extsym that
|
||||||
|
this symbol is defined in a discarded section. */
|
||||||
|
if (discarded)
|
||||||
|
h->indx = -3;
|
||||||
|
|
||||||
*sym_hash = h;
|
*sym_hash = h;
|
||||||
|
|
||||||
new_weak = (flags & BSF_WEAK) != 0;
|
new_weak = (flags & BSF_WEAK) != 0;
|
||||||
|
@ -9201,6 +9209,10 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Strip a global symbol defined in a discarded section. */
|
||||||
|
if (h->indx == -3)
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We should also warn if a forced local symbol is referenced from
|
/* We should also warn if a forced local symbol is referenced from
|
||||||
|
|
12
ld/ChangeLog
12
ld/ChangeLog
|
@ -1,3 +1,15 @@
|
||||||
|
2016-05-06 H.J. Lu <hongjiu.lu@intel.com>
|
||||||
|
|
||||||
|
PR ld/17550
|
||||||
|
* testsuite/ld-elf/pr17550-1.s: New file.
|
||||||
|
* testsuite/ld-elf/pr17550-2.s: Likewise.
|
||||||
|
* testsuite/ld-elf/pr17550-3.s: Likewise.
|
||||||
|
* testsuite/ld-elf/pr17550-4.s: Likewise.
|
||||||
|
* testsuite/ld-elf/pr17550a.d: Likewise.
|
||||||
|
* testsuite/ld-elf/pr17550b.d: Likewise.
|
||||||
|
* testsuite/ld-elf/pr17550c.d: Likewise.
|
||||||
|
* testsuite/ld-elf/pr17550d.d: Likewise.
|
||||||
|
|
||||||
2016-05-06 Senthil Kumar Selvaraj <senthil_kumar.selvaraj@atmel.com>
|
2016-05-06 Senthil Kumar Selvaraj <senthil_kumar.selvaraj@atmel.com>
|
||||||
|
|
||||||
* ld/testsuite/ld-srec/srec.exp: Mark test as XFAIL for AVR.
|
* ld/testsuite/ld-srec/srec.exp: Mark test as XFAIL for AVR.
|
||||||
|
|
9
ld/testsuite/ld-elf/pr17550-1.s
Normal file
9
ld/testsuite/ld-elf/pr17550-1.s
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
.section .data,"awG",%progbits,foo_group,comdat
|
||||||
|
.dc.a x_alias
|
||||||
|
.type x, %object
|
||||||
|
.p2align 2
|
||||||
|
.size x, 4
|
||||||
|
x:
|
||||||
|
.zero 4
|
||||||
|
.globl x_alias
|
||||||
|
.set x_alias,x
|
6
ld/testsuite/ld-elf/pr17550-2.s
Normal file
6
ld/testsuite/ld-elf/pr17550-2.s
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
.section .data,"awG",%progbits,foo_group,comdat
|
||||||
|
.type x, %object
|
||||||
|
.p2align 2
|
||||||
|
.size x, 4
|
||||||
|
x:
|
||||||
|
.zero 4
|
14
ld/testsuite/ld-elf/pr17550-3.s
Normal file
14
ld/testsuite/ld-elf/pr17550-3.s
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
.data
|
||||||
|
.dc.a y
|
||||||
|
.section .data,"awG",%progbits,foo_group,comdat
|
||||||
|
.type y, %object
|
||||||
|
.size y, 4
|
||||||
|
y:
|
||||||
|
.zero 4
|
||||||
|
.globl x
|
||||||
|
.type x, %object
|
||||||
|
.size x, 4
|
||||||
|
x:
|
||||||
|
.zero 4
|
||||||
|
.globl x_alias
|
||||||
|
.set x_alias,x
|
15
ld/testsuite/ld-elf/pr17550-4.s
Normal file
15
ld/testsuite/ld-elf/pr17550-4.s
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
.data
|
||||||
|
.dc.a y
|
||||||
|
.section .data,"awG",%progbits,foo_group,comdat
|
||||||
|
.globl y
|
||||||
|
.type y, %object
|
||||||
|
.size y, 4
|
||||||
|
y:
|
||||||
|
.zero 4
|
||||||
|
.globl x
|
||||||
|
.type x, %object
|
||||||
|
.size x, 4
|
||||||
|
x:
|
||||||
|
.zero 4
|
||||||
|
.globl x_alias
|
||||||
|
.set x_alias,x
|
14
ld/testsuite/ld-elf/pr17550a.d
Normal file
14
ld/testsuite/ld-elf/pr17550a.d
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#source: pr17550-1.s
|
||||||
|
#source: pr17550-2.s
|
||||||
|
#ld: -r
|
||||||
|
#readelf: -s --wide
|
||||||
|
#notarget: alpha-*-* cr16-*-* crx-*-* d30v-*-* dlx-*-* i960-*-* pj*-*-*
|
||||||
|
# Disabled on alpha because alpha has a different .set directive.
|
||||||
|
# cr16 and crx use non-standard scripts with memory regions, which don't
|
||||||
|
# play well with comdat group sections under ld -r. Generic linker
|
||||||
|
# targets don't support comdat group sections.
|
||||||
|
|
||||||
|
#failif
|
||||||
|
#...
|
||||||
|
+[0-9]+: +[0-9a-f]+ +0 +OBJECT +GLOBAL +DEFAULT +UND x_alias
|
||||||
|
#...
|
14
ld/testsuite/ld-elf/pr17550b.d
Normal file
14
ld/testsuite/ld-elf/pr17550b.d
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#source: pr17550-2.s
|
||||||
|
#source: pr17550-1.s
|
||||||
|
#ld: -r
|
||||||
|
#readelf: -s --wide
|
||||||
|
#notarget: alpha-*-* cr16-*-* crx-*-* d30v-*-* dlx-*-* i960-*-* pj*-*-*
|
||||||
|
# Disabled on alpha because alpha has a different .set directive.
|
||||||
|
# cr16 and crx use non-standard scripts with memory regions, which don't
|
||||||
|
# play well with comdat group sections under ld -r. Generic linker
|
||||||
|
# targets don't support comdat group sections.
|
||||||
|
|
||||||
|
#failif
|
||||||
|
#...
|
||||||
|
+[0-9]+: +[0-9a-f]+ +0 +OBJECT +GLOBAL +DEFAULT +UND x_alias
|
||||||
|
#...
|
9
ld/testsuite/ld-elf/pr17550c.d
Normal file
9
ld/testsuite/ld-elf/pr17550c.d
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#source: pr17550-2.s
|
||||||
|
#source: pr17550-3.s
|
||||||
|
#ld: -r
|
||||||
|
#error: .*: defined in discarded section `\.data\[foo_group\]'
|
||||||
|
#notarget: alpha-*-* cr16-*-* crx-*-* d30v-*-* dlx-*-* i960-*-* pj*-*-*
|
||||||
|
# Disabled on alpha because alpha has a different .set directive.
|
||||||
|
# cr16 and crx use non-standard scripts with memory regions, which don't
|
||||||
|
# play well with comdat group sections under ld -r. Generic linker
|
||||||
|
# targets don't support comdat group sections.
|
13
ld/testsuite/ld-elf/pr17550d.d
Normal file
13
ld/testsuite/ld-elf/pr17550d.d
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#source: pr17550-2.s
|
||||||
|
#source: pr17550-4.s
|
||||||
|
#ld: -r
|
||||||
|
#readelf: -s --wide
|
||||||
|
#notarget: alpha-*-* cr16-*-* crx-*-* d30v-*-* dlx-*-* i960-*-* pj*-*-*
|
||||||
|
# Disabled on alpha because alpha has a different .set directive.
|
||||||
|
# cr16 and crx use non-standard scripts with memory regions, which don't
|
||||||
|
# play well with comdat group sections under ld -r. Generic linker
|
||||||
|
# targets don't support comdat group sections.
|
||||||
|
|
||||||
|
#...
|
||||||
|
+[0-9]+: +[0-9a-f]+ +0 +OBJECT +GLOBAL +DEFAULT +UND y
|
||||||
|
#pass
|
Loading…
Add table
Add a link
Reference in a new issue