I’m trying to compile this project for RISC-V architecture, and I encountered errors:
0src/field_5x52_asm_impl.h:28:1: error: unknown register name '%r15' in 'asm'
1 28 | __asm__ __volatile__(
2 | ^
3src/field_5x52_asm_impl.h:28:1: error: unknown register name '%r14' in 'asm'
4src/field_5x52_asm_impl.h:28:1: error: unknown register name '%r13' in 'asm'
5src/field_5x52_asm_impl.h:28:1: error: unknown register name '%r12' in 'asm'
6src/field_5x52_asm_impl.h:28:1: error: unknown register name '%r11' in 'asm'
7src/field_5x52_asm_impl.h:28:1: error: unknown register name '%r10' in 'asm'
8src/field_5x52_asm_impl.h:28:1: error: unknown register name '%r9' in 'asm'
9src/field_5x52_asm_impl.h:28:1: error: unknown register name '%r8' in 'asm'
10src/field_5x52_asm_impl.h:28:1: error: unknown register name '%rdx' in 'asm'
11src/field_5x52_asm_impl.h:28:1: error: unknown register name '%rcx' in 'asm'
12src/field_5x52_asm_impl.h:28:1: error: unknown register name '%rax' in 'asm'
13src/field_5x52_asm_impl.h:28:1: error: output number 0 not directly addressable
14src/field_5x52_asm_impl.h: In function 'secp256k1_fe_sqr':
15src/field_5x52_asm_impl.h:298:1: error: unknown register name '%r15' in 'asm'
16 298 | __asm__ __volatile__(
17 | ^
18src/field_5x52_asm_impl.h:298:1: error: unknown register name '%r14' in 'asm'
19src/field_5x52_asm_impl.h:298:1: error: unknown register name '%r13' in 'asm'
20src/field_5x52_asm_impl.h:298:1: error: unknown register name '%r12' in 'asm'
21src/field_5x52_asm_impl.h:298:1: error: unknown register name '%r11' in 'asm'
22src/field_5x52_asm_impl.h:298:1: error: unknown register name '%r10' in 'asm'
23src/field_5x52_asm_impl.h:298:1: error: unknown register name '%r9' in 'asm'
24src/field_5x52_asm_impl.h:298:1: error: unknown register name '%r8' in 'asm'
25src/field_5x52_asm_impl.h:298:1: error: unknown register name '%rdx' in 'asm'
26src/field_5x52_asm_impl.h:298:1: error: unknown register name '%rcx' in 'asm'
27src/field_5x52_asm_impl.h:298:1: error: unknown register name '%rbx' in 'asm'
28src/field_5x52_asm_impl.h:298:1: error: unknown register name '%rax' in 'asm'
29src/field_5x52_asm_impl.h:298:1: error: output number 0 not directly addressable
After further investigation I found that for RISC-V, macro USE_ASM_X86_64
was defined unexpectedly, and checking for x86_64 assembly availability... yes
appeared in the compilation log file, which means SECP_64BIT_ASM_CHECK
was not working as expected.
For unknown reasons, AC_COMPILE_IFELSE
does not check if __asm__
can be compiled, and an example can verify this point:
0AC_DEFUN([SECP_64BIT_ASM_CHECK],[
1AC_MSG_CHECKING(for x86_64 assembly availability)
2AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3 #include <stdint.h>]],[[
4 __asm__ __volatile__("this is obviously wrong");
5 ]])],[has_64bit_asm=yes],[has_64bit_asm=no])
6AC_MSG_RESULT([$has_64bit_asm])
7])
It always gives results: checking for x86_64 assembly availability... yes
After testing, replacing AC_COMPILE_IFELSE
with AC_LINK_IFELSE
can correctly check if __asm__
can be compiled and make the project able to compile for RISC-V.