diff options
author | Konstantin Belousov <kib@FreeBSD.org> | 2012-03-20 13:20:49 +0000 |
---|---|---|
committer | Konstantin Belousov <kib@FreeBSD.org> | 2012-03-20 13:20:49 +0000 |
commit | 082f959ac8281d323f9289c45b769275e172c917 (patch) | |
tree | 141ae8f14c62c6f65aeb3d57bd0ca7ebd14c319a /libexec/rtld-elf/i386 | |
parent | 04296b6f1892a8f3b5ec1bc546bd90caf4fab6ef (diff) | |
download | src-082f959ac8281d323f9289c45b769275e172c917.tar.gz src-082f959ac8281d323f9289c45b769275e172c917.zip |
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
Notes
Notes:
svn path=/head/; revision=233231
Diffstat (limited to 'libexec/rtld-elf/i386')
-rw-r--r-- | libexec/rtld-elf/i386/reloc.c | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/libexec/rtld-elf/i386/reloc.c b/libexec/rtld-elf/i386/reloc.c index a2c8c987f32e..5f4e24721d0c 100644 --- a/libexec/rtld-elf/i386/reloc.c +++ b/libexec/rtld-elf/i386/reloc.c @@ -83,6 +83,7 @@ do_copy_relocations(Obj_Entry *dstobj) size = dstsym->st_size; 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); @@ -119,7 +120,8 @@ init_pltgot(Obj_Entry *obj) /* Process the 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; @@ -151,7 +153,7 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, RtldLockState *lockstate) const Obj_Entry *defobj; def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj, - false, cache, lockstate); + flags, cache, lockstate); if (def == NULL) goto done; @@ -170,7 +172,7 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, RtldLockState *lockstate) const Obj_Entry *defobj; def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj, - false, cache, lockstate); + flags, cache, lockstate); if (def == NULL) goto done; @@ -200,7 +202,7 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, RtldLockState *lockstate) const Obj_Entry *defobj; def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj, - false, cache, lockstate); + flags, cache, lockstate); if (def == NULL) goto done; @@ -220,7 +222,7 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, RtldLockState *lockstate) Elf_Addr add; def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj, - false, cache, lockstate); + flags, cache, lockstate); if (def == NULL) goto done; @@ -253,7 +255,7 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, RtldLockState *lockstate) const Obj_Entry *defobj; def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj, - false, cache, lockstate); + flags, cache, lockstate); if (def == NULL) goto done; @@ -267,7 +269,7 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, RtldLockState *lockstate) const Obj_Entry *defobj; def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj, - false, cache, lockstate); + flags, cache, lockstate); if (def == NULL) goto done; @@ -286,7 +288,7 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, RtldLockState *lockstate) done: if (cache != NULL) free(cache); - return(r); + return (r); } /* Process the PLT relocations. */ @@ -322,7 +324,7 @@ reloc_plt(Obj_Entry *obj) /* Relocate the jump slots in an object. */ int -reloc_jmpslots(Obj_Entry *obj, RtldLockState *lockstate) +reloc_jmpslots(Obj_Entry *obj, int flags, RtldLockState *lockstate) { const Elf_Rel *rellim; const Elf_Rel *rel; @@ -338,8 +340,8 @@ reloc_jmpslots(Obj_Entry *obj, RtldLockState *lockstate) switch (ELF_R_TYPE(rel->r_info)) { case R_386_JMP_SLOT: where = (Elf_Addr *)(obj->relocbase + rel->r_offset); - def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj, true, NULL, - lockstate); + def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj, + SYMLOOK_IN_PLT | flags, NULL, lockstate); if (def == NULL) return (-1); if (ELF_ST_TYPE(def->st_info) == STT_GNU_IFUNC) { @@ -390,7 +392,7 @@ reloc_iresolve(Obj_Entry *obj, RtldLockState *lockstate) } int -reloc_gnu_ifunc(Obj_Entry *obj, RtldLockState *lockstate) +reloc_gnu_ifunc(Obj_Entry *obj, int flags, RtldLockState *lockstate) { const Elf_Rel *rellim; const Elf_Rel *rel; @@ -406,8 +408,8 @@ reloc_gnu_ifunc(Obj_Entry *obj, RtldLockState *lockstate) switch (ELF_R_TYPE(rel->r_info)) { case R_386_JMP_SLOT: where = (Elf_Addr *)(obj->relocbase + rel->r_offset); - def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj, true, NULL, - lockstate); + def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj, + SYMLOOK_IN_PLT | flags, NULL, lockstate); if (def == NULL) return (-1); if (ELF_ST_TYPE(def->st_info) != STT_GNU_IFUNC) |