[PATCH] D135189: [lld/mac] With -demangle, strip leading _ from non-mangled names

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 4 12:57:12 PDT 2022


thakis created this revision.
thakis added a reviewer: lld-macho.
Herald added projects: lld-macho, All.
thakis requested review of this revision.

For

  void f();
  int main() { f(); }

`lld -demangle` now produces

  ld64.lld: error: undefined symbol: f
  >>> referenced by path/to/main.o:(symbol main+0x8)

instead of

  ld64.lld: error: undefined symbol: _f
  >>> referenced by path/to/main.o:(symbol _main+0x8)

previously. (Without `-demangle`, it still prints `_f` and `_main`.)

This does *not* match ld64's behavior, but it does match e.g. lld/COFF's
behaviour.

This is arguably easier to understand: clang prepends symbol names with `_`
on macOS, so it seems friendly if the linker removes it again in its
diagnostics. It also makes the `extern "C"` insertion diagnostics we added
recently look more self-consistent.

--------------------

I'm not 100% sure this is a good idea, but it might be. Maybe best to land
it for a while and see how it feels?


https://reviews.llvm.org/D135189

Files:
  lld/MachO/Symbols.cpp
  lld/test/MachO/invalid/duplicate-symbol.s
  lld/test/MachO/invalid/undefined-symbol.s
  lld/test/MachO/undef-suggest-extern-c.s
  lld/test/MachO/undef-suggest-extern-c2.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135189.465126.patch
Type: text/x-patch
Size: 4874 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221004/50ceefc5/attachment.bin>


More information about the llvm-commits mailing list