Search code examples
clangstm32keil

Prevent ArmClang to add calls to Standard C library


I am evaluating Keil Microvision IDE on STM32H753.

I am doing compiler comparison between ARMCC5 and AC6 in the different optimisation levels. AC6 is based on Clang.

My code is not using memcpy and I have unchecked "Use MicroLIB" in the project settings , However a basic byte per byte copy loop in my code is replaced by a memcpy with AC6 (only in "high" optimisation levels). It doesn't happen with ARMCC5.

I tried using compilation options to avoid that, as described here: -ffreestanding and -disable-simplify-libcalls, at both compiler and linker levels but it didn't change (for the second option, I get an error message saying that the option is not supported).

In the ARMCLANG reference guide i've found the options -nostdlib -nostdlibinc that prevent (??) the compiler to use any function of a standard lib.

However I still need the math.h function.

Do you know how to prevent clang to use functions from the Standard C Lib that are not explicitely called in the code ?

EDIT: here is a quick and dirty reproduceable example: https://godbolt.org/z/AX8_WV Please do not discuss the quality of this example, I know it is dumb !!, I know about memset, etc... It is just to understand the issue


Solution

  • gcc know a lot about the memcpy, memset and similar functions and even they are called "the builtin functions". If you do not want those functions to be used by default just use the command line option -fno-builtin

    https://godbolt.org/z/a42m4j