Shared Libraries on my mind

I just finished writing up 4 pages of documentation on how to correctly build shared libraries for FreeBSD using Yahoo!’s Makefile macros. The fact that Makefiles are such a black art probably explains the popularity of alternative build systems.

I’m sure a bunch of these ideas will be covered in Theodore Ts’o’s Designing and Creating Great Shared Libraries talk in a few weeks, but I wanted to write down a couple of key points before I forget:

  • Using the -soname linker option is good because it guarantess that code built against your library (either an executable or another .so) only gets used with a binary-compatible version of your library. If you make an unversioned library, you’ll probably need to rename it when you add versioning.
  • Passing the -no-undefined flag to the linker can save you lots of trouble. It’s way better to have your make fail because of an undefined symbol than to end up with errors like this on Apache startup:
    
    Syntax error on line 68 of /usr/local/etc/apache/httpd.conf:
    
    /usr/local/libexec/apache/mod_yscript.so: Undefined symbol "Bar__3FooiPCc"
    
    
  • -fPIC good. TEXTREL bad.
  • objdump -p is a really useful tool.
  • Even after 16 years of development, there are still bugs in gcc.

Now I’ve gotta go hire a tech writer to clean up by doc.