If the person writing the code was anticipating someone LD_PRELOADing a printf replacement, then yeah, they should use -fno-builtin-printf. If they weren't, then they might have just as well written puts() themselves anyway. And for that matter, it'd be totally legal for libc to make printf an inlineable function.
Not perfectly supporting an inherently hacky interface like LD_PRELOAD is really really different from being "inherently unsafe". By that measure I'm pretty sure everything about C is inherently unsafe.
Posted May 25, 2012 2:59 UTC (Fri) by daglwn (subscriber, #65432)
[Link]
By "inherently unsafe," I mean the compiler would arguably make a transformation that causes wrong results. That's certainly not what the programmer expects.
GCC Explorer - an interactive take on compilation
Posted May 25, 2012 12:47 UTC (Fri) by njs (guest, #40338)
[Link]
printf's behavior is defined in the C standard, just like the rest of the language. Any optimization the compiler does to anything, ever, might arguably make a transformation that causes wrong results. Such things are just called "compiler bugs"...
GCC Explorer - an interactive take on compilation
Posted May 25, 2012 14:25 UTC (Fri) by BenHutchings (subscriber, #37955)
[Link]
No, the use of a LD_PRELOAD library which wraps printf() and not puts() is the invalid transformation.