[lld] 8792cd7 - Revert "[lld] Add support for other demanglers other than Itanium"
Luís Ferreira via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 30 10:08:11 PST 2021
Author: Luís Ferreira
Date: 2021-12-30T18:04:21Z
New Revision: 8792cd75d0ccc0a9043b5456f147a198a9d90cd2
URL: https://github.com/llvm/llvm-project/commit/8792cd75d0ccc0a9043b5456f147a198a9d90cd2
DIFF: https://github.com/llvm/llvm-project/commit/8792cd75d0ccc0a9043b5456f147a198a9d90cd2.diff
LOG: Revert "[lld] Add support for other demanglers other than Itanium"
This reverts commit e60d6dfd5acdc821d391ad5af2c706397bdfd36a.
clang-ppc64le-rhel buildbot failed (https://lab.llvm.org/buildbot#builders/57/builds/13424):
tools/lld/MachO/CMakeFiles/lldMachO.dir/Symbols.cpp.o: In function `lld::demangle(llvm::StringRef, bool)':
Symbols.cpp:(.text._ZN3lld8demangleEN4llvm9StringRefEb[_ZN3lld8demangleEN4llvm9StringRefEb]+0x90): undefined reference to `llvm::demangle(std::string const&)'
Added:
Modified:
lld/COFF/Symbols.cpp
lld/Common/Strings.cpp
lld/ELF/SymbolTable.cpp
lld/ELF/Symbols.cpp
lld/MachO/Symbols.cpp
lld/include/lld/Common/Strings.h
lld/test/ELF/undef.s
lld/wasm/Symbols.cpp
Removed:
################################################################################
diff --git a/lld/COFF/Symbols.cpp b/lld/COFF/Symbols.cpp
index a03cb03f8d175..8a6a9b27d45fa 100644
--- a/lld/COFF/Symbols.cpp
+++ b/lld/COFF/Symbols.cpp
@@ -36,9 +36,9 @@ static std::string maybeDemangleSymbol(StringRef symName) {
StringRef demangleInput = prefixless;
if (config->machine == I386)
demangleInput.consume_front("_");
- std::string demangled = demangle(demangleInput, true);
+ std::string demangled = demangle(std::string(demangleInput));
if (demangled != demangleInput)
- return prefix + demangle(demangleInput, true);
+ return prefix + demangle(std::string(demangleInput));
return (prefix + prefixless).str();
}
return std::string(symName);
diff --git a/lld/Common/Strings.cpp b/lld/Common/Strings.cpp
index 6e5478e335ca3..7bf336490dae0 100644
--- a/lld/Common/Strings.cpp
+++ b/lld/Common/Strings.cpp
@@ -9,6 +9,7 @@
#include "lld/Common/Strings.h"
#include "lld/Common/ErrorHandler.h"
#include "lld/Common/LLVM.h"
+#include "llvm/Demangle/Demangle.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/GlobPattern.h"
#include <algorithm>
@@ -18,6 +19,18 @@
using namespace llvm;
using namespace lld;
+// Returns the demangled C++ symbol name for name.
+std::string lld::demangleItanium(StringRef name) {
+ // demangleItanium() can be called for all symbols. Only demangle C++ symbols,
+ // to avoid getting unexpected result for a C symbol that happens to match a
+ // mangled type name such as "Pi" (which would demangle to "int*").
+ if (!name.startswith("_Z") && !name.startswith("__Z") &&
+ !name.startswith("___Z") && !name.startswith("____Z"))
+ return std::string(name);
+
+ return demangle(std::string(name));
+}
+
SingleStringMatcher::SingleStringMatcher(StringRef Pattern) {
if (Pattern.size() > 2 && Pattern.startswith("\"") &&
Pattern.endswith("\"")) {
diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp
index ec425cd7e1d12..c93a166daa6e4 100644
--- a/lld/ELF/SymbolTable.cpp
+++ b/lld/ELF/SymbolTable.cpp
@@ -143,13 +143,12 @@ StringMap<SmallVector<Symbol *, 0>> &SymbolTable::getDemangledSyms() {
StringRef name = sym->getName();
size_t pos = name.find('@');
if (pos == std::string::npos)
- demangled = demangle(name, config->demangle);
+ demangled = demangleItanium(name);
else if (pos + 1 == name.size() || name[pos + 1] == '@')
- demangled = demangle(name.substr(0, pos), config->demangle);
+ demangled = demangleItanium(name.substr(0, pos));
else
- demangled = (demangle(name.substr(0, pos), config->demangle) +
- name.substr(pos))
- .str();
+ demangled =
+ (demangleItanium(name.substr(0, pos)) + name.substr(pos)).str();
(*demangledSyms)[demangled].push_back(sym);
}
}
diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index ed83b75953dd9..acb0dd27d0abf 100644
--- a/lld/ELF/Symbols.cpp
+++ b/lld/ELF/Symbols.cpp
@@ -26,9 +26,16 @@ using namespace llvm::ELF;
using namespace lld;
using namespace lld::elf;
+// Returns a symbol for an error message.
+static std::string demangle(StringRef symName) {
+ if (elf::config->demangle)
+ return demangleItanium(symName);
+ return std::string(symName);
+}
+
std::string lld::toString(const elf::Symbol &sym) {
StringRef name = sym.getName();
- std::string ret = demangle(name, config->demangle);
+ std::string ret = demangle(name);
const char *suffix = sym.getVersionSuffix();
if (*suffix == '@')
@@ -37,7 +44,7 @@ std::string lld::toString(const elf::Symbol &sym) {
}
std::string lld::toELFString(const Archive::Symbol &b) {
- return demangle(b.getName(), config->demangle);
+ return demangle(b.getName());
}
Defined *ElfSym::bss;
diff --git a/lld/MachO/Symbols.cpp b/lld/MachO/Symbols.cpp
index b0ebd224affbd..bb6d073dcf308 100644
--- a/lld/MachO/Symbols.cpp
+++ b/lld/MachO/Symbols.cpp
@@ -9,7 +9,6 @@
#include "Symbols.h"
#include "InputFiles.h"
#include "SyntheticSections.h"
-#include "lld/Common/Strings.h"
using namespace llvm;
using namespace lld;
@@ -28,12 +27,17 @@ static_assert(sizeof(void *) != 8 || sizeof(Defined) == 80,
static_assert(sizeof(SymbolUnion) == sizeof(Defined),
"Defined should be the largest Symbol kind");
-std::string lld::toString(const Symbol &sym) {
- return demangle(sym.getName(), config->demangle);
+// Returns a symbol for an error message.
+static std::string demangle(StringRef symName) {
+ if (config->demangle)
+ return demangleItanium(symName);
+ return std::string(symName);
}
+std::string lld::toString(const Symbol &sym) { return demangle(sym.getName()); }
+
std::string lld::toMachOString(const object::Archive::Symbol &b) {
- return demangle(b.getName(), config->demangle);
+ return demangle(b.getName());
}
uint64_t Symbol::getStubVA() const { return in.stubs->getVA(stubsIndex); }
diff --git a/lld/include/lld/Common/Strings.h b/lld/include/lld/Common/Strings.h
index ece801892767a..71126f6150171 100644
--- a/lld/include/lld/Common/Strings.h
+++ b/lld/include/lld/Common/Strings.h
@@ -12,19 +12,14 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringRef.h"
-#include "llvm/Demangle/Demangle.h"
#include "llvm/Support/GlobPattern.h"
#include <string>
#include <vector>
namespace lld {
-// Returns a demangled symbol name. If Name is not a mangled name, it returns
-// name.
-inline std::string demangle(llvm::StringRef symName, bool shouldDemangle) {
- if (shouldDemangle)
- return llvm::demangle(symName.str().c_str());
- return std::string(symName);
-}
+// Returns a demangled C++ symbol name. If Name is not a mangled
+// name, it returns name.
+std::string demangleItanium(llvm::StringRef name);
std::vector<uint8_t> parseHex(llvm::StringRef s);
bool isValidCIdentifier(llvm::StringRef s);
diff --git a/lld/test/ELF/undef.s b/lld/test/ELF/undef.s
index 6398b73d51e62..931a482e1810b 100644
--- a/lld/test/ELF/undef.s
+++ b/lld/test/ELF/undef.s
@@ -31,18 +31,6 @@
# CHECK-NEXT: >>> referenced by undef.s
# CHECK-NEXT: >>> {{.*}}:(.text+0x1A)
-# CHECK: error: undefined symbol: Pi
-# CHECK-NEXT: >>> referenced by undef.s
-# CHECK-NEXT: >>> {{.*}}:(.text+0x1F)
-
-# CHECK: error: undefined symbol: D main
-# CHECK-NEXT: >>> referenced by undef.s
-# CHECK-NEXT: >>> {{.*}}:(.text+0x24)
-
-# CHECK: error: undefined symbol: a::main
-# CHECK-NEXT: >>> referenced by undef.s
-# CHECK-NEXT: >>> {{.*}}:(.text+0x29)
-
# CHECK: error: undefined symbol: zed2
# CHECK-NEXT: >>> referenced by {{.*}}.o:(.text+0x0) in archive {{.*}}2.a
@@ -96,6 +84,3 @@ _start:
call _Z3fooi
call _ZTV3Foo
call __Z3fooi
- call Pi
- call _Dmain
- call _RNvC1a4main
diff --git a/lld/wasm/Symbols.cpp b/lld/wasm/Symbols.cpp
index 6c134fd380bc7..684f4832b2678 100644
--- a/lld/wasm/Symbols.cpp
+++ b/lld/wasm/Symbols.cpp
@@ -22,7 +22,6 @@
using namespace llvm;
using namespace llvm::object;
using namespace llvm::wasm;
-using namespace lld::wasm;
namespace lld {
std::string toString(const wasm::Symbol &sym) {
@@ -34,8 +33,9 @@ std::string maybeDemangleSymbol(StringRef name) {
// `main` in the case where we need to pass it arguments.
if (name == "__main_argc_argv")
return "main";
-
- return demangle(name, config->demangle);
+ if (wasm::config->demangle)
+ return demangleItanium(name);
+ return std::string(name);
}
std::string toString(wasm::Symbol::Kind kind) {
More information about the llvm-commits
mailing list