Skip to content

Commit

Permalink
rtld: relocate R_X86_64_64 symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
john-tornblom committed May 4, 2024
1 parent c6e5c82 commit 3e42e22
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions crt/rtld.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ along with this program; see the file COPYING. If not, see
#define DT_RELA 7
#define DT_RELASZ 8

#define R_X86_64_64 1
#define R_X86_64_GLOB_DAT 6
#define R_X86_64_JMP_SLOT 7
#define R_X86_64_RELATIVE 8
Expand Down Expand Up @@ -427,6 +428,30 @@ r_relative(Elf64_Rela* rela) {
}


/**
*
**/
static int
r_direct_64(Elf64_Rela* rela) {
unsigned long loc = (unsigned long)(__text_start + rela->r_offset);
Elf64_Sym* sym = symtab + ELF64_R_SYM(rela->r_info);
const char* name = strtab + sym->st_name;
int pid = syscall(SYS_getpid);
unsigned long val = 0;

for(rtld_lib_t *lib=libhead; lib!=0; lib=lib->next) {
if((val=rtld_sym(lib, name))) {
val += rela->r_addend;
return mdbg_copyin(pid, &val, loc, sizeof(val));
}
}

klog_printf("Unable to resolve '%s'\n", name);

return -1;
}


/**
*
**/
Expand Down Expand Up @@ -476,6 +501,12 @@ rtld_load(void) {
}
break;

case R_X86_64_64:
if(r_direct_64(&rela[i])) {
return -1;
}
break;

case R_X86_64_GLOB_DAT:
if(r_glob_dat(&rela[i])) {
return -1;
Expand Down

0 comments on commit 3e42e22

Please sign in to comment.