[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
This commit is contained in:
Martin Storsjö 2021-11-13 10:13:42 +02:00
parent 4e5488afb2
commit d703b92296
3 changed files with 13 additions and 27 deletions

View File

@ -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);

View File

@ -213,4 +213,5 @@ sym191:
sym192:
sym193:
sym194:
sym195:
ret

View File

@ -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
...