<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/147401>147401</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
`clang -O` produces references to `memset` even with `-fno-builtin -ffreestanding -nostdlib`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
attila-lendvai
</td>
</tr>
</table>
<pre>
i'm compiling a static linux binary that talks directly to the kernel, i.e. without libc:
`clang -O3 -nostdlib -nostartfiles -ffreestanding -fno-builtin-memset -Wl,-Bstatic -Qunused-arguments --target=x86_64-linux-gnu eval2.ll`
if i delete the `-O` then it works as expected.
i think some of the optimizations emits calls to `memset` regardless of the command line arguments.
```
$ clang --version
clang version 20.1.7
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /gnu/store/hvi2iz7n4zk4pyxvibrxa6j43hkv4wn2-clang-20.1.7/bin
```
```
$ uname -a
Linux lelap 6.14.11 #1 SMP PREEMPT_DYNAMIC 1 x86_64 GNU/Linux
$ guix describe
Generation 231 Jul 06 2025 13:09:57 (current)
guix 50b7528
repository URL: https://codeberg.org/guix/guix.git
branch: master
commit: 50b75285883623ee244d0a71a225807c0672ac33
```
[eval2.ll.gz](https://github.com/user-attachments/files/21110384/eval2.ll.gz)
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx8lN2OnDgThq_GfVICmeKvOeCAZEKUT_n7solWexQZXA1OG7tlm56eufqVGZLMJquVkICSq1zv4_IrvFeTIWpZ-YKVdwexhtm6VoSgtEg0GXkV6jBY-dAqhvUCo10uSiszgQAfRFAjaGXWGwzKCPcAYRYBgtBnD1I5GoN-gGAhzARncoY0w5egUkrhXoXZrgG0GkaWd4xvT8VHLcwEyYccEmN9kFoNT1_ChZPS5CE5nRyRD8LI2EhyMjYZVqWDMslCi6cAyZ9xo-TF3mLy_9WsnmQi3LQuZIK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