On 04/10/2011 15:56, Bustamante, Paul wrote:
> Dear all,
>
> I have a question with GCC compiler. When I have a function that I
> don't need to compile, I use the options "-ffunction-sections
> -fdata-sections" and in the linker --gc-sections. That's ok, but if I
> have a sentence like this, inside that function: printf("text to
> print");, I saw that in the code I have the string "text to print",
> and if I have more, more large is the code.
>
> Somebody can tell me how to avoid this?
>
> Best regards,
>
> Paul
>

The obvious answer is that, when possible, you should avoid including 
and compiling code that is not in use.  Obviously that's not always 
possible or convenient (perhaps the code is shared amongst various 
projects, for example).  But if you can disable the code with "#if" 
constructs, you will get better results.  It will avoid any "leftovers" 
such as your read-only data here, it will compile faster, and it will 
let the compiler do a better job.

As an example of this last point, consider the situation like this:

static void foo(int a) {...}
void used1(void) { ... foo(1); ... }
void unused2(void) { ... foo(2); ... }
void unused3(void) { ... foo(3); ... }

If "unused2" and "unused3" are not used, then with -ffunction-sections 
and --gc-sections they will be compiled, but not included in the link. 
Function foo() will be created as a normal function.

If "unused2" and "unused3" are omitted from the compilation, then the 
compiler can spot that foo() is only used once - and inline it within 
the body of "used1".  As well as removing the function call overhead, 
this also lets the compiler use constant propagation to optimise the 
parameter "a" as a compile-time constant 1.  The result is smaller and 
faster code.

mvh.,

David




------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mspgcc-users

Reply via email to