[PATCH] D63132: [ELF][RISCV] Set st_shndx of __global_pointer$ to 1 if .sdata does not exist
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 11 07:39:26 PDT 2019
MaskRay added a comment.
> GNU ld treats it as undefined:
Yes. That was why I created the patch to fix the musl -fpie -pie link error: `ld.lld: error: relocation R_RISCV_PCREL_HI20 cannot refer to absolute symbol: __global_pointer$`. This error is lld specific: in -pie/-shared mode, a PC relative relocation to an absolute symbol is not allowed.
In https://groups.google.com/forum/#!searchin/generic-abi/SHN_ABS|sort:date/generic-abi/MC4b4sqnKC0/oQgZxxwMmJAJ, Cary's interpretation of gABI is:
> On the contrary, the only interpretation that makes sense to me is that it will not change because of relocation at link time or at load time.
If lld resolves the PC relative relocation statically, the value will be incorrect when the pie or shared object is loaded at runtime because the SHN_ABS symbol's value does not change. The best lld can do is to issue an error.
An alternative is to create a dummy `.sdata` in musl's `Scrt1.o`. I don't know how reasonable it is to have `lla gp,__global_pointer$` in other code that might not define `.sdata`.
Repository:
rLLD LLVM Linker
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D63132/new/
https://reviews.llvm.org/D63132
More information about the llvm-commits
mailing list