[lld] 32647c8 - [lld][nfc] Remove lld::demangle() (partial revert of D116279)
Jez Ng via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 14 12:29:08 PDT 2022
Author: Jez Ng
Date: 2022-10-14T15:28:47-04:00
New Revision: 32647c8f53a6558833acca95dc241e9e1132ecce
URL: https://github.com/llvm/llvm-project/commit/32647c8f53a6558833acca95dc241e9e1132ecce
DIFF: https://github.com/llvm/llvm-project/commit/32647c8f53a6558833acca95dc241e9e1132ecce.diff
LOG: [lld][nfc] Remove lld::demangle() (partial revert of D116279)
{D116279}, in addition to adding support for other demanglers, also
factored out some of the demangling logic. However, I don't think the
abstraction really carries its weight -- after {D135942}, only the ELF
and WASM backends call it with anything other than a non-constant
`shouldDemangle` argument. The COFF and Mach-O backends were already
doing the should-demangle check before calling `demangle()`.
Reviewed By: MaskRay, #lld-macho
Differential Revision: https://reviews.llvm.org/D135943
Added:
Modified:
lld/COFF/Symbols.cpp
lld/ELF/SymbolTable.cpp
lld/ELF/Symbols.cpp
lld/MachO/SymbolTable.cpp
lld/include/lld/Common/Strings.h
lld/wasm/Symbols.cpp
Removed:
################################################################################
diff --git a/lld/COFF/Symbols.cpp b/lld/COFF/Symbols.cpp
index a03cb03f8d175..5a038b38f8ba3 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(demangleInput.str());
if (demangled != demangleInput)
- return prefix + demangle(demangleInput, true);
+ return prefix + demangle(demangleInput.str());
return (prefix + prefixless).str();
}
return std::string(symName);
diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp
index 8ee3365c32c64..f09d0d7f90958 100644
--- a/lld/ELF/SymbolTable.cpp
+++ b/lld/ELF/SymbolTable.cpp
@@ -21,6 +21,7 @@
#include "lld/Common/Memory.h"
#include "lld/Common/Strings.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/Demangle/Demangle.h"
using namespace llvm;
using namespace llvm::object;
@@ -145,13 +146,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 = demangle(name.str());
else if (pos + 1 == name.size() || name[pos + 1] == '@')
- demangled = demangle(name.substr(0, pos), config->demangle);
+ demangled = demangle(name.substr(0, pos).str());
else
- demangled = (demangle(name.substr(0, pos), config->demangle) +
- name.substr(pos))
- .str();
+ demangled =
+ (demangle(name.substr(0, pos).str()) + name.substr(pos)).str();
(*demangledSyms)[demangled].push_back(sym);
}
}
diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index b5a62649528b6..248255248c1ee 100644
--- a/lld/ELF/Symbols.cpp
+++ b/lld/ELF/Symbols.cpp
@@ -15,7 +15,7 @@
#include "Target.h"
#include "Writer.h"
#include "lld/Common/ErrorHandler.h"
-#include "lld/Common/Strings.h"
+#include "llvm/Demangle/Demangle.h"
#include "llvm/Support/Compiler.h"
#include <cstring>
@@ -43,9 +43,16 @@ LLVM_ATTRIBUTE_UNUSED static inline void assertSymbols() {
AssertSymbol<LazyObject>();
}
+// Returns a symbol for an error message.
+static std::string maybeDemangleSymbol(StringRef symName) {
+ if (elf::config->demangle)
+ return demangle(symName.str());
+ return symName.str();
+}
+
std::string lld::toString(const elf::Symbol &sym) {
StringRef name = sym.getName();
- std::string ret = demangle(name, config->demangle);
+ std::string ret = maybeDemangleSymbol(name);
const char *suffix = sym.getVersionSuffix();
if (*suffix == '@')
diff --git a/lld/MachO/SymbolTable.cpp b/lld/MachO/SymbolTable.cpp
index 8ad7dbb8a89cf..c2c62cd14c82c 100644
--- a/lld/MachO/SymbolTable.cpp
+++ b/lld/MachO/SymbolTable.cpp
@@ -15,6 +15,7 @@
#include "SyntheticSections.h"
#include "lld/Common/ErrorHandler.h"
#include "lld/Common/Memory.h"
+#include "llvm/Demangle/Demangle.h"
using namespace llvm;
using namespace lld;
diff --git a/lld/include/lld/Common/Strings.h b/lld/include/lld/Common/Strings.h
index 29cd83acff85f..453903b2e3c36 100644
--- a/lld/include/lld/Common/Strings.h
+++ b/lld/include/lld/Common/Strings.h
@@ -13,19 +13,11 @@
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.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);
-}
llvm::SmallVector<uint8_t, 0> parseHex(llvm::StringRef s);
bool isValidCIdentifier(llvm::StringRef s);
diff --git a/lld/wasm/Symbols.cpp b/lld/wasm/Symbols.cpp
index 4ee5125c65abc..71f0fb1653dd6 100644
--- a/lld/wasm/Symbols.cpp
+++ b/lld/wasm/Symbols.cpp
@@ -15,7 +15,7 @@
#include "OutputSegment.h"
#include "lld/Common/ErrorHandler.h"
#include "lld/Common/Memory.h"
-#include "lld/Common/Strings.h"
+#include "llvm/Demangle/Demangle.h"
#define DEBUG_TYPE "lld"
@@ -34,8 +34,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 demangle(name.str());
+ return name.str();
}
std::string toString(wasm::Symbol::Kind kind) {
More information about the llvm-commits
mailing list