dcsimg
Linux Today: Linux News On Internet Time.





IBM developerWorks: Override the GNU C Library--Painlessly

May 20, 2002, 11:00 (14 Talkback[s])
(Other stories by Jay Allen)

[ Thanks to Maria for this link. ]

"What do you do if you don't have the source for your application and it's failing because a GNU Library for C (glibc) function is returning something bad to the application? Because glibc is open-source, you can of course get the source code, make your changes, rebuild, and install. This is not for the faint of heart, however, because although the API is well documented, the internal organization of the GNU C library is not. Finding the correct function prototypes is only the first of many challenges. It's a big package as well, so the first time you compile, it will take some time (glibc 2.2.2 has 8,552 files and 1,775,440 lines of code, including comments).

"Better than rebuilding glibc is selectively overriding a function. Many of the modern Unixes support the concept of preloading user defined libraries. These libraries can be either complete replacements (that is, a private version of glibc) or subsets -- even a single function. You can use a private version of glibc by setting the LD_LIBRARY_PATH to include your private version of the library first. You can use a subset of library routines that you write by using the LD_PRELOAD environmental value. Both LD_LIBRARY_PATH and LD_PRELOAD are controlled by the dynamic ELF linker/loader. It uses a first match to satisfy any symbol name. By preloading your version of a library or function you short circuit the normal path, allowing you to override it..."

Complete Story

Related Stories: