Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -308,7 +308,8 @@ } template -static bool shouldKeepInSymtab(InputSectionBase *Sec, StringRef SymName, +static bool shouldKeepInSymtab(elf::ObjectFile *F, + InputSectionBase *Sec, StringRef SymName, const SymbolBody &B) { if (B.isFile()) return false; @@ -335,7 +336,7 @@ if (Config->Discard == DiscardPolicy::Locals) return false; - return !(Sec->getSectionHdr()->sh_flags & SHF_MERGE); + return !(Sec && Sec->getSectionHdr()->sh_flags & SHF_MERGE); } template static bool includeInSymtab(const SymbolBody &B) { @@ -374,7 +375,7 @@ fatal(getFilename(F) + ": invalid symbol name offset"); StringRef SymName(StrTab.data() + B->getNameOffset()); InputSectionBase *Sec = DR->Section; - if (!shouldKeepInSymtab(Sec, SymName, *B)) + if (!shouldKeepInSymtab(F, Sec, SymName, *B)) continue; ++Out::SymTab->NumLocals; if (Config->Relocatable) Index: test/ELF/local.s =================================================================== --- test/ELF/local.s +++ test/ELF/local.s @@ -1,5 +1,5 @@ // Check that symbol table is correctly populated with local symbols. -// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t +// RUN: llvm-mc -save-temp-labels -filetype=obj -triple=x86_64-pc-linux %s -o %t // RUN: ld.lld %t -o %t1 // RUN: llvm-readobj -t -s %t1 | FileCheck %s // REQUIRES: x86 @@ -14,7 +14,7 @@ // CHECK-NEXT: Offset: // CHECK-NEXT: Size: // CHECK-NEXT: Link: -// CHECK-NEXT: Info: 5 +// CHECK-NEXT: Info: 6 // CHECK: Symbols [ // CHECK-NEXT: Symbol { @@ -27,6 +27,15 @@ // CHECK-NEXT: Section: Undefined // CHECK-NEXT: } // CHECK-NEXT: Symbol { +// CHECK-NEXT: Name: .Labs +// CHECK-NEXT: Value: 0x2B +// CHECK-NEXT: Size: 0 +// CHECK-NEXT: Binding: Local +// CHECK-NEXT: Type: None +// CHECK-NEXT: Other: 0 +// CHECK-NEXT: Section: Absolute +// CHECK-NEXT: } +// CHECK-NEXT: Symbol { // CHECK-NEXT: Name: abs // CHECK-NEXT: Value: 0x2A // CHECK-NEXT: Size: 0 @@ -80,3 +89,4 @@ foo: goo: abs = 42 +.Labs = 43