PR4499, assign file positions assumes segment offsets increasing
[deliverable/binutils-gdb.git] / include / elf / internal.h
index 6998ae03c4523430e10e12faa4a520dbc19c9a3d..794c16812eea6c3cb6acda720203920549364500 100644 (file)
@@ -1,6 +1,5 @@
 /* ELF support for BFD.
-   Copyright 1991, 1992, 1993, 1994, 1995, 1997, 1998, 2000, 2001, 2002,
-   2003, 2006, 2007, 2008, 2010 Free Software Foundation, Inc.
+   Copyright (C) 1991-2019 Free Software Foundation, Inc.
 
    Written by Fred Fish @ Cygnus Support, from information published
    in "UNIX System V Release 4, Programmers Guide: ANSI C and
@@ -116,6 +115,14 @@ typedef struct elf_internal_shdr {
   unsigned char *contents;             /* Section contents.  */
 } Elf_Internal_Shdr;
 
+/* Compression header */
+
+typedef struct elf_internal_chdr {
+  unsigned int ch_type;                /* Type of compression */
+  bfd_size_type        ch_size;                /* Size of uncompressed data in bytes */
+  bfd_vma      ch_addralign;           /* Alignment of uncompressed data */
+} Elf_Internal_Chdr;
+
 /* Symbol table entry */
 
 struct elf_internal_sym {
@@ -124,6 +131,7 @@ struct elf_internal_sym {
   unsigned long        st_name;                /* Symbol name, index in string tbl */
   unsigned char        st_info;                /* Type and binding attributes */
   unsigned char        st_other;               /* Visibilty, and target specific */
+  unsigned char st_target_internal;    /* Internal-only information */
   unsigned int  st_shndx;              /* Associated section index */
 };
 
@@ -265,8 +273,6 @@ struct elf_segment_map
   bfd_vma p_align;
   /* Segment size in file and memory */
   bfd_vma p_size;
-  /* Required size of filehdr + phdrs, if non-zero */
-  bfd_vma header_size;
   /* Whether the p_flags field is valid; if not, the flags are based
      on the section flags.  */
   unsigned int p_flags_valid : 1;
@@ -283,6 +289,13 @@ struct elf_segment_map
   unsigned int includes_filehdr : 1;
   /* Whether this segment includes the program headers.  */
   unsigned int includes_phdrs : 1;
+  /* Assume this PT_LOAD header has an lma of zero when sorting
+     headers before assigning file offsets.  PT_LOAD headers with this
+     flag set are placed after one with includes_filehdr set, and
+     before PT_LOAD headers without this flag set.  */
+  unsigned int no_sort_lma : 1;
+  /* Index holding original order before sorting segments.  */
+  unsigned int idx;
   /* Number of sections (may be 0).  */
   unsigned int count;
   /* Sections.  Actual number of elements is in count field.  */
@@ -302,7 +315,9 @@ struct elf_segment_map
 /* 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.  */
+   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.  */                                           \
@@ -315,6 +330,15 @@ struct elf_segment_map
     || (((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                                        \
@@ -334,7 +358,21 @@ struct elf_segment_map
                   <= (segment)->p_memsz - 1))                          \
           && (((sec_hdr)->sh_addr - (segment)->p_vaddr                 \
                + ELF_SECTION_SIZE(sec_hdr, segment))                   \
-              <= (segment)->p_memsz))))
+              <= (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))
This page took 0.033441 seconds and 4 git commands to generate.