Rust unwind information #18

Closed
opened 2020-06-24 17:02:33 +08:00 by pca006132 · 4 comments

Implementation for exception requires stack unwinding, which needs unwind information for the raise function implemented in rust.

Currently, even with "panic-strategy": "unwind", the unwind information is still not generated, and when the unwinder tries to unwind from the raise function in Rust, it would return an error as it hits the EXIDX_CANTUNWIND.

Related log with comments:

[     4.497136s] DEBUG(runtime::eh_artiq): Trying to raise exception
_Unwind_RaiseException(ex_obj=00131AA8)
__unw_init_local(cursor=1013B2B0, context=1013B848)
[     4.505484s] DEBUG(dyld): PC: 12559C, TEXT_START: 0x0, TEXT_END: 0x12ab90

// Comment: Unwinding from libunwind:_Unwind_Raise_Exception
// corresponding personality function is the cpp one

findUnwindSections: section 0012AB90 length 00ACD940
PC: 0X12559C
Begin: 0X100000
begin != end
This PC: 0X125570
Index data addr: 0X12ABDC
Index data : 0X809B46AF
__unw_get_proc_info(cursor=1013B2B0, &info=1013BD80)
unwind_phase1(ex_ojb=00131AA8): calling personality function 001254FC
__unw_get_proc_info(cursor=1013B2B0, &info=1013B260)
_Unwind_GetLanguageSpecificData(context=1013B2B0) => 0x0
__unw_step(cursor=1013B2B0)
__unw_get_reg(cursor=1013B2B0, regNum=11, &value=1013B240)
_Unwind_VRS_Get(context=1013B2B0, regclass=0, reg=11, rep=0, value=0x1013BDC8, result = 0)
_Unwind_VRS_Set(context=1013B2B0, regclass=0, reg=13, rep=0, value=0x1013BDC8)
__unw_set_reg(cursor=1013B2B0, regNum=13, value=0x1013bdc8)
__unw_get_reg(cursor=1013B2B0, regNum=13, &value=1013B240)
_Unwind_VRS_Get(context=1013B2B0, regclass=0, reg=13, rep=0, value=0x1013BDC8, result = 0)
_Unwind_VRS_Set(context=1013B2B0, regclass=0, reg=13, rep=0, value=0x1013BDAC)
__unw_set_reg(cursor=1013B2B0, regNum=13, value=0x1013bdac)
_Unwind_VRS_Pop(context=1013B2B0, regclass=0, discriminator=20464, representation=0)
__unw_get_reg(cursor=1013B2B0, regNum=13, &value=1013B200)
_Unwind_VRS_Get(context=1013B2B0, regclass=0, reg=13, rep=0, value=0x1013BDAC, result = 0)
_Unwind_VRS_Set(context=1013B2B0, regclass=0, reg=4, rep=0, value=0x131AA8)
__unw_set_reg(cursor=1013B2B0, regNum=4, value=0x131aa8)
_Unwind_VRS_Set(context=1013B2B0, regclass=0, reg=5, rep=0, value=0x1013BDD0)
__unw_set_reg(cursor=1013B2B0, regNum=5, value=0x1013bdd0)
_Unwind_VRS_Set(context=1013B2B0, regclass=0, reg=6, rep=0, value=0x1)
__unw_set_reg(cursor=1013B2B0, regNum=6, value=0x1)
_Unwind_VRS_Set(context=1013B2B0, regclass=0, reg=7, rep=0, value=0x0)
__unw_set_reg(cursor=1013B2B0, regNum=7, value=0x0)
_Unwind_VRS_Set(context=1013B2B0, regclass=0, reg=8, rep=0, value=0x10)
__unw_set_reg(cursor=1013B2B0, regNum=8, value=0x10)
_Unwind_VRS_Set(context=1013B2B0, regclass=0, reg=9, rep=0, value=0x0)
__unw_set_reg(cursor=1013B2B0, regNum=9, value=0x0)
_Unwind_VRS_Set(context=1013B2B0, regclass=0, reg=10, rep=0, value=0x1013BE50)
__unw_set_reg(cursor=1013B2B0, regNum=10, value=0x1013be50)
_Unwind_VRS_Set(context=1013B2B0, regclass=0, reg=11, rep=0, value=0x1013BE80)
__unw_set_reg(cursor=1013B2B0, regNum=11, value=0x1013be80)
_Unwind_VRS_Set(context=1013B2B0, regclass=0, reg=14, rep=0, value=0x117B18)
__unw_set_reg(cursor=1013B2B0, regNum=14, value=0x117b18)
_Unwind_VRS_Set(context=1013B2B0, regclass=0, reg=13, rep=0, value=0x1013BDD0)
__unw_set_reg(cursor=1013B2B0, regNum=13, value=0x1013bdd0)
__unw_get_reg(cursor=1013B2B0, regNum=14, &value=1013B240)
_Unwind_VRS_Get(context=1013B2B0, regclass=0, reg=14, rep=0, value=0x117B18, result = 0)
_Unwind_VRS_Set(context=1013B2B0, regclass=0, reg=15, rep=0, value=0x117B18)
__unw_set_reg(cursor=1013B2B0, regNum=15, value=0x117b18)
[     4.758413s] DEBUG(dyld): PC: 117B17, TEXT_START: 0x0, TEXT_END: 0x12ab90

