ldso: mark functions used during self relocation

These functions are marked as always inline through the 'SELF_RELOC' macro. This
became necessary because on riscv functions calls are performed through the
global offset table, which is not initialized at this point.

Fixes #2203
This commit is contained in:
Sebastian Sumpf
2016-12-22 11:24:26 +01:00
committed by Norman Feske
parent f2568856dd
commit 6e14aa4364
3 changed files with 10 additions and 3 deletions

View File

@ -144,7 +144,7 @@ class Linker::Dynamic
_d->un.ptr = (Elf::Addr)Debug::d(); _d->un.ptr = (Elf::Addr)Debug::d();
} }
void _init() void _init() SELF_RELOC
{ {
for (Elf::Dyn const *d = &_dynamic; d->tag != DT_NULL; d++) { for (Elf::Dyn const *d = &_dynamic; d->tag != DT_NULL; d++) {
switch (d->tag) { switch (d->tag) {
@ -308,7 +308,7 @@ class Linker::Dynamic
fn(n->path(_strtab)); fn(n->path(_strtab));
} }
void relocate(Bind bind) void relocate(Bind bind) SELF_RELOC
{ {
plt_setup(); plt_setup();

View File

@ -20,6 +20,13 @@
#include <file.h> #include <file.h>
#include <util.h> #include <util.h>
/*
* Mark functions that are used during the linkers self-relocation phase as
* always inline. Some platforms (riscv) perform function calls through the
* GOT that is not initialized (zero) at this state.
*/
#define SELF_RELOC __attribute__((always_inline))
/** /**
* Forward declartions and helpers * Forward declartions and helpers
*/ */

View File

@ -197,7 +197,7 @@ class Linker::Elf_object : public Object, public Fifo<Elf_object>::Element
void update_dependency(Dependency const &dep) { _dyn.dep(dep); } void update_dependency(Dependency const &dep) { _dyn.dep(dep); }
void relocate(Bind bind) override void relocate(Bind bind) override SELF_RELOC
{ {
if (!_relocated) if (!_relocated)
_dyn.relocate(bind); _dyn.relocate(bind);