[PATCH] D131521: [SDAG] avoid generating libcall in function with nobuiltin

Nick Desaulniers via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 10 15:02:22 PDT 2022


nickdesaulniers added a comment.

In D131521#3712311 <https://reviews.llvm.org/D131521#3712311>, @spatel wrote:

> I see that if you build C source with "-ffreestanding", then the functions will have a different attribute -- "no-builtins" -- is that the attribute we should be detecting here?

No (and I agree with @efriedma ).

My understanding (which itself might not be precise) is that C code can be "hosted" or "freestanding."

Hosted is the common case for userspace application developers, while freestanding is more common in embedded use cases, though these aren't always strictly the case.  The Linux kernel for example hasn't yet decided whether it wants to be freestanding or not, and changes it mind per arch. *yikes*

A C program tends to implicitly link against a libc //and// a compiler runtime.  `-ffreestanding` implies a libc will not be available, but it implies nothing about the compiler runtime.  Instead `--rtlib=none` implies no compiler-rt should be linked against, but implies nothing about the libc.

The function/symbol for this patch is `__muloti4` which we should expect to be provided by the compiler runtime, not the libc.  So `-ffreestanding` is relevant for libcall optimizations that assume function symbols with specific identifiers can be assumed to have semantics specific to libc.

I don't think we have an equivalent fn attr or mdnode for `--rtlib=none` in IR.  If we did, and it was explicitly set, then we can't assume functions like `__muloti4` will be available to link against.

So I agree when @efriedma says:

> We generally expect freestanding binaries to include compiler-rt builtins, but not a C library.

I don't see `no-builtins` specifically in the LangRef; not sure if that was a typo or worse: undocumented IR attributes. *yikes*
Oh, you weren't kidding: https://godbolt.org/z/o49oK6GYG *yikes*
Well I sure wouldn't do anything with that attr until its semantics are well documented.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131521/new/

https://reviews.llvm.org/D131521



More information about the llvm-commits mailing list