- (((sec_hdr->sh_flags & SHF_TLS) == 0 \
- || sec_hdr->sh_type != SHT_NOBITS \
- || segment->p_type == PT_TLS) ? sec_hdr->sh_size : 0)
-
-/* Decide if the given sec_hdr is in the given segment. PT_TLS segment
- contains only SHF_TLS sections. Only PT_LOAD, PT_GNU_RELRO and
- and PT_TLS segments can contain SHF_TLS sections. */
-#define ELF_IS_SECTION_IN_SEGMENT(sec_hdr, segment) \
- (((((sec_hdr->sh_flags & SHF_TLS) != 0) \
- && (segment->p_type == PT_TLS \
- || segment->p_type == PT_GNU_RELRO \
- || segment->p_type == PT_LOAD)) \
- || ((sec_hdr->sh_flags & SHF_TLS) == 0 \
- && segment->p_type != PT_TLS \
- && segment->p_type != PT_PHDR)) \
- /* Any section besides one of type SHT_NOBITS must have a file \
- offset within the segment. */ \
- && (sec_hdr->sh_type == SHT_NOBITS \
- || ((bfd_vma) sec_hdr->sh_offset >= segment->p_offset \
- && (sec_hdr->sh_offset + ELF_SECTION_SIZE(sec_hdr, segment) \
- <= segment->p_offset + segment->p_filesz))) \
- /* SHF_ALLOC sections must have VMAs within the segment. Be \
- careful about segments right at the end of memory. */ \
- && ((sec_hdr->sh_flags & SHF_ALLOC) == 0 \
- || (sec_hdr->sh_addr >= segment->p_vaddr \
- && (sec_hdr->sh_addr - segment->p_vaddr \
- + ELF_SECTION_SIZE(sec_hdr, segment) <= segment->p_memsz))))
-
-/* Decide if the given sec_hdr is in the given segment in file. */
-#define ELF_IS_SECTION_IN_SEGMENT_FILE(sec_hdr, segment) \
- (sec_hdr->sh_size > 0 \
- && ELF_IS_SECTION_IN_SEGMENT (sec_hdr, segment))
-
-/* Decide if the given sec_hdr is in the given segment in memory. */
-#define ELF_IS_SECTION_IN_SEGMENT_MEMORY(sec_hdr, segment) \
- (ELF_SECTION_SIZE(sec_hdr, segment) > 0 \
- && ELF_IS_SECTION_IN_SEGMENT (sec_hdr, segment))
+ (ELF_TBSS_SPECIAL(sec_hdr, segment) ? 0 : (sec_hdr)->sh_size)
+
+/* Decide if the section SEC_HDR is in SEGMENT. If CHECK_VMA, then
+ VMAs are checked for alloc sections. If STRICT, then a zero size
+ section won't match at the end of a segment, unless the segment
+ is also zero size. Regardless of STRICT and CHECK_VMA, zero size
+ sections won't match at the start or end of PT_DYNAMIC nor PT_NOTE,
+ unless PT_DYNAMIC and PT_NOTE are themselves zero sized. */
+#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_STACK \
+ || (segment)->p_type == PT_GNU_RELRO \
+ || ((segment)->p_type >= PT_GNU_MBIND_LO \
+ && (segment)->p_type <= PT_GNU_MBIND_HI))) \
+ /* 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 \
+ + 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 \
+ + ELF_SECTION_SIZE(sec_hdr, segment)) \
+ <= (segment)->p_memsz))) \
+ /* No zero size sections at start or end of PT_DYNAMIC nor \
+ PT_NOTE. */ \
+ && (((segment)->p_type != PT_DYNAMIC \
+ && (segment)->p_type != PT_NOTE) \
+ || (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))))))
+
+#define ELF_SECTION_IN_SEGMENT(sec_hdr, segment) \
+ (ELF_SECTION_IN_SEGMENT_1 (sec_hdr, segment, 1, 0))
+
+#define ELF_SECTION_IN_SEGMENT_STRICT(sec_hdr, segment) \
+ (ELF_SECTION_IN_SEGMENT_1 (sec_hdr, segment, 1, 1))