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 = 0; uint64_t MaxPageSize; uint64_t ZStackSize; unsigned LTOPartitions; Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -925,6 +925,8 @@ } if ((V % Config->MaxPageSize) != 0) warn("-image-base: address isn't multiple of page size: " + S); + + Config->InitialDot = V; return V; } 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. @@ -776,7 +776,7 @@ void LinkerScript::assignAddresses() { // Assign addresses as instructed by linker script SECTIONS sub-commands. - Dot = 0; + Dot = Config->InitialDot; auto State = make_unique(Opt); // CurAddressState captures the local AddressState and makes it accessible // deliberately. This is needed as there are some cases where we cannot just 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