C Library Visibility

I was surprised by the recent announcement that MySQL are going to start to conceal the hidden function calls in their C connector. Surprised because although this is great news I had expected them to do this years ago. Working for HP's Advanced Technology Group I realise I take such things for granted. For this blog post I'm going to talk about why it is important and how to do it.

So, when you create a dynamic library in C the default thing that happens is every function call in that library effectively becomes a potential API call. Whether you document every single function or not to make it official API is up to you but I suspect in 99.99% of cases there are private functions you don't want users to mess with. Additionally holding the symbol information for every function so that you can link your application to it takes a massive amount of space, one such library I can think of is 8x bigger than it should be due to exposing every function call.

In MySQL's case and likely others this can cause a problem with collisions during linking. MySQL can use its bundled in YaSSL library to supply SSL, and due to the functions being exposed this can cause problems if your application links to libmysqlclient and OpenSSL since they both use the same public API calls in many places.

RedHat and other distributions actually solve this in MySQL by stripping the binaries of unneeded symbols at compile time. This is indeed one effective solution. But I don't believe this is the correct solution. In fact Ulrich Drepper in How To Write Shared Libraries pretty much reserves this as a last resort.

Comments !