[PATCH] D79038: [objdump][ELF] Handle sections not contained in PT_LOAD segments

LemonBoy via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 30 12:21:14 PDT 2020


LemonBoy updated this revision to Diff 261311.
LemonBoy added a comment.

Simplify the patch by making sure `PT_GNU_STACK` segments cannot be considered parents of any section.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79038/new/

https://reviews.llvm.org/D79038

Files:
  llvm/test/tools/llvm-objcopy/ELF/binary-paddr.test
  llvm/tools/llvm-objcopy/ELF/Object.cpp


Index: llvm/tools/llvm-objcopy/ELF/Object.cpp
===================================================================
--- llvm/tools/llvm-objcopy/ELF/Object.cpp
+++ llvm/tools/llvm-objcopy/ELF/Object.cpp
@@ -1065,6 +1065,11 @@
   // not the first.
   uint64_t SecSize = Sec.Size ? Sec.Size : 1;
 
+  // Skip PT_GNU_STACK segments, they only exist to define the stack
+  // executability and its size and don't refer to a real memory area.
+  if (Seg.Type == PT_GNU_STACK)
+    return false;
+
   if (Sec.Type == SHT_NOBITS) {
     if (!(Sec.Flags & SHF_ALLOC))
       return false;
Index: llvm/test/tools/llvm-objcopy/ELF/binary-paddr.test
===================================================================
--- llvm/test/tools/llvm-objcopy/ELF/binary-paddr.test
+++ llvm/test/tools/llvm-objcopy/ELF/binary-paddr.test
@@ -129,3 +129,47 @@
     VAddr: 0x3000
     Sections:
       - Section: .data
+
+## Check that the LMA is correctly calculated for sections not contained in a
+## PT_LOAD segment.
+
+# RUN: yaml2obj --docnum=4 %s -o %t4
+# RUN: llvm-objcopy -O binary %t4 %t4.out
+# RUN: od -A x -t x1 %t4.out | FileCheck %s --check-prefix=CHECK4 --ignore-case
+# RUN: wc -c %t4.out | FileCheck %s --check-prefix=SIZE4
+
+# CHECK4:      90 90 90 90 90 90 90 c3
+# SIZE4:       8
+
+--- !ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_EXEC
+  Machine:         EM_X86_64
+Sections:
+  - Name:            .text
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
+    Address:         0x8000
+    AddressAlign:    0x8
+    Content:         90909090909090C3
+  - Name:            .bss
+    Type:            SHT_NOBITS
+    Flags:           [ SHF_ALLOC, SHF_WRITE ]
+    Address:         0x8008
+    AddressAlign:    0x1
+    Size:            0x4
+ProgramHeaders:
+  - Type: PT_LOAD
+    Flags: [ PF_R, PF_X ]
+    VAddr: 0x8000
+    Sections:
+      - Section: .text
+  - Type: PT_GNU_STACK
+    Flags: [ PF_R, PF_W ]
+    VAddr: 0x0000
+    FileSize: 0x0000
+    Align: 0x0000
+    # The huge size makes this phdr a parent of .bss
+    MemSize: 0x1000000


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79038.261311.patch
Type: text/x-patch
Size: 2140 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200430/c857baef/attachment.bin>


More information about the llvm-commits mailing list