diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -634,12 +634,6 @@ } } -// Symbols with `l` or `L` as a prefix are linker-private and never appear in -// the output. -static bool isPrivateLabel(StringRef name) { - return name.startswith("l") || name.startswith("L"); -} - template static macho::Symbol *createDefined(const NList &sym, StringRef name, InputSection *isec, uint64_t value, diff --git a/lld/MachO/MapFile.cpp b/lld/MachO/MapFile.cpp --- a/lld/MachO/MapFile.cpp +++ b/lld/MachO/MapFile.cpp @@ -202,9 +202,10 @@ if (auto *concatOsec = dyn_cast(osec)) { for (const InputSection *isec : concatOsec->inputs) { for (Defined *sym : isec->symbols) - os << format("0x%08llX\t0x%08llX\t[%3u] %s\n", sym->getVA(), - sym->size, readerToFileOrdinal[sym->getFile()], - sym->getName().str().data()); + if (!(isPrivateLabel(sym->getName()) && sym->size == 0)) + os << format("0x%08llX\t0x%08llX\t[%3u] %s\n", sym->getVA(), + sym->size, readerToFileOrdinal[sym->getFile()], + sym->getName().str().data()); } } else if (osec == in.cStringSection || osec == in.objcMethnameSection) { const auto &liveCStrings = info.liveCStringsForSection.lookup(osec); diff --git a/lld/MachO/Symbols.h b/lld/MachO/Symbols.h --- a/lld/MachO/Symbols.h +++ b/lld/MachO/Symbols.h @@ -383,6 +383,12 @@ return defined->isExternalWeakDef() || defined->interposable; return false; } + +// Symbols with `l` or `L` as a prefix are linker-private and never appear in +// the output. +inline bool isPrivateLabel(StringRef name) { + return name.startswith("l") || name.startswith("L"); +} } // namespace macho std::string toString(const macho::Symbol &); diff --git a/lld/test/MachO/map-file.s b/lld/test/MachO/map-file.s --- a/lld/test/MachO/map-file.s +++ b/lld/test/MachO/map-file.s @@ -19,7 +19,7 @@ # CHECK: Sections: # CHECK-NEXT: Idx Name Size VMA Type -# CHECK-NEXT: 0 __text 0000001b [[#%x,TEXT:]] TEXT +# CHECK-NEXT: 0 __text 0000001c [[#%x,TEXT:]] TEXT # CHECK-NEXT: 1 __stubs 0000000c [[#%x,STUBS:]] TEXT # CHECK-NEXT: 2 __stub_helper 0000001a [[#%x,HELPER:]] TEXT # CHECK-NEXT: 3 __cstring 0000002b [[#%x,CSTR:]] DATA @@ -69,6 +69,7 @@ # CHECK-NEXT: 0x[[#%X,MAIN]] 0x00000019 [ 2] _main # CHECK-NEXT: 0x[[#%X,BAR]] 0x00000001 [ 2] _bar # CHECK-NEXT: 0x[[#%X,FOO]] 0x00000001 [ 3] __ZTIN3foo3bar4MethE +# CHECK-NEXT: 0x[[#%X,FOO+1]] 0x00000001 [ 3] ltmp1 # CHECK-NEXT: 0x[[#%X,STUBS]] 0x00000006 [ 5] _baz # CHECK-NEXT: 0x[[#%X,STUBS+6]] 0x00000006 [ 2] _bar # CHECK-NEXT: 0x[[#%X,HELPER]] 0x0000001A [ 0] helper helper @@ -86,6 +87,7 @@ # CHECK-NEXT: 0x[[#%X,DYLD]] 0x00000000 [ 0] __dyld_private # CHECK-NEXT: 0x[[#%X,TLVP]] 0x00000008 [ 0] non-lazy-pointer-to-local: _baz_tlv # CHECK-NEXT: 0x[[#%X,BSS]] 0x00000001 [ 2] _number +# CHECK-EMPTY: # MAPFILE: "name":"Total Write map file" @@ -115,11 +117,15 @@ #--- foo.s .globl __ZTIN3foo3bar4MethE +ltmp0: ## This C++ symbol makes it clear that we do not print the demangled name in ## the map file, even if `-demangle` is passed. __ZTIN3foo3bar4MethE: nop +ltmp1: + nop + .subsections_via_symbols #--- test.s