Omit unused section symbols from the symbol table.
authorRafael Espindola <rafael.espindola@gmail.com>
Thu, 4 Jun 2015 15:33:30 +0000 (15:33 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Thu, 4 Jun 2015 15:33:30 +0000 (15:33 +0000)
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

16 files changed:
lib/MC/ELFObjectWriter.cpp
test/MC/ARM/arm-elf-symver.s
test/MC/ELF/alias.s
test/MC/ELF/basic-elf-32.s
test/MC/ELF/basic-elf-64.s
test/MC/ELF/comdat-dup-group-name.s
test/MC/ELF/comdat.s
test/MC/ELF/empty.s
test/MC/ELF/many-sections-2.s
test/MC/ELF/many-sections.s
test/MC/ELF/noexec.s
test/MC/ELF/reloc-same-name-section.s
test/MC/ELF/section-sym.s
test/MC/ELF/symver.s
test/MC/ELF/undef.s
test/MC/ELF/weakref.s

index f8cf7d2..b4e4106 100644 (file)
@@ -688,6 +688,8 @@ void ELFObjectWriter::RecordRelocation(MCAssembler &Asm,
     auto *ELFSec = cast_or_null<MCSectionELF>(SecA);
     const auto *SectionSymbol =
         ELFSec ? cast<MCSymbolELF>(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;
 }
 
index 691c604..ce9c4fe 100644 (file)
@@ -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
index 8bbeb36..df39fd4 100644 (file)
@@ -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
index 16266af..1036b04 100644 (file)
@@ -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
index d99125e..b93f9ae 100644 (file)
@@ -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
index 6644e2b..e52f3dc 100644 (file)
 // CHECK-NOT: }
 // CHECK: Section: .group (0x7)
 
-// CHECK: Section: .foo (0x6)
-// CHECK: Section: .foo (0x8)
-
-
        .section        .foo,"axG",@progbits,f1,comdat
         nop
 
index e71dea0..18da17e 100644 (file)
@@ -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 (
index 6ddbd8c..7b686fe 100644 (file)
@@ -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:   }
index 5698fe6..0077552 100644 (file)
@@ -130,3 +130,4 @@ gen_sections4 m
 
 a:
 b = a + 1
+.long dm
index 43463ba..2db6abb 100644 (file)
@@ -106,3 +106,4 @@ gen_sections8 l
         .section foo
         .section bar
         .section zed
+.long zed
index d3d5cd4..e8f460e 100644 (file)
@@ -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:
 // 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:   }
index e63ea54..57463c6 100644 (file)
@@ -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:   }
index 389ffd7..4a9484d 100644 (file)
 // 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: ]
index ece651e..0f434dd 100644 (file)
@@ -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
index dcb1660..9577ea2 100644 (file)
@@ -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
index 76e420a..d342c61 100644 (file)
@@ -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