[lld] dd78e73 - [lld-macho] Don't include zero-size private label symbols in map file
Jez Ng via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 10 22:40:28 PST 2023
Author: Jez Ng
Date: 2023-03-11T01:40:14-05:00
New Revision: dd78e7334fc5eb4a3253433fe6dd80e440b5f7cc
URL: https://github.com/llvm/llvm-project/commit/dd78e7334fc5eb4a3253433fe6dd80e440b5f7cc
DIFF: https://github.com/llvm/llvm-project/commit/dd78e7334fc5eb4a3253433fe6dd80e440b5f7cc.diff
LOG: [lld-macho] Don't include zero-size private label symbols in map file
This is also what ld64 does. This will make it easier to compare their
respective map files.
Reviewed By: #lld-macho, thevinster
Differential Revision: https://reviews.llvm.org/D145654
Added:
Modified:
lld/MachO/InputFiles.cpp
lld/MachO/MapFile.cpp
lld/MachO/Symbols.h
lld/test/MachO/map-file.s
Removed:
################################################################################
diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index e0f3e0a4d459..db760d8f8382 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -634,12 +634,6 @@ void ObjFile::parseRelocations(ArrayRef<SectionHeader> sectionHeaders,
}
}
-// 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,
diff --git a/lld/MachO/MapFile.cpp b/lld/MachO/MapFile.cpp
index 0c1b4f1254d2..f736360624eb 100644
--- a/lld/MachO/MapFile.cpp
+++ b/lld/MachO/MapFile.cpp
@@ -204,9 +204,10 @@ void macho::writeMapFile() {
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);
diff --git a/lld/MachO/Symbols.h b/lld/MachO/Symbols.h
index 6113f2d7b0ec..d8e2f86e525b 100644
--- a/lld/MachO/Symbols.h
+++ b/lld/MachO/Symbols.h
@@ -383,6 +383,12 @@ inline bool needsBinding(const Symbol *sym) {
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
index f6b4e1026090..aa9fff9938eb 100644
--- 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,19 @@
#--- foo.s
.globl __ZTIN3foo3bar4MethE
+## This should not appear in the map file since it is a zero-size private label
+## symbol.
+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
+## This private label symbol will appear in the map file since it has nonzero
+## size.
+ltmp1:
+ nop
+
.subsections_via_symbols
#--- test.s
More information about the llvm-commits
mailing list