Fix the false positive of `SECP_64BIT_ASM_CHECK` #1104

pull SpriteOvO wants to merge 1 commits into bitcoin-core:master from SpriteOvO:risc-v changing 1 files +1 −1
  1. SpriteOvO commented at 10:50 AM on April 15, 2022: contributor

    I'm trying to compile this project for RISC-V architecture, and I encountered errors:

    src/field_5x52_asm_impl.h:28:1: error: unknown register name '%r15' in 'asm'
       28 | __asm__ __volatile__(
          | ^
    src/field_5x52_asm_impl.h:28:1: error: unknown register name '%r14' in 'asm'
    src/field_5x52_asm_impl.h:28:1: error: unknown register name '%r13' in 'asm'
    src/field_5x52_asm_impl.h:28:1: error: unknown register name '%r12' in 'asm'
    src/field_5x52_asm_impl.h:28:1: error: unknown register name '%r11' in 'asm'
    src/field_5x52_asm_impl.h:28:1: error: unknown register name '%r10' in 'asm'
    src/field_5x52_asm_impl.h:28:1: error: unknown register name '%r9' in 'asm'
    src/field_5x52_asm_impl.h:28:1: error: unknown register name '%r8' in 'asm'
    src/field_5x52_asm_impl.h:28:1: error: unknown register name '%rdx' in 'asm'
    src/field_5x52_asm_impl.h:28:1: error: unknown register name '%rcx' in 'asm'
    src/field_5x52_asm_impl.h:28:1: error: unknown register name '%rax' in 'asm'
    src/field_5x52_asm_impl.h:28:1: error: output number 0 not directly addressable
    src/field_5x52_asm_impl.h: In function 'secp256k1_fe_sqr':
    src/field_5x52_asm_impl.h:298:1: error: unknown register name '%r15' in 'asm'
      298 | __asm__ __volatile__(
          | ^
    src/field_5x52_asm_impl.h:298:1: error: unknown register name '%r14' in 'asm'
    src/field_5x52_asm_impl.h:298:1: error: unknown register name '%r13' in 'asm'
    src/field_5x52_asm_impl.h:298:1: error: unknown register name '%r12' in 'asm'
    src/field_5x52_asm_impl.h:298:1: error: unknown register name '%r11' in 'asm'
    src/field_5x52_asm_impl.h:298:1: error: unknown register name '%r10' in 'asm'
    src/field_5x52_asm_impl.h:298:1: error: unknown register name '%r9' in 'asm'
    src/field_5x52_asm_impl.h:298:1: error: unknown register name '%r8' in 'asm'
    src/field_5x52_asm_impl.h:298:1: error: unknown register name '%rdx' in 'asm'
    src/field_5x52_asm_impl.h:298:1: error: unknown register name '%rcx' in 'asm'
    src/field_5x52_asm_impl.h:298:1: error: unknown register name '%rbx' in 'asm'
    src/field_5x52_asm_impl.h:298:1: error: unknown register name '%rax' in 'asm'
    src/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:

    AC_DEFUN([SECP_64BIT_ASM_CHECK],[
    AC_MSG_CHECKING(for x86_64 assembly availability)
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
      #include <stdint.h>]],[[
      __asm__ __volatile__("this is obviously wrong");
      ]])],[has_64bit_asm=yes],[has_64bit_asm=no])
    AC_MSG_RESULT([$has_64bit_asm])
    ])
    

    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.

  2. Fix the false positive of `SECP_64BIT_ASM_CHECK` 7efc9835a9
  3. real-or-random commented at 1:23 PM on April 15, 2022: contributor

    Thanks, I guess we should just use AC_LINK_IFELSE but can you tell me what compiler/toolchain you were using and can you share the configure.log for a failed run? It seems strange to me that this fails only at the linking stage.

  4. SpriteOvO commented at 2:11 PM on April 15, 2022: contributor

    Thanks, I guess we should just use AC_LINK_IFELSE but can you tell me what compiler/toolchain you were using and can you share the configure.log for a failed run? It seems strange to me that this fails only at the linking stage.

    I cloned the build script PKGBUILD from the official ArchLinux, changed the beginning arch=(x86_64) to arch=(riscv64), and ran archbuild (this will enter a clean chroot environment) to compile this project in QEMU.

    I don't see configure.log, but config.log, is it?

    config.log

    and archbuild logs that might help

    libsecp256k1-20220317+1581+ge0508ee-1-riscv64-prepare.log libsecp256k1-20220317+1581+ge0508ee-1-riscv64-build.log

    I agree it's strange, I tried to get the reason from Google and Autoconf's source code, but no luck (I don't know much about m4 language).

  5. real-or-random approved
  6. real-or-random commented at 10:42 PM on April 15, 2022: contributor

    Hm, yeah, so it seems that the risc gcc when invoked normally will error on the x86_64 asm at the compile stage. But for whatever reason, when invoked with -flto (which is done by Arch Linux), it will only error at the link stage... Let's not bother with this and just check linking.

    ACK 7efc9835a977c6400f0f024f19fda47710151dc1

  7. real-or-random merged this on Apr 16, 2022
  8. real-or-random closed this on Apr 16, 2022

  9. laanwj commented at 6:25 PM on April 21, 2022: member

    But for whatever reason, when invoked with -flto

    Correct, assembly is embedded as text in the IR file and only parsed at link time when using flto. That's when the real compilation happens.

  10. fanquake referenced this in commit ef62dad39c on May 30, 2022
  11. fanquake referenced this in commit 910bca8285 on May 30, 2022
  12. fanquake referenced this in commit c41bfd1070 on Jun 11, 2022
  13. patricklodder referenced this in commit 21badcf9d2 on Jul 25, 2022
  14. patricklodder referenced this in commit 03002a9013 on Jul 28, 2022
  15. janus referenced this in commit 8a9469f3f4 on Aug 4, 2022
  16. str4d referenced this in commit ca00f27013 on Apr 21, 2023
  17. vmta referenced this in commit e1120c94a1 on Jun 4, 2023
  18. vmta referenced this in commit 8f03457eed on Jul 1, 2023
  19. delta1 referenced this in commit 3f32c20932 on Aug 8, 2023
  20. delta1 referenced this in commit 31ac0c1081 on Aug 31, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/secp256k1. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-20 06:52 UTC