7 #if defined(HAVE_SYS_LINK_H)
8 # include <sys/link.h> /* Find DT_RPATH on Solaris 2.6 */
9 #endif /* HAVE_SYS_LINK_H */
13 #include <sys/types.h>
20 elf_open(const char *filename, int flags, Elf_Ehdr *ehdr)
24 fd = open(filename, flags);
31 if (read(fd, ehdr, sizeof(*ehdr)) != sizeof(*ehdr))
33 perror ("reading header");
38 if (0 != memcmp(ehdr->e_ident, ELFMAG, SELFMAG) ||
39 ehdr->e_ident[EI_CLASS] != ELFCLASS ||
40 ehdr->e_ident[EI_DATA] != ELFDATA2 ||
41 ehdr->e_ident[EI_VERSION] != EV_CURRENT)
44 #ifdef WORDS_BIGENDIAN
45 "`%s' probably isn't a %d-bit MSB-first ELF file.\n",
46 #else /* not WORD_BIGENDIAN */
47 "`%s' probably isn't a %d-bit LSB-first ELF file.\n",
48 #endif /* not WORD_BIGENDIAN */
49 filename, SIZEOF_VOID_P * 8);
51 errno = ENOEXEC; /* Hm, is this the best errno code to use? */
55 if (ehdr->e_phentsize != sizeof(Elf_Phdr))
57 fprintf(stderr, "section size was read as %d, not %d!\n",
58 ehdr->e_phentsize, sizeof(Elf_Phdr));
66 elf_find_dynamic_section(int fd, Elf_Ehdr *ehdr, Elf_Phdr *phdr)
69 if (lseek(fd, ehdr->e_phoff, SEEK_SET) == -1)
71 perror ("positioning for sections");
75 for (i = 0; i < ehdr->e_phnum; i++)
77 if (read(fd, phdr, sizeof(*phdr)) != sizeof(*phdr))
79 perror ("reading section header");
82 if (phdr->p_type == PT_DYNAMIC)
85 if (i == ehdr->e_phnum)
87 fprintf (stderr, "No dynamic section found.\n");
91 if (0 == phdr->p_filesz)
93 fprintf (stderr, "Length of dynamic section is zero.\n");
113 #if defined(DT_RUNPATH)
117 #endif /* DT_RUNPATH */
123 elf_dynpath_tag(int tag)
125 return ( tag == DT_RPATH
126 #if defined(DT_RUNPATH)
128 #endif /* DT_RUNPATH */