selective linking of floating point support for *printf / *scanf
Tue Aug 26 06:48:00 GMT 2014
> From: Joern Rennecke [mailto:firstname.lastname@example.org]
> Sent: Thursday, August 14, 2014 4:52 PM
> So my idea is to make the compile emit special calls when there are no
> point arguments. A library that provides the floating point enabled
> precedes libc in link order.
> Libc contains the integer-only implementations of *scanf/*printf, in two
> entry points with the special function name, which in the same object file
> also contain a reference to the ordinary function name, and another object
> with the ordinary symbol and the integer-only implementation.
> Thus, if any application translation unit has pulled in a floating-point enabled
> implementation, this is the one that'll be used. Otherwise, the integer-only
> one will be used.
> Use of special sections and alphasorting of these in the linker script
> ensures that the integer-only entry points appear in the right place at
> the start of the chosen implementation.
> If vfprintf is used
What happens in the case that a program contains both some printf and
If the undefined printf is resolved first then everything is fine but if it's the
other way around and __int_printf is resolved first the printf implementation
that will be pulled will not have float support and all the call that needs float
support will fail. Did I miss something?
> I've implemented this for AVR with these commits:
> Although it could use some more testing, and thought how to best
> introduce the change as to avoid getting broken toolchains when
> are out-of-sync.
I didn't do extensive yet but it seems you miss the case of variadic functions.
Consider the example in attachment: two calls to __int_printf will be
generated yet my_printf could be called with the format string "%f\n".
As to the patch it seems to me the macro should be per library, not per backend.
Else two backend supporting newlib would need to write the same code twice.
I'll also try to think how to support the new scheme for printf with float in newlib.
As I said it relies on printf calling _printf_float that is a weak symbol. Previous
scheme could pull 2 implementations of printf and consume more size. The
problem is that compiling newlib with automatic selection would detect some case
where float might be needed (variadic functions) and define _printf_float
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 427 bytes
Desc: not available
More information about the Newlib