This is the mail archive of the
glibc-linux@ricardo.ecn.wfu.edu
mailing list for the glibc project.
Re: ld.so cares about /usr/X11R6?
At 00:51 +0200 1999-05-28, Robert Siemer wrote:
>Hi!
>
>On 27 May 1999, Andreas Jaeger wrote:
>
>> >>>>> Robert Siemer writes:
>> > Question:
>> > Why does ld.so cares more about my directory-hierarchie and its symlinks
>> > instead to decide from LD_LIBRARY_PATH and /etc/ld.so.cache??
>> > How can I run this application even with a symlink from /usr/X11R6 to
>> > X11R6-libc6?
>>
>> The problem you describe can happen if you link with
>> --rpath=/usr/X11R6/lib. In this case the run path (search path for
>> libraries) is hardcoded into the binary. You can check this with
>> objdump.
>
>siemer@panorama:/usr/X11R6-libc5/bin > objdump -x
>ghostview.hardcoded.libc5.old | grep -B2 -A2 X11R6
>objdump: ghostview.hardcoded.libc5.old: No symbols
> NEEDED libm.so.5
> NEEDED libc.so.5
> RPATH /usr/X11R6/lib
> INIT 0x8003250
> FINI 0x8014f90
>
>
>You are right. Is it possible to change the RPATH in a binary?
Taken from another list:
_Changing_ is a little tricky, but the attached program strips rpaths
from executables (I find it essential for debugging the binutils).
It's endian-dependent, if you want this for x86 you can just change
the occurrences of 'MSB' to 'LSB' and compile (I should really fix
that).
--
Geoffrey Keating <geoffk@ozemail.com.au>
===File ~/src/killrpath.c===================================
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <elf.h>
#include <stdlib.h>
/* Reads an ELF file, nukes all the RPATH entries. */
int
main(int argc, char **argv)
{
int fd;
Elf32_Ehdr ehdr;
int i;
Elf32_Phdr phdr;
Elf32_Dyn *dyns;
int dynpos;
if (argc != 2)
{
printf ("Usage: %s objectfile\n", argv[0]);
return 1;
}
fd = open(argv[1], O_RDWR);
if (fd == -1)
{
perror ("open");
return 1;
}
if (read(fd, &ehdr, sizeof(ehdr)) != sizeof(ehdr))
{
perror ("reading header");
return 1;
}
if (*(unsigned *)ehdr.e_ident != *(const unsigned *)ELFMAG ||
ehdr.e_ident[EI_CLASS] != ELFCLASS32 ||
ehdr.e_ident[EI_DATA] != ELFDATA2MSB ||
ehdr.e_ident[EI_VERSION] != EV_CURRENT)
{
fprintf(stderr, "`%s' probably isn't a 32-bit MSB-first ELF file.\n",
argv[1]);
return 1;
}
if (ehdr.e_phentsize != sizeof(Elf32_Phdr))
{
fprintf(stderr, "section size was read as %d, not %d!\n",
ehdr.e_phentsize, sizeof(Elf32_Phdr));
return 1;
}
if (lseek(fd, ehdr.e_phoff, SEEK_SET) == -1)
{
perror ("positioning for sections");
return 1;
}
for (i = 0; i < ehdr.e_phnum; i++)
{
if (read(fd, &phdr, sizeof(phdr)) != sizeof(phdr))
{
perror ("reading section header");
return 1;
}
if (phdr.p_type == PT_DYNAMIC)
break;
}
if (i == ehdr.e_phnum)
{
fprintf (stderr, "No dynamic section found.\n");
return 2;
}
dyns = malloc(phdr.p_memsz);
if (dyns == NULL)
{
perror ("allocating memory for dynamic section");
return 1;
}
memset(dyns, 0, phdr.p_memsz);
if (lseek(fd, phdr.p_offset, SEEK_SET) == -1
|| read(fd, dyns, phdr.p_filesz) != phdr.p_filesz)
{
perror ("reading dynamic section");
return 1;
}
dynpos = 0;
for (i = 0; dyns[i].d_tag != DT_NULL; i++)
{
dyns[dynpos] = dyns[i];
if (dyns[i].d_tag != DT_RPATH)
dynpos++;
}
for (; dynpos < i; dynpos++)
dyns[dynpos].d_tag = DT_NULL;
if (lseek(fd, phdr.p_offset, SEEK_SET) == -1
|| write(fd, dyns, phdr.p_filesz) != phdr.p_filesz)
{
perror ("writing dynamic section");
return 1;
}
return 0;
}
============================================================
--
Joel Klecker (aka Espy) Debian GNU/Linux Developer
<URL:mailto:jk@espy.org> <URL:mailto:espy@debian.org>
<URL:http://web.espy.org/> <URL:http://www.debian.org/>