+bfd_boolean
+elf32_hppa_build_stubs (struct bfd_link_info *info)
+{
+ asection *stub_sec;
+ struct bfd_hash_table *table;
+ struct elf32_hppa_link_hash_table *htab;
+
+ htab = hppa_link_hash_table (info);
+ if (htab == NULL)
+ return FALSE;
+
+ for (stub_sec = htab->stub_bfd->sections;
+ stub_sec != NULL;
+ stub_sec = stub_sec->next)
+ if ((stub_sec->flags & SEC_LINKER_CREATED) == 0
+ && stub_sec->size != 0)
+ {
+ /* Allocate memory to hold the linker stubs. */
+ stub_sec->contents = bfd_zalloc (htab->stub_bfd, stub_sec->size);
+ if (stub_sec->contents == NULL)
+ return FALSE;
+ stub_sec->size = 0;
+ }
+
+ /* Build the stubs as directed by the stub hash table. */
+ table = &htab->bstab;
+ bfd_hash_traverse (table, hppa_build_one_stub, info);
+
+ return TRUE;
+}
+
+/* Return the base vma address which should be subtracted from the real
+ address when resolving a dtpoff relocation.
+ This is PT_TLS segment p_vaddr. */
+
+static bfd_vma
+dtpoff_base (struct bfd_link_info *info)
+{
+ /* If tls_sec is NULL, we should have signalled an error already. */
+ if (elf_hash_table (info)->tls_sec == NULL)
+ return 0;
+ return elf_hash_table (info)->tls_sec->vma;
+}
+
+/* Return the relocation value for R_PARISC_TLS_TPOFF*.. */
+
+static bfd_vma
+tpoff (struct bfd_link_info *info, bfd_vma address)
+{
+ struct elf_link_hash_table *htab = elf_hash_table (info);
+
+ /* If tls_sec is NULL, we should have signalled an error already. */
+ if (htab->tls_sec == NULL)
+ return 0;
+ /* hppa TLS ABI is variant I and static TLS block start just after
+ tcbhead structure which has 2 pointer fields. */
+ return (address - htab->tls_sec->vma
+ + align_power ((bfd_vma) 8, htab->tls_sec->alignment_power));
+}
+
+/* Perform a final link. */
+
+static bfd_boolean
+elf32_hppa_final_link (bfd *abfd, struct bfd_link_info *info)
+{
+ struct stat buf;
+
+ /* Invoke the regular ELF linker to do all the work. */
+ if (!bfd_elf_final_link (abfd, info))
+ return FALSE;
+
+ /* If we're producing a final executable, sort the contents of the
+ unwind section. */
+ if (bfd_link_relocatable (info))
+ return TRUE;
+
+ /* Do not attempt to sort non-regular files. This is here
+ especially for configure scripts and kernel builds which run
+ tests with "ld [...] -o /dev/null". */
+ if (stat (abfd->filename, &buf) != 0
+ || !S_ISREG(buf.st_mode))
+ return TRUE;
+
+ return elf_hppa_sort_unwind (abfd);
+}
+
+/* Record the lowest address for the data and text segments. */
+
+static void
+hppa_record_segment_addr (bfd *abfd, asection *section, void *data)
+{
+ struct elf32_hppa_link_hash_table *htab;
+
+ htab = (struct elf32_hppa_link_hash_table*) data;
+ if (htab == NULL)
+ return;
+
+ if ((section->flags & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
+ {
+ bfd_vma value;
+ Elf_Internal_Phdr *p;
+
+ p = _bfd_elf_find_segment_containing_section (abfd, section->output_section);
+ BFD_ASSERT (p != NULL);
+ value = p->p_vaddr;
+
+ if ((section->flags & SEC_READONLY) != 0)
+ {
+ if (value < htab->text_segment_base)
+ htab->text_segment_base = value;
+ }
+ else
+ {
+ if (value < htab->data_segment_base)
+ htab->data_segment_base = value;
+ }
+ }
+}
+
+/* Perform a relocation as part of a final link. */
+
+static bfd_reloc_status_type
+final_link_relocate (asection *input_section,
+ bfd_byte *contents,
+ const Elf_Internal_Rela *rela,
+ bfd_vma value,
+ struct elf32_hppa_link_hash_table *htab,
+ asection *sym_sec,
+ struct elf32_hppa_link_hash_entry *hh,
+ struct bfd_link_info *info)
+{
+ int insn;
+ unsigned int r_type = ELF32_R_TYPE (rela->r_info);
+ unsigned int orig_r_type = r_type;
+ reloc_howto_type *howto = elf_hppa_howto_table + r_type;
+ int r_format = howto->bitsize;
+ enum hppa_reloc_field_selector_type_alt r_field;
+ bfd *input_bfd = input_section->owner;
+ bfd_vma offset = rela->r_offset;
+ bfd_vma max_branch_offset = 0;
+ bfd_byte *hit_data = contents + offset;
+ bfd_signed_vma addend = rela->r_addend;
+ bfd_vma location;
+ struct elf32_hppa_stub_hash_entry *hsh = NULL;
+ int val;
+
+ if (r_type == R_PARISC_NONE)
+ return bfd_reloc_ok;
+
+ insn = bfd_get_32 (input_bfd, hit_data);
+
+ /* Find out where we are and where we're going. */
+ location = (offset +
+ input_section->output_offset +
+ input_section->output_section->vma);
+
+ /* If we are not building a shared library, convert DLTIND relocs to
+ DPREL relocs. */
+ if (!bfd_link_pic (info))
+ {
+ switch (r_type)
+ {
+ case R_PARISC_DLTIND21L:
+ case R_PARISC_TLS_GD21L:
+ case R_PARISC_TLS_LDM21L:
+ case R_PARISC_TLS_IE21L:
+ r_type = R_PARISC_DPREL21L;
+ break;
+
+ case R_PARISC_DLTIND14R:
+ case R_PARISC_TLS_GD14R:
+ case R_PARISC_TLS_LDM14R:
+ case R_PARISC_TLS_IE14R:
+ r_type = R_PARISC_DPREL14R;
+ break;
+
+ case R_PARISC_DLTIND14F:
+ r_type = R_PARISC_DPREL14F;
+ break;
+ }
+ }
+
+ switch (r_type)
+ {
+ case R_PARISC_PCREL12F:
+ case R_PARISC_PCREL17F:
+ case R_PARISC_PCREL22F:
+ /* If this call should go via the plt, find the import stub in
+ the stub hash. */
+ if (sym_sec == NULL
+ || sym_sec->output_section == NULL
+ || (hh != NULL
+ && hh->eh.plt.offset != (bfd_vma) -1
+ && hh->eh.dynindx != -1
+ && !hh->plabel
+ && (bfd_link_pic (info)
+ || !hh->eh.def_regular
+ || hh->eh.root.type == bfd_link_hash_defweak)))
+ {
+ hsh = hppa_get_stub_entry (input_section, sym_sec,
+ hh, rela, htab);
+ if (hsh != NULL)
+ {
+ value = (hsh->stub_offset
+ + hsh->stub_sec->output_offset
+ + hsh->stub_sec->output_section->vma);
+ addend = 0;
+ }
+ else if (sym_sec == NULL && hh != NULL
+ && hh->eh.root.type == bfd_link_hash_undefweak)
+ {
+ /* It's OK if undefined weak. Calls to undefined weak
+ symbols behave as if the "called" function
+ immediately returns. We can thus call to a weak
+ function without first checking whether the function
+ is defined. */
+ value = location;
+ addend = 8;
+ }
+ else
+ return bfd_reloc_undefined;
+ }
+ /* Fall thru. */
+
+ case R_PARISC_PCREL21L:
+ case R_PARISC_PCREL17C:
+ case R_PARISC_PCREL17R:
+ case R_PARISC_PCREL14R:
+ case R_PARISC_PCREL14F:
+ case R_PARISC_PCREL32:
+ /* Make it a pc relative offset. */
+ value -= location;
+ addend -= 8;
+ break;
+
+ case R_PARISC_DPREL21L:
+ case R_PARISC_DPREL14R:
+ case R_PARISC_DPREL14F:
+ /* Convert instructions that use the linkage table pointer (r19) to
+ instructions that use the global data pointer (dp). This is the
+ most efficient way of using PIC code in an incomplete executable,
+ but the user must follow the standard runtime conventions for
+ accessing data for this to work. */
+ if (orig_r_type != r_type)
+ {
+ if (r_type == R_PARISC_DPREL21L)
+ {
+ /* GCC sometimes uses a register other than r19 for the
+ operation, so we must convert any addil instruction
+ that uses this relocation. */
+ if ((insn & 0xfc000000) == ((int) OP_ADDIL << 26))
+ insn = ADDIL_DP;
+ else
+ /* We must have a ldil instruction. It's too hard to find
+ and convert the associated add instruction, so issue an
+ error. */
+ _bfd_error_handler
+ /* xgettext:c-format */
+ (_("%pB(%pA+%#" PRIx64 "): %s fixup for insn %#x "
+ "is not supported in a non-shared link"),
+ input_bfd,
+ input_section,
+ (uint64_t) offset,
+ howto->name,
+ insn);
+ }
+ else if (r_type == R_PARISC_DPREL14F)
+ {
+ /* This must be a format 1 load/store. Change the base
+ register to dp. */
+ insn = (insn & 0xfc1ffff) | (27 << 21);
+ }
+ }
+
+ /* For all the DP relative relocations, we need to examine the symbol's
+ section. If it has no section or if it's a code section, then
+ "data pointer relative" makes no sense. In that case we don't
+ adjust the "value", and for 21 bit addil instructions, we change the
+ source addend register from %dp to %r0. This situation commonly
+ arises for undefined weak symbols and when a variable's "constness"
+ is declared differently from the way the variable is defined. For
+ instance: "extern int foo" with foo defined as "const int foo". */
+ if (sym_sec == NULL || (sym_sec->flags & SEC_CODE) != 0)
+ {
+ if ((insn & ((0x3f << 26) | (0x1f << 21)))
+ == (((int) OP_ADDIL << 26) | (27 << 21)))
+ {
+ insn &= ~ (0x1f << 21);
+ }
+ /* Now try to make things easy for the dynamic linker. */
+
+ break;
+ }
+ /* Fall thru. */
+
+ case R_PARISC_DLTIND21L:
+ case R_PARISC_DLTIND14R:
+ case R_PARISC_DLTIND14F:
+ case R_PARISC_TLS_GD21L:
+ case R_PARISC_TLS_LDM21L:
+ case R_PARISC_TLS_IE21L:
+ case R_PARISC_TLS_GD14R:
+ case R_PARISC_TLS_LDM14R:
+ case R_PARISC_TLS_IE14R:
+ value -= elf_gp (input_section->output_section->owner);
+ break;
+
+ case R_PARISC_SEGREL32:
+ if ((sym_sec->flags & SEC_CODE) != 0)
+ value -= htab->text_segment_base;
+ else
+ value -= htab->data_segment_base;
+ break;
+
+ default:
+ break;
+ }
+
+ switch (r_type)
+ {
+ case R_PARISC_DIR32:
+ case R_PARISC_DIR14F:
+ case R_PARISC_DIR17F:
+ case R_PARISC_PCREL17C:
+ case R_PARISC_PCREL14F:
+ case R_PARISC_PCREL32:
+ case R_PARISC_DPREL14F:
+ case R_PARISC_PLABEL32:
+ case R_PARISC_DLTIND14F:
+ case R_PARISC_SEGBASE:
+ case R_PARISC_SEGREL32:
+ case R_PARISC_TLS_DTPMOD32:
+ case R_PARISC_TLS_DTPOFF32:
+ case R_PARISC_TLS_TPREL32:
+ r_field = e_fsel;
+ break;
+
+ case R_PARISC_DLTIND21L:
+ case R_PARISC_PCREL21L:
+ case R_PARISC_PLABEL21L:
+ r_field = e_lsel;
+ break;
+
+ case R_PARISC_DIR21L:
+ case R_PARISC_DPREL21L:
+ case R_PARISC_TLS_GD21L:
+ case R_PARISC_TLS_LDM21L:
+ case R_PARISC_TLS_LDO21L:
+ case R_PARISC_TLS_IE21L:
+ case R_PARISC_TLS_LE21L:
+ r_field = e_lrsel;
+ break;
+
+ case R_PARISC_PCREL17R:
+ case R_PARISC_PCREL14R:
+ case R_PARISC_PLABEL14R:
+ case R_PARISC_DLTIND14R:
+ r_field = e_rsel;
+ break;
+
+ case R_PARISC_DIR17R:
+ case R_PARISC_DIR14R:
+ case R_PARISC_DPREL14R:
+ case R_PARISC_TLS_GD14R:
+ case R_PARISC_TLS_LDM14R:
+ case R_PARISC_TLS_LDO14R:
+ case R_PARISC_TLS_IE14R:
+ case R_PARISC_TLS_LE14R:
+ r_field = e_rrsel;
+ break;
+
+ case R_PARISC_PCREL12F:
+ case R_PARISC_PCREL17F:
+ case R_PARISC_PCREL22F:
+ r_field = e_fsel;
+
+ if (r_type == (unsigned int) R_PARISC_PCREL17F)
+ {
+ max_branch_offset = (1 << (17-1)) << 2;
+ }
+ else if (r_type == (unsigned int) R_PARISC_PCREL12F)
+ {
+ max_branch_offset = (1 << (12-1)) << 2;
+ }
+ else
+ {
+ max_branch_offset = (1 << (22-1)) << 2;
+ }
+
+ /* sym_sec is NULL on undefined weak syms or when shared on
+ undefined syms. We've already checked for a stub for the
+ shared undefined case. */
+ if (sym_sec == NULL)
+ break;
+
+ /* If the branch is out of reach, then redirect the
+ call to the local stub for this function. */
+ if (value + addend + max_branch_offset >= 2*max_branch_offset)
+ {
+ hsh = hppa_get_stub_entry (input_section, sym_sec,
+ hh, rela, htab);
+ if (hsh == NULL)
+ return bfd_reloc_undefined;
+
+ /* Munge up the value and addend so that we call the stub
+ rather than the procedure directly. */
+ value = (hsh->stub_offset
+ + hsh->stub_sec->output_offset
+ + hsh->stub_sec->output_section->vma
+ - location);
+ addend = -8;
+ }
+ break;
+
+ /* Something we don't know how to handle. */
+ default:
+ return bfd_reloc_notsupported;
+ }
+
+ /* Make sure we can reach the stub. */
+ if (max_branch_offset != 0
+ && value + addend + max_branch_offset >= 2*max_branch_offset)
+ {
+ _bfd_error_handler
+ /* xgettext:c-format */
+ (_("%pB(%pA+%#" PRIx64 "): cannot reach %s, "
+ "recompile with -ffunction-sections"),
+ input_bfd,
+ input_section,
+ (uint64_t) offset,
+ hsh->bh_root.string);
+ bfd_set_error (bfd_error_bad_value);
+ return bfd_reloc_notsupported;
+ }
+
+ val = hppa_field_adjust (value, addend, r_field);
+
+ switch (r_type)
+ {
+ case R_PARISC_PCREL12F:
+ case R_PARISC_PCREL17C:
+ case R_PARISC_PCREL17F:
+ case R_PARISC_PCREL17R:
+ case R_PARISC_PCREL22F:
+ case R_PARISC_DIR17F:
+ case R_PARISC_DIR17R:
+ /* This is a branch. Divide the offset by four.
+ Note that we need to decide whether it's a branch or
+ otherwise by inspecting the reloc. Inspecting insn won't
+ work as insn might be from a .word directive. */
+ val >>= 2;
+ break;
+
+ default:
+ break;
+ }
+
+ insn = hppa_rebuild_insn (insn, val, r_format);
+
+ /* Update the instruction word. */
+ bfd_put_32 (input_bfd, (bfd_vma) insn, hit_data);
+ return bfd_reloc_ok;
+}
+
+/* Relocate an HPPA ELF section. */
+
+static bfd_boolean
+elf32_hppa_relocate_section (bfd *output_bfd,
+ struct bfd_link_info *info,
+ bfd *input_bfd,
+ asection *input_section,
+ bfd_byte *contents,
+ Elf_Internal_Rela *relocs,
+ Elf_Internal_Sym *local_syms,
+ asection **local_sections)
+{
+ bfd_vma *local_got_offsets;
+ struct elf32_hppa_link_hash_table *htab;
+ Elf_Internal_Shdr *symtab_hdr;
+ Elf_Internal_Rela *rela;
+ Elf_Internal_Rela *relend;
+
+ symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
+
+ htab = hppa_link_hash_table (info);
+ if (htab == NULL)
+ return FALSE;
+
+ local_got_offsets = elf_local_got_offsets (input_bfd);
+
+ rela = relocs;
+ relend = relocs + input_section->reloc_count;
+ for (; rela < relend; rela++)
+ {
+ unsigned int r_type;
+ reloc_howto_type *howto;
+ unsigned int r_symndx;
+ struct elf32_hppa_link_hash_entry *hh;
+ Elf_Internal_Sym *sym;
+ asection *sym_sec;
+ bfd_vma relocation;
+ bfd_reloc_status_type rstatus;
+ const char *sym_name;
+ bfd_boolean plabel;
+ bfd_boolean warned_undef;
+
+ r_type = ELF32_R_TYPE (rela->r_info);
+ if (r_type >= (unsigned int) R_PARISC_UNIMPLEMENTED)
+ {
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+ }
+ if (r_type == (unsigned int) R_PARISC_GNU_VTENTRY
+ || r_type == (unsigned int) R_PARISC_GNU_VTINHERIT)
+ continue;
+
+ r_symndx = ELF32_R_SYM (rela->r_info);
+ hh = NULL;
+ sym = NULL;
+ sym_sec = NULL;
+ warned_undef = FALSE;
+ if (r_symndx < symtab_hdr->sh_info)
+ {
+ /* This is a local symbol, h defaults to NULL. */
+ sym = local_syms + r_symndx;
+ sym_sec = local_sections[r_symndx];
+ relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sym_sec, rela);
+ }
+ else
+ {
+ struct elf_link_hash_entry *eh;
+ bfd_boolean unresolved_reloc, ignored;
+ struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
+
+ RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rela,
+ r_symndx, symtab_hdr, sym_hashes,
+ eh, sym_sec, relocation,
+ unresolved_reloc, warned_undef,
+ ignored);
+
+ if (!bfd_link_relocatable (info)
+ && relocation == 0
+ && eh->root.type != bfd_link_hash_defined
+ && eh->root.type != bfd_link_hash_defweak
+ && eh->root.type != bfd_link_hash_undefweak)
+ {
+ if (info->unresolved_syms_in_objects == RM_IGNORE
+ && ELF_ST_VISIBILITY (eh->other) == STV_DEFAULT
+ && eh->type == STT_PARISC_MILLI)
+ {
+ (*info->callbacks->undefined_symbol)
+ (info, eh_name (eh), input_bfd,
+ input_section, rela->r_offset, FALSE);
+ warned_undef = TRUE;
+ }
+ }
+ hh = hppa_elf_hash_entry (eh);
+ }
+
+ if (sym_sec != NULL && discarded_section (sym_sec))
+ RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
+ rela, 1, relend,
+ elf_hppa_howto_table + r_type, 0,
+ contents);
+
+ if (bfd_link_relocatable (info))
+ continue;
+
+ /* Do any required modifications to the relocation value, and
+ determine what types of dynamic info we need to output, if
+ any. */
+ plabel = 0;
+ switch (r_type)
+ {
+ case R_PARISC_DLTIND14F:
+ case R_PARISC_DLTIND14R:
+ case R_PARISC_DLTIND21L:
+ {
+ bfd_vma off;
+ bfd_boolean do_got = FALSE;
+ bfd_boolean reloc = bfd_link_pic (info);
+
+ /* Relocation is to the entry for this symbol in the
+ global offset table. */
+ if (hh != NULL)
+ {
+ bfd_boolean dyn;
+
+ off = hh->eh.got.offset;
+ dyn = htab->etab.dynamic_sections_created;
+ reloc = (!UNDEFWEAK_NO_DYNAMIC_RELOC (info, &hh->eh)
+ && (reloc
+ || (hh->eh.dynindx != -1
+ && !SYMBOL_REFERENCES_LOCAL (info, &hh->eh))));
+ if (!reloc
+ || !WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
+ bfd_link_pic (info),
+ &hh->eh))
+ {
+ /* If we aren't going to call finish_dynamic_symbol,
+ then we need to handle initialisation of the .got
+ entry and create needed relocs here. Since the
+ offset must always be a multiple of 4, we use the
+ least significant bit to record whether we have
+ initialised it already. */
+ if ((off & 1) != 0)
+ off &= ~1;
+ else
+ {
+ hh->eh.got.offset |= 1;
+ do_got = TRUE;
+ }
+ }
+ }
+ else
+ {
+ /* Local symbol case. */
+ if (local_got_offsets == NULL)
+ abort ();
+
+ off = local_got_offsets[r_symndx];
+
+ /* The offset must always be a multiple of 4. We use
+ the least significant bit to record whether we have
+ already generated the necessary reloc. */
+ if ((off & 1) != 0)
+ off &= ~1;
+ else
+ {
+ local_got_offsets[r_symndx] |= 1;
+ do_got = TRUE;
+ }
+ }
+
+ if (do_got)
+ {
+ if (reloc)
+ {
+ /* Output a dynamic relocation for this GOT entry.
+ In this case it is relative to the base of the
+ object because the symbol index is zero. */
+ Elf_Internal_Rela outrel;
+ bfd_byte *loc;
+ asection *sec = htab->etab.srelgot;
+
+ outrel.r_offset = (off
+ + htab->etab.sgot->output_offset
+ + htab->etab.sgot->output_section->vma);
+ outrel.r_info = ELF32_R_INFO (0, R_PARISC_DIR32);
+ outrel.r_addend = relocation;
+ loc = sec->contents;
+ loc += sec->reloc_count++ * sizeof (Elf32_External_Rela);
+ bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
+ }
+ else
+ bfd_put_32 (output_bfd, relocation,
+ htab->etab.sgot->contents + off);
+ }
+
+ if (off >= (bfd_vma) -2)
+ abort ();
+
+ /* Add the base of the GOT to the relocation value. */
+ relocation = (off
+ + htab->etab.sgot->output_offset
+ + htab->etab.sgot->output_section->vma);
+ }
+ break;
+
+ case R_PARISC_SEGREL32:
+ /* If this is the first SEGREL relocation, then initialize
+ the segment base values. */
+ if (htab->text_segment_base == (bfd_vma) -1)
+ bfd_map_over_sections (output_bfd, hppa_record_segment_addr, htab);
+ break;
+
+ case R_PARISC_PLABEL14R:
+ case R_PARISC_PLABEL21L:
+ case R_PARISC_PLABEL32:
+ if (htab->etab.dynamic_sections_created)
+ {
+ bfd_vma off;
+ bfd_boolean do_plt = 0;
+ /* If we have a global symbol with a PLT slot, then
+ redirect this relocation to it. */
+ if (hh != NULL)
+ {
+ off = hh->eh.plt.offset;
+ if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (1,
+ bfd_link_pic (info),
+ &hh->eh))
+ {
+ /* In a non-shared link, adjust_dynamic_symbol
+ isn't called for symbols forced local. We
+ need to write out the plt entry here. */
+ if ((off & 1) != 0)
+ off &= ~1;
+ else
+ {
+ hh->eh.plt.offset |= 1;
+ do_plt = 1;
+ }
+ }
+ }
+ else
+ {
+ bfd_vma *local_plt_offsets;
+
+ if (local_got_offsets == NULL)
+ abort ();
+
+ local_plt_offsets = local_got_offsets + symtab_hdr->sh_info;
+ off = local_plt_offsets[r_symndx];
+
+ /* As for the local .got entry case, we use the last
+ bit to record whether we've already initialised
+ this local .plt entry. */
+ if ((off & 1) != 0)
+ off &= ~1;
+ else
+ {
+ local_plt_offsets[r_symndx] |= 1;
+ do_plt = 1;
+ }
+ }
+
+ if (do_plt)
+ {
+ if (bfd_link_pic (info))
+ {
+ /* Output a dynamic IPLT relocation for this
+ PLT entry. */
+ Elf_Internal_Rela outrel;
+ bfd_byte *loc;
+ asection *s = htab->etab.srelplt;
+
+ outrel.r_offset = (off
+ + htab->etab.splt->output_offset
+ + htab->etab.splt->output_section->vma);
+ outrel.r_info = ELF32_R_INFO (0, R_PARISC_IPLT);
+ outrel.r_addend = relocation;
+ loc = s->contents;
+ loc += s->reloc_count++ * sizeof (Elf32_External_Rela);
+ bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
+ }
+ else
+ {
+ bfd_put_32 (output_bfd,
+ relocation,
+ htab->etab.splt->contents + off);
+ bfd_put_32 (output_bfd,
+ elf_gp (htab->etab.splt->output_section->owner),
+ htab->etab.splt->contents + off + 4);
+ }
+ }
+
+ if (off >= (bfd_vma) -2)
+ abort ();
+
+ /* PLABELs contain function pointers. Relocation is to
+ the entry for the function in the .plt. The magic +2
+ offset signals to $$dyncall that the function pointer
+ is in the .plt and thus has a gp pointer too.
+ Exception: Undefined PLABELs should have a value of
+ zero. */
+ if (hh == NULL
+ || (hh->eh.root.type != bfd_link_hash_undefweak
+ && hh->eh.root.type != bfd_link_hash_undefined))
+ {
+ relocation = (off
+ + htab->etab.splt->output_offset
+ + htab->etab.splt->output_section->vma
+ + 2);
+ }
+ plabel = 1;
+ }
+ /* Fall through. */
+
+ case R_PARISC_DIR17F:
+ case R_PARISC_DIR17R:
+ case R_PARISC_DIR14F:
+ case R_PARISC_DIR14R:
+ case R_PARISC_DIR21L:
+ case R_PARISC_DPREL14F:
+ case R_PARISC_DPREL14R:
+ case R_PARISC_DPREL21L:
+ case R_PARISC_DIR32:
+ if ((input_section->flags & SEC_ALLOC) == 0)
+ break;
+
+ if (bfd_link_pic (info)
+ ? ((hh == NULL
+ || hh->dyn_relocs != NULL)
+ && ((hh != NULL && pc_dynrelocs (hh))
+ || IS_ABSOLUTE_RELOC (r_type)))
+ : (hh != NULL
+ && hh->dyn_relocs != NULL))
+ {
+ Elf_Internal_Rela outrel;
+ bfd_boolean skip;
+ asection *sreloc;
+ bfd_byte *loc;
+
+ /* When generating a shared object, these relocations
+ are copied into the output file to be resolved at run
+ time. */
+
+ outrel.r_addend = rela->r_addend;
+ outrel.r_offset =
+ _bfd_elf_section_offset (output_bfd, info, input_section,
+ rela->r_offset);
+ skip = (outrel.r_offset == (bfd_vma) -1
+ || outrel.r_offset == (bfd_vma) -2);
+ outrel.r_offset += (input_section->output_offset
+ + input_section->output_section->vma);
+
+ if (skip)
+ {
+ memset (&outrel, 0, sizeof (outrel));
+ }
+ else if (hh != NULL
+ && hh->eh.dynindx != -1
+ && (plabel
+ || !IS_ABSOLUTE_RELOC (r_type)
+ || !bfd_link_pic (info)
+ || !SYMBOLIC_BIND (info, &hh->eh)
+ || !hh->eh.def_regular))
+ {
+ outrel.r_info = ELF32_R_INFO (hh->eh.dynindx, r_type);
+ }
+ else /* It's a local symbol, or one marked to become local. */
+ {
+ int indx = 0;
+
+ /* Add the absolute offset of the symbol. */
+ outrel.r_addend += relocation;
+
+ /* Global plabels need to be processed by the
+ dynamic linker so that functions have at most one
+ fptr. For this reason, we need to differentiate
+ between global and local plabels, which we do by
+ providing the function symbol for a global plabel
+ reloc, and no symbol for local plabels. */
+ if (! plabel
+ && sym_sec != NULL
+ && sym_sec->output_section != NULL
+ && ! bfd_is_abs_section (sym_sec))
+ {
+ asection *osec;
+
+ osec = sym_sec->output_section;
+ indx = elf_section_data (osec)->dynindx;
+ if (indx == 0)
+ {
+ osec = htab->etab.text_index_section;
+ indx = elf_section_data (osec)->dynindx;
+ }
+ BFD_ASSERT (indx != 0);
+
+ /* We are turning this relocation into one
+ against a section symbol, so subtract out the
+ output section's address but not the offset
+ of the input section in the output section. */
+ outrel.r_addend -= osec->vma;
+ }
+
+ outrel.r_info = ELF32_R_INFO (indx, r_type);
+ }
+ sreloc = elf_section_data (input_section)->sreloc;
+ if (sreloc == NULL)
+ abort ();
+
+ loc = sreloc->contents;
+ loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
+ bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
+ }
+ break;
+
+ case R_PARISC_TLS_LDM21L:
+ case R_PARISC_TLS_LDM14R:
+ {
+ bfd_vma off;
+
+ off = htab->tls_ldm_got.offset;
+ if (off & 1)
+ off &= ~1;
+ else
+ {
+ Elf_Internal_Rela outrel;
+ bfd_byte *loc;
+
+ outrel.r_offset = (off
+ + htab->etab.sgot->output_section->vma
+ + htab->etab.sgot->output_offset);
+ outrel.r_addend = 0;
+ outrel.r_info = ELF32_R_INFO (0, R_PARISC_TLS_DTPMOD32);
+ loc = htab->etab.srelgot->contents;
+ loc += htab->etab.srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
+
+ bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
+ htab->tls_ldm_got.offset |= 1;
+ }
+
+ /* Add the base of the GOT to the relocation value. */
+ relocation = (off
+ + htab->etab.sgot->output_offset
+ + htab->etab.sgot->output_section->vma);
+
+ break;
+ }
+
+ case R_PARISC_TLS_LDO21L:
+ case R_PARISC_TLS_LDO14R:
+ relocation -= dtpoff_base (info);
+ break;
+
+ case R_PARISC_TLS_GD21L:
+ case R_PARISC_TLS_GD14R:
+ case R_PARISC_TLS_IE21L:
+ case R_PARISC_TLS_IE14R:
+ {
+ bfd_vma off;
+ int indx;
+ char tls_type;
+
+ indx = 0;
+ if (hh != NULL)
+ {
+ if (!htab->etab.dynamic_sections_created
+ || hh->eh.dynindx == -1
+ || SYMBOL_REFERENCES_LOCAL (info, &hh->eh)
+ || UNDEFWEAK_NO_DYNAMIC_RELOC (info, &hh->eh))
+ /* This is actually a static link, or it is a
+ -Bsymbolic link and the symbol is defined
+ locally, or the symbol was forced to be local
+ because of a version file. */
+ ;
+ else
+ indx = hh->eh.dynindx;
+ off = hh->eh.got.offset;
+ tls_type = hh->tls_type;
+ }
+ else
+ {
+ off = local_got_offsets[r_symndx];
+ tls_type = hppa_elf_local_got_tls_type (input_bfd)[r_symndx];
+ }
+
+ if (tls_type == GOT_UNKNOWN)
+ abort ();
+
+ if ((off & 1) != 0)
+ off &= ~1;
+ else
+ {
+ bfd_boolean need_relocs = FALSE;
+ Elf_Internal_Rela outrel;
+ bfd_byte *loc = NULL;
+ int cur_off = off;
+
+ /* The GOT entries have not been initialized yet. Do it
+ now, and emit any relocations. If both an IE GOT and a
+ GD GOT are necessary, we emit the GD first. */
+
+ if (indx != 0
+ || (bfd_link_dll (info)
+ && (hh == NULL
+ || !UNDEFWEAK_NO_DYNAMIC_RELOC (info, &hh->eh))))
+ {
+ need_relocs = TRUE;
+ loc = htab->etab.srelgot->contents;
+ loc += (htab->etab.srelgot->reloc_count
+ * sizeof (Elf32_External_Rela));
+ }
+
+ if (tls_type & GOT_TLS_GD)
+ {
+ if (need_relocs)
+ {
+ outrel.r_offset
+ = (cur_off
+ + htab->etab.sgot->output_section->vma
+ + htab->etab.sgot->output_offset);
+ outrel.r_info
+ = ELF32_R_INFO (indx, R_PARISC_TLS_DTPMOD32);
+ outrel.r_addend = 0;
+ bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
+ htab->etab.srelgot->reloc_count++;
+ loc += sizeof (Elf32_External_Rela);
+ bfd_put_32 (output_bfd, 0,
+ htab->etab.sgot->contents + cur_off);
+ }
+ else
+ /* If we are not emitting relocations for a
+ general dynamic reference, then we must be in a
+ static link or an executable link with the
+ symbol binding locally. Mark it as belonging
+ to module 1, the executable. */
+ bfd_put_32 (output_bfd, 1,
+ htab->etab.sgot->contents + cur_off);
+
+ if (indx != 0)
+ {
+ outrel.r_info
+ = ELF32_R_INFO (indx, R_PARISC_TLS_DTPOFF32);
+ outrel.r_offset += 4;
+ bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
+ htab->etab.srelgot->reloc_count++;
+ loc += sizeof (Elf32_External_Rela);
+ bfd_put_32 (output_bfd, 0,
+ htab->etab.sgot->contents + cur_off + 4);
+ }
+ else
+ bfd_put_32 (output_bfd, relocation - dtpoff_base (info),
+ htab->etab.sgot->contents + cur_off + 4);
+ cur_off += 8;
+ }
+
+ if (tls_type & GOT_TLS_IE)
+ {
+ if (need_relocs
+ && !(bfd_link_executable (info)
+ && SYMBOL_REFERENCES_LOCAL (info, &hh->eh)))
+ {
+ outrel.r_offset
+ = (cur_off
+ + htab->etab.sgot->output_section->vma
+ + htab->etab.sgot->output_offset);
+ outrel.r_info = ELF32_R_INFO (indx,
+ R_PARISC_TLS_TPREL32);
+ if (indx == 0)
+ outrel.r_addend = relocation - dtpoff_base (info);
+ else
+ outrel.r_addend = 0;
+ bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
+ htab->etab.srelgot->reloc_count++;
+ loc += sizeof (Elf32_External_Rela);
+ }
+ else
+ bfd_put_32 (output_bfd, tpoff (info, relocation),
+ htab->etab.sgot->contents + cur_off);
+ cur_off += 4;
+ }
+
+ if (hh != NULL)
+ hh->eh.got.offset |= 1;
+ else
+ local_got_offsets[r_symndx] |= 1;
+ }
+
+ if ((tls_type & GOT_NORMAL) != 0
+ && (tls_type & (GOT_TLS_GD | GOT_TLS_LDM | GOT_TLS_IE)) != 0)
+ {
+ if (hh != NULL)
+ _bfd_error_handler (_("%s has both normal and TLS relocs"),
+ hh_name (hh));
+ else
+ {
+ Elf_Internal_Sym *isym
+ = bfd_sym_from_r_symndx (&htab->sym_cache,
+ input_bfd, r_symndx);
+ if (isym == NULL)
+ return FALSE;
+ sym_name
+ = bfd_elf_string_from_elf_section (input_bfd,
+ symtab_hdr->sh_link,
+ isym->st_name);
+ if (sym_name == NULL)
+ return FALSE;
+ if (*sym_name == '\0')
+ sym_name = bfd_section_name (input_bfd, sym_sec);
+ _bfd_error_handler
+ (_("%pB:%s has both normal and TLS relocs"),
+ input_bfd, sym_name);
+ }
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+ }
+
+ if ((tls_type & GOT_TLS_GD)
+ && r_type != R_PARISC_TLS_GD21L
+ && r_type != R_PARISC_TLS_GD14R)
+ off += 2 * GOT_ENTRY_SIZE;
+
+ /* Add the base of the GOT to the relocation value. */
+ relocation = (off
+ + htab->etab.sgot->output_offset
+ + htab->etab.sgot->output_section->vma);
+
+ break;
+ }
+
+ case R_PARISC_TLS_LE21L:
+ case R_PARISC_TLS_LE14R:
+ {
+ relocation = tpoff (info, relocation);
+ break;
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ rstatus = final_link_relocate (input_section, contents, rela, relocation,
+ htab, sym_sec, hh, info);
+
+ if (rstatus == bfd_reloc_ok)
+ continue;
+
+ if (hh != NULL)
+ sym_name = hh_name (hh);
+ else
+ {
+ sym_name = bfd_elf_string_from_elf_section (input_bfd,
+ symtab_hdr->sh_link,
+ sym->st_name);
+ if (sym_name == NULL)
+ return FALSE;
+ if (*sym_name == '\0')
+ sym_name = bfd_section_name (input_bfd, sym_sec);
+ }
+
+ howto = elf_hppa_howto_table + r_type;
+
+ if (rstatus == bfd_reloc_undefined || rstatus == bfd_reloc_notsupported)
+ {
+ if (rstatus == bfd_reloc_notsupported || !warned_undef)
+ {
+ _bfd_error_handler
+ /* xgettext:c-format */
+ (_("%pB(%pA+%#" PRIx64 "): cannot handle %s for %s"),
+ input_bfd,
+ input_section,
+ (uint64_t) rela->r_offset,
+ howto->name,
+ sym_name);
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+ }
+ }
+ else
+ (*info->callbacks->reloc_overflow)
+ (info, (hh ? &hh->eh.root : NULL), sym_name, howto->name,
+ (bfd_vma) 0, input_bfd, input_section, rela->r_offset);
+ }
+
+ return TRUE;
+}
+
+/* Finish up dynamic symbol handling. We set the contents of various
+ dynamic sections here. */
+
+static bfd_boolean
+elf32_hppa_finish_dynamic_symbol (bfd *output_bfd,
+ struct bfd_link_info *info,
+ struct elf_link_hash_entry *eh,
+ Elf_Internal_Sym *sym)
+{
+ struct elf32_hppa_link_hash_table *htab;
+ Elf_Internal_Rela rela;
+ bfd_byte *loc;
+
+ htab = hppa_link_hash_table (info);
+ if (htab == NULL)
+ return FALSE;
+
+ if (eh->plt.offset != (bfd_vma) -1)
+ {
+ bfd_vma value;
+
+ if (eh->plt.offset & 1)
+ abort ();
+
+ /* This symbol has an entry in the procedure linkage table. Set
+ it up.
+
+ The format of a plt entry is
+ <funcaddr>
+ <__gp>
+ */
+ value = 0;
+ if (eh->root.type == bfd_link_hash_defined
+ || eh->root.type == bfd_link_hash_defweak)
+ {
+ value = eh->root.u.def.value;
+ if (eh->root.u.def.section->output_section != NULL)
+ value += (eh->root.u.def.section->output_offset
+ + eh->root.u.def.section->output_section->vma);
+ }
+
+ /* Create a dynamic IPLT relocation for this entry. */
+ rela.r_offset = (eh->plt.offset
+ + htab->etab.splt->output_offset
+ + htab->etab.splt->output_section->vma);
+ if (eh->dynindx != -1)
+ {
+ rela.r_info = ELF32_R_INFO (eh->dynindx, R_PARISC_IPLT);
+ rela.r_addend = 0;
+ }
+ else
+ {
+ /* This symbol has been marked to become local, and is
+ used by a plabel so must be kept in the .plt. */
+ rela.r_info = ELF32_R_INFO (0, R_PARISC_IPLT);
+ rela.r_addend = value;
+ }
+
+ loc = htab->etab.srelplt->contents;
+ loc += htab->etab.srelplt->reloc_count++ * sizeof (Elf32_External_Rela);
+ bfd_elf32_swap_reloca_out (htab->etab.splt->output_section->owner, &rela, loc);
+
+ if (!eh->def_regular)
+ {
+ /* Mark the symbol as undefined, rather than as defined in
+ the .plt section. Leave the value alone. */
+ sym->st_shndx = SHN_UNDEF;
+ }
+ }
+
+ if (eh->got.offset != (bfd_vma) -1
+ && (hppa_elf_hash_entry (eh)->tls_type & GOT_NORMAL) != 0
+ && !UNDEFWEAK_NO_DYNAMIC_RELOC (info, eh))
+ {
+ bfd_boolean is_dyn = (eh->dynindx != -1
+ && !SYMBOL_REFERENCES_LOCAL (info, eh));
+
+ if (is_dyn || bfd_link_pic (info))
+ {
+ /* This symbol has an entry in the global offset table. Set
+ it up. */
+
+ rela.r_offset = ((eh->got.offset &~ (bfd_vma) 1)
+ + htab->etab.sgot->output_offset
+ + htab->etab.sgot->output_section->vma);
+
+ /* If this is a -Bsymbolic link and the symbol is defined
+ locally or was forced to be local because of a version
+ file, we just want to emit a RELATIVE reloc. The entry
+ in the global offset table will already have been
+ initialized in the relocate_section function. */
+ if (!is_dyn)
+ {
+ rela.r_info = ELF32_R_INFO (0, R_PARISC_DIR32);
+ rela.r_addend = (eh->root.u.def.value
+ + eh->root.u.def.section->output_offset
+ + eh->root.u.def.section->output_section->vma);
+ }
+ else
+ {
+ if ((eh->got.offset & 1) != 0)
+ abort ();
+
+ bfd_put_32 (output_bfd, 0,
+ htab->etab.sgot->contents + (eh->got.offset & ~1));
+ rela.r_info = ELF32_R_INFO (eh->dynindx, R_PARISC_DIR32);
+ rela.r_addend = 0;
+ }
+
+ loc = htab->etab.srelgot->contents;
+ loc += (htab->etab.srelgot->reloc_count++
+ * sizeof (Elf32_External_Rela));
+ bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
+ }
+ }
+
+ if (eh->needs_copy)
+ {
+ asection *sec;
+
+ /* This symbol needs a copy reloc. Set it up. */
+
+ if (! (eh->dynindx != -1
+ && (eh->root.type == bfd_link_hash_defined
+ || eh->root.type == bfd_link_hash_defweak)))
+ abort ();
+
+ rela.r_offset = (eh->root.u.def.value
+ + eh->root.u.def.section->output_offset
+ + eh->root.u.def.section->output_section->vma);
+ rela.r_addend = 0;
+ rela.r_info = ELF32_R_INFO (eh->dynindx, R_PARISC_COPY);
+ if (eh->root.u.def.section == htab->etab.sdynrelro)
+ sec = htab->etab.sreldynrelro;
+ else
+ sec = htab->etab.srelbss;
+ loc = sec->contents + sec->reloc_count++ * sizeof (Elf32_External_Rela);
+ bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
+ }
+
+ /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
+ if (eh == htab->etab.hdynamic || eh == htab->etab.hgot)
+ {
+ sym->st_shndx = SHN_ABS;
+ }
+
+ return TRUE;
+}
+
+/* Used to decide how to sort relocs in an optimal manner for the
+ dynamic linker, before writing them out. */
+
+static enum elf_reloc_type_class
+elf32_hppa_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
+ const asection *rel_sec ATTRIBUTE_UNUSED,
+ const Elf_Internal_Rela *rela)
+{
+ /* Handle TLS relocs first; we don't want them to be marked
+ relative by the "if (ELF32_R_SYM (rela->r_info) == STN_UNDEF)"
+ check below. */
+ switch ((int) ELF32_R_TYPE (rela->r_info))
+ {
+ case R_PARISC_TLS_DTPMOD32:
+ case R_PARISC_TLS_DTPOFF32:
+ case R_PARISC_TLS_TPREL32:
+ return reloc_class_normal;
+ }
+
+ if (ELF32_R_SYM (rela->r_info) == STN_UNDEF)
+ return reloc_class_relative;
+
+ switch ((int) ELF32_R_TYPE (rela->r_info))
+ {
+ case R_PARISC_IPLT:
+ return reloc_class_plt;
+ case R_PARISC_COPY:
+ return reloc_class_copy;
+ default:
+ return reloc_class_normal;
+ }
+}
+
+/* Finish up the dynamic sections. */
+
+static bfd_boolean
+elf32_hppa_finish_dynamic_sections (bfd *output_bfd,
+ struct bfd_link_info *info)
+{
+ bfd *dynobj;
+ struct elf32_hppa_link_hash_table *htab;
+ asection *sdyn;
+ asection * sgot;
+
+ htab = hppa_link_hash_table (info);
+ if (htab == NULL)
+ return FALSE;
+
+ dynobj = htab->etab.dynobj;
+
+ sgot = htab->etab.sgot;
+ /* A broken linker script might have discarded the dynamic sections.
+ Catch this here so that we do not seg-fault later on. */
+ if (sgot != NULL && bfd_is_abs_section (sgot->output_section))
+ return FALSE;
+
+ sdyn = bfd_get_linker_section (dynobj, ".dynamic");
+
+ if (htab->etab.dynamic_sections_created)
+ {
+ Elf32_External_Dyn *dyncon, *dynconend;
+
+ if (sdyn == NULL)
+ abort ();
+
+ dyncon = (Elf32_External_Dyn *) sdyn->contents;
+ dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
+ for (; dyncon < dynconend; dyncon++)
+ {
+ Elf_Internal_Dyn dyn;
+ asection *s;
+
+ bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
+
+ switch (dyn.d_tag)
+ {
+ default:
+ continue;
+
+ case DT_PLTGOT:
+ /* Use PLTGOT to set the GOT register. */
+ dyn.d_un.d_ptr = elf_gp (output_bfd);
+ break;
+
+ case DT_JMPREL:
+ s = htab->etab.srelplt;
+ dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
+ break;
+
+ case DT_PLTRELSZ:
+ s = htab->etab.srelplt;
+ dyn.d_un.d_val = s->size;
+ break;
+ }
+
+ bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
+ }
+ }
+
+ if (sgot != NULL && sgot->size != 0)
+ {
+ /* Fill in the first entry in the global offset table.
+ We use it to point to our dynamic section, if we have one. */
+ bfd_put_32 (output_bfd,
+ sdyn ? sdyn->output_section->vma + sdyn->output_offset : 0,
+ sgot->contents);
+
+ /* The second entry is reserved for use by the dynamic linker. */
+ memset (sgot->contents + GOT_ENTRY_SIZE, 0, GOT_ENTRY_SIZE);
+
+ /* Set .got entry size. */
+ elf_section_data (sgot->output_section)
+ ->this_hdr.sh_entsize = GOT_ENTRY_SIZE;
+ }
+
+ if (htab->etab.splt != NULL && htab->etab.splt->size != 0)
+ {
+ /* Set plt entry size to 0 instead of PLT_ENTRY_SIZE, since we add the
+ plt stubs and as such the section does not hold a table of fixed-size
+ entries. */
+ elf_section_data (htab->etab.splt->output_section)->this_hdr.sh_entsize = 0;
+
+ if (htab->need_plt_stub)
+ {
+ /* Set up the .plt stub. */
+ memcpy (htab->etab.splt->contents
+ + htab->etab.splt->size - sizeof (plt_stub),
+ plt_stub, sizeof (plt_stub));
+
+ if ((htab->etab.splt->output_offset
+ + htab->etab.splt->output_section->vma
+ + htab->etab.splt->size)
+ != (sgot->output_offset
+ + sgot->output_section->vma))
+ {
+ _bfd_error_handler
+ (_(".got section not immediately after .plt section"));
+ return FALSE;
+ }
+ }
+ }
+
+ return TRUE;
+}
+
+/* Called when writing out an object file to decide the type of a
+ symbol. */
+static int
+elf32_hppa_elf_get_symbol_type (Elf_Internal_Sym *elf_sym, int type)
+{
+ if (ELF_ST_TYPE (elf_sym->st_info) == STT_PARISC_MILLI)
+ return STT_PARISC_MILLI;
+ else
+ return type;
+}
+
+/* Misc BFD support code. */
+#define bfd_elf32_bfd_is_local_label_name elf_hppa_is_local_label_name
+#define bfd_elf32_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
+#define bfd_elf32_bfd_reloc_name_lookup elf_hppa_reloc_name_lookup
+#define elf_info_to_howto elf_hppa_info_to_howto
+#define elf_info_to_howto_rel elf_hppa_info_to_howto_rel
+
+/* Stuff for the BFD linker. */
+#define bfd_elf32_bfd_final_link elf32_hppa_final_link
+#define bfd_elf32_bfd_link_hash_table_create elf32_hppa_link_hash_table_create
+#define elf_backend_adjust_dynamic_symbol elf32_hppa_adjust_dynamic_symbol
+#define elf_backend_copy_indirect_symbol elf32_hppa_copy_indirect_symbol
+#define elf_backend_check_relocs elf32_hppa_check_relocs
+#define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
+#define elf_backend_create_dynamic_sections elf32_hppa_create_dynamic_sections
+#define elf_backend_fake_sections elf_hppa_fake_sections
+#define elf_backend_relocate_section elf32_hppa_relocate_section
+#define elf_backend_hide_symbol elf32_hppa_hide_symbol
+#define elf_backend_finish_dynamic_symbol elf32_hppa_finish_dynamic_symbol
+#define elf_backend_finish_dynamic_sections elf32_hppa_finish_dynamic_sections
+#define elf_backend_size_dynamic_sections elf32_hppa_size_dynamic_sections
+#define elf_backend_init_index_section _bfd_elf_init_1_index_section
+#define elf_backend_gc_mark_hook elf32_hppa_gc_mark_hook
+#define elf_backend_grok_prstatus elf32_hppa_grok_prstatus
+#define elf_backend_grok_psinfo elf32_hppa_grok_psinfo
+#define elf_backend_object_p elf32_hppa_object_p
+#define elf_backend_final_write_processing elf_hppa_final_write_processing
+#define elf_backend_get_symbol_type elf32_hppa_elf_get_symbol_type
+#define elf_backend_reloc_type_class elf32_hppa_reloc_type_class
+#define elf_backend_action_discarded elf_hppa_action_discarded
+
+#define elf_backend_can_gc_sections 1
+#define elf_backend_can_refcount 1
+#define elf_backend_plt_alignment 2
+#define elf_backend_want_got_plt 0
+#define elf_backend_plt_readonly 0
+#define elf_backend_want_plt_sym 0
+#define elf_backend_got_header_size 8
+#define elf_backend_want_dynrelro 1
+#define elf_backend_rela_normal 1
+#define elf_backend_dtrel_excludes_plt 1
+#define elf_backend_no_page_alias 1
+
+#define TARGET_BIG_SYM hppa_elf32_vec
+#define TARGET_BIG_NAME "elf32-hppa"
+#define ELF_ARCH bfd_arch_hppa
+#define ELF_TARGET_ID HPPA32_ELF_DATA
+#define ELF_MACHINE_CODE EM_PARISC
+#define ELF_MAXPAGESIZE 0x1000
+#define ELF_OSABI ELFOSABI_HPUX
+#define elf32_bed elf32_hppa_hpux_bed
+
+#include "elf32-target.h"
+
+#undef TARGET_BIG_SYM
+#define TARGET_BIG_SYM hppa_elf32_linux_vec
+#undef TARGET_BIG_NAME
+#define TARGET_BIG_NAME "elf32-hppa-linux"
+#undef ELF_OSABI
+#define ELF_OSABI ELFOSABI_GNU
+#undef elf32_bed
+#define elf32_bed elf32_hppa_linux_bed
+
+#include "elf32-target.h"
+
+#undef TARGET_BIG_SYM
+#define TARGET_BIG_SYM hppa_elf32_nbsd_vec
+#undef TARGET_BIG_NAME
+#define TARGET_BIG_NAME "elf32-hppa-netbsd"
+#undef ELF_OSABI
+#define ELF_OSABI ELFOSABI_NETBSD
+#undef elf32_bed
+#define elf32_bed elf32_hppa_netbsd_bed