[lld] r319138 - Factor out common code to Common/Strings.cpp.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 27 18:15:27 PST 2017
Author: ruiu
Date: Mon Nov 27 18:15:26 2017
New Revision: 319138
URL: http://llvm.org/viewvc/llvm-project?rev=319138&view=rev
Log:
Factor out common code to Common/Strings.cpp.
Differential Revision: https://reviews.llvm.org/D40530
Added:
lld/trunk/Common/Strings.cpp
lld/trunk/include/lld/Common/Strings.h
Modified:
lld/trunk/COFF/Strings.cpp
lld/trunk/COFF/Strings.h
lld/trunk/COFF/Symbols.cpp
lld/trunk/Common/CMakeLists.txt
lld/trunk/ELF/Strings.cpp
lld/trunk/ELF/Strings.h
lld/trunk/ELF/SymbolTable.cpp
lld/trunk/ELF/Symbols.cpp
lld/trunk/wasm/Strings.cpp
lld/trunk/wasm/Strings.h
Modified: lld/trunk/COFF/Strings.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Strings.cpp?rev=319138&r1=319137&r2=319138&view=diff
==============================================================================
--- lld/trunk/COFF/Strings.cpp (original)
+++ lld/trunk/COFF/Strings.cpp Mon Nov 27 18:15:26 2017
@@ -20,7 +20,7 @@ using namespace lld;
using namespace lld::coff;
using namespace llvm;
-Optional<std::string> coff::demangle(StringRef S) {
+Optional<std::string> coff::demangleMSVC(StringRef S) {
#if defined(_MSC_VER)
// UnDecorateSymbolName is not thread-safe, so we need a mutex.
static std::mutex Mu;
Modified: lld/trunk/COFF/Strings.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Strings.h?rev=319138&r1=319137&r2=319138&view=diff
==============================================================================
--- lld/trunk/COFF/Strings.h (original)
+++ lld/trunk/COFF/Strings.h Mon Nov 27 18:15:26 2017
@@ -16,7 +16,7 @@
namespace lld {
namespace coff {
-llvm::Optional<std::string> demangle(llvm::StringRef S);
+llvm::Optional<std::string> demangleMSVC(llvm::StringRef S);
}
}
Modified: lld/trunk/COFF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Symbols.cpp?rev=319138&r1=319137&r2=319138&view=diff
==============================================================================
--- lld/trunk/COFF/Symbols.cpp (original)
+++ lld/trunk/COFF/Symbols.cpp Mon Nov 27 18:15:26 2017
@@ -21,7 +21,7 @@ using namespace llvm::object;
// Returns a symbol name for an error message.
std::string lld::toString(coff::Symbol &B) {
- if (Optional<std::string> S = coff::demangle(B.getName()))
+ if (Optional<std::string> S = coff::demangleMSVC(B.getName()))
return ("\"" + *S + "\" (" + B.getName() + ")").str();
return B.getName();
}
Modified: lld/trunk/Common/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/Common/CMakeLists.txt?rev=319138&r1=319137&r2=319138&view=diff
==============================================================================
--- lld/trunk/Common/CMakeLists.txt (original)
+++ lld/trunk/Common/CMakeLists.txt Mon Nov 27 18:15:26 2017
@@ -5,6 +5,7 @@ endif()
add_lld_library(lldCommon
ErrorHandler.cpp
Reproduce.cpp
+ Strings.cpp
TargetOptionsCommandFlags.cpp
Threads.cpp
Version.cpp
Added: lld/trunk/Common/Strings.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/Common/Strings.cpp?rev=319138&view=auto
==============================================================================
--- lld/trunk/Common/Strings.cpp (added)
+++ lld/trunk/Common/Strings.cpp Mon Nov 27 18:15:26 2017
@@ -0,0 +1,32 @@
+//===- Strings.cpp -------------------------------------------------------===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lld/Common/Strings.h"
+#include "llvm/Demangle/Demangle.h"
+
+using namespace llvm;
+using namespace lld;
+
+// Returns the demangled C++ symbol name for Name.
+Optional<std::string> lld::demangleItanium(StringRef Name) {
+ // itaniumDemangle can be used to demangle strings other than symbol
+ // names which do not necessarily start with "_Z". Name can be
+ // either a C or C++ symbol. Don't call itaniumDemangle if the name
+ // does not look like a C++ symbol name to avoid getting unexpected
+ // result for a C symbol that happens to match a mangled type name.
+ if (!Name.startswith("_Z"))
+ return None;
+
+ char *Buf = itaniumDemangle(Name.str().c_str(), nullptr, nullptr, nullptr);
+ if (!Buf)
+ return None;
+ std::string S(Buf);
+ free(Buf);
+ return S;
+}
Modified: lld/trunk/ELF/Strings.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Strings.cpp?rev=319138&r1=319137&r2=319138&view=diff
==============================================================================
--- lld/trunk/ELF/Strings.cpp (original)
+++ lld/trunk/ELF/Strings.cpp Mon Nov 27 18:15:26 2017
@@ -60,21 +60,3 @@ bool elf::isValidCIdentifier(StringRef S
std::all_of(S.begin() + 1, S.end(),
[](char C) { return C == '_' || isAlnum(C); });
}
-
-// Returns the demangled C++ symbol name for Name.
-Optional<std::string> elf::demangle(StringRef Name) {
- // itaniumDemangle can be used to demangle strings other than symbol
- // names which do not necessarily start with "_Z". Name can be
- // either a C or C++ symbol. Don't call itaniumDemangle if the name
- // does not look like a C++ symbol name to avoid getting unexpected
- // result for a C symbol that happens to match a mangled type name.
- if (!Name.startswith("_Z"))
- return None;
-
- char *Buf = itaniumDemangle(Name.str().c_str(), nullptr, nullptr, nullptr);
- if (!Buf)
- return None;
- std::string S(Buf);
- free(Buf);
- return S;
-}
Modified: lld/trunk/ELF/Strings.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Strings.h?rev=319138&r1=319137&r2=319138&view=diff
==============================================================================
--- lld/trunk/ELF/Strings.h (original)
+++ lld/trunk/ELF/Strings.h Mon Nov 27 18:15:26 2017
@@ -66,10 +66,6 @@ private:
std::vector<llvm::GlobPattern> Patterns;
};
-// Returns a demangled C++ symbol name. If Name is not a mangled
-// name, it returns Optional::None.
-llvm::Optional<std::string> demangle(StringRef Name);
-
inline ArrayRef<uint8_t> toArrayRef(StringRef S) {
return {(const uint8_t *)S.data(), S.size()};
}
Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=319138&r1=319137&r2=319138&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Mon Nov 27 18:15:26 2017
@@ -21,6 +21,7 @@
#include "Symbols.h"
#include "SyntheticSections.h"
#include "lld/Common/ErrorHandler.h"
+#include "lld/Common/Strings.h"
#include "llvm/ADT/STLExtras.h"
using namespace llvm;
@@ -631,7 +632,7 @@ StringMap<std::vector<Symbol *>> &Symbol
for (Symbol *Sym : SymVector) {
if (!Sym->isDefined())
continue;
- if (Optional<std::string> S = demangle(Sym->getName()))
+ if (Optional<std::string> S = demangleItanium(Sym->getName()))
(*DemangledSyms)[*S].push_back(Sym);
else
(*DemangledSyms)[Sym->getName()].push_back(Sym);
Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=319138&r1=319137&r2=319138&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Mon Nov 27 18:15:26 2017
@@ -11,12 +11,12 @@
#include "InputFiles.h"
#include "InputSection.h"
#include "OutputSections.h"
-#include "Strings.h"
#include "SyntheticSections.h"
#include "Target.h"
#include "Writer.h"
#include "lld/Common/ErrorHandler.h"
+#include "lld/Common/Strings.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Path.h"
#include <cstring>
@@ -315,7 +315,7 @@ void elf::printTraceSymbol(Symbol *Sym)
// Returns a symbol for an error message.
std::string lld::toString(const Symbol &B) {
if (Config->Demangle)
- if (Optional<std::string> S = demangle(B.getName()))
+ if (Optional<std::string> S = demangleItanium(B.getName()))
return *S;
return B.getName();
}
Added: lld/trunk/include/lld/Common/Strings.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Common/Strings.h?rev=319138&view=auto
==============================================================================
--- lld/trunk/include/lld/Common/Strings.h (added)
+++ lld/trunk/include/lld/Common/Strings.h Mon Nov 27 18:15:26 2017
@@ -0,0 +1,23 @@
+//===- Strings.h ------------------------------------------------*- C++ -*-===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLD_STRINGS_H
+#define LLD_STRINGS_H
+
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
+#include <string>
+
+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);
+}
+
+#endif
Modified: lld/trunk/wasm/Strings.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Strings.cpp?rev=319138&r1=319137&r2=319138&view=diff
==============================================================================
--- lld/trunk/wasm/Strings.cpp (original)
+++ lld/trunk/wasm/Strings.cpp Mon Nov 27 18:15:26 2017
@@ -9,32 +9,14 @@
#include "Strings.h"
#include "Config.h"
+#include "lld/Common/Strings.h"
#include "llvm/ADT/StringRef.h"
-#include "llvm/Demangle/Demangle.h"
using namespace llvm;
-// Returns the demangled C++ symbol name for Name.
-Optional<std::string> lld::wasm::demangle(StringRef Name) {
- // itaniumDemangle can be used to demangle strings other than symbol
- // names which do not necessarily start with "_Z". Name can be
- // either a C or C++ symbol. Don't call itaniumDemangle if the name
- // does not look like a C++ symbol name to avoid getting unexpected
- // result for a C symbol that happens to match a mangled type name.
- if (!Name.startswith("_Z"))
- return None;
-
- char *Buf = itaniumDemangle(Name.str().c_str(), nullptr, nullptr, nullptr);
- if (!Buf)
- return None;
- std::string S(Buf);
- free(Buf);
- return S;
-}
-
std::string lld::wasm::displayName(StringRef Name) {
if (Config->Demangle)
- if (Optional<std::string> S = demangle(Name))
+ if (Optional<std::string> S = demangleItanium(Name))
return "`" + *S + "'";
return Name;
}
Modified: lld/trunk/wasm/Strings.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Strings.h?rev=319138&r1=319137&r2=319138&view=diff
==============================================================================
--- lld/trunk/wasm/Strings.h (original)
+++ lld/trunk/wasm/Strings.h Mon Nov 27 18:15:26 2017
@@ -17,10 +17,6 @@
namespace lld {
namespace wasm {
-// Returns a demangled C++ symbol name. If Name is not a mangled
-// name, it returns Optional::None.
-llvm::Optional<std::string> demangle(llvm::StringRef Name);
-
std::string displayName(llvm::StringRef Name);
} // namespace wasm
More information about the llvm-commits
mailing list