riscv icon indicating copy to clipboard operation
riscv copied to clipboard

__udivdi3 / __udivmoddi4 infinite recursion

Open timnewsham opened this issue 1 year ago • 0 comments

I noticed crashes using "%d" formatting, ie this seg faults with qemu-riscv64:

#include <stdio.h>

int
main(int argc, char **argv) {
	printf("%d\n", 1);
	return 0;
}

In gdb I see infinite recursion between __udivdi3 and __udivmoddi4:

Program received signal SIGSEGV, Segmentation fault.
0x0000000000015674 in __udivdi3 (a=0, b=1) at riscv/compiler-rt/lib/builtins/udivdi3.c:17
17	COMPILER_RT_ABI du_int __udivdi3(du_int a, du_int b) {
(gdb) up
#1  0x0000000000015744 in __udivmoddi4 (a=1, b=10, rem=0x0) at riscv/compiler-rt/lib/builtins/udivmoddi4.c:45
45	      return n.s.low / d.s.low;
(gdb) 
#2  0x000000000001569c in __udivdi3 (a=1, b=10) at riscv/compiler-rt/lib/builtins/udivdi3.c:18
18	  return __udivmoddi4(a, b, 0);
(gdb) 
#3  0x0000000000015744 in __udivmoddi4 (a=1, b=10, rem=0x0) at riscv/compiler-rt/lib/builtins/udivmoddi4.c:45
45	      return n.s.low / d.s.low;

I'm building with clang-11 and clang-14 (same behavior for both). I havent been able to test with CLANG_VERSION = 10 that your Makefiles call for.

Is this caused by the compiler generating different math calls than musl expects?

timnewsham avatar Dec 08 '24 04:12 timnewsham