Bad habits: (Statically linked) library copies

Today (yes, a Saturday, don’t ask I have to work any day, …) I had to hunt an ugly bug for a custom. Actually that gdchart, an aging PHP charing extension, does not work with PHP 5.3. Actually an issue that is all over the web and zillion of people want to see work and a patch for.

I wonder why there are no patches for this apparently kind of prominent issue. Anyway, after too much time diving thru all the mess that is PHP (yeah, I’d prefer nearly any language, such as Lua, but that is a different topic), I found the culprit the all so often “private, modified, and statically linked copy of a library” problem. Point in case: libgd, an albeit aging and ugly graphic library by itself.

So PHP 5.3 changed the symbol visibility and no long exports the libgd symbols the gdchart extension needs to perform it’s work. So after finding all this out the fix (or workaround, whatever you wanna name it) was trivial. I wonder why noone else came up with a fix, yet. Though, maybe PHP website constructors are just not up to digging thru such details.

Point being: Don’t ever, never ever, copy a library into your project and link it in statically. You’ll doing anyone a favor. Not yourself, not the distributors, nor the users. Yes, I understand it’s tempting, and worst historic coding practice. But don’t! It will just duplicate workload and headache. Not only will it age, be subject to security issues, bugs and lagging features long after the upstream library was improved. You’re unlikely doing a better job on it than the original authors. And from my T2 experience I know it! Maintaining all the thousand packages I have seen it all: from zlib, to libjpeg, libtiff, libpng, libgd, or lua, you name it.

And for the higher educated readers: You will also waste storage space by having the same executable code bundled multiple times, as well as also consume more virtual memory as those multiple executable chunks have to be mapped into memory multiple times as well, …

2 Responses to “Bad habits: (Statically linked) library copies”

  1. Mark Says:

    Hello, how do I go about using your patch, or patching php 5.3 on my own? Do I need T2 to use your patch?

  2. René Says:

    You can just apply the patch (patch -p1 … libgd-symbol-visibility.patch inside the unpacked php source tree) and re-compile PHP.

    You do not need to use T2, but of course I can only recommend it :-)

Leave a Reply

You must be logged in to post a comment.