Deleted Added
full compact
29c29
< * $FreeBSD: head/libexec/rtld-elf/powerpc/reloc.c 208256 2010-05-18 08:55:23Z rdivacky $
---
> * $FreeBSD: head/libexec/rtld-elf/powerpc64/reloc.c 209885 2010-07-10 17:43:24Z nwhitehorn $
46,48c46,50
< #define _ppc_ha(x) ((((u_int32_t)(x) & 0x8000) ? \
< ((u_int32_t)(x) + 0x10000) : (u_int32_t)(x)) >> 16)
< #define _ppc_la(x) ((u_int32_t)(x) & 0xffff)
---
> struct funcdesc {
> Elf_Addr addr;
> Elf_Addr toc;
> Elf_Addr env;
> };
50,56d51
< #define min(a,b) (((a) < (b)) ? (a) : (b))
< #define max(a,b) (((a) > (b)) ? (a) : (b))
<
< #define PLT_EXTENDED_BEGIN (1 << 13)
< #define JMPTAB_BASE(N) (18 + N*2 + ((N > PLT_EXTENDED_BEGIN) ? \
< (N - PLT_EXTENDED_BEGIN)*2 : 0))
<
112c107
< dbg("copy_reloc: src=%p,dst=%p,size=%d\n",srcaddr,dstaddr,size);
---
> dbg("copy_reloc: src=%p,dst=%p,size=%zd\n",srcaddr,dstaddr,size);
171,172c166,167
< case R_PPC_ADDR32: /* word32 S + A */
< case R_PPC_GLOB_DAT: /* word32 S + A */
---
> case R_PPC64_ADDR64: /* doubleword64 S + A */
> case R_PPC_GLOB_DAT:
188c183
< case R_PPC_RELATIVE: /* word32 B + A */
---
> case R_PPC_RELATIVE: /* doubleword64 B + A */
219c214
< case R_PPC_DTPMOD32:
---
> case R_PPC64_DTPMOD64:
230c225
< case R_PPC_TPREL32:
---
> case R_PPC64_TPREL64:
259c254
< case R_PPC_DTPREL32:
---
> case R_PPC64_DTPREL64:
272c267
< _rtld_error("%s: Unsupported relocation type %d"
---
> _rtld_error("%s: Unsupported relocation type %ld"
289a285
> int bytes = obj->nchains * sizeof(SymCache);
297,298c293,296
< cache = calloc(obj->nchains, sizeof(SymCache));
< /* No need to check for NULL here */
---
> cache = mmap(NULL, bytes, PROT_READ|PROT_WRITE, MAP_ANON,
> -1, 0);
> if (cache == MAP_FAILED)
> cache = NULL;
314,315c312,314
< if (cache != NULL)
< free(cache);
---
> if (cache) {
> munmap(cache, bytes);
> }
318a318
>
325,329c325,327
< Elf_Word *where = (Elf_Word *)(obj->relocbase + rela->r_offset);
< Elf_Addr *pltresolve, *pltlongresolve, *jmptab;
< Elf_Addr distance;
< int N = obj->pltrelasize / sizeof(Elf_Rela);
< int reloff;
---
> Elf_Addr *where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
> Elf_Addr *glink;
> long reloff;
333,334c331,333
< if (reloff < 0)
< return (-1);
---
> if (obj->priv == NULL)
> obj->priv = malloc(obj->pltrelasize);
> glink = obj->priv + reloff*sizeof(Elf_Addr)*2;
336,360c335,336
< pltlongresolve = obj->pltgot + 5;
< pltresolve = pltlongresolve + 5;
<
< distance = (Elf_Addr)pltresolve - (Elf_Addr)(where + 1);
<
< dbg(" reloc_plt_object: where=%p,pltres=%p,reloff=%x,distance=%x",
< (void *)where, (void *)pltresolve, reloff, distance);
<
< if (reloff < PLT_EXTENDED_BEGIN) {
< /* li r11,reloff */
< /* b pltresolve */
< where[0] = 0x39600000 | reloff;
< where[1] = 0x48000000 | (distance & 0x03fffffc);
< } else {
< jmptab = obj->pltgot + JMPTAB_BASE(N);
< jmptab[reloff] = (u_int)pltlongresolve;
<
< /* lis r11,jmptab[reloff]@ha */
< /* lwzu r12,jmptab[reloff]@l(r11) */
< /* mtctr r12 */
< /* bctr */
< where[0] = 0x3d600000 | _ppc_ha(&jmptab[reloff]);
< where[1] = 0x858b0000 | _ppc_la(&jmptab[reloff]);
< where[2] = 0x7d8903a6;
< where[3] = 0x4e800420;
---
> if ((reloff < 0) || (reloff >= 0x8000)) {
> return (-1);
362d337
<
364,367c339
< /*
< * The icache will be sync'd in init_pltgot, which is called
< * after all the slots have been updated
< */
---
> dbg(" reloc_plt_object: where=%p,reloff=%lx,glink=%p", (void *)where, reloff, glink);
368a341,345
> memcpy(where, _rtld_bind_start, sizeof(struct funcdesc));
> ((struct funcdesc *)(where))->env = (Elf_Addr)glink;
> *(glink++) = (Elf_Addr)obj;
> *(glink++) = reloff*sizeof(Elf_Rela);
>
383d359
<
443,445c419
< * Update the value of a PLT jump slot. Branch directly to the target if
< * it is within +/- 32Mb, otherwise go indirectly via the pltcall
< * trampoline call and jump table.
---
> * Update the value of a PLT jump slot.
451,452c425,427
< Elf_Addr offset;
< const Elf_Rela *rela = (const Elf_Rela *) rel;
---
> dbg(" reloc_jmpslot: where=%p, target=%p (%#lx + %#lx)",
> (void *)wherep, (void *)target, *(Elf_Addr *)target,
> (Elf_Addr)defobj->relocbase);
454,456d428
< dbg(" reloc_jmpslot: where=%p, target=%p",
< (void *)wherep, (void *)target);
<
462d433
< offset = target - (Elf_Addr)wherep;
464,472c435,441
< if (abs(offset) < 32*1024*1024) { /* inside 32MB? */
< /* b value # branch directly */
< *wherep = 0x48000000 | (offset & 0x03fffffc);
< __syncicache(wherep, 4);
< } else {
< Elf_Addr *pltcall, *jmptab;
< int distance;
< int N = obj->pltrelasize / sizeof(Elf_Rela);
< int reloff = rela - obj->pltrela;
---
> memcpy(wherep, (void *)target, sizeof(struct funcdesc));
> if (((struct funcdesc *)(wherep))->addr < (Elf_Addr)defobj->relocbase) {
> /*
> * XXX: It is possible (e.g. LD_BIND_NOW) that the function
> * descriptor we are copying has not yet been relocated.
> * If this happens, fix it.
> */
474,495c443,446
< if (reloff < 0)
< return (-1);
<
< pltcall = obj->pltgot;
<
< dbg(" reloc_jmpslot: indir, reloff=%x, N=%x\n",
< reloff, N);
<
< jmptab = obj->pltgot + JMPTAB_BASE(N);
< jmptab[reloff] = target;
<
< if (reloff < PLT_EXTENDED_BEGIN) {
< /* for extended PLT entries, we keep the old code */
<
< distance = (Elf_Addr)pltcall - (Elf_Addr)(wherep + 1);
<
< /* li r11,reloff */
< /* b pltcall # use indirect pltcall routine */
< wherep[0] = 0x39600000 | reloff;
< wherep[1] = 0x48000000 | (distance & 0x03fffffc);
< __syncicache(wherep, 8);
< }
---
> ((struct funcdesc *)(wherep))->addr +=
> (Elf_Addr)defobj->relocbase;
> ((struct funcdesc *)(wherep))->toc +=
> (Elf_Addr)defobj->relocbase;
497a449,450
> __asm __volatile("dcbst 0,%0; sync" :: "r"(wherep) : "memory");
>
501,508d453
<
< /*
< * Setup the plt glue routines.
< */
< #define PLTCALL_SIZE 20
< #define PLTLONGRESOLVE_SIZE 20
< #define PLTRESOLVE_SIZE 24
<
512,580d456
< Elf_Word *pltcall, *pltresolve, *pltlongresolve;
< Elf_Word *jmptab;
< int N = obj->pltrelasize / sizeof(Elf_Rela);
<
< pltcall = obj->pltgot;
<
< if (pltcall == NULL) {
< return;
< }
<
< /*
< * From the SVR4 PPC ABI:
< *
< * 'The first 18 words (72 bytes) of the PLT are reserved for
< * use by the dynamic linker.
< * ...
< * 'If the executable or shared object requires N procedure
< * linkage table entries, the link editor shall reserve 3*N
< * words (12*N bytes) following the 18 reserved words. The
< * first 2*N of these words are the procedure linkage table
< * entries themselves. The static linker directs calls to bytes
< * (72 + (i-1)*8), for i between 1 and N inclusive. The remaining
< * N words (4*N bytes) are reserved for use by the dynamic linker.'
< */
<
< /*
< * Copy the absolute-call assembler stub into the first part of
< * the reserved PLT area.
< */
< memcpy(pltcall, _rtld_powerpc_pltcall, PLTCALL_SIZE);
<
< /*
< * Determine the address of the jumptable, which is the dyn-linker
< * reserved area after the call cells. Write the absolute address
< * of the jumptable into the absolute-call assembler code so it
< * can determine this address.
< */
< jmptab = obj->pltgot + JMPTAB_BASE(N);
< pltcall[1] |= _ppc_ha(jmptab); /* addis 11,11,jmptab@ha */
< pltcall[2] |= _ppc_la(jmptab); /* lwz 11,jmptab@l(11) */
<
< /*
< * Skip down 20 bytes into the initial reserved area and copy
< * in the standard resolving assembler call. Into this assembler,
< * insert the absolute address of the _rtld_bind_start routine
< * and the address of the relocation object.
< *
< * We place pltlongresolve first, so it can fix up its arguments
< * and then fall through to the regular PLT resolver.
< */
< pltlongresolve = obj->pltgot + 5;
<
< memcpy(pltlongresolve, _rtld_powerpc_pltlongresolve,
< PLTLONGRESOLVE_SIZE);
< pltlongresolve[0] |= _ppc_ha(jmptab); /* lis 12,jmptab@ha */
< pltlongresolve[1] |= _ppc_la(jmptab); /* addi 12,12,jmptab@l */
<
< pltresolve = pltlongresolve + PLTLONGRESOLVE_SIZE/sizeof(uint32_t);
< memcpy(pltresolve, _rtld_powerpc_pltresolve, PLTRESOLVE_SIZE);
< pltresolve[0] |= _ppc_ha(_rtld_bind_start);
< pltresolve[1] |= _ppc_la(_rtld_bind_start);
< pltresolve[3] |= _ppc_ha(obj);
< pltresolve[4] |= _ppc_la(obj);
<
< /*
< * Sync the icache for the byte range represented by the
< * trampoline routines and call slots.
< */
< __syncicache(pltcall, 72 + N * 8);
586c462
< register Elf_Addr **tp __asm__("r2");
---
> register Elf_Addr **tp __asm__("r13");
597c473
< _tp = (Elf_Addr **) ((char *) allocate_tls(list, NULL, TLS_TCB_SIZE, 8)
---
> _tp = (Elf_Addr **) ((char *)allocate_tls(list, NULL, TLS_TCB_SIZE, 16)
610c486
< register Elf_Addr **tp __asm__("r2");
---
> register Elf_Addr **tp __asm__("r13");