Skip to content

Commit

Permalink
options/rtdl: Implement R_IRELATIVE relocation
Browse files Browse the repository at this point in the history
  • Loading branch information
Qwinci committed Feb 4, 2024
1 parent c86c391 commit ebe3623
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions options/rtdl/generic/linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,23 @@ void processLateRelocation(Relocation rel) {
__ensure(p);
memcpy(rel.destination(), (void *)p->virtualAddress(), p->symbol()->st_size);
break;

// TODO: R_IRELATIVE also exists on other architectures but will likely need a different implementation.
#if defined(__x86_64__) || defined(__i386__)
case R_IRELATIVE: {
uintptr_t addr = rel.object()->baseAddress + rel.addend_rel();
auto* fn = reinterpret_cast<uintptr_t (*)()>(addr);
rel.relocate(fn());
} break;
#elif defined(__aarch64__)
case R_IRELATIVE: {
uintptr_t addr = rel.object()->baseAddress + rel.addend_rel();
auto* fn = reinterpret_cast<uintptr_t (*)(uint64_t)>(addr);
// TODO: the function should get passed AT_HWCAP value.
rel.relocate(fn(0));
} break;
#endif

default:
break;
}
Expand Down Expand Up @@ -1464,8 +1481,8 @@ void Loader::_scheduleInit(SharedObject *object) {
}

void Loader::_processRelocations(Relocation &rel) {
// copy relocations have to be performed after all other relocations
if(rel.type() == R_COPY)
// copy and irelative relocations have to be performed after all other relocations
if(rel.type() == R_COPY || rel.type() == R_IRELATIVE)
return;

// resolve the symbol if there is a symbol
Expand Down

0 comments on commit ebe3623

Please sign in to comment.