LWN.net Logo

GCC Explorer - an interactive take on compilation

GCC Explorer - an interactive take on compilation

Posted May 24, 2012 18:07 UTC (Thu) by njs (guest, #40338)
In reply to: GCC Explorer - an interactive take on compilation by dgm
Parent article: GCC Explorer - an interactive take on compilation

Yes, but GCC knows whether you're using the C run time library. All these magic optimizations are dependent on which C standard you've asked it to conform to, whether you're running in strict mode, etc.


(Log in to post comments)

GCC Explorer - an interactive take on compilation

Posted May 24, 2012 23:36 UTC (Thu) by daglwn (subscriber, #65432) [Link]

It does not know whether you LD_PRELOADed something before execution.

prinf optimization is inherently unsafe.

GCC Explorer - an interactive take on compilation

Posted May 24, 2012 23:49 UTC (Thu) by njs (guest, #40338) [Link]

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.

GCC Explorer - an interactive take on compilation

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.

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds