From owner-p4-projects@FreeBSD.ORG Mon Mar 17 19:35:57 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 9B31A1065679; Mon, 17 Mar 2008 19:35:57 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5A12C1065677 for ; Mon, 17 Mar 2008 19:35:57 +0000 (UTC) (envelope-from rrs@cisco.com) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 4C9718FC13 for ; Mon, 17 Mar 2008 19:35:57 +0000 (UTC) (envelope-from rrs@cisco.com) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m2HJZvfX028831 for ; Mon, 17 Mar 2008 19:35:57 GMT (envelope-from rrs@cisco.com) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m2HJZvl3028829 for perforce@freebsd.org; Mon, 17 Mar 2008 19:35:57 GMT (envelope-from rrs@cisco.com) Date: Mon, 17 Mar 2008 19:35:57 GMT Message-Id: <200803171935.m2HJZvl3028829@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to rrs@cisco.com using -f From: "Randall R. Stewart" To: Perforce Change Reviews Cc: Subject: PERFORCE change 137942 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Mar 2008 19:35:58 -0000 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); }