I'm currently building a Linux fromscratch (mostly following the guide at linuxfromscratch.org version7.3). I ran into the following problem: when I build an executable itgets a hardcoded path to something called ELF interpreter.
readelf -l program
shows something like
[Requesting program interpreter: /lib/ld-linux.so.2]
I traced this library ld-linux-so.2 to be part of glibc. I am not veryhappy with this behaviour because it makes the binary very unportable; if I change the location of /lib/ld-linux.so.2 the executable nolonger works and the only "fix" I found is to use the patchelf utilityfrom NixOS to change the hardcoded path to another hardcoded path. Forthis reason I would like to link against a static version of the ldlibrary but such is not produced. And so this is my question, couldyou please explain how could I build glibc so that it will produce astatic version of ld-linux.so.2 which I could later link to myexecutables. I don't fully understand what this ld library does, but Iassume this is the part that loads other dynamic libraries (or atleast glibc.so). I would like to link my executables dynamically, butI would like the dynamic linker itself to be statically built intothem, so they would not depend on hardcoded paths. Or alternatively Iwould like to be able to set the path to the interpreter withenvironment variable similar to LD_LIBRARY_PATH, maybeLD_INTERPRETER_PATH. The goal is to be able to produce portablebinaries, that would run on any platform with the same ABI no matterwhat the directory structure is.
Some background that may be relevant: I'm using Slackware 14 x86 tobuild i686 compiler toolchain, so overall it is all x86 host andtarget. I am using glibc 2.17 and gcc 4.7.x.