MFp4: Fix a bug in the mips relocation code that prevents shared images

from working.

From p4 filelog of the upstream file in p4

//depot/projects/mips2-jnpr/src/libexec/rtld-elf/mips/reloc.c
... #6 change 140737 edit on 2008/04/27 by gonzo@gonzo_jeeves (text+ko)

        o Looks like handler for R_MIPS_REL32 brought by CS 137942
            is broken for tradmips. Code from NetBSD's
            libexec/ld.elf_so/arch/mips/mips_reloc.c works just fine.

... #3 change 137942 edit on 2008/03/17 by rrs@rrs-mips2-jnpr (text+ko)

        Any relocation symbol lookup if its 0. It looks like
               this is the way the compiler indicates you need to
               look in another shared library. When we hit these
               as we relocate a object we will do the symbol
               lookups and setup the relocation table with the
               right value.

Submitted by:	rrs@, gonzo@
This commit is contained in:
Warner Losh 2008-10-10 05:10:10 +00:00
parent e91c7c813e
commit 2ab1831e76
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=183739

View File

@ -258,31 +258,23 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
case R_TYPE(REL32):
/* 32-bit PC-relative reference */
def = obj->symtab + symnum;
tmp = load_ptr(where);
if (tmp == 0) {
def = find_symdef(symnum, obj, &defobj, false, NULL);
if (def == NULL) {
dbg("Warning5, cant find symbole %d:%s", (int)symnum,
obj->strtab + obj->symtab[symnum].st_name);
} else {
tmp = def->st_value + (Elf_Addr)defobj->relocbase;
dbg("Correctiong symnum:%d:%s to addr:%x", (int)symnum,
obj->strtab + obj->symtab[symnum].st_name,
(u_int32_t)tmp
);
}
if (symnum >= obj->gotsym) {
tmp = load_ptr(where);
tmp += got[obj->local_gotno + symnum - obj->gotsym];
store_ptr(where, tmp);
break;
} else {
tmp += (Elf_Addr)obj->relocbase;
}
store_ptr(where, tmp);
if (tmp == (Elf_Addr)obj->relocbase) {
dbg("rel sym %p falls on relocbase symidx:%x symbol:%s", rel,
(uint32_t)ELF_R_SYM(rel->r_info),
obj->strtab + obj->symtab[symnum].st_name
);
tmp = load_ptr(where);
if (def->st_info ==
ELF_ST_INFO(STB_LOCAL, STT_SECTION)
)
tmp += (Elf_Addr)def->st_value;
tmp += (Elf_Addr)obj->relocbase;
store_ptr(where, tmp);
}
break;
default:
dbg("sym = %lu, type = %lu, offset = %p, "
"contents = %p, symbol = %s",