[PATCH] ld/elf: Ignore section symbols when matching linkonce with comdat

H.J. Lu hjl.tools@gmail.com
Sat Jan 16 23:51:24 GMT 2021


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 decision.

This patch applies to both master and 2.36 branch.


H.J.
---
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.
---
 bfd/elflink.c                       |   6 +++++-
 ld/testsuite/ld-i386/i386.exp       |   5 +++++
 ld/testsuite/ld-i386/pr27193.dd     |   5 +++++
 ld/testsuite/ld-i386/pr27193a.o.bz2 | Bin 0 -> 468 bytes
 ld/testsuite/ld-i386/pr27193b.s     |   8 ++++++++
 5 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 ld/testsuite/ld-i386/pr27193.dd
 create mode 100644 ld/testsuite/ld-i386/pr27193a.o.bz2
 create mode 100644 ld/testsuite/ld-i386/pr27193b.s

diff --git a/bfd/elflink.c b/bfd/elflink.c
index 8794864f54c..59a6080f37a 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -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;
 
diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
index f3e62a4151e..0be6b861dab 100644
--- a/ld/testsuite/ld-i386/i386.exp
+++ b/ld/testsuite/ld-i386/i386.exp
@@ -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
index 00000000000..a9ba40bbb7c
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr27193.dd
@@ -0,0 +1,5 @@
+#...
+0+1040 <__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
index 0000000000000000000000000000000000000000..365899db9d58abcbf8e737299a223aa50407e56e
GIT binary patch
literal 468
zcmV;_0W1DOT4*^jL0KkKS<U*Xy8r=xf8YQ9@f~E(ML>7Ojs*Yj-(ac?00aO8NB}?p
z07L);umN?0FiMDRP)(@xo<!3onmr>=Q$~O=OpJpd0QDcL15-w$6vQW@8fm6zMw%K7
zO${1kWE&*WkPH$elx;xC>SzrO00000XaE3c271PG$qOd15}`;w09K>j+GS?(Fg#Et
zDNC=zt1iM9j(#fpHutck6^9(wuN%UFEJX~>q?`!grAZvpt!xM?N04{%VPev9Rh<;7
zUKa6bTf!1SCXx%Wr9|;FB+_+a8n(uU(rqUwNFj!cI+`RoG$I&-OI8I#7FCLcx0YWy
zNwjNC7QEylt>aFK1=~fNJU=;<xhYp?*@Xx<u*CujV-+@v8Y{FSw+HDUQw&(+N_L#_
z16l9wlA7hphDUFGIkt!8u0(u5tz7j82i1&35+uHu{MYxIK;&FGTPispCasm&rRIey
zHO<^q1RNy|8Nr5w2<^ItBjhnoo2>d80-kx)5neGUdINGJ6V|H(C(9{-EQ@0$wK{;p
z9U?j}VfvWtt4mrVUa1iKkS+2QpgKVLQUQj7YWf^96L{9bCbVlhJBFXCd{^?n#oUoj
K6eKf#s&2sVqr?CJ

literal 0
HcmV?d00001

diff --git a/ld/testsuite/ld-i386/pr27193b.s b/ld/testsuite/ld-i386/pr27193b.s
new file mode 100644
index 00000000000..9b27a6f7631
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr27193b.s
@@ -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
-- 
2.29.2



More information about the Binutils mailing list