Things I find worth sharing in my dealing with computers and programming (mostly on Linux/UNIX).

Wednesday, October 18, 2006

Statically linked plugins

While looking for something completely different (isn't that how it always happens?) I found a very interesting discussion from three years ago on the binutils list. It all begins when one guy complains about what he sees as a bug in the linker:

One of the 'issues' he sees is the traditional UNIX linker behaviour, which I found out about on the Sun forums a while ago. The order of the libraries on the command line matters. The linker doesn't help you, as I remember was the case on Windows, and it sucks if you're coming from the Redmond OS to UNIX.

The other main issue is related to the registration of static plugins, which we've also faced in my team at work. Later in the discussion, one guy from ARM sums up the options in this case quite nicely.

Where I work, because of some misunderstood requirements, we have to use static linking and some 'registerable' components - you could call them plugins. (Now even the lead technical guys say: "hey, I never said we should use static linking!". Probably somebody was too lazy to change the old Makefiles, taken over from a different project? But that's a different story). At first the (dumb) approach was to add everything under --whole-archive, which would make the executables incredibly bloated, of course. Nowadays, only the registerable components (which use a mechanism very similar to the one outlined in this guy's first post) libraries are under --whole-archive, while the rest is wrapped around in --start-group/--end-group, because at a certain moment the number of static libs got out of control, and nobody wants to spend times sorting 100 static libraries. Thank God for the *-group options! I did the whole work, since nobody else seemed to be bothered by the binary size or want to do anything about it.

Now, reading the post with the options, there are at least two which look interesting, and I will look into them:

  • the one about using the '-u' linker option, but that probably only works for dynamic libs

  • the use of the '-R' option to GNU ld



At the moment I haven't checked them out. However, I think that you have to strive to do things properly, otherwise you might end up reinventing the same shit once again. And I'm not looking forward to that.

0 Comments:

Post a Comment

<< Home