[llvm] r370426 - [PPC32] Emit R_PPC_GOT_TPREL16 instead R_PPC_GOT_TPREL16_LO

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 5 04:42:09 PDT 2019


Merged to release_90 in r371059.

On Fri, Aug 30, 2019 at 4:19 AM Fangrui Song via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
>
> Author: maskray
> Date: Thu Aug 29 19:20:49 2019
> New Revision: 370426
>
> URL: http://llvm.org/viewvc/llvm-project?rev=370426&view=rev
> Log:
> [PPC32] Emit R_PPC_GOT_TPREL16 instead R_PPC_GOT_TPREL16_LO
>
> Unlike ppc64, which has ADDISgotTprelHA+LDgotTprelL pairs,
> ppc32 just uses LDgotTprelL32, so it does not make lots of sense to use
> _LO without a paired _HA.
>
> Emit R_PPC_GOT_TPREL16 instead R_PPC_GOT_TPREL16_LO to match GCC, and
> get better linker relocation check. Note, R_PPC_GOT_TPREL16_{HA,LO}
> don't have good linker support:
>
> (a) lld does not support R_PPC_GOT_TPREL16_{HA,LO}.
> (b) Top of tree ld.bfd does not support R_PPC_GOT_REL16_HA Initial-Exec -> Local-Exec relaxation:
>
>   // a.o
>   addis 3, 3, tsd_tls at got@tprel at ha
>   lwz 3, tsd_tls at got@tprel at l(3)
>   add 3, 3, tsd_tls at 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
>
> Reviewed By: adalava
>
> Differential Revision: https://reviews.llvm.org/D66925
>
> Modified:
>     llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp
>     llvm/trunk/test/CodeGen/PowerPC/tls.ll
>
> Modified: llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp?rev=370426&r1=370425&r2=370426&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp (original)
> +++ llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp Thu Aug 29 19:20:49 2019
> @@ -870,8 +870,10 @@ void PPCAsmPrinter::EmitInstruction(cons
>      const GlobalValue *GValue = MO.getGlobal();
>      MCSymbol *MOSymbol = getSymbol(GValue);
>      const MCExpr *Exp =
> -      MCSymbolRefExpr::create(MOSymbol, MCSymbolRefExpr::VK_PPC_GOT_TPREL_LO,
> -                              OutContext);
> +        MCSymbolRefExpr::create(MOSymbol,
> +                                isPPC64 ? MCSymbolRefExpr::VK_PPC_GOT_TPREL_LO
> +                                        : MCSymbolRefExpr::VK_PPC_GOT_TPREL,
> +                                OutContext);
>      TmpInst.getOperand(1) = MCOperand::createExpr(Exp);
>      EmitToStreamer(*OutStreamer, TmpInst);
>      return;
>
> Modified: llvm/trunk/test/CodeGen/PowerPC/tls.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/PowerPC/tls.ll?rev=370426&r1=370425&r2=370426&view=diff
> ==============================================================================
> --- llvm/trunk/test/CodeGen/PowerPC/tls.ll (original)
> +++ llvm/trunk/test/CodeGen/PowerPC/tls.ll Thu Aug 29 19:20:49 2019
> @@ -43,7 +43,7 @@ entry:
>  ;OPT0-PPC32-LABEL:    main2:
>  ;OPT0-PPC32:       li [[REG1:[0-9]+]], _GLOBAL_OFFSET_TABLE_ at l
>  ;OPT0-PPC32:       addis [[REG1]], [[REG1]], _GLOBAL_OFFSET_TABLE_ at ha
> -;OPT0-PPC32:       lwz [[REG2:[0-9]+]], a2 at got@tprel at l([[REG1]])
> +;OPT0-PPC32:       lwz [[REG2:[0-9]+]], a2 at got@tprel([[REG1]])
>  ;OPT0-PPC32:       add 3, [[REG2]], a2 at tls
>
>  ;OPT0-PPC32-PIC-LABEL:  main2:
> @@ -51,4 +51,4 @@ entry:
>  ;OPT0-PPC32-PIC-NOT:    li {{[0-9]+}}, _GLOBAL_OFFSET_TABLE_ at l
>  ;OPT0-PPC32-PIC-NOT:    addis {{[0-9]+}}, {{[0-9+]}}, _GLOBAL_OFFSET_TABLE_ at ha
>  ;OPT0-PPC32-PIC-NOT:    bl __tls_get_addr(a2 at tlsgd)@PLT
> -;OPT0-PPC32-PIC:        lwz {{[0-9]+}}, a2 at got@tprel at l({{[0-9]+}})
> +;OPT0-PPC32-PIC:        lwz {{[0-9]+}}, a2 at got@tprel({{[0-9]+}})
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list