[PATCH] D28430: ELF: Implement support for .gnu.linkonce.t.*.
Peter Collingbourne via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 6 18:49:15 PST 2017
pcc created this revision.
pcc added reviewers: rafael, ruiu.
pcc added subscribers: llvm-commits, eugenis, grimar.
The linkonce feature is a sort of proto-comdat. bfd and gold appear to
treat linkonce sections as if they were single-element comdat groups named
after the section name suffix (which means they can cause comdat groups to
be discarded), and this feature is necessary to link parts of the x86-32
CRT on Linux.
We only need support for .gnu.linkonce.t.* for the CRT (and I cannot find
any other uses of linkonce in the x86-32 prebuilt libraries on my system),
so this patch does only that.
Fixes PR31215.
https://reviews.llvm.org/D28430
Files:
lld/ELF/InputFiles.cpp
lld/ELF/InputFiles.h
lld/test/ELF/comdat-linkonce.s
Index: lld/test/ELF/comdat-linkonce.s
===================================================================
--- /dev/null
+++ lld/test/ELF/comdat-linkonce.s
@@ -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
Index: lld/ELF/InputFiles.h
===================================================================
--- lld/ELF/InputFiles.h
+++ lld/ELF/InputFiles.h
@@ -184,8 +184,9 @@
void initializeSymbols();
void initializeDwarfLine();
InputSectionBase<ELFT> *getRelocTarget(const Elf_Shdr &Sec);
- InputSectionBase<ELFT> *createInputSection(const Elf_Shdr &Sec,
- StringRef SectionStringTable);
+ InputSectionBase<ELFT> *
+ createInputSection(const Elf_Shdr &Sec, StringRef SectionStringTable,
+ llvm::DenseSet<llvm::CachedHashStringRef> &ComdatGroups);
bool shouldMerge(const Elf_Shdr &Sec);
SymbolBody *createSymbolBody(const Elf_Sym *Sym);
Index: lld/ELF/InputFiles.cpp
===================================================================
--- lld/ELF/InputFiles.cpp
+++ lld/ELF/InputFiles.cpp
@@ -294,7 +294,7 @@
case SHT_NULL:
break;
default:
- Sections[I] = createInputSection(Sec, SectionStringTable);
+ Sections[I] = createInputSection(Sec, SectionStringTable, ComdatGroups);
}
// .ARM.exidx sections have a reverse dependency on the InputSection they
@@ -329,12 +329,11 @@
}
template <class ELFT>
-InputSectionBase<ELFT> *
-elf::ObjectFile<ELFT>::createInputSection(const Elf_Shdr &Sec,
- StringRef SectionStringTable) {
+InputSectionBase<ELFT> *elf::ObjectFile<ELFT>::createInputSection(
+ const Elf_Shdr &Sec, StringRef SectionStringTable,
+ DenseSet<CachedHashStringRef> &ComdatGroups) {
StringRef Name =
check(this->getObj().getSectionName(&Sec, SectionStringTable));
-
switch (Sec.sh_type) {
case SHT_ARM_ATTRIBUTES:
// FIXME: ARM meta-data section. Retain the first attribute section
@@ -399,6 +398,15 @@
if (Config->Strip != StripPolicy::None && Name.startswith(".debug"))
return &InputSection<ELFT>::Discarded;
+ // The linkonce feature is a sort of proto-comdat. bfd and gold appear to
+ // treat linkonce sections as if they were single-element comdat groups named
+ // after the section name suffix (which means they can cause comdat groups to
+ // be discarded), and this feature is necessary to link parts of the x86-32
+ // CRT on Linux.
+ if (Name.startswith(".gnu.linkonce.t.") &&
+ !ComdatGroups.insert(CachedHashStringRef(Name.substr(16))).second)
+ 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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28430.83485.patch
Type: text/x-patch
Size: 3088 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170107/b74393ef/attachment.bin>
More information about the llvm-commits
mailing list