[lld] r291474 - ELF: Discard .gnu.linkonce.* sections.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 9 12:26:33 PST 2017


Author: pcc
Date: Mon Jan  9 14:26:33 2017
New Revision: 291474

URL: http://llvm.org/viewvc/llvm-project?rev=291474&view=rev
Log:
ELF: Discard .gnu.linkonce.* sections.

The linkonce feature is a sort of proto-comdat. As far as I am aware no
compiler produces linkonce sections anymore, but some glibc i386 object
files contain definitions of symbol "__x86.get_pc_thunk.bx" in linkonce
sections. Drop those sections to avoid duplicate symbol errors.

This is glibc PR20543, we should remove this hack once that has been
fixed for a while.

Fixes PR31215.

Differential Revision: https://reviews.llvm.org/D28430

Added:
    lld/trunk/test/ELF/comdat-linkonce.s
Modified:
    lld/trunk/ELF/InputFiles.cpp

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=291474&r1=291473&r2=291474&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Mon Jan  9 14:26:33 2017
@@ -418,6 +418,14 @@ elf::ObjectFile<ELFT>::createInputSectio
   if (Config->Strip != StripPolicy::None && Name.startswith(".debug"))
     return &InputSection<ELFT>::Discarded;
 
+  // The linkonce feature is a sort of proto-comdat. Some glibc i386 object
+  // files contain definitions of symbol "__x86.get_pc_thunk.bx" in linkonce
+  // sections. Drop those sections to avoid duplicate symbol errors.
+  // FIXME: This is glibc PR20543, we should remove this hack once that has been
+  // fixed for a while.
+  if (Name.startswith(".gnu.linkonce."))
+    return &InputSection<ELFT>::Discarded;
+
   // The linker merges EH (exception handling) frames and creates a
   // .eh_frame_hdr section for runtime. So we handle them with a special
   // class. For relocatable outputs, they are just passed through.

Added: lld/trunk/test/ELF/comdat-linkonce.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/comdat-linkonce.s?rev=291474&view=auto
==============================================================================
--- lld/trunk/test/ELF/comdat-linkonce.s (added)
+++ lld/trunk/test/ELF/comdat-linkonce.s Mon Jan  9 14:26:33 2017
@@ -0,0 +1,9 @@
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/comdat.s -o %t2.o
+// RUN: ld.lld -shared %t.o %t2.o -o %t
+// RUN: ld.lld -shared %t2.o %t.o -o %t
+
+.section .gnu.linkonce.t.zed
+.globl abc
+abc:
+nop




More information about the llvm-commits mailing list