// Comment: Unwinding from raise, written in Rust
// no unwinding information, the index data is 0x1 which corresponds to `EXIDX_CANTUNWIND`

findUnwindSections: section 0012AB90 length 00ACD940
PC: 0X117B17
Begin: 0X100000
begin != end
This PC: 0X100000
Index data addr: 0X12AB94
Index data : 0X1
unwind_phase1(ex_ojb=00131AA8): personality result 9 start_ip 125570 ehtp 0012ABDC additional 1
personality result: failure
panic at runtime/src/eh_artiq.rs:186:5: assertion failed: result == uw::_URC_END_OF_STACK
Implementation for exception requires stack unwinding, which needs unwind information for the raise function implemented in rust. Currently, even with `"panic-strategy": "unwind"`, the unwind information is still not generated, and when the unwinder tries to unwind from the raise function in Rust, it would return an error as it hits the `EXIDX_CANTUNWIND`. Related log with comments: ``` [ 4.497136s] DEBUG(runtime::eh_artiq): Trying to raise exception _Unwind_RaiseException(ex_obj=00131AA8) __unw_init_local(cursor=1013B2B0, context=1013B848) [ 4.505484s] DEBUG(dyld): PC: 12559C, TEXT_START: 0x0, TEXT_END: 0x12ab90 // Comment: Unwinding from libunwind:_Unwind_Raise_Exception // corresponding personality function is the cpp one findUnwindSections: section 0012AB90 length 00ACD940 PC: 0X12559C Begin: 0X100000 begin != end This PC: 0X125570 Index data addr: 0X12ABDC Index data : 0X809B46AF __unw_get_proc_info(cursor=1013B2B0, &info=1013BD80) unwind_phase1(ex_ojb=00131AA8): calling personality function 001254FC __unw_get_proc_info(cursor=1013B2B0, &info=1013B260) _Unwind_GetLanguageSpecificData(context=1013B2B0) => 0x0 __unw_step(cursor=1013B2B0) __unw_get_reg(cursor=1013B2B0, regNum=11, &value=1013B240) _Unwind_VRS_Get(context=1013B2B0, regclass=0, reg=11, rep=0, value=0x1013BDC8, result = 0) _Unwind_VRS_Set(context=1013B2B0, regclass=0, reg=13, rep=0, value=0x1013BDC8) __unw_set_reg(cursor=1013B2B0, regNum=13, value=0x1013bdc8) __unw_get_reg(cursor=1013B2B0, regNum=13, &value=1013B240) _Unwind_VRS_Get(context=1013B2B0, regclass=0, reg=13, rep=0, value=0x1013BDC8, result = 0) _Unwind_VRS_Set(context=1013B2B0, regclass=0, reg=13, rep=0, value=0x1013BDAC) __unw_set_reg(cursor=1013B2B0, regNum=13, value=0x1013bdac) _Unwind_VRS_Pop(context=1013B2B0, regclass=0, discriminator=20464, representation=0) __unw_get_reg(cursor=1013B2B0, regNum=13, &value=1013B200) _Unwind_VRS_Get(context=1013B2B0, regclass=0, reg=13, rep=0, value=0x1013BDAC, result = 0) _Unwind_VRS_Set(context=1013B2B0, regclass=0, reg=4, rep=0, value=0x131AA8) __unw_set_reg(cursor=1013B2B0, regNum=4, value=0x131aa8) _Unwind_VRS_Set(context=1013B2B0, regclass=0, reg=5, rep=0, value=0x1013BDD0) __unw_set_reg(cursor=1013B2B0, regNum=5, value=0x1013bdd0) _Unwind_VRS_Set(context=1013B2B0, regclass=0, reg=6, rep=0, value=0x1) __unw_set_reg(cursor=1013B2B0, regNum=6, value=0x1) _Unwind_VRS_Set(context=1013B2B0, regclass=0, reg=7, rep=0, value=0x0) __unw_set_reg(cursor=1013B2B0, regNum=7, value=0x0) _Unwind_VRS_Set(context=1013B2B0, regclass=0, reg=8, rep=0, value=0x10) __unw_set_reg(cursor=1013B2B0, regNum=8, value=0x10) _Unwind_VRS_Set(context=1013B2B0, regclass=0, reg=9, rep=0, value=0x0) __unw_set_reg(cursor=1013B2B0, regNum=9, value=0x0) _Unwind_VRS_Set(context=1013B2B0, regclass=0, reg=10, rep=0, value=0x1013BE50) __unw_set_reg(cursor=1013B2B0, regNum=10, value=0x1013be50) _Unwind_VRS_Set(context=1013B2B0, regclass=0, reg=11, rep=0, value=0x1013BE80) __unw_set_reg(cursor=1013B2B0, regNum=11, value=0x1013be80) _Unwind_VRS_Set(context=1013B2B0, regclass=0, reg=14, rep=0, value=0x117B18) __unw_set_reg(cursor=1013B2B0, regNum=14, value=0x117b18) _Unwind_VRS_Set(context=1013B2B0, regclass=0, reg=13, rep=0, value=0x1013BDD0) __unw_set_reg(cursor=1013B2B0, regNum=13, value=0x1013bdd0) __unw_get_reg(cursor=1013B2B0, regNum=14, &value=1013B240) _Unwind_VRS_Get(context=1013B2B0, regclass=0, reg=14, rep=0, value=0x117B18, result = 0) _Unwind_VRS_Set(context=1013B2B0, regclass=0, reg=15, rep=0, value=0x117B18) __unw_set_reg(cursor=1013B2B0, regNum=15, value=0x117b18) [ 4.758413s] DEBUG(dyld): PC: 117B17, TEXT_START: 0x0, TEXT_END: 0x12ab90 // Comment: Unwinding from raise, written in Rust // no unwinding information, the index data is 0x1 which corresponds to `EXIDX_CANTUNWIND` findUnwindSections: section 0012AB90 length 00ACD940 PC: 0X117B17 Begin: 0X100000 begin != end This PC: 0X100000 Index data addr: 0X12AB94 Index data : 0X1 unwind_phase1(ex_ojb=00131AA8): personality result 9 start_ip 125570 ehtp 0012ABDC additional 1 personality result: failure panic at runtime/src/eh_artiq.rs:186:5: assertion failed: result == uw::_URC_END_OF_STACK ```

