diff --git a/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp b/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp --- a/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp +++ b/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp @@ -168,6 +168,11 @@ return SymbolTypeOrErr.takeError(); SymbolRef::Type SymbolType = *SymbolTypeOrErr; if (Obj.isELF()) { + // Ignore any symbols coming from sections that don't have runtime + // allocated memory. + if ((elf_section_iterator(*Sec)->getFlags() & ELF::SHF_ALLOC) == 0) + return Error::success(); + // Allow function and data symbols. Additionally allow STT_NONE, which are // common for functions defined in assembly. uint8_t Type = ELFSymbolRef(Symbol).getELFType(); diff --git a/llvm/test/DebugInfo/Symbolize/ELF/symtab-file2.yaml b/llvm/test/DebugInfo/Symbolize/ELF/symtab-file2.yaml --- a/llvm/test/DebugInfo/Symbolize/ELF/symtab-file2.yaml +++ b/llvm/test/DebugInfo/Symbolize/ELF/symtab-file2.yaml @@ -73,3 +73,39 @@ Index: SHN_ABS - Name: local Section: .text + +# RUN: yaml2obj --docnum=3 %s -o %t3 +# RUN: llvm-symbolizer --obj=%t3 'DATA 0x1001' 2>&1 | FileCheck %s --check-prefix=CHECK3 + +# CHECK3: code +# CHECK3-NEXT: 4096 2 +# CHECK3-NEXT: ??:? +# CHECK3-EMPTY: + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_DYN + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + Address: 0x1000 + Size: 1 + - Name: .debug + Type: SHT_PROGBITS + Address: 0x0000 + Size: 0xFFFF +Symbols: + - Name: debug + Section: .debug + Binding: STB_WEAK + Value: 0x1001 + Size: 0 + - Name: code + Section: .text + Binding: STB_WEAK + Value: 0x1000 + Size: 2