Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

imposing library loading order

I have a gcc-compiled application linked against dynamic libraries. Is there a way to impose the order in which libraries are loaded? (In my case one library constructor uses resources set up by other library constructor).

Thanks.

like image 418
jackhab Avatar asked Dec 07 '09 11:12

jackhab


1 Answers

gcc isn't in-charge of loading the libraries, either ld.so does it automatically when your program loads, or you do it manually as @jldupont suggests.

And ld.so might deliberately randomise the order to prevent return-to-stdlib attacks.

So either:

  1. Load the libraries yourself.
  2. Or remove the dependencies between the library load scripts.
  3. Make the libraries contain the dependencies themselves (might work, might not) That is when you get to the point of linking each shared library, make sure it includes -l<dependentlib> in the link command. You can test this by creating a trival program that links only with that shared library - if it builds and runs, then the library contains all necessary dependent libs. This might help if ld.so loads the libraries in dependency order - which I think it has to do.
like image 165
Douglas Leeder Avatar answered Oct 11 '22 08:10

Douglas Leeder