Use ui_file_as_string in gdb/printcmd.c
[binutils-gdb.git] / bfd / elfxx-mips.c
index cfb9a52af02322eea07c18f3894ccf2b11341e67..e4fc0430402a227419a98db88d93c38b6b96ee83 100644 (file)
@@ -913,7 +913,7 @@ static bfd *reldyn_sorting_bfd;
     : 0x8f998010))                             /* lw t9,0x8010(gp) */
 #define STUB_MOVE 0x03e07825                   /* or t7,ra,zero */
 #define STUB_LUI(VAL) (0x3c180000 + (VAL))     /* lui t8,VAL */
-#define STUB_JALR 0x0320f809                   /* jalr t9,ra */
+#define STUB_JALR 0x0320f809                   /* jalr ra,t9 */
 #define STUB_ORI(VAL) (0x37180000 + (VAL))     /* ori t8,t8,VAL */
 #define STUB_LI16U(VAL) (0x34180000 + (VAL))   /* ori t8,zero,VAL unsigned */
 #define STUB_LI16S(abfd, VAL)                                          \
@@ -1578,12 +1578,13 @@ mips_elf_create_stub_symbol (struct bfd_link_info *info,
                             const char *prefix, asection *s, bfd_vma value,
                             bfd_vma size)
 {
+  bfd_boolean micromips_p = ELF_ST_IS_MICROMIPS (h->root.other);
   struct bfd_link_hash_entry *bh;
   struct elf_link_hash_entry *elfh;
   char *name;
   bfd_boolean res;
 
-  if (ELF_ST_IS_MICROMIPS (h->root.other))
+  if (micromips_p)
     value |= 1;
 
   /* Create a new symbol.  */
@@ -1601,6 +1602,8 @@ mips_elf_create_stub_symbol (struct bfd_link_info *info,
   elfh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
   elfh->size = size;
   elfh->forced_local = 1;
+  if (micromips_p)
+    elfh->other = ELF_ST_SET_MICROMIPS (elfh->other);
   return TRUE;
 }
 
@@ -1805,6 +1808,7 @@ mips_elf_local_pic_function_p (struct mips_elf_link_hash_entry *h)
           || h->root.root.type == bfd_link_hash_defweak)
          && h->root.def_regular
          && !bfd_is_abs_section (h->root.root.u.def.section)
