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

Qing Shan Zhang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 19 22:35:13 PST 2019


steven.zhang added a comment.

In D58378#1402373 <https://reviews.llvm.org/D58378#1402373>, @nemanjai wrote:

> This can cause relocation overflows:
>
>   $ cat b.c 
>   double b[1LU << 33];
>   double foo() { return b[(1LU << _SH) - 1] ; }
>   void setfoo(double d) { b[(1LU << _SH) - 1] = d; }
>  
>   $ cat main.c 
>   double foo();
>   void setfoo(double);
>   int main(void) {
>     setfoo(445.2);
>     return foo() == 445.2;
>   }
>  
>   $ clang -O2 b.c main.c -D_SH=28
>   /tmp/b-9d97be.o: In function `foo':
>   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
>   /tmp/b-9d97be.o: In function `setfoo':
>   b.c:(.text+0x28): relocation truncated to fit: R_PPC64_TOC16_HA against symbol `b' defined in COMMON section in /tmp/b-9d97be.o+7ffffff8
>   clang-9: error: linker command failed with exit code 1 (use -v to see invocation)
>


I need to double check the ELF spec to see why it is limited to 27bit. And I check this with llvm linker(lld), it linked successfully but encounter the runtime segment fault if _SH=28. Seems that, lld also miss to do this check.


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

https://reviews.llvm.org/D58378





More information about the llvm-commits mailing list