HOWTO: Using libfreevec using LD_PRELOAD

Ok, let's suppose you've downloaded libfreevec, built it successfully and now you want to use it for the whole system, without recompiling the whole system to use the library! Is it possible? Thanks to a glibc feature you can!

There are two ways to do that:

  • one is to use the LD_PRELOAD environment variable, eg. at boot time, but there is a more elegant way to do this.
  • by use of the /etc/ld.so.preload file, which is most likely distro-agnostic, so that the dynamic loader ld.so loads libfreevec before any other library (including libc.so).

    The 2nd is a much more elegant solution, IMHO, and I've been using it for months with no problems whatsoever. So, after you install the library somewhere (by default it's installed in /usr/local/lib/) you could just do a:

    echo /usr/local/lib/libfreevec_libc.so > /etc/ld.so.preload

    Beware it has to be the libfreevec_libc.so and not the libfreevec.so as the 2nd one prefixes each function with vec_ and is only useful to someone that wants to use the library explicitly -for whatever reason.

    The next application you will load you will use the AltiVec functions in libfreevec! Enjoy! :)

    Note: This has a slight overhead which would reduce some of the performance in the functions, but would still prove a good move in most cases.