[PATCH] D56920: [PPC64] Sort .toc sections accessed with small code model relocs close to the .got

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 20 23:21:58 PST 2019


MaskRay added a comment.

In D56920#1364451 <https://reviews.llvm.org/D56920#1364451>, @grimar wrote:

> I am not PPC expert, but approach itself seems probably OK to me. At least I do not have good ideas on how to do what you want much simpler/better atm.
>  Maybe other reviewers will have something.
>
> My comments/suggestions are below.
>
> Also, do you know how this problem is solved by the GNU linkers?


Both ld.bfd and gold have the similar "small_toc_reloc" notation and `binutils-gdb/gold/power.cc` does similar TOC sorting (ld.bfd has a much more complicated rule).
https://sourceware.org/git/?p=binutils-gdb.git;a=blob;hb=dff021e14a9c72380311c15a90c1a646b179b987;f=gold/powerpc.cc#l8376



================
Comment at: ELF/Arch/PPC64.cpp:112
+    return false;
+}
+
----------------
MaskRay wrote:
> grimar wrote:
> > This does not seem to be clang-formatted.
> > Also, since you only have 3 entries here, probably it will be better to use `if` instead of `switch`.
> Using a `switch` for 3 entries looks good to me. I guess this is an incomplete list (but enough to make some not-so-small applications able to link against `libgcc.a`). If it is indeed incomplete, this code deserves a comment.
> 
> I've checked some powerpc64le target which failed to link due to
> `libgcc/libgcc2.c:1444: relocation R_PPC64_ADDR16_DS out of range: 37088 is not in [-32768, 32767]`
> The relocation out-of-range issues goes away with this patch.
> 
> "Power Architecture 64-bit ELF V2 ABI Specification" published on July 16, 2015 does not give examples what relocation types may be used in small/medium/large code models... The x86-64 ABI gives a few regarding PIC/non-PIC * small/medium/large code model..
There are indeed a few other relocation types that need to be added. They can be added in another patch, though.

gold
https://sourceware.org/git/?p=binutils-gdb.git;a=blob;hb=dff021e14a9c72380311c15a90c1a646b179b987;f=gold/powerpc.cc#l7291

ld.bfd
https://sourceware.org/git/?p=binutils-gdb.git;a=blob;hb=dff021e14a9c72380311c15a90c1a646b179b987;f=bfd/elf64-ppc.c#l4395
and line 4535

```c
	  if (r_type == R_PPC64_GOT_TLSLD16
	      || r_type == R_PPC64_GOT_TLSGD16
	      || r_type == R_PPC64_GOT_TPREL16_DS
	      || r_type == R_PPC64_GOT_DTPREL16_DS
	      || r_type == R_PPC64_GOT16
	      || r_type == R_PPC64_GOT16_DS)
	    {
	      htab->do_multi_toc = 1;
	      ppc64_elf_tdata (abfd)->has_small_toc_reloc = 1;
	    }
```


Repository:
  rLLD LLVM Linker

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

https://reviews.llvm.org/D56920





More information about the llvm-commits mailing list