Automatic date update in version.in
[external/binutils.git] / bfd / bfd.c
index 31bcc34..f56a8d3 100644 (file)
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -1,5 +1,5 @@
 /* Generic BFD library interface and support routines.
-   Copyright (C) 1990-2018 Free Software Foundation, Inc.
+   Copyright (C) 1990-2019 Free Software Foundation, Inc.
    Written by Cygnus Support.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -74,8 +74,9 @@ CODE_FRAGMENT
 .     least-recently-used list of BFDs.  *}
 .  struct bfd *lru_prev, *lru_next;
 .
-.  {* When a file is closed by the caching routines, BFD retains
-.     state information on the file here...  *}
+.  {* Track current file position (or current buffer offset for
+.     in-memory BFDs).  When a file is closed by the caching routines,
+.     BFD retains state information on the file here.  *}
 .  ufile_ptr where;
 .
 .  {* File modified time, if mtime_set is TRUE.  *}
@@ -219,6 +220,9 @@ CODE_FRAGMENT
 .  {* Set if this is a thin archive.  *}
 .  unsigned int is_thin_archive : 1;
 .
+.  {* Set if this archive should not cache element positions.  *}
+.  unsigned int no_element_cache : 1;
+.
 .  {* Set if only required symbols should be added in the link hash table for
 .     this object.  Used by VMS linkers.  *}
 .  unsigned int selective_search : 1;
@@ -235,6 +239,9 @@ CODE_FRAGMENT
 .  {* Set if this is a plugin output file.  *}
 .  unsigned int lto_output : 1;
 .
+.  {* Set if this is a slim LTO object not loaded with a compiler plugin.  *}
+.  unsigned int lto_slim_object : 1;
+.
 .  {* Set to dummy BFD created when claimed by a compiler plug-in
 .     library.  *}
 .  bfd *plugin_dummy_bfd;
@@ -304,20 +311,15 @@ CODE_FRAGMENT
 .    {
 .      struct aout_data_struct *aout_data;
 .      struct artdata *aout_ar_data;
-.      struct _oasys_data *oasys_obj_data;
-.      struct _oasys_ar_data *oasys_ar_data;
 .      struct coff_tdata *coff_obj_data;
 .      struct pe_tdata *pe_obj_data;
 .      struct xcoff_tdata *xcoff_obj_data;
 .      struct ecoff_tdata *ecoff_obj_data;
-.      struct ieee_data_struct *ieee_data;
-.      struct ieee_ar_data_struct *ieee_ar_data;
 .      struct srec_data_struct *srec_data;
 .      struct verilog_data_struct *verilog_data;
 .      struct ihex_data_struct *ihex_data;
 .      struct tekhex_data_struct *tekhex_data;
 .      struct elf_obj_tdata *elf_obj_data;
-.      struct nlm_obj_tdata *nlm_obj_data;
 .      struct mmo_data_struct *mmo_data;
 .      struct sun_core_struct *sun_core_data;
 .      struct sco5_core_struct *sco5_core_data;
@@ -1092,14 +1094,6 @@ _bfd_doprnt_scan (const char *format, union _bfd_doprnt_args *args)
   return arg_count;
 }
 
-/* This is the default routine to handle BFD error messages.
-   Like fprintf (stderr, ...), but also handles some extra format specifiers.
-
-   %pA section name from section.  For group components, prints group name too.
-   %pB file name from bfd.  For archive components, prints archive too.
-
-   Beware: Only supports a maximum of 9 format arguments.  */
-
 static void
 error_handler_internal (const char *fmt, va_list ap)
 {
@@ -1161,6 +1155,26 @@ error_handler_internal (const char *fmt, va_list ap)
 
 static bfd_error_handler_type _bfd_error_internal = error_handler_internal;
 
+/*
+FUNCTION
+       _bfd_error_handler
+
+SYNOPSIS
+       void _bfd_error_handler (const char *fmt, ...) ATTRIBUTE_PRINTF_1;
+
+DESCRIPTION
+       This is the default routine to handle BFD error messages.
+       Like fprintf (stderr, ...), but also handles some extra format
+       specifiers.
+
+       %pA section name from section.  For group components, prints
+       group name too.
+       %pB file name from bfd.  For archive components, prints
+       archive too.
+
+       Beware: Only supports a maximum of 9 format arguments.
+*/
+
 void
 _bfd_error_handler (const char *fmt, ...)
 {
@@ -2324,6 +2338,8 @@ bfd_update_compression_header (bfd *abfd, bfd_byte *contents,
                  bfd_put_32 (abfd, sec->size, &echdr->ch_size);
                  bfd_put_32 (abfd, 1 << sec->alignment_power,
                              &echdr->ch_addralign);
+                 /* bfd_log2 (alignof (Elf32_Chdr)) */
+                 bfd_set_section_alignment (abfd, sec, 2);
                }
              else
                {
@@ -2334,6 +2350,8 @@ bfd_update_compression_header (bfd *abfd, bfd_byte *contents,
                  bfd_put_64 (abfd, sec->size, &echdr->ch_size);
                  bfd_put_64 (abfd, 1 << sec->alignment_power,
                              &echdr->ch_addralign);
+                 /* bfd_log2 (alignof (Elf64_Chdr)) */
+                 bfd_set_section_alignment (abfd, sec, 3);
                }
            }
          else
@@ -2346,6 +2364,8 @@ bfd_update_compression_header (bfd *abfd, bfd_byte *contents,
                 order.  */
              memcpy (contents, "ZLIB", 4);
              bfd_putb64 (sec->size, contents + 4);
+             /* No way to keep the original alignment, just use 1 always. */
+             bfd_set_section_alignment (abfd, sec, 0);
            }
        }
     }
