Skip to content

clang: "expected relocatable expression" when compiling large inline asm with -O0 and address sanitizer #92182

@theuni

Description

@theuni

As in title: Bitcoin Core's sha256 Transform function in hand-written sse4 asm (implementing the algorithm from Intel's whitepaper) is unable to compile with optimizations disabled and address sanitizer enabled: sha256_sse4.cpp. The file is standalone and requires no other files.

Compile with: clang++ -std=c++20 -fPIC -O0 -fsanitize=address -c crypto/sha256_sse4.cpp -o out.o

crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
"shl $0x6,%2;"
^
:1:1882: note: instantiated into assembly here
crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
"shl $0x6,%2;"
^
:1:2580: note: instantiated into assembly here
crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
"shl $0x6,%2;"
^
<snip>

It's no problem with optimizations at >= -O1 or with asan off. gcc is able to compile it fine with the same options.

We intend to work around it by disabling asan for clang with no optimizations: bitcoin/bitcoin#30097

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions