forked from OSchip/llvm-project
ELF2: Support --entry=<addr>.
If an argument for --entry is a number, that's not a symbol name but an absolute address. If that's the case, the address is directly set to ELF header's e_entry. llvm-svn: 250334
This commit is contained in:
parent
f9e0b253ad
commit
2b675074fe
|
@ -58,6 +58,7 @@ struct Configuration {
|
|||
bool ZNow = false;
|
||||
ELFKind EKind = ELFNoneKind;
|
||||
uint16_t EMachine = llvm::ELF::EM_NONE;
|
||||
uint64_t EntryAddr = -1;
|
||||
};
|
||||
|
||||
extern Configuration *Config;
|
||||
|
|
|
@ -201,7 +201,11 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
|
|||
// Add entry symbol.
|
||||
if (Config->Entry.empty())
|
||||
Config->Entry = (Config->EMachine == EM_MIPS) ? "__start" : "_start";
|
||||
Config->EntrySym = Symtab.addUndefined(Config->Entry);
|
||||
|
||||
// Set either EntryAddr (if S is a number) or EntrySym (otherwise).
|
||||
StringRef S = Config->Entry;
|
||||
if (S.getAsInteger(0, Config->EntryAddr))
|
||||
Config->EntrySym = Symtab.addUndefined(S);
|
||||
|
||||
// In the assembly for 32 bit x86 the _GLOBAL_OFFSET_TABLE_ symbol
|
||||
// is magical and is used to produce a R_386_GOTPC relocation.
|
||||
|
|
|
@ -648,9 +648,12 @@ template <class ELFT> void Writer<ELFT>::writeHeader() {
|
|||
EHdr->e_type = Config->Shared ? ET_DYN : ET_EXEC;
|
||||
EHdr->e_machine = FirstObj.getEMachine();
|
||||
EHdr->e_version = EV_CURRENT;
|
||||
if (Config->EntrySym)
|
||||
if (Config->EntrySym) {
|
||||
if (auto *E = dyn_cast<ELFSymbolBody<ELFT>>(Config->EntrySym->repl()))
|
||||
EHdr->e_entry = getSymVA<ELFT>(*E);
|
||||
} else if (Config->EntryAddr != uint64_t(-1)) {
|
||||
EHdr->e_entry = Config->EntryAddr;
|
||||
}
|
||||
EHdr->e_phoff = sizeof(Elf_Ehdr);
|
||||
EHdr->e_shoff = SectionHeaderOff;
|
||||
EHdr->e_ehsize = sizeof(Elf_Ehdr);
|
||||
|
|
|
@ -2,5 +2,16 @@
|
|||
# RUN: not ld.lld2 %t1 -o %t2
|
||||
# RUN: ld.lld2 %t1 -o %t2 -e _end
|
||||
|
||||
.globl _end;
|
||||
# RUN: ld.lld2 %t1 -o %t2 -e 4096
|
||||
# RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=DEC %s
|
||||
# RUN: ld.lld2 %t1 -o %t2 -e 0xcafe
|
||||
# RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=HEX %s
|
||||
# RUN: ld.lld2 %t1 -o %t2 -e 0777
|
||||
# RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=OCT %s
|
||||
|
||||
# DEC: Entry: 0x1000
|
||||
# HEX: Entry: 0xCAFE
|
||||
# OCT: Entry: 0x1FF
|
||||
|
||||
.globl _end
|
||||
_end:
|
||||
|
|
Loading…
Reference in New Issue