[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Should .a library contains non-reallocatable code?



* Ian Jackson <ijackson@chiark.greenend.org.uk> [150224 15:50]:
> > You still pollute the ABI with the details of the internals:
> > 
> > if you try to change main.c to:
> > #include <stdio.h>
> > #include "foo1.h"
> > #include "bar2.h"
> > int main() {
> >   double rr1;
> >   foo(&rr1);
> >   int r1 = rr1;
> >   int r2 = bar2();
> >   printf("%d %d\n", r1, r2);
> >   return 0;
> > }
> > 
> > and run gcc -Wall main.c -L. -lbar2 -lfoo1 ; LD_LIBRARY_PATH=. ./a.out
> > you get:
> > foo2: 0x7f42db6f0a48
> > foo2: 0x7f42db6f0a48
> > 0 17
> > 
> > (In this specific case a version script might helps, but I'd not bet
> > on helping in all cases).
> 
> I don't know what exactly you ran.  Your transcript is not complete
> and I don't get the same results.  I suspect you didn't pass
> -Bsymbolic everywhere.
> 
> I changed main.c to contain the code you just showed, and reran by
> ./build script (same as before), and got this:
[...]
> 
> (64)ian@zealot:~$ ./build
> + egrep . bar.c bar1.c bar1.h bar2.c bar2.h foo.c foo1.c foo1.h foo2.c foo2.h main.c t.c build
> [...]
> main.c:#include <stdio.h>
> main.c:#include "foo1.h"
> main.c:#include "bar2.h"
> main.c:int main() {
> main.c:  double rr1;
> main.c:  foo(&rr1);
> main.c:  int r1 = rr1;
> main.c:  int r2 = bar2();
> main.c:  printf("%d %d\n", r1, r2);
> main.c:  return 0;
> main.c:}
> [...]
> + gcc -Wall main.c -L. -lbar1 -lbar2

You forgot to change that line as I said to change it.

main.c now uses libfoo1 and libbar2, so in my example I build against
those.  Now you only need a bit of bad luck to use -lbar2 -lfoo1 in
that order and you get the problem. -Bsymbolic only helps against bar
being poluted.  It does not help against libbar polluting the main
program. (For this you need at least something like symbol versioning
to hide the symbols).

	Bernhard R. Link
-- 
F8AC 04D5 0B9B 064B 3383  C3DA AFFC 96D1 151D FFDC


Reply to: