[PATCH] D34313: Prefer -Ttext over linker script values
Rafael Ávila de Espíndola via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 16 18:24:01 PDT 2017
rafael created this revision.
Herald added a subscriber: emaste.
I found this while trying to build u-boot. It uses -Ttext in combination with linker scripts.
My first reaction was to change the linker scripts to have the correct value, but I found that it is actually quite convenient to have -Ttext take precedence.
By having just
.text : { *(.text) }
In the script, they can define the text address in a single Makefile and pass it to ld with -Ttext and for the C code with -DFoo=value. Doing the same with linker scripts would require them to be generated during the build.
https://reviews.llvm.org/D34313
Files:
ELF/LinkerScript.cpp
ELF/Writer.cpp
test/ELF/linkerscript/ttext-script.s
Index: test/ELF/linkerscript/ttext-script.s
===================================================================
--- /dev/null
+++ test/ELF/linkerscript/ttext-script.s
@@ -0,0 +1,11 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: echo "SECTIONS { .text 0x200000 : { *(.text) } }" > %t.script
+# RUN: ld.lld -T %t.script -Ttext 0x100000 %t.o -o %t
+# RUN: llvm-readobj --elf-output-style=GNU -s %t | FileCheck %s
+
+# CHECK: .text PROGBITS 0000000000100000
+
+.global _start
+_start:
+nop
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -1231,6 +1231,13 @@
if (auto *Cmd = dyn_cast<OutputSectionCommand>(Base))
OutputSectionCommands.push_back(Cmd);
+ // Prefer command line supplied address over other constraints.
+ for (OutputSectionCommand *Cmd : OutputSectionCommands) {
+ auto I = Config->SectionStartMap.find(Cmd->Name);
+ if (I != Config->SectionStartMap.end())
+ Cmd->AddrExpr = [=] { return I->second; };
+ }
+
// This is a bit of a hack. A value of 0 means undef, so we set it
// to 1 t make __ehdr_start defined. The section number is not
// particularly relevant.
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -464,11 +464,6 @@
OSCmd->Sec = Sec;
SecToCommand[Sec] = OSCmd;
- // Prefer user supplied address over additional alignment constraint
- auto I = Config->SectionStartMap.find(Sec->Name);
- if (I != Config->SectionStartMap.end())
- OSCmd->AddrExpr = [=] { return I->second; };
-
Commands.push_back(OSCmd);
if (Sec->Sections.size()) {
auto *ISD = make<InputSectionDescription>("");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34313.102922.patch
Type: text/x-patch
Size: 1830 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170617/be2382ad/attachment.bin>
More information about the llvm-commits
mailing list