This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by thakis on Oct 4 2022, 12:57 PM.

Details

Summary

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?

Diff Detail

Event Timeline

thakis created this revision.Oct 4 2022, 12:57 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptOct 4 2022, 12:57 PM
thakis requested review of this revision.Oct 4 2022, 12:57 PM
int3 accepted this revision.Oct 4 2022, 1:00 PM
int3 added a subscriber: int3.

seems reasonable :)

This revision is now accepted and ready to land.Oct 4 2022, 1:00 PM
oontvoo accepted this revision.Oct 4 2022, 1:04 PM
oontvoo added a subscriber: oontvoo.

LG (also seems harmless! :) )

Herald added a project: Restricted Project. · View Herald TranscriptOct 4 2022, 1:47 PM