@@ -2360,12 +2380,14 @@ bfd_update_compression_header (bfd *abfd, bfd_byte *contents,
    SYNOPSIS
        bfd_boolean bfd_check_compression_header
          (bfd *abfd, bfd_byte *contents, asection *sec,
-         bfd_size_type *uncompressed_size);
+         bfd_size_type *uncompressed_size,
+         unsigned int *uncompressed_alignment_power);
 
 DESCRIPTION
        Check the compression header at CONTENTS of SEC in ABFD and
-       store the uncompressed size in UNCOMPRESSED_SIZE if the
-       compression header is valid.
+       store the uncompressed size in UNCOMPRESSED_SIZE and the
+       uncompressed data alignment in UNCOMPRESSED_ALIGNMENT_POWER
+       if the compression header is valid.
 
 RETURNS
        Return TRUE if the compression header is valid.
@@ -2374,7 +2396,8 @@ RETURNS
 bfd_boolean
 bfd_check_compression_header (bfd *abfd, bfd_byte *contents,
                              asection *sec,
-                             bfd_size_type *uncompressed_size)
+                             bfd_size_type *uncompressed_size,
+                             unsigned int *uncompressed_alignment_power)
 {
   if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
       && (elf_section_flags (sec) & SHF_COMPRESSED) != 0)
@@ -2396,9 +2419,10 @@ bfd_check_compression_header (bfd *abfd, bfd_byte *contents,
          chdr.ch_addralign = bfd_get_64 (abfd, &echdr->ch_addralign);
        }
       if (chdr.ch_type == ELFCOMPRESS_ZLIB
-         && chdr.ch_addralign == 1U << sec->alignment_power)
+         && chdr.ch_addralign == (1U << bfd_log2 (chdr.ch_addralign)))
        {
          *uncompressed_size = chdr.ch_size;
+         *uncompressed_alignment_power = bfd_log2 (chdr.ch_addralign);
          return TRUE;
        }
     }
@@ -2461,10 +2485,6 @@ bfd_convert_section_size (bfd *ibfd, sec_ptr isec, bfd *obfd,
 {
   bfd_size_type hdr_size;
 
-  /* Do nothing if input file will be decompressed.  */
-  if ((ibfd->flags & BFD_DECOMPRESS))
-    return size;
-
   /* Do nothing if either input or output aren't ELF.  */
   if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
@@ -2475,6 +2495,14 @@ bfd_convert_section_size (bfd *ibfd, sec_ptr isec, bfd *obfd,
       == get_elf_backend_data (obfd)->s->elfclass)
     return size;
 
+  /* Convert GNU property size.  */
+  if (CONST_STRNEQ (isec->name, NOTE_GNU_PROPERTY_SECTION_NAME))
+    return _bfd_elf_convert_gnu_property_size (ibfd, obfd);
+
+  /* Do nothing if input file will be decompressed.  */
+  if ((ibfd->flags & BFD_DECOMPRESS))
+    return size;
+
   /* Do nothing if the input section isn't a SHF_COMPRESSED section. */
   hdr_size = bfd_get_compression_header_size (ibfd, isec);
   if (hdr_size == 0)
@@ -2515,10 +2543,6 @@ bfd_convert_section_contents (bfd *ibfd, sec_ptr isec, bfd *obfd,
   Elf_Internal_Chdr chdr;
   bfd_boolean use_memmove;
 
-  /* Do nothing if input file will be decompressed.  */
-  if ((ibfd->flags & BFD_DECOMPRESS))
-    return TRUE;
-
   /* Do nothing if either input or output aren't ELF.  */
   if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
@@ -2529,6 +2553,15 @@ bfd_convert_section_contents (bfd *ibfd, sec_ptr isec, bfd *obfd,
       == get_elf_backend_data (obfd)->s->elfclass)
     return TRUE;
 
+  /* Convert GNU properties.  */
+  if (CONST_STRNEQ (isec->name, NOTE_GNU_PROPERTY_SECTION_NAME))
+    return _bfd_elf_convert_gnu_properties (ibfd, isec, obfd, ptr,
+                                           ptr_size);
+
+  /* Do nothing if input file will be decompressed.  */
+  if ((ibfd->flags & BFD_DECOMPRESS))
+    return TRUE;
+
   /* Do nothing if the input section isn't a SHF_COMPRESSED section. */
   ihdr_size = bfd_get_compression_header_size (ibfd, isec);
   if (ihdr_size == 0)