Shared Lib: remove unused Symbol

Viewed 748

I want to build a shared library.
Cross-Compilation isn't easy for this one, so i want to remove all unneeded functions during compilation (gcc) & linking (ld).

In executable programs with a main() you can remove unused functions with

  • C_FLAGS = -ffunction-sections -fdata-sections
  • LD_FLAGS = --gc-sections

With this flags, GCC only keeps functions that are reachable from main.

Obviously, you don't have a main() in a shared library.
But, is there a way to tell GCC which functions are definitely needed for dynamic linking?
GCC could then build a call-tree from this functions and remove all others which are unreachable from there.

Is this possible?
Which GCC Flags are needed?

0 Answers
Related