Inconsistent .eh_frame_hdr on powerpc64
[deliverable/binutils-gdb.git] / bfd / elf-properties.c
index a0456f8df9fadf5c5bf8dc66bc237f372732f808..bfb106edc92d1f80035f40ac32e419a9f495ee98 100644 (file)
@@ -88,23 +88,28 @@ _bfd_elf_parse_gnu_properties (bfd *abfd, Elf_Internal_Note *note)
     {
 bad_size:
       _bfd_error_handler
-       (_("warning: %B: corrupt GNU_PROPERTY_TYPE (%ld) size: %#lx\n"),
+       (_("warning: %B: corrupt GNU_PROPERTY_TYPE (%ld) size: %#lx"),
         abfd, note->type, note->descsz);
       return FALSE;
     }
 
-  while (1)
+  while (ptr != ptr_end)
     {
-      unsigned int type = bfd_h_get_32 (abfd, ptr);
-      unsigned int datasz = bfd_h_get_32 (abfd, ptr + 4);
+      unsigned int type;
+      unsigned int datasz;
       elf_property *prop;
 
+      if ((size_t) (ptr_end - ptr) < 8)
+       goto bad_size;
+
+      type = bfd_h_get_32 (abfd, ptr);
+      datasz = bfd_h_get_32 (abfd, ptr + 4);
       ptr += 8;
 
-      if ((ptr + datasz) > ptr_end)
+      if (datasz > (size_t) (ptr_end - ptr))
        {
          _bfd_error_handler
-           (_("warning: %B: corrupt GNU_PROPERTY_TYPE (%ld) type (0x%x) datasz: 0x%x\n"),
+           (_("warning: %B: corrupt GNU_PROPERTY_TYPE (%ld) type (0x%x) datasz: 0x%x"),
             abfd, note->type, type, datasz);
          /* Clear all properties.  */
          elf_properties (abfd) = NULL;
@@ -113,7 +118,15 @@ bad_size:
 
       if (type >= GNU_PROPERTY_LOPROC)
        {
-         if (type < GNU_PROPERTY_LOUSER && bed->parse_gnu_properties)
+         if (bed->elf_machine_code == EM_NONE)
+           {
+             /* Ignore processor-specific properties with generic ELF
+                target vector.  They should be handled by the matching
+                ELF target vector.  */
+             goto next;
+           }
+         else if (type < GNU_PROPERTY_LOUSER
+                  && bed->parse_gnu_properties)
            {
              enum elf_property_kind kind
                = bed->parse_gnu_properties (abfd, type, ptr, datasz);
@@ -135,7 +148,7 @@ bad_size:
              if (datasz != align_size)
                {
                  _bfd_error_handler
-                   (_("warning: %B: corrupt stack size: 0x%x\n"),
+                   (_("warning: %B: corrupt stack size: 0x%x"),
                     abfd, datasz);
                  /* Clear all properties.  */
                  elf_properties (abfd) = NULL;
@@ -153,13 +166,14 @@ bad_size:
              if (datasz != 0)
                {
                  _bfd_error_handler
-                   (_("warning: %B: corrupt no copy on protected size: 0x%x\n"),
+                   (_("warning: %B: corrupt no copy on protected size: 0x%x"),
                     abfd, datasz);
                  /* Clear all properties.  */
                  elf_properties (abfd) = NULL;
                  return FALSE;
                }
              prop = _bfd_elf_get_property (abfd, type, datasz);
+             elf_has_no_copy_on_protected (abfd) = TRUE;
              prop->pr_kind = property_number;
              goto next;
 
@@ -169,16 +183,11 @@ bad_size:
        }
 
       _bfd_error_handler
-       (_("warning: %B: unsupported GNU_PROPERTY_TYPE (%ld) type: 0x%x\n"),
+       (_("warning: %B: unsupported GNU_PROPERTY_TYPE (%ld) type: 0x%x"),
         abfd, note->type, type);
 
 next:
       ptr += (datasz + (align_size - 1)) & ~ (align_size - 1);
-      if (ptr == ptr_end)
-       break;
-
-      if (ptr > (ptr_end - 8))
-       goto bad_size;
     }
 
   return TRUE;
@@ -189,8 +198,8 @@ next:
    with ABFD.  */
 
 static bfd_boolean
-elf_merge_gnu_properties (bfd *abfd, elf_property *aprop,
-                         elf_property *bprop)
+elf_merge_gnu_properties (struct bfd_link_info *info, bfd *abfd,
+                         elf_property *aprop, elf_property *bprop)
 {
   const struct elf_backend_data *bed = get_elf_backend_data (abfd);
   unsigned int pr_type = aprop != NULL ? aprop->pr_type : bprop->pr_type;
@@ -198,7 +207,7 @@ elf_merge_gnu_properties (bfd *abfd, elf_property *aprop,
   if (bed->merge_gnu_properties != NULL
       && pr_type >= GNU_PROPERTY_LOPROC
       && pr_type < GNU_PROPERTY_LOUSER)
-    return bed->merge_gnu_properties (abfd, aprop, bprop);
+    return bed->merge_gnu_properties (info, abfd, aprop, bprop);
 
   switch (pr_type)
     {
@@ -255,7 +264,8 @@ elf_find_and_remove_property (elf_property_list **listp,
 /* Merge GNU property list *LISTP with ABFD.  */
 
 static void
-elf_merge_gnu_property_list (bfd *abfd, elf_property_list **listp)
+elf_merge_gnu_property_list (struct bfd_link_info *info, bfd *abfd,
+                            elf_property_list **listp)
 {
   elf_property_list *p, **lastp;
   elf_property *pr;
@@ -267,7 +277,7 @@ elf_merge_gnu_property_list (bfd *abfd, elf_property_list **listp)
       pr = elf_find_and_remove_property (listp, p->property.pr_type);
       /* Pass NULL to elf_merge_gnu_properties for the property which
         isn't on *LISTP.  */
-      elf_merge_gnu_properties (abfd, &p->property, pr);
+      elf_merge_gnu_properties (info, abfd, &p->property, pr);
       if (p->property.pr_kind == property_remove)
        {
          /* Remove this property.  */
@@ -279,8 +289,11 @@ elf_merge_gnu_property_list (bfd *abfd, elf_property_list **listp)
 
   /* Merge the remaining properties on *LISTP with ABFD.  */
   for (p = *listp; p != NULL; p = p->next)
-    if (elf_merge_gnu_properties (abfd, NULL, &p->property))
+    if (elf_merge_gnu_properties (info, abfd, NULL, &p->property))
       {
+       if (p->property.pr_type == GNU_PROPERTY_NO_COPY_ON_PROTECTED)
+         elf_has_no_copy_on_protected (abfd) = TRUE;
+
        pr = _bfd_elf_get_property (abfd, p->property.pr_type,
                                    p->property.pr_datasz);
        /* It must be a new property.  */
@@ -291,9 +304,10 @@ elf_merge_gnu_property_list (bfd *abfd, elf_property_list **listp)
       }
 }
 
-/* Set up GNU properties.  */
+/* Set up GNU properties.  Return the first relocatable ELF input with
+   GNU properties if found.  Otherwise, return NULL.  */
 
-void
+bfd *
 _bfd_elf_link_setup_gnu_properties (struct bfd_link_info *info)
 {
   bfd *abfd, *first_pbfd = NULL;
@@ -308,7 +322,7 @@ _bfd_elf_link_setup_gnu_properties (struct bfd_link_info *info)
   /* Find the first relocatable ELF input with GNU properties.  */
   for (abfd = info->input_bfds; abfd != NULL; abfd = abfd->link.next)
     if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
-       && bfd_count_sections (abfd) != 0
+       && (abfd->flags & DYNAMIC) == 0
        && elf_properties (abfd) != NULL)
       {
        has_properties = TRUE;
@@ -328,11 +342,11 @@ _bfd_elf_link_setup_gnu_properties (struct bfd_link_info *info)
 
   /* Do nothing if there is no .note.gnu.property section.  */
   if (!has_properties)
-    return;
+    return NULL;
 
   /* Merge .note.gnu.property sections.  */
   for (abfd = info->input_bfds; abfd != NULL; abfd = abfd->link.next)
-    if (abfd != first_pbfd && bfd_count_sections (abfd) != 0)
+    if (abfd != first_pbfd && (abfd->flags & DYNAMIC) == 0)
       {
        elf_property_list *null_ptr = NULL;
        elf_property_list **listp = &null_ptr;
@@ -356,7 +370,7 @@ _bfd_elf_link_setup_gnu_properties (struct bfd_link_info *info)
           when all properties are from ELF objects with different
           machine code or class.  */
        if (first_pbfd != NULL)
-         elf_merge_gnu_property_list (first_pbfd, listp);
+         elf_merge_gnu_property_list (info, first_pbfd, listp);
 
        if (list != NULL)
          {
@@ -403,7 +417,7 @@ _bfd_elf_link_setup_gnu_properties (struct bfd_link_info *info)
          /* Discard .note.gnu.property section if all properties have
             been removed.  */
          sec->output_section = bfd_abs_section_ptr;
-         return;
+         return NULL;
        }
 
       /* Compute the section size.  */
@@ -479,5 +493,12 @@ _bfd_elf_link_setup_gnu_properties (struct bfd_link_info *info)
 
       /* Cache the section contents for elf_link_input_bfd.  */
       elf_section_data (sec)->this_hdr.contents = contents;
+
+      /* If GNU_PROPERTY_NO_COPY_ON_PROTECTED is set, protected data
+        symbol is defined in the shared object.  */
+      if (elf_has_no_copy_on_protected (first_pbfd))
+       info->extern_protected_data = FALSE;
     }
+
+  return first_pbfd;
 }
This page took 0.029922 seconds and 4 git commands to generate.