[llvm] [PowerPC] Alignment of toc-data symbol should not be increased during optimizations (PR #94593)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 7 17:29:27 PDT 2024


MaskRay wrote:

> > Why does AIX have this requirement? ppc64 ELFv2 ABI can increase the alignment without any issue.
> 
> IIUC, AIX has limited TOC region especially for small code model and TOC region is created by linker(i.e., compiler can not fully control the layout of the TOC entries), so to avoid wasting of TOC entries, guarding alignment of the TOC data symbols be same with normal toc entries is necessary.
> 
> ```
> int a;
> int foo()
> {
>   return a;
> }
> 
> int b;
> int main() {
>   return b + foo();
> }
> ```
> 
> If a is a toc-data symbol and we change its alignment to 16 in the assembly ( 2^16 is the size of the TOC region for small code model), compiling the modified assembly will make AIX linker emit TOC overflow error.

Thanks for the example. I have also tried

```
clang -O2 -c a.c --target=powerpc64 -mabi=elfv{1,2} -mcmodel={small,medium}
```

AIX has the limited R_TOC relocation, similar to R_PPC64_TOC16_DS emitted by ELFv1 ELFv2 with -mcmodel=small.
I think nearly nobody uses -mcmodel=small for ELF, so having this exception only for AIX makes sense.

https://github.com/llvm/llvm-project/pull/94593


More information about the llvm-commits mailing list