This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] disable ppc-use-absolute-jumptables for AIX
AbandonedPublic

Authored by tingwang on Jun 29 2023, 1:29 AM.

Details

Reviewers
shchenz
nemanjai
kamaub
stefanp
joerg
Group Reviewers
Restricted Project
Summary

ppc-use-absolute-jumptables is not workable on AIX due to jump table encoding and PIC requirement, and AIX only supports relative jump table entries right now. Disable the flag for AIX.

Diff Detail

Event Timeline

tingwang created this revision.Jun 29 2023, 1:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 29 2023, 1:29 AM
tingwang requested review of this revision.Jun 29 2023, 1:29 AM
tingwang updated this revision to Diff 536078.Jun 29 2023, 5:58 PM

Update test case after commit NFC patch.

This indeed is a bug on AIX (which has PIC as default). Relative jump table in the data section but no add in the text section, so the target addresses would be wrong.

Thanks for catching this bug.

llvm/test/CodeGen/PowerPC/absol-jump-table-enabled.ll
73

This change seems problematic to me. PIC is a functionality option while -ppc-use-absolute-jumptables=true is an optimization option (save the add instruction?), so if -ppc-use-absolute-jumptables=true and --relocation-model=pic are both true, we should use relative jump table which matches PIC requirement.

tingwang added inline comments.Jul 3 2023, 12:24 AM
llvm/test/CodeGen/PowerPC/absol-jump-table-enabled.ll
73

I don't take relative jump table as a necessary condition for PIC, for example check attached case_xlc.c when compiled by xlc using -qpic=small (which is equivalent to -fpic according to the migration guide) generates absolute address for jump table entries, use ldx to load the entry, and then jump to the address without add.

shchenz added a subscriber: joerg.Jul 3 2023, 1:54 AM

add @joerg who helped to add PIC mode jump table in https://reviews.llvm.org/D26336

llvm/test/CodeGen/PowerPC/absol-jump-table-enabled.ll
73

XLC don't use add, but the contents in the jump table are not block addresses. They are the sum of the function address and the offsets of the branch targets in that function.

add @joerg who helped to add PIC mode jump table in https://reviews.llvm.org/D26336

Thank you for the info. Now I see the factor on AIX: xlc put jump tables in data section (which is writable) with R_POS relocation. Loader will update those entries. While in LLVM right now, jump tables are emitted in text section. Now for absolute BlockAddress, even if linker added R_POS relocation for those entries, loader cannot do update because that's text section, and it generates error like following:

0509-141   Relocation entry 0 (at address 1000003E0)
                   has an invalid l_rsecnm field.

The fix is wrong. I will update patch later.

tingwang planned changes to this revision.Jul 4 2023, 12:55 AM
tingwang updated this revision to Diff 536991.Jul 4 2023, 2:00 AM
tingwang retitled this revision from [PowerPC] fix jumptable encoding when ppc-use-absolute-jumptables is turned on to [PowerPC] disable ppc-use-absolute-jumptables for AIX.
tingwang edited the summary of this revision. (Show Details)

Disable the flag on AIX.

However the issue remains on at least ppc64le. I'm not sure of the purpose of this flag, so just expose the issue and leave it here.

tingwang abandoned this revision.Jul 6 2023, 7:24 PM

Not necessary.