[lld] r373075 - [LLD] [COFF] Use the unified llvm demangle frontend function. NFC.
Martin Storsjo via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 27 05:23:45 PDT 2019
Author: mstorsjo
Date: Fri Sep 27 05:23:45 2019
New Revision: 373075
URL: http://llvm.org/viewvc/llvm-project?rev=373075&view=rev
Log:
[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
Modified:
lld/trunk/COFF/CMakeLists.txt
lld/trunk/COFF/Symbols.cpp
lld/trunk/Common/Strings.cpp
lld/trunk/include/lld/Common/Strings.h
lld/trunk/test/COFF/undefined-symbol-itanium-i386.s
lld/trunk/test/COFF/undefined-symbol.s
Modified: lld/trunk/COFF/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/CMakeLists.txt?rev=373075&r1=373074&r2=373075&view=diff
==============================================================================
--- lld/trunk/COFF/CMakeLists.txt (original)
+++ lld/trunk/COFF/CMakeLists.txt Fri Sep 27 05:23:45 2019
@@ -30,6 +30,7 @@ add_lld_library(lldCOFF
DebugInfoCodeView
DebugInfoMSF
DebugInfoPDB
+ Demangle
LibDriver
LTO
MC
Modified: lld/trunk/COFF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Symbols.cpp?rev=373075&r1=373074&r2=373075&view=diff
==============================================================================
--- lld/trunk/COFF/Symbols.cpp (original)
+++ lld/trunk/COFF/Symbols.cpp Fri Sep 27 05:23:45 2019
@@ -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 {
Modified: lld/trunk/Common/Strings.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/Common/Strings.cpp?rev=373075&r1=373074&r2=373075&view=diff
==============================================================================
--- lld/trunk/Common/Strings.cpp (original)
+++ lld/trunk/Common/Strings.cpp Fri Sep 27 05:23:45 2019
@@ -36,23 +36,6 @@ Optional<std::string> lld::demangleItani
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);
Modified: lld/trunk/include/lld/Common/Strings.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Common/Strings.h?rev=373075&r1=373074&r2=373075&view=diff
==============================================================================
--- lld/trunk/include/lld/Common/Strings.h (original)
+++ lld/trunk/include/lld/Common/Strings.h Fri Sep 27 05:23:45 2019
@@ -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);
Modified: lld/trunk/test/COFF/undefined-symbol-itanium-i386.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/undefined-symbol-itanium-i386.s?rev=373075&r1=373074&r2=373075&view=diff
==============================================================================
--- lld/trunk/test/COFF/undefined-symbol-itanium-i386.s (original)
+++ lld/trunk/test/COFF/undefined-symbol-itanium-i386.s Fri Sep 27 05:23:45 2019
@@ -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)
@@ -18,6 +19,9 @@
# 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
.globl _main
@@ -34,3 +38,4 @@ _f1:
.globl _f2
_f2:
call *__imp___Z3bazv
+ call _Z3fooi
Modified: lld/trunk/test/COFF/undefined-symbol.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/undefined-symbol.s?rev=373075&r1=373074&r2=373075&view=diff
==============================================================================
--- lld/trunk/test/COFF/undefined-symbol.s (original)
+++ lld/trunk/test/COFF/undefined-symbol.s Fri Sep 27 05:23:45 2019
@@ -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)
@@ -18,6 +19,9 @@
# 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
.globl main
@@ -34,3 +38,4 @@ f1:
.globl f2
f2:
callq *"__imp_?baz@@YAHXZ"(%rip)
+ callq *__imp_undecorated(%rip)
More information about the llvm-commits
mailing list