From: Shankar Easwaran Date: Mon, 10 Nov 2014 14:55:21 +0000 (+0000) Subject: [Gnu] Support --image-base option X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7757f1ace6dc8f0d9a5814dc7c9b5740663fc7af;p=platform%2Fupstream%2Fllvm.git [Gnu] Support --image-base option The value for --image-base is used as the base address of the program. llvm-svn: 221589 --- diff --git a/lld/include/lld/ReaderWriter/ELFLinkingContext.h b/lld/include/lld/ReaderWriter/ELFLinkingContext.h index d040560..9bcb8f6 100644 --- a/lld/include/lld/ReaderWriter/ELFLinkingContext.h +++ b/lld/include/lld/ReaderWriter/ELFLinkingContext.h @@ -76,6 +76,7 @@ public: uint16_t getOutputMachine() const; bool mergeCommonStrings() const { return _mergeCommonStrings; } virtual uint64_t getBaseAddress() const { return _baseAddress; } + virtual void setBaseAddress(uint64_t address) { _baseAddress = address; } void notifySymbolTableCoalesce(const Atom *existingAtom, const Atom *newAtom, bool &useNew) override; diff --git a/lld/lib/Driver/GnuLdDriver.cpp b/lld/lib/Driver/GnuLdDriver.cpp index 9400691..34c2da1 100644 --- a/lld/lib/Driver/GnuLdDriver.cpp +++ b/lld/lib/Driver/GnuLdDriver.cpp @@ -594,6 +594,19 @@ bool GnuLdDriver::parse(int argc, const char *argv[], ctx->setAlignSegments(false); break; + case OPT_image_base: { + ErrorOr baseAddress = + lld::parseNum(inputArg->getValue(), false); + if (baseAddress && baseAddress.get()) + ctx->setBaseAddress(baseAddress.get()); + else { + diagnostics << "invalid value for image base " << inputArg->getValue() + << "\n"; + return false; + } + break; + } + default: break; } // end switch on option ID diff --git a/lld/lib/Driver/GnuLdOptions.td b/lld/lib/Driver/GnuLdOptions.td index c3ed1426..4385c82 100644 --- a/lld/lib/Driver/GnuLdOptions.td +++ b/lld/lib/Driver/GnuLdOptions.td @@ -106,6 +106,9 @@ def no_whole_archive: Flag<["--"], "no-whole-archive">, def nostdlib : Flag<["-"], "nostdlib">, HelpText<"Disable default search path for libraries">, Group; +def image_base : Separate<["--"], "image-base">, + HelpText<"Set the base address">, + Group; //===----------------------------------------------------------------------===// /// Static Executable Options diff --git a/lld/test/elf/X86_64/imagebase.test b/lld/test/elf/X86_64/imagebase.test new file mode 100644 index 0000000..67c3b6e --- /dev/null +++ b/lld/test/elf/X86_64/imagebase.test @@ -0,0 +1,94 @@ +# Checks that segments start at the image address specified. + +# Build executable +# RUN: yaml2obj -format=elf -docnum 1 %s -o %t.o +# RUN: lld -flavor gnu -target x86_64 %t.o -o %t.exe -static \ +# RUN: --no-align-segments --noinhibit-exec --image-base 0x600000 +# RUN: llvm-readobj -program-headers %t.exe | FileCheck %s +# +#CHECK: VirtualAddress: 0x600000 +#CHECK: PhysicalAddress: 0x600000 +#CHECK: VirtualAddress: 0x600178 +#CHECK: PhysicalAddress: 0x600178 + +# object +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000010 + Content: 554889E5B864000000C745FC000000005DC366666666662E0F1F840000000000554889E531C05DC3 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '64000000' + - Name: .rodata + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '64000000' + - Name: .eh_frame + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x0000000000000008 + Content: 1400000000000000037A5200017810011B0C070890010000180000001C000000000000001200000000410E108602430D060000001800000038000000000000000800000000410E108602430D06000000 + - Name: .rela.eh_frame + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .eh_frame + Relocations: + - Offset: 0x0000000000000020 + Symbol: .text + Type: R_X86_64_PC32 + Addend: 0 + - Offset: 0x000000000000003C + Symbol: .text + Type: R_X86_64_PC32 + Addend: 32 +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .eh_frame + Type: STT_SECTION + Section: .eh_frame + Global: + - Name: foo + Type: STT_FUNC + Section: .text + Value: 0x0000000000000020 + Size: 0x0000000000000008 + - Name: main + Type: STT_FUNC + Section: .text + Size: 0x0000000000000012 + - Name: myval + Type: STT_OBJECT + Section: .bss + Size: 0x0000000000000004 + - Name: val + Type: STT_OBJECT + Section: .rodata + Size: 0x0000000000000004 +...