[PATCH] D145654: [lld-macho] Don't include zero-size private label symbols in map file
Jez Ng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 8 22:42:53 PST 2023
int3 created this revision.
int3 added a reviewer: lld-macho.
Herald added projects: lld-macho, All.
int3 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This is also what ld64 does. This will make it easier to compare their
respective map files.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D145654
Files:
lld/MachO/InputFiles.cpp
lld/MachO/MapFile.cpp
lld/MachO/Symbols.h
lld/test/MachO/map-file.s
Index: lld/test/MachO/map-file.s
===================================================================
--- lld/test/MachO/map-file.s
+++ 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
Index: lld/MachO/Symbols.h
===================================================================
--- lld/MachO/Symbols.h
+++ 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 &);
Index: lld/MachO/MapFile.cpp
===================================================================
--- lld/MachO/MapFile.cpp
+++ lld/MachO/MapFile.cpp
@@ -202,9 +202,10 @@
if (auto *concatOsec = dyn_cast<ConcatOutputSection>(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);
Index: lld/MachO/InputFiles.cpp
===================================================================
--- lld/MachO/InputFiles.cpp
+++ 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 <class NList>
static macho::Symbol *createDefined(const NList &sym, StringRef name,
InputSection *isec, uint64_t value,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145654.503635.patch
Type: text/x-patch
Size: 3776 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230309/2171d9e1/attachment.bin>
More information about the llvm-commits
mailing list