<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/92182>92182</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang: "expected relocatable expression" when compiling large inline asm with -O0 and address sanitizer
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
theuni
</td>
</tr>
</table>
<pre>
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](https://github.com/bitcoin/bitcoin/blob/master/src/crypto/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;"
> ^
> <inline asm>:1:1882: note: instantiated into assembly here
> crypto/sha256_sse4.cpp:44:9: error: expected relocatable expression
> "shl $0x6,%2;"
> ^
> <inline asm>: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: https://github.com/bitcoin/bitcoin/pull/30097
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVU1v4zYQ_TXjy8CGNJRk66CDP2Igp-1hgR4LShpZbClSJak62V9fkE4QZ5FtsYcAa8D2CBgN33vDeSO9VxfD3EB5gPK0kksYrWvCyItRq9b2z83eozIYVNAMYo8HFTqrDB6tY6CtRz9KKiv86qTxg3UTDovpgrImvjZK06-vToXABr3nAqWfEGinplnzxCYoc8EwMkp9sU6FccLB2QkfTWCd6l9HFXiWMzugGpXHxchWMwaLnZ1mpRmvKoxo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