[PATCH] D70401: [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs

David Sawatzke via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 9 12:23:57 PDT 2023


david-sawatzke added a comment.

Hey I've tried using this patch (roughly following https://noxim.xyz/blog/rust-ch32v003/).

It uses the older version of this patch for the rust llvm version (here the llvm tree https://github.com/Noxime/llvm-project/tree/rv32e) and I use rust commit 0939ec13 (together with the small patch for the RVE).

I've experience some issues that results in corruption of $sp, the following is the smallest reproduction (hopefully small enough):
Code:

  rust
  #![no_std]
  
  pub fn test()  {
  }

which, with the following .ll for release builds:

  source_filename = "miscomp_repro.8b6a426d3b54bd13-cgu.0"
  target datalayout = "e-m:e-p:32:32-i64:64-n32-S128"
  target triple = "riscv32"
  
  define dso_local void @_ZN13miscomp_repro4test17h065760f827b95d43E() unnamed_addr #0 {
  start:
    ret void
  }
  
  attributes #0 = { mustprogress nofree norecurse nosync nounwind readnone willreturn "target-cpu"="generic-rv32" "target-features"="+e,+c" }

results in this assembly:

  	.text
  	.attribute	4, 4
  	.attribute	5, "rv32e1p9_c2p0"
  	.file	"miscomp_repro.8b6a426d3b54bd13-cgu.0"
  	.section	.text._ZN13miscomp_repro4test17h065760f827b95d43E,"ax", at progbits
  	.globl	_ZN13miscomp_repro4test17h065760f827b95d43E
  	.p2align	1
  	.type	_ZN13miscomp_repro4test17h065760f827b95d43E, at function
  _ZN13miscomp_repro4test17h065760f827b95d43E:
  	mv	sp, s0
  	ret
  .Lfunc_end0:
  	.size	_ZN13miscomp_repro4test17h065760f827b95d43E, .Lfunc_end0-_ZN13miscomp_repro4test17h065760f827b95d43E
  
  	.section	".note.GNU-stack","", at progbits

Since s0 isn't required to have any specific contents (and in the larger project this was extracted from doesn't), this corrupts the stack pointer. Large functions using the stack first save sp to  0, so not all functions have this issue. This also happens (but more verbose) in debug builds, but works fine with the exact same toolchain using the riscv32i target.

Here is the repro with some further output, I hope this patch and not something else is to blame (if so, sorry in advance).

F27877626: miscomp_repro.zip <https://reviews.llvm.org/F27877626>


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70401



More information about the cfe-commits mailing list