[lld] r255829 - ELF: Separate error message generation from call of error() or warning().
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 16 14:26:46 PST 2015
Author: ruiu
Date: Wed Dec 16 16:26:45 2015
New Revision: 255829
URL: http://llvm.org/viewvc/llvm-project?rev=255829&view=rev
Log:
ELF: Separate error message generation from call of error() or warning().
Previously reportConflict returned only when the third argument is false.
Now it always returns a value.
Modified:
lld/trunk/ELF/SymbolTable.cpp
lld/trunk/ELF/SymbolTable.h
Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=255829&r1=255828&r2=255829&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Wed Dec 16 16:26:45 2015
@@ -121,14 +121,12 @@ void SymbolTable<ELFT>::addELFFile(ELFFi
}
template <class ELFT>
-void SymbolTable<ELFT>::reportConflict(const Twine &Message,
- const SymbolBody &Old,
- const SymbolBody &New, bool Warning) {
+std::string SymbolTable<ELFT>::conflictMsg(SymbolBody *Old, SymbolBody *New) {
typedef typename ELFFile<ELFT>::Elf_Sym Elf_Sym;
typedef typename ELFFile<ELFT>::Elf_Sym_Range Elf_Sym_Range;
- const Elf_Sym &OldE = cast<ELFSymbolBody<ELFT>>(Old).Sym;
- const Elf_Sym &NewE = cast<ELFSymbolBody<ELFT>>(New).Sym;
+ const Elf_Sym &OldE = cast<ELFSymbolBody<ELFT>>(*Old).Sym;
+ const Elf_Sym &NewE = cast<ELFSymbolBody<ELFT>>(*New).Sym;
ELFFileBase<ELFT> *OldFile = nullptr;
ELFFileBase<ELFT> *NewFile = nullptr;
@@ -140,14 +138,10 @@ void SymbolTable<ELFT>::reportConflict(c
NewFile = File.get();
}
- std::string Msg = (Message + ": " + Old.getName() + " in " +
- (OldFile ? OldFile->getName() : "(internal)") + " and " +
- (NewFile ? NewFile->getName() : "(internal)"))
- .str();
- if (Warning)
- warning(Msg);
- else
- error(Msg);
+ StringRef Sym = Old->getName();
+ StringRef F1 = OldFile ? OldFile->getName() : "(internal)";
+ StringRef F2 = NewFile ? NewFile->getName() : "(internal)";
+ return (Sym + " in " + F1 + " and " + F2).str();
}
// This function resolves conflicts if there's an existing symbol with
@@ -178,16 +172,20 @@ template <class ELFT> void SymbolTable<E
}
if (New->isTLS() != Existing->isTLS())
- reportConflict("TLS attribute mismatch for symbol", *Existing, *New, false);
+ error("TLS attribute mismatch for symbol: " + conflictMsg(Existing, New));
// compare() returns -1, 0, or 1 if the lhs symbol is less preferable,
// equivalent (conflicting), or more preferable, respectively.
int comp = Existing->compare<ELFT>(New);
+ if (comp == 0) {
+ std::string S = "duplicate symbol: " + conflictMsg(Existing, New);
+ if (!Config->AllowMultipleDefinition)
+ error(S);
+ warning(S);
+ return;
+ }
if (comp < 0)
Sym->Body = New;
- else if (comp == 0)
- reportConflict("duplicate symbol", *Existing, *New,
- Config->AllowMultipleDefinition);
}
template <class ELFT> Symbol *SymbolTable<ELFT>::insert(SymbolBody *New) {
Modified: lld/trunk/ELF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=255829&r1=255828&r2=255829&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.h (original)
+++ lld/trunk/ELF/SymbolTable.h Wed Dec 16 16:26:45 2015
@@ -66,8 +66,7 @@ private:
void addMemberFile(Lazy *Body);
void checkCompatibility(std::unique_ptr<InputFile> &File);
void resolve(SymbolBody *Body);
- void reportConflict(const Twine &Message, const SymbolBody &Old,
- const SymbolBody &New, bool Warning);
+ std::string conflictMsg(SymbolBody *Old, SymbolBody *New);
std::vector<std::unique_ptr<InputFile>> ArchiveFiles;
More information about the llvm-commits
mailing list