[PATCH] D25513: [ELF] - Do not crash on duplicate STT_SECTION symbol.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 12 05:32:50 PDT 2016
grimar created this revision.
grimar added reviewers: ruiu, rafael, davide.
grimar added subscribers: llvm-commits, grimar, evgeny777.
Global symbols of type STT_SECTION has section filed null, because reference
relocation sections, for which we do not create input sections:
- Type: STT_SECTION Section: .rela.text
In case of duplicate symbol lld crashed trying to access nullptr.
https://reviews.llvm.org/D25513
Files:
ELF/InputFiles.cpp
ELF/SymbolTable.cpp
ELF/SymbolTable.h
test/ELF/invalid/report-duplicates.test
Index: test/ELF/invalid/report-duplicates.test
===================================================================
--- test/ELF/invalid/report-duplicates.test
+++ test/ELF/invalid/report-duplicates.test
@@ -0,0 +1,28 @@
+# RUN: yaml2obj %s -o %t.o
+# RUN: not ld.lld %t.o -o %tout 2>&1 | FileCheck %s
+# CHECK: duplicate symbol: in (internal) and {{.*}}.o
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x0000000000000010
+ Content: "00000000"
+ - Name: .rela.text
+ Type: SHT_RELA
+ Link: .symtab
+ AddressAlign: 0x0000000000000008
+ Info: .text
+ Relocations:
+Symbols:
+ Global:
+ - Type: STT_SECTION
+ Section: .rela.text
+ - Type: STT_SECTION
+ Section: .rela.text
Index: ELF/SymbolTable.h
===================================================================
--- ELF/SymbolTable.h
+++ ELF/SymbolTable.h
@@ -63,7 +63,7 @@
uint8_t Type, bool CanOmitFromDynSym, InputFile *File);
Symbol *addRegular(StringRef Name, const Elf_Sym &Sym,
- InputSectionBase<ELFT> *Section);
+ InputSectionBase<ELFT> *Section, InputFile *File);
Symbol *addRegular(StringRef Name, uint8_t Binding, uint8_t StOther);
Symbol *addSynthetic(StringRef N, OutputSectionBase<ELFT> *Section,
uintX_t Value, uint8_t StOther);
Index: ELF/SymbolTable.cpp
===================================================================
--- ELF/SymbolTable.cpp
+++ ELF/SymbolTable.cpp
@@ -378,17 +378,17 @@
template <typename ELFT>
Symbol *SymbolTable<ELFT>::addRegular(StringRef Name, const Elf_Sym &Sym,
- InputSectionBase<ELFT> *Section) {
+ InputSectionBase<ELFT> *Section,
+ InputFile *File) {
Symbol *S;
bool WasInserted;
std::tie(S, WasInserted) = insert(Name, Sym.getType(), Sym.getVisibility(),
- /*CanOmitFromDynSym*/ false,
- Section ? Section->getFile() : nullptr);
+ /*CanOmitFromDynSym*/ false, File);
int Cmp = compareDefinedNonCommon(S, WasInserted, Sym.getBinding());
if (Cmp > 0)
replaceBody<DefinedRegular<ELFT>>(S, Name, Sym, Section);
else if (Cmp == 0)
- reportDuplicate(S->body(), Section->getFile());
+ reportDuplicate(S->body(), File);
return S;
}
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -458,7 +458,7 @@
/*CanOmitFromDynSym*/ false,
this)
->body();
- return elf::Symtab<ELFT>::X->addRegular(Name, *Sym, Sec)->body();
+ return elf::Symtab<ELFT>::X->addRegular(Name, *Sym, Sec, this)->body();
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25513.74366.patch
Type: text/x-patch
Size: 3227 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161012/2a2d3cf1/attachment.bin>
More information about the llvm-commits
mailing list