Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
achow101 opened this issue Apr 3, 2024 · 7 comments
Open
1 task done

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

achow101 opened this issue Apr 3, 2024 · 7 comments

Comments

@achow101
Copy link
Member

achow101 commented Apr 3, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current behaviour

Configure with

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

Compile fails:

crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
   44 |         "shl    $0x6,%2;"
      |         ^
<inline asm>:1:1882: note: instantiated into assembly here
crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
   44 |         "shl    $0x6,%2;"
      |         ^
<inline asm>:1:2591: note: instantiated into assembly here
crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
   44 |         "shl    $0x6,%2;"
      |         ^
<inline asm>:1:3284: note: instantiated into assembly here
crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
   44 |         "shl    $0x6,%2;"
      |         ^
<inline asm>:1:4686: note: instantiated into assembly here
crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
   44 |         "shl    $0x6,%2;"
      |         ^
<inline asm>:1:5395: note: instantiated into assembly here
crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
   44 |         "shl    $0x6,%2;"
      |         ^
<inline asm>:1:6088: note: instantiated into assembly here
crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
   44 |         "shl    $0x6,%2;"
      |         ^
<inline asm>:1:7490: note: instantiated into assembly here
crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
   44 |         "shl    $0x6,%2;"
      |         ^
<inline asm>:1:8199: note: instantiated into assembly here
crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
   44 |         "shl    $0x6,%2;"
      |         ^
<inline asm>:1:8892: note: instantiated into assembly here
crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
   44 |         "shl    $0x6,%2;"
      |         ^
<inline asm>:1:10312: note: instantiated into assembly here
crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
   44 |         "shl    $0x6,%2;"
      |         ^
<inline asm>:1:11021: note: instantiated into assembly here
crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
   44 |         "shl    $0x6,%2;"
      |         ^
<inline asm>:1:11714: note: instantiated into assembly here
crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
   44 |         "shl    $0x6,%2;"
      |         ^
<inline asm>:1:12859: note: instantiated into assembly here
crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
   44 |         "shl    $0x6,%2;"
      |         ^
<inline asm>:1:13356: note: instantiated into assembly here
crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
   44 |         "shl    $0x6,%2;"
      |         ^
<inline asm>:1:13853: note: instantiated into assembly here
crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
   44 |         "shl    $0x6,%2;"
      |         ^
<inline asm>:1:14900: note: instantiated into assembly here
crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
   44 |         "shl    $0x6,%2;"
      |         ^
<inline asm>:1:15397: note: instantiated into assembly here
crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
   44 |         "shl    $0x6,%2;"
      |         ^
<inline asm>:1:15894: note: instantiated into assembly here
18 errors generated.
make[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

@maflcko
Copy link
Member

maflcko commented Apr 3, 2024

Recalling the IRC discussion, I presume this happens since -O0 in #16435 ?

@maflcko
Copy link
Member

maflcko commented Apr 3, 2024

Ref:

1802024-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

@fanquake
Copy link
Member

fanquake commented Apr 3, 2024

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.

@fanquake
Copy link
Member

fanquake commented Apr 3, 2024

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.

@jonatack
Copy link
Contributor

jonatack commented Apr 3, 2024

FWIW, unable to reproduce on arm64 macOS 14.4.1 with Homebrew clang 17.0.6.

@maflcko
Copy link
Member

maflcko commented Apr 3, 2024

It only happens on x86-64, because the asm is in that format.

@theuni
Copy link
Member

theuni commented Apr 3, 2024

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.

@fanquake fanquake changed the title Compilation failure when using --enable-fuzz and --enable-debug due to inline asm Compilation failure with -O0 + -fsanitize=address due to inline asm Apr 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants