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
- Repository
- rG LLVM Github Monorepo
Event Timeline
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 ↗ | (On Diff #536078) | 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. |
llvm/test/CodeGen/PowerPC/absol-jump-table-enabled.ll | ||
---|---|---|
73 ↗ | (On Diff #536078) | 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. |
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 ↗ | (On Diff #536078) | 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. |
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.
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.