Re: easy way to tell if "in" package build?
At 18:51 +0200 1999-10-20, Marcus Brinkmann wrote:
This is the wrong approach. Creating such dependencies on Debian specific
hacks in build tools and environment variables looks a lot like "magic".
A hack is not nicer if it is hidden deep in the system. I am not even sure
if the current Debian policy wrt rpaths is so ideal as most developers
seem never to question.
I have a suggestion, we should have a `strip-rpath' program.
This is a program from Geoff Keating <geoffk@ozemail.com.au>, it
needs to be fixed to work on little-endian and 64-bit ELF, before
it'd meet our needs, but it's a start (I'm sure he's willing to give
this program a license if someone wants to work on it).
#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/>
Reply to: