[lld] r286244 - [ELF] Better error reporting for duplicate symbol
Eugene Leviant via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 8 08:26:32 PST 2016
Author: evgeny777
Date: Tue Nov 8 10:26:32 2016
New Revision: 286244
URL: http://llvm.org/viewvc/llvm-project?rev=286244&view=rev
Log:
[ELF] Better error reporting for duplicate symbol
Differential revision: https://reviews.llvm.org/D26397
Added:
lld/trunk/test/ELF/Inputs/conflict-debug.s
Modified:
lld/trunk/ELF/Relocations.cpp
lld/trunk/ELF/Relocations.h
lld/trunk/ELF/SymbolTable.cpp
lld/trunk/ELF/SymbolTable.h
lld/trunk/test/ELF/basic.s
lld/trunk/test/ELF/conflict.s
lld/trunk/test/ELF/lto/duplicated.ll
lld/trunk/test/ELF/tls-mismatch.s
Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=286244&r1=286243&r2=286244&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Tue Nov 8 10:26:32 2016
@@ -539,8 +539,8 @@ static DefinedRegular<ELFT> *getSymbolAt
}
template <class ELFT>
-static std::string getLocation(SymbolBody &Sym, InputSectionBase<ELFT> &S,
- typename ELFT::uint Offset) {
+std::string getLocation(SymbolBody *Sym, InputSectionBase<ELFT> &S,
+ typename ELFT::uint Offset) {
ObjectFile<ELFT> *File = S.getFile();
// First check if we can get desired values from debugging information.
@@ -552,7 +552,7 @@ static std::string getLocation(SymbolBod
// use object file name.
std::string SrcFile = File->SourceFile;
if (SrcFile.empty())
- SrcFile = Sym.File ? getFilename(Sym.File) : getFilename(File);
+ SrcFile = Sym && Sym->File ? getFilename(Sym->File) : getFilename(File);
// Find a symbol at a given location.
DefinedRegular<ELFT> *Encl = getSymbolAt(&S, Offset);
@@ -576,7 +576,7 @@ static void reportUndefined(SymbolBody &
Config->UnresolvedSymbols != UnresolvedPolicy::NoUndef)
return;
- std::string Msg = getLocation(Sym, S, Offset) + ": undefined symbol '" +
+ std::string Msg = getLocation(&Sym, S, Offset) + ": undefined symbol '" +
maybeDemangle(Sym.getName()) + "'";
if (Config->UnresolvedSymbols == UnresolvedPolicy::Warn)
@@ -853,5 +853,18 @@ template void createThunks<ELF64LE>(Inpu
const ELF64LE::Shdr &);
template void createThunks<ELF64BE>(InputSectionBase<ELF64BE> &,
const ELF64BE::Shdr &);
+
+template std::string getLocation<ELF32LE>(SymbolBody *Sym,
+ InputSectionBase<ELF32LE> &S,
+ uint32_t Offset);
+template std::string getLocation<ELF32BE>(SymbolBody *Sym,
+ InputSectionBase<ELF32BE> &S,
+ uint32_t Offset);
+template std::string getLocation<ELF64LE>(SymbolBody *Sym,
+ InputSectionBase<ELF64LE> &S,
+ uint64_t Offset);
+template std::string getLocation<ELF64BE>(SymbolBody *Sym,
+ InputSectionBase<ELF64BE> &S,
+ uint64_t Offset);
}
}
Modified: lld/trunk/ELF/Relocations.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.h?rev=286244&r1=286243&r2=286244&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.h (original)
+++ lld/trunk/ELF/Relocations.h Tue Nov 8 10:26:32 2016
@@ -88,6 +88,10 @@ template <class ELFT>
void createThunks(InputSectionBase<ELFT> &, const typename ELFT::Shdr &);
template <class ELFT>
+std::string getLocation(SymbolBody *Sym, InputSectionBase<ELFT> &S,
+ typename ELFT::uint Offset);
+
+template <class ELFT>
static inline typename ELFT::uint getAddend(const typename ELFT::Rel &Rel) {
return 0;
}
Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=286244&r1=286243&r2=286244&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Tue Nov 8 10:26:32 2016
@@ -234,7 +234,7 @@ std::pair<Symbol *, bool> SymbolTable<EL
// Construct a string in the form of "Sym in File1 and File2".
// Used to construct an error message.
static std::string conflictMsg(SymbolBody *Existing, InputFile *NewFile) {
- return maybeDemangle(Existing->getName()) + " in " +
+ return "'" + maybeDemangle(Existing->getName()) + "' in " +
getFilename(Existing->File) + " and " + getFilename(NewFile);
}
@@ -257,7 +257,7 @@ SymbolTable<ELFT>::insert(StringRef &Nam
S->IsUsedInRegularObj = true;
if (!WasInserted && S->body()->Type != SymbolBody::UnknownType &&
((Type == STT_TLS) != S->body()->isTls()))
- error("TLS attribute mismatch for symbol: " + conflictMsg(S->body(), File));
+ error("TLS attribute mismatch for symbol " + conflictMsg(S->body(), File));
return {S, WasInserted};
}
@@ -365,16 +365,35 @@ Symbol *SymbolTable<ELFT>::addCommon(Str
return S;
}
-template <class ELFT>
-void SymbolTable<ELFT>::reportDuplicate(SymbolBody *Existing,
- InputFile *NewFile) {
- std::string Msg = "duplicate symbol: " + conflictMsg(Existing, NewFile);
+static void reportDuplicate(const std::string &Msg) {
if (Config->AllowMultipleDefinition)
warn(Msg);
else
error(Msg);
}
+static void reportDuplicate(SymbolBody *Existing, InputFile *NewFile) {
+ reportDuplicate("duplicate symbol " + conflictMsg(Existing, NewFile));
+}
+
+template <class ELFT>
+static void reportDuplicate(SymbolBody *Existing,
+ InputSectionBase<ELFT> *ErrSec,
+ typename ELFT::uint ErrOffset) {
+ DefinedRegular<ELFT> *D = dyn_cast<DefinedRegular<ELFT>>(Existing);
+ if (!D || !D->Section || !ErrSec) {
+ reportDuplicate(Existing, ErrSec ? ErrSec->getFile() : nullptr);
+ return;
+ }
+
+ std::string OldLoc = getLocation(Existing, *D->Section, D->Value);
+ std::string NewLoc = getLocation(nullptr, *ErrSec, ErrOffset);
+
+ reportDuplicate(NewLoc + ": duplicate symbol '" +
+ maybeDemangle(Existing->getName()) + "'");
+ reportDuplicate(OldLoc + ": previous definition was here");
+}
+
template <typename ELFT>
Symbol *SymbolTable<ELFT>::addRegular(StringRef Name, const Elf_Sym &Sym,
InputSectionBase<ELFT> *Section) {
@@ -397,7 +416,7 @@ Symbol *SymbolTable<ELFT>::addRegular(St
replaceBody<DefinedRegular<ELFT>>(S, Name, StOther, Type, Value, Size,
Section);
else if (Cmp == 0)
- reportDuplicate(S->body(), Section->getFile());
+ reportDuplicate(S->body(), Section, Value);
return S;
}
Modified: lld/trunk/ELF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=286244&r1=286243&r2=286244&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.h (original)
+++ lld/trunk/ELF/SymbolTable.h Tue Nov 8 10:26:32 2016
@@ -100,8 +100,6 @@ private:
uint8_t Visibility, bool CanOmitFromDynSym,
InputFile *File);
- void reportDuplicate(SymbolBody *Existing, InputFile *NewFile);
-
std::map<std::string, std::vector<SymbolBody *>> getDemangledSyms();
void handleAnonymousVersion();
Added: lld/trunk/test/ELF/Inputs/conflict-debug.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/conflict-debug.s?rev=286244&view=auto
==============================================================================
--- lld/trunk/test/ELF/Inputs/conflict-debug.s (added)
+++ lld/trunk/test/ELF/Inputs/conflict-debug.s Tue Nov 8 10:26:32 2016
@@ -0,0 +1,5 @@
+.file 1 "conflict-debug.s"
+.globl zed
+.loc 1 4
+zed:
+ nop
Modified: lld/trunk/test/ELF/basic.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/basic.s?rev=286244&r1=286243&r2=286244&view=diff
==============================================================================
--- lld/trunk/test/ELF/basic.s (original)
+++ lld/trunk/test/ELF/basic.s Tue Nov 8 10:26:32 2016
@@ -221,7 +221,8 @@ _start:
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: not ld.lld %t %t -o %t2 2>&1 | FileCheck --check-prefix=DUP %s
-# DUP: duplicate symbol: _start in {{.*}} and {{.*}}
+# DUP: {{.*}} (.text+0x0): duplicate symbol '_start'
+# DUP: {{.*}} (.text+0x0): previous definition was here
# RUN: not ld.lld %t -o %t -m wrong_emul_fbsd 2>&1 | FileCheck --check-prefix=UNKNOWN_EMUL %s
# UNKNOWN_EMUL: unknown emulation: wrong_emul_fbsd
Modified: lld/trunk/test/ELF/conflict.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/conflict.s?rev=286244&r1=286243&r2=286244&view=diff
==============================================================================
--- lld/trunk/test/ELF/conflict.s (original)
+++ lld/trunk/test/ELF/conflict.s Tue Nov 8 10:26:32 2016
@@ -3,14 +3,18 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o
# RUN: not ld.lld %t1.o %t1.o -o %t2 2>&1 | FileCheck -check-prefix=DEMANGLE %s
-# DEMANGLE: duplicate symbol: mul(double, double) in
-# DEMANGLE: duplicate symbol: foo in
+# DEMANGLE: {{.*}} (.text+0x0): duplicate symbol 'mul(double, double)'
+# DEMANGLE-NEXT: {{.*}} (.text+0x0): previous definition was here
+# DEMANGLE-NEXT: {{.*}} (.text+0x0): duplicate symbol 'foo'
+# DEMANGLE-NEXT: {{.*}} (.text+0x0): previous definition was here
# RUN: not ld.lld %t1.o %t1.o -o %t2 --no-demangle 2>&1 | \
# RUN: FileCheck -check-prefix=NO_DEMANGLE %s
-# NO_DEMANGLE: duplicate symbol: _Z3muldd in
-# NO_DEMANGLE: duplicate symbol: foo in
+# NO_DEMANGLE: {{.*}} (.text+0x0): duplicate symbol '_Z3muldd'
+# NO_DEMANGLE-NEXT: {{.*}} (.text+0x0): previous definition was here
+# NO_DEMANGLE-NEXT: {{.*}} (.text+0x0): duplicate symbol 'foo'
+# NO_DEMANGLE-NEXT: {{.*}} (.text+0x0): previous definition was here
# RUN: not ld.lld %t1.o %t1.o -o %t2 --demangle --no-demangle 2>&1 | \
# RUN: FileCheck -check-prefix=NO_DEMANGLE %s
@@ -21,7 +25,14 @@
# RUN: llvm-ar rcs %t3.a %t2.o
# RUN: not ld.lld %t1.o %t3.a -u baz -o %t2 2>&1 | FileCheck -check-prefix=ARCHIVE %s
-# ARCHIVE: duplicate symbol: foo in {{.*}}1.o and {{.*}}3.a({{.*}}2.o)
+# ARCHIVE: {{.*}}3.a({{.*}}2.o) (.text+0x0): duplicate symbol 'foo'
+# ARCHIVE-NEXT: {{.*}}1.o (.text+0x0): previous definition was here
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/conflict-debug.s -o %t-dbg.o
+# RUN: not ld.lld %t-dbg.o %t-dbg.o -o %t-dbg 2>&1 | FileCheck -check-prefix=DBGINFO %s
+
+# DBGINFO: conflict-debug.s (4): duplicate symbol 'zed'
+# DBGINFO-NEXT: conflict-debug.s (4): previous definition was here
.globl _Z3muldd, foo
_Z3muldd:
Modified: lld/trunk/test/ELF/lto/duplicated.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/duplicated.ll?rev=286244&r1=286243&r2=286244&view=diff
==============================================================================
--- lld/trunk/test/ELF/lto/duplicated.ll (original)
+++ lld/trunk/test/ELF/lto/duplicated.ll Tue Nov 8 10:26:32 2016
@@ -1,7 +1,7 @@
; REQUIRES: x86
; RUN: llvm-as %s -o %t.o
; RUN: not ld.lld -m elf_x86_64 %t.o %t.o -o %t.so -shared 2>&1 | FileCheck %s
-; CHECK: duplicate symbol: f in {{.*}}.o and {{.*}}.o
+; CHECK: duplicate symbol 'f' in {{.*}}.o and {{.*}}.o
target triple = "x86_64-unknown-linux-gnu"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
Modified: lld/trunk/test/ELF/tls-mismatch.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/tls-mismatch.s?rev=286244&r1=286243&r2=286244&view=diff
==============================================================================
--- lld/trunk/test/ELF/tls-mismatch.s (original)
+++ lld/trunk/test/ELF/tls-mismatch.s Tue Nov 8 10:26:32 2016
@@ -2,7 +2,7 @@
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/tls-mismatch.s -o %t2
// RUN: not ld.lld %t %t2 -o %t3 2>&1 | FileCheck %s
-// CHECK: TLS attribute mismatch for symbol: tlsvar
+// CHECK: TLS attribute mismatch for symbol 'tlsvar'
.globl _start,tlsvar
_start:
More information about the llvm-commits
mailing list