Compilation failure with -O0 + -fsanitize=address due to inline asm #29801

issue achow101 openend this issue on April 3, 2024
  1. achow101 commented at 3:49 pm on April 3, 2024: member

    Is there an existing issue for this?

    • I have searched the existing issues

    Current behaviour

    Configure with

    0./configure --enable-fuzz --enable-debug --with-sanitizers=address,fuzzer,undefined,integer CC=clang CXX=clang++
    

    Compile fails:

     0crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
     1   44 |         "shl    $0x6,%2;"
     2      |         ^
     3<inline asm>:1:1882: note: instantiated into assembly here
     4crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
     5   44 |         "shl    $0x6,%2;"
     6      |         ^
     7<inline asm>:1:2591: note: instantiated into assembly here
     8crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
     9   44 |         "shl    $0x6,%2;"
    10      |         ^
    11<inline asm>:1:3284: note: instantiated into assembly here
    12crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
    13   44 |         "shl    $0x6,%2;"
    14      |         ^
    15<inline asm>:1:4686: note: instantiated into assembly here
    16crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
    17   44 |         "shl    $0x6,%2;"
    18      |         ^
    19<inline asm>:1:5395: note: instantiated into assembly here
    20crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
    21   44 |         "shl    $0x6,%2;"
    22      |         ^
    23<inline asm>:1:6088: note: instantiated into assembly here
    24crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
    25   44 |         "shl    $0x6,%2;"
    26      |         ^
    27<inline asm>:1:7490: note: instantiated into assembly here
    28crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
    29   44 |         "shl    $0x6,%2;"
    30      |         ^
    31<inline asm>:1:8199: note: instantiated into assembly here
    32crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
    33   44 |         "shl    $0x6,%2;"
    34      |         ^
    35<inline asm>:1:8892: note: instantiated into assembly here
    36crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
    37   44 |         "shl    $0x6,%2;"
    38      |         ^
    39<inline asm>:1:10312: note: instantiated into assembly here
    40crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
    41   44 |         "shl    $0x6,%2;"
    42      |         ^
    43<inline asm>:1:11021: note: instantiated into assembly here
    44crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
    45   44 |         "shl    $0x6,%2;"
    46      |         ^
    47<inline asm>:1:11714: note: instantiated into assembly here
    48crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
    49   44 |         "shl    $0x6,%2;"
    50      |         ^
    51<inline asm>:1:12859: note: instantiated into assembly here
    52crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
    53   44 |         "shl    $0x6,%2;"
    54      |         ^
    55<inline asm>:1:13356: note: instantiated into assembly here
    56crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
    57   44 |         "shl    $0x6,%2;"
    58      |         ^
    59<inline asm>:1:13853: note: instantiated into assembly here
    60crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
    61   44 |         "shl    $0x6,%2;"
    62      |         ^
    63<inline asm>:1:14900: note: instantiated into assembly here
    64crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
    65   44 |         "shl    $0x6,%2;"
    66      |         ^
    67<inline asm>:1:15397: note: instantiated into assembly here
    68crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
    69   44 |         "shl    $0x6,%2;"
    70      |         ^
    71<inline asm>:1:15894: note: instantiated into assembly here
    7218 errors generated.
    73make[2]: *** [Makefile:14531: crypto/libbitcoin_crypto_base_la-sha256_sse4.lo] Error 1
    

    Expected behaviour

    It should successfully compile with the debug symbols so that fuzz crashes can be debugged.

    Previously, it was possible to work around this issue by using --disable-asm however that was removed in #29407

    Steps to reproduce

    See above configure .

    --enable-debug and --enable-fuzz individually do not result in compilation failure. I am only seeing this when using them together.

    Relevant log output

    config.log

    How did you obtain Bitcoin Core

    Compiled from source

    What version of Bitcoin Core are you using?

    master@0d509bab45d292caeaf34600e57b5928757c6005

    Operating system and version

    Arch w/ linux kernel 6.8.2

    Machine specifications

    No response

  2. maflcko commented at 3:56 pm on April 3, 2024: member
    Recalling the IRC discussion, I presume this happens since -O0 in #16435 ?
  3. maflcko added the label Build system on Apr 3, 2024
  4. maflcko added the label Tests on Apr 3, 2024
  5. maflcko commented at 4:00 pm on April 3, 2024: member

    Ref:

    01802024-04-01T18:09:22  <cfields> clang++ -std=c++20 -O0 -fsanitize=address -c crypto/sha256_sse4.cpp -o out.o
    

    https://www.erisian.com.au/bitcoin-core-dev/log-2024-04-02.html

  6. fanquake commented at 4:00 pm on April 3, 2024: member
    The broken combination is clang++ -std=c++20 -O0 -fsanitize=address -c crypto/sha256_sse4.cpp -o out.o, pointed out by Cory. Happens for me with Clang-18.
  7. fanquake removed the label Build system on Apr 3, 2024
  8. fanquake added the label Upstream on Apr 3, 2024
  9. fanquake commented at 4:03 pm on April 3, 2024: member
    I guess the next step is to followup / file an issue with LLVM. I’ve got #29796 open which may “fix” this by just dropping -O0, depending on the outcome of discussion.
  10. jonatack commented at 5:28 pm on April 3, 2024: contributor
    FWIW, unable to reproduce on arm64 macOS 14.4.1 with Homebrew clang 17.0.6.
  11. maflcko commented at 6:02 pm on April 3, 2024: member
    It only happens on x86-64, because the asm is in that format.
  12. theuni commented at 8:05 pm on April 3, 2024: member
    In addition to the discussion in #29781, I’ll PR a change to make this work with DISABLE_OPTIMIZED_SHA256 as a fallback. I’m doing that as part of a larger refactor of the crypto defines, though.
  13. fanquake renamed this:
    Compilation failure when using `--enable-fuzz` and `--enable-debug` due to inline asm
    Compilation failure with `-O0` + `-fsanitize=address` due to inline asm
    on Apr 6, 2024
  14. ajtowns commented at 8:56 am on May 13, 2024: contributor

    How about adding something like:

     0--- a/configure.ac
     1+++ b/configure.ac
     2@@ -349,7 +349,14 @@ esac
     3 if test "$enable_debug" = "yes"; then
     4 
     5   dnl Disable all optimizations
     6-  AX_CHECK_COMPILE_FLAG([-O0], [DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -O0"], [], [$CXXFLAG_WERROR])
     7+  case "$use_sanitizers" in
     8+    *address*)
     9+      AX_CHECK_COMPILE_FLAG([-Og], [DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -Og"], [], [$CXXFLAG_WERROR])
    10+      ;;
    11+    *)
    12+      AX_CHECK_COMPILE_FLAG([-O0], [DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -O0"], [], [$CXXFLAG_WERROR])
    13+      ;;
    14+  esac
    

    in the meantime?

  15. theuni commented at 6:17 pm on May 13, 2024: member
    @ajtowns Thanks for the reminder here. See #30097 for a function-level application (kinda :) of the above.
  16. fanquake closed this on May 16, 2024

  17. fanquake referenced this in commit ae2658caac on May 16, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-22 06:12 UTC

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