2 Taken from another list:
4 _Changing_ is a little tricky, but the attached program strips rpaths
5 from executables (I find it essential for debugging the binutils).
6 It's endian-dependent, if you want this for x86 you can just change
7 the occurrences of 'MSB' to 'LSB' and compile (I should really fix
11 Geoffrey Keating <geoffk@ozemail.com.au>
22 #if defined(HAVE_LINK_H)
24 #endif /* HAVE_LINK_H */
29 /* Reads an ELF file, nukes all the RPATH entries. */
32 killrpath(const char *filename)
41 fd = elf_open(filename, O_RDWR, &ehdr);
49 if (0 != elf_find_dynamic_section(fd, &ehdr, &phdr))
51 perror("found no dynamic section");
55 dyns = malloc(phdr.p_memsz);
58 perror ("allocating memory for dynamic section");
61 memset(dyns, 0, phdr.p_memsz);
62 if (lseek(fd, phdr.p_offset, SEEK_SET) == -1
63 || read(fd, dyns, phdr.p_filesz) != (int)phdr.p_filesz)
65 perror ("reading dynamic section");
70 for (i = 0; dyns[i].d_tag != DT_NULL; i++)
72 dyns[dynpos] = dyns[i];
73 if ( ! elf_dynpath_tag(dyns[i].d_tag) )
76 for (; dynpos < i; dynpos++)
77 dyns[dynpos].d_tag = DT_NULL;
79 if (lseek(fd, phdr.p_offset, SEEK_SET) == -1
80 || write(fd, dyns, phdr.p_filesz) != (int)phdr.p_filesz)
82 perror ("writing dynamic section");