From owner-freebsd-toolchain@freebsd.org Tue Dec 15 03:34:44 2015 Return-Path: Delivered-To: freebsd-toolchain@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 629FAA47F8B for ; Tue, 15 Dec 2015 03:34:44 +0000 (UTC) (envelope-from markmi@dsl-only.net) Received: from asp.reflexion.net (outbound-mail-211-152.reflexion.net [208.70.211.152]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 23FD11E7A for ; Tue, 15 Dec 2015 03:34:43 +0000 (UTC) (envelope-from markmi@dsl-only.net) Received: (qmail 9419 invoked from network); 15 Dec 2015 03:34:36 -0000 Received: from unknown (HELO mail-cs-02.app.dca.reflexion.local) (10.81.19.2) by 0 (rfx-qmail) with SMTP; 15 Dec 2015 03:34:36 -0000 Received: by mail-cs-02.app.dca.reflexion.local (Reflexion email security v7.80.0) with SMTP; Mon, 14 Dec 2015 22:34:35 -0500 (EST) Received: (qmail 5775 invoked from network); 15 Dec 2015 03:34:35 -0000 Received: from unknown (HELO iron2.pdx.net) (69.64.224.71) by 0 (rfx-qmail) with SMTP; 15 Dec 2015 03:34:35 -0000 X-No-Relay: not in my network X-No-Relay: not in my network Received: from [192.168.1.8] (c-76-115-7-162.hsd1.or.comcast.net [76.115.7.162]) by iron2.pdx.net (Postfix) with ESMTPSA id 304B31C43BA; Mon, 14 Dec 2015 19:34:30 -0800 (PST) From: Mark Millard Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Subject: powerpc64 11.0-CURRENT lib32/libc.so.7 _init dies (powerpc64-gcc/WITH_LIBCPLUSPLUS based): details of how Message-Id: <3FCCD60E-E5EB-4BB4-8C4A-767AE93C8945@dsl-only.net> Date: Mon, 14 Dec 2015 19:34:35 -0800 To: FreeBSD PowerPC ML , FreeBSD Toolchain Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2104\)) X-Mailer: Apple Mail (2.2104) X-BeenThere: freebsd-toolchain@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Maintenance of FreeBSD's integrated toolchain List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Dec 2015 03:34:44 -0000 If I avoid use of lib32 I can use powerpc64-gcc on a powerpc64 PowerMac = G5 to build and then install kernel and world, including WITH_BOOT=3D. = Rebooting and running works fine. WITH_LIB32=3D does build and install = as well --but it does not run fine. After the reboot compiling/linking the below source code with -m32 via = powerpc64-gcc running the a.out has lib32/libc.so.7 die in libc.so.7's = _init: > # more main.c > int main() > { > return 0; > } > # file a.out > a.out: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 = (FreeBSD), dynamically linked, interpreter /libexec/ld-elf32.so.1, = FreeBSD-style, for FreeBSD 11.0 (1100091), not stripped > Reading symbols from a.out...(no debugging symbols found)...done. > (gdb) start > Temporary breakpoint 1 at 0x1800684 > Starting program: /root/c_tests/a.out=20 >=20 > Program received signal SIGSEGV, Segmentation fault. > 0x41867ee0 in _init () from /usr/lib32/libc.so.7 > (gdb) x/20i 0x41867ecc > 0x41867ecc <_init>: stwu r1,-16(r1) > 0x41867ed0 <_init+4>: mflr r0 > 0x41867ed4 <_init+8>: stw r31,12(r1) > 0x41867ed8 <_init+12>: stw r0,20(r1) > 0x41867edc <_init+16>: mr r31,r1 > =3D> 0x41867ee0 <_init+20>: lwz r3,-11432(r30) > 0x41867ee4 <_init+24>: lwz r9,0(r3) > 0x41867ee8 <_init+28>: cmpwi cr7,r9,0 > 0x41867eec <_init+32>: beq cr7,0x41867f04 <_init+56> . . . so r30 is as it was at the indirect call from objlist_call_init . = . . > (gdb) x/150i objlist_call_init > 0x41814c74 : stwu r1,-64(r1) > 0x41814c78 : mflr r0 > 0x41814c7c : bl 0x4183bb58 > 0x41814c80 : li r8,0 > 0x41814c84 : stw r30,56(r1) > 0x41814c88 : mflr r30 > . . . > 0x41814d88 : bl 0x418131b0 = > 0x41814d8c : lwz r9,4(r28) > 0x41814d90 : lwz r5,256(r9) > 0x41814d94 : mtctr r5 > 0x41814d98 : bctrl > . . . . . . which established r30=3D=3D0x4183bb58+4 (from the bl prior to the = mflr above). . . > (gdb) x/4i 0x4183bb58 > 0x4183bb58: blrl > 0x4183bb5c <_SDA_BASE_>: .long 0x2b3f8 > 0x4183bb60 <_SDA_BASE_+4>: .long 0x0 > 0x4183bb64 <_SDA_BASE_+8>: .long 0x0 > (gdb) info registers > r0 0x41814d9c 1098993052 > r1 0xffffd730 4294956848 > r2 0x41835508 1099126024 > r3 0x0 0 > r4 0x4183c4dc 1099154652 > r5 0x41867ecc 1099333324 > r6 0x0 0 > r7 0x1000 4096 > r8 0x0 0 > r9 0x0 0 > r10 0x4182f200 1099100672 > r11 0xffffd780 4294956928 > r12 0x41814d58 1098992984 > r13 0x0 0 > r14 0x6474e552 1685382482 > r15 0x6474e551 1685382481 > r16 0x2 2 > r17 0x4183b48c 1099150476 > r18 0x4182f000 1099100160 > r19 0x0 0 > r20 0x1 1 > r21 0x0 0 > r22 0x4183bb90 1099152272 > r23 0xffffd788 4294956936 > r24 0x4183bbb4 1099152308 > r25 0x4183bbc8 1099152328 > r26 0x4183bbcc 1099152332 > r27 0x4183bbec 1099152364 > r28 0x41830050 1099104336 > r29 0x0 0 > r30 0x4183bb5c 1099152220 > r31 0xffffd730 4294956848 > pc 0x41867ee0 0x41867ee0 <_init+20> > msr > cr 0x28000482 671089794 > lr 0x41814d9c 0x41814d9c > ctr 0x41867ecc 1099333324 > xer 0x20000000 536870912 > (gdb) x 0x4183bb5c-11432 > 0x41838eb4: Cannot access memory at address 0x41838eb4 That subtraction being from "lwz r3,-11432(r30)". My guess would be that the r30 value and the offset in _init are not = matched up correctly. I've not tracked down where the _init code at and = after _init+20 comes from (i.e., _init at and after 0x41867ee0). Context details, ignore unless you care: (tabs and such probably not preserved) > # freebsd-version -ku; uname -aKU > 11.0-CURRENT > 11.0-CURRENT > FreeBSD FBSDG5C0 11.0-CURRENT FreeBSD 11.0-CURRENT #1 r291891M: Wed = Dec 9 09:15:33 PST 2015 = root@FBSDG5C0:/usr/obj/xtoolchain/powerpc.powerpc64/usr/src/sys/GENERIC64v= tsc-NODEBUG powerpc 1100091 1100091 > # more ~/src.configs/src.conf.powerpc64-xtoolchain.powerpc64-host=20 > KERNCONF=3DGENERIC64vtsc-NODEBUG > TARGET=3Dpowerpc > TARGET_ARCH=3Dpowerpc64 > WITHOUT_CROSS_COMPILER=3D > # > # 1 thing that fails to build if attempted: > WITHOUT_CLANG_EXTRAS=3D > # > WITH_FAST_DEPEND=3D > WITH_LIBCPLUSPLUS=3D > WITH_LIB32=3D > WITH_BOOT=3D > WITH_CLANG=3D > WITH_CLANG_IS_CC=3D > WITH_CLANG_FULL=3D > WITH_LLDB=3D > # > WITHOUT_GCC=3D > WITHOUT_GNUCXX=3D > # > NO_WERROR=3D > MALLOC_PRODUCTION=3D > #CFLAGS+=3D -DELF_VERBOSE > # > WITH_DEBUG=3D > WITH_DEBUG_FILES=3D > # > CC=3D/usr/local/bin/powerpc64-portbld-freebsd11.0-gcc > CXX=3D/usr/local/bin/powerpc64-portbld-freebsd11.0-g++ > CPP=3D/usr/local/bin/powerpc64-portbld-freebsd11.0-cpp > CROSS_BINUTILS_PREFIX=3D/usr/local/powerpc64-freebsd/bin/ > X_COMPILER_TYPE=3Dgcc > # > DEPFLAGS+=3D -isystem = /usr/obj/xtoolchain/powerpc.powerpc64/usr/src/tmp/usr/include/. = -I/usr/obj/xtoolchain/powerpc.powerpc64/usr/src/tmp/usr/include/c++/v1/. = -I/usr/include/c++/v1/. > # > CFLAGS+=3D -isystem = /usr/obj/xtoolchain/powerpc.powerpc64/usr/src/tmp/usr/include/. = -Wl,-rpath-link = -Wl,/usr/obj/xtoolchain/powerpc.powerpc64/usr/src/tmp/usr/lib/. = -Wl,-rpath-link = -Wl,/usr/obj/xtoolchain/powerpc.powerpc64/usr/src/tmp/lib/. = -L/usr/obj/xtoolchain/powerpc.powerpc64/usr/src/tmp/usr/lib/. = -L/usr/obj/xtoolchain/powerpc.powerpc64/usr/src/tmp/lib/. > # > LDFLAGS+=3D -Wl,-rpath-link = -Wl,/usr/obj/xtoolchain/powerpc.powerpc64/usr/src/tmp/usr/lib/. = -Wl,-rpath-link = -Wl,/usr/obj/xtoolchain/powerpc.powerpc64/usr/src/tmp/lib/. = -L/usr/obj/xtoolchain/powerpc.powerpc64/usr/src/tmp/usr/lib/. = -L/usr/obj/xtoolchain/powerpc.powerpc64/usr/src/tmp/lib/. > # > CXXFLAGS+=3D -isystem = /usr/obj/xtoolchain/powerpc.powerpc64/usr/src/tmp/usr/include/. = -I/usr/obj/xtoolchain/powerpc.powerpc64/usr/src/tmp/usr/include/c++/v1/. = -std=3Dgnu++11 > # > CXXFLAGS+=3D -I/usr/include/c++/v1/. -std=3Dgnu++11 -L/usr/lib/. > # svnlite diff /usr/src/ > Index: /usr/src/sys/boot/ofw/Makefile.inc > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- /usr/src/sys/boot/ofw/Makefile.inc (revision 291891) > +++ /usr/src/sys/boot/ofw/Makefile.inc (working copy) > @@ -2,7 +2,7 @@ > =20 > .if ${MACHINE_ARCH} =3D=3D "powerpc64" > CFLAGS+=3D -m32 -mcpu=3Dpowerpc > -LDFLAGS+=3D -m elf32ppc_fbsd > +LDFLAGS+=3D -Wl,-m -Wl,elf32ppc_fbsd > .endif > =20 > .include "../Makefile.inc" > Index: /usr/src/sys/boot/powerpc/Makefile.inc > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- /usr/src/sys/boot/powerpc/Makefile.inc (revision 291891) > +++ /usr/src/sys/boot/powerpc/Makefile.inc (working copy) > @@ -2,6 +2,7 @@ > =20 > .if ${MACHINE_ARCH} =3D=3D "powerpc64" > CFLAGS+=3D -m32 -mcpu=3Dpowerpc > +LDFLAGS+=3D -Wl,-m -Wl,elf32ppc_fbsd > .endif > =20 > .include "../Makefile.inc" > Index: /usr/src/sys/boot/uboot/Makefile.inc > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- /usr/src/sys/boot/uboot/Makefile.inc (revision 291891) > +++ /usr/src/sys/boot/uboot/Makefile.inc (working copy) > @@ -2,7 +2,7 @@ > =20 > .if ${MACHINE_ARCH} =3D=3D "powerpc64" > CFLAGS+=3D -m32 -mcpu=3Dpowerpc > -LDFLAGS+=3D -m elf32ppc_fbsd > +LDFLAGS+=3D -Wl,-m -Wl,elf32ppc_fbsd > .endif > =20 > .include "../Makefile.inc" > Index: /usr/src/sys/powerpc/ofw/ofw_machdep.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- /usr/src/sys/powerpc/ofw/ofw_machdep.c (revision 291891) > +++ /usr/src/sys/powerpc/ofw/ofw_machdep.c (working copy) > @@ -110,6 +110,23 @@ > * Assume that interrupt are disabled at this point, or > * SPRG1-3 could be trashed > */ > +#if defined(AIM) && defined(__powerpc64__) > +/* HACK: PowerMac G5 specific code to avoid demonstrated hangs in > + * the early boot time frame. > + * This would need a live test for PowerMac vs. not in order > + * to remove HACK status. > + */ > + if (1) > + __asm __volatile("mfsprg0 %0\n\t" > + "mtsprg1 %1\n\t" > + "mtsprg2 %2\n\t" > + "mtsprg3 %3\n\t" > + : "=3D&r"(ofw_sprg0_save) > + : "r"(ofmsr[2]), > + "r"(ofmsr[3]), > + "r"(ofmsr[4])); > + else > +#endif > __asm __volatile("mfsprg0 %0\n\t" > "mtsprg0 %1\n\t" > "mtsprg1 %2\n\t" > # svnlite diff /usr/ports/ > Index: = /usr/ports/devel/powerpc64-gcc/files/patch-gcc-freebsd-powerpc64 > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- /usr/ports/devel/powerpc64-gcc/files/patch-gcc-freebsd-powerpc64 = (revision 403711) > +++ /usr/ports/devel/powerpc64-gcc/files/patch-gcc-freebsd-powerpc64 = (working copy) > @@ -1,5 +1,5 @@ > ---- gcc/config/rs6000/freebsd64.h 2015-11-28 09:06:13.019999000 = -0800 > -+++ gcc/config/rs6000/freebsd64.h 2015-11-28 09:16:10.459373000 = -0800 > +--- gcc/config/rs6000/freebsd64.h.orig 2015-01-05 = 04:33:28.000000000 -0800 > ++++ gcc/config/rs6000/freebsd64.h 2015-12-09 00:14:28.520684000 = -0800 > @@ -65,6 +65,13 @@ > #define INVALID_64BIT "-m%s not supported in this configuration" > #define INVALID_32BIT INVALID_64BIT > @@ -27,3 +27,12 @@ > if (rs6000_isa_flags & OPTION_MASK_EABI) \ > { \ > rs6000_isa_flags &=3D ~OPTION_MASK_EABI; \ > +@@ -304,7 +317,7 @@ > +=20 > + /* rs6000.h gets this wrong for FreeBSD. We use the GCC defaults = instead. */ > + #undef WCHAR_TYPE > +-#define WCHAR_TYPE (TARGET_64BIT ? "int" : "long int") > ++#define WCHAR_TYPE "int" > + #undef WCHAR_TYPE_SIZE > + #define WCHAR_TYPE_SIZE 32 > +=20 powerpc64-gcc's misclassification of the base type for L". . ." notation = does need to be patched. Otherwise building lib32 fails for type errors. = That is what the above is for. Having a powerpc64 self-host powerpc64-gcc has a work around of copying = 6 files to the right names/places near the end of the powerpc64-gcc = build and continuing it from that state. (I've not made a patch to deal = with powerpc64-gcc not really being a cross-compiler context for this.) > # ls -l /usr/lib/libstdc+* > lrwxr-xr-x 1 root wheel 8 Dec 5 05:41 /usr/lib/libstdc++.a -> = libc++.a > lrwxr-xr-x 1 root wheel 9 Dec 5 05:41 /usr/lib/libstdc++.so -> = libc++.so > # ls -l /usr/bin/g[c+][c+] > lrwxr-xr-x 1 root wheel 48 Dec 5 05:38 /usr/bin/g++ -> = /usr/local/bin/powerpc64-portbld-freebsd11.0-g++ > lrwxr-xr-x 1 root wheel 48 Dec 5 05:38 /usr/bin/gcc -> = /usr/local/bin/powerpc64-portbld-freebsd11.0-gcc These symbolic links deal with some environment-forced/automatic = references to what would otherwise be to missing files. =3D=3D=3D Mark Millard markmi at dsl-only.net