+         && !bfd_is_und_section (h->root.root.u.def.section)
          && (!ELF_ST_IS_MIPS16 (h->root.other)
              || (h->fn_stub && h->need_fn_stub))
          && (PIC_OBJECT_P (h->root.root.u.def.section->owner)
@@ -1961,6 +1965,8 @@ mips_elf_add_la25_stub (struct bfd_link_info *info,
   /* Prefer to use LUI/ADDIU stubs if the function is at the beginning
      of the section and if we would need no more than 2 nops.  */
   value = mips_elf_get_la25_target (stub, &s);
+  if (ELF_ST_IS_MICROMIPS (stub->h->root.other))
+    value &= ~1;
   use_trampoline_p = (value != 0 || s->alignment_power > 4);
 
   h->la25_stub = stub;
@@ -3746,7 +3752,7 @@ mips_elf_create_local_got_entry (bfd *abfd, struct bfd_link_info *info,
   if (g->assigned_low_gotno > g->assigned_high_gotno)
     {
       /* We didn't allocate enough space in the GOT.  */
-      (*_bfd_error_handler)
+      _bfd_error_handler
        (_("not enough GOT space for local GOT entries"));
       bfd_set_error (bfd_error_bad_value);
       return NULL;
@@ -5615,7 +5621,7 @@ mips_elf_calculate_relocation (bfd *abfd, bfd *input_bfd,
   if ((mips16_branch_reloc_p (r_type) && target_is_micromips_code_p)
       || (micromips_branch_reloc_p (r_type) && target_is_16_bit_code_p))
    {
-      (*_bfd_error_handler)
+      _bfd_error_handler
        (_("MIPS16 and microMIPS functions cannot call each other"));
       return bfd_reloc_notsupported;
    }
@@ -7111,7 +7117,8 @@ _bfd_mips_elf_section_processing (bfd *abfd, Elf_Internal_Shdr *hdr)
                                        &intopt);
          if (intopt.size < sizeof (Elf_External_Options))
            {
-             (*_bfd_error_handler)
+             _bfd_error_handler
+               /* xgettext:c-format */
                (_("%B: Warning: bad `%s' option size %u smaller than its header"),
                abfd, MIPS_ELF_OPTIONS_SECTION_NAME (abfd), intopt.size);
              break;
@@ -7344,7 +7351,8 @@ _bfd_mips_elf_section_from_shdr (bfd *abfd,
                                        &intopt);
          if (intopt.size < sizeof (Elf_External_Options))
            {
-             (*_bfd_error_handler)
+             _bfd_error_handler
+               /* xgettext:c-format */
                (_("%B: Warning: bad `%s' option size %u smaller than its header"),
                abfd, MIPS_ELF_OPTIONS_SECTION_NAME (abfd), intopt.size);
              break;
@@ -8114,7 +8122,8 @@ _bfd_mips_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
       r_symndx = mips16_stub_symndx (bed, sec, relocs, rel_end);
       if (r_symndx == 0)
        {
-         (*_bfd_error_handler)
+         _bfd_error_handler
+           /* xgettext:c-format */
            (_("%B: Warning: cannot determine the target function for"
               " stub section `%s'"),
             abfd, name);
@@ -8239,7 +8248,8 @@ _bfd_mips_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
       r_symndx = mips16_stub_symndx (bed, sec, relocs, rel_end);
       if (r_symndx == 0)
        {
-         (*_bfd_error_handler)
+         _bfd_error_handler
+           /* xgettext:c-format */
            (_("%B: Warning: cannot determine the target function for"
               " stub section `%s'"),
             abfd, name);
@@ -8370,7 +8380,8 @@ _bfd_mips_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
        h = NULL;
       else if (r_symndx >= extsymoff + NUM_SHDR_ENTRIES (symtab_hdr))
        {
-         (*_bfd_error_handler)
+         _bfd_error_handler
+           /* xgettext:c-format */
            (_("%B: Malformed reloc detected for section %s"),
             abfd, name);
          bfd_set_error (bfd_error_bad_value);
@@ -8445,7 +8456,8 @@ _bfd_mips_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
            return FALSE;
          if (htab->is_vxworks && !bfd_link_pic (info))
            {
-             (*_bfd_error_handler)
+             _bfd_error_handler
+               /* xgettext:c-format */
                (_("%B: GOT reloc at 0x%lx not expected in executables"),
                 abfd, (unsigned long) rel->r_offset);
              bfd_set_error (bfd_error_bad_value);
@@ -8582,7 +8594,8 @@ _bfd_mips_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
        case R_MICROMIPS_CALL16:
          if (h == NULL)
            {
-             (*_bfd_error_handler)
+             _bfd_error_handler
+               /* xgettext:c-format */
                (_("%B: CALL16 reloc at 0x%lx not against global symbol"),
                 abfd, (unsigned long) rel->r_offset);
              bfd_set_error (bfd_error_bad_value);
@@ -8867,7 +8880,8 @@ _bfd_mips_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
            case R_MIPS_26:
            case R_MICROMIPS_26_S1:
              howto = MIPS_ELF_RTYPE_TO_HOWTO (abfd, r_type, FALSE);
-             (*_bfd_error_handler)
+             _bfd_error_handler
+               /* xgettext:c-format */
                (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
                 abfd, howto->name,
                 (h) ? h->root.root.string : "a local symbol");
@@ -9363,9 +9377,9 @@ _bfd_mips_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
      some that we can't convert.  */
   if (!htab->use_plts_and_copy_relocs || bfd_link_pic (info))
     {
-      (*_bfd_error_handler) (_("non-dynamic relocations refer to "
-                              "dynamic symbol %s"),
-                            h->root.root.string);
+      _bfd_error_handler (_("non-dynamic relocations refer to "
+                           "dynamic symbol %s"),
+                         h->root.root.string);
       bfd_set_error (bfd_error_bad_value);
       return FALSE;
     }
@@ -10272,7 +10286,8 @@ _bfd_mips_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
                        name = bfd_elf_sym_name (input_bfd, symtab_hdr,
                                                 local_syms + r_symndx,
                                                 sec);
-                     (*_bfd_error_handler)
+                     _bfd_error_handler
+                       /* xgettext:c-format */
                        (_("%B: Can't find matching LO16 reloc against `%s' for %s at 0x%lx in section `%A'"),
                         input_bfd, input_section, name, howto->name,
                         rel->r_offset);
@@ -10814,7 +10829,8 @@ _bfd_mips_elf_finish_dynamic_symbol (bfd *output_bfd,
              /* ADDIUPC has a span of +/-16MB, check we're in range.  */
              if (gotpc_offset + 0x1000000 >= 0x2000000)
                {
-                 (*_bfd_error_handler)
+                 _bfd_error_handler
+                   /* xgettext:c-format */
                    (_("%B: `%A' offset of %ld from `%A' "
                       "beyond the range of ADDIUPC"),
                     output_bfd,
@@ -11377,7 +11393,8 @@ mips_finish_exec_plt (bfd *output_bfd, struct bfd_link_info *info)
       /* ADDIUPC has a span of +/-16MB, check we're in range.  */
       if (gotpc_offset + 0x1000000 >= 0x2000000)
        {
-         (*_bfd_error_handler)
+         _bfd_error_handler
+           /* xgettext:c-format */
            (_("%B: `%A' offset of %ld from `%A' beyond the range of ADDIUPC"),
             output_bfd,
             htab->sgotplt->output_section,
@@ -11640,7 +11657,8 @@ _bfd_mips_elf_finish_dynamic_sections (bfd *output_bfd,
                }
              /* In case if we don't have global got symbols we default
                 to setting DT_MIPS_GOTSYM to the same value as
-                DT_MIPS_SYMTABNO, so we just fall through.  */
+                DT_MIPS_SYMTABNO.  */
+             /* Fall through.  */
 
            case DT_MIPS_SYMTABNO:
              name = ".dynsym";
@@ -14289,7 +14307,8 @@ update_mips_abiflags_isa (bfd *abfd, Elf_Internal_ABIFlags_v0 *abiflags)
     case E_MIPS_ARCH_64R2: new_isa = LEVEL_REV (64, 2); break;
     case E_MIPS_ARCH_64R6: new_isa = LEVEL_REV (64, 6); break;
     default:
-      (*_bfd_error_handler)
+      _bfd_error_handler
+       /* xgettext:c-format */
        (_("%B: Unknown architecture %s"),
         abfd, bfd_printable_name (abfd));
     }
@@ -14818,7 +14837,8 @@ _bfd_mips_elf_final_link (bfd *abfd, struct bfd_link_info *info)
            gptab_bss_sec = o;
          else
            {
-             (*_bfd_error_handler)
+             _bfd_error_handler
+               /* xgettext:c-format */
                (_("%s: illegal section name `%s'"),
                 bfd_get_filename (abfd), o->name);
              bfd_set_error (bfd_error_nonrepresentable_section);
@@ -15057,8 +15077,9 @@ _bfd_mips_elf_final_link (bfd *abfd, struct bfd_link_info *info)
    if there are conflicting settings.  */
 
 static bfd_boolean
-mips_elf_merge_obj_e_flags (bfd *ibfd, bfd *obfd)
+mips_elf_merge_obj_e_flags (bfd *ibfd, struct bfd_link_info *info)
 {
+  bfd *obfd = info->output_bfd;
   struct mips_elf_obj_tdata *out_tdata = mips_elf_tdata (obfd);
   flagword old_flags;
   flagword new_flags;
@@ -15095,7 +15116,7 @@ mips_elf_merge_obj_e_flags (bfd *ibfd, bfd *obfd)
   if (((new_flags & (EF_MIPS_PIC | EF_MIPS_CPIC)) != 0)
       != ((old_flags & (EF_MIPS_PIC | EF_MIPS_CPIC)) != 0))
     {
-      (*_bfd_error_handler)
+      _bfd_error_handler
        (_("%B: warning: linking abicalls files with non-abicalls files"),
         ibfd);
       ok = TRUE;
@@ -15112,7 +15133,7 @@ mips_elf_merge_obj_e_flags (bfd *ibfd, bfd *obfd)
   /* Compare the ISAs.  */
   if (mips_32bit_flags_p (old_flags) != mips_32bit_flags_p (new_flags))
     {
-      (*_bfd_error_handler)
+      _bfd_error_handler
        (_("%B: linking 32-bit code with 64-bit code"),
         ibfd);
       ok = FALSE;
@@ -15143,7 +15164,8 @@ mips_elf_merge_obj_e_flags (bfd *ibfd, bfd *obfd)
       else
        {
          /* The ISAs aren't compatible.  */
-         (*_bfd_error_handler)
+         _bfd_error_handler
+           /* xgettext:c-format */
            (_("%B: linking %s module with previous %s modules"),
             ibfd,
             bfd_printable_name (ibfd),
@@ -15166,7 +15188,8 @@ mips_elf_merge_obj_e_flags (bfd *ibfd, bfd *obfd)
          || (elf_elfheader (ibfd)->e_ident[EI_CLASS]
              != elf_elfheader (obfd)->e_ident[EI_CLASS]))
        {
-         (*_bfd_error_handler)
+         _bfd_error_handler
+           /* xgettext:c-format */
            (_("%B: ABI mismatch: linking %s module with previous %s modules"),
             ibfd,
             elf_mips_abi_name (ibfd),
@@ -15190,7 +15213,8 @@ mips_elf_merge_obj_e_flags (bfd *ibfd, bfd *obfd)
 
       if (m16_mis || micro_mis)
        {
-         (*_bfd_error_handler)
+         _bfd_error_handler
+           /* xgettext:c-format */
            (_("%B: ASE mismatch: linking %s module with previous %s modules"),
             ibfd,
             m16_mis ? "MIPS16" : "microMIPS",
@@ -15207,6 +15231,7 @@ mips_elf_merge_obj_e_flags (bfd *ibfd, bfd *obfd)
   /* Compare NaN encodings.  */
   if ((new_flags & EF_MIPS_NAN2008) != (old_flags & EF_MIPS_NAN2008))
     {
+      /* xgettext:c-format */
       _bfd_error_handler (_("%B: linking %s module with previous %s modules"),
                          ibfd,
                          (new_flags & EF_MIPS_NAN2008
@@ -15221,6 +15246,7 @@ mips_elf_merge_obj_e_flags (bfd *ibfd, bfd *obfd)
   /* Compare FP64 state.  */
   if ((new_flags & EF_MIPS_FP64) != (old_flags & EF_MIPS_FP64))
     {
+      /* xgettext:c-format */
       _bfd_error_handler (_("%B: linking %s module with previous %s modules"),
                          ibfd,
                          (new_flags & EF_MIPS_FP64
@@ -15235,7 +15261,8 @@ mips_elf_merge_obj_e_flags (bfd *ibfd, bfd *obfd)
   /* Warn about any other mismatches */
   if (new_flags != old_flags)
     {
-      (*_bfd_error_handler)
+      /* xgettext:c-format */
+      _bfd_error_handler
        (_("%B: uses different e_flags (0x%lx) fields than previous modules "
           "(0x%lx)"),
         ibfd, (unsigned long) new_flags,
@@ -15249,8 +15276,9 @@ mips_elf_merge_obj_e_flags (bfd *ibfd, bfd *obfd)
 /* Merge object attributes from IBFD into OBFD.  Raise an error if
    there are conflicting attributes.  */
 static bfd_boolean
-mips_elf_merge_obj_attributes (bfd *ibfd, bfd *obfd)
+mips_elf_merge_obj_attributes (bfd *ibfd, struct bfd_link_info *info)
 {
+  bfd *obfd = info->output_bfd;
   obj_attribute *in_attr;
   obj_attribute *out_attr;
   bfd *abi_fp_bfd;
@@ -15320,17 +15348,20 @@ mips_elf_merge_obj_attributes (bfd *ibfd, bfd *obfd)
          in_string = _bfd_mips_fp_abi_string (in_fp);
          /* First warn about cases involving unrecognised ABIs.  */
          if (!out_string && !in_string)
+           /* xgettext:c-format */
            _bfd_error_handler
              (_("Warning: %B uses unknown floating point ABI %d "
                 "(set by %B), %B uses unknown floating point ABI %d"),
               obfd, abi_fp_bfd, ibfd, out_fp, in_fp);
          else if (!out_string)
            _bfd_error_handler
+             /* xgettext:c-format */
              (_("Warning: %B uses unknown floating point ABI %d "
                 "(set by %B), %B uses %s"),
               obfd, abi_fp_bfd, ibfd, out_fp, in_string);
          else if (!in_string)
            _bfd_error_handler
+             /* xgettext:c-format */
              (_("Warning: %B uses %s (set by %B), "
                 "%B uses unknown floating point ABI %d"),
               obfd, abi_fp_bfd, ibfd, out_string, in_fp);
@@ -15344,6 +15375,7 @@ mips_elf_merge_obj_attributes (bfd *ibfd, bfd *obfd)
              else if (out_fp == Val_GNU_MIPS_ABI_FP_SOFT)
                in_string = "-mhard-float";
              _bfd_error_handler
+               /* xgettext:c-format */
                (_("Warning: %B uses %s (set by %B), %B uses %s"),
                 obfd, abi_fp_bfd, ibfd, out_string, in_string);
            }
@@ -15362,6 +15394,7 @@ mips_elf_merge_obj_attributes (bfd *ibfd, bfd *obfd)
          {
          case Val_GNU_MIPS_ABI_MSA_128:
            _bfd_error_handler
+             /* xgettext:c-format */
              (_("Warning: %B uses %s (set by %B), "
                 "%B uses unknown MSA ABI %d"),
               obfd, abi_msa_bfd, ibfd,
@@ -15373,6 +15406,7 @@ mips_elf_merge_obj_attributes (bfd *ibfd, bfd *obfd)
              {
              case Val_GNU_MIPS_ABI_MSA_128:
                _bfd_error_handler
+                 /* xgettext:c-format */
                  (_("Warning: %B uses unknown MSA ABI %d "
                     "(set by %B), %B uses %s"),
                     obfd, abi_msa_bfd, ibfd,
@@ -15381,6 +15415,7 @@ mips_elf_merge_obj_attributes (bfd *ibfd, bfd *obfd)
 
              default:
                _bfd_error_handler
+                 /* xgettext:c-format */
                  (_("Warning: %B uses unknown MSA ABI %d "
                     "(set by %B), %B uses unknown MSA ABI %d"),
                   obfd, abi_msa_bfd, ibfd,
@@ -15392,7 +15427,7 @@ mips_elf_merge_obj_attributes (bfd *ibfd, bfd *obfd)
     }
 
   /* Merge Tag_compatibility attributes and any common GNU ones.  */
-  return _bfd_elf_merge_object_attributes (ibfd, obfd);
+  return _bfd_elf_merge_object_attributes (ibfd, info);
 }
 
 /* Merge object ABI flags from IBFD into OBFD.  Raise an error if
@@ -15431,8 +15466,9 @@ mips_elf_merge_obj_abiflags (bfd *ibfd, bfd *obfd)
    object file when linking.  */
 
 bfd_boolean
-_bfd_mips_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
+_bfd_mips_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
 {
+  bfd *obfd = info->output_bfd;
   struct mips_elf_obj_tdata *out_tdata;
   struct mips_elf_obj_tdata *in_tdata;
   bfd_boolean null_input_bfd = TRUE;
@@ -15440,9 +15476,9 @@ _bfd_mips_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
   bfd_boolean ok;
 
   /* Check if we have the same endianness.  */
-  if (! _bfd_generic_verify_endian_match (ibfd, obfd))
+  if (! _bfd_generic_verify_endian_match (ibfd, info))
     {
-      (*_bfd_error_handler)
+      _bfd_error_handler
        (_("%B: endianness incompatible with that of the selected emulation"),
         ibfd);
       return FALSE;
@@ -15456,7 +15492,7 @@ _bfd_mips_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
 
   if (strcmp (bfd_get_target (ibfd), bfd_get_target (obfd)) != 0)
     {
-      (*_bfd_error_handler)
+      _bfd_error_handler
        (_("%B: ABI is incompatible with that of the selected emulation"),
         ibfd);
       return FALSE;
@@ -15508,27 +15544,27 @@ _bfd_mips_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
 
       if (LEVEL_REV (in_abiflags.isa_level, in_abiflags.isa_rev)
          < LEVEL_REV (abiflags.isa_level, abiflags.isa_rev))
-       (*_bfd_error_handler)
+       _bfd_error_handler
          (_("%B: warning: Inconsistent ISA between e_flags and "
             ".MIPS.abiflags"), ibfd);
       if (abiflags.fp_abi != Val_GNU_MIPS_ABI_FP_ANY
          && in_abiflags.fp_abi != abiflags.fp_abi)
-       (*_bfd_error_handler)
+       _bfd_error_handler
          (_("%B: warning: Inconsistent FP ABI between .gnu.attributes and "
             ".MIPS.abiflags"), ibfd);
       if ((in_abiflags.ases & abiflags.ases) != abiflags.ases)
-       (*_bfd_error_handler)
+       _bfd_error_handler
          (_("%B: warning: Inconsistent ASEs between e_flags and "
             ".MIPS.abiflags"), ibfd);
       /* The isa_ext is allowed to be an extension of what can be inferred
         from e_flags.  */
       if (!mips_mach_extends_p (bfd_mips_isa_ext_mach (abiflags.isa_ext),
                                bfd_mips_isa_ext_mach (in_abiflags.isa_ext)))
-       (*_bfd_error_handler)
+       _bfd_error_handler
          (_("%B: warning: Inconsistent ISA extensions between e_flags and "
             ".MIPS.abiflags"), ibfd);
       if (in_abiflags.flags2 != 0)
-       (*_bfd_error_handler)
+       _bfd_error_handler
          (_("%B: warning: Unexpected flag in the flags2 field of "
             ".MIPS.abiflags (0x%lx)"), ibfd,
           (unsigned long) in_abiflags.flags2);
@@ -15569,9 +15605,9 @@ _bfd_mips_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
       ok = TRUE;
     }
   else
-    ok = mips_elf_merge_obj_e_flags (ibfd, obfd);
+    ok = mips_elf_merge_obj_e_flags (ibfd, info);
 
-  ok = mips_elf_merge_obj_attributes (ibfd, obfd) && ok;
+  ok = mips_elf_merge_obj_attributes (ibfd, info) && ok;
 
   ok = mips_elf_merge_obj_abiflags (ibfd, obfd) && ok;