llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[Clang] libc calls still get generated when libc is not linked

Open DaisyTheDev opened this issue 2 months ago • 2 comments

When I use clang in freestanding environments where I purposefully don't want libc to be linked (-ffreestanding -nodefaultlibs -nostartfiles), clang will still generate libc calls to functions like "memset" and "memcpy" when there aren't any actual calls nor references to them in the user's code. From my experience, this behavior is unconditional and can lead to link errors that aren't directly the user's fault. This can get pretty annoying at times as well. It makes you try to work around the compiler just to get rid of it. There's seemingly no flag to remove this behavior either.

DaisyTheDev avatar Sep 08 '26 04:09 DaisyTheDev

@llvm/issue-subscribers-libc

Author: DaisyTheDev

When I use clang in freestanding environments where I purposefully don't want libc to be linked, clang will still generate libc calls to functions like "memset" and "memcpy" when there aren't any actual calls nor references to them in the user's code. From my experience, this behavior is unconditional and can lead to link errors that aren't directly the user's fault. This can get pretty annoying at times as well. It makes you try to work around the compiler just to get rid of it. There's seemingly no flag to remove this behavior either.

https://github.com/llvm/llvm-project/issues/37803

https://clang.llvm.org/docs/UsersManual.html#freestanding-builds

Andarwinux avatar Sep 08 '26 06:09 Andarwinux