[PATCH] D27201: [ELF] - Do not create 4gb output when -obinary -Ttext and -omagic used together. (variant 2)

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 29 04:33:23 PST 2016


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar, evgeny777, emaste.

This is the same like https://reviews.llvm.org/D27200 but uses a different approach.
https://reviews.llvm.org/D27200 eliminates the excessive PT_LOAD, but this one has less changes.
What does look better ?


https://reviews.llvm.org/D27201

Files:
  ELF/Writer.cpp
  test/ELF/oformat-binary-ttext.s


Index: test/ELF/oformat-binary-ttext.s
===================================================================
--- test/ELF/oformat-binary-ttext.s
+++ test/ELF/oformat-binary-ttext.s
@@ -0,0 +1,18 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+
+# RUN: ld.lld -N -Ttext 0x100 -o %t.out %t --oformat binary
+# RUN: od -t x1 -v %t.out | FileCheck %s --check-prefix=BIN
+
+# BIN:      0000000 90 00 00 00 00 00 00 00
+# BIN-NEXT: 0000010
+# BIN-NOT:  0000020
+
+## The same but without OMAGIC.
+# RUN: ld.lld -Ttext 0x100 -o %t.out %t --oformat binary
+# RUN: od -t x1 -v %t.out | FileCheck %s --check-prefix=BIN
+
+.text
+.globl _start
+_start:
+ nop
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -1125,7 +1125,7 @@
   // Add the first PT_LOAD segment for regular output sections.
   uintX_t Flags = computeFlags<ELFT>(PF_R);
   Phdr *Load = AddHdr(PT_LOAD, Flags);
-  if (!ScriptConfig->HasSections) {
+  if (!Config->OFormatBinary && !ScriptConfig->HasSections) {
     Load->add(Out<ELFT>::ElfHeader);
     Load->add(Out<ELFT>::ProgramHeaders);
   }
@@ -1234,8 +1234,9 @@
 // The first section of each PT_LOAD and the first section after PT_GNU_RELRO
 // have to be page aligned so that the dynamic linker can set the permissions.
 template <class ELFT> void Writer<ELFT>::fixSectionAlignments() {
+  // Load can be empty if we produce binary output.
   for (const Phdr &P : Phdrs)
-    if (P.H.p_type == PT_LOAD)
+    if (P.H.p_type == PT_LOAD && P.First)
       P.First->PageAlign = true;
 
   for (const Phdr &P : Phdrs) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27201.79539.patch
Type: text/x-patch
Size: 1685 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161129/83fcce60/attachment.bin>


More information about the llvm-commits mailing list