From 9f299abc056749f22fa2f18ce217b1ba5036f0fc Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 4 Jun 2015 15:33:30 +0000 Subject: [PATCH] Omit unused section symbols from the symbol table. Section symbols exist as an optimization: instead of having multiple relocations point to different symbols, many of them can point to a single section symbol. When that optimization is unused, a section symbol is also unused and adds no extra information to the object file. This saves a bit of space on the object files and makes the output of llvm-objdump -t easier to read and consequently some tests get quite a bit simpler. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239045 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/ELFObjectWriter.cpp | 8 +++-- test/MC/ARM/arm-elf-symver.s | 18 ----------- test/MC/ELF/alias.s | 8 ----- test/MC/ELF/basic-elf-32.s | 14 --------- test/MC/ELF/basic-elf-64.s | 10 ------ test/MC/ELF/comdat-dup-group-name.s | 4 --- test/MC/ELF/comdat.s | 2 +- test/MC/ELF/empty.s | 4 +-- test/MC/ELF/many-sections-2.s | 1 + test/MC/ELF/many-sections.s | 1 + test/MC/ELF/noexec.s | 12 +------- test/MC/ELF/reloc-same-name-section.s | 4 +-- test/MC/ELF/section-sym.s | 44 +++++++++++++++++++++++++-- test/MC/ELF/symver.s | 18 ----------- test/MC/ELF/undef.s | 36 ---------------------- test/MC/ELF/weakref.s | 18 ----------- 16 files changed, 55 insertions(+), 147 deletions(-) diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index f8cf7d2ea5d..b4e410622e0 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -688,6 +688,8 @@ void ELFObjectWriter::RecordRelocation(MCAssembler &Asm, auto *ELFSec = cast_or_null(SecA); const auto *SectionSymbol = ELFSec ? cast(ELFSec->getBeginSymbol()) : nullptr; + if (SectionSymbol) + SectionSymbol->setUsedInReloc(); ELFRelocationEntry Rec(FixupOffset, SectionSymbol, Type, Addend); Relocations[&FixupSection].push_back(Rec); return; @@ -733,12 +735,12 @@ bool ELFObjectWriter::isInSymtab(const MCAsmLayout &Layout, if (Symbol.isUndefined() && !Symbol.isBindingSet()) return false; - if (Symbol.getType() == ELF::STT_SECTION) - return true; - if (Symbol.isTemporary()) return false; + if (Symbol.getType() == ELF::STT_SECTION) + return false; + return true; } diff --git a/test/MC/ARM/arm-elf-symver.s b/test/MC/ARM/arm-elf-symver.s index 691c604c7f8..ce9c4fe5f00 100644 --- a/test/MC/ARM/arm-elf-symver.s +++ b/test/MC/ARM/arm-elf-symver.s @@ -87,24 +87,6 @@ global1: @ CHECK-NEXT: Section: .text @ CHECK-NEXT: } @ CHECK-NEXT: Symbol { -@ CHECK-NEXT: Name: (0) -@ CHECK-NEXT: Value: 0x0 -@ CHECK-NEXT: Size: 0 -@ CHECK-NEXT: Binding: Local (0x0) -@ CHECK-NEXT: Type: Section (0x3) -@ CHECK-NEXT: Other: 0 -@ CHECK-NEXT: Section: .data -@ CHECK-NEXT: } -@ CHECK-NEXT: Symbol { -@ CHECK-NEXT: Name: (0) -@ CHECK-NEXT: Value: 0x0 -@ CHECK-NEXT: Size: 0 -@ CHECK-NEXT: Binding: Local (0x0) -@ CHECK-NEXT: Type: Section (0x3) -@ CHECK-NEXT: Other: 0 -@ CHECK-NEXT: Section: .bss -@ CHECK-NEXT: } -@ CHECK-NEXT: Symbol { @ CHECK-NEXT: Name: bar2@zed @ CHECK-NEXT: Value: 0x0 @ CHECK-NEXT: Size: 0 diff --git a/test/MC/ELF/alias.s b/test/MC/ELF/alias.s index 8bbeb36ccb4..df39fd4be14 100644 --- a/test/MC/ELF/alias.s +++ b/test/MC/ELF/alias.s @@ -111,14 +111,6 @@ leaq .Llocal1(%rip), %rdi // CHECK-NOT: Symbol { // CHECK: } // CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: (0) -// CHECK-NOT: Symbol { -// CHECK: } -// CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: (0) -// CHECK-NOT: Symbol { -// CHECK: } -// CHECK-NEXT: Symbol { // CHECK-NEXT: Name: bar2 // CHECK-NEXT: Value: 0x0 // CHECK-NEXT: Size: 0 diff --git a/test/MC/ELF/basic-elf-32.s b/test/MC/ELF/basic-elf-32.s index 16266af7f44..1036b04a747 100644 --- a/test/MC/ELF/basic-elf-32.s +++ b/test/MC/ELF/basic-elf-32.s @@ -54,20 +54,6 @@ main: # @main // CHECK: ] // CHECK: Symbols [ -// CHECK: Symbol { -// CHECK: Binding: Local -// CHECK: Type: Section -// CHECK: } - -// CHECK: Symbol { -// CHECK: Binding: Local -// CHECK: Type: Section -// CHECK: } - -// CHECK: Symbol { -// CHECK: Binding: Local -// CHECK: Type: Section -// CHECK: } // CHECK: Symbol { // CHECK: Name: main diff --git a/test/MC/ELF/basic-elf-64.s b/test/MC/ELF/basic-elf-64.s index d99125e06a9..b93f9aebd3a 100644 --- a/test/MC/ELF/basic-elf-64.s +++ b/test/MC/ELF/basic-elf-64.s @@ -57,16 +57,6 @@ main: # @main // CHECK: Binding: Local // CHECK: Type: Section -// CHECK: Symbol { -// CHECK: Binding: Local -// CHECK: Type: Section -// CHECK: } - -// CHECK: Symbol { -// CHECK: Binding: Local -// CHECK: Type: Section -// CHECK: } - // CHECK: Symbol { // CHECK: Name: main // CHECK: Binding: Global diff --git a/test/MC/ELF/comdat-dup-group-name.s b/test/MC/ELF/comdat-dup-group-name.s index 6644e2b7675..e52f3dcc04d 100644 --- a/test/MC/ELF/comdat-dup-group-name.s +++ b/test/MC/ELF/comdat-dup-group-name.s @@ -24,10 +24,6 @@ // CHECK-NOT: } // CHECK: Section: .group (0x7) -// CHECK: Section: .foo (0x6) -// CHECK: Section: .foo (0x8) - - .section .foo,"axG",@progbits,f1,comdat nop diff --git a/test/MC/ELF/comdat.s b/test/MC/ELF/comdat.s index e71dea089c4..18da17e6118 100644 --- a/test/MC/ELF/comdat.s +++ b/test/MC/ELF/comdat.s @@ -46,7 +46,7 @@ // CHECK-NEXT: Offset: // CHECK-NEXT: Size: 12 // CHECK-NEXT: Link: -// CHECK-NEXT: Info: 10 +// CHECK-NEXT: Info: 3 // CHECK-NEXT: AddressAlignment: 4 // CHECK-NEXT: EntrySize: 4 // CHECK-NEXT: SectionData ( diff --git a/test/MC/ELF/empty.s b/test/MC/ELF/empty.s index 6ddbd8c942a..7b686fef3a2 100644 --- a/test/MC/ELF/empty.s +++ b/test/MC/ELF/empty.s @@ -78,9 +78,9 @@ // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 // CHECK-NEXT: Offset: -// CHECK-NEXT: Size: 96 +// CHECK-NEXT: Size: 24 // CHECK-NEXT: Link: -// CHECK-NEXT: Info: 4 +// CHECK-NEXT: Info: 1 // CHECK-NEXT: AddressAlignment: 8 // CHECK-NEXT: EntrySize: 24 // CHECK-NEXT: } diff --git a/test/MC/ELF/many-sections-2.s b/test/MC/ELF/many-sections-2.s index 5698fe6ce39..0077552ef31 100644 --- a/test/MC/ELF/many-sections-2.s +++ b/test/MC/ELF/many-sections-2.s @@ -130,3 +130,4 @@ gen_sections4 m a: b = a + 1 +.long dm diff --git a/test/MC/ELF/many-sections.s b/test/MC/ELF/many-sections.s index 43463ba666e..2db6abb9321 100644 --- a/test/MC/ELF/many-sections.s +++ b/test/MC/ELF/many-sections.s @@ -106,3 +106,4 @@ gen_sections8 l .section foo .section bar .section zed +.long zed diff --git a/test/MC/ELF/noexec.s b/test/MC/ELF/noexec.s index d3d5cd49112..e8f460e65fa 100644 --- a/test/MC/ELF/noexec.s +++ b/test/MC/ELF/noexec.s @@ -1,4 +1,4 @@ -// RUN: llvm-mc -no-exec-stack -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | llvm-readobj -s -t | FileCheck %s +// RUN: llvm-mc -no-exec-stack -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | llvm-readobj -s | FileCheck %s // CHECK: Section { // CHECK: Index: @@ -14,13 +14,3 @@ // CHECK-NEXT: AddressAlignment: 1 // CHECK-NEXT: EntrySize: 0 // CHECK-NEXT: } - -// CHECK: Symbol { -// CHECK: Name: (0) -// CHECK: Value: 0x0 -// CHECK: Size: 0 -// CHECK: Binding: Local -// CHECK: Type: Section -// CHECK: Other: 0 -// CHECK: Section: .note.GNU-stack -// CHECK-NEXT: } diff --git a/test/MC/ELF/reloc-same-name-section.s b/test/MC/ELF/reloc-same-name-section.s index e63ea548e5a..57463c65f89 100644 --- a/test/MC/ELF/reloc-same-name-section.s +++ b/test/MC/ELF/reloc-same-name-section.s @@ -7,13 +7,13 @@ // CHECK-NEXT: Relocation { // CHECK-NEXT: Offset: // CHECK-NEXT: Type: -// CHECK-NEXT: Symbol: .foo (7) +// CHECK-NEXT: Symbol: .foo (4) // CHECK-NEXT: Addend: // CHECK-NEXT: } // CHECK-NEXT: Relocation { // CHECK-NEXT: Offset: // CHECK-NEXT: Type: -// CHECK-NEXT: Symbol: .foo (8) +// CHECK-NEXT: Symbol: .foo (5) // CHECK-NEXT: Addend: // CHECK-NEXT: } // CHECK-NEXT: } diff --git a/test/MC/ELF/section-sym.s b/test/MC/ELF/section-sym.s index 389ffd728ec..4a9484d9b77 100644 --- a/test/MC/ELF/section-sym.s +++ b/test/MC/ELF/section-sym.s @@ -40,14 +40,54 @@ // CHECK-NEXT: EntrySize: 0 // CHECK-NEXT: } -// The relocation points to symbol 6 +// The relocation points to symbol 3 // CHECK: Relocations [ // CHECK-NEXT: Section ({{.*}}) .relabar { // CHECK-NEXT: Relocation { // CHECK-NEXT: Offset: 0x0 // CHECK-NEXT: Type: R_X86_64_32 (10) -// CHECK-NEXT: Symbol: foo (6) +// CHECK-NEXT: Symbol: foo (3) // CHECK-NEXT: Addend: 0x0 // CHECK-NEXT: } // CHECK-NEXT: } // CHECK-NEXT: ] + +// Symbol 3 is section 6 +// CHECK: Symbols [ +// CHECK-NEXT: Symbol { +// CHECK-NEXT: Name: (0) +// CHECK-NEXT: Value: 0x0 +// CHECK-NEXT: Size: 0 +// CHECK-NEXT: Binding: Local (0x0) +// CHECK-NEXT: Type: None (0x0) +// CHECK-NEXT: Other: 0 +// CHECK-NEXT: Section: Undefined (0x0) +// CHECK-NEXT: } +// CHECK-NEXT: Symbol { +// CHECK-NEXT: Name: f1 (57) +// CHECK-NEXT: Value: 0x0 +// CHECK-NEXT: Size: 0 +// CHECK-NEXT: Binding: Local (0x0) +// CHECK-NEXT: Type: None (0x0) +// CHECK-NEXT: Other: 0 +// CHECK-NEXT: Section: .group (0x5) +// CHECK-NEXT: } +// CHECK-NEXT: Symbol { +// CHECK-NEXT: Name: f2 (54) +// CHECK-NEXT: Value: 0x0 +// CHECK-NEXT: Size: 0 +// CHECK-NEXT: Binding: Local (0x0) +// CHECK-NEXT: Type: None (0x0) +// CHECK-NEXT: Other: 0 +// CHECK-NEXT: Section: .group (0x7) +// CHECK-NEXT: } +// CHECK-NEXT: Symbol { +// CHECK-NEXT: Name: (0) +// CHECK-NEXT: Value: 0x0 +// CHECK-NEXT: Size: 0 +// CHECK-NEXT: Binding: Local (0x0) +// CHECK-NEXT: Type: Section (0x3) +// CHECK-NEXT: Other: 0 +// CHECK-NEXT: Section: foo (0x6) +// CHECK-NEXT: } +// CHECK-NEXT: ] diff --git a/test/MC/ELF/symver.s b/test/MC/ELF/symver.s index ece651e49fd..0f434dd859d 100644 --- a/test/MC/ELF/symver.s +++ b/test/MC/ELF/symver.s @@ -86,24 +86,6 @@ global1: // CHECK-NEXT: Section: .text // CHECK-NEXT: } // CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: (0) -// CHECK-NEXT: Value: 0x0 -// CHECK-NEXT: Size: 0 -// CHECK-NEXT: Binding: Local -// CHECK-NEXT: Type: Section -// CHECK-NEXT: Other: 0 -// CHECK-NEXT: Section: .data -// CHECK-NEXT: } -// CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: (0) -// CHECK-NEXT: Value: 0x0 -// CHECK-NEXT: Size: 0 -// CHECK-NEXT: Binding: Local -// CHECK-NEXT: Type: Section -// CHECK-NEXT: Other: 0 -// CHECK-NEXT: Section: .bss -// CHECK-NEXT: } -// CHECK-NEXT: Symbol { // CHECK-NEXT: Name: bar2@zed // CHECK-NEXT: Value: 0x0 // CHECK-NEXT: Size: 0 diff --git a/test/MC/ELF/undef.s b/test/MC/ELF/undef.s index dcb1660bbad..9577ea22875 100644 --- a/test/MC/ELF/undef.s +++ b/test/MC/ELF/undef.s @@ -42,42 +42,6 @@ test2_b = undef + 1 // CHECK-NEXT: Section: .rodata.str1.1 // CHECK-NEXT: } // CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: (0) -// CHECK-NEXT: Value: 0x0 -// CHECK-NEXT: Size: 0 -// CHECK-NEXT: Binding: Local -// CHECK-NEXT: Type: Section -// CHECK-NEXT: Other: 0 -// CHECK-NEXT: Section: .text -// CHECK-NEXT: } -// CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: (0) -// CHECK-NEXT: Value: 0x0 -// CHECK-NEXT: Size: 0 -// CHECK-NEXT: Binding: Local -// CHECK-NEXT: Type: Section -// CHECK-NEXT: Other: 0 -// CHECK-NEXT: Section: .data -// CHECK-NEXT: } -// CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: (0) -// CHECK-NEXT: Value: 0x0 -// CHECK-NEXT: Size: 0 -// CHECK-NEXT: Binding: Local -// CHECK-NEXT: Type: Section -// CHECK-NEXT: Other: 0 -// CHECK-NEXT: Section: .bss -// CHECK-NEXT: } -// CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: (0) -// CHECK-NEXT: Value: 0x0 -// CHECK-NEXT: Size: 0 -// CHECK-NEXT: Binding: Local -// CHECK-NEXT: Type: Section -// CHECK-NEXT: Other: 0 -// CHECK-NEXT: Section: .rodata.str1.1 -// CHECK-NEXT: } -// CHECK-NEXT: Symbol { // CHECK-NEXT: Name: .Lsym1 // CHECK-NEXT: Value: 0x0 // CHECK-NEXT: Size: 0 diff --git a/test/MC/ELF/weakref.s b/test/MC/ELF/weakref.s index 76e420a73e7..d342c61f745 100644 --- a/test/MC/ELF/weakref.s +++ b/test/MC/ELF/weakref.s @@ -125,24 +125,6 @@ bar15: // CHECK-NEXT: Section: .text // CHECK-NEXT: } // CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: (0) -// CHECK-NEXT: Value: 0x0 -// CHECK-NEXT: Size: 0 -// CHECK-NEXT: Binding: Local -// CHECK-NEXT: Type: Section -// CHECK-NEXT: Other: 0 -// CHECK-NEXT: Section: .data -// CHECK-NEXT: } -// CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: (0) -// CHECK-NEXT: Value: 0x0 -// CHECK-NEXT: Size: 0 -// CHECK-NEXT: Binding: Local -// CHECK-NEXT: Type: Section -// CHECK-NEXT: Other: 0 -// CHECK-NEXT: Section: .bss -// CHECK-NEXT: } -// CHECK-NEXT: Symbol { // CHECK-NEXT: Name: bar10 // CHECK-NEXT: Value: 0x28 // CHECK-NEXT: Size: 0 -- 2.34.1