0

Lets say I have a large library liblarge, and application app which links to liblarge.

Liblarge is under the LGPL license, and app is under a proprietary one. I'd like to be able to remove all "dead code" from liblarge which is not used from app. Can I do this somehow? Provide a list of used functions to the linker perhaps?

joe
  • 1,125
  • 9
  • 18
  • Compile liblarge as a static library and link against *.a. I presume from the GCC reference it is a C or C++ application, due to the nature of how the ABI works the single *.o is the smallest unit you can break it down into. – Darryl Miles Sep 18 '12 at 19:45
  • Yes that would certainly remove the dead code, but I was hoping to keep liblarge as a dynamic library for easy compliance with the LGPL. – joe Sep 18 '12 at 23:44

1 Answers1

0

There is no easy way for you to proceed.

You can use the above technique (in my comment) on a private copy to workout which *.o you can remove. Then you can build your own modified liblarge source tree that builds DSO/DLL but removes the *.o from the linker command line (for building the DSO/DLL) after you worked out you did not need.

This is just how C/C++ works a lot of information is lost once code is turned into object code.

For example you might then wish to try and reduce the size of each *.o file. The main way to do that is to split up .c/.cpp compilation units.

The problem with the C/C++ ABIs is that the compiler is free to put code anywhere in the *.o file and then jump into and out of segments inside it using relative offsets. There is not enough metadata saved in the *.o to be able to take apart compiled code and see all the dependencies it requires to function. To do this you need to manually split up the input source code.

This is one reason why for embedded software development when memory footprint used to be important you would literally put one function in inside on source file. These days embedded systems have a lot of memory.

Darryl Miles
  • 4,576
  • 1
  • 21
  • 20