This is an archive of the discontinued LLVM Phabricator instance.

[libc++abi][AIX] Use reserved slot in stack to pass the address of exception object
ClosedPublic

Authored by xingxue on Oct 19 2022, 7:23 AM.

Details

Summary

The existing implementation of the personality for legacy IBM xlclang++ compiler generated code passes the address of exception object in r14 for the landing pad to retrieve with a call to __xlc_exception_handle(). This clobbers the content of r14 in user code (and potentially, when running cleanup actions, the address of another exception object being passed). This patch changes to use the stack slot reserved for compilers to pass the address. It has been confirmed that xlclang++-generated code does not use this slot. The following is the AIX stack frame layout.

Low Address
                                                          32-bit  64-bit

        SP----> +---------------------------------------+
                | back chain to caller                  | 0       0
                +---------------------------------------+
                | saved CR                              | 4       8 (8-11)
                +---------------------------------------+
                | saved LR                              | 8       16
                +---------------------------------------+
                | reserved for compilers                | 12      24                  <=======
                +---------------------------------------+
                | reserved for binders                  | 16      32
                +---------------------------------------+
                | saved TOC pointer                     | 20      40
                +---------------------------------------+
                | Parameter save area (+padding*) (P)   | 24      48
                +---------------------------------------+
                | Alloca space (A)                      | 24+P    etc.
                +---------------------------------------+
                | Local variable space (L)              | 24+P+A
                +---------------------------------------+
                | Float/int conversion temporary (X)    | 24+P+A+L
                +---------------------------------------+
                | Save area for AltiVec registers (W)   | 24+P+A+L+X
                +---------------------------------------+
                | AltiVec alignment padding (Y)         | 24+P+A+L+X+W
                +---------------------------------------+
                | Save area for VRSAVE register (Z)     | 24+P+A+L+X+W+Y
                +---------------------------------------+
                | Save area for GP registers (G)        | 24+P+A+X+L+X+W+Y+Z
                +---------------------------------------+
                | Save area for FP registers (F)        | 24+P+A+X+L+X+W+Y+Z+G
                +---------------------------------------+
        old SP->| back chain to caller's caller         |
                +---------------------------------------+
                | saved CR                              | 4       8 (8-11)
                +---------------------------------------+
                | saved LR                              | 8       16
                +---------------------------------------+
High Address

Diff Detail

Event Timeline

xingxue created this revision.Oct 19 2022, 7:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 19 2022, 7:23 AM
Herald added a subscriber: StephenFan. · View Herald Transcript
xingxue requested review of this revision.Oct 19 2022, 7:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 19 2022, 7:23 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
xingxue edited the summary of this revision. (Show Details)Oct 19 2022, 8:49 AM

LGTM from the AIX perspective.

xingxue updated this revision to Diff 469217.Oct 20 2022, 6:59 AM

Updated diff to include binary files.

cebowleratibm added inline comments.Oct 21 2022, 7:51 AM
libcxxabi/src/aix_state_tab_eh.inc
665

Suggestion: rename dummy to force_a_stackframe or similar. The comments are helpful but the name makes it really hard for anyone to erroneously remove it, noting that you also have tests that would fail if anyone did but the more layers of defense and readability the better.

xingxue updated this revision to Diff 469721.Oct 21 2022, 12:53 PM

Changes in the update:

  • addressed comment: rename dummy() to force_a_stackframe();
  • added attribute optnone to force_a_stackframe();
  • use assembly for IBM legacy compiler xlclang++ generated test cases instead of binary object files.
xingxue marked an inline comment as done.Oct 21 2022, 12:54 PM
xingxue added inline comments.
libcxxabi/src/aix_state_tab_eh.inc
665

Renamed as suggested, thanks!

Confirming LGTM from the AIX side.

cebowleratibm accepted this revision.Oct 25 2022, 7:51 AM

I have no further concerns with this patch and can confirm the solution works for EH support of the XL C++ V16 xlclang++ compiler. No further concerns.

This revision was not accepted when it landed; it landed in state Needs Review.Oct 27 2022, 2:07 PM
This revision was automatically updated to reflect the committed changes.
xingxue marked an inline comment as done.

This patch is AIX specific and it has been thoroughly reviewed and approved by AIX compiler experts @hubert.reinterpretcast, @cebowleratibm (Thank you!). Since we need to have the patch in the coming service pack, I've committed it in rGa499051f10a2d0150b60c14493558476039f701a. Commit rGfb391e45e9cc35429f077413ca660f4f5f5212c1 modified a comment.

This patch is AIX specific and it has been thoroughly reviewed and approved by AIX compiler experts @hubert.reinterpretcast, @cebowleratibm (Thank you!). Since we need to have the patch in the coming service pack, I've committed it in rGa499051f10a2d0150b60c14493558476039f701a. Commit rGfb391e45e9cc35429f077413ca660f4f5f5212c1 modified a comment.

That's fine.