Darryl Gove's blog
Crossfile inlining and inline templates
Found an interesting 'feature' of using crossfile (-xipo) optimisation together with inline templates. Suppose you have a 'library' routine which is defined in one file and uses an inline template. This library routine is used all over the code. Here's an example of such a routine:
int T(int);
int W(int i)
{
return T(i);
}
The routine W relies on an inline template (T) to do the work. The inline template contains some code like:
.inline T,0 add %o0,%o0,%o0 .end
The main routine resides in another file, and uses the routine W:
#includeint W(int); void main() { printf("%i\n",W(9)); }
To use inline templates you compile the file that contains the call to the inline template together with the inline template that it calls - like this:
$ cc -c -xO4 m.c $ cc -c -xO4 w.c t.il $ cc -xO4 m.o w.o
However, when crossfile optimisation (-xipo) is used, the routine W is inlined into main, and now main has a dependence on the inline template. But when m.o is recompiled after W has been inlined into main, the compiler cannot see the inline template for T because it was not present on the initial compile line for m.c. The result of this is an error like:
$ cc -c -xO4 -xipo m.c $ cc -c -xO4 -xipo w.c t.il $ cc -xO4 -xipo m.o w.o Undefined first referenced symbol in file T m.o ld: fatal: Symbol referencing errors. No output written to a.out
As you might guess from the above description, the workaround is not intuitive. You need to add the inline template to the initial compile of the file m.c:
$ cc -c -xO4 -xipo m.c t.il $ cc -c -xO4 -xipo w.c t.il $ cc -xO4 -xipo m.o w.o
It is not sufficient to add the inline template to the final compile line.
Looking beyond the simple test case shown above, the problem really is that when crossfile optimisation is used, the developer is no longer aware of the places in the code where inlining has happened (which is as it should be). So the developer can't know which initial compile lines to add the inline template to.
Hence, the conclusion is that whenever you are compiling code that relies on inline templates with crossfile optimisation, it is necessary to include the inline template on the compile line of every file.
Posted at 12:03PM May 15, 2008 by Darryl Gove in Sun | Comments[1]



thanks for this text
Posted by istanbul on May 16, 2008 at 06:36 AM PDT #