[PATCH] D24668: [ELF] Linkerscript: do not fail if there is no space for program headers and there is PHDRS directive

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 20 21:48:31 PDT 2016


ruiu added inline comments.

================
Comment at: ELF/LinkerScript.cpp:472-479
@@ -471,10 +471,10 @@
       Out<ELFT>::ElfHeader->getSize() + Out<ELFT>::ProgramHeaders->getSize();
-  if (HeaderSize > MinVA)
+  if (HeaderSize > HeaderVA && !hasPhdrsCommands())
     fatal("Not enough space for ELF and program headers");
 
-  // ELF and Program headers need to be right before the first section in
-  // memory. Set their addresses accordingly.
-  MinVA = alignDown(MinVA - HeaderSize, Target->PageSize);
-  Out<ELFT>::ElfHeader->setVA(MinVA);
-  Out<ELFT>::ProgramHeaders->setVA(Out<ELFT>::ElfHeader->getSize() + MinVA);
+  HeaderVA = HeaderSize > HeaderVA
+                 ? alignTo(Dot, Target->PageSize)
+                 : alignDown(HeaderVA - HeaderSize, Target->PageSize);
+  Out<ELFT>::ElfHeader->setVA(HeaderVA);
+  Out<ELFT>::ProgramHeaders->setVA(Out<ELFT>::ElfHeader->getSize() + HeaderVA);
 }
----------------
I thought about this new code probably more than 15 minutes but am still not sure if this is correct. What is the problem you are trying to fix with this change?

================
Comment at: test/ELF/linkerscript/phdrs.s:23-28
@@ +22,8 @@
+## Check PHDR VA.
+# RUN: echo "PHDRS { header PT_PHDR PHDRS; other PT_LOAD; } \
+# RUN:       SECTIONS { \
+# RUN:           . = 0; \
+# RUN:           .text : {*(.text*)} : other \
+# RUN:           .foo : {*(.foo.*)} : other \
+# RUN:           .data : {*(.data.*)} : other }" > %t.script
+# RUN: ld.lld -o %t1 --script %t.script %t
----------------
Is this linker script expected to create a valid executable?


Repository:
  rL LLVM

https://reviews.llvm.org/D24668





More information about the llvm-commits mailing list