[lld] d703b92 - [LLD] [COFF] Omit section symbols and IMAGE_SYM_CLASS_LABEL from the PE symbol table
Martin Storsjö via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 23 00:39:33 PST 2021
Author: Martin Storsjö
Date: 2021-11-23T10:17:04+02:00
New Revision: d703b922961e0d02a5effdd4bfbb23ad50a3cc9f
URL: https://github.com/llvm/llvm-project/commit/d703b922961e0d02a5effdd4bfbb23ad50a3cc9f
DIFF: https://github.com/llvm/llvm-project/commit/d703b922961e0d02a5effdd4bfbb23ad50a3cc9f.diff
LOG: [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
Added:
Modified:
lld/COFF/Writer.cpp
lld/test/COFF/strtab-size.s
lld/test/COFF/symtab.test
Removed:
################################################################################
diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp
index 600d14034dea8..0788f3519f4e0 100644
--- a/lld/COFF/Writer.cpp
+++ b/lld/COFF/Writer.cpp
@@ -1211,6 +1211,12 @@ void Writer::createSymbolAndStringTable() {
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/lld/test/COFF/strtab-size.s b/lld/test/COFF/strtab-size.s
index 574b1a0265ba6..153363baf8c71 100644
--- a/lld/test/COFF/strtab-size.s
+++ b/lld/test/COFF/strtab-size.s
@@ -213,4 +213,5 @@ sym191:
sym192:
sym193:
sym194:
+sym195:
ret
diff --git a/lld/test/COFF/symtab.test b/lld/test/COFF/symtab.test
index 1d47def32c8fc..949e9604bfd89 100644
--- a/lld/test/COFF/symtab.test
+++ b/lld/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 @@ symbols:
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
...
More information about the llvm-commits
mailing list