Date: Mon, 17 Mar 2008 19:35:57 GMT From: "Randall R. Stewart" <rrs@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 137942 for review Message-ID: <200803171935.m2HJZvl3028829@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=137942 Change 137942 by rrs@rrs-mips2-jnpr on 2008/03/17 19:35:54 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. Affected files ... .. //depot/projects/mips2-jnpr/src/libexec/rtld-elf/mips/reloc.c#3 edit Differences ... ==== //depot/projects/mips2-jnpr/src/libexec/rtld-elf/mips/reloc.c#3 (text+ko) ==== @@ -92,12 +92,11 @@ i = (got[1] & 0x80000000) ? 2 : 1; /* Relocate the local GOT entries */ got += i; - - for (; i < local_gotno; i++) - *got++ += relocbase; + for (; i < local_gotno; i++) { + *got++ += relocbase; + } sym = symtab + gotsym; - /* Now do the global GOT entries */ for (i = gotsym; i < symtabno; i++) { *got = sym->st_value + relocbase; @@ -177,15 +176,19 @@ /* Relocate the local GOT entries */ got += i; - for (; i < obj->local_gotno; i++) - *got++ += (Elf_Addr)obj->relocbase; + dbg("got:%p for %d entries adding %x", + got, obj->local_gotno, (uint32_t)obj->relocbase); + for (; i < obj->local_gotno; i++) { + *got += (Elf_Addr)obj->relocbase; + got++; + } sym = obj->symtab + obj->gotsym; + + dbg("got:%p for %d entries", + got, obj->symtabno); /* Now do the global GOT entries */ for (i = obj->gotsym; i < obj->symtabno; i++) { - dbg(" doing got %d sym %p (%s, %x)", i - obj->gotsym, sym, - sym->st_name + obj->strtab, *got); - if (ELF_ST_TYPE(sym->st_info) == STT_FUNC && sym->st_value != 0 && sym->st_shndx == SHN_UNDEF) { /* @@ -204,24 +207,38 @@ * calls are bound immediately. - mycroft, 2003/09/24 */ *got = sym->st_value + (Elf_Addr)obj->relocbase; + if ((Elf_Addr)(*got) == (Elf_Addr)obj->relocbase) { + dbg("Warning2, i:%d maps to relocbase address:%x", + i, (uint32_t)obj->relocbase); + } + } else if (sym->st_info == ELF_ST_INFO(STB_GLOBAL, STT_SECTION)) { /* Symbols with index SHN_ABS are not relocated. */ - if (sym->st_shndx != SHN_ABS) + if (sym->st_shndx != SHN_ABS) { *got = sym->st_value + (Elf_Addr)obj->relocbase; + if ((Elf_Addr)(*got) == (Elf_Addr)obj->relocbase) { + dbg("Warning3, i:%d maps to relocbase address:%x", + i, (uint32_t)obj->relocbase); + } + } } else { /* TODO: add cache here */ def = find_symdef(i, obj, &defobj, false, NULL); - if (def == NULL) + if (def == NULL) { + dbg("Warning4, cant find symbole %d", i); return -1; + } *got = def->st_value + (Elf_Addr)defobj->relocbase; + if ((Elf_Addr)(*got) == (Elf_Addr)obj->relocbase) { + dbg("Warning4, i:%d maps to relocbase address:%x", + i, (uint32_t)obj->relocbase); + } + } - - dbg(" --> now %x", *got); ++sym; ++got; } - got = obj->pltgot; rellim = (const Elf_Rel *)((caddr_t)obj->rel + obj->relsize); for (rel = obj->rel; rel < rellim; rel++) { @@ -231,7 +248,6 @@ where = obj->relocbase + rel->r_offset; symnum = ELF_R_SYM(rel->r_info); - switch (ELF_R_TYPE(rel->r_info)) { case R_TYPE(NONE): break; @@ -240,8 +256,28 @@ /* 32-bit PC-relative reference */ def = obj->symtab + symnum; tmp = load_ptr(where); - tmp += (Elf_Addr)obj->relocbase; + 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 + ); + } + } 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 + ); + } break; default: @@ -269,6 +305,9 @@ const Elf_Rel *rellim; const Elf_Rel *rel; + dbg("reloc_plt obj:%p pltrel:%p sz:%d", obj, obj->pltrel, (int)obj->pltrelsize); + dbg("gottable %p num syms:%d", obj->pltgot, obj->symtabno ); + dbg("*****************************************************"); rellim = (const Elf_Rel *)((char *)obj->pltrel + obj->pltrelsize); for (rel = obj->pltrel; rel < rellim; rel++) { @@ -276,7 +315,7 @@ where = (Elf_Addr *)(obj->relocbase + rel->r_offset); *where += (Elf_Addr )obj->relocbase; } - + return (0); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200803171935.m2HJZvl3028829>