Let's say I have foo.a with
a.o
T aaa
U bbb
b.o
T bbb
How can I either modify foo.a or create a relocatable foo.o such that when it is linked in another project, a.o:bbb uses b.o:bbb instead of a bbb that might be defined elsewhere? Note that I can't use --whole-archive because main is defined in one the .o in foo.a. Also note that I can know the symbols to keep global (eg aaa) or to use local (eg bbb) if that helps.
I tried to create a relocatable object with a version script exporting only aaa in the hope bbb would be linked local implicitly. Unfortunately, the resulting .o contains no symbols:
$ cat version.script
{ global: aaa; local: *; };
$ ld -relocatable --version-script version.script foo.a -o foo.o
$ nm foo.o
nm: foo.o: no symbols
This might not even be the right approach so I'm open to suggestions. Thank you!