Skip to content

Commit

Permalink
lld-link: Only print demangled symbol names by default
Browse files Browse the repository at this point in the history
This makes lld-link's output a bit more concise. Since most developers can't
read mangled names, this should make the output a bit easier to understand as
well. It also makes lld-link's output consistent with ld.lld's output.

(link.exe prints both demangled and mangled names; lld-link used to match
link.exe output but now no longer does.)

For people working on toolchains, add a `/demangle:no` flag that makes lld-link
print the mangled name instead of the demangled name. (If desired, people could
pipe that through `demumble -b` to get the old behavior of both demangled and
mangled output.)

Differential Revision: https://reviews.llvm.org/D58132

llvm-svn: 355878
  • Loading branch information
nico committed Mar 11, 2019
1 parent 86af6f5 commit 020d92c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
1 change: 1 addition & 0 deletions lld/COFF/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ struct Configuration {
bool NoEntry = false;
std::string OutputFile;
std::string ImportName;
bool Demangle = true;
bool DoGC = true;
bool DoICF = true;
bool TailMerge;
Expand Down
3 changes: 3 additions & 0 deletions lld/COFF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,9 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
Config->Incremental = true;
}

// Handle /demangle
Config->Demangle = Args.hasFlag(OPT_demangle, OPT_demangle_no);

// Handle /debugtype
Config->DebugTypes = parseDebugTypes(Args);

Expand Down
8 changes: 3 additions & 5 deletions lld/COFF/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ def help_q : Flag<["/?", "-?"], "">, Alias<help>;
// LLD extensions
def exclude_all_symbols : F<"exclude-all-symbols">;
def export_all_symbols : F<"export-all-symbols">;
defm demangle : B<"demangle",
"Demangle symbols in output (default)",
"Do not demangle symbols in output">;
def kill_at : F<"kill-at">;
def lldmingw : F<"lldmingw">;
def output_def : Joined<["/", "-"], "output-def:">;
Expand All @@ -178,11 +181,6 @@ def show_timing : F<"time">;

class QF<string name> : Joined<["/", "-", "-?"], name#":">;

multiclass QB<string name> {
def "" : F<name>;
def _no : F<name#":no">;
}

def ignoreidl : F<"ignoreidl">;
def nologo : F<"nologo">;
def throwingnew : F<"throwingnew">;
Expand Down
7 changes: 5 additions & 2 deletions lld/COFF/Symbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
using namespace llvm;
using namespace llvm::object;

using namespace lld::coff;

// Returns a symbol name for an error message.
std::string lld::toString(coff::Symbol &B) {
if (Optional<std::string> S = lld::demangleMSVC(B.getName()))
return ("\"" + *S + "\" (" + B.getName() + ")").str();
if (Config->Demangle)
if (Optional<std::string> S = lld::demangleMSVC(B.getName()))
return *S;
return B.getName();
}

Expand Down
6 changes: 3 additions & 3 deletions lld/test/COFF/undefined-symbol-cv.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
# RUN: llvm-mc -triple=x86_64-windows-msvc -filetype=obj -o %t.obj %s
# RUN: not lld-link /out:%t.exe %t.obj 2>&1 | FileCheck %s

# CHECK: error: undefined symbol: "int __cdecl foo(void)" (?foo@@YAHXZ)
# CHECK: error: undefined symbol: int __cdecl foo(void)
# CHECK-NEXT: >>> referenced by file1.cpp:1
# CHECK-NEXT: >>> {{.*}}.obj:(main)
# CHECK-NEXT: >>> referenced by file1.cpp:2
# CHECK-NEXT: >>> {{.*}}.obj:(main)
# CHECK-EMPTY:
# CHECK-NEXT: error: undefined symbol: "int __cdecl bar(void)" (?bar@@YAHXZ)
# CHECK-NEXT: error: undefined symbol: int __cdecl bar(void)
# CHECK-NEXT: >>> referenced by file2.cpp:3
# CHECK-NEXT: >>> {{.*}}.obj:(main)
# CHECK-NEXT: >>> referenced by file1.cpp:4
# CHECK-NEXT: >>> {{.*}}.obj:(f1)
# CHECK-EMPTY:
# CHECK-NEXT: error: undefined symbol: "int __cdecl baz(void)" (?baz@@YAHXZ)
# CHECK-NEXT: error: undefined symbol: int __cdecl baz(void)
# CHECK-NEXT: >>> referenced by file1.cpp:5
# CHECK-NEXT: >>> {{.*}}.obj:(f2)

Expand Down
12 changes: 9 additions & 3 deletions lld/test/COFF/undefined-symbol.s
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
# REQUIRES: x86
# RUN: llvm-mc -triple=x86_64-windows-msvc -filetype=obj -o %t.obj %s
# RUN: not lld-link /out:%t.exe %t.obj 2>&1 | FileCheck %s
# RUN: not lld-link /out:%t.exe /demangle %t.obj 2>&1 | FileCheck %s
# RUN: not lld-link /out:%t.exe /demangle:no %t.obj 2>&1 | FileCheck --check-prefix=NODEMANGLE %s

# CHECK: error: undefined symbol: "int __cdecl foo(void)" (?foo@@YAHXZ)
# NODEMANGLE: error: undefined symbol: ?foo@@YAHXZ
# NODEMANGLE: error: undefined symbol: ?bar@@YAHXZ
# NODEMANGLE: error: undefined symbol: __imp_?baz@@YAHXZ

# CHECK: error: undefined symbol: int __cdecl foo(void)
# CHECK-NEXT: >>> referenced by {{.*}}.obj:(main)
# CHECK-NEXT: >>> referenced by {{.*}}.obj:(main)
# CHECK-EMPTY:
# CHECK-NEXT: error: undefined symbol: "int __cdecl bar(void)" (?bar@@YAHXZ)
# CHECK-NEXT: error: undefined symbol: int __cdecl bar(void)
# CHECK-NEXT: >>> referenced by {{.*}}.obj:(main)
# CHECK-NEXT: >>> referenced by {{.*}}.obj:(f1)
# CHECK-EMPTY:
# CHECK-NEXT: error: undefined symbol: "__declspec(dllimport) int __cdecl baz(void)" (__imp_?baz@@YAHXZ)
# CHECK-NEXT: error: undefined symbol: __declspec(dllimport) int __cdecl baz(void)
# CHECK-NEXT: >>> referenced by {{.*}}.obj:(f2)

.section .text,"xr",one_only,main
Expand Down

0 comments on commit 020d92c

Please sign in to comment.