[lld] r366573 - lld-link: Demangle symbols from archives in diagnostics
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 19 06:29:10 PDT 2019
Author: nico
Date: Fri Jul 19 06:29:10 2019
New Revision: 366573
URL: http://llvm.org/viewvc/llvm-project?rev=366573&view=rev
Log:
lld-link: Demangle symbols from archives in diagnostics
Also add test coverage for thin archives (which are the only way I could
come up with to test at least some of the diagnostic changes).
Differential Revision: https://reviews.llvm.org/D64927
Added:
lld/trunk/test/COFF/Inputs/mangled-symbol.s
lld/trunk/test/COFF/thin-archive.s
Modified:
lld/trunk/COFF/Driver.cpp
lld/trunk/COFF/Driver.h
lld/trunk/COFF/InputFiles.cpp
lld/trunk/COFF/InputFiles.h
lld/trunk/COFF/SymbolTable.cpp
lld/trunk/COFF/SymbolTable.h
lld/trunk/COFF/Symbols.cpp
lld/trunk/COFF/Symbols.h
Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=366573&r1=366572&r2=366573&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Fri Jul 19 06:29:10 2019
@@ -268,13 +268,12 @@ void LinkerDriver::addArchiveBuffer(Memo
}
void LinkerDriver::enqueueArchiveMember(const Archive::Child &c,
- StringRef symName,
+ const Archive::Symbol &sym,
StringRef parentName) {
- auto reportBufferError = [=](Error &&e,
- StringRef childName) {
+ auto reportBufferError = [=](Error &&e, StringRef childName) {
fatal("could not get the buffer for the member defining symbol " +
- symName + ": " + parentName + "(" + childName + "): " +
+ toString(sym) + ": " + parentName + "(" + childName + "): " +
toString(std::move(e)));
};
@@ -285,7 +284,7 @@ void LinkerDriver::enqueueArchiveMember(
reportBufferError(mbOrErr.takeError(), check(c.getFullName()));
MemoryBufferRef mb = mbOrErr.get();
enqueueTask([=]() {
- driver->addArchiveBuffer(mb, symName, parentName, offsetInArchive);
+ driver->addArchiveBuffer(mb, toString(sym), parentName, offsetInArchive);
});
return;
}
@@ -293,15 +292,15 @@ void LinkerDriver::enqueueArchiveMember(
std::string childName = CHECK(
c.getFullName(),
"could not get the filename for the member defining symbol " +
- symName);
+ toString(sym));
auto future = std::make_shared<std::future<MBErrPair>>(
createFutureForFile(childName));
enqueueTask([=]() {
auto mbOrErr = future->get();
if (mbOrErr.second)
reportBufferError(errorCodeToError(mbOrErr.second), childName);
- driver->addArchiveBuffer(takeBuffer(std::move(mbOrErr.first)), symName,
- parentName, /* OffsetInArchive */ 0);
+ driver->addArchiveBuffer(takeBuffer(std::move(mbOrErr.first)),
+ toString(sym), parentName, /*OffsetInArchive=*/0);
});
}
Modified: lld/trunk/COFF/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.h?rev=366573&r1=366572&r2=366573&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.h (original)
+++ lld/trunk/COFF/Driver.h Fri Jul 19 06:29:10 2019
@@ -72,7 +72,7 @@ public:
void parseDirectives(InputFile *file);
// Used by ArchiveFile to enqueue members.
- void enqueueArchiveMember(const Archive::Child &c, StringRef symName,
+ void enqueueArchiveMember(const Archive::Child &c, const Archive::Symbol &sym,
StringRef parentName);
MemoryBufferRef takeBuffer(std::unique_ptr<MemoryBuffer> mb);
Modified: lld/trunk/COFF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.cpp?rev=366573&r1=366572&r2=366573&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.cpp (original)
+++ lld/trunk/COFF/InputFiles.cpp Fri Jul 19 06:29:10 2019
@@ -85,16 +85,15 @@ void ArchiveFile::parse() {
}
// Returns a buffer pointing to a member file containing a given symbol.
-void ArchiveFile::addMember(const Archive::Symbol *sym) {
- const Archive::Child &c =
- CHECK(sym->getMember(),
- "could not get the member for symbol " + sym->getName());
+void ArchiveFile::addMember(const Archive::Symbol &sym) {
+ const Archive::Child &c = CHECK(
+ sym.getMember(), "could not get the member for symbol " + toString(sym));
// Return an empty buffer if we have already returned the same buffer.
if (!seen.insert(c.getChildOffset()).second)
return;
- driver->enqueueArchiveMember(c, sym->getName(), getName());
+ driver->enqueueArchiveMember(c, sym, getName());
}
std::vector<MemoryBufferRef> getArchiveMembers(Archive *file) {
Modified: lld/trunk/COFF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.h?rev=366573&r1=366572&r2=366573&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.h (original)
+++ lld/trunk/COFF/InputFiles.h Fri Jul 19 06:29:10 2019
@@ -96,7 +96,7 @@ public:
// Enqueues an archive member load for the given symbol. If we've already
// enqueued a load for the same archive member, this function does nothing,
// which ensures that we don't load the same member more than once.
- void addMember(const Archive::Symbol *sym);
+ void addMember(const Archive::Symbol &sym);
private:
std::unique_ptr<Archive> file;
Modified: lld/trunk/COFF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=366573&r1=366572&r2=366573&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.cpp (original)
+++ lld/trunk/COFF/SymbolTable.cpp Fri Jul 19 06:29:10 2019
@@ -179,7 +179,7 @@ void SymbolTable::loadMinGWAutomaticImpo
log("Loading lazy " + l->getName() + " from " + l->file->getName() +
" for automatic import");
l->pendingArchiveLoad = true;
- l->file->addMember(&l->sym);
+ l->file->addMember(l->sym);
}
}
@@ -363,13 +363,13 @@ Symbol *SymbolTable::addUndefined(String
if (auto *l = dyn_cast<Lazy>(s)) {
if (!s->pendingArchiveLoad) {
s->pendingArchiveLoad = true;
- l->file->addMember(&l->sym);
+ l->file->addMember(l->sym);
}
}
return s;
}
-void SymbolTable::addLazy(ArchiveFile *f, const Archive::Symbol sym) {
+void SymbolTable::addLazy(ArchiveFile *f, const Archive::Symbol &sym) {
StringRef name = sym.getName();
Symbol *s;
bool wasInserted;
@@ -382,7 +382,7 @@ void SymbolTable::addLazy(ArchiveFile *f
if (!u || u->weakAlias || s->pendingArchiveLoad)
return;
s->pendingArchiveLoad = true;
- f->addMember(&sym);
+ f->addMember(sym);
}
void SymbolTable::reportDuplicate(Symbol *existing, InputFile *newFile) {
Modified: lld/trunk/COFF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.h?rev=366573&r1=366572&r2=366573&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.h (original)
+++ lld/trunk/COFF/SymbolTable.h Fri Jul 19 06:29:10 2019
@@ -83,7 +83,7 @@ public:
Symbol *addAbsolute(StringRef n, uint64_t va);
Symbol *addUndefined(StringRef name, InputFile *f, bool isWeakAlias);
- void addLazy(ArchiveFile *f, const Archive::Symbol sym);
+ void addLazy(ArchiveFile *f, const Archive::Symbol &sym);
Symbol *addAbsolute(StringRef n, COFFSymbolRef s);
Symbol *addRegular(InputFile *f, StringRef n,
const llvm::object::coff_symbol_generic *s = nullptr,
Modified: lld/trunk/COFF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Symbols.cpp?rev=366573&r1=366572&r2=366573&view=diff
==============================================================================
--- lld/trunk/COFF/Symbols.cpp (original)
+++ lld/trunk/COFF/Symbols.cpp Fri Jul 19 06:29:10 2019
@@ -20,18 +20,21 @@ using namespace llvm::object;
using namespace lld::coff;
+namespace lld {
+
static_assert(sizeof(SymbolUnion) <= 48,
"symbols should be optimized for memory usage");
// Returns a symbol name for an error message.
-std::string lld::toString(coff::Symbol &b) {
+static std::string demangle(StringRef symName) {
if (config->demangle)
- if (Optional<std::string> s = lld::demangleMSVC(b.getName()))
+ if (Optional<std::string> s = demangleMSVC(symName))
return *s;
- return b.getName();
+ return symName;
}
+std::string toString(coff::Symbol &b) { return demangle(b.getName()); }
+std::string toString(const Archive::Symbol &b) { return demangle(b.getName()); }
-namespace lld {
namespace coff {
StringRef Symbol::getName() {
Modified: lld/trunk/COFF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Symbols.h?rev=366573&r1=366572&r2=366573&view=diff
==============================================================================
--- lld/trunk/COFF/Symbols.h (original)
+++ lld/trunk/COFF/Symbols.h Fri Jul 19 06:29:10 2019
@@ -430,6 +430,7 @@ void replaceSymbol(Symbol *s, ArgT &&...
} // namespace coff
std::string toString(coff::Symbol &b);
+std::string toString(const coff::Archive::Symbol &b);
} // namespace lld
#endif
Added: lld/trunk/test/COFF/Inputs/mangled-symbol.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/Inputs/mangled-symbol.s?rev=366573&view=auto
==============================================================================
--- lld/trunk/test/COFF/Inputs/mangled-symbol.s (added)
+++ lld/trunk/test/COFF/Inputs/mangled-symbol.s Fri Jul 19 06:29:10 2019
@@ -0,0 +1,9 @@
+ .text
+
+ .def "?f@@YAHXZ"
+ .scl 2
+ .type 32
+ .endef
+ .global "?f@@YAHXZ"
+"?f@@YAHXZ":
+ retq $0
Added: lld/trunk/test/COFF/thin-archive.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/thin-archive.s?rev=366573&view=auto
==============================================================================
--- lld/trunk/test/COFF/thin-archive.s (added)
+++ lld/trunk/test/COFF/thin-archive.s Fri Jul 19 06:29:10 2019
@@ -0,0 +1,36 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-windows-msvc -o %t.main.obj %s
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-windows-msvc -o %t.lib.obj \
+# RUN: %S/Inputs/mangled-symbol.s
+# RUN: lld-link /lib /out:%t.lib %t.lib.obj
+# RUN: lld-link /lib /llvmlibthin /out:%t_thin.lib %t.lib.obj
+
+# RUN: lld-link /entry:main %t.main.obj %t.lib /out:%t.exe 2>&1 | \
+# RUN: FileCheck --allow-empty %s
+# RUN: lld-link /entry:main %t.main.obj %t_thin.lib /out:%t.exe 2>&1 | \
+# RUN: FileCheck --allow-empty %s
+
+# RUN: rm %t.lib.obj
+# RUN: lld-link /entry:main %t.main.obj %t.lib /out:%t.exe 2>&1 | \
+# RUN: FileCheck --allow-empty %s
+# RUN: not lld-link /entry:main %t.main.obj %t_thin.lib /out:%t.exe 2>&1 | \
+# RUN: FileCheck --check-prefix=NOOBJ %s
+# RUN: not lld-link /entry:main %t.main.obj %t_thin.lib /out:%t.exe \
+# RUN: /demangle:no 2>&1 | FileCheck --check-prefix=NOOBJNODEMANGLE %s
+
+# CHECK-NOT: error: could not get the buffer for the member defining
+# NOOBJ: error: could not get the buffer for the member defining symbol int __cdecl f(void): {{.*}}.lib({{.*}}.lib.obj):
+# NOOBJNODEMANGLE: error: could not get the buffer for the member defining symbol ?f@@YAHXZ: {{.*}}.lib({{.*}}.lib.obj):
+
+ .text
+
+ .def main
+ .scl 2
+ .type 32
+ .endef
+ .global main
+main:
+ call "?f@@YAHXZ"
+ retq $0
More information about the llvm-commits
mailing list