[PATCH] D27200: [ELF] - Do not create 4gb output when -obinary -Ttext and -omagic used together.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 2 04:26:42 PST 2016
grimar updated this revision to Diff 80057.
grimar added a comment.
- Updated.
https://reviews.llvm.org/D27200
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
@@ -1114,8 +1114,17 @@
// 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) {
+
+ // Do not create PT_LOAD segment for binary output, it does not
+ // have file or program headers.
+ Phdr *Load = nullptr;
+ if (!Config->OFormatBinary)
+ Load = AddHdr(PT_LOAD, Flags);
+ // We do not place headers when have SECTIONS command here, because it is
+ // possible to have no place for them. We do it later when script assign
+ // sections addressed. But we still need to create this load for them for case
+ // when first section uses AT command and requires own PT_LOAD.
+ if (Load && !ScriptConfig->HasSections) {
Load->add(Out<ELFT>::ElfHeader);
Load->add(Out<ELFT>::ProgramHeaders);
}
@@ -1142,7 +1151,7 @@
// different flags or is loaded at a discontiguous address using AT linker
// script command.
uintX_t NewFlags = computeFlags<ELFT>(Sec->getPhdrFlags());
- if (Script<ELFT>::X->hasLMA(Sec->getName()) || Flags != NewFlags) {
+ if (!Load || Script<ELFT>::X->hasLMA(Sec->getName()) || Flags != NewFlags) {
Load = AddHdr(PT_LOAD, NewFlags);
Flags = NewFlags;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27200.80057.patch
Type: text/x-patch
Size: 2076 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161202/a6fa0f68/attachment.bin>
More information about the llvm-commits
mailing list