On Fri, 8 Jun 2012, Bin.Cheng wrote:

> For example, most c programs call printf to format output data, that
> means floating point code get linked even the program only want to
> output non-floating point numbers. Currently, we rely on end-user to
> call iprintf if the program does not want floating point.

The name "iprintf" is in the user's namespace, not the implementation 
namespace, so it wouldn't be a particularly good idea for the compiler to 
generate calls to it (certainly not in standards modes; cf. bug 46926).  
But as I understand it you're suggesting something more complicated than 
generating a call to a special function.

> I noticed that GCC now can check format string of printf functions, so
> I am wondering if it is possible to take advantage of this utility, by
> making gcc detect whether printf prints floating point number and then
> generate assembly directive in backend to pull in floating point
> functions only if necessary.

Obviously this won't help if the program is using functions such as 
vprintf to print things with variable format strings....

> The problem is:
> The check is done in front end, so how should I expose the check
> result to back-end. Is there any hook utility?

The front end should generate appropriate GIMPLE describing semantics of 
the translation unit.  If you are simply calling some system-defined 
__iprintf this is a matter of rewriting function calls (given an 
appropriate C-family target hook to do the rewriting).  But if you want 
e.g. an assembler directive causing a relocation against some magic symbol 
to cause certain code to be linked in, you could probably generate a call 
to __builtin_<arch>_printf_needs_float (for example), again given a 
suitable hook, and then have the back end handle such a call by generating 
a directive rather than code.

-- 
Joseph S. Myers
jos...@codesourcery.com

Reply via email to