Yet more signed overflow fixes
[deliverable/binutils-gdb.git] / bfd / elfnn-ia64.c
index 3af05f66f4101a0e401c185b4996a679d7f6e97d..459d986c0350f5e5982c7738ea69273f2ae97f7a 100644 (file)
@@ -1,5 +1,5 @@
 /* IA-64 support for 64-bit ELF
-   Copyright (C) 1998-2018 Free Software Foundation, Inc.
+   Copyright (C) 1998-2019 Free Software Foundation, Inc.
    Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -27,7 +27,6 @@
 #include "elf/ia64.h"
 #include "objalloc.h"
 #include "hashtab.h"
-#include "bfd_stdint.h"
 #include "elfxx-ia64.h"
 
 #define ARCH_SIZE      NN
@@ -197,13 +196,24 @@ static asection *get_pltoff
 
 /* Given a ELF reloc, return the matching HOWTO structure.  */
 
-static void
+static bfd_boolean
 elfNN_ia64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
                          arelent *bfd_reloc,
                          Elf_Internal_Rela *elf_reloc)
 {
-  bfd_reloc->howto
-    = ia64_elf_lookup_howto ((unsigned int) ELFNN_R_TYPE (elf_reloc->r_info));
+  unsigned int r_type = ELF32_R_TYPE (elf_reloc->r_info);
+
+  bfd_reloc->howto = ia64_elf_lookup_howto (r_type);
+  if (bfd_reloc->howto == NULL)
+    {
+      /* xgettext:c-format */
+      _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
+                         abfd, r_type);
+      bfd_set_error (bfd_error_bad_value);
+      return FALSE;
+    }
+
+  return TRUE;
 }
 \f
 #define PLT_HEADER_SIZE                (3 * 16)
@@ -593,6 +603,9 @@ elfNN_ia64_relax_section (bfd *abfd, asection *sec,
                     1, change it to slot 2.  */
                  if ((irel->r_offset & 3) == 1)
                    irel->r_offset += 1;
+
+                 changed_contents = TRUE;
+                 changed_relocs = TRUE;
                }
 
              continue;
@@ -607,6 +620,9 @@ elfNN_ia64_relax_section (bfd *abfd, asection *sec,
 
              /* Make the relocation offset point to slot 1.  */
              irel->r_offset = (irel->r_offset & ~((bfd_vma) 0x3)) + 1;
+
+             changed_contents = TRUE;
+             changed_relocs = TRUE;
              continue;
            }
 
