Skip to content

Apply fixes for coreclr-interp on linux-riscv64#127919

Open
am11 wants to merge 4 commits intodotnet:mainfrom
am11:patch-53
Open

Apply fixes for coreclr-interp on linux-riscv64#127919
am11 wants to merge 4 commits intodotnet:mainfrom
am11:patch-53

Conversation

@am11
Copy link
Copy Markdown
Member

@am11 am11 commented May 7, 2026

First time we ran the tests (with #127909) and found issues with interpreter tests.

  1. clang-21 defaults to rvv baseline, previously clang-18 was defaulting to rv64gc; so we need to pin to our baseline for runtime binaries. This program helped figuring out SIGILL:
$ cat riscv_default_probe.c 
#if defined(__riscv_v)
#error At RVV (__riscv_v)
#elif defined(__riscv_b)
#error At Bitmanip (__riscv_b)
#elif defined(__riscv_zfa)
#error At Zfa
#elif defined(__riscv_zfh)
#error At Zfh
#elif defined(__riscv_d)
#error At D
#elif defined(__riscv_f)
#error At F
#elif defined(__riscv_c)
#error At C
#elif defined(__riscv_m)
#error At M
#elif defined(__riscv_a)
#error At A
#elif defined(__riscv_i)
#error At I
#else
#error At unknown baseline
#endif

$ clang-21 --target=riscv64-unknown-linux-gnu -c riscv_default_probe.c
riscv_default_probe.c:2:2: error: At RVV (__riscv_v)
    2 | #error At RVV (__riscv_v)
      |  ^

# vs.

$ clang-18 --target=riscv64-unknown-linux-gnu -c riscv_default_probe.c
riscv_default_probe.c:10:2: error: At D
   10 | #error At D
      |  ^
  1. Remove negative sign from prolog offset; it was growing in opposite direction.
  2. Remove an invalid assert in the RISC-V/LoongArch return classification path. After fixing offset issue, tests progressed to TestCallingConvention2Rev and then tripped a debug-only check that is AMD64-specific and not applicable on these targets. Return classification here is already handled by FP-struct info plus size-based integer mapping, so removing the assert preserves intended behavior and unblocks the interpreter calling-convention tests.

Fixes #127860

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label May 7, 2026
@am11
Copy link
Copy Markdown
Member Author

am11 commented May 7, 2026

cc @clamp03, interp tests are now passing:

am11@k1:~$ CORE_ROOT=$(pwd)/artifacts/tests/coreclr/linux.riscv64.Debug/Tests/Core_Root DOTNET_TieredCompilation=0 artifacts/tests/coreclr/linux.riscv64.Debug/JIT/Interpreter/InterpreterTester/InterpreterTester.sh
BEGIN EXECUTION
/home/am11/artifacts/tests/coreclr/linux.riscv64.Debug/Tests/Core_Root/corerun -p System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization=true InterpreterTester.dll ''
TestCallingConvention0: a = 1, b = 2, c = 3, d = 4, e = 5, f = 6
TestCallingConvention1: a = 1, b = 2, c = 3, d = 4, e = 5, f = 6
TestCallingConvention9: a = 1, b = 2, c = 3, d = 4
TestCallingConvention10: a = 1, b = 2, c = 3
TestCallingConvention11: s = 
1
2
3
TestCallingConvention12: a = 1, b = 2, c = 3, d = 4, e = 5, f = 6, g = 7, h = 8, i = 9, j = a, k = 10, l = 11, m = 12
TestCallingConvention13: a = 1, b = 2, c = 3, d = 4, e = 5, f = 6, g = 7, h = 8, s = (9, 10, 11, 12)
TestCallingConvention0Rev: a = 1, b = 2, c = 3, d = 4, e = 5, f = 6
TestCallingConvention1Rev: a = 1, b = 2, c = 3, d = 4, e = 5, f = 6
TestCallingConvention2Rev: s = 1, 2
TestCallingConvention3Rev: v = 1, 2
TestCallingConvention4Rev: s = 1, 2, 3, 4, 5, 6
TestCallingConvention5Rev: s = 1, 2, 3, 4
TestCallingConvention6Rev: s = 1, 2, 3, 4
TestCallingConvention7Rev: s = 1, 2, 3, 4
TestCallingConvention8Rev: s = 1, 2, 3, 4
TestCallingConvention9Rev: a = 1, b = 2, c = 3, d = 4
TestCallingConvention10Rev: a = 1, b = 2, c = 3
TestCallingConvention11Rev: s = 1, 2, 3
TestCallingConvention12Rev: a = 1, b = 2, c = 3, d = 4, e = 5, f = 6, g = 7, h = 8, i = 9, j = a, k = 10, l = 11, m = 12
TestCallingConvention13Rev: a = 1, b = 2, c = 3, d = 4, e = 5, f = 6, g = 7, h = 8, s = (9, 10, 11, 12)
TestCallingConvention0: a = 1, b = 2, c = 3, d = 4, e = 5, f = 6
TestCallingConvention1: a = 1, b = 2, c = 3, d = 4, e = 5, f = 6
TestCallingConvention: s = 
1
2
TestCallingConvention: s = 
1
2
3
4
5
6
TestCallingConvention: s = 
1
2
3
4
TestCallingConvention: s = 
1
2
3
4
TestCallingConvention: s = 
1
2
3
4
TestCallingConvention: s = 
1
2
3
4
TestCallingConvention9: a = 1, b = 2, c = 3, d = 4
TestCallingConvention10: a = 1, b = 2, c = 3
TestCallingConvention: s = 
1
2
3
TestCallingConvention12: a = 1, b = 2, c = 3, d = 4, e = 5, f = 6, g = 7, h = 8, i = 9, j = a, k = 10, l = 11, m = 12
TestCallingConvention13: a = 1, b = 2, c = 3, d = 4, e = 5, f = 6, g = 7, h = 8, s = (9, 10, 11, 12)
Sum
Mul4
TestSwitch
PowLoop
TestJitFields
TestFields
TestStructRefFields
TestSpecialFields
TestFloat
TestConvOvf
TestConvOvfUn
TestConvBoundaries
TestLocalloc
TestVirtual
bc.NonVirtualMethod
bc.VirtualMethod
bc.GenericVirtualMethod
bc.GenericVirtualMethod<int>
bc.GenericVirtualMethod<string>
itest.VirtualMethod
itest.GenericVirtualMethod<int>
itest.GenericVirtualMethod<string>
bc.NonVirtualMethod
bc.VirtualMethod
bc.GenericVirtualMethod<int>
bc.GenericVirtualMethod<string>
itest.VirtualMethod
itest.GenericVirtualMethod<int>
itest.GenericVirtualMethod<string>
TestBoxing
TestArray
TestXxObj
TestSizeof
TestLdtoken
TestMdArray
TestExceptionHandling
1
2
3
Object reference not set to an instance of an object.
4
6
7
TestStringCtor
TestSharedGenerics
Test calls to shared generics from non-generic code
Test calls to shared generics from generic code (unshared generics)
Test calls to shared generics from generic code (shared generics)
Test isinst with shared generics (string)
Test castclass with shared generics (string)
Expected InvalidCastException from casting object to string[]
Test unbox.any with shared generics
Expected InvalidCastException from casting object to string
Test box with shared generics
Test classic unbox instruction with shared generics
Test newarr
Test new MD arr
TestDelegate
CallingFunc first time
Return CallingFunc first time
CallingFunc second time
Return CallingFunc second time
TestIntrinsics
Vector128.IsHardwareAccelerated=
False
X86Base.IsSupported=
False
ArmBase.IsSupported=
False
TestCalli
CallingFunc first time
Return CallingFunc first time
CallingFunc second time
Return CallingFunc second time
TestStaticVirtualGeneric_CodePointerCase
TestPreciseInitCctors
TestThreading_Interlocked_CompareExchange
TestRuntimeHelpers_IsReferenceOrContainsReferences
TestMemoryMarshal_GetArrayDataReference
Empty string length: 0
BitConverter.IsLittleEndian: True
IntPtr.Zero: 0, UIntPtr.Zero: 0
TestPInvoke
Hello world from pinvoke.dll!writeToStdout

calling missingPInvoke
caught #1
calling missingPInvokeWithMarshaling
caught #2
All tests passed successfully!
Interpreted App returned 100
Expected: 100
Actual: 100
END EXECUTION - PASSED

@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @BrzVlad, @janvorli, @kg
See info in area-owners.md if you want to be subscribed.

@jkotas jkotas added the arch-riscv Related to the RISC-V architecture label May 7, 2026
@jkotas
Copy link
Copy Markdown
Member

jkotas commented May 7, 2026

we need to pin to our baseline for runtime binaries

I am not following why we need to do that. What are the problems solved by this pinning?

@am11
Copy link
Copy Markdown
Member Author

am11 commented May 7, 2026

What are the problems solved by this pinning?

It crashes with SIGILL on old devices without vector ISA support.

@am11
Copy link
Copy Markdown
Member Author

am11 commented May 7, 2026

Also, it matches:

if (syscall(__NR_riscv_hwprobe, pairs, 1, 0, NULL, 0) == 0)
{
// Our baseline support is for RV64GC (see #73437)
assert(pairs[0].value & RISCV_HWPROBE_IMA_FD);
assert(pairs[0].value & RISCV_HWPROBE_IMA_C);

@jkotas
Copy link
Copy Markdown
Member

jkotas commented May 7, 2026

It crashes with SIGILL on old devices without vector ISA support.

Is there a clang PR that changed the default? I would be curious about their justification for ignoring these old devices by default. C/C++ compilers have typically lower default baselines than we do. It is surprising that it is opposite here.

@am11
Copy link
Copy Markdown
Member Author

am11 commented May 7, 2026

llvm hasn't changed their defaults since 2019 llvm/llvm-project@e3d5ff5 (same as current main: https://github.com/llvm/llvm-project/blob/b3c15dbae051e29cfbd8b4110ac190528fb563a7/clang/lib/Driver/ToolChains/Arch/RISCV.cpp#L344; that is rv64gc baseline to run Linux based OS)

However, Ubuntu has changed their default to require vector extension https://canonical.com/blog/canonical-and-ubuntu-risc-v-a-2025-retro-and-looking-forward-to-2026. I was cross-building on Ubuntu 26.04 and clang21 from its packages, therefore, it has the altered defaults.

If I install it with official script: curl -sSL https://apt.llvm.org/llvm.sh | bash -s - 21 all, then it defaults to rv64gc.

root@a8238645b83c:/runtime# curl -sSL https://apt.llvm.org/llvm.sh | bash -s - 21 all
root@a8238645b83c:/runtime# clang-21 --target=riscv64-unknown-linux-gnu -c riscv_default_probe.c
riscv_default_probe.c:10:2: error: At D
   10 | #error At D
      |  ^
1 error generated.

This shows the case that distro altered the baseline while linux kernel, toolchains (llvm and gcc) and other distros all are sticking to the rv64gc baseline. This PR makes it explicit. IMO, it's fine, given this file has:

eng/native/configurecompiler.cmake:858:   add_compile_options(-march=armv7-a)
eng/native/configurecompiler.cmake:868:   add_compile_options(-march=armv6zk)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-riscv Related to the RISC-V architecture area-CodeGen-Interpreter-coreclr community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RISC-V] Interpreter Test Fails

2 participants