[lld] r247089 - [lld][elf2] Fix hard coded entry address.
Michael Spencer via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 8 15:53:18 PDT 2015
Fixed in r247096.
- Michael Spencer
On Tue, Sep 8, 2015 at 3:43 PM, Rui Ueyama <ruiu at google.com> wrote:
> On Wed, Sep 9, 2015 at 7:34 AM, Michael J. Spencer via llvm-commits
> <llvm-commits at lists.llvm.org> wrote:
>>
>> Author: mspencer
>> Date: Tue Sep 8 17:34:57 2015
>> New Revision: 247089
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=247089&view=rev
>> Log:
>> [lld][elf2] Fix hard coded entry address.
>>
>> Modified:
>> lld/trunk/ELF/SymbolTable.cpp
>> lld/trunk/ELF/SymbolTable.h
>> lld/trunk/ELF/Writer.cpp
>> lld/trunk/test/elf2/basic.s
>> lld/trunk/test/elf2/basic32.s
>> lld/trunk/test/elf2/basic32be.s
>> lld/trunk/test/elf2/basic64be.s
>>
>> Modified: lld/trunk/ELF/SymbolTable.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=247089&r1=247088&r2=247089&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/ELF/SymbolTable.cpp (original)
>> +++ lld/trunk/ELF/SymbolTable.cpp Tue Sep 8 17:34:57 2015
>> @@ -17,7 +17,7 @@ using namespace llvm::object;
>> using namespace lld;
>> using namespace lld::elf2;
>>
>> -SymbolTable::SymbolTable() {
>> +SymbolTable::SymbolTable() : EntrySym(nullptr) {
>> }
>>
>> void SymbolTable::addFile(std::unique_ptr<InputFile> File) {
>> @@ -33,8 +33,10 @@ void SymbolTable::addFile(std::unique_pt
>> }
>>
>> template <class ELFT> void SymbolTable::init() {
>> - resolve<ELFT>(new (Alloc)
>> - Undefined<ELFT>("_start",
>> Undefined<ELFT>::Synthetic));
>> + if (EntrySym)
>> + return;
>
>
> How can this guarded condition happen?
>
>>
>> + EntrySym = new (Alloc) Undefined<ELFT>("_start",
>> Undefined<ELFT>::Synthetic);
>> + resolve<ELFT>(EntrySym);
>> }
>>
>> template <class ELFT> void SymbolTable::addELFFile(ELFFileBase *File) {
>>
>> Modified: lld/trunk/ELF/SymbolTable.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=247089&r1=247088&r2=247089&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/ELF/SymbolTable.h (original)
>> +++ lld/trunk/ELF/SymbolTable.h Tue Sep 8 17:34:57 2015
>> @@ -54,6 +54,10 @@ public:
>> return SharedFiles;
>> }
>>
>> + SymbolBody *getEntrySym() const {
>> + return EntrySym;
>> + }
>
>
> You may want to return EntrySym->getReplacement() instead of requiring all
> calling sides to do that.
>
>>
>> +
>> private:
>> Symbol *insert(SymbolBody *New);
>> template <class ELFT> void addELFFile(ELFFileBase *File);
>> @@ -73,6 +77,8 @@ private:
>> std::vector<std::unique_ptr<ObjectFileBase>> ObjectFiles;
>>
>> std::vector<std::unique_ptr<SharedFileBase>> SharedFiles;
>> +
>> + SymbolBody *EntrySym;
>
>
> Use C++11 member initialization -- SymbolBody *EntrySym = nullptr;
>
>>
>> };
>>
>> } // namespace elf2
>>
>> Modified: lld/trunk/ELF/Writer.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=247089&r1=247088&r2=247089&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/ELF/Writer.cpp (original)
>> +++ lld/trunk/ELF/Writer.cpp Tue Sep 8 17:34:57 2015
>> @@ -577,7 +577,8 @@ template <class ELFT> void Writer<ELFT>:
>> auto &FirstObj = cast<ObjectFile<ELFT>>(*Symtab.getFirstELF());
>> EHdr->e_machine = FirstObj.getEMachine();
>> EHdr->e_version = EV_CURRENT;
>> - EHdr->e_entry = 0x401000;
>> + EHdr->e_entry = getSymVA(
>> +
>> cast<DefinedRegular<ELFT>>(Symtab.getEntrySym()->getReplacement()));
>> EHdr->e_phoff = sizeof(Elf_Ehdr);
>> EHdr->e_shoff = SectionHeaderOff;
>> EHdr->e_ehsize = sizeof(Elf_Ehdr);
>>
>> Modified: lld/trunk/test/elf2/basic.s
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic.s?rev=247089&r1=247088&r2=247089&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/test/elf2/basic.s (original)
>> +++ lld/trunk/test/elf2/basic.s Tue Sep 8 17:34:57 2015
>> @@ -1,6 +1,7 @@
>> # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
>> # RUN: lld -flavor gnu2 %t -o %t2
>> -# RUN: llvm-readobj -file-headers -sections -program-headers %t2 |
>> FileCheck %s
>> +# RUN: llvm-readobj -file-headers -sections -program-headers -symbols %t2
>> \
>> +# RUN: | FileCheck %s
>> # REQUIRES: x86
>>
>> # exits with return code 42 on linux
>> @@ -23,7 +24,7 @@ _start:
>> # CHECK-NEXT: Type: Executable (0x2)
>> # CHECK-NEXT: Machine: EM_X86_64 (0x3E)
>> # CHECK-NEXT: Version: 1
>> -# CHECK-NEXT: Entry: 0x401000
>> +# CHECK-NEXT: Entry: [[ENTRY:0x[0-9A-F]+]]
>> # CHECK-NEXT: ProgramHeaderOffset: 0x40
>> # CHECK-NEXT: SectionHeaderOffset: 0x1070
>> # CHECK-NEXT: Flags [ (0x0)
>> @@ -127,6 +128,26 @@ _start:
>> # CHECK-NEXT: EntrySize: 0
>> # CHECK-NEXT: }
>> # CHECK-NEXT: ]
>> +# CHECK-NEXT: Symbols [
>> +# CHECK-NEXT: Symbol {
>> +# CHECK-NEXT: Name: (0)
>> +# CHECK-NEXT: Value: 0x0
>> +# CHECK-NEXT: Size: 0
>> +# CHECK-NEXT: Binding: Local (0x0)
>> +# CHECK-NEXT: Type: None (0x0)
>> +# CHECK-NEXT: Other: 0
>> +# CHECK-NEXT: Section: Undefined (0x0)
>> +# CHECK-NEXT: }
>> +# CHECK-NEXT: Symbol {
>> +# CHECK-NEXT: Name: _start (7)
>> +# CHECK-NEXT: Value: [[ENTRY]]
>> +# CHECK-NEXT: Size: 0
>> +# CHECK-NEXT: Binding: Global (0x1)
>> +# CHECK-NEXT: Type: None (0x0)
>> +# CHECK-NEXT: Other: 0
>> +# CHECK-NEXT: Section: .text (0x1)
>> +# CHECK-NEXT: }
>> +# CHECK-NEXT: ]
>> # CHECK-NEXT: ProgramHeaders [
>> # CHECK-NEXT: ProgramHeader {
>> # CHECK-NEXT: Type: PT_LOAD (0x1)
>>
>> Modified: lld/trunk/test/elf2/basic32.s
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic32.s?rev=247089&r1=247088&r2=247089&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/test/elf2/basic32.s (original)
>> +++ lld/trunk/test/elf2/basic32.s Tue Sep 8 17:34:57 2015
>> @@ -23,7 +23,7 @@ _start:
>> # CHECK-NEXT: Type: Executable (0x2)
>> # CHECK-NEXT: Machine: EM_386 (0x3)
>> # CHECK-NEXT: Version: 1
>> -# CHECK-NEXT: Entry: 0x401000
>> +# CHECK-NEXT: Entry: 0x1000
>> # CHECK-NEXT: ProgramHeaderOffset: 0x34
>> # CHECK-NEXT: SectionHeaderOffset: 0x1058
>> # CHECK-NEXT: Flags [ (0x0)
>>
>> Modified: lld/trunk/test/elf2/basic32be.s
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic32be.s?rev=247089&r1=247088&r2=247089&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/test/elf2/basic32be.s (original)
>> +++ lld/trunk/test/elf2/basic32be.s Tue Sep 8 17:34:57 2015
>> @@ -23,7 +23,7 @@ _start:
>> # CHECK-NEXT: Type: Executable (0x2)
>> # CHECK-NEXT: Machine: EM_PPC (0x14)
>> # CHECK-NEXT: Version: 1
>> -# CHECK-NEXT: Entry: 0x401000
>> +# CHECK-NEXT: Entry: 0x1000
>> # CHECK-NEXT: ProgramHeaderOffset: 0x34
>> # CHECK-NEXT: SectionHeaderOffset: 0x1058
>> # CHECK-NEXT: Flags [ (0x0)
>>
>> Modified: lld/trunk/test/elf2/basic64be.s
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic64be.s?rev=247089&r1=247088&r2=247089&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/test/elf2/basic64be.s (original)
>> +++ lld/trunk/test/elf2/basic64be.s Tue Sep 8 17:34:57 2015
>> @@ -28,7 +28,7 @@ _start:
>> # CHECK-NEXT: Type: Executable (0x2)
>> # CHECK-NEXT: Machine: EM_PPC64 (0x15)
>> # CHECK-NEXT: Version: 1
>> -# CHECK-NEXT: Entry: 0x401000
>> +# CHECK-NEXT: Entry: 0x100C
>> # CHECK-NEXT: ProgramHeaderOffset: 0x40
>> # CHECK-NEXT: SectionHeaderOffset: 0x1088
>> # CHECK-NEXT: Flags [ (0x0)
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
>
More information about the llvm-commits
mailing list