@@ -617,9 +633,9 @@ elfNN_ia64_relax_section (bfd *abfd, asection *sec,
            {
              _bfd_error_handler
                /* xgettext:c-format */
-               (_("%B: Can't relax br at %#Lx in section `%A'."
-                  " Please use brl or indirect branch."),
-                sec->owner, roff, sec);
+               (_("%pB: can't relax br at %#" PRIx64 " in section `%pA';"
+                  " please use brl or indirect branch"),
+                sec->owner, (uint64_t) roff, sec);
              bfd_set_error (bfd_error_bad_value);
              goto error_return;
            }
@@ -940,7 +956,7 @@ elfNN_ia64_fake_sections (bfd *abfd, Elf_Internal_Shdr *hdr,
 {
   const char *name;
 
-  name = bfd_get_section_name (abfd, sec);
+  name = bfd_section_name (sec);
 
   if (is_unwind_section_name (abfd, name))
     {
@@ -986,9 +1002,8 @@ elfNN_ia64_fake_sections (bfd *abfd, Elf_Internal_Shdr *hdr,
 /* The final processing done just before writing out an IA-64 ELF
    object file.  */
 
-static void
-elfNN_ia64_final_write_processing (bfd *abfd,
-                                  bfd_boolean linker ATTRIBUTE_UNUSED)
+static bfd_boolean
+elfNN_ia64_final_write_processing (bfd *abfd)
 {
   Elf_Internal_Shdr *hdr;
   asection *s;
@@ -1020,6 +1035,7 @@ elfNN_ia64_final_write_processing (bfd *abfd,
       elf_elfheader(abfd)->e_flags = flags;
       elf_flags_init (abfd) = TRUE;
     }
+  return _bfd_elf_final_write_processing (abfd);
 }
 
 /* Hook called by the linker routine which adds symbols from an object
@@ -1175,8 +1191,7 @@ elfNN_ia64_modify_segment_map (bfd *abfd,
    for SHF_IA_64_NORECOV on each.  */
 
 static bfd_boolean
-elfNN_ia64_modify_program_headers (bfd *abfd,
-                                  struct bfd_link_info *info ATTRIBUTE_UNUSED)
+elfNN_ia64_modify_headers (bfd *abfd, struct bfd_link_info *info)
 {
   struct elf_obj_tdata *tdata = elf_tdata (abfd);
   struct elf_segment_map *m;
@@ -1208,7 +1223,7 @@ elfNN_ia64_modify_program_headers (bfd *abfd,
       found:;
       }
 
-  return TRUE;
+  return _bfd_elf_modify_headers (abfd, info);
 }
 
 /* According to the Tahoe assembler spec, all labels starting with a
@@ -1545,11 +1560,10 @@ elfNN_ia64_create_dynamic_sections (bfd *abfd,
     return FALSE;
 
   {
-    flagword flags = bfd_get_section_flags (abfd, ia64_info->root.sgot);
-    bfd_set_section_flags (abfd, ia64_info->root.sgot,
-                          SEC_SMALL_DATA | flags);
+    flagword flags = bfd_section_flags (ia64_info->root.sgot);
+    bfd_set_section_flags (ia64_info->root.sgot, SEC_SMALL_DATA | flags);
     /* The .got section is always aligned at 8 bytes.  */
-    if (! bfd_set_section_alignment (abfd, ia64_info->root.sgot, 3))
+    if (!bfd_set_section_alignment (ia64_info->root.sgot, 3))
       return FALSE;
   }
 
@@ -1563,7 +1577,7 @@ elfNN_ia64_create_dynamic_sections (bfd *abfd,
                                           | SEC_LINKER_CREATED
                                           | SEC_READONLY));
   if (s == NULL
-      || !bfd_set_section_alignment (abfd, s, LOG_SECTION_ALIGN))
+      || !bfd_set_section_alignment (s, LOG_SECTION_ALIGN))
     return FALSE;
   ia64_info->rel_pltoff_sec = s;
 
@@ -1961,11 +1975,11 @@ get_got (bfd *abfd, struct bfd_link_info *info,
       got = ia64_info->root.sgot;
 
       /* The .got section is always aligned at 8 bytes.  */
-      if (!bfd_set_section_alignment (abfd, got, 3))
+      if (!bfd_set_section_alignment (got, 3))
        return NULL;
 
-      flags = bfd_get_section_flags (abfd, got);
-      if (! bfd_set_section_flags (abfd, got, SEC_SMALL_DATA | flags))
+      flags = bfd_section_flags (got);
+      if (!bfd_set_section_flags (got, SEC_SMALL_DATA | flags))
        return NULL;
     }
 
@@ -2000,7 +2014,7 @@ get_fptr (bfd *abfd, struct bfd_link_info *info,
                                                     ? 0 : SEC_READONLY)
                                                  | SEC_LINKER_CREATED));
       if (!fptr
-         || !bfd_set_section_alignment (abfd, fptr, 4))
+         || !bfd_set_section_alignment (fptr, 4))
        {
          BFD_ASSERT (0);
          return NULL;
@@ -2018,8 +2032,7 @@ get_fptr (bfd *abfd, struct bfd_link_info *info,
                                                          | SEC_LINKER_CREATED
                                                          | SEC_READONLY));
          if (fptr_rel == NULL
-             || !bfd_set_section_alignment (abfd, fptr_rel,
-                                            LOG_SECTION_ALIGN))
+             || !bfd_set_section_alignment (fptr_rel, LOG_SECTION_ALIGN))
            {
              BFD_ASSERT (0);
              return NULL;
@@ -2055,7 +2068,7 @@ get_pltoff (bfd *abfd, struct bfd_link_info *info ATTRIBUTE_UNUSED,
                                                    | SEC_SMALL_DATA
                                                    | SEC_LINKER_CREATED));
       if (!pltoff
-         || !bfd_set_section_alignment (abfd, pltoff, 4))
+         || !bfd_set_section_alignment (pltoff, 4))
        {
          BFD_ASSERT (0);
          return NULL;
@@ -2096,8 +2109,7 @@ get_reloc_section (bfd *abfd,
                                                  | SEC_LINKER_CREATED
                                                  | SEC_READONLY));
       if (srel == NULL
-         || !bfd_set_section_alignment (dynobj, srel,
-                                        LOG_SECTION_ALIGN))
+         || !bfd_set_section_alignment (srel, LOG_SECTION_ALIGN))
        return NULL;
     }
 
