[PATCH] D25323: [ELF] Don't emit empty PT_LOAD segment

Eugene Leviant via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 6 06:32:51 PDT 2016


evgeny777 created this revision.
evgeny777 added reviewers: ruiu, rafael.
evgeny777 added subscribers: grimar, ikudrin, llvm-commits.
evgeny777 set the repository for this revision to rL LLVM.
evgeny777 added a project: lld.

This can happen when:

- Linker script puts RW section first.
- There is no place for program headers.


Repository:
  rL LLVM

https://reviews.llvm.org/D25323

Files:
  ELF/Writer.cpp
  test/ELF/linkerscript/empty-load.s


Index: test/ELF/linkerscript/empty-load.s
===================================================================
--- test/ELF/linkerscript/empty-load.s
+++ test/ELF/linkerscript/empty-load.s
@@ -0,0 +1,22 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: echo "SECTIONS { .rw : { *(.rw) } .text : { *(.text) }  }" > %t.script
+# RUN: ld.lld -o %t1 --script %t.script %t
+# RUN: llvm-objdump -private-headers %t1 | FileCheck %s
+
+## We expect 2 PT_LOAD segments
+# CHECK:       PHDR
+# CHECK-NEXT:     filesz
+# CHECK-NEXT:  LOAD
+# CHECK-NEXT:     filesz
+# CHECK-NEXT:  LOAD
+# CHECK-NEXT:     filesz
+# CHECK-NEXT:  STACK
+# CHECK-NEXT:     filesz
+
+.globl _start
+_start:
+  jmp _start
+
+.section .rw, "aw"
+ .quad 0
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -1248,6 +1248,11 @@
         H.p_memsz = alignTo(H.p_memsz, H.p_align);
     }
   }
+
+  Phdrs.erase(
+      std::remove_if(Phdrs.begin(), Phdrs.end(),
+                     [](Phdr &P) { return !P.First && P.H.p_type == PT_LOAD; }),
+      Phdrs.end());
 }
 
 template <class ELFT> static typename ELFT::uint getEntryAddr() {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25323.73792.patch
Type: text/x-patch
Size: 1224 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161006/75bc402e/attachment.bin>


More information about the llvm-commits mailing list