summaryrefslogtreecommitdiffstats
path: root/libdwfl
diff options
context:
space:
mode:
authorTimm Bäder <tbaeder@redhat.com>2020-11-23 13:27:12 +0100
committerMark Wielaard <mark@klomp.org>2020-11-25 16:54:43 +0100
commit64dc5374b7e12a1ee95af6e1e91249dc2410878b (patch)
tree5dc3673f87eda598bf45883d37bb7ba547c47ca8 /libdwfl
parentsegment_report_module: Inline consider_dyn() into only caller (diff)
downloadelfutils-64dc5374b7e12a1ee95af6e1e91249dc2410878b.tar.gz
elfutils-64dc5374b7e12a1ee95af6e1e91249dc2410878b.tar.bz2
elfutils-64dc5374b7e12a1ee95af6e1e91249dc2410878b.tar.xz
segment_report_module: Inline consider_phdr() into only caller
Get rid of the nested function this way Signed-off-by: Timm Bäder <tbaeder@redhat.com>
Diffstat (limited to 'libdwfl')
-rw-r--r--libdwfl/ChangeLog5
-rw-r--r--libdwfl/dwfl_segment_report_module.c135
2 files changed, 69 insertions, 71 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 88f0714e..889e3ee8 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,6 +1,11 @@
12020-11-23 Timm Bäder <tbaeder@redhat.com> 12020-11-23 Timm Bäder <tbaeder@redhat.com>
2 2
3 * segment_report_module.c (dwfl_segment_report_module): Remove 3 * segment_report_module.c (dwfl_segment_report_module): Remove
4 consider_phdr, do checks inline.
5
62020-11-23 Timm Bäder <tbaeder@redhat.com>
7
8 * segment_report_module.c (dwfl_segment_report_module): Remove
4 consider_dyn, do checks inline. 9 consider_dyn, do checks inline.
5 10
62020-11-23 Timm Bäder <tbaeder@redhat.com> 112020-11-23 Timm Bäder <tbaeder@redhat.com>
diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c
index a1051e1e..7e747184 100644
--- a/libdwfl/dwfl_segment_report_module.c
+++ b/libdwfl/dwfl_segment_report_module.c
@@ -357,7 +357,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
357 /* NOTE if the number of sections is > 0xff00 then e_shnum 357 /* NOTE if the number of sections is > 0xff00 then e_shnum
358 is zero and the actual number would come from the section 358 is zero and the actual number would come from the section
359 zero sh_size field. We ignore this here because getting shdrs 359 zero sh_size field. We ignore this here because getting shdrs
360 is just a nice bonus (see below in consider_phdr PT_LOAD 360 is just a nice bonus (see below in the type == PT_LOAD case
361 where we trim the last segment). */ 361 where we trim the last segment). */
362 shdrs_end = ehdr.e32.e_shoff + ehdr.e32.e_shnum * ehdr.e32.e_shentsize; 362 shdrs_end = ehdr.e32.e_shoff + ehdr.e32.e_shnum * ehdr.e32.e_shentsize;
363 break; 363 break;
@@ -522,75 +522,6 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
522 finish_portion (&data, &data_size); 522 finish_portion (&data, &data_size);
523 } 523 }
524 524
525 /* Consider each of the program headers we've read from the image. */
526 inline void consider_phdr (GElf_Word type,
527 GElf_Addr vaddr, GElf_Xword memsz,
528 GElf_Off offset, GElf_Xword filesz,
529 GElf_Xword align)
530 {
531 switch (type)
532 {
533 case PT_DYNAMIC:
534 dyn_vaddr = vaddr;
535 dyn_filesz = filesz;
536 break;
537
538 case PT_NOTE:
539 /* We calculate from the p_offset of the note segment,
540 because we don't yet know the bias for its p_vaddr. */
541 consider_notes (start + offset, filesz, align);
542 break;
543
544 case PT_LOAD:
545 align = dwfl->segment_align > 1 ? dwfl->segment_align : align ?: 1;
546
547 GElf_Addr vaddr_end = (vaddr + memsz + align - 1) & -align;
548 GElf_Addr filesz_vaddr = filesz < memsz ? vaddr + filesz : vaddr_end;
549 GElf_Off filesz_offset = filesz_vaddr - vaddr + offset;
550
551 if (file_trimmed_end < offset + filesz)
552 {
553 file_trimmed_end = offset + filesz;
554
555 /* Trim the last segment so we don't bother with zeros
556 in the last page that are off the end of the file.
557 However, if the extra bit in that page includes the
558 section headers, keep them. */
559 if (shdrs_end <= filesz_offset && shdrs_end > file_trimmed_end)
560 {
561 filesz += shdrs_end - file_trimmed_end;
562 file_trimmed_end = shdrs_end;
563 }
564 }
565
566 total_filesz += filesz;
567
568 if (file_end < filesz_offset)
569 {
570 file_end = filesz_offset;
571 if (filesz_vaddr - start == filesz_offset)
572 contiguous = file_end;
573 }
574
575 if (!found_bias && (offset & -align) == 0
576 && likely (filesz_offset >= phoff + phnum * phentsize))
577 {
578 bias = start - vaddr;
579 found_bias = true;
580 }
581
582 if ((vaddr & -align) < module_start)
583 {
584 module_start = vaddr & -align;
585 module_address_sync = vaddr + memsz;
586 }
587
588 if (module_end < vaddr_end)
589 module_end = vaddr_end;
590 break;
591 }
592 }
593
594 Elf32_Phdr *p32 = phdrsp; 525 Elf32_Phdr *p32 = phdrsp;
595 Elf64_Phdr *p64 = phdrsp; 526 Elf64_Phdr *p64 = phdrsp;
596 if ((ei_class == ELFCLASS32 527 if ((ei_class == ELFCLASS32
@@ -602,6 +533,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
602 } 533 }
603 else 534 else
604 { 535 {
536 /* Consider each of the program headers we've read from the image. */
605 for (uint_fast16_t i = 0; i < phnum; ++i) 537 for (uint_fast16_t i = 0; i < phnum; ++i)
606 { 538 {
607 bool is32 = (ei_class == ELFCLASS32); 539 bool is32 = (ei_class == ELFCLASS32);
@@ -612,7 +544,68 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
612 GElf_Xword filesz = is32 ? p32[i].p_filesz : p64[i].p_filesz; 544 GElf_Xword filesz = is32 ? p32[i].p_filesz : p64[i].p_filesz;
613 GElf_Xword align = is32 ? p32[i].p_align : p64[i].p_align; 545 GElf_Xword align = is32 ? p32[i].p_align : p64[i].p_align;
614 546
615 consider_phdr (type, vaddr, memsz, offset, filesz, align); 547 if (type == PT_DYNAMIC)
548 {
549 dyn_vaddr = vaddr;
550 dyn_filesz = filesz;
551 }
552 else if (type == PT_NOTE)
553 {
554 /* We calculate from the p_offset of the note segment,
555 because we don't yet know the bias for its p_vaddr. */
556 consider_notes ( start + offset, filesz, align);
557 }
558 else if (type == PT_LOAD)
559 {
560 align = (dwfl->segment_align > 1
561 ? dwfl->segment_align : (align ?: 1));
562
563 GElf_Addr vaddr_end = (vaddr + memsz + align - 1) & -align;
564 GElf_Addr filesz_vaddr = (filesz < memsz
565 ? vaddr + filesz : vaddr_end);
566 GElf_Off filesz_offset = filesz_vaddr - vaddr + offset;
567
568 if (file_trimmed_end < offset + filesz)
569 {
570 file_trimmed_end = offset + filesz;
571
572 /* Trim the last segment so we don't bother with zeros
573 in the last page that are off the end of the file.
574 However, if the extra bit in that page includes the
575 section headers, keep them. */
576 if (shdrs_end <= filesz_offset
577 && shdrs_end > file_trimmed_end)
578 {
579 filesz += shdrs_end - file_trimmed_end;
580 file_trimmed_end = shdrs_end;
581 }
582 }
583
584 total_filesz += filesz;
585
586 if (file_end < filesz_offset)
587 {
588 file_end = filesz_offset;
589 if (filesz_vaddr - start == filesz_offset)
590 contiguous = file_end;
591 }
592
593 if (!found_bias && (offset & -align) == 0
594 && likely (filesz_offset >= phoff + phnum * phentsize))
595 {
596 bias = start - vaddr;
597 found_bias = true;
598 }
599
600 if ((vaddr & -align) < module_start)
601 {
602 module_start = vaddr & -align;
603 module_address_sync = vaddr + memsz;
604 }
605
606 if (module_end < vaddr_end)
607 module_end = vaddr_end;
608 }
616 } 609 }
617 } 610 }
618 611