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");
56 dyns = malloc(PHDR(p_memsz));
59 perror ("allocating memory for dynamic section");
63 memset(dyns, 0, PHDR(p_memsz));
64 if (lseek(fd, PHDR(p_offset), SEEK_SET) == -1
65 || read(fd, dyns, PHDR(p_filesz)) != (ssize_t)PHDR(p_filesz))
67 perror ("reading dynamic section");
74 for (i = 0; DYNSS(i, d_tag) != DT_NULL; i++)
77 ((Elf32_Dyn *)dyns)[dynpos] = ((Elf32_Dyn *)dyns)[i];
79 ((Elf64_Dyn *)dyns)[dynpos] = ((Elf64_Dyn *)dyns)[i];
80 if ( ! elf_dynpath_tag(DYNSS(i, d_tag)) )
83 for (; dynpos < i; dynpos++)
86 ((Elf32_Dyn *)dyns)[dynpos].d_tag = DT_NULL;
87 ((Elf32_Dyn *)dyns)[dynpos].d_un.d_val = 0x0;
89 ((Elf64_Dyn *)dyns)[dynpos].d_tag = DT_NULL;
90 ((Elf64_Dyn *)dyns)[dynpos].d_un.d_val = 0x0;
94 if (lseek(fd, PHDR(p_offset), SEEK_SET) == -1
95 || write(fd, dyns, PHDR(p_filesz)) != (int)PHDR(p_filesz))
97 perror ("writing dynamic section");