summaryrefslogtreecommitdiffstats
path: root/libexec/rtld-elf/sparc64
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/sparc64
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/sparc64')
-rw-r--r--libexec/rtld-elf/sparc64/reloc.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/libexec/rtld-elf/sparc64/reloc.c b/libexec/rtld-elf/sparc64/reloc.c
index 4ab0eae..ce0d945 100644
--- a/libexec/rtld-elf/sparc64/reloc.c
+++ b/libexec/rtld-elf/sparc64/reloc.c
@@ -231,7 +231,7 @@ static const long reloc_target_bitmask[] = {
__asm __volatile("flush %0 + %1" : : "r" (va), "I" (offs));
static int reloc_nonplt_object(Obj_Entry *obj, const Elf_Rela *rela,
- SymCache *cache, RtldLockState *lockstate);
+ SymCache *cache, int flags, RtldLockState *lockstate);
static void install_plt(Elf_Word *pltgot, Elf_Addr proc);
extern char _rtld_bind_start_0[];
@@ -264,6 +264,7 @@ do_copy_relocations(Obj_Entry *dstobj)
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) {
@@ -291,7 +292,8 @@ do_copy_relocations(Obj_Entry *dstobj)
}
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;
@@ -310,7 +312,7 @@ 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, rela, cache, lockstate) < 0)
+ if (reloc_nonplt_object(obj, rela, cache, flags, lockstate) < 0)
goto done;
}
r = 0;
@@ -322,7 +324,7 @@ done:
static int
reloc_nonplt_object(Obj_Entry *obj, const Elf_Rela *rela, SymCache *cache,
- RtldLockState *lockstate)
+ int flags, RtldLockState *lockstate)
{
const Obj_Entry *defobj;
const Elf_Sym *def;
@@ -385,7 +387,7 @@ reloc_nonplt_object(Obj_Entry *obj, const Elf_Rela *rela, SymCache *cache,
if (RELOC_RESOLVE_SYMBOL(type)) {
/* Find the symbol. */
def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
- false, cache, lockstate);
+ flags, cache, lockstate);
if (def == NULL)
return (-1);
@@ -526,7 +528,7 @@ reloc_plt(Obj_Entry *obj)
#define LOVAL(v) ((v) & 0x000003ff)
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;
@@ -540,7 +542,7 @@ reloc_jmpslots(Obj_Entry *obj, RtldLockState *lockstate)
assert(ELF64_R_TYPE_ID(rela->r_info) == R_SPARC_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)
return -1;
target = (Elf_Addr)(defobj->relocbase + def->st_value);
@@ -559,7 +561,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