[llvm-bugs] [Bug 38455] New: Optimizing to library calls with -ffreestanding and -O0
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Aug 6 02:31:39 PDT 2018
https://bugs.llvm.org/show_bug.cgi?id=38455
Bug ID: 38455
Summary: Optimizing to library calls with -ffreestanding and
-O0
Product: clang
Version: unspecified
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: LLVM Codegen
Assignee: unassignedclangbugs at nondot.org
Reporter: bztemail at gmail.com
CC: llvm-bugs at lists.llvm.org
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:
http://clang-developers.42468.n3.nabble.com/Disable-memset-synthesis-td4057810.html
http://lists.llvm.org/pipermail/llvm-dev/2012-May/050122.html
https://groups.google.com/forum/%23!msg/llvm-dev/TxuxaOqkK6U/Op9qRCwrjngJ&sa=U&ved=0ahUKEwjvhsPbjNjcAhVGZFAKHZzuAR4QFgg9MAc&usg=AOvVaw3-mAM-UuHkMTQq_WtXgHYm
https://bugs.chromium.org/p/nativeclient/issues/detail?id=3493
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
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180806/2ba231b6/attachment.html>
More information about the llvm-bugs
mailing list