summaryrefslogtreecommitdiffstats
path: root/libexec/rtld-elf/powerpc
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2012-03-20 13:20:49 +0000
committerkib <kib@FreeBSD.org>2012-03-20 13:20:49 +0000
commitc49b39491ded257751332662302997df5b34fd12 (patch)
tree141ae8f14c62c6f65aeb3d57bd0ca7ebd14c319a /libexec/rtld-elf/powerpc
parente87823cf6ee42b9d37c7af7ba277341a2fd2fac9 (diff)
downloadFreeBSD-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/powerpc')
-rw-r--r--libexec/rtld-elf/powerpc/reloc.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/libexec/rtld-elf/powerpc/reloc.c b/libexec/rtld-elf/powerpc/reloc.c
index d0637f4..979e43e 100644
--- a/libexec/rtld-elf/powerpc/reloc.c
+++ b/libexec/rtld-elf/powerpc/reloc.c
@@ -92,6 +92,7 @@ do_copy_relocations(Obj_Entry *dstobj)
size = dstsym->st_size;
symlook_init(&req, name);
req.ventry = fetch_ventry(dstobj, ELF_R_SYM(rela->r_info));
+ req.flags = SYMLOOK_EARLY;
for (srcobj = dstobj->next; srcobj != NULL;
srcobj = srcobj->next) {
@@ -159,7 +160,7 @@ reloc_non_plt_self(Elf_Dyn *dynp, Elf_Addr relocbase)
*/
static int
reloc_nonplt_object(Obj_Entry *obj_rtld, Obj_Entry *obj, const Elf_Rela *rela,
- SymCache *cache, RtldLockState *lockstate)
+ SymCache *cache, int flags, RtldLockState *lockstate)
{
Elf_Addr *where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
const Elf_Sym *def;
@@ -174,7 +175,7 @@ reloc_nonplt_object(Obj_Entry *obj_rtld, Obj_Entry *obj, const Elf_Rela *rela,
case R_PPC_ADDR32: /* word32 S + A */
case R_PPC_GLOB_DAT: /* word32 S + A */
def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
- false, cache, lockstate);
+ flags, cache, lockstate);
if (def == NULL) {
return (-1);
}
@@ -221,7 +222,7 @@ reloc_nonplt_object(Obj_Entry *obj_rtld, Obj_Entry *obj, const Elf_Rela *rela,
case R_PPC_DTPMOD32:
def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
- false, cache, lockstate);
+ flags, cache, lockstate);
if (def == NULL)
return (-1);
@@ -232,7 +233,7 @@ reloc_nonplt_object(Obj_Entry *obj_rtld, Obj_Entry *obj, const Elf_Rela *rela,
case R_PPC_TPREL32:
def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
- false, cache, lockstate);
+ flags, cache, lockstate);
if (def == NULL)
return (-1);
@@ -261,7 +262,7 @@ reloc_nonplt_object(Obj_Entry *obj_rtld, Obj_Entry *obj, const Elf_Rela *rela,
case R_PPC_DTPREL32:
def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
- false, cache, lockstate);
+ flags, cache, lockstate);
if (def == NULL)
return (-1);
@@ -285,7 +286,8 @@ reloc_nonplt_object(Obj_Entry *obj_rtld, Obj_Entry *obj, const Elf_Rela *rela,
* 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_Rela *relalim;
const Elf_Rela *rela;
@@ -309,8 +311,8 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, RtldLockState *lockstate)
*/
relalim = (const Elf_Rela *)((caddr_t)obj->rela + obj->relasize);
for (rela = obj->rela; rela < relalim; rela++) {
- if (reloc_nonplt_object(obj_rtld, obj, rela, cache, lockstate)
- < 0)
+ if (reloc_nonplt_object(obj_rtld, obj, rela, cache, flags,
+ lockstate) < 0)
goto done;
}
r = 0;
@@ -416,7 +418,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_Rela *relalim;
@@ -430,7 +432,7 @@ reloc_jmpslots(Obj_Entry *obj, RtldLockState *lockstate)
assert(ELF_R_TYPE(rela->r_info) == R_PPC_JMP_SLOT);
where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
- true, NULL, lockstate);
+ SYMLOOK_IN_PLT | flags, NULL, lockstate);
if (def == NULL) {
dbg("reloc_jmpslots: sym not found");
return (-1);
@@ -525,7 +527,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 */
OpenPOWER on IntegriCloud