[PATCH] D58378: [PowerPC]Leverage the addend in the TOC relocation to do the address calculation

qshanz via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 2 01:30:52 PST 2020


steven.zhang added a comment.

In D58378#1800862 <https://reviews.llvm.org/D58378#1800862>, @MaskRay wrote:

> > b.c:(.text+0x8): relocation truncated to fit: R_PPC64_TOC16_HA against symbol `b' defined in COMMON section in /tmp/b-9d97be.o+7ffffff8
>
> The r_addend is 0x7ffffff8, a value close to 2**31.
>
> The distance between the TOC entry and the variable address cannot be too far. More accurately, `-0x80008000 <= address - .TOC. + r_addend < 0x7fff8000`
>
> GNU ld correctly reports a relocation overflow. lld currently does not check `R_PPC64_TOC16_HA` overflow.
>
>   % powerpc64le-linux-gnu-ld -pie b.o main.o
>   powerpc64le-linux-gnu-ld: warning: cannot find entry symbol _start; defaulting to 0000000000000230
>   powerpc64le-linux-gnu-ld: b.o: in function `foo':
>   b.c:(.text+0x8): relocation truncated to fit: R_PPC64_TOC16_HA against symbol `b' defined in COMMON section in b.o+7ffffff8
>
>
> The largest address a pair of HA/L can materialize is something like:
>
>   addis 3, 2, 32767  # adding 1 will overflow to -32768
>   lfd 1, 32767(3)
>


Thank you for this information! I miss the "double" type in the array(it is not 27 bit, but 30 bit). So,  for some unknown reason, linker reserve the 0x8000 for special usage. The addend + 0x8000 should be fit into the 32bit sign value. I will split this patch into two parts.

1. fix the missing part of the ASM printer of the offset.
2. Add the combine rule to generate the global address that has offset.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58378/new/

https://reviews.llvm.org/D58378





More information about the llvm-commits mailing list