libdyld: add const qualifiers.
This commit is contained in:
parent
cf3a9e04b8
commit
d88904b3d7
|
@ -5,14 +5,14 @@
|
||||||
|
|
||||||
struct dyld_info {
|
struct dyld_info {
|
||||||
Elf32_Addr base;
|
Elf32_Addr base;
|
||||||
void *init;
|
const void *init;
|
||||||
const char *strtab;
|
const char *strtab;
|
||||||
Elf32_Sym *symtab;
|
const Elf32_Sym *symtab;
|
||||||
struct {
|
struct {
|
||||||
Elf32_Word nbucket;
|
Elf32_Word nbucket;
|
||||||
Elf32_Word nchain;
|
Elf32_Word nchain;
|
||||||
Elf32_Word *bucket;
|
const Elf32_Word *bucket;
|
||||||
Elf32_Word *chain;
|
const Elf32_Word *chain;
|
||||||
} hash;
|
} hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ struct dyld_info {
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int dyld_load(void *shlib, Elf32_Addr base,
|
int dyld_load(const void *shlib, Elf32_Addr base,
|
||||||
Elf32_Addr (*resolve_import)(const char *),
|
Elf32_Addr (*resolve_import)(const char *),
|
||||||
struct dyld_info *info, const char **error_out);
|
struct dyld_info *info, const char **error_out);
|
||||||
void *dyld_lookup(const char *symbol, struct dyld_info *info);
|
void *dyld_lookup(const char *symbol, struct dyld_info *info);
|
||||||
|
|
|
@ -3,11 +3,11 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <dyld.h>
|
#include <dyld.h>
|
||||||
|
|
||||||
static int fixup_rela(struct dyld_info *info, Elf32_Rela *rela,
|
static int fixup_rela(struct dyld_info *info, const Elf32_Rela *rela,
|
||||||
Elf32_Addr (*resolve_import)(const char *),
|
Elf32_Addr (*resolve_import)(const char *),
|
||||||
const char **error_out)
|
const char **error_out)
|
||||||
{
|
{
|
||||||
Elf32_Sym *sym = NULL;
|
const Elf32_Sym *sym = NULL;
|
||||||
if(ELF32_R_SYM(rela->r_info) != 0)
|
if(ELF32_R_SYM(rela->r_info) != 0)
|
||||||
sym = &info->symtab[ELF32_R_SYM(rela->r_info)];
|
sym = &info->symtab[ELF32_R_SYM(rela->r_info)];
|
||||||
Elf32_Addr value;
|
Elf32_Addr value;
|
||||||
|
@ -49,11 +49,11 @@ static int fixup_rela(struct dyld_info *info, Elf32_Rela *rela,
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int dyld_load(void *shlib, Elf32_Addr base,
|
int dyld_load(const void *shlib, Elf32_Addr base,
|
||||||
Elf32_Addr (*resolve_import)(const char *),
|
Elf32_Addr (*resolve_import)(const char *),
|
||||||
struct dyld_info *info, const char **error_out)
|
struct dyld_info *info, const char **error_out)
|
||||||
{
|
{
|
||||||
Elf32_Ehdr *ehdr = (Elf32_Ehdr *)shlib;
|
const Elf32_Ehdr *ehdr = (const Elf32_Ehdr *)shlib;
|
||||||
|
|
||||||
const unsigned char expected_ident[EI_NIDENT] = {
|
const unsigned char expected_ident[EI_NIDENT] = {
|
||||||
ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3,
|
ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3,
|
||||||
|
@ -75,14 +75,14 @@ int dyld_load(void *shlib, Elf32_Addr base,
|
||||||
#error Unsupported architecture
|
#error Unsupported architecture
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Elf32_Phdr *phdr = (Elf32_Phdr *)((intptr_t)shlib + ehdr->e_phoff);
|
const Elf32_Phdr *phdr = (const Elf32_Phdr *)((intptr_t)shlib + ehdr->e_phoff);
|
||||||
Elf32_Dyn *dyn = NULL;
|
const Elf32_Dyn *dyn = NULL;
|
||||||
for(int i = 0; i < ehdr->e_phnum; i++) {
|
for(int i = 0; i < ehdr->e_phnum; i++) {
|
||||||
if(phdr[i].p_type == PT_DYNAMIC)
|
if(phdr[i].p_type == PT_DYNAMIC)
|
||||||
dyn = (Elf32_Dyn *)((intptr_t)shlib + phdr[i].p_offset);
|
dyn = (const Elf32_Dyn *)((intptr_t)shlib + phdr[i].p_offset);
|
||||||
|
|
||||||
memcpy((void*)(base + phdr[i].p_vaddr),
|
memcpy((void*)(base + phdr[i].p_vaddr),
|
||||||
(void*)((intptr_t)shlib + phdr[i].p_offset),
|
(const void*)((intptr_t)shlib + phdr[i].p_offset),
|
||||||
phdr[i].p_filesz);
|
phdr[i].p_filesz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,23 +91,24 @@ int dyld_load(void *shlib, Elf32_Addr base,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *strtab = NULL;
|
const char *strtab = NULL;
|
||||||
Elf32_Sym *symtab = NULL;
|
const Elf32_Sym *symtab = NULL;
|
||||||
Elf32_Rela *rela = NULL, *pltrel = NULL;
|
const Elf32_Rela *rela = NULL, *pltrel = NULL;
|
||||||
Elf32_Word *hash = NULL, init = 0;
|
const Elf32_Word *hash = NULL;
|
||||||
|
Elf32_Word init = 0;
|
||||||
size_t syment = sizeof(Elf32_Sym), relaent = sizeof(Elf32_Rela),
|
size_t syment = sizeof(Elf32_Sym), relaent = sizeof(Elf32_Rela),
|
||||||
relanum = 0, pltrelnum = 0;
|
relanum = 0, pltrelnum = 0;
|
||||||
while(dyn->d_tag != DT_NULL) {
|
while(dyn->d_tag != DT_NULL) {
|
||||||
switch(dyn->d_tag) {
|
switch(dyn->d_tag) {
|
||||||
case DT_STRTAB: strtab = (char *)(base + dyn->d_un.d_ptr); break;
|
case DT_STRTAB: strtab = (const char *)(base + dyn->d_un.d_ptr); break;
|
||||||
case DT_SYMTAB: symtab = (Elf32_Sym *)(base + dyn->d_un.d_ptr); break;
|
case DT_SYMTAB: symtab = (const Elf32_Sym *)(base + dyn->d_un.d_ptr); break;
|
||||||
case DT_SYMENT: syment = dyn->d_un.d_val; break;
|
case DT_SYMENT: syment = dyn->d_un.d_val; break;
|
||||||
case DT_RELA: rela = (Elf32_Rela *)(base + dyn->d_un.d_ptr); break;
|
case DT_RELA: rela = (const Elf32_Rela *)(base + dyn->d_un.d_ptr); break;
|
||||||
case DT_RELAENT: relaent = dyn->d_un.d_val; break;
|
case DT_RELAENT: relaent = dyn->d_un.d_val; break;
|
||||||
case DT_RELASZ: relanum = dyn->d_un.d_val / sizeof(Elf32_Rela); break;
|
case DT_RELASZ: relanum = dyn->d_un.d_val / sizeof(Elf32_Rela); break;
|
||||||
case DT_JMPREL: pltrel = (Elf32_Rela *)(base + dyn->d_un.d_ptr); break;
|
case DT_JMPREL: pltrel = (const Elf32_Rela *)(base + dyn->d_un.d_ptr); break;
|
||||||
case DT_PLTRELSZ: pltrelnum = dyn->d_un.d_val / sizeof(Elf32_Rela); break;
|
case DT_PLTRELSZ: pltrelnum = dyn->d_un.d_val / sizeof(Elf32_Rela); break;
|
||||||
case DT_HASH: hash = (Elf32_Word *)(base + dyn->d_un.d_ptr); break;
|
case DT_HASH: hash = (const Elf32_Word *)(base + dyn->d_un.d_ptr); break;
|
||||||
case DT_INIT: init = dyn->d_un.d_val; break;
|
case DT_INIT: init = dyn->d_un.d_val; break;
|
||||||
|
|
||||||
case DT_REL:
|
case DT_REL:
|
||||||
|
|
Loading…
Reference in New Issue