[lld] r257647 - Demangle symbols when including them in error messages.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 13 10:55:39 PST 2016
Author: ruiu
Date: Wed Jan 13 12:55:39 2016
New Revision: 257647
URL: http://llvm.org/viewvc/llvm-project?rev=257647&view=rev
Log:
Demangle symbols when including them in error messages.
Added:
lld/trunk/test/ELF/conflict.s
Modified:
lld/trunk/ELF/Config.h
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/Options.td
lld/trunk/ELF/SymbolTable.cpp
lld/trunk/ELF/Symbols.cpp
lld/trunk/ELF/Symbols.h
Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=257647&r1=257646&r2=257647&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Wed Jan 13 12:55:39 2016
@@ -53,6 +53,7 @@ struct Configuration {
bool AllowMultipleDefinition;
bool AsNeeded = false;
bool Bsymbolic;
+ bool Demangle = true;
bool DiscardAll;
bool DiscardLocals;
bool DiscardNone;
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=257647&r1=257646&r2=257647&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Wed Jan 13 12:55:39 2016
@@ -185,6 +185,7 @@ void LinkerDriver::readConfigs(opt::Inpu
Config->AllowMultipleDefinition = Args.hasArg(OPT_allow_multiple_definition);
Config->Bsymbolic = Args.hasArg(OPT_Bsymbolic);
+ Config->Demangle = !Args.hasArg(OPT_no_demangle);
Config->DiscardAll = Args.hasArg(OPT_discard_all);
Config->DiscardLocals = Args.hasArg(OPT_discard_locals);
Config->DiscardNone = Args.hasArg(OPT_discard_none);
Modified: lld/trunk/ELF/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Options.td?rev=257647&r1=257646&r2=257647&view=diff
==============================================================================
--- lld/trunk/ELF/Options.td (original)
+++ lld/trunk/ELF/Options.td Wed Jan 13 12:55:39 2016
@@ -67,6 +67,9 @@ def no_allow_shlib_undefined : Flag<["--
def no_as_needed : Flag<["--"], "no-as-needed">;
+def no_demangle: Flag<["--"], "no-demangle">,
+ HelpText<"Demangle symbol names">;
+
def no_whole_archive : Flag<["--", "-"], "no-whole-archive">,
HelpText<"Restores the default behavior of loading archive members">;
Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=257647&r1=257646&r2=257647&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Wed Jan 13 12:55:39 2016
@@ -165,7 +165,7 @@ std::string SymbolTable<ELFT>::conflictM
StringRef Sym = Old->getName();
StringRef F1 = OldFile ? OldFile->getName() : "(internal)";
StringRef F2 = NewFile ? NewFile->getName() : "(internal)";
- return (Sym + " in " + F1 + " and " + F2).str();
+ return (demangle(Sym) + " in " + F1 + " and " + F2).str();
}
// This function resolves conflicts if there's an existing symbol with
Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=257647&r1=257646&r2=257647&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Wed Jan 13 12:55:39 2016
@@ -13,6 +13,11 @@
#include "InputFiles.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/Config/config.h"
+
+#ifdef HAVE_CXXABI_H
+#include <cxxabi.h>
+#endif
using namespace llvm;
using namespace llvm::object;
@@ -133,6 +138,23 @@ void elf2::initSymbols() {
doInitSymbols<ELF64BE>();
}
+// Returns the demangled C++ symbol name for Name.
+std::string elf2::demangle(StringRef Name) {
+#if !defined(HAVE_CXXABI_H)
+ return Name;
+#else
+ if (!Config->Demangle)
+ return Name;
+ char *Buf =
+ abi::__cxa_demangle(Name.str().c_str(), nullptr, nullptr, nullptr);
+ if (!Buf)
+ return Name;
+ std::string S(Buf);
+ free(Buf);
+ return S;
+#endif
+}
+
template int SymbolBody::compare<ELF32LE>(SymbolBody *Other);
template int SymbolBody::compare<ELF32BE>(SymbolBody *Other);
template int SymbolBody::compare<ELF64LE>(SymbolBody *Other);
Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=257647&r1=257646&r2=257647&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Wed Jan 13 12:55:39 2016
@@ -44,6 +44,11 @@ template <class ELFT> class SharedFile;
// Called at the beginning of main().
void initSymbols();
+// Returns a demangled C++ symbol name. If Name is not a mangled
+// name or the system does not provide __cxa_demangle function,
+// it returns the unmodified string.
+std::string demangle(StringRef Name);
+
// A real symbol object, SymbolBody, is usually accessed indirectly
// through a Symbol. There's always one Symbol for each symbol name.
// The resolver updates SymbolBody pointers as it resolves symbols.
Added: lld/trunk/test/ELF/conflict.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/conflict.s?rev=257647&view=auto
==============================================================================
--- lld/trunk/test/ELF/conflict.s (added)
+++ lld/trunk/test/ELF/conflict.s Wed Jan 13 12:55:39 2016
@@ -0,0 +1,17 @@
+# XFAIL: win32
+# REQUIRES: x86
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: not ld.lld %t %t -o %t2 2>&1 | FileCheck -check-prefix=DEMANGLE %s
+
+# RUN: not ld.lld %t %t -o %t2 --no-demangle 2>&1 | \
+# RUN: FileCheck -check-prefix=NO_DEMANGLE %s
+
+# DEMANGLE: duplicate symbol: {{mul\(double, double\)|_Z3muldd}} in
+# NO_DEMANGLE: duplicate symbol: _Z3muldd in
+
+.globl _Z3muldd
+_Z3muldd:
+ mov $60, %rax
+ mov $42, %rdi
+ syscall
More information about the llvm-commits
mailing list