[LLD] [COFF] Omit section symbols and IMAGE_SYM_CLASS_LABEL from the PE symbol table
The section symbols aren't of much practical use when looking at
a linked image. This shrinks one observed mingw style unstripped
binary by 14%.
IMAGE_SYM_CLASS_LABEL is in spirit the same as a temporary assembler
label that isn't emitted on the object file level at all.
Differential Revision: https://reviews.llvm.org/D113866
GitOrigin-RevId: d703b922961e0d02a5effdd4bfbb23ad50a3cc9f
diff --git a/COFF/Writer.cpp b/COFF/Writer.cpp
index 600d140..0788f35 100644
--- a/COFF/Writer.cpp
+++ b/COFF/Writer.cpp
@@ -1211,6 +1211,12 @@
if (!d || d->writtenToSymtab)
continue;
d->writtenToSymtab = true;
+ if (auto *dc = dyn_cast_or_null<DefinedCOFF>(d)) {
+ COFFSymbolRef symRef = dc->getCOFFSymbol();
+ if (symRef.isSectionDefinition() ||
+ symRef.getStorageClass() == COFF::IMAGE_SYM_CLASS_LABEL)
+ continue;
+ }
if (Optional<coff_symbol16> sym = createSymbol(d))
outputSymtab.push_back(*sym);
diff --git a/test/COFF/strtab-size.s b/test/COFF/strtab-size.s
index 574b1a0..153363b 100644
--- a/test/COFF/strtab-size.s
+++ b/test/COFF/strtab-size.s
@@ -213,4 +213,5 @@
sym192:
sym193:
sym194:
+sym195:
ret
diff --git a/test/COFF/symtab.test b/test/COFF/symtab.test
index 1d47def..949e960 100644
--- a/test/COFF/symtab.test
+++ b/test/COFF/symtab.test
@@ -11,33 +11,6 @@
# CHECK: Symbols [
# CHECK-NEXT: Symbol {
-# CHECK-NEXT: Name: .text
-# CHECK-NEXT: Value: 0
-# CHECK-NEXT: Section: .text (1)
-# CHECK-NEXT: BaseType: Null (0x0)
-# CHECK-NEXT: ComplexType: Null (0x0)
-# CHECK-NEXT: StorageClass: Static (0x3)
-# CHECK-NEXT: AuxSymbolCount: 0
-# CHECK-NEXT: }
-# CHECK-NEXT: Symbol {
-# CHECK-NEXT: Name: .text2
-# CHECK-NEXT: Value: 0
-# CHECK-NEXT: Section: .text (1)
-# CHECK-NEXT: BaseType: Null (0x0)
-# CHECK-NEXT: ComplexType: Null (0x0)
-# CHECK-NEXT: StorageClass: Static (0x3)
-# CHECK-NEXT: AuxSymbolCount: 0
-# CHECK-NEXT: }
-# CHECK-NEXT: Symbol {
-# CHECK-NEXT: Name: .data
-# CHECK-NEXT: Value: 0
-# CHECK-NEXT: Section: .data (3)
-# CHECK-NEXT: BaseType: Null (0x0)
-# CHECK-NEXT: ComplexType: Null (0x0)
-# CHECK-NEXT: StorageClass: Static (0x3)
-# CHECK-NEXT: AuxSymbolCount: 0
-# CHECK-NEXT: }
-# CHECK-NEXT: Symbol {
# CHECK-NEXT: Name: MessageBoxA
# CHECK-NEXT: Value: 80
# CHECK-NEXT: Section: .text (1)
@@ -235,4 +208,10 @@
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: .Ltemp_symbol
+ Value: 1
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_LABEL
...