> Wiadomość napisana przez Krystian Lewandowski <k.lewandow...@me.com> w dniu 
> 05.07.2019, o godz. 22:46:
> 
> Based on information from Dimitry Andric: 
> https://bugs.llvm.org/show_bug.cgi?id=42478
> - it does happen only for -triple aarch64-unknown-openbsd
> - with -stack-protector 2
> I tried to find a reason for this behaviour.  Please note I have no knowledge
> about LLVM internals, dont trust me, double check.
> 
> I'll point to OpenBSD (master branch) github links, I hope its fine with you.
> 
> 1.  So the crash is caused directly by:
> https://github.com/openbsd/src/blob/master/gnu/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp#L1500
> where getValue() is called on NULL pointer.
> 
> 2.  I think it is caused by Global being NULL here:
> https://github.com/openbsd/src/blob/master/gnu/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp#L766
> It should be returned from provided module as __stack_chk_guard function.
> https://github.com/openbsd/src/blob/master/gnu/llvm/lib/CodeGen/TargetLoweringBase.cpp#L1658
> 
> 3.  This "__stack_chk_guard" function should be registered here:
> https://github.com/openbsd/src/blob/master/gnu/llvm/lib/CodeGen/StackProtector.cpp#L341
>  by
> insertSSPDeclarations() call but this piece of code is never executed because
> getStackGuard() returns earlier - getIRStackGuard() returns non-NULL value:
> https://github.com/openbsd/src/blob/master/gnu/llvm/lib/CodeGen/TargetLoweringBase.cpp#L1635
> 
> Im not sure which one is valid:
> a.  with TargetLoweringBase::getIRStackGuard() returning non-NULL value,
> TargetLoweringBase::getSDagStackGuard() should never be called by
> IRTranslator::getStackGuard() and this flow should be handled in a different 
> manner
> b.  or insertSSPDeclarations() should be called in 
> StackProtector::getStackGuard()
> in both cases
> 
> I was able to get rid of crash by the diff below (b. case).
> 
> -- 
> Krystian
> 
> Index: StackProtector.cpp
> ===================================================================
> RCS file: /cvs/src/gnu/llvm/lib/CodeGen/StackProtector.cpp,v
> retrieving revision 1.8
> diff -u -p -r1.8 StackProtector.cpp
> --- StackProtector.cpp        23 Jun 2019 22:05:12 -0000      1.8
> +++ StackProtector.cpp        5 Jul 2019 20:41:17 -0000
> @@ -322,8 +322,10 @@ bool StackProtector::RequiresStackProtec
> static Value *getStackGuard(const TargetLoweringBase *TLI, Module *M,
>                             IRBuilder<> &B,
>                             bool *SupportsSelectionDAGSP = nullptr) {
> -  if (Value *Guard = TLI->getIRStackGuard(B))
> +  if (Value *Guard = TLI->getIRStackGuard(B)) {
> +    TLI->insertSSPDeclarations(*M);
>     return B.CreateLoad(Guard, true, "StackGuard");
> +  }
> 
>   // Use SelectionDAG SSP handling, since there isn't an IR guard.
>   //

Adding Jeremie to the thread, because he is working on devel/llvm 8.0.0.

-- 
Krystian

Reply via email to