[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 <[email protected]> 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.con fs.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 libunwind: _Unwind_RaiseException(ex_obj=0x810043060) libunwind: unw_init_local(cursor=0x3fffffffffffcb68, context=0x3fffffffffffd100) libunwind: unw_step(cursor=0x3fffffffffffcb68) libunwind: unw_get_proc_info(cursor=0x3fffffffffffcb68, &info=0x3fffffffffffd850) libunwind: unw_get_proc_name(cursor=0x3fffffffffffcb68, &buf=0x3fffffffffffd648, bufLen=512) libunwind: unw_get_reg(cursor=0x3fffffffffffcb68, regNum=-1, &value=0x3fffffffffffd638) libunwind: unwind_phase1(ex_ojb=0x810043060): pc=0x81019d954, start_ip=0x81019d860, func=.anonymous., lsda=0x0, personality=0x0 libunwind: unw_step(cursor=0x3fffffffffffcb68) libunwind: unw_get_proc_info(cursor=0x3fffffffffffcb68, &info=0x3fffffffffffd850) libunwind: unw_get_proc_name(cursor=0x3fffffffffffcb68, &buf=0x3fffffffffffd648, bufLen=512) libunwind: unw_get_reg(cursor=0x3fffffffffffcb68, regNum=-1, &value=0x3fffffffffffd638) libunwind: unwind_phase1(ex_ojb=0x810043060): pc=0x10000da8, start_ip=0x10000d64, func=.anonymous., lsda=0x10000f84, personality=0x8101b5360 libunwind: unwind_phase1(ex_ojb=0x810043060): calling personality function 0x8101b5360 libunwind: unw_get_proc_info(cursor=0x3fffffffffffcb68, &info=0x3fffffffffffc970) libunwind: _Unwind_GetLanguageSpecificData(context=0x3fffffffffffcb68) => 0x10000f84 libunwind: unw_get_proc_info(cursor=0x3fffffffffffcb68, &info=0x3fffffffffffc8b0) libunwind: _Unwind_GetRegionStart(context=0x3fffffffffffcb68) => 0x10000d64 libunwind: unw_get_reg(cursor=0x3fffffffffffcb68, regNum=-1, &value=0x3fffffffffffc8e8) libunwind: _Unwind_GetIP(context=0x3fffffffffffcb68) => 0x10000da8 libunwind: unw_get_proc_info(cursor=0x3fffffffffffcb68, &info=0x3fffffffffffc8a0) libunwind: _Unwind_GetRegionStart(context=0x3fffffffffffcb68) => 0x10000d64 libunwind: unw_get_reg(cursor=0x3fffffffffffcb68, regNum=-2, &value=0x3fffffffffffd848) libunwind: unwind_phase1(ex_ojb=0x810043060): _URC_HANDLER_FOUND libunwind: unw_init_local(cursor=0x3fffffffffffcb68, context=0x3fffffffffffd100) libunwind: unwind_phase2(ex_ojb=0x810043060) libunwind: unw_step(cursor=0x3fffffffffffcb68) libunwind: unw_get_reg(cursor=0x3fffffffffffcb68, regNum=-2, &value=0x3fffffffffffca78) libunwind: unw_get_proc_info(cursor=0x3fffffffffffcb68, &info=0x3fffffffffffca30) libunwind: unw_get_proc_name(cursor=0x3fffffffffffcb68, &buf=0x3fffffffffffc830, bufLen=512) libunwind: unwind_phase2(ex_ojb=0x810043060): start_ip=0x81019d860, func=.anonymous., sp=0x3fffffffffffd900, lsda=0x0, personality=0x0 libunwind: unw_step(cursor=0x3fffffffffffcb68) libunwind: unw_get_reg(cursor=0x3fffffffffffcb68, regNum=-2, &value=0x3fffffffffffca78) libunwind: unw_get_proc_info(cursor=0x3fffffffffffcb68, &info=0x3fffffffffffca30) libunwind: unw_get_proc_name(cursor=0x3fffffffffffcb68, &buf=0x3fffffffffffc830, bufLen=512) libunwind: unwind_phase2(ex_ojb=0x810043060): start_ip=0x10000d64, func=.anonymous., sp=0x3fffffffffffd9a0, lsda=0x10000f84, personality=0x8101b5360 libunwind: unw_get_proc_info(cursor=0x3fffffffffffcb68, &info=0x3fffffffffffc630) libunwind: _Unwind_GetLanguageSpecificData(context=0x3fffffffffffcb68) => 0x10000f84 libunwind: _Unwind_SetIP(context=0x3fffffffffffcb68, value=0x10000dac) libunwind: unw_set_reg(cursor=0x3fffffffffffcb68, regNum=-1, value=0x10000dac) libunwind: _Unwind_SetGR(context=0x3fffffffffffcb68, reg=3, value=0x810043060) libunwind: unw_set_reg(cursor=0x3fffffffffffcb68, regNum=3, value=0x810043060) libunwind: _Unwind_SetGR(context=0x3fffffffffffcb68, reg=4, value=0x1) libunwind: unw_set_reg(cursor=0x3fffffffffffcb68, regNum=4, value=0x1) libunwind: unwind_phase2(ex_ojb=0x810043060): _URC_INSTALL_CONTEXT libunwind: unw_get_reg(cursor=0x3fffffffffffcb68, regNum=-1, &value=0x3fffffffffffc830) libunwind: unw_get_reg(cursor=0x3fffffffffffcb68, regNum=-2, &value=0x3fffffffffffca78) libunwind: unwind_phase2(ex_ojb=0x810043060): re-entering user code with ip=0x10000dac, sp=0x3fffffffffffd9a0 libunwind: unw_resume(cursor=0x3fffffffffffcb68) Segmentation fault (core dumped) Note that the 0x10000dac address below is after the "ld r2,40(r1)" that sets up r2's value for use in the 00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3 routine. The ip value reported by unwind_phase2 appears to too large by 0x4 . (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,-128(r1) 0x0000000010000d74 <+16>: mr r31,r1 0x0000000010000d78 <+20>: li r3,8 0x0000000010000d7c <+24>: bl 0x100007a0 <00000018.plt_call.__cxa_allocate_exception@@CXXABI_1.3> 0x0000000010000d80 <+28>: ld r2,40(r1) 0x0000000010000d84 <+32>: nop 0x0000000010000d88 <+36>: ld r4,-32728(r2) 0x0000000010000d8c <+40>: addi r4,r4,16 0x0000000010000d90 <+44>: std r4,0(r3) 0x0000000010000d94 <+48>: nop 0x0000000010000d98 <+52>: nop 0x0000000010000d9c <+56>: ld r4,-32720(r2) 0x0000000010000da0 <+60>: ld r5,-32712(r2) 0x0000000010000da4 <+64>: bl 0x10000800 <00000018.plt_call.__cxa_throw@@CXXABI_1.3> 0x0000000010000da8 <+68>: ld r2,40(r1) 0x0000000010000dac <+72>: bl 0x100007c0 <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3> 0x0000000010000db0 <+76>: ld r2,40(r1) 0x0000000010000db4 <+80>: bl 0x100007e0 <00000018.plt_call.__cxa_end_catch@@CXXABI_1.3> 0x0000000010000db8 <+84>: ld r2,40(r1) 0x0000000010000dbc <+88>: li r3,0 0x0000000010000dc0 <+92>: addi r1,r1,128 0x0000000010000dc4 <+96>: ld r0,16(r1) 0x0000000010000dc8 <+100>: ld r31,-8(r1) 0x0000000010000dcc <+104>: mtlr r0 0x0000000010000dd0 <+108>: blr 0x0000000010000dd4 <+112>: .long 0x0 0x0000000010000dd8 <+116>: .long 0x0 0x0000000010000ddc <+120>: .long 0x0 End of assembler dump. === Mark Millard marklmi at yahoo.com ( dsl-only.net went away in early 2018-Mar) _______________________________________________ [email protected] mailing list https://lists.freebsd.org/mailman/listinfo/freebsd-toolchain To unsubscribe, send any mail to "[email protected]"
