Add elf_x86_64_need_pic
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 25 Feb 2016 00:31:29 +0000 (16:31 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 25 Feb 2016 12:13:42 +0000 (04:13 -0800)
Add elf_x86_64_need_pic and replace x86_64_elf_howto_table[r_type].name
with howto->name.

* elf64-x86-64.c (elf_x86_64_need_pic): New function.
(elf_x86_64_relocate_section): Use it.  Replace
x86_64_elf_howto_table[r_type] with howto.

bfd/ChangeLog
bfd/elf64-x86-64.c

index 2a32a6f..c52a0bc 100644 (file)
@@ -1,5 +1,11 @@
 2016-02-24  H.J. Lu  <hongjiu.lu@intel.com>
 
+       * elf64-x86-64.c (elf_x86_64_need_pic): New function.
+       (elf_x86_64_relocate_section): Use it.  Replace
+       x86_64_elf_howto_table[r_type] with howto.
+
+2016-02-24  H.J. Lu  <hongjiu.lu@intel.com>
+
        PR ld/19698
        * elflink.c (bfd_elf_record_link_assignment): Set versioned if
        symbol version is unknown.
index 7debc1e..48d263e 100644 (file)
@@ -3861,6 +3861,42 @@ is_32bit_relative_branch (bfd_byte *contents, bfd_vma offset)
              && (contents [offset - 1] & 0xf0) == 0x80));
 }
 
+static bfd_boolean
+elf_x86_64_need_pic (bfd *input_bfd, struct elf_link_hash_entry *h,
+                    reloc_howto_type *howto)
+{
+  const char *fmt;
+  const char *v;
+  const char *pic = "";
+
+  switch (ELF_ST_VISIBILITY (h->other))
+    {
+    case STV_HIDDEN:
+      v = _("hidden symbol");
+      break;
+    case STV_INTERNAL:
+      v = _("internal symbol");
+      break;
+    case STV_PROTECTED:
+      v = _("protected symbol");
+      break;
+    default:
+      v = _("symbol");
+      pic = _("; recompile with -fPIC");
+      break;
+    }
+
+  if (h->def_regular)
+    fmt = _("%B: relocation %s against %s `%s' can not be used when making a shared object%s");
+  else
+    fmt = _("%B: relocation %s against undefined %s `%s' can not be used when making a shared object%s");
+
+  (*_bfd_error_handler) (fmt, input_bfd, howto->name,
+                        v,  h->root.root.string, pic);
+  bfd_set_error (bfd_error_bad_value);
+  return FALSE;
+}
+
 /* Relocate an x86_64 ELF section.  */
 
 static bfd_boolean
@@ -4078,8 +4114,7 @@ elf_x86_64_relocate_section (bfd *output_bfd,
              (*_bfd_error_handler)
                (_("%B: relocation %s against STT_GNU_IFUNC "
                   "symbol `%s' isn't handled by %s"), input_bfd,
-                x86_64_elf_howto_table[r_type].name,
-                name, __FUNCTION__);
+                howto->name, name, __FUNCTION__);
              bfd_set_error (bfd_error_bad_value);
              return FALSE;
 
@@ -4103,8 +4138,7 @@ elf_x86_64_relocate_section (bfd *output_bfd,
                  (*_bfd_error_handler)
                    (_("%B: relocation %s against STT_GNU_IFUNC "
                       "symbol `%s' has non-zero addend: %d"),
-                    input_bfd, x86_64_elf_howto_table[r_type].name,
-                    name, rel->r_addend);
+                    input_bfd, howto->name, name, rel->r_addend);
                  bfd_set_error (bfd_error_bad_value);
                  return FALSE;
                }
@@ -4536,39 +4570,7 @@ elf_x86_64_relocate_section (bfd *output_bfd,
                }
 
              if (fail)
-               {
-                 const char *fmt;
-                 const char *v;
-                 const char *pic = "";
-
-                 switch (ELF_ST_VISIBILITY (h->other))
-                   {
-                   case STV_HIDDEN:
-                     v = _("hidden symbol");
-                     break;
-                   case STV_INTERNAL:
-                     v = _("internal symbol");
-                     break;
-                   case STV_PROTECTED:
-                     v = _("protected symbol");
-                     break;
-                   default:
-                     v = _("symbol");
-                     pic = _("; recompile with -fPIC");
-                     break;
-                   }
-
-                 if (h->def_regular)
-                   fmt = _("%B: relocation %s against %s `%s' can not be used when making a shared object%s");
-                 else
-                   fmt = _("%B: relocation %s against undefined %s `%s' can not be used when making a shared object%s");
-
-                 (*_bfd_error_handler) (fmt, input_bfd,
-                                        x86_64_elf_howto_table[r_type].name,
-                                        v,  h->root.root.string, pic);
-                 bfd_set_error (bfd_error_bad_value);
-                 return FALSE;
-               }
+               return elf_x86_64_need_pic (input_bfd, h, howto);
            }
          /* Fall through.  */
 
@@ -4681,16 +4683,16 @@ direct:
                                 "symbol `%s' at 0x%lx in section `%A' is "
                                 "out of range"),
                               input_bfd, input_section, addend,
-                              x86_64_elf_howto_table[r_type].name,
-                              name, (unsigned long) rel->r_offset);
+                              howto->name, name,
+                              (unsigned long) rel->r_offset);
                          else
                            (*_bfd_error_handler)
                              (_("%B: addend 0x%x in relocation %s against "
                                 "symbol `%s' at 0x%lx in section `%A' is "
                                 "out of range"),
                               input_bfd, input_section, addend,
-                              x86_64_elf_howto_table[r_type].name,
-                              name, (unsigned long) rel->r_offset);
+                              howto->name, name,
+                              (unsigned long) rel->r_offset);
                          bfd_set_error (bfd_error_bad_value);
                          return FALSE;
                        }