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:

     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.

  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. SpriteOvO cross-referenced this on Apr 16, 2022 from issue addpkg: libsecp256k1 by SpriteOvO
  10. 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.

  11. fanquake referenced this in commit ef62dad39c on May 30, 2022
  12. fanquake referenced this in commit 910bca8285 on May 30, 2022
  13. fanquake referenced this in commit c41bfd1070 on Jun 11, 2022
  14. patricklodder referenced this in commit 21badcf9d2 on Jul 25, 2022
  15. patricklodder referenced this in commit 03002a9013 on Jul 28, 2022
  16. janus referenced this in commit 8a9469f3f4 on Aug 4, 2022
  17. str4d referenced this in commit ca00f27013 on Apr 21, 2023
  18. real-or-random cross-referenced this on May 11, 2023 from issue build: Rename arm to arm32 and check if it's really supported by hebasto
  19. vmta referenced this in commit e1120c94a1 on Jun 4, 2023
  20. vmta referenced this in commit 8f03457eed on Jul 1, 2023
  21. jonasnick cross-referenced this on Jul 17, 2023 from issue Upstream PRs 1056, 1104, 1105, 1084, 1114, 1115 by jonasnick
  22. jonasnick cross-referenced this on Jul 17, 2023 from issue Upstream PRs 1056, 1104, 1105, 1084, 1114, 1115 by jonasnick
  23. jonasnick cross-referenced this on Jul 17, 2023 from issue Upstream PRs 1056, 1104, 1105, 1084, 1114, 1115, 1116, 1120, 1122, 1121, 1128, 1131, 1144, 1150, 1146 by jonasnick

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: 2024-10-30 01:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me