[LLVMdev] [RFC] NoBuiltin Attribute

Bill Wendling wendling at apple.com
Mon Feb 18 22:33:51 PST 2013


On Feb 18, 2013, at 8:10 PM, Krzysztof Parzyszek <kparzysz at codeaurora.org> wrote:

> On 2/18/2013 8:08 PM, Chris Lattner wrote:
>> 
>> That code is presumably compiled by someone.  If whoever compiles it specifies -fno-builtin, the attribute would be added to it.  It doesn't affect its clients.
> 
> I thought that no-builtin attached to foo means that foo should not be considered a builtin function.  For example, if someone wrote their own printf, they may want to mark it as no-builtin so that the compiler doesn't assume it's the printf from libc.
> 
This is the GCC definition of the `-fno-builtin' flags:

`-fno-builtin'
`-fno-builtin-FUNCTION'
     Don't recognize built-in functions that do not begin with
     `__builtin_' as prefix.  *Note Other built-in functions provided
     by GCC: Other Builtins, for details of the functions affected,
     including those which are not built-in functions when `-ansi' or
     `-std' options for strict ISO C conformance are used because they
     do not have an ISO standard meaning.

     GCC normally generates special code to handle certain built-in
     functions more efficiently; for instance, calls to `alloca' may
     become single instructions that adjust the stack directly, and
     calls to `memcpy' may become inline copy loops.  The resulting
     code is often both smaller and faster, but since the function
     calls no longer appear as such, you cannot set a breakpoint on
     those calls, nor can you change the behavior of the functions by
     linking with a different library.  In addition, when a function is
     recognized as a built-in function, GCC may use information about
     that function to warn about problems with calls to that function,
     or to generate more efficient code, even if the resulting code
     still contains calls to that function.  For example, warnings are
     given with `-Wformat' for bad calls to `printf', when `printf' is
     built in, and `strlen' is known not to modify global memory.

     With the `-fno-builtin-FUNCTION' option only the built-in function
     FUNCTION is disabled.  FUNCTION must not begin with `__builtin_'.
     If a function is named this is not built-in in this version of
     GCC, this option is ignored.  There is no corresponding
     `-fbuiltin-FUNCTION' option; if you wish to enable built-in
     functions selectively when using `-fno-builtin' or
     `-ffreestanding', you may define macros such as:

          #define abs(n)          __builtin_abs ((n))
          #define strcpy(d, s)    __builtin_strcpy ((d), (s))



> What does it mean in LLVM?
> 
I believe that it should have an analogous meaning.

-bw




More information about the llvm-dev mailing list