@@ -3155,7 +3167,7 @@ elfNN_ia64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 
          /* It's OK to base decisions on the section name, because none
             of the dynobj section names depend upon the input files.  */
-         name = bfd_get_section_name (dynobj, sec);
+         name = bfd_section_name (sec);
 
          if (strcmp (name, ".got.plt") == 0)
            strip = FALSE;
@@ -3693,8 +3705,8 @@ elfNN_ia64_choose_gp (bfd *abfd, struct bfd_link_info *info, bfd_boolean final)
 overflow:
          _bfd_error_handler
            /* xgettext:c-format */
-           (_("%B: short data segment overflowed (%#Lx >= 0x400000)"),
-            abfd, max_short_vma - min_short_vma);
+           (_("%pB: short data segment overflowed (%#" PRIx64 " >= 0x400000)"),
+            abfd, (uint64_t) (max_short_vma - min_short_vma));
          return FALSE;
        }
       else if ((gp_val > min_short_vma
@@ -3703,7 +3715,7 @@ overflow:
                   && max_short_vma - gp_val >= 0x200000))
        {
          _bfd_error_handler
-           (_("%B: __gp does not cover short data segment"), abfd);
+           (_("%pB: __gp does not cover short data segment"), abfd);
          return FALSE;
        }
     }
@@ -3842,15 +3854,21 @@ elfNN_ia64_relocate_section (bfd *output_bfd,
       r_type = ELFNN_R_TYPE (rel->r_info);
       if (r_type > R_IA64_MAX_RELOC_CODE)
        {
-         _bfd_error_handler
-           /* xgettext:c-format */
-           (_("%B: unknown relocation type %d"), input_bfd, (int) r_type);
+         /* xgettext:c-format */
+         _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
+                             input_bfd, (int) r_type);
          bfd_set_error (bfd_error_bad_value);
          ret_val = FALSE;
          continue;
        }
 
       howto = ia64_elf_lookup_howto (r_type);
+      if (howto == NULL)
+       {
+         ret_val = FALSE;
+         continue;
+       }
+
       r_symndx = ELFNN_R_SYM (rel->r_info);
       h = NULL;
       sym = NULL;
