402 }
403 }
404 return (ELF_READ_OKAY);
405 }
406
407 /*
408 * process_shdr: Read Section Headers to attempt to get HW/SW
409 * capabilities by looking at the SUNW_cap
410 * section and set string in Elf_Info.
411 * Also look for symbol tables and debug
412 * information sections. Set the "stripped" field
413 * in Elf_Info with corresponding flags.
414 */
415 static int
416 process_shdr(Elf_Info *EI)
417 {
418 int capn, mac;
419 int i, j, idx;
420 FILE_ELF_OFF_T cap_off;
421 FILE_ELF_SIZE_T csize;
422 char *section_name;
423 Elf_Cap Chdr;
424 Elf_Shdr *shdr = &EI_Shdr;
425
426
427 csize = sizeof (Elf_Cap);
428 mac = EI_Ehdr.e_machine;
429
430 /* if there are no sections, return success anyway */
431 if (EI_Ehdr.e_shoff == 0 && EI_Ehdr_shnum == 0)
432 return (ELF_READ_OKAY);
433
434 /* read section names from String Section */
435 if (get_shdr(EI, EI_Ehdr_shstrndx) == ELF_READ_FAIL)
436 return (ELF_READ_FAIL);
437
438 if ((section_name = malloc(shdr->sh_size)) == NULL)
439 return (ELF_READ_FAIL);
440
441 if (pread64(EI->elffd, section_name, shdr->sh_size, shdr->sh_offset)
442 != shdr->sh_size)
443 return (ELF_READ_FAIL);
444
445 /* read all the sections and process them */
446 for (idx = 1, i = 0; i < EI_Ehdr_shnum; idx++, i++) {
447 char *str;
448
449 if (get_shdr(EI, i) == ELF_READ_FAIL)
450 return (ELF_READ_FAIL);
451
452 if (shdr->sh_type == SHT_NULL) {
453 idx--;
454 continue;
455 }
456
457 cap_off = shdr->sh_offset;
458 if (shdr->sh_type == SHT_SUNW_cap) {
459 char capstr[128];
460
461 if (shdr->sh_size == 0 || shdr->sh_entsize == 0) {
462 (void) fprintf(stderr, ELF_ERR_ELFCAP1,
463 File, EI->file);
464 return (ELF_READ_FAIL);
465 }
466 capn = (shdr->sh_size / shdr->sh_entsize);
467 for (j = 0; j < capn; j++) {
521 * information (line number or debug section names,
522 * or SHT_SUNW_DEBUGSTR or SHT_SUNW_DEBUG section
523 * types) then report:
524 * "not stripped"
525 * - Symbol Table present with no debugging
526 * information (line number or debug section names,
527 * or SHT_SUNW_DEBUGSTR or SHT_SUNW_DEBUG section
528 * types) then report:
529 * "not stripped, no debugging information
530 * available"
531 */
532 if ((EI->stripped & E_NOSTRIP) == E_NOSTRIP)
533 continue;
534
535 if (!(EI->stripped & E_SYMTAB) &&
536 (shdr->sh_type == SHT_SYMTAB)) {
537 EI->stripped |= E_SYMTAB;
538 continue;
539 }
540
541 str = §ion_name[shdr->sh_name];
542
543 if (!(EI->stripped & E_DBGINF) &&
544 ((shdr->sh_type == SHT_SUNW_DEBUG) ||
545 (shdr->sh_type == SHT_SUNW_DEBUGSTR) ||
546 (is_in_list(str)))) {
547 EI->stripped |= E_DBGINF;
548 }
549 }
550 free(section_name);
551
552 return (ELF_READ_OKAY);
553 }
|
402 }
403 }
404 return (ELF_READ_OKAY);
405 }
406
407 /*
408 * process_shdr: Read Section Headers to attempt to get HW/SW
409 * capabilities by looking at the SUNW_cap
410 * section and set string in Elf_Info.
411 * Also look for symbol tables and debug
412 * information sections. Set the "stripped" field
413 * in Elf_Info with corresponding flags.
414 */
415 static int
416 process_shdr(Elf_Info *EI)
417 {
418 int capn, mac;
419 int i, j, idx;
420 FILE_ELF_OFF_T cap_off;
421 FILE_ELF_SIZE_T csize;
422 char *strtab;
423 size_t strtab_sz;
424 Elf_Cap Chdr;
425 Elf_Shdr *shdr = &EI_Shdr;
426
427
428 csize = sizeof (Elf_Cap);
429 mac = EI_Ehdr.e_machine;
430
431 /* if there are no sections, return success anyway */
432 if (EI_Ehdr.e_shoff == 0 && EI_Ehdr_shnum == 0)
433 return (ELF_READ_OKAY);
434
435 /* read section names from String Section */
436 if (get_shdr(EI, EI_Ehdr_shstrndx) == ELF_READ_FAIL)
437 return (ELF_READ_FAIL);
438
439 if ((strtab = malloc(shdr->sh_size)) == NULL)
440 return (ELF_READ_FAIL);
441
442 if (pread64(EI->elffd, strtab, shdr->sh_size, shdr->sh_offset)
443 != shdr->sh_size)
444 return (ELF_READ_FAIL);
445
446 strtab_sz = shdr->sh_size;
447
448 /* read all the sections and process them */
449 for (idx = 1, i = 0; i < EI_Ehdr_shnum; idx++, i++) {
450 char *shnam;
451
452 if (get_shdr(EI, i) == ELF_READ_FAIL)
453 return (ELF_READ_FAIL);
454
455 if (shdr->sh_type == SHT_NULL) {
456 idx--;
457 continue;
458 }
459
460 cap_off = shdr->sh_offset;
461 if (shdr->sh_type == SHT_SUNW_cap) {
462 char capstr[128];
463
464 if (shdr->sh_size == 0 || shdr->sh_entsize == 0) {
465 (void) fprintf(stderr, ELF_ERR_ELFCAP1,
466 File, EI->file);
467 return (ELF_READ_FAIL);
468 }
469 capn = (shdr->sh_size / shdr->sh_entsize);
470 for (j = 0; j < capn; j++) {
524 * information (line number or debug section names,
525 * or SHT_SUNW_DEBUGSTR or SHT_SUNW_DEBUG section
526 * types) then report:
527 * "not stripped"
528 * - Symbol Table present with no debugging
529 * information (line number or debug section names,
530 * or SHT_SUNW_DEBUGSTR or SHT_SUNW_DEBUG section
531 * types) then report:
532 * "not stripped, no debugging information
533 * available"
534 */
535 if ((EI->stripped & E_NOSTRIP) == E_NOSTRIP)
536 continue;
537
538 if (!(EI->stripped & E_SYMTAB) &&
539 (shdr->sh_type == SHT_SYMTAB)) {
540 EI->stripped |= E_SYMTAB;
541 continue;
542 }
543
544 if (shdr->sh_name >= strtab_sz)
545 shnam = NULL;
546 else
547 shnam = &strtab[shdr->sh_name];
548
549 if (!(EI->stripped & E_DBGINF) &&
550 ((shdr->sh_type == SHT_SUNW_DEBUG) ||
551 (shdr->sh_type == SHT_SUNW_DEBUGSTR) ||
552 (shnam != NULL && is_in_list(shnam)))) {
553 EI->stripped |= E_DBGINF;
554 }
555 }
556 free(strtab);
557
558 return (ELF_READ_OKAY);
559 }
|