[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to use a different ld-linux.so?
From: |
John Reiser |
Subject: |
Re: How to use a different ld-linux.so? |
Date: |
Mon, 28 Jun 2004 10:30:49 -0700 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20030225 |
I have a need to use a different runtime linker (ld-linux.so) for some
of my applications. I _don't_ want to change the executables themselves
(changing the path to the runtime linker in the ELF image for example).
Why not? http://www.BitWagon.com/rtldi/rtldi.html
I know that I can just run my application as an argument to ld-linux.so,
and that actually does work very well. But, I am left with two
problems:
* Some of my applications fork/exec other programs, and those other
programs also need to use the other runtime linker. Just as I don't
want to change the ELF image, I certainly don't want to have to
recompile the programs to exec the runtime linker!
fork() is never a problem, but it is necessary to intercept execve()
if you wish to invoke a different executable or to change its environment.
* Debugging: I can't debug because I can't find a way to convince GDB
to invoke the program-to-be-debugged using an alternative runtime
linker.
$ gdb /lib/ld-linux.so.2
(gdb) run --library-path /lib /bin/date
If you want to set breakpoints then put one near the end of _dl_start_user
where it invokes _dl_init_internal. Inspect /proc/<pid>/maps to find out
what has been mapped, then use the add-symbol-file command of gdb.
Find the offset from "objdump --section-headers a.elf | grep text"
then add the base from the map of the address space.
... another idea is to use LD_PRELOAD
to install a private version of the execve() system call, which would
set the alternative ld-linux.so as the first argument.
By using LD_PRELOAD one can supersede the visible uses of execve() [the ones
that use global symbol linkage to invoke execve()], but there can be "bare"
system calls that do not use symbols.