am 5487ecb5
: am e9cdce33
: am 3c9afb5e
: am 6b4c77f8
: Merge "Use Elf32_Addr instead of unsigned in linker"
* commit '5487ecb52a328906b81635f8c8018f48031c19a1': Use Elf32_Addr instead of unsigned in linker
This commit is contained in:
commit
947695bd9b
@ -626,32 +626,31 @@ Elf32_Sym* dlsym_linear_lookup(const char* name, soinfo** found, soinfo* start)
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
soinfo* find_containing_library(const void* addr) {
|
soinfo* find_containing_library(const void* p) {
|
||||||
for (soinfo* si = solist; si != NULL; si = si->next) {
|
Elf32_Addr address = reinterpret_cast<Elf32_Addr>(p);
|
||||||
if ((unsigned)addr >= si->base && (unsigned)addr - si->base < si->size) {
|
for (soinfo* si = solist; si != NULL; si = si->next) {
|
||||||
return si;
|
if (address >= si->base && address - si->base < si->size) {
|
||||||
}
|
return si;
|
||||||
}
|
}
|
||||||
return NULL;
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Elf32_Sym* dladdr_find_symbol(soinfo* si, const void* addr) {
|
Elf32_Sym* dladdr_find_symbol(soinfo* si, const void* addr) {
|
||||||
unsigned int i;
|
Elf32_Addr soaddr = reinterpret_cast<Elf32_Addr>(addr) - si->base;
|
||||||
unsigned soaddr = (unsigned)addr - si->base;
|
|
||||||
|
|
||||||
/* Search the library's symbol table for any defined symbol which
|
// Search the library's symbol table for any defined symbol which
|
||||||
* contains this address */
|
// contains this address.
|
||||||
for (i=0; i<si->nchain; i++) {
|
for (size_t i = 0; i < si->nchain; ++i) {
|
||||||
Elf32_Sym *sym = &si->symtab[i];
|
Elf32_Sym* sym = &si->symtab[i];
|
||||||
|
if (sym->st_shndx != SHN_UNDEF &&
|
||||||
if (sym->st_shndx != SHN_UNDEF &&
|
soaddr >= sym->st_value &&
|
||||||
soaddr >= sym->st_value &&
|
soaddr < sym->st_value + sym->st_size) {
|
||||||
soaddr < sym->st_value + sym->st_size) {
|
return sym;
|
||||||
return sym;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@ -867,8 +866,8 @@ static int soinfo_relocate(soinfo* si, Elf32_Rel* rel, unsigned count,
|
|||||||
for (size_t idx = 0; idx < count; ++idx, ++rel) {
|
for (size_t idx = 0; idx < count; ++idx, ++rel) {
|
||||||
unsigned type = ELF32_R_TYPE(rel->r_info);
|
unsigned type = ELF32_R_TYPE(rel->r_info);
|
||||||
unsigned sym = ELF32_R_SYM(rel->r_info);
|
unsigned sym = ELF32_R_SYM(rel->r_info);
|
||||||
unsigned reloc = (unsigned)(rel->r_offset + si->load_bias);
|
Elf32_Addr reloc = static_cast<Elf32_Addr>(rel->r_offset + si->load_bias);
|
||||||
unsigned sym_addr = 0;
|
Elf32_Addr sym_addr = 0;
|
||||||
char* sym_name = NULL;
|
char* sym_name = NULL;
|
||||||
|
|
||||||
DEBUG("Processing '%s' relocation at index %d\n", si->name, idx);
|
DEBUG("Processing '%s' relocation at index %d\n", si->name, idx);
|
||||||
@ -943,7 +942,7 @@ static int soinfo_relocate(soinfo* si, Elf32_Rel* rel, unsigned count,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
sym_addr = (unsigned)(s->st_value + lsi->load_bias);
|
sym_addr = static_cast<Elf32_Addr>(s->st_value + lsi->load_bias);
|
||||||
}
|
}
|
||||||
count_relocation(kRelocSymbol);
|
count_relocation(kRelocSymbol);
|
||||||
} else {
|
} else {
|
||||||
@ -959,39 +958,39 @@ static int soinfo_relocate(soinfo* si, Elf32_Rel* rel, unsigned count,
|
|||||||
count_relocation(kRelocAbsolute);
|
count_relocation(kRelocAbsolute);
|
||||||
MARK(rel->r_offset);
|
MARK(rel->r_offset);
|
||||||
TRACE_TYPE(RELO, "RELO JMP_SLOT %08x <- %08x %s\n", reloc, sym_addr, sym_name);
|
TRACE_TYPE(RELO, "RELO JMP_SLOT %08x <- %08x %s\n", reloc, sym_addr, sym_name);
|
||||||
*((unsigned*)reloc) = sym_addr;
|
*reinterpret_cast<Elf32_Addr*>(reloc) = sym_addr;
|
||||||
break;
|
break;
|
||||||
case R_ARM_GLOB_DAT:
|
case R_ARM_GLOB_DAT:
|
||||||
count_relocation(kRelocAbsolute);
|
count_relocation(kRelocAbsolute);
|
||||||
MARK(rel->r_offset);
|
MARK(rel->r_offset);
|
||||||
TRACE_TYPE(RELO, "RELO GLOB_DAT %08x <- %08x %s\n", reloc, sym_addr, sym_name);
|
TRACE_TYPE(RELO, "RELO GLOB_DAT %08x <- %08x %s\n", reloc, sym_addr, sym_name);
|
||||||
*((unsigned*)reloc) = sym_addr;
|
*reinterpret_cast<Elf32_Addr*>(reloc) = sym_addr;
|
||||||
break;
|
break;
|
||||||
case R_ARM_ABS32:
|
case R_ARM_ABS32:
|
||||||
count_relocation(kRelocAbsolute);
|
count_relocation(kRelocAbsolute);
|
||||||
MARK(rel->r_offset);
|
MARK(rel->r_offset);
|
||||||
TRACE_TYPE(RELO, "RELO ABS %08x <- %08x %s\n", reloc, sym_addr, sym_name);
|
TRACE_TYPE(RELO, "RELO ABS %08x <- %08x %s\n", reloc, sym_addr, sym_name);
|
||||||
*((unsigned*)reloc) += sym_addr;
|
*reinterpret_cast<Elf32_Addr*>(reloc) += sym_addr;
|
||||||
break;
|
break;
|
||||||
case R_ARM_REL32:
|
case R_ARM_REL32:
|
||||||
count_relocation(kRelocRelative);
|
count_relocation(kRelocRelative);
|
||||||
MARK(rel->r_offset);
|
MARK(rel->r_offset);
|
||||||
TRACE_TYPE(RELO, "RELO REL32 %08x <- %08x - %08x %s\n",
|
TRACE_TYPE(RELO, "RELO REL32 %08x <- %08x - %08x %s\n",
|
||||||
reloc, sym_addr, rel->r_offset, sym_name);
|
reloc, sym_addr, rel->r_offset, sym_name);
|
||||||
*((unsigned*)reloc) += sym_addr - rel->r_offset;
|
*reinterpret_cast<Elf32_Addr*>(reloc) += sym_addr - rel->r_offset;
|
||||||
break;
|
break;
|
||||||
#elif defined(ANDROID_X86_LINKER)
|
#elif defined(ANDROID_X86_LINKER)
|
||||||
case R_386_JMP_SLOT:
|
case R_386_JMP_SLOT:
|
||||||
count_relocation(kRelocAbsolute);
|
count_relocation(kRelocAbsolute);
|
||||||
MARK(rel->r_offset);
|
MARK(rel->r_offset);
|
||||||
TRACE_TYPE(RELO, "RELO JMP_SLOT %08x <- %08x %s\n", reloc, sym_addr, sym_name);
|
TRACE_TYPE(RELO, "RELO JMP_SLOT %08x <- %08x %s\n", reloc, sym_addr, sym_name);
|
||||||
*((unsigned*)reloc) = sym_addr;
|
*reinterpret_cast<Elf32_Addr*>(reloc) = sym_addr;
|
||||||
break;
|
break;
|
||||||
case R_386_GLOB_DAT:
|
case R_386_GLOB_DAT:
|
||||||
count_relocation(kRelocAbsolute);
|
count_relocation(kRelocAbsolute);
|
||||||
MARK(rel->r_offset);
|
MARK(rel->r_offset);
|
||||||
TRACE_TYPE(RELO, "RELO GLOB_DAT %08x <- %08x %s\n", reloc, sym_addr, sym_name);
|
TRACE_TYPE(RELO, "RELO GLOB_DAT %08x <- %08x %s\n", reloc, sym_addr, sym_name);
|
||||||
*((unsigned*)reloc) = sym_addr;
|
*reinterpret_cast<Elf32_Addr*>(reloc) = sym_addr;
|
||||||
break;
|
break;
|
||||||
#elif defined(ANDROID_MIPS_LINKER)
|
#elif defined(ANDROID_MIPS_LINKER)
|
||||||
case R_MIPS_REL32:
|
case R_MIPS_REL32:
|
||||||
@ -1000,9 +999,9 @@ static int soinfo_relocate(soinfo* si, Elf32_Rel* rel, unsigned count,
|
|||||||
TRACE_TYPE(RELO, "RELO REL32 %08x <- %08x %s\n",
|
TRACE_TYPE(RELO, "RELO REL32 %08x <- %08x %s\n",
|
||||||
reloc, sym_addr, (sym_name) ? sym_name : "*SECTIONHDR*");
|
reloc, sym_addr, (sym_name) ? sym_name : "*SECTIONHDR*");
|
||||||
if (s) {
|
if (s) {
|
||||||
*((unsigned*)reloc) += sym_addr;
|
*reinterpret_cast<Elf32_Addr*>(reloc) += sym_addr;
|
||||||
} else {
|
} else {
|
||||||
*((unsigned*)reloc) += si->base;
|
*reinterpret_cast<Elf32_Addr*>(reloc) += si->base;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif /* ANDROID_*_LINKER */
|
#endif /* ANDROID_*_LINKER */
|
||||||
@ -1019,7 +1018,7 @@ static int soinfo_relocate(soinfo* si, Elf32_Rel* rel, unsigned count,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
TRACE_TYPE(RELO, "RELO RELATIVE %08x <- +%08x\n", reloc, si->base);
|
TRACE_TYPE(RELO, "RELO RELATIVE %08x <- +%08x\n", reloc, si->base);
|
||||||
*((unsigned*)reloc) += si->base;
|
*reinterpret_cast<Elf32_Addr*>(reloc) += si->base;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#if defined(ANDROID_X86_LINKER)
|
#if defined(ANDROID_X86_LINKER)
|
||||||
@ -1028,7 +1027,7 @@ static int soinfo_relocate(soinfo* si, Elf32_Rel* rel, unsigned count,
|
|||||||
MARK(rel->r_offset);
|
MARK(rel->r_offset);
|
||||||
|
|
||||||
TRACE_TYPE(RELO, "RELO R_386_32 %08x <- +%08x %s\n", reloc, sym_addr, sym_name);
|
TRACE_TYPE(RELO, "RELO R_386_32 %08x <- +%08x %s\n", reloc, sym_addr, sym_name);
|
||||||
*((unsigned *)reloc) += (unsigned)sym_addr;
|
*reinterpret_cast<Elf32_Addr*>(reloc) += sym_addr;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R_386_PC32:
|
case R_386_PC32:
|
||||||
@ -1036,7 +1035,7 @@ static int soinfo_relocate(soinfo* si, Elf32_Rel* rel, unsigned count,
|
|||||||
MARK(rel->r_offset);
|
MARK(rel->r_offset);
|
||||||
TRACE_TYPE(RELO, "RELO R_386_PC32 %08x <- +%08x (%08x - %08x) %s\n",
|
TRACE_TYPE(RELO, "RELO R_386_PC32 %08x <- +%08x (%08x - %08x) %s\n",
|
||||||
reloc, (sym_addr - reloc), sym_addr, reloc, sym_name);
|
reloc, (sym_addr - reloc), sym_addr, reloc, sym_name);
|
||||||
*((unsigned *)reloc) += (unsigned)(sym_addr - reloc);
|
*reinterpret_cast<Elf32_Addr*>(reloc) += (sym_addr - reloc);
|
||||||
break;
|
break;
|
||||||
#endif /* ANDROID_X86_LINKER */
|
#endif /* ANDROID_X86_LINKER */
|
||||||
|
|
||||||
@ -1614,7 +1613,7 @@ static bool soinfo_link_image(soinfo* si) {
|
|||||||
* fixed it's own GOT. It is safe to make references to externs
|
* fixed it's own GOT. It is safe to make references to externs
|
||||||
* and other non-local data at this point.
|
* and other non-local data at this point.
|
||||||
*/
|
*/
|
||||||
static unsigned __linker_init_post_relocation(KernelArgumentBlock& args, unsigned linker_base) {
|
static Elf32_Addr __linker_init_post_relocation(KernelArgumentBlock& args, Elf32_Addr linker_base) {
|
||||||
/* NOTE: we store the args pointer on a special location
|
/* NOTE: we store the args pointer on a special location
|
||||||
* of the temporary TLS area in order to pass it to
|
* of the temporary TLS area in order to pass it to
|
||||||
* the C Library's runtime initializer.
|
* the C Library's runtime initializer.
|
||||||
@ -1794,20 +1793,17 @@ static unsigned __linker_init_post_relocation(KernelArgumentBlock& args, unsigne
|
|||||||
* load bias, i.e. add the value of any p_vaddr in the file to get
|
* load bias, i.e. add the value of any p_vaddr in the file to get
|
||||||
* the corresponding address in memory.
|
* the corresponding address in memory.
|
||||||
*/
|
*/
|
||||||
static Elf32_Addr
|
static Elf32_Addr get_elf_exec_load_bias(const Elf32_Ehdr* elf) {
|
||||||
get_elf_exec_load_bias(const Elf32_Ehdr* elf)
|
Elf32_Addr offset = elf->e_phoff;
|
||||||
{
|
const Elf32_Phdr* phdr_table = (const Elf32_Phdr*)((char*)elf + offset);
|
||||||
Elf32_Addr offset = elf->e_phoff;
|
const Elf32_Phdr* phdr_end = phdr_table + elf->e_phnum;
|
||||||
const Elf32_Phdr* phdr_table = (const Elf32_Phdr*)((char*)elf + offset);
|
|
||||||
const Elf32_Phdr* phdr_end = phdr_table + elf->e_phnum;
|
|
||||||
const Elf32_Phdr* phdr;
|
|
||||||
|
|
||||||
for (phdr = phdr_table; phdr < phdr_end; phdr++) {
|
for (const Elf32_Phdr* phdr = phdr_table; phdr < phdr_end; phdr++) {
|
||||||
if (phdr->p_type == PT_LOAD) {
|
if (phdr->p_type == PT_LOAD) {
|
||||||
return (Elf32_Addr)elf + phdr->p_offset - phdr->p_vaddr;
|
return reinterpret_cast<Elf32_Addr>(elf) + phdr->p_offset - phdr->p_vaddr;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1819,10 +1815,10 @@ get_elf_exec_load_bias(const Elf32_Ehdr* elf)
|
|||||||
* relocations, any attempt to reference an extern variable, extern
|
* relocations, any attempt to reference an extern variable, extern
|
||||||
* function, or other GOT reference will generate a segfault.
|
* function, or other GOT reference will generate a segfault.
|
||||||
*/
|
*/
|
||||||
extern "C" unsigned __linker_init(void* raw_args) {
|
extern "C" Elf32_Addr __linker_init(void* raw_args) {
|
||||||
KernelArgumentBlock args(raw_args);
|
KernelArgumentBlock args(raw_args);
|
||||||
|
|
||||||
unsigned linker_addr = args.getauxval(AT_BASE);
|
Elf32_Addr linker_addr = args.getauxval(AT_BASE);
|
||||||
|
|
||||||
Elf32_Ehdr *elf_hdr = (Elf32_Ehdr*) linker_addr;
|
Elf32_Ehdr *elf_hdr = (Elf32_Ehdr*) linker_addr;
|
||||||
Elf32_Phdr *phdr = (Elf32_Phdr*)((unsigned char*) linker_addr + elf_hdr->e_phoff);
|
Elf32_Phdr *phdr = (Elf32_Phdr*)((unsigned char*) linker_addr + elf_hdr->e_phoff);
|
||||||
@ -1850,7 +1846,7 @@ extern "C" unsigned __linker_init(void* raw_args) {
|
|||||||
|
|
||||||
// We have successfully fixed our own relocations. It's safe to run
|
// We have successfully fixed our own relocations. It's safe to run
|
||||||
// the main part of the linker now.
|
// the main part of the linker now.
|
||||||
unsigned start_address = __linker_init_post_relocation(args, linker_addr);
|
Elf32_Addr start_address = __linker_init_post_relocation(args, linker_addr);
|
||||||
|
|
||||||
set_soinfo_pool_protection(PROT_READ);
|
set_soinfo_pool_protection(PROT_READ);
|
||||||
|
|
||||||
|
@ -90,8 +90,8 @@ struct soinfo {
|
|||||||
char name[SOINFO_NAME_LEN];
|
char name[SOINFO_NAME_LEN];
|
||||||
const Elf32_Phdr* phdr;
|
const Elf32_Phdr* phdr;
|
||||||
int phnum;
|
int phnum;
|
||||||
unsigned entry;
|
Elf32_Addr entry;
|
||||||
unsigned base;
|
Elf32_Addr base;
|
||||||
unsigned size;
|
unsigned size;
|
||||||
|
|
||||||
int unused; // DO NOT USE, maintained for compatibility.
|
int unused; // DO NOT USE, maintained for compatibility.
|
||||||
|
Loading…
Reference in New Issue
Block a user