summaryrefslogtreecommitdiffstats
path: root/lld/COFF/Symbols.cpp
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2016-12-07 23:17:02 +0000
committerRui Ueyama <ruiu@google.com>2016-12-07 23:17:02 +0000
commita45d45e231a6ef811c75f4da8edb8b81cdca2841 (patch)
treedaf7c64d731b6a3bf750a524d0dbeef68b7b17b5 /lld/COFF/Symbols.cpp
parentd5b21b24189bc8258d3b495ae001bfdd0a6f9d03 (diff)
downloadbcm5719-llvm-a45d45e231a6ef811c75f4da8edb8b81cdca2841.tar.gz
bcm5719-llvm-a45d45e231a6ef811c75f4da8edb8b81cdca2841.zip
COFF: Define overloaded toString functions.
Previously, we had different way to stringize SymbolBody and InputFile to construct error messages. This patch defines overloaded function toString() so that we don't need to memorize all these different function names. With that change, it is now easy to include demangled names in error messages. Now, if there is a symbol name conflict, we'll print out both mangled and demangled names. llvm-svn: 288992
Diffstat (limited to 'lld/COFF/Symbols.cpp')
-rw-r--r--lld/COFF/Symbols.cpp35
1 files changed, 21 insertions, 14 deletions
diff --git a/lld/COFF/Symbols.cpp b/lld/COFF/Symbols.cpp
index 6e2db6631ce..56458623134 100644
--- a/lld/COFF/Symbols.cpp
+++ b/lld/COFF/Symbols.cpp
@@ -7,13 +7,15 @@
//
//===----------------------------------------------------------------------===//
+#include "Symbols.h"
#include "Error.h"
#include "InputFiles.h"
-#include "Symbols.h"
+#include "Strings.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
+using namespace llvm;
using namespace llvm::object;
using llvm::sys::fs::identify_magic;
using llvm::sys::fs::file_magic;
@@ -36,6 +38,16 @@ StringRef SymbolBody::getName() {
return Name;
}
+InputFile *SymbolBody::getFile() {
+ if (auto *Sym = dyn_cast<DefinedCOFF>(this))
+ return Sym->File;
+ if (auto *Sym = dyn_cast<DefinedBitcode>(this))
+ return Sym->File;
+ if (auto *Sym = dyn_cast<Lazy>(this))
+ return Sym->File;
+ return nullptr;
+}
+
// Returns 1, 0 or -1 if this symbol should take precedence
// over the Other, tie or lose, respectively.
int SymbolBody::compare(SymbolBody *Other) {
@@ -150,18 +162,6 @@ int SymbolBody::compare(SymbolBody *Other) {
llvm_unreachable("unknown symbol kind");
}
-std::string SymbolBody::getDebugName() {
- std::string N = getName().str();
- if (auto *D = dyn_cast<DefinedCOFF>(this)) {
- N += " ";
- N += D->File->getShortName();
- } else if (auto *D = dyn_cast<DefinedBitcode>(this)) {
- N += " ";
- N += D->File->getShortName();
- }
- return N;
-}
-
COFFSymbolRef DefinedCOFF::getCOFFSymbol() {
size_t SymSize = File->getCOFFObj()->getSymbolTableEntrySize();
if (SymSize == sizeof(coff_symbol16))
@@ -201,7 +201,7 @@ std::unique_ptr<InputFile> Lazy::getMember() {
else
fatal("unknown file type: " + File->getName());
- Obj->setParentName(File->getName());
+ Obj->ParentName = File->getName();
return Obj;
}
@@ -213,5 +213,12 @@ Defined *Undefined::getWeakAlias() {
return nullptr;
}
+// Returns a symbol name for an error message.
+std::string toString(SymbolBody &B) {
+ if (Optional<std::string> S = demangle(B.getName()))
+ return ("\"" + *S + "\" (" + B.getName() + ")").str();
+ return B.getName();
+}
+
} // namespace coff
} // namespace lld
OpenPOWER on IntegriCloud