Incremental Linking

Gerald Rogers grogers@mail.ipinfusion.com
Mon Jul 8 08:57:00 GMT 2002


Yes,

Basically what I am trying to do is make my library appear local to the module 
which is using it.  So when I link the library against my module, the library 
is only seen by that module.  This way I could link multiple modules to the 
library, and eliminate global variable and name conflicts in a flat shared 
memory space (i.e. vxWorks).  This means I have as many copies of the library 
in my final link as there are modules, but it can be much simpler than the 
architectural alternatives.  

So to look at it this way:  

I link file 1 with the library(file 3) and export only those globals and 
functions I wish to be able to link with later.  I do the same with file 2.  
I then link the result of the 2 steps above with the standard libraries to 
produce the final image.  Since I have performed an intermediate link between 
the library and the modules, the final link will not have any namespace 
issues, and each instance of the module and library will operate on those 
variables and functions that exist within the scope of the link.


This is what I am attempting to do.  I have succeeded without linking the 
standard libraries, but when I include things which require the standard 
library I need to perform incremental links.  If I include the -r option it 
exports all symbols, not just the ones I want and undefined.

Thanks,

Gerald Rogers
IP Infusion, Inc.

On Monday 08 July 2002 11:42 am, Leo Przybylski wrote:
> You do not want multiple instances of the C standard library? Isn't
> stdlib.h protected against multiple inclusion by the preprocessor?
>
> -Leo
>
> On Mon, 2002-07-08 at 04:31, Gerald Rogers wrote:
> > I am seeking help with performing an incremental link which will exclude
> > all symbols except those I defined in the -retain-symbols-file filename
> > option, and those which are unresolved.
> >
> > I have a piece of software which has a common library, and on those
> > systems which have a flat name space I get name conflicts.  I was wanting
> > to link the library into each module instance which uses the library, and
> > then link all of the modules into a single application.
> >
> > As a test, I used the following setup.  This failed to exclude those
> > symbols I did not want in the object.
> >
> > file 1:
> > #include "stdlib.h"
> >
> > int x;
> >
> > extern int foo();
> >
> > int func1()
> > {
> >    foo();
> >    printf("func1 x addr %x, x val %d\n", &x, x);
> > }
> >
> >
> > file 2:
> > #include "stdlib.h"
> >
> > int x;
> >
> > extern int foo();
> >
> > int func2()
> > {
> >    foo();
> >    printf("func1 x addr %x, x val %d\n", &x, x);
> > }
> >
> > file 3:
> > extern int x;
> >
> > int foo()
> > {
> >   x = x + 1;
> > }
> >
> > Symbols_file:
> > func1
> > func2
> >
> > In the above files, I performed the following.
> >
> > gcc -c file1.c
> > gcc -c file2.c
> > gcc -c file3.c
> >
> > ld -r -retain-symbols-file symbol_file file1.0 file3.0 -o file_1.o
> >
> > The output is a .o which contains all the symbols from file1.c and
> > file3.c .
> >
> > What I wanted to see was the symbols to contain only the following:
> > func1 from file1
> > printf from file1  (unresolved so should be included).
> >
> > Is there any way to do this with incremental links.
> >
> > I have managed to link into seperate objects when I did not include
> > unresolved symbols (i.e. printf) without the -r option, and then link the
> > seperate objects together.  However, when I include printf that means I
> > have to link against the standard libraries, and I don't want multiple
> > instances of the standard libraries.
> >
> > Any help is greatly appreciated.
> >
> > Thanks,
> >
> > Gerald Rogers
> > IP Infusion, Inc.



More information about the Gcc-help mailing list