package linksem

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

gnu_ext_section_to_segment_mapping contains (GNU specific) functionality * relating to calculating the section to segment mapping for an ELF file. In * particular, the test over whether a section is inside a segment is ABI * specific. This module provides that test.

elf32_section_in_segment sec_hdr segment implements the * ELF_SECTION_IN_SEGMENT1 macro from readelf. Note the macro is always used * with check_vma and strict set to 1. * #define ELF_SECTION_IN_SEGMENT_1(sec_hdr, segment, check_vma, strict) \ ((/* Only PT_LOAD, PT_GNU_RELRO and PT_TLS segments can contain \ SHF_TLS sections. */ \ ((((sec_hdr)->sh_flags & SHF_TLS) != 0) \ && ((segment)->p_type == PT_TLS \ || (segment)->p_type == PT_GNU_RELRO \ || (segment)->p_type == PT_LOAD)) \ /* PT_TLS segment contains only SHF_TLS sections, PT_PHDR no \ sections at all. */ \ || (((sec_hdr)->sh_flags & SHF_TLS) == 0 \ && (segment)->p_type != PT_TLS \ && (segment)->p_type != PT_PHDR)) \ /* PT_LOAD and similar segments only have SHF_ALLOC sections. */ \ && !(((sec_hdr)->sh_flags & SHF_ALLOC) == 0 \ && ((segment)->p_type == PT_LOAD \ || (segment)->p_type == PT_DYNAMIC \ || (segment)->p_type == PT_GNU_EH_FRAME \ || (segment)->p_type == PT_GNU_RELRO \ || (segment)->p_type == PT_GNU_STACK)) \ /* Any section besides one of type SHT_NOBITS must have file \ offsets within the segment. */ \ && ((sec_hdr)->sh_type == SHT_NOBITS \ || ((bfd_vma) (sec_hdr)->sh_offset >= (segment)->p_offset \ && (!(strict) \ || ((sec_hdr)->sh_offset - (segment)->p_offset \ <= (segment)->p_filesz - 1)) \ && (((sec_hdr)->sh_offset - (segment)->p_offset \

  1. ELF_SECTION_SIZE(sec_hdr, segment)) \ <= (segment)->p_filesz))) \ /* SHF_ALLOC sections must have VMAs within the segment. */ \ && (!(check_vma) \ || ((sec_hdr)->sh_flags & SHF_ALLOC) == 0 \ || ((sec_hdr)->sh_addr >= (segment)->p_vaddr \ && (!(strict) \ || ((sec_hdr)->sh_addr - (segment)->p_vaddr \ <= (segment)->p_memsz - 1)) \ && (((sec_hdr)->sh_addr - (segment)->p_vaddr \
  2. ELF_SECTION_SIZE(sec_hdr, segment)) \ <= (segment)->p_memsz))) \ /* No zero size sections at start or end of PT_DYNAMIC. */ \ && ((segment)->p_type != PT_DYNAMIC \ || (sec_hdr)->sh_size != 0 \ || (segment)->p_memsz == 0 \ || (((sec_hdr)->sh_type == SHT_NOBITS \ || ((bfd_vma) (sec_hdr)->sh_offset > (segment)->p_offset \ && ((sec_hdr)->sh_offset - (segment)->p_offset \ < (segment)->p_filesz))) \ && (((sec_hdr)->sh_flags & SHF_ALLOC) == 0 \ || ((sec_hdr)->sh_addr > (segment)->p_vaddr \ && ((sec_hdr)->sh_addr - (segment)->p_vaddr \ < (segment)->p_memsz)))))) * * From internal.h of readelf's source code.

Only PT_LOAD, PT_GNU_RELRO and PT_TLS segments can contain SHF_TLS sections * and PT_TLS segment contains only SHF_TLS sections, PT_PHDR no sections at all

PT_LOAD and similar segments only have SHF_ALLOC sections

Any section besides one of type SHT_NOBITS must have file offsets within * the segment.

SHF_ALLOC sections must have VMAs within the segment

No zero size sections at start or end of PT_DYNAMIC

The final section in segment tests, bringing all the above together.

OCaml

Innovation. Community. Security.