[lld] fd30414 - [lld-macho] Demangle location name in undefined symbol diagnostics

Daniel Bertalan via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 25 09:43:13 PDT 2022


Author: Daniel Bertalan
Date: 2022-07-25T18:42:16+02:00
New Revision: fd3041420681fe1581b75695f2b61b14b710d8d7

URL: https://github.com/llvm/llvm-project/commit/fd3041420681fe1581b75695f2b61b14b710d8d7
DIFF: https://github.com/llvm/llvm-project/commit/fd3041420681fe1581b75695f2b61b14b710d8d7.diff

LOG: [lld-macho] Demangle location name in undefined symbol diagnostics

If the `-demangle` flag is passed to lld, symbol names will now be
demangled in the "referenced by:" message in addition to the referenced
symbol's name, which was already demangled before this change.

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

Added: 
    

Modified: 
    lld/MachO/InputSection.cpp
    lld/test/MachO/invalid/undefined-symbol.s

Removed: 
    


################################################################################
diff  --git a/lld/MachO/InputSection.cpp b/lld/MachO/InputSection.cpp
index 76b11d9da4f89..ca073f8ac6f39 100644
--- a/lld/MachO/InputSection.cpp
+++ b/lld/MachO/InputSection.cpp
@@ -67,7 +67,7 @@ std::string InputSection::getLocation(uint64_t off) const {
   // First, try to find a symbol that's near the offset. Use it as a reference
   // point.
   if (auto *sym = getContainingSymbol(off))
-    return (toString(getFile()) + ":(symbol " + sym->getName() + "+0x" +
+    return (toString(getFile()) + ":(symbol " + toString(*sym) + "+0x" +
             Twine::utohexstr(off - sym->value) + ")")
         .str();
 

diff  --git a/lld/test/MachO/invalid/undefined-symbol.s b/lld/test/MachO/invalid/undefined-symbol.s
index 4b80716347bb3..9da4a7326011b 100644
--- a/lld/test/MachO/invalid/undefined-symbol.s
+++ b/lld/test/MachO/invalid/undefined-symbol.s
@@ -4,18 +4,24 @@
 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/foo.s -o %t/foo.o
 # RUN: llvm-ar crs %t/foo.a %t/foo.o
 # RUN: not %lld --icf=all -o /dev/null %t/main.o 2>&1 | \
-# RUN:     FileCheck %s -DSYM=_foo -DLOC='%t/main.o:(symbol _main+0x1)'
+# RUN:     FileCheck %s -DSYM=__ZN3foo3barEi -DLOC='%t/main.o:(symbol _main+0x1)'
+# RUN: not %lld -demangle --icf=all -o /dev/null %t/main.o 2>&1 | \
+# RUN:     FileCheck %s -DSYM='foo::bar(int)' -DLOC='%t/main.o:(symbol _main+0x1)'
 # RUN: not %lld -o /dev/null %t/main.o %t/foo.a 2>&1 | \
-# RUN:     FileCheck %s -DSYM=_bar -DLOC='%t/foo.a(foo.o):(symbol _foo+0x1)'
+# RUN:     FileCheck %s -DSYM=_bar -DLOC='%t/foo.a(foo.o):(symbol __ZN3foo3barEi+0x1)'
+# RUN: not %lld -demangle -o /dev/null %t/main.o %t/foo.a 2>&1 | \
+# RUN:     FileCheck %s -DSYM=_bar -DLOC='%t/foo.a(foo.o):(symbol foo::bar(int)+0x1)'
 # RUN: not %lld -o /dev/null %t/main.o -force_load %t/foo.a 2>&1 | \
-# RUN:     FileCheck %s -DSYM=_bar -DLOC='%t/foo.a(foo.o):(symbol _foo+0x1)'
+# RUN:     FileCheck %s -DSYM=_bar -DLOC='%t/foo.a(foo.o):(symbol __ZN3foo3barEi+0x1)'
+# RUN: not %lld -demangle -o /dev/null %t/main.o -force_load %t/foo.a 2>&1 | \
+# RUN:     FileCheck %s -DSYM=_bar -DLOC='%t/foo.a(foo.o):(symbol foo::bar(int)+0x1)'
 # CHECK: error: undefined symbol: [[SYM]]
 # CHECK-NEXT: >>> referenced by [[LOC]]
 
 #--- foo.s
-.globl _foo
+.globl __ZN3foo3barEi
 .text
-_foo:
+__ZN3foo3barEi:
   callq _bar
   retq
 
@@ -23,13 +29,13 @@ _foo:
 .text
 
 _anotherref:
-  callq _foo
+  callq __ZN3foo3barEi
   movq $0, %rax
   retq
 
 .globl _main
 _main:
-  callq _foo
+  callq __ZN3foo3barEi
   movq $0, %rax
   retq
 


        


More information about the llvm-commits mailing list