Index: ELF/InputFiles.cpp =================================================================== --- ELF/InputFiles.cpp +++ ELF/InputFiles.cpp @@ -458,7 +458,7 @@ /*CanOmitFromDynSym*/ false, this) ->body(); - return elf::Symtab::X->addRegular(Name, *Sym, Sec)->body(); + return elf::Symtab::X->addRegular(Name, *Sym, Sec, this)->body(); } } 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 *Section); + InputSectionBase *Section, InputFile *File); Symbol *addRegular(StringRef Name, uint8_t Binding, uint8_t StOther); Symbol *addSynthetic(StringRef N, OutputSectionBase *Section, uintX_t Value, uint8_t StOther); Index: ELF/SymbolTable.cpp =================================================================== --- ELF/SymbolTable.cpp +++ ELF/SymbolTable.cpp @@ -378,17 +378,17 @@ template Symbol *SymbolTable::addRegular(StringRef Name, const Elf_Sym &Sym, - InputSectionBase *Section) { + InputSectionBase *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>(S, Name, Sym, Section); else if (Cmp == 0) - reportDuplicate(S->body(), Section->getFile()); + reportDuplicate(S->body(), File); return S; } 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