@@ -3971,7 +3989,7 @@ elfNN_ia64_relocate_section (bfd *output_bfd,
                     shared libraries nor dynamic executables.  */
                  _bfd_error_handler
                    /* xgettext:c-format */
-                   (_("%B: non-pic code with imm relocation against dynamic symbol `%s'"),
+                   (_("%pB: non-pic code with imm relocation against dynamic symbol `%s'"),
                     input_bfd,
                     h ? h->root.root.string
                       : bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
@@ -4039,7 +4057,7 @@ elfNN_ia64_relocate_section (bfd *output_bfd,
            {
              _bfd_error_handler
                /* xgettext:c-format */
-               (_("%B: @gprel relocation against dynamic symbol %s"),
+               (_("%pB: @gprel relocation against dynamic symbol %s"),
                 input_bfd,
                 h ? h->root.root.string
                   : bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
@@ -4102,7 +4120,7 @@ elfNN_ia64_relocate_section (bfd *output_bfd,
                      /* ??? People shouldn't be doing non-pic code in
                         shared libraries.  Hork.  */
                      _bfd_error_handler
-                       (_("%B: linking non-pic code in a position independent executable"),
+                       (_("%pB: linking non-pic code in a position independent executable"),
                         input_bfd);
                      ret_val = FALSE;
                      continue;
@@ -4240,13 +4258,13 @@ elfNN_ia64_relocate_section (bfd *output_bfd,
 
              if (r_type == R_IA64_PCREL21BI)
                /* xgettext:c-format */
-               msg = _("%B: @internal branch to dynamic symbol %s");
+               msg = _("%pB: @internal branch to dynamic symbol %s");
              else if (r_type == R_IA64_PCREL21F || r_type == R_IA64_PCREL21M)
                /* xgettext:c-format */
-               msg = _("%B: speculation fixup to dynamic symbol %s");
+               msg = _("%pB: speculation fixup to dynamic symbol %s");
              else
                /* xgettext:c-format */
-               msg = _("%B: @pcrel relocation against dynamic symbol %s");
+               msg = _("%pB: @pcrel relocation against dynamic symbol %s");
              _bfd_error_handler (msg, input_bfd,
                                  h ? h->root.root.string
                                  : bfd_elf_sym_name (input_bfd,
@@ -4481,10 +4499,10 @@ missing_tls_sec:
              case R_IA64_LTOFF_DTPREL22:
                _bfd_error_handler
                  /* xgettext:c-format */
-                 (_("%B: missing TLS section for relocation %s against `%s'"
-                    " at %#Lx in section `%A'."),
+                 (_("%pB: missing TLS section for relocation %s against `%s'"
+                    " at %#" PRIx64 " in section `%pA'."),
                   input_bfd, howto->name, name,
-                  rel->r_offset, input_section);
+                  (uint64_t) rel->r_offset, input_section);
                break;
 
              case R_IA64_PCREL21B:
@@ -4498,10 +4516,11 @@ missing_tls_sec:
                       that the section is too big to relax.  */
                    _bfd_error_handler
                      /* xgettext:c-format */
-                     (_("%B: Can't relax br (%s) to `%s' at %#Lx"
-                        " in section `%A' with size %#Lx (> 0x1000000)."),
-                      input_bfd, howto->name, name, rel->r_offset,
-                      input_section, input_section->size);
+                     (_("%pB: Can't relax br (%s) to `%s' at %#" PRIx64
+                        " in section `%pA' with size %#" PRIx64
+                        " (> 0x1000000)."),
+                      input_bfd, howto->name, name, (uint64_t) rel->r_offset,
+                      input_section, (uint64_t) input_section->size);
                    break;
                  }
                /* Fall through.  */
@@ -4755,7 +4774,7 @@ elfNN_ia64_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
   if ((in_flags & EF_IA_64_TRAPNIL) != (out_flags & EF_IA_64_TRAPNIL))
     {
       _bfd_error_handler
-       (_("%B: linking trap-on-NULL-dereference with non-trapping files"),
+       (_("%pB: linking trap-on-NULL-dereference with non-trapping files"),
         ibfd);
 
       bfd_set_error (bfd_error_bad_value);
@@ -4764,7 +4783,7 @@ elfNN_ia64_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
   if ((in_flags & EF_IA_64_BE) != (out_flags & EF_IA_64_BE))
     {
       _bfd_error_handler
-       (_("%B: linking big-endian files with little-endian files"),
+       (_("%pB: linking big-endian files with little-endian files"),
         ibfd);
 
       bfd_set_error (bfd_error_bad_value);
@@ -4773,7 +4792,7 @@ elfNN_ia64_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
   if ((in_flags & EF_IA_64_ABI64) != (out_flags & EF_IA_64_ABI64))
     {
       _bfd_error_handler
-       (_("%B: linking 64-bit files with 32-bit files"),
+       (_("%pB: linking 64-bit files with 32-bit files"),
         ibfd);
 
       bfd_set_error (bfd_error_bad_value);
@@ -4782,7 +4801,7 @@ elfNN_ia64_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
   if ((in_flags & EF_IA_64_CONS_GP) != (out_flags & EF_IA_64_CONS_GP))
     {
       _bfd_error_handler
-       (_("%B: linking constant-gp files with non-constant-gp files"),
+       (_("%pB: linking constant-gp files with non-constant-gp files"),
         ibfd);
 
       bfd_set_error (bfd_error_bad_value);
@@ -4792,7 +4811,7 @@ elfNN_ia64_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
       != (out_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
     {
       _bfd_error_handler
-       (_("%B: linking auto-pic files with non-auto-pic files"),
+       (_("%pB: linking auto-pic files with non-auto-pic files"),
         ibfd);
 
       bfd_set_error (bfd_error_bad_value);
@@ -4953,14 +4972,18 @@ elfNN_ia64_hpux_vec (const bfd_target *vec)
   return (vec == &ia64_elfNN_hpux_be_vec);
 }
 
-static void
-elfNN_hpux_post_process_headers (bfd *abfd,
-                                struct bfd_link_info *info ATTRIBUTE_UNUSED)
+static bfd_boolean
+elfNN_hpux_init_file_header (bfd *abfd, struct bfd_link_info *info)
 {
-  Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd);
+  Elf_Internal_Ehdr *i_ehdrp;
 
+  if (!_bfd_elf_init_file_header (abfd, info))
+    return FALSE;
+
+  i_ehdrp = elf_elfheader (abfd);
   i_ehdrp->e_ident[EI_OSABI] = get_elf_backend_data (abfd)->elf_osabi;
   i_ehdrp->e_ident[EI_ABIVERSION] = 1;
+  return TRUE;
 }
 
 static bfd_boolean
@@ -5017,8 +5040,8 @@ elfNN_hpux_backend_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
        elfNN_ia64_additional_program_headers
 #define elf_backend_modify_segment_map \
        elfNN_ia64_modify_segment_map
-#define elf_backend_modify_program_headers \
-       elfNN_ia64_modify_program_headers
+#define elf_backend_modify_headers \
+       elfNN_ia64_modify_headers
 #define elf_info_to_howto \
        elfNN_ia64_info_to_howto
 
@@ -5046,7 +5069,7 @@ elfNN_hpux_backend_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
 #define elf_backend_size_dynamic_sections \
        elfNN_ia64_size_dynamic_sections
 #define elf_backend_omit_section_dynsym \
-  ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
+       _bfd_elf_omit_section_dynsym_all
 #define elf_backend_relocate_section \
        elfNN_ia64_relocate_section
 #define elf_backend_finish_dynamic_symbol \
@@ -5064,6 +5087,7 @@ elfNN_hpux_backend_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
        elfNN_ia64_print_private_bfd_data
 
 #define elf_backend_plt_readonly       1
+#define elf_backend_can_gc_sections    1
 #define elf_backend_want_plt_sym       0
 #define elf_backend_plt_alignment      5
 #define elf_backend_got_header_size    0
@@ -5101,8 +5125,8 @@ elfNN_hpux_backend_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
 
 /* These are HP-UX specific functions.  */
 
-#undef  elf_backend_post_process_headers
-#define elf_backend_post_process_headers elfNN_hpux_post_process_headers
+#undef  elf_backend_init_file_header
+#define elf_backend_init_file_header elfNN_hpux_init_file_header
 
 #undef  elf_backend_section_from_bfd_section
 #define elf_backend_section_from_bfd_section elfNN_hpux_backend_section_from_bfd_section
This page took 0.029961 seconds and 4 git commands to generate.