[PATCH] D109090: [PPC64] fix/workaround runtime crash on FreeBSD with llvm12 and later

Alfredo Dal'Ava JĂșnior via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 9 14:16:04 PDT 2021


adalava added a comment.

In D109090#2978298 <https://reviews.llvm.org/D109090#2978298>, @arichardson wrote:

> This does not seem like the right approach to me. Have you looked into why the pointer is not correct. Does it affect static binaries or dynamic ones? Maybe this can be fixed in rtld instead? As it works for all other architectures (and PPC Linux), I feel like that is the more likely cause

Agreed, it looks like "GV->setDSOLocal(true)" is only exposing the problem. I confirmed it affects only dynamic binaries, static ones are fine. On clang11 it points to something like 0x81030fad8, and on clang12 0xffffffffffff8ee8. I noticed PPC64LE Linux binaries are using a different approach since "__stack_chk_guard" isn't defined on glibc, according to https://reviews.llvm.org/D17740. I used the patch bellow to force the Linux approach and it builds sane binaries but it's not correct since FreeBSD has "__stack_chk_guard" defined on libc.

  diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  index 7be3115bb7db..cb88af4c0821 100644
  --- a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  +++ b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  @@ -16633,8 +16633,8 @@ SDValue PPCTargetLowering::getNegatedExpression(SDValue Op, SelectionDAG &DAG,
  
   // Override to enable LOAD_STACK_GUARD lowering on Linux.
   bool PPCTargetLowering::useLoadStackGuardNode() const {
  -  if (!Subtarget.isTargetLinux())
  -    return TargetLowering::useLoadStackGuardNode();
  +  //if (!Subtarget.isTargetLinux())
  +  //  return TargetLowering::useLoadStackGuardNode();
     return true;
   }
  
  diff --git a/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp b/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
  index c74b6bcf4287..d92ea1053201 100644
  --- a/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
  +++ b/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
  @@ -3022,8 +3022,8 @@ bool PPCInstrInfo::expandPostRAPseudo(MachineInstr &MI) const {
       return true;
     }
     case TargetOpcode::LOAD_STACK_GUARD: {
  -    assert(Subtarget.isTargetLinux() &&
  -           "Only Linux target is expected to contain LOAD_STACK_GUARD");
  +    //assert(Subtarget.isTargetLinux() &&
  +    //       "Only Linux target is expected to contain LOAD_STACK_GUARD");
       const int64_t Offset = Subtarget.isPPC64() ? -0x7010 : -0x7008;
       const unsigned Reg = Subtarget.isPPC64() ? PPC::X13 : PPC::R2;
       MI.setDesc(get(Subtarget.isPPC64() ? PPC::LD : PPC::LWZ));


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109090



More information about the llvm-commits mailing list