diff options
| -rw-r--r-- | lld/ELF/LinkerScript.cpp | 5 | ||||
| -rw-r--r-- | lld/ELF/Writer.cpp | 7 | ||||
| -rw-r--r-- | lld/test/ELF/linkerscript/ttext-script.s | 11 |
3 files changed, 18 insertions, 5 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 327a962384a..5f66712107c 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -464,11 +464,6 @@ void LinkerScript::fabricateDefaultCommands() { 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>(""); diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 4ff06388ec7..17e62a5bec3 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1231,6 +1231,13 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() { 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. diff --git a/lld/test/ELF/linkerscript/ttext-script.s b/lld/test/ELF/linkerscript/ttext-script.s new file mode 100644 index 00000000000..9dcde9bb13c --- /dev/null +++ b/lld/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 |