Notes: I've added the unwind(allowed) attribute to the raise function: https://git.m-labs.hk/pca006132/artiq-zynq/src/branch/eh/src/runtime/src/eh_artiq.rs#L176

However, there is still no unwind information for it:

pca006132@zeus ~/c/r/artiq-zynq> readelf -u ./build/firmware/armv7-none-eabihf/release/runtime | grep raise
pca006132@zeus ~/c/r/artiq-zynq> readelf -u ./build/firmware/armv7-none-eabihf/release/runtime | grep unwind
0x100000: 0x1 [cantunwind]
0x1254fc <__aeabi_unwind_cpp_pr0>: 0x80b0b0b0
0x125508 <_ZN12_GLOBAL__N_114unwindOneFrameEjP21_Unwind_Control_BlockP15_Unwind_Context>: @0x0
0x125558 <__aeabi_unwind_cpp_pr1>: 0x80b0b0b0
0x125954 <__gnu_unwind_frame>: 0x809b8480
0x125a00 <unw_getcontext>: 0x1 [cantunwind]
0x125a84 <_ZN9libunwind12UnwindCursorINS_17LocalAddressSpaceENS_13Registers_armEEC2EP13unw_context_tRS1_>: @0x0
0x125e10 <_ZN9libunwind13Registers_armC2EPKv>: @0x0
0x125e5c <_ZN9libunwind20AbstractUnwindCursorD2Ev>: 0x80b0b0b0
0x125eac <_ZN9libunwind12UnwindCursorINS_17LocalAddressSpaceENS_13Registers_armEE4stepEv>: @0x0
0x125f0c <_ZN9libunwind12UnwindCursorINS_17LocalAddressSpaceENS_13Registers_armEE7getInfoEP15unw_proc_info_t>: 0x80b0b0b0
0x125f4c <_ZN9libunwind12UnwindCursorINS_17LocalAddressSpaceENS_13Registers_armEE15getFunctionNameEPcjPj>: 0x809b8480
0x125f6c <_ZN9libunwind12UnwindCursorINS_17LocalAddressSpaceENS_13Registers_armEE24setInfoBasedOnIPRegisterEb>: @0x0
0x125fe4 <_ZN9libunwind12UnwindCursorINS_17LocalAddressSpaceENS_13Registers_armEE15getRegisterNameEi>: 0x80b0b0b0
0x125ff8 <_ZNK9libunwind13Registers_arm11getRegisterEi>: 0x809b8480
0x12610c <_ZN9libunwind13Registers_arm16getFloatRegisterEi>: @0x0
0x1261d0 <_ZN9libunwind13Registers_arm16setFloatRegisterEiy>: @0x0
0x12629c <_ZN9libunwind12UnwindCursorINS_17LocalAddressSpaceENS_13Registers_armEE13stepWithEHABIEv>: @0x0
0x1262e8 <_ZN9libunwind13Registers_arm6jumptoEv>: @0x0
0x126304 <_ZN9libunwind13Registers_arm26restoreSavedFloatRegistersEv>: @0x0
0x126354 <_ZN9libunwind17LocalAddressSpace18findUnwindSectionsEjRNS_18UnwindInfoSectionsE>: @0x0
0x1263b0 <_ZN9libunwind12UnwindCursorINS_17LocalAddressSpaceENS_13Registers_armEE23getInfoFromEHABISectionEjRKNS_18UnwindInfoSectionsE>: 0x809b46af
0x1266a4 <_ZNK9libunwind20EHABISectionIteratorINS_17LocalAddressSpaceEE15functionAddressEv>: @0x0
0x1266dc <_ZN9libunwind17LocalAddressSpace5get32Ej>: 0x809b8480
0x1266fc <_ZN9libunwind13Registers_arm15getRegisterNameEi>: 0x80b0b0b0
0x126cf4 <_ZN9libunwind13Registers_arm20restoreCoreAndJumpToEv>: 0x1 [cantunwind]
0x1281d0 <__aeabi_uidivmod>: 0x1 [cantunwind]
0x12ab90 <__multi3+0x4>: 0x1 [cantunwind]
Notes: I've added the `unwind(allowed)` attribute to the `raise` function: https://git.m-labs.hk/pca006132/artiq-zynq/src/branch/eh/src/runtime/src/eh_artiq.rs#L176 However, there is still no unwind information for it: ``` pca006132@zeus ~/c/r/artiq-zynq> readelf -u ./build/firmware/armv7-none-eabihf/release/runtime | grep raise pca006132@zeus ~/c/r/artiq-zynq> readelf -u ./build/firmware/armv7-none-eabihf/release/runtime | grep unwind 0x100000: 0x1 [cantunwind] 0x1254fc <__aeabi_unwind_cpp_pr0>: 0x80b0b0b0 0x125508 <_ZN12_GLOBAL__N_114unwindOneFrameEjP21_Unwind_Control_BlockP15_Unwind_Context>: @0x0 0x125558 <__aeabi_unwind_cpp_pr1>: 0x80b0b0b0 0x125954 <__gnu_unwind_frame>: 0x809b8480 0x125a00 <unw_getcontext>: 0x1 [cantunwind] 0x125a84 <_ZN9libunwind12UnwindCursorINS_17LocalAddressSpaceENS_13Registers_armEEC2EP13unw_context_tRS1_>: @0x0 0x125e10 <_ZN9libunwind13Registers_armC2EPKv>: @0x0 0x125e5c <_ZN9libunwind20AbstractUnwindCursorD2Ev>: 0x80b0b0b0 0x125eac <_ZN9libunwind12UnwindCursorINS_17LocalAddressSpaceENS_13Registers_armEE4stepEv>: @0x0 0x125f0c <_ZN9libunwind12UnwindCursorINS_17LocalAddressSpaceENS_13Registers_armEE7getInfoEP15unw_proc_info_t>: 0x80b0b0b0 0x125f4c <_ZN9libunwind12UnwindCursorINS_17LocalAddressSpaceENS_13Registers_armEE15getFunctionNameEPcjPj>: 0x809b8480 0x125f6c <_ZN9libunwind12UnwindCursorINS_17LocalAddressSpaceENS_13Registers_armEE24setInfoBasedOnIPRegisterEb>: @0x0 0x125fe4 <_ZN9libunwind12UnwindCursorINS_17LocalAddressSpaceENS_13Registers_armEE15getRegisterNameEi>: 0x80b0b0b0 0x125ff8 <_ZNK9libunwind13Registers_arm11getRegisterEi>: 0x809b8480 0x12610c <_ZN9libunwind13Registers_arm16getFloatRegisterEi>: @0x0 0x1261d0 <_ZN9libunwind13Registers_arm16setFloatRegisterEiy>: @0x0 0x12629c <_ZN9libunwind12UnwindCursorINS_17LocalAddressSpaceENS_13Registers_armEE13stepWithEHABIEv>: @0x0 0x1262e8 <_ZN9libunwind13Registers_arm6jumptoEv>: @0x0 0x126304 <_ZN9libunwind13Registers_arm26restoreSavedFloatRegistersEv>: @0x0 0x126354 <_ZN9libunwind17LocalAddressSpace18findUnwindSectionsEjRNS_18UnwindInfoSectionsE>: @0x0 0x1263b0 <_ZN9libunwind12UnwindCursorINS_17LocalAddressSpaceENS_13Registers_armEE23getInfoFromEHABISectionEjRKNS_18UnwindInfoSectionsE>: 0x809b46af 0x1266a4 <_ZNK9libunwind20EHABISectionIteratorINS_17LocalAddressSpaceEE15functionAddressEv>: @0x0 0x1266dc <_ZN9libunwind17LocalAddressSpace5get32Ej>: 0x809b8480 0x1266fc <_ZN9libunwind13Registers_arm15getRegisterNameEi>: 0x80b0b0b0 0x126cf4 <_ZN9libunwind13Registers_arm20restoreCoreAndJumpToEv>: 0x1 [cantunwind] 0x1281d0 <__aeabi_uidivmod>: 0x1 [cantunwind] 0x12ab90 <__multi3+0x4>: 0x1 [cantunwind] ```

More places that you may have considered already:

  • zc706's armv7-none-eabihf.json field "panic_strategy"
  • Cargo.toml section [profile.release] key "panic"
More places that you may have considered already: * zc706's `armv7-none-eabihf.json` field `"panic_strategy"` * `Cargo.toml` section `[profile.release]` key `"panic"`

zc706's armv7-none-eabihf.json field "panic_strategy"

Note that artiq-zynq has its own copy of this JSON file.

> zc706's armv7-none-eabihf.json field "panic_strategy" Note that artiq-zynq has its own copy of this JSON file.

Setting "requires-uwtable": true and "force-unwind-tables": "yes" solves the issue.

Setting `"requires-uwtable": true` and `"force-unwind-tables": "yes"` solves the issue.
Sign in to join this conversation.
No Milestone
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/artiq-zynq#18
There is no content yet.