[Explicitly setting r2 to its expected value in gdb does let the program complete without failing.]
> On 2019-Mar-12, at 16:34, Mark Millard <mark...@yahoo.com> wrote: > > [The unoptimized code is more revealing so I switch to > presenting it and what it lead me to: more detail on > r2 being mishandled.] > >> On 2019-Mar-12, at 14:05, Mark Millard <marklmi at yahoo.com> wrote: >> >> [I got some libunwind debug output from the a.out run. This >> and a disassembly of main suggest an instruction pointer >> address is too large by 0x4 for jumping to the code that >> would call __cxa_begin_catch .] >> >>> On 2019-Mar-12, at 12:20, Mark Millard <mark...@yahoo.com> wrote: >>> >>> [I sometimes experiment with building powerpc64 (and 32-bit) via >>> more modern toolchains, here a amd64->powerpc64 cross build via >>> system-clang (so 8.0.0).] >>> >>> buildworld with WITH_LLVM_LIBUNWIND= completes for powerpc64 >>> (but not 32-bit powerpc). However, for a system installed >>> from such for pwoerpc64, the following program (for example) >>> gets a segmentation fault: >>> >>> # more ~/c_tests/exception_test.cpp >>> #include <exception> >>> >>> int main(void) >>> { >>> try { throw std::exception(); } >>> catch (std::exception& e) {} >>> return 0; >>> } >>> >>> (Note: the same a.out works under a WITHOUT_LLVM_LIBUNWIND= >>> environment, that was patched for DW_CFA_remember_state and >>> DW_CFA_restore_state handling, with the system built via >>> devel/powerpc64-xtoolchain-gcc related materials. So the >>> failure is on the system library does of things for the >>> WITH_LLVM_LIBUNWIND= context.) >>> >>> Unfortunately: >>> >>> A) devel/gdb makes extensive use of thrown C++ exceptions >>> and so does not work for a powerpc64 system based on >>> WITH_LLVM_LIBUNWIND= . >>> >>> B) The world built is not using dwarf-2 so /usr/libexec/gdb >>> is not handy/useful. >>> >>> C) CFLAGS+=-gdwarf-2 leads to system-clang having an Abort >>> trap during buildworld's compile of gcrt1.s . (Reference >>> material later, below.) >>> >>> D) lldb crashes in llvm_unreachable in >>> lldb::RegisterContextSP FreeBSDThread::GetRegisterContext() >>> on powerpc64. (Reference material later, below.) >>> >>> So I've not managed to check the backtrace for the >>> segmentation fault in the short example. >>> >>> >>> >>> For reference . . . >>> >>> >>> For (C) ( -gdwarf-2 use ): >>> >>> QUOTES >>> (gdb) bt >>> #0 thr_kill () at thr_kill.S:3 >>> #1 0x000000000474afcf in __raise (s=6) at /usr/src/lib/libc/gen/raise.c:52 >>> #2 0x00000000046cd386 in abort () at /usr/src/lib/libc/stdlib/abort.c:79 >>> #3 0x00000000047394ba in __assert (func=<optimized out>, file=<optimized >>> out>, line=<optimized out>, failedexpr=<optimized out>) at >>> /usr/src/lib/libc/gen/assert.c:51 >>> #4 0x000000000429aa9f in resetRootFile () at >>> /usr/src/contrib/llvm/include/llvm/MC/MCDwarf.h:316 >>> #5 parseDirectiveFile () at >>> /usr/src/contrib/llvm/lib/MC/MCParser/AsmParser.cpp:3377 >>> #6 parseStatement () at >>> /usr/src/contrib/llvm/lib/MC/MCParser/AsmParser.cpp:2023 >>> #7 0x000000000428cc12 in Run () at >>> /usr/src/contrib/llvm/lib/MC/MCParser/AsmParser.cpp:884 >>> #8 0x000000000163c649 in ExecuteAssembler () at >>> /usr/src/contrib/llvm/tools/clang/tools/driver/cc1as_main.cpp:503 >>> #9 cc1as_main () at >>> /usr/src/contrib/llvm/tools/clang/tools/driver/cc1as_main.cpp:589 >>> #10 0x0000000001643d10 in ExecuteCC1Tool () at >>> /usr/src/contrib/llvm/tools/clang/tools/driver/driver.cpp:312 >>> #11 main () at /usr/src/contrib/llvm/tools/clang/tools/driver/driver.cpp:382 >>> >>> void resetRootFile() { >>> assert(Header.MCDwarfFiles.empty()); >>> Header.RootFile.Name.clear(); >>> Header.resetMD5Usage(); >>> Header.HasSource = false; >>> } >>> >>> --- lib/csu__L --- >>> cc: error: unable to execute command: Abort trap (core dumped) >>> cc: error: clang integrated assembler command failed due to signal (use -v >>> to see invocation) >>> FreeBSD clang version 8.0.0 (branches/release_80 355677) (based on LLVM >>> 8.0.0) >>> Target: powerpc64-unknown-freebsd13.0 >>> Thread model: posix >>> InstalledDir: /usr/bin >>> cc: note: diagnostic msg: PLEASE submit a bug report to >>> https://bugs.freebsd.org/submit/ and include the crash backtrace, >>> preprocessed source, and associated run script. >>> cc: note: diagnostic msg: Error generating preprocessed source(s) - no >>> preprocessable inputs. >>> *** [gcrt1.o] Error code 254 >>> >>> make[5]: stopped in /usr/src/lib/csu/powerpc64 >>> .ERROR_TARGET='gcrt1.o' >>> .ERROR_META_FILE='/usr/obj/powerpc64vtsc_clang_altbinutils/powerpc.powerpc64/usr/src/powerpc.powerpc64/lib/csu/powerpc64/gcrt1.o.meta' >>> .MAKE.LEVEL='5' >>> MAKEFILE='' >>> .MAKE.MODE='meta missing-filemon=yes missing-meta=yes silent=yes verbose' >>> _ERROR_CMD='cc -gdwarf-2 -target powerpc64-unknown-freebsd13.0 >>> --sysroot=/usr/obj/powerpc64vtsc_clang_altbinutils/powerpc.powerpc64/usr/src/powerpc.powerpc64/tmp >>> -B/usr/local/powerpc64-unknown-freebsd13.0/bin/ -O2 -pipe >>> -I/usr/src/lib/csu/common -I/usr/src/lib/libc/include -mlongcall >>> -DCRT_IRELOC_SUPPRESS -std=gnu99 -Wsystem-headers -Wall -Wno-format-y2k -W >>> -Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes >>> -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow >>> -Wunused-parameter -Wcast-align -Wchar-subscripts -Winline -Wnested-externs >>> -Wredundant-decls -Wold-style-definition -Wno-pointer-sign -Wthread-safety >>> -Wno-empty-body -Wno-string-plus-int -Wno-unused-const-variable >>> -Qunused-arguments -c -o gcrt1.o gcrt1.s;' >>> .CURDIR='/usr/src/lib/csu/powerpc64' >>> .MAKE='make' >>> .OBJDIR='/usr/obj/powerpc64vtsc_clang_altbinutils/powerpc.powerpc64/usr/src/powerpc.powerpc64/lib/csu/powerpc64' >>> .TARGETS='all' >>> DESTDIR='/usr/obj/powerpc64vtsc_clang_altbinutils/powerpc.powerpc64/usr/src/powerpc.powerpc64/tmp' >>> LD_LIBRARY_PATH='' >>> MACHINE='powerpc' >>> MACHINE_ARCH='powerpc64' >>> MAKEOBJDIRPREFIX='' >>> MAKESYSPATH='/usr/src/share/mk' >>> MAKE_VERSION='20181221' >>> PATH='/usr/obj/powerpc64vtsc_clang_altbinutils/powerpc.powerpc64/usr/src/powerpc.powerpc64/tmp/usr/sbin:/usr/obj/powerpc64vtsc_clang_altbinutils/powerpc.powerpc64/usr/src/powerpc.powerpc64/tmp/usr/bin:/usr/obj/powerpc64vtsc_clang_altbinutils/powerpc.powerpc64/usr/src/powerpc.powerpc64/tmp/legacy/usr/sbin:/usr/obj/powerpc64vtsc_clang_altbinutils/powerpc.powerpc64/usr/src/powerpc.powerpc64/tmp/legacy/usr/bin:/usr/obj/powerpc64vtsc_clang_altbinutils/powerpc.powerpc64/usr/src/powerpc.powerpc64/tmp/legacy/bin::/sbin:/bin:/usr/sbin:/usr/bin' >>> SRCTOP='/usr/src' >>> OBJTOP='/usr/obj/powerpc64vtsc_clang_altbinutils/powerpc.powerpc64/usr/src/powerpc.powerpc64' >>> .MAKE.MAKEFILES='/usr/src/share/mk/sys.mk >>> /usr/src/share/mk/local.sys.env.mk /usr/src/share/mk/src.sys.env.mk >>> /root/src.configs/src.conf.powerpc64-clang_altbinutils-bootstrap.amd64-host >>> /usr/src/share/mk/bsd.mkopt.mk /usr/src/share/mk/src.sys.obj.mk >>> /usr/src/share/mk/auto.obj.mk /usr/src/share/mk/bsd.suffixes.mk >>> /root/src.configs/make.conf /usr/src/share/mk/local.sys.mk >>> /usr/src/share/mk/src.sys.mk /dev/null /usr/src/lib/csu/powerpc64/Makefile >>> /usr/src/share/mk/bsd.lib.mk /usr/src/share/mk/bsd.init.mk >>> /usr/src/share/mk/bsd.opts.mk /usr/src/share/mk/bsd.cpu.mk >>> /usr/src/share/mk/local.init.mk /usr/src/share/mk/src.init.mk >>> /usr/src/lib/csu/powerpc64/../Makefile.inc /usr/src/share/mk/src.opts.mk >>> /usr/src/share/mk/bsd.own.mk /usr/src/share/mk/bsd.compiler.mk >>> /usr/src/share/mk/bsd.linker.mk >>> /usr/src/lib/csu/powerpc64/../../Makefile.inc >>> /usr/src/share/mk/bsd.libnames.mk /usr/src/share/mk/src.libnames.mk >>> /usr/src/share/mk/bsd.symver.mk /usr/src/share/mk/bsd.nls.mk >>> /usr/src/share/mk/bsd.c onfs.mk /usr/src/share/mk/bsd.files.mk /usr/src/share/mk/bsd.dirs.mk /usr/src/share/mk/bsd.incs.mk /usr/src/share/mk/bsd.links.mk /usr/src/share/mk/bsd.dep.mk /usr/src/share/mk/bsd.clang-analyze.mk /usr/src/share/mk/bsd.obj.mk /usr/src/share/mk/bsd.subdir.mk /usr/src/share/mk/bsd.sys.mk' >>> .PATH='. /usr/src/lib/csu/powerpc64 /usr/src/lib/csu/common' >>> 1 error >>> END QUOTES >>> >>> >>> For (D) (lldb): >>> >>> QUOTES >>> CPU not supported >>> UNREACHABLE executed at >>> /usr/src/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp:192! >>> Abort trap (core dumped) >>> >>> (gdb) bt >>> #0 0x0000000813715208 in .__sys_thr_kill () at thr_kill.S:3 >>> #1 0x00000008137147cc in __raise (s=<optimized out>) at >>> /usr/src/lib/libc/gen/raise.c:52 >>> #2 0x000000081366b5d8 in abort () at /usr/src/lib/libc/stdlib/abort.c:79 >>> #3 0x0000000011df6fb8 in llvm::llvm_unreachable_internal () at >>> /usr/src/contrib/llvm/lib/Support/ErrorHandling.cpp:222 >>> #4 0x00000000103aaaf8 in FreeBSDThread::GetRegisterContext () at >>> /usr/src/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp:192 >>> #5 0x00000000105807d4 in lldb_private::Thread::SetupForResume () at >>> /usr/src/contrib/llvm/tools/lldb/source/Target/Thread.cpp:613 >>> #6 0x0000000010571bc8 in lldb_private::ThreadList::WillResume () at >>> /usr/src/contrib/llvm/tools/lldb/source/Target/ThreadList.cpp:541 >>> #7 0x00000000105da23c in lldb_private::Process::PrivateResume () at >>> /usr/src/contrib/llvm/tools/lldb/source/Target/Process.cpp:3281 >>> #8 0x00000000105a00c8 in lldb_private::Target::Launch () at >>> /usr/src/contrib/llvm/tools/lldb/source/Target/Target.cpp:2922 >>> #9 0x000000001073f550 in CommandObjectProcessLaunch::DoExecute () at >>> /usr/src/contrib/llvm/tools/lldb/source/Commands/CommandObjectProcess.cpp:221 >>> #10 0x00000000106c36c4 in lldb_private::CommandObjectParsed::Execute () at >>> /usr/src/contrib/llvm/tools/lldb/source/Interpreter/CommandObject.cpp:975 >>> #11 0x00000000106d8b44 in lldb_private::CommandInterpreter::HandleCommand >>> () at >>> /usr/src/contrib/llvm/tools/lldb/source/Interpreter/CommandInterpreter.cpp:1761 >>> #12 0x00000000106da0a0 in >>> lldb_private::CommandInterpreter::IOHandlerInputComplete () at >>> /usr/src/contrib/llvm/tools/lldb/source/Interpreter/CommandInterpreter.cpp:2801 >>> #13 0x00000000107c0a08 in lldb_private::IOHandlerEditline::Run () at >>> /usr/src/contrib/llvm/tools/lldb/source/Core/IOHandler.cpp:558 >>> #14 0x0000000010346e5c in lldb_private::Debugger::ExecuteIOHandlers () at >>> /usr/src/contrib/llvm/tools/lldb/source/Core/Debugger.cpp:988 >>> #15 0x00000000106c8ddc in >>> lldb_private::CommandInterpreter::RunCommandInterpreter () at >>> /usr/src/contrib/llvm/tools/lldb/source/Interpreter/CommandInterpreter.cpp:3003 >>> #16 0x000000001034feb4 in lldb::SBDebugger::RunCommandInterpreter () at >>> /usr/src/contrib/llvm/tools/lldb/source/API/SBDebugger.cpp:935 >>> #17 0x00000000101de878 in Driver::MainLoop () at >>> /usr/src/contrib/llvm/tools/lldb/tools/driver/Driver.cpp:756 >>> #18 0x00000000101a0088 in main () at >>> /usr/src/contrib/llvm/tools/lldb/tools/driver/Driver.cpp:936 >>> >>> lldb::RegisterContextSP FreeBSDThread::GetRegisterContext() { >>> if (!m_reg_context_sp) { >>> m_posix_thread = nullptr; >>> >>> RegisterInfoInterface *reg_interface = nullptr; >>> const ArchSpec &target_arch = GetProcess()->GetTarget().GetArchitecture(); >>> >>> switch (target_arch.GetMachine()) { >>> case llvm::Triple::aarch64: >>> reg_interface = new RegisterInfoPOSIX_arm64(target_arch); >>> break; >>> case llvm::Triple::arm: >>> reg_interface = new RegisterInfoPOSIX_arm(target_arch); >>> break; >>> case llvm::Triple::ppc: >>> #ifndef __powerpc64__ >>> reg_interface = new RegisterContextFreeBSD_powerpc32(target_arch); >>> break; >>> #endif >>> case llvm::Triple::ppc64: >>> reg_interface = new RegisterContextFreeBSD_powerpc64(target_arch); >>> break; >>> case llvm::Triple::mips64: >>> reg_interface = new RegisterContextFreeBSD_mips64(target_arch); >>> break; >>> case llvm::Triple::x86: >>> reg_interface = new RegisterContextFreeBSD_i386(target_arch); >>> break; >>> case llvm::Triple::x86_64: >>> reg_interface = new RegisterContextFreeBSD_x86_64(target_arch); >>> break; >>> default: >>> llvm_unreachable("CPU not supported"); >>> } >>> END QUOTES. >> >> >> >> I ran into libunwind having LIBUNWIND_PRINT_UNWINDING and >> LIBUNWIND_PRINT_APIS so I can report for the segmentation >> fault: >> >> # export LIBUNWIND_PRINT_UNWINDING="" >> # export LIBUNWIND_PRINT_APIS="" >> # ./a.out >> . . . > > Using unoptimized code instead: > > # c++ -g exception_test.cpp > libunwind: __register_frame_info(0x137d6610, 0x13ae3150) > libunwind: __register_frame_info(0x137d6610, 0x13ae3150) > libunwind: __deregister_frame_info(0x137d6610) > libunwind: __deregister_frame_info(0x137d6610) > # ./a.out > libunwind: _Unwind_RaiseException(ex_obj=0x810043060) > libunwind: unw_init_local(cursor=0x3fffffffffffcb48, > context=0x3fffffffffffd0e0) > libunwind: unw_step(cursor=0x3fffffffffffcb48) > libunwind: unw_get_proc_info(cursor=0x3fffffffffffcb48, > &info=0x3fffffffffffd830) > libunwind: unw_get_proc_name(cursor=0x3fffffffffffcb48, > &buf=0x3fffffffffffd628, bufLen=512) > libunwind: unw_get_reg(cursor=0x3fffffffffffcb48, regNum=-1, > &value=0x3fffffffffffd618) > libunwind: unwind_phase1(ex_ojb=0x810043060): pc=0x81019d954, > start_ip=0x81019d860, func=.anonymous., lsda=0x0, personality=0x0 > libunwind: unw_step(cursor=0x3fffffffffffcb48) > libunwind: unw_get_proc_info(cursor=0x3fffffffffffcb48, > &info=0x3fffffffffffd830) > libunwind: unw_get_proc_name(cursor=0x3fffffffffffcb48, > &buf=0x3fffffffffffd628, bufLen=512) > libunwind: unw_get_reg(cursor=0x3fffffffffffcb48, regNum=-1, > &value=0x3fffffffffffd618) > libunwind: unwind_phase1(ex_ojb=0x810043060): pc=0x10000dac, > start_ip=0x10000d64, func=.anonymous., lsda=0x10000fe0, > personality=0x8101b5360 > libunwind: unwind_phase1(ex_ojb=0x810043060): calling personality function > 0x8101b5360 > libunwind: unw_get_proc_info(cursor=0x3fffffffffffcb48, > &info=0x3fffffffffffc950) > libunwind: _Unwind_GetLanguageSpecificData(context=0x3fffffffffffcb48) => > 0x10000fe0 > libunwind: unw_get_proc_info(cursor=0x3fffffffffffcb48, > &info=0x3fffffffffffc890) > libunwind: _Unwind_GetRegionStart(context=0x3fffffffffffcb48) => 0x10000d64 > libunwind: unw_get_reg(cursor=0x3fffffffffffcb48, regNum=-1, > &value=0x3fffffffffffc8c8) > libunwind: _Unwind_GetIP(context=0x3fffffffffffcb48) => 0x10000dac > libunwind: unw_get_proc_info(cursor=0x3fffffffffffcb48, > &info=0x3fffffffffffc880) > libunwind: _Unwind_GetRegionStart(context=0x3fffffffffffcb48) => 0x10000d64 > libunwind: unw_get_reg(cursor=0x3fffffffffffcb48, regNum=-2, > &value=0x3fffffffffffd828) > libunwind: unwind_phase1(ex_ojb=0x810043060): _URC_HANDLER_FOUND > libunwind: unw_init_local(cursor=0x3fffffffffffcb48, > context=0x3fffffffffffd0e0) > libunwind: unwind_phase2(ex_ojb=0x810043060) > libunwind: unw_step(cursor=0x3fffffffffffcb48) > libunwind: unw_get_reg(cursor=0x3fffffffffffcb48, regNum=-2, > &value=0x3fffffffffffca58) > libunwind: unw_get_proc_info(cursor=0x3fffffffffffcb48, > &info=0x3fffffffffffca10) > libunwind: unw_get_proc_name(cursor=0x3fffffffffffcb48, > &buf=0x3fffffffffffc810, bufLen=512) > libunwind: unwind_phase2(ex_ojb=0x810043060): start_ip=0x81019d860, > func=.anonymous., sp=0x3fffffffffffd8e0, lsda=0x0, personality=0x0 > libunwind: unw_step(cursor=0x3fffffffffffcb48) > libunwind: unw_get_reg(cursor=0x3fffffffffffcb48, regNum=-2, > &value=0x3fffffffffffca58) > libunwind: unw_get_proc_info(cursor=0x3fffffffffffcb48, > &info=0x3fffffffffffca10) > libunwind: unw_get_proc_name(cursor=0x3fffffffffffcb48, > &buf=0x3fffffffffffc810, bufLen=512) > libunwind: unwind_phase2(ex_ojb=0x810043060): start_ip=0x10000d64, > func=.anonymous., sp=0x3fffffffffffd980, lsda=0x10000fe0, > personality=0x8101b5360 > libunwind: unw_get_proc_info(cursor=0x3fffffffffffcb48, > &info=0x3fffffffffffc610) > libunwind: _Unwind_GetLanguageSpecificData(context=0x3fffffffffffcb48) => > 0x10000fe0 > libunwind: _Unwind_SetIP(context=0x3fffffffffffcb48, value=0x10000db4) > libunwind: unw_set_reg(cursor=0x3fffffffffffcb48, regNum=-1, value=0x10000db4) > libunwind: _Unwind_SetGR(context=0x3fffffffffffcb48, reg=3, value=0x810043060) > libunwind: unw_set_reg(cursor=0x3fffffffffffcb48, regNum=3, value=0x810043060) > libunwind: _Unwind_SetGR(context=0x3fffffffffffcb48, reg=4, value=0x1) > libunwind: unw_set_reg(cursor=0x3fffffffffffcb48, regNum=4, value=0x1) > libunwind: unwind_phase2(ex_ojb=0x810043060): _URC_INSTALL_CONTEXT > libunwind: unw_get_reg(cursor=0x3fffffffffffcb48, regNum=-1, > &value=0x3fffffffffffc810) > libunwind: unw_get_reg(cursor=0x3fffffffffffcb48, regNum=-2, > &value=0x3fffffffffffca58) > libunwind: unwind_phase2(ex_ojb=0x810043060): re-entering user code with > ip=0x10000db4, sp=0x3fffffffffffd980 > libunwind: unw_resume(cursor=0x3fffffffffffcb48) > Segmentation fault (core dumped) > > The below shows that the 0x10000db4 in this case seems right --and > also that the code sequence does not set r2. Apparently the > throw handling was supposed to set it so the optimized code > skips setting it. (Later below it seems r2 should have been > set by something but was not correctly set.) > > (gdb) disass main > Dump of assembler code for function main(): > 0x0000000010000d64 <+0>: mflr r0 > 0x0000000010000d68 <+4>: std r31,-8(r1) > 0x0000000010000d6c <+8>: std r0,16(r1) > 0x0000000010000d70 <+12>: stdu r1,-160(r1) > 0x0000000010000d74 <+16>: mr r31,r1 > 0x0000000010000d78 <+20>: li r3,0 > 0x0000000010000d7c <+24>: stw r3,148(r31) > 0x0000000010000d80 <+28>: li r3,8 > 0x0000000010000d84 <+32>: bl 0x100007a0 > <00000018.plt_call.__cxa_allocate_exception@@CXXABI_1.3> > 0x0000000010000d88 <+36>: ld r2,40(r1) > 0x0000000010000d8c <+40>: std r3,112(r31) > 0x0000000010000d90 <+44>: bl 0x10000e00 <std::exception::exception()> > 0x0000000010000d94 <+48>: nop > 0x0000000010000d98 <+52>: ld r4,-32728(r2) > 0x0000000010000d9c <+56>: nop > 0x0000000010000da0 <+60>: ld r5,-32720(r2) > 0x0000000010000da4 <+64>: ld r3,112(r31) > 0x0000000010000da8 <+68>: bl 0x10000800 > <00000018.plt_call.__cxa_throw@@CXXABI_1.3> > 0x0000000010000dac <+72>: ld r2,40(r1) > 0x0000000010000db0 <+76>: b 0x10000df4 <main()+144> > 0x0000000010000db4 <+80>: mr r5,r4 > 0x0000000010000db8 <+84>: std r3,136(r31) > 0x0000000010000dbc <+88>: stw r5,132(r31) > 0x0000000010000dc0 <+92>: b 0x10000dc4 <main()+96> > 0x0000000010000dc4 <+96>: ld r3,136(r31) > 0x0000000010000dc8 <+100>: bl 0x100007c0 > <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3> > 0x0000000010000dcc <+104>: ld r2,40(r1) > 0x0000000010000dd0 <+108>: std r3,120(r31) > 0x0000000010000dd4 <+112>: bl 0x100007e0 > <00000018.plt_call.__cxa_end_catch@@CXXABI_1.3> > 0x0000000010000dd8 <+116>: ld r2,40(r1) > 0x0000000010000ddc <+120>: li r3,0 > 0x0000000010000de0 <+124>: addi r1,r1,160 > 0x0000000010000de4 <+128>: ld r0,16(r1) > 0x0000000010000de8 <+132>: ld r31,-8(r1) > 0x0000000010000dec <+136>: mtlr r0 > 0x0000000010000df0 <+140>: blr > 0x0000000010000df4 <+144>: .long 0x0 > 0x0000000010000df8 <+148>: .long 0x0 > 0x0000000010000dfc <+152>: .long 0x0 > End of assembler dump. > > Notably lr seems to be: 0x10000dcc which > is just after: > > bl 0x100007c0 <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3> > > Note also the pc, r12, and ctr all having the failure > address: 0x81042b900 . > > #0 0x000000081042b900 in ?? () from /lib/libc.so.7 > (gdb) x/32i 0x000000081042b8F0 > 0x81042b8f0 <getfss...@got.plt>: .long 0x8 > 0x81042b8f4 <getfss...@got.plt+4>: vmrglh v1,v30,v7 > 0x81042b8f8: .long 0x8 > 0x81042b8fc: vsubeuqm v1,v30,v7,v17 > => 0x81042b900: .long 0x8 > 0x81042b904: vpmsumw v1,v30,v7 > 0x81042b908 <_citrus_bcs_skip_ws_...@got.plt>: .long 0x8 > 0x81042b90c <_citrus_bcs_skip_ws_...@got.plt+4>: .long 0x103e3c92 > 0x81042b910: .long 0x8 > 0x81042b914: .long 0x103e3c9b > 0x81042b918: .long 0x8 > > (gdb) info reg > r0 0x810563d10 34633825552 > r1 0x3fffffffffffd980 4611686018427378048 > r2 0x0 0 > r3 0x810043060 34628448352 > r4 0x1 1 > r5 0x1 1 > r6 0x8103d9490 34632209552 > r7 0x0 0 > r8 0x29 41 > r9 0x4e 78 > r10 0x3fffffffffffc8f8 4611686018427373816 > r11 0x81056c28c 34633859724 > r12 0x81042b900 34632546560 > r13 0x81005f020 34628562976 > r14 0x0 0 > r15 0x0 0 > r16 0x0 0 > r17 0x0 0 > r18 0x0 0 > r19 0x0 0 > r20 0x0 0 > r21 0x0 0 > r22 0x0 0 > r23 0x0 0 > r24 0x0 0 > r25 0x0 0 > r26 0x0 0 > r27 0x0 0 > r28 0x1 1 > r29 0x3fffffffffffdb78 4611686018427378552 > r30 0x3fffffffffffdb88 4611686018427378568 > r31 0x3fffffffffffd980 4611686018427378048 > pc 0x81042b900 0x81042b900 > msr <unavailable> > cr 0x28000802 671090690 > lr 0x10000dcc 0x10000dcc <main()+104> > ctr 0x81042b900 34632546560 > xer 0x0 0 > fpscr 0x0 0 > vscr <unavailable> > vrsave <unavailable> > > And the following shows how r12 and ctr were filled in by > code that expected r2 to be correct: > > (gdb) x/32i 0x100007c0 > 0x100007c0 <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3>: std > r2,40(r1) > 0x100007c4 <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3+4>: ld > r12,-32608(r2) > 0x100007c8 <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3+8>: mtctr > r12 > 0x100007cc <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3+12>: ld > r11,-32592(r2) > 0x100007d0 <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3+16>: ld > r2,-32600(r2) > 0x100007d4 <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3+20>: bctr > 0x100007d8 <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3+24>: .long > 0x0 > 0x100007dc <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3+28>: .long > 0x0 > . . . > > Overall: r2 seem to be mishandled in the exception handling. Just before: 0x0000000010000dc8 <+100>: bl 0x100007c0 <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3> (gdb) set $r2=0x10019300 (gdb) c Continuing. Program exited normally. r2 has the wrong value and needs to have been set by: ld r2,40(r1) (expressed as an additional instruction in teh prelude to bl 0x100007c0 <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3>) That shows how I got the 0x10019300 value as well: 40(r1) lookup. This makes the optimized code interesting because it had the "ld r2,40(r1)" but it was skipped by that code being started at 0x0000000010000dac . 0x0000000010000da8 <+68>: ld r2,40(r1) 0x0000000010000dac <+72>: bl 0x100007c0 <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3> (An earlier message of this sequence has more detail for the optimized code.) > Note on the gdb use: > > The above devel/gdb activity was executed from a > devel/powerpc64-xtoolchain-gcc built world that was based on > WITHOUT_LLVM_LIBUNWIND= and and my patched libgcc_s material. > This means it suffered from mismatches with the clang/libunwind > world (that I chroot to): > > QUOTE > warning: .dynamic section for "/usr/lib/libc++.so.1" is not at the expected > address (wrong library or version mismatch?) > > warning: .dynamic section for "/lib/libcxxrt.so.1" is not at the expected > address (wrong library or version mismatch?) > > warning: .dynamic section for "/lib/libm.so.5" is not at the expected address > (wrong library or version mismatch?) > > warning: .dynamic section for "/lib/libc.so.7" is not at the expected address > (wrong library or version mismatch?) > > warning: .dynamic section for "/lib/libgcc_s.so.1" is not at the expected > address (wrong library or version mismatch?) > > warning: .dynamic section for "/libexec/ld-elf.so.1" is not at the expected > address (wrong library or version mismatch?) > END QUOTE > > But any thrown exceptions the gdb may have used worked in my > patched WITHOUT_LLVM_LIBUNWIND= environment. This gdb is not > limited to dwarf-2. > > The material from the a.out is not misinterpreted even if > library code details might be. === Mark Millard marklmi at yahoo.com ( dsl-only.net went away in early 2018-Mar) _______________________________________________ freebsd-toolchain@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/freebsd-toolchain To unsubscribe, send any mail to "freebsd-toolchain-unsubscr...@freebsd.org"