powerpc64 11.0-CURRENT lib32/libc.so.7 _init dies (powerpc64-gcc/WITH_LIBCPLUSPLUS based): details of how
Mark Millard
markmi at dsl-only.net
Tue Dec 15 03:34:44 UTC 2015
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=. Rebooting and running works fine. WITH_LIB32= 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
>
> 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
> => 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 <objlist_call_init>: stwu r1,-64(r1)
> 0x41814c78 <objlist_call_init+4>: mflr r0
> 0x41814c7c <objlist_call_init+8>: bl 0x4183bb58
> 0x41814c80 <objlist_call_init+12>: li r8,0
> 0x41814c84 <objlist_call_init+16>: stw r30,56(r1)
> 0x41814c88 <objlist_call_init+20>: mflr r30
> . . .
> 0x41814d88 <objlist_call_init+276>: bl 0x418131b0 <ld_utrace_log>
> 0x41814d8c <objlist_call_init+280>: lwz r9,4(r28)
> 0x41814d90 <objlist_call_init+284>: lwz r5,256(r9)
> 0x41814d94 <objlist_call_init+288>: mtctr r5
> 0x41814d98 <objlist_call_init+292>: bctrl
> . . .
. . . which established r30==0x4183bb58+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 <unavailable>
> cr 0x28000482 671089794
> lr 0x41814d9c 0x41814d9c <objlist_call_init+296>
> 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 at FBSDG5C0:/usr/obj/xtoolchain/powerpc.powerpc64/usr/src/sys/GENERIC64vtsc-NODEBUG powerpc 1100091 1100091
> # more ~/src.configs/src.conf.powerpc64-xtoolchain.powerpc64-host
> KERNCONF=GENERIC64vtsc-NODEBUG
> TARGET=powerpc
> TARGET_ARCH=powerpc64
> WITHOUT_CROSS_COMPILER=
> #
> # 1 thing that fails to build if attempted:
> WITHOUT_CLANG_EXTRAS=
> #
> WITH_FAST_DEPEND=
> WITH_LIBCPLUSPLUS=
> WITH_LIB32=
> WITH_BOOT=
> WITH_CLANG=
> WITH_CLANG_IS_CC=
> WITH_CLANG_FULL=
> WITH_LLDB=
> #
> WITHOUT_GCC=
> WITHOUT_GNUCXX=
> #
> NO_WERROR=
> MALLOC_PRODUCTION=
> #CFLAGS+= -DELF_VERBOSE
> #
> WITH_DEBUG=
> WITH_DEBUG_FILES=
> #
> CC=/usr/local/bin/powerpc64-portbld-freebsd11.0-gcc
> CXX=/usr/local/bin/powerpc64-portbld-freebsd11.0-g++
> CPP=/usr/local/bin/powerpc64-portbld-freebsd11.0-cpp
> CROSS_BINUTILS_PREFIX=/usr/local/powerpc64-freebsd/bin/
> X_COMPILER_TYPE=gcc
> #
> DEPFLAGS+= -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+= -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+= -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+= -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=gnu++11
> #
> CXXFLAGS+= -I/usr/include/c++/v1/. -std=gnu++11 -L/usr/lib/.
> # svnlite diff /usr/src/
> Index: /usr/src/sys/boot/ofw/Makefile.inc
> ===================================================================
> --- /usr/src/sys/boot/ofw/Makefile.inc (revision 291891)
> +++ /usr/src/sys/boot/ofw/Makefile.inc (working copy)
> @@ -2,7 +2,7 @@
>
> .if ${MACHINE_ARCH} == "powerpc64"
> CFLAGS+= -m32 -mcpu=powerpc
> -LDFLAGS+= -m elf32ppc_fbsd
> +LDFLAGS+= -Wl,-m -Wl,elf32ppc_fbsd
> .endif
>
> .include "../Makefile.inc"
> Index: /usr/src/sys/boot/powerpc/Makefile.inc
> ===================================================================
> --- /usr/src/sys/boot/powerpc/Makefile.inc (revision 291891)
> +++ /usr/src/sys/boot/powerpc/Makefile.inc (working copy)
> @@ -2,6 +2,7 @@
>
> .if ${MACHINE_ARCH} == "powerpc64"
> CFLAGS+= -m32 -mcpu=powerpc
> +LDFLAGS+= -Wl,-m -Wl,elf32ppc_fbsd
> .endif
>
> .include "../Makefile.inc"
> Index: /usr/src/sys/boot/uboot/Makefile.inc
> ===================================================================
> --- /usr/src/sys/boot/uboot/Makefile.inc (revision 291891)
> +++ /usr/src/sys/boot/uboot/Makefile.inc (working copy)
> @@ -2,7 +2,7 @@
>
> .if ${MACHINE_ARCH} == "powerpc64"
> CFLAGS+= -m32 -mcpu=powerpc
> -LDFLAGS+= -m elf32ppc_fbsd
> +LDFLAGS+= -Wl,-m -Wl,elf32ppc_fbsd
> .endif
>
> .include "../Makefile.inc"
> Index: /usr/src/sys/powerpc/ofw/ofw_machdep.c
> ===================================================================
> --- /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"
> + : "=&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
> ===================================================================
> --- /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 &= ~OPTION_MASK_EABI; \
> +@@ -304,7 +317,7 @@
> +
> + /* 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
> +
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.
===
Mark Millard
markmi at dsl-only.net
More information about the freebsd-ppc
mailing list