<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Optimizing to library calls with -ffreestanding and -O0"
href="https://bugs.llvm.org/show_bug.cgi?id=38455">38455</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Optimizing to library calls with -ffreestanding and -O0
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>LLVM Codegen
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>bztemail@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>I'm trying to compile a simple C code for bare metal. My problem is,
with "-ffreestanding -fno-builtin -O0" flags clang still generates
library calls for memset and memcpy. This is clearly a bug, because
1. -ffreestanding should mean there's no standard library, like libc
therefore the C compiler should not rely on memset and memcpy library
functions
2. -fno-builtin should mean not to use llvm.memset and llvm.memcpy
instristics either
3. -O0 should mean do not optimize at all, compile as-is (without
replacing loops by calls)
Please don't tell me that a freestanding environment should already
have memset, because I'm trying to compile a libc! Optimizing the
memset implementation with a memset call inside generates bad code
with an infinite function call loop btw.
I've spent days to read the documentation and surf the forums but I
was unable to find a solution. Is there any workaround I'm unaware of?
As a comparision, gcc understands "-ffreestanding -O0", and compiles
it properly without any unwanted library calls.
The problem appears with both x86_64 and AArch64 targets, haven't tried others.
Also please note that I'm not the only one with this problem:
<a href="http://clang-developers.42468.n3.nabble.com/Disable-memset-synthesis-td4057810.html">http://clang-developers.42468.n3.nabble.com/Disable-memset-synthesis-td4057810.html</a>
<a href="http://lists.llvm.org/pipermail/llvm-dev/2012-May/050122.html">http://lists.llvm.org/pipermail/llvm-dev/2012-May/050122.html</a>
<a href="https://groups.google.com/forum/%23!msg/llvm-dev/TxuxaOqkK6U/Op9qRCwrjngJ&sa=U&ved=0ahUKEwjvhsPbjNjcAhVGZFAKHZzuAR4QFgg9MAc&usg=AOvVaw3-mAM-UuHkMTQq_WtXgHYm">https://groups.google.com/forum/%23!msg/llvm-dev/TxuxaOqkK6U/Op9qRCwrjngJ&sa=U&ved=0ahUKEwjvhsPbjNjcAhVGZFAKHZzuAR4QFgg9MAc&usg=AOvVaw3-mAM-UuHkMTQq_WtXgHYm</a>
<a href="https://bugs.chromium.org/p/nativeclient/issues/detail?id=3493">https://bugs.chromium.org/p/nativeclient/issues/detail?id=3493</a>
I'm sure most of the developers using clang with "ffreestanding" and "O0" would
expect their code to be compiled as-is, without any unresolved library calls. I
understand that this feature is good for application programming, but it's a
serious hickup and rather troublesome for an experienced programmer compiling
for bare metal.
If you want more details, please let me know.
Thank you,
bzt</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>