diff options
author | kib <kib@FreeBSD.org> | 2012-03-20 13:20:49 +0000 |
---|---|---|
committer | kib <kib@FreeBSD.org> | 2012-03-20 13:20:49 +0000 |
commit | c49b39491ded257751332662302997df5b34fd12 (patch) | |
tree | 141ae8f14c62c6f65aeb3d57bd0ca7ebd14c319a /libexec/rtld-elf/arm | |
parent | e87823cf6ee42b9d37c7af7ba277341a2fd2fac9 (diff) | |
download | FreeBSD-src-c49b39491ded257751332662302997df5b34fd12.zip FreeBSD-src-c49b39491ded257751332662302997df5b34fd12.tar.gz |
Fix several problems with our ELF filters implementation.
Do not relocate twice an object which happens to be needed by loaded
binary (or dso) and some filtee opened due to symbol resolution when
relocating need objects. Record the state of the relocation
processing in Obj_Entry and short-circuit relocate_objects() if
current object already processed.
Do not call constructors for filtees loaded during the early
relocation processing before image is initialized enough to run
user-provided code. Filtees are loaded using dlopen_object(), which
normally performs relocation and initialization. If filtee is
lazy-loaded during the relocation of dso needed by the main object,
dlopen_object() runs too earlier, when most runtime services are not
yet ready.
Postpone the constructors call to the time when main binary and
depended libraries constructors are run, passing the new flag
RTLD_LO_EARLY to dlopen_object(). Symbol lookups callers inform
symlook_* functions about early stage of initialization with
SYMLOOK_EARLY. Pass flags through all functions participating in
object relocation.
Use the opportunity and fix flags argument to find_symdef() in
arch-specific reloc.c to use proper name SYMLOOK_IN_PLT instead of
true, which happen to have the same numeric value.
Reported and tested by: theraven
Reviewed by: kan
MFC after: 2 weeks
Diffstat (limited to 'libexec/rtld-elf/arm')
-rw-r--r-- | libexec/rtld-elf/arm/reloc.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/libexec/rtld-elf/arm/reloc.c b/libexec/rtld-elf/arm/reloc.c index 11b962a..aaad2da 100644 --- a/libexec/rtld-elf/arm/reloc.c +++ b/libexec/rtld-elf/arm/reloc.c @@ -54,6 +54,8 @@ do_copy_relocations(Obj_Entry *dstobj) symlook_init(&req, name); req.ventry = fetch_ventry(dstobj, ELF_R_SYM(rel->r_info)); + req.flags = SYMLOOK_EARLY; + for (srcobj = dstobj->next; srcobj != NULL; srcobj = srcobj->next) { res = symlook_obj(&req, srcobj); @@ -135,7 +137,7 @@ store_ptr(void *where, Elf_Addr val) static int reloc_nonplt_object(Obj_Entry *obj, const Elf_Rel *rel, SymCache *cache, - RtldLockState *lockstate) + int flags, RtldLockState *lockstate) { Elf_Addr *where; const Elf_Sym *def; @@ -161,7 +163,7 @@ reloc_nonplt_object(Obj_Entry *obj, const Elf_Rel *rel, SymCache *cache, if (addend & 0x00800000) addend |= 0xff000000; - def = find_symdef(symnum, obj, &defobj, false, cache, + def = find_symdef(symnum, obj, &defobj, flags, cache, lockstate); if (def == NULL) return -1; @@ -188,7 +190,7 @@ reloc_nonplt_object(Obj_Entry *obj, const Elf_Rel *rel, SymCache *cache, case R_ARM_ABS32: /* word32 B + S + A */ case R_ARM_GLOB_DAT: /* word32 B + S */ - def = find_symdef(symnum, obj, &defobj, false, cache, + def = find_symdef(symnum, obj, &defobj, flags, cache, lockstate); if (def == NULL) return -1; @@ -237,7 +239,7 @@ reloc_nonplt_object(Obj_Entry *obj, const Elf_Rel *rel, SymCache *cache, break; case R_ARM_TLS_DTPOFF32: - def = find_symdef(symnum, obj, &defobj, false, cache, + def = find_symdef(symnum, obj, &defobj, flags, cache, lockstate); if (def == NULL) return -1; @@ -254,7 +256,7 @@ reloc_nonplt_object(Obj_Entry *obj, const Elf_Rel *rel, SymCache *cache, break; case R_ARM_TLS_DTPMOD32: - def = find_symdef(symnum, obj, &defobj, false, cache, + def = find_symdef(symnum, obj, &defobj, flags, cache, lockstate); if (def == NULL) return -1; @@ -272,7 +274,7 @@ reloc_nonplt_object(Obj_Entry *obj, const Elf_Rel *rel, SymCache *cache, break; case R_ARM_TLS_TPOFF32: - def = find_symdef(symnum, obj, &defobj, false, cache, + def = find_symdef(symnum, obj, &defobj, flags, cache, lockstate); if (def == NULL) return -1; @@ -311,7 +313,8 @@ reloc_nonplt_object(Obj_Entry *obj, const Elf_Rel *rel, SymCache *cache, * * Process non-PLT relocations * */ int -reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, RtldLockState *lockstate) +reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, int flags, + RtldLockState *lockstate) { const Elf_Rel *rellim; const Elf_Rel *rel; @@ -330,7 +333,7 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, RtldLockState *lockstate) rellim = (const Elf_Rel *)((caddr_t)obj->rel + obj->relsize); for (rel = obj->rel; rel < rellim; rel++) { - if (reloc_nonplt_object(obj, rel, cache, lockstate) < 0) + if (reloc_nonplt_object(obj, rel, cache, flags, lockstate) < 0) goto done; } r = 0; @@ -367,7 +370,7 @@ reloc_plt(Obj_Entry *obj) * * LD_BIND_NOW was set - force relocation for all jump slots * */ int -reloc_jmpslots(Obj_Entry *obj, RtldLockState *lockstate) +reloc_jmpslots(Obj_Entry *obj, int flags, RtldLockState *lockstate) { const Obj_Entry *defobj; const Elf_Rel *rellim; @@ -381,7 +384,7 @@ reloc_jmpslots(Obj_Entry *obj, RtldLockState *lockstate) assert(ELF_R_TYPE(rel->r_info) == R_ARM_JUMP_SLOT); where = (Elf_Addr *)(obj->relocbase + rel->r_offset); def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj, - true, NULL, lockstate); + SYMLOOK_IN_PLT | flags, NULL, lockstate); if (def == NULL) { dbg("reloc_jmpslots: sym not found"); return (-1); @@ -406,7 +409,8 @@ reloc_iresolve(Obj_Entry *obj, struct Struct_RtldLockState *lockstate) } int -reloc_gnu_ifunc(Obj_Entry *obj, struct Struct_RtldLockState *lockstate) +reloc_gnu_ifunc(Obj_Entry *obj, int flags, + struct Struct_RtldLockState *lockstate) { /* XXX not implemented */ |