Skip to content

[libunwind][AIX] Fix up TOC register if unw_getcontext is called from a different module #66549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions libunwind/src/UnwindRegistersSave.S
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,21 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
mflr 0
std 0, PPC64_OFFS_SRR0(3) // store lr as ssr0
PPC64_STR(1)
PPC64_STR(4) // Save r4 first since it will be used for fixing r2.
#if defined(_AIX)
// The TOC register (r2) was changed by the glue code if unw_getcontext
// is called from a different module. Save the original TOC register
// in the context if this is the case.
mflr 4
lwz 4, 0(4) // Get the first instruction at the return address.
xoris 0, 4, 0xe841 // Is it reloading the TOC register "ld 2,40(1)"?
cmplwi 0, 0x28
bne 0, LnoR2Fix // No need to fix up r2 if it is not.
ld 2, 40(1) // Use the saved TOC register in the stack.
LnoR2Fix:
#endif
PPC64_STR(2)
PPC64_STR(3)
PPC64_STR(4)
PPC64_STR(5)
PPC64_STR(6)
PPC64_STR(7)
Expand Down Expand Up @@ -547,9 +559,21 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
mflr 0
stw 0, 0(3) // store lr as ssr0
stw 1, 12(3)
stw 4, 24(3) // Save r4 first since it will be used for fixing r2.
#if defined(_AIX)
// The TOC register (r2) was changed by the glue code if unw_getcontext
// is called from a different module. Save the original TOC register
// in the context if this is the case.
mflr 4
lwz 4, 0(4) // Get the instruction at the return address.
xoris 0, 4, 0x8041 // Is it reloading the TOC register "ld 2,40(1)"?
cmplwi 0, 0x14
bne 0, LnoR2Fix // No need to fix up r2 if it is not.
lwz 2, 20(1) // Use the saved TOC register in the stack.
LnoR2Fix:
#endif
stw 2, 16(3)
stw 3, 20(3)
stw 4, 24(3)
stw 5, 28(3)
stw 6, 32(3)
stw 7, 36(3)
Expand Down
3 changes: 0 additions & 3 deletions libunwind/test/unw_resume.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
// Ensure that unw_resume() resumes execution at the stack frame identified by
// cursor.

// TODO: Investigate this failure on AIX system.
// XFAIL: target={{.*}}-aix{{.*}}

// TODO: Figure out why this fails with Memory Sanitizer.
// XFAIL: msan

Expand Down