]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
ld/elf: Ignore section symbols when matching linkonce with comdat
authorH.J. Lu <hjl.tools@gmail.com>
Mon, 18 Jan 2021 04:01:16 +0000 (20:01 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Mon, 18 Jan 2021 12:52:55 +0000 (04:52 -0800)
When deciding if a single member comdat group section in file FOO should
be discarded by a linkonce section in file BAR, we check if 2 sections
define the same set of local and global symbols.  When only one of the
files doesn't contain the unused section symbols in the symbol table,
such as object files generated by clang or GNU assembler with

commit d1bcae833b32f1408485ce69f844dcd7ded093a8
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Jan 7 06:42:00 2021 -0800

    ELF: Don't generate unused section symbols

the check will fail since one file has the extra unused section symbols.
We should ignore both undefined and section symbols in the symbol table
when making such a decision.

bfd/

PR ld/27193
* elflink.c (elf_create_symbuf): Also ignore section symbols.

ld/

PR ld/27193
* testsuite/ld-i386/i386.exp: Run PR ld/27193 test.
* testsuite/ld-i386/pr27193.dd: New file.
* testsuite/ld-i386/pr27193a.o.bz2: Likewise.
* testsuite/ld-i386/pr27193b.s: Likewise.

(cherry picked from commit 994b25132814f4c2be93ce53a616a74139c4cf3c)

bfd/ChangeLog
bfd/elflink.c
ld/ChangeLog
ld/testsuite/ld-i386/i386.exp
ld/testsuite/ld-i386/pr27193.dd [new file with mode: 0644]
ld/testsuite/ld-i386/pr27193a.o.bz2 [new file with mode: 0644]
ld/testsuite/ld-i386/pr27193b.s [new file with mode: 0644]

index 4af18e9bc904bd7aa8b6b165bb047a877f16ef1d..eeb5fb4632f3a50959133891e106aa24692dfed9 100644 (file)
@@ -1,3 +1,8 @@
+2021-01-18  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/27193
+       * elflink.c (elf_create_symbuf): Also ignore section symbols.
+
 2021-01-18  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/23169
index acc959d526a9adecb8314ddfbae560a6922ff080..27564adb8c3d95eb071d87015d49a4c4c0154c35 100644 (file)
@@ -8126,8 +8126,12 @@ elf_create_symbuf (size_t symcount, Elf_Internal_Sym *isymbuf)
   if (indbuf == NULL)
     return NULL;
 
+  /* NB: When checking if 2 sections define the same set of local and
+     global symbols, ignore both undefined and section symbols in the
+     symbol table.  */
   for (ind = indbuf, i = 0; i < symcount; i++)
-    if (isymbuf[i].st_shndx != SHN_UNDEF)
+    if (isymbuf[i].st_shndx != SHN_UNDEF
+       && ELF_ST_TYPE (isymbuf[i].st_info) != STT_SECTION)
       *ind++ = &isymbuf[i];
   indbufend = ind;
 
index 6bd5477229d6e78e47589fbb17b60f51053fa9b6..6b437fed2438262b137b96745f1653e661129c61 100644 (file)
@@ -1,3 +1,11 @@
+2021-01-18  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/27193
+       * testsuite/ld-i386/i386.exp: Run PR ld/27193 test.
+       * testsuite/ld-i386/pr27193.dd: New file.
+       * testsuite/ld-i386/pr27193a.o.bz2: Likewise.
+       * testsuite/ld-i386/pr27193b.s: Likewise.
+
 2021-01-18  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/23169
index 655f83df53afc12e3d56eca2aa04b3d537fbd9d5..9bfc70c9fb9d3da17054ca3960977c507bc56e10 100644 (file)
@@ -245,6 +245,11 @@ set i386tests {
      "-melf_i386 -shared -Bsymbolic -z notext" ""
      "--32 -mx86-used-note=yes"
      { pr19827a.S }  {{readelf {-rW} pr19827.rd}} "pr19827.so"}
+    {"Build pr27193.so"
+     "-melf_i386 -shared" ""
+     "--32"
+     { pr27193a.o.bz2 pr27193b.s }
+     {{objdump {-dw} pr27193.dd}} "pr27193.so"}
 }
 
 proc iamcu_tests {} {
diff --git a/ld/testsuite/ld-i386/pr27193.dd b/ld/testsuite/ld-i386/pr27193.dd
new file mode 100644 (file)
index 0000000..7d1e799
--- /dev/null
@@ -0,0 +1,5 @@
+#...
+0+[a-f0-9]+ <__x86.get_pc_thunk.bx>:
+ +[a-f0-9]+:   8b 1c 24                mov    \(%esp\),%ebx
+ +[a-f0-9]+:   c3                      ret    
+#pass
diff --git a/ld/testsuite/ld-i386/pr27193a.o.bz2 b/ld/testsuite/ld-i386/pr27193a.o.bz2
new file mode 100644 (file)
index 0000000..365899d
Binary files /dev/null and b/ld/testsuite/ld-i386/pr27193a.o.bz2 differ
diff --git a/ld/testsuite/ld-i386/pr27193b.s b/ld/testsuite/ld-i386/pr27193b.s
new file mode 100644 (file)
index 0000000..9b27a6f
--- /dev/null
@@ -0,0 +1,8 @@
+        .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
+       .p2align 4
+__x86.get_pc_thunk.bx:
+       mov     (%esp),%ebx
+       ret