Lines Matching full:elf
52 static inline Elf *
54 Elf_Cmd cmd, Elf *parent) in file_read_ar()
56 Elf *elf; in file_read_ar() local
59 elf = allocate_elf (fildes, map_address, offset, maxsize, cmd, parent, in file_read_ar()
61 if (elf != NULL) in file_read_ar()
65 elf->state.ar.offset = offset + SARMAG; in file_read_ar()
67 elf->state.ar.elf_ar_hdr.ar_rawname = elf->state.ar.raw_name; in file_read_ar()
70 return elf; in file_read_ar()
92 /* Make the ELF header available. */ in get_shnum()
101 /* We already read the ELF header. We have to copy the header in get_shnum()
142 /* Get the number of sections from the ELF header. */ in get_shnum()
191 /* Get the number of sections from the ELF header. */ in get_shnum()
246 /* Create descriptor for ELF file in memory. */
247 static Elf *
249 off_t offset, size_t maxsize, Elf_Cmd cmd, Elf *parent) in file_read_elf()
282 Elf *elf = allocate_elf (fildes, map_address, offset, maxsize, cmd, parent, in file_read_elf() local
284 if (elf == NULL) in file_read_elf()
289 assert (offsetof (struct Elf, state.elf32.scns) in file_read_elf()
290 == offsetof (struct Elf, state.elf64.scns)); in file_read_elf()
291 elf->state.elf32.scns.cnt = scncnt; in file_read_elf()
292 elf->state.elf32.scns.max = scnmax; in file_read_elf()
295 elf->state.elf.scnincr = 10; in file_read_elf()
298 elf->class = e_ident[EI_CLASS]; in file_read_elf()
316 elf->state.elf32.ehdr = ehdr; in file_read_elf()
323 free (elf); in file_read_elf()
327 elf->state.elf32.shdr in file_read_elf()
335 elf->state.elf32.scns.data[cnt].index = cnt; in file_read_elf()
336 elf->state.elf32.scns.data[cnt].elf = elf; in file_read_elf()
337 elf->state.elf32.scns.data[cnt].shdr.e32 = in file_read_elf()
338 &elf->state.elf32.shdr[cnt]; in file_read_elf()
339 if (likely (elf->state.elf32.shdr[cnt].sh_offset < maxsize) in file_read_elf()
340 && likely (elf->state.elf32.shdr[cnt].sh_size in file_read_elf()
341 <= maxsize - elf->state.elf32.shdr[cnt].sh_offset)) in file_read_elf()
342 elf->state.elf32.scns.data[cnt].rawdata_base = in file_read_elf()
343 elf->state.elf32.scns.data[cnt].data_base = in file_read_elf()
345 + elf->state.elf32.shdr[cnt].sh_offset); in file_read_elf()
346 elf->state.elf32.scns.data[cnt].list = &elf->state.elf32.scns; in file_read_elf()
351 if (elf->state.elf32.shdr[cnt].sh_type == SHT_SYMTAB_SHNDX in file_read_elf()
352 && elf->state.elf32.shdr[cnt].sh_link < scncnt) in file_read_elf()
353 elf->state.elf32.scns.data[elf->state.elf32.shdr[cnt].sh_link].shndx_index in file_read_elf()
358 if (elf->state.elf32.scns.data[cnt].shndx_index == 0) in file_read_elf()
359 elf->state.elf32.scns.data[cnt].shndx_index = -1; in file_read_elf()
364 /* Copy the ELF header. */ in file_read_elf()
365 elf->state.elf32.ehdr = memcpy (&elf->state.elf32.ehdr_mem, e_ident, in file_read_elf()
370 CONVERT (elf->state.elf32.ehdr_mem.e_type); in file_read_elf()
371 CONVERT (elf->state.elf32.ehdr_mem.e_machine); in file_read_elf()
372 CONVERT (elf->state.elf32.ehdr_mem.e_version); in file_read_elf()
373 CONVERT (elf->state.elf32.ehdr_mem.e_entry); in file_read_elf()
374 CONVERT (elf->state.elf32.ehdr_mem.e_phoff); in file_read_elf()
375 CONVERT (elf->state.elf32.ehdr_mem.e_shoff); in file_read_elf()
376 CONVERT (elf->state.elf32.ehdr_mem.e_flags); in file_read_elf()
377 CONVERT (elf->state.elf32.ehdr_mem.e_ehsize); in file_read_elf()
378 CONVERT (elf->state.elf32.ehdr_mem.e_phentsize); in file_read_elf()
379 CONVERT (elf->state.elf32.ehdr_mem.e_phnum); in file_read_elf()
380 CONVERT (elf->state.elf32.ehdr_mem.e_shentsize); in file_read_elf()
381 CONVERT (elf->state.elf32.ehdr_mem.e_shnum); in file_read_elf()
382 CONVERT (elf->state.elf32.ehdr_mem.e_shstrndx); in file_read_elf()
387 elf->state.elf32.scns.data[cnt].index = cnt; in file_read_elf()
388 elf->state.elf32.scns.data[cnt].elf = elf; in file_read_elf()
389 elf->state.elf32.scns.data[cnt].list = &elf->state.elf32.scns; in file_read_elf()
394 elf->state.elf32.scns_last = &elf->state.elf32.scns; in file_read_elf()
412 elf->state.elf64.ehdr = ehdr; in file_read_elf()
418 elf->state.elf64.shdr in file_read_elf()
426 elf->state.elf64.scns.data[cnt].index = cnt; in file_read_elf()
427 elf->state.elf64.scns.data[cnt].elf = elf; in file_read_elf()
428 elf->state.elf64.scns.data[cnt].shdr.e64 = in file_read_elf()
429 &elf->state.elf64.shdr[cnt]; in file_read_elf()
430 if (likely (elf->state.elf64.shdr[cnt].sh_offset < maxsize) in file_read_elf()
431 && likely (elf->state.elf64.shdr[cnt].sh_size in file_read_elf()
432 <= maxsize - elf->state.elf64.shdr[cnt].sh_offset)) in file_read_elf()
433 elf->state.elf64.scns.data[cnt].rawdata_base = in file_read_elf()
434 elf->state.elf64.scns.data[cnt].data_base = in file_read_elf()
436 + elf->state.elf64.shdr[cnt].sh_offset); in file_read_elf()
437 elf->state.elf64.scns.data[cnt].list = &elf->state.elf64.scns; in file_read_elf()
442 if (elf->state.elf64.shdr[cnt].sh_type == SHT_SYMTAB_SHNDX in file_read_elf()
443 && elf->state.elf64.shdr[cnt].sh_link < scncnt) in file_read_elf()
444 elf->state.elf64.scns.data[elf->state.elf64.shdr[cnt].sh_link].shndx_index in file_read_elf()
449 if (elf->state.elf64.scns.data[cnt].shndx_index == 0) in file_read_elf()
450 elf->state.elf64.scns.data[cnt].shndx_index = -1; in file_read_elf()
455 /* Copy the ELF header. */ in file_read_elf()
456 elf->state.elf64.ehdr = memcpy (&elf->state.elf64.ehdr_mem, e_ident, in file_read_elf()
461 CONVERT (elf->state.elf64.ehdr_mem.e_type); in file_read_elf()
462 CONVERT (elf->state.elf64.ehdr_mem.e_machine); in file_read_elf()
463 CONVERT (elf->state.elf64.ehdr_mem.e_version); in file_read_elf()
464 CONVERT (elf->state.elf64.ehdr_mem.e_entry); in file_read_elf()
465 CONVERT (elf->state.elf64.ehdr_mem.e_phoff); in file_read_elf()
466 CONVERT (elf->state.elf64.ehdr_mem.e_shoff); in file_read_elf()
467 CONVERT (elf->state.elf64.ehdr_mem.e_flags); in file_read_elf()
468 CONVERT (elf->state.elf64.ehdr_mem.e_ehsize); in file_read_elf()
469 CONVERT (elf->state.elf64.ehdr_mem.e_phentsize); in file_read_elf()
470 CONVERT (elf->state.elf64.ehdr_mem.e_phnum); in file_read_elf()
471 CONVERT (elf->state.elf64.ehdr_mem.e_shentsize); in file_read_elf()
472 CONVERT (elf->state.elf64.ehdr_mem.e_shnum); in file_read_elf()
473 CONVERT (elf->state.elf64.ehdr_mem.e_shstrndx); in file_read_elf()
478 elf->state.elf64.scns.data[cnt].index = cnt; in file_read_elf()
479 elf->state.elf64.scns.data[cnt].elf = elf; in file_read_elf()
480 elf->state.elf64.scns.data[cnt].list = &elf->state.elf64.scns; in file_read_elf()
485 elf->state.elf64.scns_last = &elf->state.elf64.scns; in file_read_elf()
488 return elf; in file_read_elf()
492 Elf *
495 size_t maxsize, Elf_Cmd cmd, Elf *parent) in __libelf_read_mmaped_file()
497 /* We have to find out what kind of file this is. We handle ELF in __libelf_read_mmaped_file()
499 header. The header for an ELF file is EI_NIDENT bytes in size, in __libelf_read_mmaped_file()
526 static Elf *
528 Elf *parent) in read_unmmaped_file()
530 /* We have to find out what kind of file this is. We handle ELF in read_unmmaped_file()
532 header. The identification header for an ELF file is EI_NIDENT in read_unmmaped_file()
533 bytes in size, but we read the whole ELF header since we will in read_unmmaped_file()
569 /* Make sure at least the ELF header is contained in the file. */ in read_unmmaped_file()
588 static struct Elf *
590 Elf_Cmd cmd, Elf *parent) in read_file()
639 struct Elf *result = __libelf_read_mmaped_file (fildes, map_address, in read_file()
664 read_long_names (Elf *elf) in read_long_names() argument
674 if (elf->map_address != NULL) in read_long_names()
676 if ((size_t) offset > elf->maximum_size in read_long_names()
677 || elf->maximum_size - offset < sizeof (struct ar_hdr)) in read_long_names()
681 hdr = (struct ar_hdr *) (elf->map_address + offset); in read_long_names()
686 if (unlikely (pread_retry (elf->fildes, &hdrm, sizeof (hdrm), in read_long_names()
687 elf->start_offset + offset) in read_long_names()
710 if (elf->map_address != NULL) in read_long_names()
712 if (len > elf->maximum_size - offset - sizeof (struct ar_hdr)) in read_long_names()
715 elf->state.ar.long_names = (char *) memcpy (newp, in read_long_names()
716 elf->map_address + offset in read_long_names()
722 if (unlikely ((size_t) pread_retry (elf->fildes, newp, len, in read_long_names()
723 elf->start_offset + offset in read_long_names()
730 elf->state.ar.long_names = NULL; in read_long_names()
733 elf->state.ar.long_names = newp; in read_long_names()
736 elf->state.ar.long_names_len = len; in read_long_names()
771 __libelf_next_arhdr_wrlock (elf) in __libelf_next_arhdr_wrlock() argument
772 Elf *elf; in __libelf_next_arhdr_wrlock()
777 if (elf->map_address != NULL)
780 if (unlikely ((size_t) elf->state.ar.offset
781 > elf->start_offset + elf->maximum_size
782 || (elf->start_offset + elf->maximum_size
783 - elf->state.ar.offset) < sizeof (struct ar_hdr)))
789 ar_hdr = (struct ar_hdr *) (elf->map_address + elf->state.ar.offset);
793 ar_hdr = &elf->state.ar.ar_hdr;
795 if (unlikely (pread_retry (elf->fildes, ar_hdr, sizeof (struct ar_hdr),
796 elf->state.ar.offset)
814 *((char *) mempcpy (elf->state.ar.raw_name, ar_hdr->ar_name, 16)) = '\0';
816 elf_ar_hdr = &elf->state.ar.elf_ar_hdr;
825 elf_ar_hdr->ar_name = memcpy (elf->state.ar.ar_name, "/", 2);
829 elf_ar_hdr->ar_name = memcpy (elf->state.ar.ar_name, "/SYM64/", 8);
833 elf_ar_hdr->ar_name = memcpy (elf->state.ar.ar_name, "//", 3);
840 if (unlikely (elf->state.ar.long_names == NULL
841 && read_long_names (elf) == NULL))
850 if (unlikely (offset >= elf->state.ar.long_names_len))
856 elf_ar_hdr->ar_name = elf->state.ar.long_names + offset;
870 endp = (char *) memccpy (elf->state.ar.ar_name, ar_hdr->ar_name,
880 elf->state.ar.ar_name[i] = '\0';
881 while (i > 0 && elf->state.ar.ar_name[--i] == ' ');
884 elf_ar_hdr->ar_name = elf->state.ar.ar_name;
929 maxsize = elf->maximum_size - elf->state.ar.offset - sizeof (struct ar_hdr);
940 static Elf *
941 dup_elf (int fildes, Elf_Cmd cmd, Elf *ref) in dup_elf()
943 struct Elf *result; in dup_elf()
1003 static struct Elf *
1006 /* We simply create an empty `Elf' structure. */ in write_file()
1008 Elf *result = allocate_elf (fd, NULL, 0, 0, cmd, NULL, ELF_K_ELF, in write_file()
1017 result->state.elf.scnincr = NSCNSALLOC; in write_file()
1020 assert (offsetof (struct Elf, state.elf32.scns) in write_file()
1021 == offsetof (struct Elf, state.elf64.scns)); in write_file()
1022 result->state.elf.scns_last = &result->state.elf32.scns; in write_file()
1031 Elf *
1035 Elf *ref;
1037 Elf *retval;
1056 Elf *lock_dup_elf ()