Skip to content

Fix for unw_backtrace fast path does not work on x86_64 [https://github.com/libunwind/libunwind/issues/440]#444

Merged
djwatson merged 2 commits into
libunwind:masterfrom
DataDog:gleocadie/fix-frame-caraterization
Dec 28, 2022

Conversation

@gleocadie

@gleocadie gleocadie commented Dec 8, 2022

Copy link
Copy Markdown
Contributor

I recently it the issue describe in #440 .
This PR is an attempt to fix it.

@TannerFirl

Copy link
Copy Markdown

I see similar logic in arm and aarch64. Do we know if #440 also applies in these cases? Specifically:

src/aarch64/Gstash_frame.c:61:          || (rs->reg.where[FP] == DWARF_WHERE_CFAREL
src/aarch64/Gstash_frame.c:66:          || (rs->reg.where[LR] == DWARF_WHERE_CFAREL
src/aarch64/Gstash_frame.c:71:          || (rs->reg.where[SP] == DWARF_WHERE_CFAREL
src/aarch64/Gstash_frame.c:79:    if (rs->reg.where[FP] == DWARF_WHERE_CFAREL)
src/aarch64/Gstash_frame.c:81:    if (rs->reg.where[LR] == DWARF_WHERE_CFAREL)
src/aarch64/Gstash_frame.c:83:    if (rs->reg.where[SP] == DWARF_WHERE_CFAREL)
src/arm/Gstash_frame.c:61:          || (rs->reg.where[R7] == DWARF_WHERE_CFAREL
src/arm/Gstash_frame.c:66:          || (rs->reg.where[LR] == DWARF_WHERE_CFAREL
src/arm/Gstash_frame.c:71:          || (rs->reg.where[SP] == DWARF_WHERE_CFAREL
src/arm/Gstash_frame.c:79:    if (rs->reg.where[R7] == DWARF_WHERE_CFAREL)
src/arm/Gstash_frame.c:81:    if (rs->reg.where[LR] == DWARF_WHERE_CFAREL)
src/arm/Gstash_frame.c:83:    if (rs->reg.where[SP] == DWARF_WHERE_CFAREL)
src/dwarf/Gparser.c:193:          set_reg (sr, regnum, DWARF_WHERE_CFAREL, val * dci->data_align);
src/dwarf/Gparser.c:202:          set_reg (sr, regnum, DWARF_WHERE_CFAREL, val * dci->data_align);
src/dwarf/Gparser.c:211:          set_reg (sr, regnum, DWARF_WHERE_CFAREL, val * dci->data_align);
src/dwarf/Gparser.c:400:          set_reg (sr, regnum, DWARF_WHERE_CFAREL, ~(val * dci->data_align) + 1);
src/dwarf/Gparser.c:410:            set_reg (sr, regnum, DWARF_WHERE_CFAREL,
src/dwarf/Gparser.c:922:        case DWARF_WHERE_CFAREL:
src/x86_64/Gstash_frame.c:74:          || (rs->reg.where[RBP] == DWARF_WHERE_CFAREL
src/x86_64/Gstash_frame.c:79:          || (rs->reg.where[RSP] == DWARF_WHERE_CFAREL
src/x86_64/Gstash_frame.c:87:    if (rs->reg.where[RBP] == DWARF_WHERE_CFAREL)
src/x86_64/Gstash_frame.c:89:    if (rs->reg.where[RSP] == DWARF_WHERE_CFAREL)

@gleocadie

Copy link
Copy Markdown
Contributor Author

src/x86_64/Gstash_frame.c:74: || (rs->reg.where[RBP] == DWARF_WHERE_CFAREL
src/x86_64/Gstash_frame.c:79: || (rs->reg.where[RSP] == DWARF_WHERE_CFAREL
src/x86_64/Gstash_frame.c:87: if (rs->reg.where[RBP] == DWARF_WHERE_CFAREL)
src/x86_64/Gstash_frame.c:89: if (rs->reg.where[RSP] == DWARF_WHERE_CFAREL)

Good point, I was only focusing on x86_64. But according to the code, for Gstash_frame.c in arm and aarch64, we can do the same.
But for those arch, it will be a bit difficult for me to test (none available)
I'll see what I can do.

@TannerFirl

Copy link
Copy Markdown

But for those arch, it will be a bit difficult for me to test (none available)

I can test aarch changes.

Btw, I can confirm aarch fast backtrace is not working. with debug enabled and verbose logging, export UNW_DEBUG_LEVEL=1; make Ltest-bt.log I see:

	via backtrace():
 >unw_init_local_common: (cursor=0xffffffffb2a8)
 >uc_addr: Accessing VG register from context is not supported
 >_ULaarch64_tdep_trace: begin ip 0x400000083f48 cfa 0xffffffffae90
 >_ULaarch64_step: (cursor=0xffffffffb2a8, ip=0x0000400000083f48, cfa=0x0000ffffffffae90))
 >_ULaarch64_dwarf_search_unwind_table: e->fde_offset = aa0, segbase = 4000000a04e8, debug_frame_base = 0, fde_addr = 4000000a0f88
 >_ULaarch64_step: dwarf_step()=1
 >_ULaarch64_tdep_trace: returning -5, depth 0

@gleocadie

Copy link
Copy Markdown
Contributor Author

@TannerFirl thanks for your help

@djwatson

Copy link
Copy Markdown
Member

Lgtm, thanks for the fix!

@djwatson
djwatson merged commit b0b4d98 into libunwind:master Dec 28, 2022
@gleocadie
gleocadie deleted the gleocadie/fix-frame-caraterization branch December 28, 2022 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants