Remove U suffix from constants for K&R compilers.
[deliverable/binutils-gdb.git] / bfd / elf-hppa.h
index c8dab6c632fec30c62891054980d467062348056..b55e1c4e5bc1111f238c2e38128794d6edf8e42b 100644 (file)
@@ -63,6 +63,15 @@ static boolean elf_hppa_add_symbol_hook
 static boolean elf_hppa_final_link
   PARAMS ((bfd *, struct bfd_link_info *));
 
+static boolean elf_hppa_unmark_useless_dynamic_symbols
+  PARAMS ((struct elf_link_hash_entry *, PTR));
+
+static boolean elf_hppa_remark_useless_dynamic_symbols
+  PARAMS ((struct elf_link_hash_entry *, PTR));
+
+static void elf_hppa_record_segment_addrs
+  PARAMS ((bfd *, asection *, PTR));
+
 /* ELF/PA relocation howto entries.  */
 
 static reloc_howto_type elf_hppa_howto_table[ELF_HOWTO_TABLE_SIZE] =
@@ -159,8 +168,8 @@ static reloc_howto_type elf_hppa_howto_table[ELF_HOWTO_TABLE_SIZE] =
   {R_PARISC_PCREL16DF, 0, 0, 0, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_PARISC_PCREL16DF"},
 
   {R_PARISC_DIR64, 0, 0, 0, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_PARISC_DIR64"},
-  {R_PARISC_DIR64WR, 0, 0, 0, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_PARISC_DIR64WR"},
-  {R_PARISC_DIR64DR, 0, 0, 0, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_PARISC_DIR64DR"},
+  {R_PARISC_NONE, 0, 0, 0, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_PARISC_NONE"},
+  {R_PARISC_NONE, 0, 0, 0, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_PARISC_NONE"},
   {R_PARISC_DIR14WR, 0, 0, 0, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_PARISC_DIR14WR"},
   {R_PARISC_DIR14DR, 0, 0, 0, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_PARISC_DIR14DR"},
   {R_PARISC_DIR16F, 0, 0, 0, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_PARISC_DIR16F"},
@@ -182,8 +191,8 @@ static reloc_howto_type elf_hppa_howto_table[ELF_HOWTO_TABLE_SIZE] =
 
   {R_PARISC_DLTIND14DR, 0, 0, 0, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_PARISC_DLTIND14DR"},
   {R_PARISC_LTOFF16F, 0, 0, 0, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_PARISC_LTOFF16F"},
+  {R_PARISC_LTOFF16WF, 0, 0, 0, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_PARISC_LTOFF16DF"},
   {R_PARISC_LTOFF16DF, 0, 0, 0, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_PARISC_LTOFF16DF"},
-  {R_PARISC_SECREL64, 0, 0, 0, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_PARISC_SECREL64"},
   {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_PARISC_UNIMPLEMENTED"},
   {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_PARISC_UNIMPLEMENTED"},
   {R_PARISC_BASEREL14WR, 0, 0, 0, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_PARISC_BSEREL14WR"},
@@ -647,7 +656,13 @@ elf_hppa_final_write_processing (abfd, linker)
   else if (mach == 20)
     elf_elfheader (abfd)->e_flags |= EFA_PARISC_2_0;
   else if (mach == 25)
-    elf_elfheader (abfd)->e_flags |= EF_PARISC_WIDE | EFA_PARISC_2_0;
+    elf_elfheader (abfd)->e_flags |= (EF_PARISC_WIDE
+                                     | EFA_PARISC_2_0
+                                     /* The GNU tools have trapped without
+                                        option since 1993, so need to take
+                                        a step backwards with the ELF
+                                        based toolchains.  */
+                                     | EF_PARISC_TRAPNIL);
 }
 
 /* Return true if SYM represents a local label symbol.  */
@@ -736,6 +751,98 @@ elf_hppa_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
   return true;
 }
 
+static boolean
+elf_hppa_unmark_useless_dynamic_symbols (h, data)
+     struct elf_link_hash_entry *h;
+     PTR data;
+{
+  struct bfd_link_info *info = (struct bfd_link_info *)data;
+
+  /* If we are not creating a shared library, and this symbol is
+     referenced by a shared library but is not defined anywhere, then
+     the generic code will warn that it is undefined.
+
+     This behavior is undesirable on HPs since the standard shared
+     libraries contain reerences to undefined symbols.
+
+     So we twiddle the flags associated with such symbols so that they
+     will not trigger the warning.  ?!? FIXME.  This is horribly fraglie.
+
+     Ultimately we should have better controls over the generic ELF BFD
+     linker code.  */
+  if (! info->relocateable
+      && ! (info->shared
+           && !info->no_undefined)
+      && h->root.type == bfd_link_hash_undefined
+      && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0
+      && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0)
+    {
+      h->elf_link_hash_flags &= ~ELF_LINK_HASH_REF_DYNAMIC;
+      h->elf_link_hash_flags |= 0x8000;
+    }
+
+  return true;
+}
+
+
+static boolean
+elf_hppa_remark_useless_dynamic_symbols (h, data)
+     struct elf_link_hash_entry *h;
+     PTR data;
+{
+  struct bfd_link_info *info = (struct bfd_link_info *)data;
+
+  /* If we are not creating a shared library, and this symbol is
+     referenced by a shared library but is not defined anywhere, then
+     the generic code will warn that it is undefined.
+
+     This behavior is undesirable on HPs since the standard shared
+     libraries contain reerences to undefined symbols.
+
+     So we twiddle the flags associated with such symbols so that they
+     will not trigger the warning.  ?!? FIXME.  This is horribly fragile.
+
+     Ultimately we should have better controls over the generic ELF BFD
+     linker code.  */
+  if (! info->relocateable
+      && ! (info->shared
+           && !info->no_undefined)
+      && h->root.type == bfd_link_hash_undefined
+      && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0
+      && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0
+      && (h->elf_link_hash_flags & 0x8000) != 0)
+    {
+      h->elf_link_hash_flags |= ELF_LINK_HASH_REF_DYNAMIC;
+      h->elf_link_hash_flags &= ~0x8000;
+    }
+
+  return true;
+}
+
+/* Record the lowest address for the data and text segments.  */
+static void
+elf_hppa_record_segment_addrs (abfd, section, data)
+     bfd *abfd ATTRIBUTE_UNUSED;
+     asection *section;
+     PTR data;
+{
+  struct elf64_hppa_link_hash_table *hppa_info;
+  bfd_vma value;
+  hppa_info = (struct elf64_hppa_link_hash_table *)data;
+
+  value = section->vma - section->filepos;
+
+  if ((section->flags & (SEC_ALLOC | SEC_LOAD | SEC_READONLY)
+       == (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
+      && value < hppa_info->text_segment_base)
+    hppa_info->text_segment_base = value;
+  else if ((section->flags & (SEC_ALLOC | SEC_LOAD | SEC_READONLY)
+       == (SEC_ALLOC | SEC_LOAD))
+      && value < hppa_info->data_segment_base)
+    hppa_info->data_segment_base = value;
+}
+
 /* Called after we have seen all the input files/sections, but before
    final symbol resolution and section placement has been determined.
 
@@ -747,40 +854,97 @@ elf_hppa_final_link (abfd, info)
      bfd *abfd;
      struct bfd_link_info *info;
 {
-  /* Make sure we've got ourselves a suitable __gp value.  */
-  if (!info->relocateable)
+  boolean retval;
+
+  if (! info->relocateable)
     {
-      bfd_vma min_short_vma = (bfd_vma) -1, max_short_vma = 0;
       struct elf_link_hash_entry *gp;
-      bfd_vma gp_val = 0;
-      asection *os;
+      bfd_vma gp_val;
+      struct elf64_hppa_link_hash_table *hppa_info;
+
+      hppa_info = elf64_hppa_hash_table (info);
 
-      /* Find the .opd section.  __gp's value should be the same as
-        the start of .PARISC.global section.  */
-      for (os = abfd->sections; os ; os = os->next)
+      /* The linker script defines a value for __gp iff it was referenced
+        by one of the objects being linked.  First try to find the symbol
+        in the hash table.  If that fails, just compute the value __gp
+        should have had.  */
+      gp = elf_link_hash_lookup (elf_hash_table (info), "__gp", false,
+                                false, false);
+
+      if (gp)
        {
-         bfd_vma lo, hi;
 
-         /* This would be cleaner if we marked sections with an attribute
-            indicating they are short sections.  */
-         if (strcmp (os->name, ".PARISC.global") == 0)
-           break;
+         /* Adjust the value of __gp as we may want to slide it into the
+            .plt section so that the stubs can access PLT entries without
+            using an addil sequence.  */
+         gp->root.u.def.value += elf64_hppa_hash_table (info)->gp_offset;
+
+         gp_val = (gp->root.u.def.section->output_section->vma
+                   + gp->root.u.def.section->output_offset
+                   + gp->root.u.def.value);
        }
+      else
+       {
+         asection *sec;
+  
 
-      BFD_ASSERT (os != NULL)
+         /* First look for a .plt section.  If found, then __gp is the
+            address of the .plt + gp_offset.
 
-      gp_val = (os->output_section->vma + os->output_offset);
-                  
-      gp = elf_link_hash_lookup (elf_hash_table (info), "__gp", true,
-                                true, false);
-      gp->root.type = bfd_link_hash_defined;
-      gp->root.u.def.section = os;
-      gp->root.u.def.value = 0;
+            If no .plt is found, then look for .dlt, .opd and .data (in
+            that order) and set __gp to the base address of whichever section
+           is found first.  */
+
+         sec = hppa_info->plt_sec;
+         if (sec)
+           gp_val = (sec->output_offset
+                     + sec->output_section->vma
+                     + hppa_info->gp_offset);
+         else
+           {
+             sec = hppa_info->dlt_sec;
+             if (!sec)
+               sec = hppa_info->opd_sec;
+             if (!sec)
+               sec = bfd_get_section_by_name (abfd, ".data");
+             if (!sec)
+               return false;
+
+             gp_val = sec->output_offset + sec->output_section->vma;
+           }
+       }
+
+      /* Install whatever value we found/computed for __gp.  */
       _bfd_set_gp_value (abfd, gp_val);
     }
 
+  /* We need to know the base of the text and data segments so that we
+     can perform SEGREL relocations.  We will recore the base addresses
+     when we encounter the first SEGREL relocation.  */
+  elf64_hppa_hash_table (info)->text_segment_base = (bfd_vma)-1;
+  elf64_hppa_hash_table (info)->data_segment_base = (bfd_vma)-1;
+
+  /* HP's shared libraries have references to symbols that are not
+     defined anywhere.  The generic ELF BFD linker code will complaim
+     about such symbols.
+
+     So we detect the losing case and arrange for the flags on the symbol
+     to indicate that it was never referenced.  This keeps the generic
+     ELF BFD link code happy and appears to not create any secondary
+     problems.  Ultimately we need a way to control the behavior of the
+     generic ELF BFD link code better.  */
+  elf_link_hash_traverse (elf_hash_table (info),
+                         elf_hppa_unmark_useless_dynamic_symbols,
+                         info);
+
   /* Invoke the regular ELF backend linker to do all the work.  */
-  return bfd_elf_bfd_final_link (abfd, info);
+  retval = bfd_elf_bfd_final_link (abfd, info);
+
+  elf_link_hash_traverse (elf_hash_table (info),
+                         elf_hppa_remark_useless_dynamic_symbols,
+                         info);
+
+  return retval;
 }
 
 /* Relocate an HPPA ELF section.  */
@@ -809,7 +973,7 @@ elf_hppa_relocate_section (output_bfd, info, input_bfd, input_section,
   for (; rel < relend; rel++)
     {
       int r_type;
-      reloc_howto_type *howto;
+      reloc_howto_type *howto = elf_hppa_howto_table + ELF_R_TYPE (rel->r_info);
       unsigned long r_symndx;
       struct elf_link_hash_entry *h;
       Elf_Internal_Sym *sym;
@@ -887,7 +1051,6 @@ elf_hppa_relocate_section (output_bfd, info, input_bfd, input_section,
            {
              sym_sec = h->root.u.def.section;
 
-
              /* If this symbol has an entry in the PA64 dynamic hash
                 table, then get it.  */
              dyn_name = get_dyn_name (input_bfd, h, rel,
@@ -915,13 +1078,38 @@ elf_hppa_relocate_section (output_bfd, info, input_bfd, input_section,
              else
                relocation = 0;
            }
+         /* Allow undefined symbols in shared libraries.  */
+          else if (info->shared && !info->no_undefined)
+           {
+             if (info->symbolic)
+               (*info->callbacks->undefined_symbol)
+                 (info, h->root.root.string, input_bfd,
+                  input_section, rel->r_offset, false);
+
+             /* If this symbol has an entry in the PA64 dynamic hash
+                table, then get it.  */
+             dyn_name = get_dyn_name (input_bfd, h, rel,
+                                      &dynh_buf, &dynh_buflen);
+             dyn_h = elf64_hppa_dyn_hash_lookup (&hppa_info->dyn_hash_table,
+                                                 dyn_name, false, false);
+
+             if (dyn_h == NULL)
+               {
+                 (*_bfd_error_handler)
+                   (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"),
+                    bfd_get_filename (input_bfd), h->root.root.string,
+                    bfd_get_section_name (input_bfd, input_section));
+                 relocation = 0;
+               }
+             relocation = 0;
+           }
          else if (h->root.type == bfd_link_hash_undefweak)
            relocation = 0;
          else
            {
              if (!((*info->callbacks->undefined_symbol)
                    (info, h->root.root.string, input_bfd,
-                    input_section, rel->r_offset)))
+                    input_section, rel->r_offset, true)))
                return false;
              break;
            }
@@ -999,24 +1187,12 @@ elf_hppa_final_link_relocate (rel, input_bfd, output_bfd,
   bfd_vma addend = rel->r_addend;
   reloc_howto_type *howto = elf_hppa_howto_table + ELF_R_TYPE (rel->r_info);
   unsigned long r_type = howto->type;
-  unsigned long r_format = howto->bitsize;
   unsigned long r_field = e_fsel;
   bfd_byte *hit_data = contents + offset;
   struct elf64_hppa_link_hash_table *hppa_info = elf64_hppa_hash_table (info);
 
   insn = bfd_get_32 (input_bfd, hit_data);
 
-/* For reference here a quick summary of the relocations found in the
-   HPUX 11.00 PA64 .o and .a files, but not yet implemented.  This is mostly
-   a guide to help prioritize what relocation support is worked on first.
-   The list will be deleted eventually.
-
-   27210 R_PARISC_SEGREL32
-   772 R_PARISC_PLTOFF14DR
-   386 R_PARISC_PLTOFF21L
-   6 R_PARISC_LTOFF64
-   5 R_PARISC_SEGREL64  */
-
   switch (r_type)
     {
     case R_PARISC_NONE:
@@ -1045,8 +1221,9 @@ elf_hppa_final_link_relocate (rel, input_bfd, output_bfd,
        /* If this is a call to a function defined in another dynamic
           library, then redirect the call to the local stub for this
           function.  */
-       if (sym_sec->output_section == NULL)
-         value = dyn_h->stub_offset;
+       if (sym_sec == NULL || sym_sec->output_section == NULL)
+         value = (dyn_h->stub_offset + hppa_info->stub_sec->output_offset
+                  + hppa_info->stub_sec->output_section->vma);
   
        /* Turn VALUE into a proper PC relative address.  */
        value -= (offset + input_section->output_offset
@@ -1079,8 +1256,9 @@ elf_hppa_final_link_relocate (rel, input_bfd, output_bfd,
        /* If this is a call to a function defined in another dynamic
           library, then redirect the call to the local stub for this
           function.  */
-       if (sym_sec->output_section == NULL)
-         value = dyn_h->stub_offset;
+       if (sym_sec == NULL || sym_sec->output_section == NULL)
+         value = (dyn_h->stub_offset + hppa_info->stub_sec->output_offset
+                  + hppa_info->stub_sec->output_section->vma);
   
        /* Turn VALUE into a proper PC relative address.  */
        value -= (offset + input_section->output_offset
@@ -1118,10 +1296,62 @@ elf_hppa_final_link_relocate (rel, input_bfd, output_bfd,
     case R_PARISC_LTOFF_TP16F:
     case R_PARISC_LTOFF_TP16WF:
     case R_PARISC_LTOFF_TP16DF:
+    case R_PARISC_LTOFF16F:
+    case R_PARISC_LTOFF16WF:
+    case R_PARISC_LTOFF16DF:
       {
+       /* If this relocation was against a local symbol, then we still
+          have not set up the DLT entry (it's not convienent to do so
+          in the "finalize_dlt" routine because it is difficult to get
+          to the local symbol's value).
+
+          So, if this is a local symbol (h == NULL), then we need to
+          fill in its DLT entry. 
+
+          Similarly we may still need to set up an entry in .opd for
+          a local function which had its address taken.  */
+       if (dyn_h->h == NULL)
+         {
+           bfd_put_64 (hppa_info->dlt_sec->owner,
+                       value,
+                       hppa_info->dlt_sec->contents + dyn_h->dlt_offset);
+
+           /* Now handle .opd creation if needed.  */
+           if (r_type == R_PARISC_LTOFF_FPTR14R
+               || r_type == R_PARISC_LTOFF_FPTR14DR
+               || r_type == R_PARISC_LTOFF_FPTR14WR
+               || r_type == R_PARISC_LTOFF_FPTR21L
+               || r_type == R_PARISC_LTOFF_FPTR16F
+               || r_type == R_PARISC_LTOFF_FPTR16WF
+               || r_type == R_PARISC_LTOFF_FPTR16DF)
+             {
+               /* The first two words of an .opd entry are zero.  */
+               memset (hppa_info->opd_sec->contents + dyn_h->opd_offset,
+                       0, 16);
+
+               /* The next word is the address of the function.  */
+               bfd_put_64 (hppa_info->opd_sec->owner, value,
+                           (hppa_info->opd_sec->contents
+                            + dyn_h->opd_offset + 16));
+
+               /* The last word is our local __gp value.  */
+               value = _bfd_get_gp_value
+                         (hppa_info->opd_sec->output_section->owner);
+               bfd_put_64 (hppa_info->opd_sec->owner, value,
+                           (hppa_info->opd_sec->contents
+                            + dyn_h->opd_offset + 24));
+             }
+         }
+
        /* We want the value of the DLT offset for this symbol, not
-          the symbol's actual address.  */
-       value = dyn_h->dlt_offset + hppa_info->dlt_sec->output_offset;
+          the symbol's actual address.  Note that __gp may not point
+          to the start of the DLT, so we have to compute the absolute
+          address, then subtract out the value of __gp.  */
+       value = (dyn_h->dlt_offset
+                + hppa_info->dlt_sec->output_offset
+                + hppa_info->dlt_sec->output_section->vma);
+       value -= _bfd_get_gp_value (output_bfd);
+
 
        /* All DLTIND relocations are basically the same at this point,
           except that we need different field selectors for the 21bit
@@ -1134,6 +1364,9 @@ elf_hppa_final_link_relocate (rel, input_bfd, output_bfd,
                 || r_type == R_PARISC_LTOFF_FPTR16F
                 || r_type == R_PARISC_LTOFF_FPTR16WF
                 || r_type == R_PARISC_LTOFF_FPTR16DF
+                || r_type == R_PARISC_LTOFF16F
+                || r_type == R_PARISC_LTOFF16DF
+                || r_type == R_PARISC_LTOFF16WF
                 || r_type == R_PARISC_LTOFF_TP16F
                 || r_type == R_PARISC_LTOFF_TP16WF
                 || r_type == R_PARISC_LTOFF_TP16DF)
@@ -1182,11 +1415,97 @@ elf_hppa_final_link_relocate (rel, input_bfd, output_bfd,
        break;
       }
 
+    case R_PARISC_DIR21L:
+    case R_PARISC_DIR17R:
+    case R_PARISC_DIR17F:
+    case R_PARISC_DIR14R:
+    case R_PARISC_DIR14WR:
+    case R_PARISC_DIR14DR:
+    case R_PARISC_DIR16F:
+    case R_PARISC_DIR16WF:
+    case R_PARISC_DIR16DF:
+      {
+       /* All DIR relocations are basically the same at this point,
+          except that we need different field selectors for the 21bit
+          version vs the 14bit versions.  */
+       if (r_type == R_PARISC_DIR21L)
+         value = hppa_field_adjust (value, addend, e_lrsel);
+       else if (r_type == R_PARISC_DIR17F
+                || r_type == R_PARISC_DIR16F
+                || r_type == R_PARISC_DIR16WF
+                || r_type == R_PARISC_DIR16DF)
+         value = hppa_field_adjust (value, addend, e_fsel);
+       else
+         value = hppa_field_adjust (value, addend, e_rrsel);
+
+       insn = elf_hppa_relocate_insn (insn, value, r_type);
+       break;
+      }
+
+    case R_PARISC_PLTOFF21L:
+    case R_PARISC_PLTOFF14R:
+    case R_PARISC_PLTOFF14F:
+    case R_PARISC_PLTOFF14WR:
+    case R_PARISC_PLTOFF14DR:
+    case R_PARISC_PLTOFF16F:
+    case R_PARISC_PLTOFF16WF:
+    case R_PARISC_PLTOFF16DF:
+      {
+       /* We want the value of the PLT offset for this symbol, not
+          the symbol's actual address.  Note that __gp may not point
+          to the start of the DLT, so we have to compute the absolute
+          address, then subtract out the value of __gp.  */
+       value = (dyn_h->plt_offset
+                + hppa_info->plt_sec->output_offset
+                + hppa_info->plt_sec->output_section->vma);
+       value -= _bfd_get_gp_value (output_bfd);
+
+       /* All PLTOFF relocations are basically the same at this point,
+          except that we need different field selectors for the 21bit
+          version vs the 14bit versions.  */
+       if (r_type == R_PARISC_PLTOFF21L)
+         value = hppa_field_adjust (value, addend, e_lrsel);
+       else if (r_type == R_PARISC_PLTOFF14F
+                || r_type == R_PARISC_PLTOFF16F
+                || r_type == R_PARISC_PLTOFF16WF
+                || r_type == R_PARISC_PLTOFF16DF)
+         value = hppa_field_adjust (value, addend, e_fsel);
+       else
+         value = hppa_field_adjust (value, addend, e_rrsel);
+
+       insn = elf_hppa_relocate_insn (insn, value, r_type);
+       break;
+      }
+
     case R_PARISC_LTOFF_FPTR32:
       {
+       /* We may still need to create the FPTR itself if it was for
+          a local symbol.  */
+       if (dyn_h->h == NULL)
+         {
+           /* The first two words of an .opd entry are zero.  */
+           memset (hppa_info->opd_sec->contents + dyn_h->opd_offset, 0, 16);
+
+           /* The next word is the address of the function.  */
+           bfd_put_64 (hppa_info->opd_sec->owner, value,
+                       (hppa_info->opd_sec->contents
+                        + dyn_h->opd_offset + 16));
+
+           /* The last word is our local __gp value.  */
+           value = _bfd_get_gp_value
+                     (hppa_info->opd_sec->output_section->owner);
+           bfd_put_64 (hppa_info->opd_sec->owner, value,
+                       hppa_info->opd_sec->contents + dyn_h->opd_offset + 24);
+         }
+
        /* We want the value of the DLT offset for this symbol, not
-          the symbol's actual address.  */
-       value = dyn_h->dlt_offset + hppa_info->dlt_sec->output_offset;
+          the symbol's actual address.  Note that __gp may not point
+          to the start of the DLT, so we have to compute the absolute
+          address, then subtract out the value of __gp.  */
+       value = (dyn_h->dlt_offset
+                + hppa_info->dlt_sec->output_offset
+                + hppa_info->dlt_sec->output_section->vma);
+       value -= _bfd_get_gp_value (output_bfd);
        bfd_put_32 (input_bfd, value, hit_data);
        return bfd_reloc_ok;
       }
@@ -1194,9 +1513,33 @@ elf_hppa_final_link_relocate (rel, input_bfd, output_bfd,
     case R_PARISC_LTOFF_FPTR64:
     case R_PARISC_LTOFF_TP64:
       {
+       /* We may still need to create the FPTR itself if it was for
+          a local symbol.  */
+       if (dyn_h->h == NULL && r_type == R_PARISC_LTOFF_FPTR64)
+         {
+           /* The first two words of an .opd entry are zero.  */
+           memset (hppa_info->opd_sec->contents + dyn_h->opd_offset, 0, 16);
+
+           /* The next word is the address of the function.  */
+           bfd_put_64 (hppa_info->opd_sec->owner, value,
+                       (hppa_info->opd_sec->contents
+                        + dyn_h->opd_offset + 16));
+
+           /* The last word is our local __gp value.  */
+           value = _bfd_get_gp_value
+                     (hppa_info->opd_sec->output_section->owner);
+           bfd_put_64 (hppa_info->opd_sec->owner, value,
+                       hppa_info->opd_sec->contents + dyn_h->opd_offset + 24);
+         }
+
        /* We want the value of the DLT offset for this symbol, not
-          the symbol's actual address.  */
-       value = dyn_h->dlt_offset + hppa_info->dlt_sec->output_offset;
+          the symbol's actual address.  Note that __gp may not point
+          to the start of the DLT, so we have to compute the absolute
+          address, then subtract out the value of __gp.  */
+       value = (dyn_h->dlt_offset
+                + hppa_info->dlt_sec->output_offset
+                + hppa_info->dlt_sec->output_section->vma);
+       value -= _bfd_get_gp_value (output_bfd);
        bfd_put_64 (input_bfd, value, hit_data);
        return bfd_reloc_ok;
       }
@@ -1218,13 +1561,27 @@ elf_hppa_final_link_relocate (rel, input_bfd, output_bfd,
       bfd_put_64 (input_bfd, value + addend, hit_data);
       return bfd_reloc_ok;
 
+    case R_PARISC_LTOFF64:
+       /* We want the value of the DLT offset for this symbol, not
+          the symbol's actual address.  Note that __gp may not point
+          to the start of the DLT, so we have to compute the absolute
+          address, then subtract out the value of __gp.  */
+      value = (dyn_h->dlt_offset
+              + hppa_info->dlt_sec->output_offset
+              + hppa_info->dlt_sec->output_section->vma);
+      value -= _bfd_get_gp_value (output_bfd);
+
+      bfd_put_64 (input_bfd, value + addend, hit_data);
+      return bfd_reloc_ok;
+
     case R_PARISC_PCREL32:
       {
        /* If this is a call to a function defined in another dynamic
           library, then redirect the call to the local stub for this
           function.  */
-       if (sym_sec->output_section == NULL)
-         value = dyn_h->stub_offset;
+       if (sym_sec == NULL || sym_sec->output_section == NULL)
+         value = (dyn_h->stub_offset + hppa_info->stub_sec->output_offset
+                  + hppa_info->stub_sec->output_section->vma);
   
        /* Turn VALUE into a proper PC relative address.  */
        value -= (offset + input_section->output_offset
@@ -1241,8 +1598,10 @@ elf_hppa_final_link_relocate (rel, input_bfd, output_bfd,
        /* If this is a call to a function defined in another dynamic
           library, then redirect the call to the local stub for this
           function.  */
-       if (sym_sec->output_section == NULL)
-         value = dyn_h->stub_offset;
+       if (sym_sec == NULL || sym_sec->output_section == NULL)
+         value = (dyn_h->stub_offset + hppa_info->stub_sec->output_offset
+                  + hppa_info->stub_sec->output_section->vma);
+  
   
        /* Turn VALUE into a proper PC relative address.  */
        value -= (offset + input_section->output_offset
@@ -1255,21 +1614,77 @@ elf_hppa_final_link_relocate (rel, input_bfd, output_bfd,
       }
 
 
-    /* These do not require any work here.  They are simply passed
-       through as dynamic relocations.  */
     case R_PARISC_FPTR64:
+      {
+       /* We may still need to create the FPTR itself if it was for
+          a local symbol.  */
+       if (dyn_h->h == NULL)
+         {
+           /* The first two words of an .opd entry are zero.  */
+           memset (hppa_info->opd_sec->contents + dyn_h->opd_offset, 0, 16);
+
+           /* The next word is the address of the function.  */
+           bfd_put_64 (hppa_info->opd_sec->owner, value,
+                       (hppa_info->opd_sec->contents
+                        + dyn_h->opd_offset + 16));
+
+           /* The last word is our local __gp value.  */
+           value = _bfd_get_gp_value
+                     (hppa_info->opd_sec->output_section->owner);
+           bfd_put_64 (hppa_info->opd_sec->owner, value,
+                       hppa_info->opd_sec->contents + dyn_h->opd_offset + 24);
+         }
+
+       /* We want the value of the OPD offset for this symbol, not
+           the symbol's actual address.  */
+       value = (dyn_h->opd_offset
+                + hppa_info->opd_sec->output_offset
+                + hppa_info->opd_sec->output_section->vma);
+              
+       bfd_put_64 (input_bfd, value + addend, hit_data);
+       return bfd_reloc_ok;
+      }
+
+    case R_PARISC_SECREL32:
+      bfd_put_32 (input_bfd,
+                 (value + addend
+                  - sym_sec->output_section->vma),
+                 hit_data);
       return bfd_reloc_ok;
 
+    case R_PARISC_SEGREL32:
+    case R_PARISC_SEGREL64:
+      {
+       /* If this is the first SEGREL relocation, then initialize
+          the segment base values.  */
+       if (hppa_info->text_segment_base == (bfd_vma) -1)
+         bfd_map_over_sections (output_bfd, elf_hppa_record_segment_addrs,
+                                elf64_hppa_hash_table (info));
+
+       /* VALUE holds the absolute address.  We want to include the
+          addend, then turn it into a segment relative address.
+
+          The segment is derived from SYM_SEC.  We assume that there are
+          only two segments of note in the resulting executable/shlib.
+          A readonly segment (.text) and a readwrite segment (.data).  */
+       value += addend;
+
+       if (sym_sec->flags & SEC_CODE)
+         value -= hppa_info->text_segment_base;
+       else
+         value -= hppa_info->data_segment_base;
+
+       if (r_type == R_PARISC_SEGREL32)
+         bfd_put_32 (input_bfd, value, hit_data);
+       else
+         bfd_put_64 (input_bfd, value, hit_data);
+        return bfd_reloc_ok;
+      }
+      
+
     /* Something we don't know how to handle.  */
     default:
-      /* ?!? This is temporary as we flesh out basic linker support, once
-        the basic support is functional we will return the not_supported
-        error conditional appropriately.  */
-#if 0
-      return bfd_reloc_not_supported;
-#else
-      return bfd_reloc_ok;
-#endif
+      return bfd_reloc_notsupported;
     }
 
   /* Update the instruction word.  */
@@ -1289,8 +1704,6 @@ elf_hppa_relocate_insn (insn, sym_value, r_type)
      long sym_value;
      unsigned long r_type;
 {
-  long constant_value;
-
   switch (r_type)
     {
     /* This is any 22bit branch.  In PA2.0 syntax it corresponds to
@@ -1320,6 +1733,7 @@ elf_hppa_relocate_insn (insn, sym_value, r_type)
        the "B" instruction as well as BE.  */
     case R_PARISC_PCREL17F:
     case R_PARISC_DIR17F:
+    case R_PARISC_DIR17R:
     case R_PARISC_PCREL17C:
     case R_PARISC_PCREL17R:
       {
@@ -1348,6 +1762,8 @@ elf_hppa_relocate_insn (insn, sym_value, r_type)
     case R_PARISC_PCREL21L:
     case R_PARISC_LTOFF_TP21L:
     case R_PARISC_DPREL21L:
+    case R_PARISC_PLTOFF21L:
+    case R_PARISC_DIR21L:
       {
         int w;
 
@@ -1377,6 +1793,12 @@ elf_hppa_relocate_insn (insn, sym_value, r_type)
     case R_PARISC_DPREL14R:
     case R_PARISC_DPREL14F:
     case R_PARISC_GPREL16F:
+    case R_PARISC_PLTOFF14R:
+    case R_PARISC_PLTOFF14F:
+    case R_PARISC_PLTOFF16F:
+    case R_PARISC_DIR14R:
+    case R_PARISC_DIR16F:
+    case R_PARISC_LTOFF16F:
       {
         int w;
 
@@ -1401,9 +1823,12 @@ elf_hppa_relocate_insn (insn, sym_value, r_type)
     case R_PARISC_LTOFF_TP16DF:
     case R_PARISC_DPREL14DR:
     case R_PARISC_GPREL16DF:
+    case R_PARISC_PLTOFF14DR:
+    case R_PARISC_PLTOFF16DF:
+    case R_PARISC_DIR14DR:
+    case R_PARISC_DIR16DF:
+    case R_PARISC_LTOFF16DF:
       {
-        int w;
-
        /* Mask off bits in INSN we do not want.  */
        insn &= 0xffffc00e;
 
@@ -1431,9 +1856,12 @@ elf_hppa_relocate_insn (insn, sym_value, r_type)
     case R_PARISC_LTOFF_TP16WF:
     case R_PARISC_DPREL14WR:
     case R_PARISC_GPREL16WF:
+    case R_PARISC_PLTOFF14WR:
+    case R_PARISC_PLTOFF16WF:
+    case R_PARISC_DIR16WF:
+    case R_PARISC_DIR14WR:
+    case R_PARISC_LTOFF16WF:
       {
-        int w;
-
        /* Mask off bits in INSN we do not want.  */
        insn &= 0xffffc006;
 
@@ -1450,7 +1878,6 @@ elf_hppa_relocate_insn (insn, sym_value, r_type)
        return insn | sym_value;
       }
 
-
     default:
       return insn;
     }
This page took 0.031144 seconds and 4 git commands to generate.