Date: Mon, 24 Feb 2003 01:28:57 -0800 (PST) From: Serguei Tzukanov <tzukanov@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 25750 for review Message-ID: <200302240928.h1O9SvOJ063806@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=25750 Change 25750 by tzukanov@tzukanov_antares on 2003/02/24 01:27:59 Make dynamic linker actually work. Affected files ... .. //depot/projects/s390/lib/csu/s390/crti.S#2 edit .. //depot/projects/s390/lib/libc/s390/SYS.h#2 edit .. //depot/projects/s390/libexec/Makefile#6 edit .. //depot/projects/s390/libexec/rtld-elf/s390/Makefile.inc#2 edit .. //depot/projects/s390/libexec/rtld-elf/s390/lockdflt.c#2 edit .. //depot/projects/s390/libexec/rtld-elf/s390/reloc.c#2 edit .. //depot/projects/s390/libexec/rtld-elf/s390/rtld_machdep.h#2 edit .. //depot/projects/s390/libexec/rtld-elf/s390/rtld_start.S#2 edit .. //depot/projects/s390/libexec/rtld-elf/s390x/Makefile.inc#2 edit .. //depot/projects/s390/libexec/rtld-elf/s390x/lockdflt.c#2 delete .. //depot/projects/s390/libexec/rtld-elf/s390x/rtld_machdep.h#2 delete .. //depot/projects/s390/libexec/rtld-elf/s390x/rtld_start.S#2 delete .. //depot/projects/s390/sys/s390/conf/GENERIC#8 edit .. //depot/projects/s390/sys/s390/s390/machdep.c#6 edit Differences ... ==== //depot/projects/s390/lib/csu/s390/crti.S#2 (text+ko) ==== @@ -35,10 +35,12 @@ lr %r2, %r15 lr %r3, %r0 ahi %r15, -96 - bras %r13, 1f + bras %r13, _do_start +#if 0 .long _do_start 1: l %r1, 0(%r13) br %r1 +#endif /* not reached (I hope) */ .section .init, "ax", @progbits ==== //depot/projects/s390/lib/libc/s390/SYS.h#2 (text+ko) ==== @@ -16,7 +16,7 @@ bras %r13, 1f; \ 0: .long _GLOBAL_OFFSET_TABLE_ - 0b; \ .long .cerror@PLT - 0b; \ -1: l %r12, 0(%r12); \ +1: l %r12, 0(%r13); \ la %r12, 0(%r12, %r13); \ l %r1, 4(%r13); \ b 0(%r1, %r13); ==== //depot/projects/s390/libexec/Makefile#6 (text+ko) ==== @@ -23,6 +23,7 @@ rpc.rwalld \ rpc.sprayd \ rshd \ + rtld-elf \ save-entropy \ talkd \ tcpd \ @@ -30,10 +31,6 @@ xtend \ ypxfr -.if ${MACHINE_ARCH} != s390 -SUBDIR+=rtld-elf -.endif - .if !defined(NO_BIND) SUBDIR+=named-xfer .endif ==== //depot/projects/s390/libexec/rtld-elf/s390/Makefile.inc#2 (text+ko) ==== @@ -1,1 +1,3 @@ # $FreeBSD: src/libexec/rtld-elf/s390/Makefile.inc,v 1.0 2002/03/13 02:40:39 tzukanov Exp $ + +CFLAGS+= -DDEBUG ==== //depot/projects/s390/libexec/rtld-elf/s390/lockdflt.c#2 (text+ko) ==== @@ -33,7 +33,12 @@ #include "debug.h" #include "rtld.h" -#define CACHE_LINE_SIZE 32 /* What's the actual value of this for G5/G6? */ +/* What're the actual value of these for G5/G6/z800/z900? */ +#ifdef __s390x__ +#define CACHE_LINE_SIZE 128 +#else +#define CACHE_LINE_SIZE 32 +#endif #define WAFLAG 0x1 /* A writer holds the lock */ #define RC_INCR 0x2 /* Adjusts count of readers desiring lock */ @@ -51,8 +56,10 @@ { __asm volatile ( " bcr 15, 0\n" - " cs %[ov], %[nv], (%[p])" - : [ov]"=&r"(ov) : [nv]"r"(nv), [p]"a"(p): "cc"); + " cs %[ov], %[nv], 0(%[p])" + : [ov]"=&r"(ov) + : [nv]"r"(nv), [p]"a"(p) + : "cc"); return ov; } @@ -75,7 +82,7 @@ free(base); base = xmalloc(2 * CACHE_LINE_SIZE); p = (char *)base; - r = (uintptr_t)p % CACHE_LINE_SIZE + r = (uintptr_t)p % CACHE_LINE_SIZE; if (r) p += CACHE_LINE_SIZE - r; } ==== //depot/projects/s390/libexec/rtld-elf/s390/reloc.c#2 (text+ko) ==== @@ -2,7 +2,7 @@ * Copyright 1996, 1997, 1998, 1999 John D. Polstra. * All rights reserved. * - * Modified for S/390 by Serguei Tzukanov in October, 2002. + * Modified for S/390 and zSeries by Serguei Tzukanov in October, 2002. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -43,6 +43,65 @@ #include "debug.h" #include "rtld.h" +#define _SHIFT1 (1 << 7) + +#define _B8 1 +#define _L12 2 +#define _H16 3 +#define _PC16 (_H16 | _SHIFT1) +#define _W32 4 +#define _PC32 (_W32 | _SHIFT1) +#define _Q64 5 + +#ifdef __s390x__ +#define _AD _Q64 +#else +#define _AD _W32 +#endif + +#define _B 1 +#define _G 2 +#define _L 3 +#define _O 4 +#define _P 5 +#define _S 6 + +#define _ILL 0 + +static struct _reldesc { + uint8_t op[4]; +} reldesc[] = { + {{ _ILL }}, /* R_390_NONE */ + {{ _B8, _S, }}, /* R_390_8 */ + {{ _L12, _S, }}, /* R_390_12 */ + {{ _H16, _S, }}, /* R_390_16 */ + {{ _W32, _S, }}, /* R_390_32 */ + {{ _W32, _S, _P }}, /* R_390_PC32 */ + {{ _L12, _O, }}, /* R_390_GOT12 */ + {{ _W32, _O, }}, /* R_390_GOT32 */ + {{ _W32, _L, }}, /* R_390_PLT32 */ + {{ _ILL }}, /* R_390_COPY */ + {{ _AD, _S }}, /* R_390_GLOB_DAT */ + {{ _ILL }}, /* R_390_JMP_SLOT */ + {{ _AD, _B }}, /* R_390_RELATIVE */ + {{ _AD, _S, _G }}, /* R_390_GOTOFF */ + {{ _AD, _G, _P }}, /* R_390_GOTPC */ + {{ _H16, _O }}, /* R_390_GOT16 */ + {{ _H16, _S, _P }}, /* R_390_PC16 */ + {{ _PC16, _S, _P }}, /* R_390_PC16DBL */ + {{ _PC16, _L, _P }}, /* R_390_PLT16DBL */ +#ifdef __s390x__ + {{ _PC32, _S, _P }}, /* R_390_PC32DBL */ + {{ _PC32, _L, _P }}, /* R_390_PLT32DBL */ + {{ _PC32, _G, _P }}, /* R_390_GOTPCDBL */ + {{ _Q64, _S }}, /* R_390_64 */ + {{ _Q64, _S, _P }}, /* R_390_PC64 */ + {{ _Q64, _O }}, /* R_390_GOT64 */ + {{ _Q64, _L }}, /* R_390_PLT64 */ + {{ _PC32, _G, _O, _P }}, /* R_390_GOTENT */ +#endif +}; + /* * Process the special R_390_COPY relocations in the main program. These * copy data from a shared object into a region in the main program's BSS @@ -53,15 +112,13 @@ int do_copy_relocations(Obj_Entry *dstobj) { - const Elf_Rela *relalim; - const Elf_Rela *rela; - const Elf_Sym *dstsym; - const Elf_Sym *srcsym; - void *dstaddr; + const Elf_Rela *rela, *relalim; + const Elf_Sym *dstsym, *srcsym; const void *srcaddr; + unsigned long hash; Obj_Entry *srcobj; - unsigned long hash; const char *name; + void *dstaddr; size_t size; /* COPY relocations are invalid elsewhere. */ @@ -109,12 +166,88 @@ } } +static int +reloc_non_plt_one(Obj_Entry *obj, const Elf_Rela *rela, SymCache *cache) +{ + const Obj_Entry *defobj; + Elf_Addr *where, value; + struct _reldesc desc; + const Elf_Sym *def; + int type, field, i; + + type = ELF_R_TYPE(rela->r_info); + desc = reldesc[type]; + field = desc.op[0]; + if (field == _ILL) { + return 0; + } + + where = (Elf_Addr *)(obj->relocbase + rela->r_offset); + + value = rela->r_addend; + for (i = 1; desc.op[i] && (i < 4); i++) { + switch (desc.op[i]) { + case _B: + value += (Elf_Addr)obj->relocbase; + break; + case _G: + dbg("_G\n"); + break; + case _L: + dbg("_L\n"); + break; + case _O: + dbg("_O\n"); + break; + case _P: + value -= (Elf_Addr)where; + break; + case _S: + defobj = NULL; + def = find_symdef(ELF_R_SYM(rela->r_info), + obj, &defobj, false, cache); + if (def == NULL) + return -1; + + value += (Elf_Addr)(defobj->relocbase + def->st_value); + break; + } + } + + if (field & _SHIFT1) { + /* We need shifting with sign copying. */ + value = ((long)value) >> 1; + field &= ~_SHIFT1; + } + + switch (field) { + case _B8: + *(uint8_t *)where = (uint8_t)value; + break; + case _L12: + *(uint16_t *)where += value << 4; + break; + case _H16: + *(int16_t *)where = (int16_t)value; + break; + case _W32: + *(int32_t *)where = (int32_t)value; + break; +#ifdef __s390x__ + case _Q64: + *where = value; +#endif + } + + return 0; +} + /* Process the non-PLT relocations. */ int reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld) { - const Elf_Rel *relalim; - const Elf_Rel *rela; + const Elf_Rela *relalim; + const Elf_Rela *rela; SymCache *cache; size_t bytes; int error; @@ -122,7 +255,7 @@ bytes = obj->nchains * sizeof(SymCache); cache = mmap(NULL, bytes, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0); - if (cache == MMAP_FAILED) + if (cache == MAP_FAILED) cache = NULL; else memset(cache, 0, obj->nchains * sizeof(SymCache)); @@ -157,25 +290,18 @@ where = (Elf_Addr *)(obj->relocbase + rela->r_offset); /* Relocate the GOT slot pointing into the PLT. */ - where = (Elf_Addr *)(obj->relocbase + rel->r_offset); + where = (Elf_Addr *)(obj->relocbase + rela->r_offset); *where += (Elf_Addr)obj->relocbase; } return 0; } -static void -reloc_jmpslot(Elf_Addr *wherep, Elf_Addr target, const Obj_Entry *obj) -{ - Elf_Addr offset: -} - /* Relocate the jump slots in an object. */ int reloc_jmpslots(Obj_Entry *obj) { + const Elf_Rela *rela, *relalim; const Obj_Entry *defobj; - const Elf_Rela *relalim; - const Elf_Rela *rela; Elf_Addr *where, target; const Elf_Sym *def; @@ -184,7 +310,7 @@ relalim = (const Elf_Rela *)((char *)obj->pltrela + obj->pltrelasize); for (rela = obj->pltrela; rela < relalim; rela++) { - assert(ELF_R_TYPE(rela->r_info) == R_386_JMP_SLOT); + assert(ELF_R_TYPE(rela->r_info) == R_390_JMP_SLOT); def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj, true, NULL); @@ -193,7 +319,8 @@ where = (Elf_Addr *)(obj->relocbase + rela->r_offset); target = (Elf_Addr)(defobj->relocbase + def->st_value); - reloc_jmpslot(where, target, defobj); + reloc_jmpslot(where, target, defobj, obj, + (const Elf_Rel *)rela); } obj->jmpslots_done = true; ==== //depot/projects/s390/libexec/rtld-elf/s390/rtld_machdep.h#2 (text+ko) ==== @@ -2,7 +2,7 @@ * Copyright (c) 1999, 2000 John D. Polstra. * All rights reserved. * - * Modified for S/390 by Serguei Tzukanov in July, 2002. + * Modified for S/390 and zSeries by Serguei Tzukanov in July, 2002. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -40,11 +40,13 @@ /* Fixup the jump slot at "where" to transfer control to "target". */ static inline Elf_Addr reloc_jmpslot(Elf_Addr *where, Elf_Addr target, - const struct Struct_Obj_Entry *obj) + const struct Struct_Obj_Entry *defobj, + const struct Struct_Obj_Entry *obj, + const Elf_Rel *rel) { dbg("reloc_jmpslot: *%p = %p", (void *)(where), (void *)(target)); - (*(Elf_Addr *)(where) = (Elf_Addr)(target)); + *where = target; return target; } ==== //depot/projects/s390/libexec/rtld-elf/s390/rtld_start.S#2 (text+ko) ==== @@ -10,23 +10,24 @@ #include <machine/asm.h> ENTRY(.rtld_start) - lr %r2, %r15 /* sp */ - ahi %r15, -96 -16 + lr %r2, %r15 + ahi %r15, -96 - 16 + st %r0, 96 + 8(%r15) /* save ps_strings */ + la %r4, 96 + 4(%r15) /* objp */ la %r3, 96(%r15) /* exit_proc */ - la %r4, 100(%r15) /* objp */ - st %r0, 104(%r15) /* save ps_strings */ - bras %r1, 1f -0: .long _GLOBAL_OFFSET_TABLE_ - 0b - .long _rtld@PLT - 0b; -1: l %r12, 0(%r1) - la %r12, 0(%r12, %r1) - l %r5, 4(%r1) - bas %r14, 0(%r1, %r5) /* call _rtld */ - lr %r5, %r2 - l %r0, 104(%r15) /* ps_strings */ + bras %r14, _rtld /* call _rtld */ l %r4, 96(%r15) /* cleanup */ - la %r15, 112(%r15) - br %r5 /* _start */ + l %r0, 96 + 8(%r15) /* ps_strings */ + la %r15, 96 + 16(%r15) /* sp */ + br %r2 /* _start */ ENTRY(_rtld_bind_start) - + ahi %r15, -96 - 56 + stm %r2, %r15, 96(%r15) + l %r2, 96 + 56 + 24(%r15) /* obj */ + l %r3, 96 + 56 + 28(%r15) /* reloff */ + bras %r14, _rtld_bind /* call _rtld_bind */ + lr %r1, %r2 + lm %r2, %r15, 96(%r15) + ahi %r15, 96 + 56 + br %r1 /* call resolved function */ ==== //depot/projects/s390/libexec/rtld-elf/s390x/Makefile.inc#2 (text+ko) ==== @@ -1,1 +1,5 @@ # $FreeBSD: src/libexec/rtld-elf/s390x/Makefile.inc,v 1.0 2002/03/13 02:40:39 tzukanov Exp $ + +CFLAGS+=-I${.CURDIR}/s390 + +.PATH: ${.CURDIR}/s390 ==== //depot/projects/s390/sys/s390/conf/GENERIC#8 (text+ko) ==== @@ -57,7 +57,7 @@ options COMPAT_43 # Compatible with BSD 4.3 options COMPAT_FREEBSD4 options MD_ROOT # MD is potential root device -options MD_ROOT_SIZE=4096 +options MD_ROOT_SIZE=8192 #device hhc # Debug feature device hmcsc # HMC system console ==== //depot/projects/s390/sys/s390/s390/machdep.c#6 (text+ko) ==== To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe p4-projects" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200302240928.h1O9SvOJ063806>