[llvm] 13f1bc4 - Don't populate the symbol table with symbols that don't belong to a section with the flag SHF_ALLOC

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 13 15:31:34 PDT 2022


Author: George Wright
Date: 2022-09-13T22:30:51Z
New Revision: 13f1bc41888e7d6555c532ba5fa925b9fe3e6b2f

URL: https://github.com/llvm/llvm-project/commit/13f1bc41888e7d6555c532ba5fa925b9fe3e6b2f
DIFF: https://github.com/llvm/llvm-project/commit/13f1bc41888e7d6555c532ba5fa925b9fe3e6b2f.diff

LOG: Don't populate the symbol table with symbols that don't belong to a section with the flag SHF_ALLOC

When populating the symbol table for an ELF object file, don't insert any symbols that come from ELF sections which don't have runtime allocated memory (typically debugging symbols).

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D133795

Added: 
    

Modified: 
    llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp
    llvm/test/DebugInfo/Symbolize/ELF/symtab-file2.yaml

Removed: 
    


################################################################################
diff  --git a/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp b/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp
index d8ee9264b64f4..5c65742a39f5e 100644
--- a/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp
+++ b/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp
@@ -168,6 +168,11 @@ Error SymbolizableObjectFile::addSymbol(const SymbolRef &Symbol,
     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
index 2d68eaa1e5baf..7cb65189ec500 100644
--- a/llvm/test/DebugInfo/Symbolize/ELF/symtab-file2.yaml
+++ b/llvm/test/DebugInfo/Symbolize/ELF/symtab-file2.yaml
@@ -73,3 +73,39 @@ Symbols:
     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


        


More information about the llvm-commits mailing list