- so->elf_fd = open(path, O_RDONLY);
- if (so->elf_fd < 0) {
- fprintf(stderr, "Failed to open %s\n", path);
- goto error;
- }
-
- so->elf_file = elf_begin(so->elf_fd, ELF_C_READ, NULL);
- if (!so->elf_file) {
- fprintf(stderr, "elf_begin failed: %s\n", elf_errmsg(-1));
- goto error;
- }
-
- if (elf_kind(so->elf_file) != ELF_K_ELF) {
- fprintf(stderr, "Error: %s is not an ELF object\n",
- so->elf_path);
- goto error;
- }
-
- ehdr = g_new0(GElf_Ehdr, 1);
- if (!ehdr) {
- goto error;
- }
-
- if (!gelf_getehdr(so->elf_file, ehdr)) {
- fprintf(stderr, "Error: couldn't get ehdr for %s\n",
- so->elf_path);
- goto error;
- }
-
- /* Position independent code has an e_type value of ET_DYN. */
- so->is_pic = ehdr->e_type == ET_DYN;