llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.42k stars 11.74k forks source link

Missing relocation 88 (R_PPC_GOT_TPREL16_LO) for powerpc 32 bit #42495

Closed 688cc089-1a96-4cb4-bd77-eaf433fc1da2 closed 5 years ago

688cc089-1a96-4cb4-bd77-eaf433fc1da2 commented 5 years ago
Bugzilla Link 43150
Resolution FIXED
Resolved on Aug 30, 2019 08:54
Version unspecified
OS Linux
CC @MaskRay,@luporl,@smithp35

Extended Description

When statically linking a simple test program usin LLVM9 or 10 (trunk), I found the following problem:

/root/src/llvm-project/build/bin/clang -target powerpc-unknown-freebsd13.0 -O2 -g --sysroot=/usr/obj/root/src/freebsd/powerpc.powerpc64/obj-lib32/tmp/ t1.c -o t1.lld.static -fuse-ld=/root/src/llvm-project/build/bin/ld.lld -static ld.lld: error: unknown relocation (88) against symbol je_tsd_tls ld.lld: error: unknown relocation (88) against symbol je_tsd_tls ld.lld: error: unknown relocation (88) against symbol je_tsd_tls ld.lld: error: unknown relocation (88) against symbol je_tsd_tls ld.lld: error: unknown relocation (88) against symbol je_tsd_tls ld.lld: error: unknown relocation (88) against symbol je_tsd_tls ld.lld: error: unknown relocation (88) against symbol je_tsd_tls ld.lld: error: unknown relocation (88) against symbol je_tsd_tls ld.lld: error: unknown relocation (88) against symbol je_tsd_tls ld.lld: error: unknown relocation (88) against symbol je_tsd_tls ld.lld: error: unknown relocation (88) against symbol je_tsd_tls ld.lld: error: unknown relocation (88) against symbol je_tsd_tls ld.lld: error: unknown relocation (88) against symbol je_tsd_tls ld.lld: error: unknown relocation (88) against symbol je_tsd_tls ld.lld: error: unknown relocation (88) against symbol je_tsd_tls ld.lld: error: unknown relocation (88) against symbol je_tsd_tls ld.lld: error: unknown relocation (88) against symbol je_tsd_tls ld.lld: error: unknown relocation (88) against symbol je_tsd_tls ld.lld: error: unknown relocation (88) against symbol je_tsd_tls ld.lld: error: unknown relocation (88) against symbol je_tsd_tls ld.lld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors) clang-9: error: linker command failed with exit code 1 (use -v to see invocation)

A reproduce tarball will be attached.

MaskRay commented 5 years ago

D66925/r370426

688cc089-1a96-4cb4-bd77-eaf433fc1da2 commented 5 years ago

So it is probably unnecessary to teach LLD about _LO _HA. I have an LLVM patch to emit R_PPC_GOT_TPREL16 instead of R_PPC_GOT_TPREL16_LO to circumvent the issue https://reviews.llvm.org/D66925

Your solution works! I applied D66925 patch to LLVM9 and rebuilt FreeBSD powerpc 32 bit libraries. All my static (C language) test programs are running now.

MaskRay commented 5 years ago

I observe that [1] ld.bfd has an internal error when it attempts to relax Initial-Exec to Local-Exec:

  // a.o
  addis 3, 3, tsd_tls@got@tprel@ha
  lwz 3, tsd_tls@got@tprel@l(3)
  add 3, 3, tsd_tls@tls
  // b.o
  .section .tdata,"awT"; .globl tsd_tls; tsd_tls:

  // ld/ld-new a.o b.o
  internal error, aborting at ../../bfd/elf32-ppc.c:7952 in ppc_elf_relocate_section

[2] GCC does not generate R_PPC_GOT_TPREL16_LO relocations

So it is probably unnecessary to teach LLD about _LO _HA. I have an LLVM patch to emit R_PPC_GOT_TPREL16 instead of R_PPC_GOT_TPREL16_LO to circumvent the issue https://reviews.llvm.org/D66925

688cc089-1a96-4cb4-bd77-eaf433fc1da2 commented 5 years ago

I couldn't attach the reproduce tarball, so I posted it to:

https://1drv.ms/u/s!AkaL2-RoR7mimawnUnZ2rVR2u_bSuw?e=uE2fub

688cc089-1a96-4cb4-bd77-eaf433fc1da2 commented 5 years ago

assigned to @MaskRay