forked from OSchip/llvm-project
[lld][elf2] Fix hard coded entry address.
llvm-svn: 247089
This commit is contained in:
parent
07f3af2e82
commit
546c64c733
|
@ -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_ptr<InputFile> File) {
|
|||
}
|
||||
|
||||
template <class ELFT> void SymbolTable::init() {
|
||||
resolve<ELFT>(new (Alloc)
|
||||
Undefined<ELFT>("_start", Undefined<ELFT>::Synthetic));
|
||||
if (EntrySym)
|
||||
return;
|
||||
EntrySym = new (Alloc) Undefined<ELFT>("_start", Undefined<ELFT>::Synthetic);
|
||||
resolve<ELFT>(EntrySym);
|
||||
}
|
||||
|
||||
template <class ELFT> void SymbolTable::addELFFile(ELFFileBase *File) {
|
||||
|
|
|
@ -54,6 +54,10 @@ public:
|
|||
return SharedFiles;
|
||||
}
|
||||
|
||||
SymbolBody *getEntrySym() const {
|
||||
return EntrySym;
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
} // namespace elf2
|
||||
|
|
|
@ -577,7 +577,8 @@ template <class ELFT> void Writer<ELFT>::writeHeader() {
|
|||
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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue