How to build the elf interpreter ( as static library?

Carlos O'Donell
Thu Aug 1 05:55:00 GMT 2013

On Mon, Jul 29, 2013 at 7:24 AM, Borislav Peev <> wrote:
> [Requesting program interpreter: /lib/]
> I traced this library ld-linux-so.2 to be part of glibc. I am not very
> happy with this behaviour because it makes the binary very unportable

It does not make the binary unportable.

Distributions all agree upon the dynamic loader name for a
given target architecture.

What kind of portability are you looking for?

> - if I change the location of /lib/ the executable no
> longer works and the only "fix" I found is to use the patchelf utility

You can't change the location of the dynamic loader. It is part of the ABI.

If you change the ABI then you need to relink all of your applications with
a changed compiler and linker that encode the *new* dynamic loader
path in the binaries.

It is possible to make this more dynamic, but nobody has bothered because
it works just fine. You'd have to change the kernel, glibc, and debuggers to
understand your new dynamic scheme e.g. set DT_INTERP to some special

> from NixOS to change the hardcoded path to another hardcoded path. For
> this reason I would like to link against a static version of the ld
> library but such is not produced. And so this is my question, could
> you please explain how could I build glibc so that it will produce a
> static version of which I could later link to my
> executables. I don't fully understand what this ld library does, but I
> assume this is the part that loads other dynamic libraries (or at
> least I would like to link my executables dynamically, but
> I would like the dynamic linker itself to be statically built into
> them, so they would not depend on hardcoded paths. Or alternatively I
> would like to be able to set the path to the interpreter with
> environment variable similar to LD_LIBRARY_PATH, maybe
> LD_INTERPRETER_PATH. The goal is to be able to produce portable
> binaries, that would run on any platform with the same ABI no matter
> what the directory structure is.

That's easy, just link statically e.g. -static, at which point the dynamic
loader is not used. The kernel simply starts the application by jumping
to the ELF entry point.

There are serious problems with linking statically, so you need to understand
those before using that option.

Hopefully that answers your questions.


More information about the Libc-help mailing list