Index: ELF/SymbolTable.cpp =================================================================== --- ELF/SymbolTable.cpp +++ ELF/SymbolTable.cpp @@ -372,26 +372,29 @@ error(Msg); } -static void reportDuplicate(SymbolBody *Existing, InputFile *NewFile) { +static void reportConflict(SymbolBody *Existing, InputFile *NewFile) { print("duplicate symbol " + conflictMsg(Existing, NewFile)); } +// Print out an error message, e.g. +// +// foo.o (.text+0x100): duplicate symbol 'foobar' +// bar.o (.text+0x250): previous definition was here +// +// Unlike non-regular symbols, we may be able to use DWARF debug info to +// get the precise error location to print out a user-friendly error message. +// So, we have a separate function for regular symbols created from ELF. template -static void reportDuplicate(SymbolBody *Existing, - InputSectionBase *ErrSec, - typename ELFT::uint ErrOffset) { - DefinedRegular *D = dyn_cast>(Existing); - if (!D || !D->Section || !ErrSec) { - reportDuplicate(Existing, ErrSec ? ErrSec->getFile() : nullptr); - return; - } - - std::string OldLoc = getLocation(*D->Section, D->Value); - std::string NewLoc = getLocation(*ErrSec, ErrOffset); +static void reportConflictRegular(SymbolBody *Existing, + InputSectionBase *ErrSec, + typename ELFT::uint ErrOffset) { + print(getLocation(*ErrSec, ErrOffset) + ": duplicate symbol '" + + maybeDemangle(Existing->getName()) + "'"); - print(NewLoc + ": duplicate symbol '" + maybeDemangle(Existing->getName()) + - "'"); - print(OldLoc + ": previous definition was here"); + if (auto *D = dyn_cast>(Existing)) + if (D->Section) + print(getLocation(*D->Section, D->Value) + + ": previous definition was here"); } template @@ -416,7 +419,7 @@ replaceBody>(S, Name, StOther, Type, Value, Size, Section); else if (Cmp == 0) - reportDuplicate(S->body(), Section, Value); + reportConflictRegular(S->body(), Section, Value); return S; } @@ -440,7 +443,7 @@ if (Cmp > 0) replaceBody>(S, N, Value, Section); else if (Cmp == 0) - reportDuplicate(S->body(), nullptr); + reportConflict(S->body(), nullptr); return S; } @@ -477,7 +480,7 @@ if (Cmp > 0) replaceBody>(S, Name, StOther, Type, F); else if (Cmp == 0) - reportDuplicate(S->body(), F); + reportConflict(S->body(), F); return S; }