forked from OSchip/llvm-project
[LLD] [COFF] Use the unified llvm demangle frontend function. NFC.
Add test cases for some cases where we don't want demangling to happen. Differential Revision: https://reviews.llvm.org/D67301 llvm-svn: 373075
This commit is contained in:
parent
06bc9d579c
commit
bf6f4e9932
|
@ -30,6 +30,7 @@ add_lld_library(lldCOFF
|
|||
DebugInfoCodeView
|
||||
DebugInfoMSF
|
||||
DebugInfoPDB
|
||||
Demangle
|
||||
LibDriver
|
||||
LTO
|
||||
MC
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "lld/Common/Memory.h"
|
||||
#include "lld/Common/Strings.h"
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "llvm/Demangle/Demangle.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
||||
|
@ -26,26 +27,25 @@ static_assert(sizeof(SymbolUnion) <= 48,
|
|||
"symbols should be optimized for memory usage");
|
||||
|
||||
// Returns a symbol name for an error message.
|
||||
static std::string demangle(StringRef symName) {
|
||||
static std::string maybeDemangleSymbol(StringRef symName) {
|
||||
if (config->demangle) {
|
||||
if (Optional<std::string> s = demangleMSVC(symName))
|
||||
return *s;
|
||||
if (config->mingw) {
|
||||
StringRef demangleInput = symName;
|
||||
std::string prefix;
|
||||
if (demangleInput.consume_front("__imp_"))
|
||||
prefix = "__declspec(dllimport) ";
|
||||
if (config->machine == I386)
|
||||
demangleInput.consume_front("_");
|
||||
if (Optional<std::string> s = demangleItanium(demangleInput))
|
||||
return prefix + *s;
|
||||
}
|
||||
std::string prefix;
|
||||
StringRef demangleInput = symName;
|
||||
if (demangleInput.consume_front("__imp_"))
|
||||
prefix = "__declspec(dllimport) ";
|
||||
if (config->machine == I386)
|
||||
demangleInput.consume_front("_");
|
||||
std::string demangled = demangle(demangleInput);
|
||||
if (demangled != demangleInput)
|
||||
return prefix + demangled;
|
||||
}
|
||||
return symName;
|
||||
}
|
||||
std::string toString(coff::Symbol &b) { return demangle(b.getName()); }
|
||||
std::string toString(coff::Symbol &b) {
|
||||
return maybeDemangleSymbol(b.getName());
|
||||
}
|
||||
std::string toCOFFString(const Archive::Symbol &b) {
|
||||
return demangle(b.getName());
|
||||
return maybeDemangleSymbol(b.getName());
|
||||
}
|
||||
|
||||
namespace coff {
|
||||
|
|
|
@ -36,23 +36,6 @@ Optional<std::string> lld::demangleItanium(StringRef name) {
|
|||
return s;
|
||||
}
|
||||
|
||||
Optional<std::string> lld::demangleMSVC(StringRef name) {
|
||||
std::string prefix;
|
||||
if (name.consume_front("__imp_"))
|
||||
prefix = "__declspec(dllimport) ";
|
||||
|
||||
// Demangle only C++ names.
|
||||
if (!name.startswith("?"))
|
||||
return None;
|
||||
|
||||
char *buf = microsoftDemangle(name.str().c_str(), nullptr, nullptr, nullptr);
|
||||
if (!buf)
|
||||
return None;
|
||||
std::string s(buf);
|
||||
free(buf);
|
||||
return prefix + s;
|
||||
}
|
||||
|
||||
StringMatcher::StringMatcher(ArrayRef<StringRef> pat) {
|
||||
for (StringRef s : pat) {
|
||||
Expected<GlobPattern> pat = GlobPattern::create(s);
|
||||
|
|
|
@ -20,7 +20,6 @@ namespace lld {
|
|||
// Returns a demangled C++ symbol name. If Name is not a mangled
|
||||
// name, it returns Optional::None.
|
||||
llvm::Optional<std::string> demangleItanium(llvm::StringRef name);
|
||||
llvm::Optional<std::string> demangleMSVC(llvm::StringRef s);
|
||||
|
||||
std::vector<uint8_t> parseHex(llvm::StringRef s);
|
||||
bool isValidCIdentifier(llvm::StringRef s);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
# NODEMANGLE: error: undefined symbol: __Z3fooi
|
||||
# NODEMANGLE: error: undefined symbol: __Z3barPKc
|
||||
# NODEMANGLE: error: undefined symbol: __imp___Z3bazv
|
||||
# NODEMANGLE: error: undefined symbol: _Z3fooi
|
||||
|
||||
# CHECK: error: undefined symbol: foo(int)
|
||||
# CHECK-NEXT: >>> referenced by {{.*}}.o:(_main)
|
||||
|
@ -17,6 +18,9 @@
|
|||
# CHECK-NEXT: >>> referenced by {{.*}}.o:(_f1)
|
||||
# CHECK-EMPTY:
|
||||
# CHECK-NEXT: error: undefined symbol: __declspec(dllimport) baz()
|
||||
# CHECK-NEXT: >>> referenced by {{.*}}.o:(_f2)
|
||||
# CHECK-EMPTY:
|
||||
# CHECK-NEXT: error: undefined symbol: _Z3fooi
|
||||
# CHECK-NEXT: >>> referenced by {{.*}}.o:(_f2)
|
||||
|
||||
.section .text,"xr",one_only,_main
|
||||
|
@ -34,3 +38,4 @@ _f1:
|
|||
.globl _f2
|
||||
_f2:
|
||||
call *__imp___Z3bazv
|
||||
call _Z3fooi
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
# NODEMANGLE: error: undefined symbol: ?foo@@YAHXZ
|
||||
# NODEMANGLE: error: undefined symbol: ?bar@@YAHXZ
|
||||
# NODEMANGLE: error: undefined symbol: __imp_?baz@@YAHXZ
|
||||
# NODEMANGLE: error: undefined symbol: __imp_undecorated
|
||||
|
||||
# CHECK: error: undefined symbol: int __cdecl foo(void)
|
||||
# CHECK-NEXT: >>> referenced by {{.*}}.obj:(main)
|
||||
|
@ -17,6 +18,9 @@
|
|||
# CHECK-NEXT: >>> referenced by {{.*}}.obj:(f1)
|
||||
# CHECK-EMPTY:
|
||||
# CHECK-NEXT: error: undefined symbol: __declspec(dllimport) int __cdecl baz(void)
|
||||
# CHECK-NEXT: >>> referenced by {{.*}}.obj:(f2)
|
||||
# CHECK-EMPTY:
|
||||
# CHECK-NEXT: error: undefined symbol: __imp_undecorated
|
||||
# CHECK-NEXT: >>> referenced by {{.*}}.obj:(f2)
|
||||
|
||||
.section .text,"xr",one_only,main
|
||||
|
@ -34,3 +38,4 @@ f1:
|
|||
.globl f2
|
||||
f2:
|
||||
callq *"__imp_?baz@@YAHXZ"(%rip)
|
||||
callq *__imp_undecorated(%rip)
|
||||
|
|
Loading…
Reference in New Issue