0

The (1st) problem:
I have a shared library shared1.so, which is using a static library static1.a.
I have another shared library shared2.so.
shared2.so can't link directly with static1.a due to a limitation.
I want shared2.so to use static1.a.

My solution
I exported static1.a functions in shared1.so, and now shared2.so is using static1.a functions by linking with shared1.so. This is working ok!
However I ended up with all static1.a symbols appear in shared1.so.

The (2nd) problem
How can I get rid of all these symbols/functions that are not used by shared2.so?
I tried:

arm-linux-androideabi-objcopy --strip-symbols symbols_of_static1_which_i_dont_use.txt shared1.so

however it doesn't do anything, no warning either (even with -v).
I also tried with arm-linux-androideabi-strip but it doesn't strip anything too.

EDIT:

So it seems strip only strips the static symbols and doesn't touch the .dynsym section. I'm still looking for a way to remove all unnecessary symbols of static1.a that are now exported in shared1.so

HyBRiD
  • 688
  • 4
  • 23

1 Answers1

0

However I ended up with all static1.a symbols appear in shared1.so

You didn't explain how you linked shared1.so. It's possible that by linking smarter you could avoid having extraneous static1.a symbols in shared1.so in the first place (this may be preferable to stripping the symbols out, because if the extra symbols are not used, they just bloat shared1.so for no good reason).

The 1st problem still remains.

But you've found a solution for it, have you not?

strip only strips the static symbols and doesn't touch the .dynsym section

That is correct. It is really hard to modify the dynammic symbol table after linking, because the symbols appear in hash tables.

If you want to omit certain symbols from shared1.so, and you can't avoid linking them in in the first place, then your best bet is to use linker script to limit symbol visibility to just the symbols you want to be visible. Example.

Update:

However how do I combine this with the usage of __attribute__ ((visibility ("default")))? It seems linker script overrides the functions I exported with that setting.

Correct: the linker script overrides everything.

If you are already using attributes to control symbol visibility, then you can

  • add __attribute__((visibility("hidden")) to the symbols you don't want, or
  • compile with -fvisibility=hidden flag.
Community
  • 1
  • 1
Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • Thank you very much, using linker script I managed to export only the needed functions. However how do I combine this with the usage of `__attribute__ ((visibility ("default")))`? It seems linker script overrides the functions I exported with that setting. – HyBRiD Nov 10 '14 at 12:54