elf: Get the real kept section

When mixing linkonce and comdat sections, we need to keep searching to
get the real kept section.

bfd/

	PR ld/26936
	* elflink.c (_bfd_elf_check_kept_section): Get the real kept
	section.

ld/

	PR ld/26936
	* testsuite/ld-elf/pr26936.d: New file.
	* testsuite/ld-elf/pr26936a.s: Likewise.
	* testsuite/ld-elf/pr26936b.s: Likewise.
	* testsuite/ld-elf/pr26936c.s: Likewise.
This commit is contained in:
H.J. Lu 2020-11-25 16:14:13 -08:00
parent 93bbe484a4
commit 58349d00f4
7 changed files with 64 additions and 4 deletions

View File

@ -1,3 +1,9 @@
2020-11-25 H.J. Lu <hongjiu.lu@intel.com>
PR ld/26936
* elflink.c (_bfd_elf_check_kept_section): Get the real kept
section.
2020-11-23 Nick Clifton <nickc@redhat.com>
PR 26931

View File

@ -10698,10 +10698,21 @@ _bfd_elf_check_kept_section (asection *sec, struct bfd_link_info *info)
{
if ((kept->flags & SEC_GROUP) != 0)
kept = match_group_member (sec, kept, info);
if (kept != NULL
&& ((sec->rawsize != 0 ? sec->rawsize : sec->size)
!= (kept->rawsize != 0 ? kept->rawsize : kept->size)))
kept = NULL;
if (kept != NULL)
{
if ((sec->rawsize != 0 ? sec->rawsize : sec->size)
!= (kept->rawsize != 0 ? kept->rawsize : kept->size))
kept = NULL;
else
{
/* Get the real kept section. */
asection *next;
for (next = kept->kept_section;
next != NULL;
next = next->kept_section)
kept = next;
}
}
sec->kept_section = kept;
}
return kept;

View File

@ -1,3 +1,11 @@
2020-11-25 H.J. Lu <hongjiu.lu@intel.com>
PR ld/26936
* testsuite/ld-elf/pr26936.d: New file.
* testsuite/ld-elf/pr26936a.s: Likewise.
* testsuite/ld-elf/pr26936b.s: Likewise.
* testsuite/ld-elf/pr26936c.s: Likewise.
2020-11-25 Alan Modra <amodra@gmail.com>
* ldlang.c (lang_output_section_statement_lookup): Change "create"

View File

@ -0,0 +1,12 @@
#source: pr26936a.s
#source: pr26936b.s
#source: pr26936c.s
#as: -g
#ld: -z noseparate-code -Ttext-segment 0x10000 -z max-page-size=0x1000
#readelf: -wL
#...
CU: .*/pr26936c.s:
File name +Line number +Starting address +View +Stmt
pr26936c.s +6 +0x10[0-9a-f][0-9a-f][0-9a-f] +x
#pass

View File

@ -0,0 +1,6 @@
.section .gnu.linkonce.t.__x86.get_pc_thunk.bx,"ax",%progbits
.globl __x86.get_pc_thunk.bx
.hidden __x86.get_pc_thunk.bx
.type __x86.get_pc_thunk.bx, %function
__x86.get_pc_thunk.bx:
.nop

View File

@ -0,0 +1,11 @@
.text
.globl _start
_start:
.type _start, %function
.nop
.section .text.__x86.get_pc_thunk.bx,"axG",%progbits,__x86.get_pc_thunk.bx,comdat
.globl __x86.get_pc_thunk.bx
.hidden __x86.get_pc_thunk.bx
.type __x86.get_pc_thunk.bx, %function
__x86.get_pc_thunk.bx:
.nop

View File

@ -0,0 +1,6 @@
.section .text.__x86.get_pc_thunk.bx,"axG",%progbits,__x86.get_pc_thunk.bx,comdat
.globl __x86.get_pc_thunk.bx
.hidden __x86.get_pc_thunk.bx
.type __x86.get_pc_thunk.bx, %function
__x86.get_pc_thunk.bx:
.nop