[U-Boot] Discussion topics / issues

Wolfgang Denk wd at denx.de
Sat Oct 11 17:03:46 CEST 2014


Dear Jeroen,

In message <54384450.3000204 at 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


More information about the U-Boot mailing list