[PATCH] D133795: Don't populate the symbol table with symbols that don't belong to a section with the flag SHF_ALLOC

George Wright via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 13 11:25:18 PDT 2022


gw280 created this revision.
gw280 added a reviewer: dblaikie.
Herald added subscribers: hiraditya, emaste.
Herald added a project: All.
gw280 requested review of this revision.
Herald added subscribers: llvm-commits, MaskRay.
Herald added a project: LLVM.

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).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133795

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


Index: llvm/test/DebugInfo/Symbolize/ELF/symtab-file2.yaml
===================================================================
--- llvm/test/DebugInfo/Symbolize/ELF/symtab-file2.yaml
+++ 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
Index: llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp
===================================================================
--- llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp
+++ llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp
@@ -168,6 +168,13 @@
     return SymbolTypeOrErr.takeError();
   SymbolRef::Type SymbolType = *SymbolTypeOrErr;
   if (Obj.isELF()) {
+    // Ignore any symbols coming from sections that don't have runtime
+    // allocated memory.
+    elf_section_iterator ESec(Sec.get());
+    if ((ESec->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();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133795.459822.patch
Type: text/x-patch
Size: 1890 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220913/3c3025d4/attachment.bin>


More information about the llvm-commits mailing list