[PATCH] D38360: [ELF] Set Dot initially to --image-base value when using linker scripts
James Henderson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 4 09:06:27 PDT 2017
jhenderson updated this revision to Diff 117682.
jhenderson added a comment.
Address review comment.
@grimar - I don't think the new variable should be in ScriptConfiguration. >From what I can tell, ScriptConfiguration is intended for settings controlled by the linker script, which this is not. This is controlled by the command-line.
https://reviews.llvm.org/D38360
Files:
ELF/Config.h
ELF/Driver.cpp
ELF/LinkerScript.cpp
test/ELF/linkerscript/image-base.s
Index: test/ELF/linkerscript/image-base.s
===================================================================
--- test/ELF/linkerscript/image-base.s
+++ test/ELF/linkerscript/image-base.s
@@ -0,0 +1,18 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: echo "SECTIONS { mysym = .; }" > %t.script
+
+# RUN: ld.lld %t.o -o %t-default.elf -T %t.script
+# RUN: llvm-readobj --symbols %t-default.elf | FileCheck %s --check-prefix=DEFAULT
+# DEFAULT: Name: mysym
+# DEFAULT-NEXT: Value: 0x0
+
+# RUN: ld.lld %t.o -o %t-switch.elf -T %t.script --image-base=0x100000
+# RUN: llvm-readobj --symbols %t-switch.elf | FileCheck %s --check-prefix=SWITCH
+# SWITCH: Name: mysym
+# SWITCH-NEXT: Value: 0x100000
+
+.global _start
+_start:
+ nop
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -365,7 +365,7 @@
// script parser.
CurAddressState = State.get();
CurAddressState->OutSec = Aether;
- Dot = 0;
+ Dot = Config->InitialDot;
for (size_t I = 0; I < Opt.Commands.size(); ++I) {
// Handle symbol assignments outside of any output section.
@@ -775,7 +775,7 @@
void LinkerScript::assignAddresses() {
// Assign addresses as instructed by linker script SECTIONS sub-commands.
- Dot = 0;
+ Dot = Config->InitialDot;
auto State = make_unique<AddressState>(Opt);
// CurAddressState captures the local AddressState and makes it accessible
// deliberately. This is needed as there are some cases where we cannot just
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -992,6 +992,7 @@
Config->MaxPageSize = getMaxPageSize(Args);
Config->ImageBase = getImageBase(Args);
+ Config->InitialDot = Args.hasArg(OPT_image_base) ? Config->ImageBase : 0;
// Default output filename is "a.out" by the Unix tradition.
if (Config->OutputFile.empty())
Index: ELF/Config.h
===================================================================
--- ELF/Config.h
+++ ELF/Config.h
@@ -174,6 +174,7 @@
uint16_t EMachine = llvm::ELF::EM_NONE;
uint64_t ErrorLimit = 20;
uint64_t ImageBase;
+ uint64_t InitialDot;
uint64_t MaxPageSize;
uint64_t ZStackSize;
unsigned LTOPartitions;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38360.117682.patch
Type: text/x-patch
Size: 2385 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171004/6ff01a6d/attachment.bin>
More information about the llvm-commits
mailing list