This is an archive of the discontinued LLVM Phabricator instance.

[libunwind][AIX] Implement _Unwind_FindEnclosingFunction() using traceback table on AIX
ClosedPublic

Authored by xingxue on Aug 11 2022, 12:03 PM.

Details

Summary

The implementation of _Unwind_FindEnclosingFunction(void *ip) takes the context of itself and then uses the context to get the info of the function enclosing ip. This approach does not work for AIX because on AIX, the TOC base in GPR2 is used as the base for calculating relative addresses. Since _Unwind_FindEnclosingFunction() may be in a different shared lib than the function containing ip, their TOC bases can be different. Therefore, using the value of GPR2 in the context from _Unwind_FindEnclosingFunction() as the base results in incorrect addresses. On the other hand, the start address of a function is available in the traceback table following the instructions of each function on AIX. To get to the traceback table, search a word of 0 starting from ip and the traceback table is located after the word 0. This patch implements _Unwind_FindEnclosingFunction() for AIX by obtaining the function start address from its traceback table.

Diff Detail

Event Timeline

xingxue created this revision.Aug 11 2022, 12:03 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptAug 11 2022, 12:03 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
xingxue requested review of this revision.Aug 11 2022, 12:03 PM
compnerd added inline comments.Aug 12 2022, 8:26 AM
libunwind/src/UnwindLevel1-gcc-ext.c
92

Should we use uintptr_t here instead of uint32_t?

93

Should we protect against _Unwind_FindEnclosingFunction(NULL)?

110

Just drop the else, we return a value if the traceback table has offsets or we will return NULL.

lkail added a subscriber: lkail.Aug 12 2022, 9:06 AM
xingxue updated this revision to Diff 452220.Aug 12 2022, 10:31 AM

Addressed comment.

  • _Unwind_FindEnclosingFunction() returns NULL if argument pc is NULL;
  • dropped else for returning NULL as suggested.
xingxue marked 3 inline comments as done.Aug 12 2022, 10:50 AM
xingxue added inline comments.
libunwind/src/UnwindLevel1-gcc-ext.c
92

p is for searching for word 0 from instruction pc and the length of PowerPC instructions is one word (32-bit) regardless of whether it is in 32-bit or 64-bit mode, so we need to use uint32_t.

93

Good idea, thanks!

110

Removed else as suggested, thanks!

xingxue edited the summary of this revision. (Show Details)Aug 12 2022, 11:24 AM
compnerd accepted this revision.Aug 12 2022, 2:21 PM
This revision is now accepted and ready to land.Aug 12 2022, 2:21 PM
MaskRay accepted this revision.Aug 12 2022, 2:31 PM
MaskRay added inline comments.
libunwind/src/UnwindLevel1-gcc-ext.c
100

llvm style prefers pre-increment ++p

This revision was automatically updated to reflect the committed changes.
xingxue marked 3 inline comments as done.
xingxue added inline comments.Aug 12 2022, 3:13 PM
libunwind/src/UnwindLevel1-gcc-ext.c
100

Sorry, changed both instances as suggested, thanks!