From: Wolfgang Denk Date: Sat, 11 Oct 2014 17:03:46 +0200 Subject: [U-Boot] Discussion topics / issues In-Reply-To: <54384450.3000204@myspectrum.nl> References: <201410071445.50854.marex@denx.de> <20141010122229.B60DC38352B@gemini.denx.de> <5437E778.3050306@myspectrum.nl> <201410101626.41944.marex@denx.de> <543804AF.9050101@myspectrum.nl> <54384450.3000204@myspectrum.nl> Message-ID: <20141011150346.150C038352A@gemini.denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Dear Jeroen, In message <54384450.3000204@myspectrum.nl> you wrote: > > If you ask to disable it, it is good if it does so, don't see a problem > with that. Anyway, it is not an u-boot issue, anything below -O2 is not > supported anyway. I'm not sure what you mean here. Gcc certainly does this replacement with -Os as used for U-Boot. > I would almost take this as an insult, I hope u-boot folks know or at > least check before they assume a compiler does XYZ. And yes > compilers will replace simple printf call with their simpler equivalent > and has been doing so for quite a while (and that is an understatement). I wonder how many people know about this - and where it is documented? > So to turn it around: just use printf: "you don't lose much but you > can only win." Sorry, but I disagree here. First, we have a compatibility problem here. GCC assumes that puts() will add a newline character after the string; U-Boot puts() does NOT do this. So the GCC auto-converted printf()s will all be wrong, as they are missing the newline. [1] Second, using puts() insteas of printf() is also a means of documenting your code. It shows your intention to print a constant string. Just one example: compare A: void add_header(const char *s) { printf("MY HEADER: %s\n", s); } versus B: void add_header(const char *s) { puts("MY HEADER: "); puts(s); /* Assuming U-Boot puts() - no automatic \n added */ putc('\n'); } Which is "better"? A is obviously much shorter and more elegant; but B is much more robust - A will happily crash your system when you try to print a string like "s%s%s%s%s%s%s%s%s%s%s" (not to mention that this may open a classic attack vector to break into a running system). So yes, it does make sense to explicitly use puts(). [1] One might argue that this is a bug in U-Boot and should be fixed, but that is another topic. Best regards, Wolfgang Denk -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de A verbal contract isn't worth the paper it's written on. -- Samuel Goldwyn