+ const struct external_ldrel *src = (const struct external_ldrel *) s;
+
+ dst->l_vaddr = bfd_get_32 (abfd, src->l_vaddr);
+ dst->l_symndx = bfd_get_32 (abfd, src->l_symndx);
+ dst->l_rtype = bfd_get_16 (abfd, src->l_rtype);
+ dst->l_rsecnm = bfd_get_16 (abfd, src->l_rsecnm);
+}
+
+/* Swap out the ldrel structure. */
+
+static void
+xcoff_swap_ldrel_out (abfd, src, d)
+ bfd *abfd;
+ const struct internal_ldrel *src;
+ PTR d;
+{
+ struct external_ldrel *dst = (struct external_ldrel *) d;
+
+ bfd_put_32 (abfd, src->l_vaddr, dst->l_vaddr);
+ bfd_put_32 (abfd, src->l_symndx, dst->l_symndx);
+ bfd_put_16 (abfd, (bfd_vma) src->l_rtype, dst->l_rtype);
+ bfd_put_16 (abfd, (bfd_vma) src->l_rsecnm, dst->l_rsecnm);
+}
+\f
+
+bfd_boolean
+xcoff_reloc_type_noop (input_bfd, input_section, output_bfd, rel, sym, howto,
+ val, addend, relocation, contents)
+ bfd *input_bfd ATTRIBUTE_UNUSED;
+ asection *input_section ATTRIBUTE_UNUSED;
+ bfd *output_bfd ATTRIBUTE_UNUSED;
+ struct internal_reloc *rel ATTRIBUTE_UNUSED;
+ struct internal_syment *sym ATTRIBUTE_UNUSED;
+ struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
+ bfd_vma val ATTRIBUTE_UNUSED;
+ bfd_vma addend ATTRIBUTE_UNUSED;
+ bfd_vma *relocation ATTRIBUTE_UNUSED;
+ bfd_byte *contents ATTRIBUTE_UNUSED;
+{
+ return TRUE;
+}
+
+bfd_boolean
+xcoff_reloc_type_fail (input_bfd, input_section, output_bfd, rel, sym, howto,
+ val, addend, relocation, contents)
+ bfd *input_bfd;
+ asection *input_section ATTRIBUTE_UNUSED;
+ bfd *output_bfd ATTRIBUTE_UNUSED;
+ struct internal_reloc *rel;
+ struct internal_syment *sym ATTRIBUTE_UNUSED;
+ struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
+ bfd_vma val ATTRIBUTE_UNUSED;
+ bfd_vma addend ATTRIBUTE_UNUSED;
+ bfd_vma *relocation ATTRIBUTE_UNUSED;
+ bfd_byte *contents ATTRIBUTE_UNUSED;
+{
+ (*_bfd_error_handler)
+ (_("%s: unsupported relocation type 0x%02x"),
+ bfd_get_filename (input_bfd), (unsigned int) rel->r_type);
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+}
+
+bfd_boolean
+xcoff_reloc_type_pos (input_bfd, input_section, output_bfd, rel, sym, howto,
+ val, addend, relocation, contents)
+ bfd *input_bfd ATTRIBUTE_UNUSED;
+ asection *input_section ATTRIBUTE_UNUSED;
+ bfd *output_bfd ATTRIBUTE_UNUSED;
+ struct internal_reloc *rel ATTRIBUTE_UNUSED;
+ struct internal_syment *sym ATTRIBUTE_UNUSED;
+ struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
+ bfd_vma val;
+ bfd_vma addend;
+ bfd_vma *relocation;
+ bfd_byte *contents ATTRIBUTE_UNUSED;
+{
+ *relocation = val + addend;
+ return TRUE;
+}
+
+bfd_boolean
+xcoff_reloc_type_neg (input_bfd, input_section, output_bfd, rel, sym, howto,
+ val, addend, relocation, contents)
+ bfd *input_bfd ATTRIBUTE_UNUSED;
+ asection *input_section ATTRIBUTE_UNUSED;
+ bfd *output_bfd ATTRIBUTE_UNUSED;
+ struct internal_reloc *rel ATTRIBUTE_UNUSED;
+ struct internal_syment *sym ATTRIBUTE_UNUSED;
+ struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
+ bfd_vma val;
+ bfd_vma addend;
+ bfd_vma *relocation;
+ bfd_byte *contents ATTRIBUTE_UNUSED;
+{
+ *relocation = addend - val;
+ return TRUE;
+}
+
+bfd_boolean
+xcoff_reloc_type_rel (input_bfd, input_section, output_bfd, rel, sym, howto,
+ val, addend, relocation, contents)
+ bfd *input_bfd ATTRIBUTE_UNUSED;
+ asection *input_section;
+ bfd *output_bfd ATTRIBUTE_UNUSED;
+ struct internal_reloc *rel ATTRIBUTE_UNUSED;
+ struct internal_syment *sym ATTRIBUTE_UNUSED;
+ struct reloc_howto_struct *howto;
+ bfd_vma val;
+ bfd_vma addend;
+ bfd_vma *relocation;
+ bfd_byte *contents ATTRIBUTE_UNUSED;
+{
+ howto->pc_relative = TRUE;
+
+ /* A PC relative reloc includes the section address. */
+ addend += input_section->vma;
+
+ *relocation = val + addend;
+ *relocation -= (input_section->output_section->vma
+ + input_section->output_offset);
+ return TRUE;
+}
+
+bfd_boolean
+xcoff_reloc_type_toc (input_bfd, input_section, output_bfd, rel, sym, howto,
+ val, addend, relocation, contents)
+ bfd *input_bfd;
+ asection *input_section ATTRIBUTE_UNUSED;
+ bfd *output_bfd;
+ struct internal_reloc *rel;
+ struct internal_syment *sym;
+ struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
+ bfd_vma val;
+ bfd_vma addend ATTRIBUTE_UNUSED;
+ bfd_vma *relocation;
+ bfd_byte *contents ATTRIBUTE_UNUSED;
+{
+ struct xcoff_link_hash_entry *h;
+
+ if (0 > rel->r_symndx)
+ return FALSE;
+
+ h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx];
+
+ if (h != NULL && h->smclas != XMC_TD)
+ {
+ if (h->toc_section == NULL)
+ {
+ (*_bfd_error_handler)
+ (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
+ bfd_get_filename (input_bfd), rel->r_vaddr,
+ h->root.root.string);
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+ }
+
+ BFD_ASSERT ((h->flags & XCOFF_SET_TOC) == 0);
+ val = (h->toc_section->output_section->vma
+ + h->toc_section->output_offset);
+ }
+
+ *relocation = ((val - xcoff_data (output_bfd)->toc)
+ - (sym->n_value - xcoff_data (input_bfd)->toc));
+ return TRUE;
+}
+
+bfd_boolean
+xcoff_reloc_type_ba (input_bfd, input_section, output_bfd, rel, sym, howto,
+ val, addend, relocation, contents)
+ bfd *input_bfd ATTRIBUTE_UNUSED;
+ asection *input_section ATTRIBUTE_UNUSED;
+ bfd *output_bfd ATTRIBUTE_UNUSED;
+ struct internal_reloc *rel ATTRIBUTE_UNUSED;
+ struct internal_syment *sym ATTRIBUTE_UNUSED;
+ struct reloc_howto_struct *howto;
+ bfd_vma val;
+ bfd_vma addend;
+ bfd_vma *relocation;
+ bfd_byte *contents ATTRIBUTE_UNUSED;
+{
+ howto->src_mask &= ~3;
+ howto->dst_mask = howto->src_mask;
+
+ *relocation = val + addend;
+
+ return TRUE;
+}
+
+static bfd_boolean
+xcoff_reloc_type_br (input_bfd, input_section, output_bfd, rel, sym, howto,
+ val, addend, relocation, contents)
+ bfd *input_bfd;
+ asection *input_section;
+ bfd *output_bfd ATTRIBUTE_UNUSED;
+ struct internal_reloc *rel;
+ struct internal_syment *sym ATTRIBUTE_UNUSED;
+ struct reloc_howto_struct *howto;
+ bfd_vma val;
+ bfd_vma addend;
+ bfd_vma *relocation;
+ bfd_byte *contents;
+{
+ struct xcoff_link_hash_entry *h;
+ bfd_vma section_offset;
+
+ if (0 > rel->r_symndx)
+ return FALSE;
+
+ h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx];
+ section_offset = rel->r_vaddr - input_section->vma;
+
+ /* If we see an R_BR or R_RBR reloc which is jumping to global
+ linkage code, and it is followed by an appropriate cror nop
+ instruction, we replace the cror with lwz r2,20(r1). This
+ restores the TOC after the glink code. Contrariwise, if the
+ call is followed by a lwz r2,20(r1), but the call is not
+ going to global linkage code, we can replace the load with a
+ cror. */
+ if (NULL != h
+ && (bfd_link_hash_defined == h->root.type
+ || bfd_link_hash_defweak == h->root.type)
+ && section_offset + 8 <= input_section->size)
+ {
+ bfd_byte *pnext;
+ unsigned long next;
+
+ pnext = contents + section_offset + 4;
+ next = bfd_get_32 (input_bfd, pnext);
+
+ /* The _ptrgl function is magic. It is used by the AIX
+ compiler to call a function through a pointer. */
+ if (h->smclas == XMC_GL || strcmp (h->root.root.string, "._ptrgl") == 0)
+ {
+ if (next == 0x4def7b82 /* cror 15,15,15 */
+ || next == 0x4ffffb82 /* cror 31,31,31 */
+ || next == 0x60000000) /* ori r0,r0,0 */
+ bfd_put_32 (input_bfd, 0x80410014, pnext); /* lwz r2,20(r1) */
+
+ }
+ else
+ {
+ if (next == 0x80410014) /* lwz r2,20(r1) */
+ bfd_put_32 (input_bfd, 0x60000000, pnext); /* ori r0,r0,0 */
+ }
+ }
+ else if (NULL != h && bfd_link_hash_undefined == h->root.type)
+ {
+ /* Normally, this relocation is against a defined symbol. In the
+ case where this is a partial link and the output section offset
+ is greater than 2^25, the linker will return an invalid error
+ message that the relocation has been truncated. Yes it has been
+ truncated but no it not important. For this case, disable the
+ overflow checking. */
+
+ howto->complain_on_overflow = complain_overflow_dont;
+ }
+
+ /* The original PC-relative relocation is biased by -r_vaddr, so adding
+ the value below will give the absolute target address. */
+ *relocation = val + addend + rel->r_vaddr;
+
+ howto->src_mask &= ~3;
+ howto->dst_mask = howto->src_mask;
+
+ if (h != NULL
+ && (h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak)
+ && bfd_is_abs_section (h->root.u.def.section)
+ && section_offset + 4 <= input_section->size)
+ {
+ bfd_byte *ptr;
+ bfd_vma insn;
+
+ /* Turn the relative branch into an absolute one by setting the
+ AA bit. */
+ ptr = contents + section_offset;
+ insn = bfd_get_32 (input_bfd, ptr);
+ insn |= 2;
+ bfd_put_32 (input_bfd, insn, ptr);
+
+ /* Make the howto absolute too. */
+ howto->pc_relative = FALSE;
+ howto->complain_on_overflow = complain_overflow_bitfield;
+ }
+ else
+ {
+ /* Use a PC-relative howto and subtract the instruction's address
+ from the target address we calculated above. */
+ howto->pc_relative = TRUE;
+ *relocation -= (input_section->output_section->vma
+ + input_section->output_offset
+ + section_offset);
+ }
+ return TRUE;
+}
+
+bfd_boolean
+xcoff_reloc_type_crel (input_bfd, input_section, output_bfd, rel, sym, howto,
+ val, addend, relocation, contents)
+ bfd *input_bfd ATTRIBUTE_UNUSED;
+ asection *input_section;
+ bfd *output_bfd ATTRIBUTE_UNUSED;
+ struct internal_reloc *rel ATTRIBUTE_UNUSED;
+ struct internal_syment *sym ATTRIBUTE_UNUSED;
+ struct reloc_howto_struct *howto;
+ bfd_vma val ATTRIBUTE_UNUSED;
+ bfd_vma addend;
+ bfd_vma *relocation;
+ bfd_byte *contents ATTRIBUTE_UNUSED;
+{
+ howto->pc_relative = TRUE;
+ howto->src_mask &= ~3;
+ howto->dst_mask = howto->src_mask;
+
+ /* A PC relative reloc includes the section address. */
+ addend += input_section->vma;
+
+ *relocation = val + addend;
+ *relocation -= (input_section->output_section->vma
+ + input_section->output_offset);
+ return TRUE;
+}
+
+static bfd_boolean
+xcoff_complain_overflow_dont_func (input_bfd, val, relocation, howto)
+ bfd *input_bfd ATTRIBUTE_UNUSED;
+ bfd_vma val ATTRIBUTE_UNUSED;
+ bfd_vma relocation ATTRIBUTE_UNUSED;
+ struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
+{
+ return FALSE;
+}
+
+static bfd_boolean
+xcoff_complain_overflow_bitfield_func (input_bfd, val, relocation, howto)
+ bfd *input_bfd;
+ bfd_vma val;
+ bfd_vma relocation;
+ struct reloc_howto_struct *howto;
+{
+ bfd_vma addrmask, fieldmask, signmask, ss;
+ bfd_vma a, b, sum;
+
+ /* Get the values to be added together. For signed and unsigned
+ relocations, we assume that all values should be truncated to
+ the size of an address. For bitfields, all the bits matter.
+ See also bfd_check_overflow. */
+ fieldmask = N_ONES (howto->bitsize);
+ addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
+ a = relocation;
+ b = val & howto->src_mask;
+
+ /* Much like unsigned, except no trimming with addrmask. In
+ addition, the sum overflows if there is a carry out of
+ the bfd_vma, i.e., the sum is less than either input
+ operand. */
+ a >>= howto->rightshift;
+ b >>= howto->bitpos;
+
+ /* Bitfields are sometimes used for signed numbers; for
+ example, a 13-bit field sometimes represents values in
+ 0..8191 and sometimes represents values in -4096..4095.
+ If the field is signed and a is -4095 (0x1001) and b is
+ -1 (0x1fff), the sum is -4096 (0x1000), but (0x1001 +
+ 0x1fff is 0x3000). It's not clear how to handle this
+ everywhere, since there is not way to know how many bits
+ are significant in the relocation, but the original code
+ assumed that it was fully sign extended, and we will keep
+ that assumption. */
+ signmask = (fieldmask >> 1) + 1;
+
+ if ((a & ~ fieldmask) != 0)
+ {
+ /* Some bits out of the field are set. This might not
+ be a problem: if this is a signed bitfield, it is OK
+ iff all the high bits are set, including the sign
+ bit. We'll try setting all but the most significant
+ bit in the original relocation value: if this is all
+ ones, we are OK, assuming a signed bitfield. */
+ ss = (signmask << howto->rightshift) - 1;
+ if ((ss | relocation) != ~ (bfd_vma) 0)
+ return TRUE;
+ a &= fieldmask;
+ }
+
+ /* We just assume (b & ~ fieldmask) == 0. */
+
+ /* We explicitly permit wrap around if this relocation
+ covers the high bit of an address. The Linux kernel
+ relies on it, and it is the only way to write assembler
+ code which can run when loaded at a location 0x80000000
+ away from the location at which it is linked. */
+ if (howto->bitsize + howto->rightshift
+ == bfd_arch_bits_per_address (input_bfd))
+ return FALSE;
+
+ sum = a + b;
+ if (sum < a || (sum & ~ fieldmask) != 0)
+ {
+ /* There was a carry out, or the field overflow. Test
+ for signed operands again. Here is the overflow test
+ is as for complain_overflow_signed. */
+ if (((~ (a ^ b)) & (a ^ sum)) & signmask)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static bfd_boolean
+xcoff_complain_overflow_signed_func (input_bfd, val, relocation, howto)
+ bfd *input_bfd;
+ bfd_vma val;
+ bfd_vma relocation;
+ struct reloc_howto_struct *howto;
+{
+ bfd_vma addrmask, fieldmask, signmask, ss;
+ bfd_vma a, b, sum;
+
+ /* Get the values to be added together. For signed and unsigned
+ relocations, we assume that all values should be truncated to
+ the size of an address. For bitfields, all the bits matter.
+ See also bfd_check_overflow. */
+ fieldmask = N_ONES (howto->bitsize);
+ addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
+ a = relocation;
+ b = val & howto->src_mask;
+
+ a = (a & addrmask) >> howto->rightshift;
+
+ /* If any sign bits are set, all sign bits must be set.
+ That is, A must be a valid negative address after
+ shifting. */
+ signmask = ~ (fieldmask >> 1);
+ ss = a & signmask;
+ if (ss != 0 && ss != ((addrmask >> howto->rightshift) & signmask))
+ return TRUE;
+
+ /* We only need this next bit of code if the sign bit of B
+ is below the sign bit of A. This would only happen if
+ SRC_MASK had fewer bits than BITSIZE. Note that if
+ SRC_MASK has more bits than BITSIZE, we can get into
+ trouble; we would need to verify that B is in range, as
+ we do for A above. */
+ signmask = ((~ howto->src_mask) >> 1) & howto->src_mask;
+ if ((b & signmask) != 0)
+ {
+ /* Set all the bits above the sign bit. */
+ b -= signmask <<= 1;
+ }
+
+ b = (b & addrmask) >> howto->bitpos;
+
+ /* Now we can do the addition. */
+ sum = a + b;
+
+ /* See if the result has the correct sign. Bits above the
+ sign bit are junk now; ignore them. If the sum is
+ positive, make sure we did not have all negative inputs;
+ if the sum is negative, make sure we did not have all
+ positive inputs. The test below looks only at the sign
+ bits, and it really just
+ SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
+ */
+ signmask = (fieldmask >> 1) + 1;
+ if (((~ (a ^ b)) & (a ^ sum)) & signmask)
+ return TRUE;
+
+ return FALSE;
+}
+
+static bfd_boolean
+xcoff_complain_overflow_unsigned_func (input_bfd, val, relocation, howto)
+ bfd *input_bfd;
+ bfd_vma val;
+ bfd_vma relocation;
+ struct reloc_howto_struct *howto;
+{
+ bfd_vma addrmask, fieldmask;
+ bfd_vma a, b, sum;
+
+ /* Get the values to be added together. For signed and unsigned
+ relocations, we assume that all values should be truncated to
+ the size of an address. For bitfields, all the bits matter.
+ See also bfd_check_overflow. */
+ fieldmask = N_ONES (howto->bitsize);
+ addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
+ a = relocation;
+ b = val & howto->src_mask;
+
+ /* Checking for an unsigned overflow is relatively easy:
+ trim the addresses and add, and trim the result as well.
+ Overflow is normally indicated when the result does not
+ fit in the field. However, we also need to consider the
+ case when, e.g., fieldmask is 0x7fffffff or smaller, an
+ input is 0x80000000, and bfd_vma is only 32 bits; then we
+ will get sum == 0, but there is an overflow, since the
+ inputs did not fit in the field. Instead of doing a
+ separate test, we can check for this by or-ing in the
+ operands when testing for the sum overflowing its final
+ field. */
+ a = (a & addrmask) >> howto->rightshift;
+ b = (b & addrmask) >> howto->bitpos;
+ sum = (a + b) & addrmask;
+ if ((a | b | sum) & ~ fieldmask)
+ return TRUE;
+
+ return FALSE;
+}
+
+/* This is the relocation function for the RS/6000/POWER/PowerPC.
+ This is currently the only processor which uses XCOFF; I hope that
+ will never change.
+
+ I took the relocation type definitions from two documents:
+ the PowerPC AIX Version 4 Application Binary Interface, First
+ Edition (April 1992), and the PowerOpen ABI, Big-Endian
+ 32-Bit Hardware Implementation (June 30, 1994). Differences
+ between the documents are noted below.
+
+ Unsupported r_type's
+
+ R_RTB:
+ R_RRTBI:
+ R_RRTBA:
+
+ These relocs are defined by the PowerPC ABI to be
+ relative branches which use half of the difference
+ between the symbol and the program counter. I can't
+ quite figure out when this is useful. These relocs are
+ not defined by the PowerOpen ABI.
+
+ Supported r_type's
+
+ R_POS:
+ Simple positive relocation.
+
+ R_NEG:
+ Simple negative relocation.
+
+ R_REL:
+ Simple PC relative relocation.
+
+ R_TOC:
+ TOC relative relocation. The value in the instruction in
+ the input file is the offset from the input file TOC to
+ the desired location. We want the offset from the final
+ TOC to the desired location. We have:
+ isym = iTOC + in
+ iinsn = in + o
+ osym = oTOC + on
+ oinsn = on + o
+ so we must change insn by on - in.
+
+ R_GL:
+ GL linkage relocation. The value of this relocation
+ is the address of the entry in the TOC section.
+
+ R_TCL:
+ Local object TOC address. I can't figure out the
+ difference between this and case R_GL.
+
+ R_TRL:
+ TOC relative relocation. A TOC relative load instruction
+ which may be changed to a load address instruction.
+ FIXME: We don't currently implement this optimization.
+
+ R_TRLA:
+ TOC relative relocation. This is a TOC relative load
+ address instruction which may be changed to a load
+ instruction. FIXME: I don't know if this is the correct
+ implementation.
+
+ R_BA:
+ Absolute branch. We don't want to mess with the lower
+ two bits of the instruction.
+
+ R_CAI:
+ The PowerPC ABI defines this as an absolute call which
+ may be modified to become a relative call. The PowerOpen
+ ABI does not define this relocation type.
+
+ R_RBA:
+ Absolute branch which may be modified to become a
+ relative branch.
+
+ R_RBAC:
+ The PowerPC ABI defines this as an absolute branch to a
+ fixed address which may be modified to an absolute branch
+ to a symbol. The PowerOpen ABI does not define this
+ relocation type.
+
+ R_RBRC:
+ The PowerPC ABI defines this as an absolute branch to a
+ fixed address which may be modified to a relative branch.
+ The PowerOpen ABI does not define this relocation type.
+
+ R_BR:
+ Relative branch. We don't want to mess with the lower
+ two bits of the instruction.
+
+ R_CREL:
+ The PowerPC ABI defines this as a relative call which may
+ be modified to become an absolute call. The PowerOpen
+ ABI does not define this relocation type.
+
+ R_RBR:
+ A relative branch which may be modified to become an
+ absolute branch.
+
+ R_RL:
+ The PowerPC AIX ABI describes this as a load which may be
+ changed to a load address. The PowerOpen ABI says this
+ is the same as case R_POS.
+
+ R_RLA:
+ The PowerPC AIX ABI describes this as a load address
+ which may be changed to a load. The PowerOpen ABI says
+ this is the same as R_POS.
+*/
+
+bfd_boolean
+xcoff_ppc_relocate_section (output_bfd, info, input_bfd,
+ input_section, contents, relocs, syms,
+ sections)
+ bfd *output_bfd;
+ struct bfd_link_info *info;
+ bfd *input_bfd;
+ asection *input_section;
+ bfd_byte *contents;
+ struct internal_reloc *relocs;
+ struct internal_syment *syms;
+ asection **sections;
+{
+ struct internal_reloc *rel;
+ struct internal_reloc *relend;
+
+ rel = relocs;
+ relend = rel + input_section->reloc_count;
+ for (; rel < relend; rel++)
+ {
+ long symndx;
+ struct xcoff_link_hash_entry *h;
+ struct internal_syment *sym;
+ bfd_vma addend;
+ bfd_vma val;
+ struct reloc_howto_struct howto;
+ bfd_vma relocation;
+ bfd_vma value_to_relocate;
+ bfd_vma address;
+ bfd_byte *location;
+
+ /* Relocation type R_REF is a special relocation type which is
+ merely used to prevent garbage collection from occurring for
+ the csect including the symbol which it references. */
+ if (rel->r_type == R_REF)
+ continue;
+
+ /* howto */
+ howto.type = rel->r_type;
+ howto.rightshift = 0;
+ howto.bitsize = (rel->r_size & 0x1f) + 1;
+ howto.size = howto.bitsize > 16 ? 2 : 1;
+ howto.pc_relative = FALSE;
+ howto.bitpos = 0;
+ howto.complain_on_overflow = (rel->r_size & 0x80
+ ? complain_overflow_signed
+ : complain_overflow_bitfield);
+ howto.special_function = NULL;
+ howto.name = "internal";
+ howto.partial_inplace = TRUE;
+ howto.src_mask = howto.dst_mask = N_ONES (howto.bitsize);
+ howto.pcrel_offset = FALSE;
+
+ /* symbol */
+ val = 0;
+ addend = 0;
+ h = NULL;
+ sym = NULL;
+ symndx = rel->r_symndx;
+
+ if (-1 != symndx)
+ {
+ asection *sec;
+
+ h = obj_xcoff_sym_hashes (input_bfd)[symndx];
+ sym = syms + symndx;
+ addend = - sym->n_value;
+
+ if (NULL == h)
+ {
+ sec = sections[symndx];
+ /* Hack to make sure we use the right TOC anchor value
+ if this reloc is against the TOC anchor. */
+ if (sec->name[3] == '0'
+ && strcmp (sec->name, ".tc0") == 0)
+ val = xcoff_data (output_bfd)->toc;
+ else
+ val = (sec->output_section->vma
+ + sec->output_offset
+ + sym->n_value
+ - sec->vma);
+ }
+ else
+ {
+ if (info->unresolved_syms_in_objects != RM_IGNORE
+ && (h->flags & XCOFF_WAS_UNDEFINED) != 0)
+ {
+ if (! ((*info->callbacks->undefined_symbol)
+ (info, h->root.root.string,
+ input_bfd, input_section,
+ rel->r_vaddr - input_section->vma,
+ (info->unresolved_syms_in_objects
+ == RM_GENERATE_ERROR))))
+ return FALSE;
+ }
+ if (h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak)
+ {
+ sec = h->root.u.def.section;
+ val = (h->root.u.def.value
+ + sec->output_section->vma
+ + sec->output_offset);
+ }
+ else if (h->root.type == bfd_link_hash_common)
+ {
+ sec = h->root.u.c.p->section;
+ val = (sec->output_section->vma
+ + sec->output_offset);
+
+ }
+ else
+ {
+ BFD_ASSERT (info->relocatable
+ || (h->flags & XCOFF_DEF_DYNAMIC) != 0
+ || (h->flags & XCOFF_IMPORT) != 0);
+ }
+ }
+ }
+
+ if (rel->r_type >= XCOFF_MAX_CALCULATE_RELOCATION
+ || !((*xcoff_calculate_relocation[rel->r_type])
+ (input_bfd, input_section, output_bfd, rel, sym, &howto, val,
+ addend, &relocation, contents)))
+ return FALSE;
+
+ /* address */
+ address = rel->r_vaddr - input_section->vma;
+ location = contents + address;
+
+ if (address > input_section->size)
+ abort ();
+
+ /* Get the value we are going to relocate. */
+ if (1 == howto.size)
+ value_to_relocate = bfd_get_16 (input_bfd, location);
+ else
+ value_to_relocate = bfd_get_32 (input_bfd, location);
+
+ /* overflow.
+
+ FIXME: We may drop bits during the addition
+ which we don't check for. We must either check at every single
+ operation, which would be tedious, or we must do the computations
+ in a type larger than bfd_vma, which would be inefficient. */
+
+ if ((unsigned int) howto.complain_on_overflow
+ >= XCOFF_MAX_COMPLAIN_OVERFLOW)
+ abort ();
+
+ if (((*xcoff_complain_overflow[howto.complain_on_overflow])
+ (input_bfd, value_to_relocate, relocation, &howto)))
+ {
+ const char *name;
+ char buf[SYMNMLEN + 1];
+ char reloc_type_name[10];
+
+ if (symndx == -1)
+ {
+ name = "*ABS*";
+ }
+ else if (h != NULL)
+ {
+ name = NULL;
+ }
+ else
+ {
+ name = _bfd_coff_internal_syment_name (input_bfd, sym, buf);
+ if (name == NULL)
+ name = "UNKNOWN";
+ }
+ sprintf (reloc_type_name, "0x%02x", rel->r_type);
+
+ if (! ((*info->callbacks->reloc_overflow)
+ (info, (h ? &h->root : NULL), name, reloc_type_name,
+ (bfd_vma) 0, input_bfd, input_section,
+ rel->r_vaddr - input_section->vma)))
+ return FALSE;
+ }
+
+ /* Add RELOCATION to the right bits of VALUE_TO_RELOCATE. */
+ value_to_relocate = ((value_to_relocate & ~howto.dst_mask)
+ | (((value_to_relocate & howto.src_mask)
+ + relocation) & howto.dst_mask));
+
+ /* Put the value back in the object file. */
+ if (1 == howto.size)
+ bfd_put_16 (input_bfd, value_to_relocate, location);
+ else
+ bfd_put_32 (input_bfd, value_to_relocate, location);
+ }
+
+ return TRUE;
+}
+
+static bfd_boolean
+_bfd_xcoff_put_ldsymbol_name (abfd, ldinfo, ldsym, name)
+ bfd *abfd ATTRIBUTE_UNUSED;
+ struct xcoff_loader_info *ldinfo;
+ struct internal_ldsym *ldsym;
+ const char *name;
+{
+ size_t len;
+ len = strlen (name);
+
+ if (len <= SYMNMLEN)
+ strncpy (ldsym->_l._l_name, name, SYMNMLEN);
+ else
+ {
+ if (ldinfo->string_size + len + 3 > ldinfo->string_alc)
+ {
+ bfd_size_type newalc;
+ char *newstrings;
+
+ newalc = ldinfo->string_alc * 2;
+ if (newalc == 0)
+ newalc = 32;
+ while (ldinfo->string_size + len + 3 > newalc)
+ newalc *= 2;
+
+ newstrings = bfd_realloc (ldinfo->strings, newalc);
+ if (newstrings == NULL)
+ {
+ ldinfo->failed = TRUE;
+ return FALSE;
+ }
+ ldinfo->string_alc = newalc;
+ ldinfo->strings = newstrings;
+ }
+
+ bfd_put_16 (ldinfo->output_bfd, (bfd_vma) (len + 1),
+ ldinfo->strings + ldinfo->string_size);
+ strcpy (ldinfo->strings + ldinfo->string_size + 2, name);
+ ldsym->_l._l_l._l_zeroes = 0;
+ ldsym->_l._l_l._l_offset = ldinfo->string_size + 2;
+ ldinfo->string_size += len + 3;
+ }
+
+ return TRUE;
+}
+
+static bfd_boolean
+_bfd_xcoff_put_symbol_name (bfd *abfd, struct bfd_strtab_hash *strtab,
+ struct internal_syment *sym,
+ const char *name)
+{
+ if (strlen (name) <= SYMNMLEN)
+ {
+ strncpy (sym->_n._n_name, name, SYMNMLEN);
+ }
+ else
+ {
+ bfd_boolean hash;
+ bfd_size_type indx;
+
+ hash = TRUE;
+ if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
+ hash = FALSE;
+ indx = _bfd_stringtab_add (strtab, name, hash, FALSE);
+ if (indx == (bfd_size_type) -1)
+ return FALSE;
+ sym->_n._n_n._n_zeroes = 0;
+ sym->_n._n_n._n_offset = STRING_SIZE_SIZE + indx;
+ }
+ return TRUE;
+}
+
+static asection *
+xcoff_create_csect_from_smclas (abfd, aux, symbol_name)
+ bfd *abfd;
+ union internal_auxent *aux;
+ const char *symbol_name;
+{
+ asection *return_value = NULL;
+
+ /* .sv64 = x_smclas == 17
+ This is an invalid csect for 32 bit apps. */
+ static const char *names[19] =
+ {
+ ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
+ ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL, ".tc0",
+ ".td", NULL, ".sv3264"
+ };
+
+ if ((19 >= aux->x_csect.x_smclas)
+ && (NULL != names[aux->x_csect.x_smclas]))
+ {
+ return_value = bfd_make_section_anyway
+ (abfd, names[aux->x_csect.x_smclas]);
+ }
+ else
+ {
+ (*_bfd_error_handler)
+ (_("%B: symbol `%s' has unrecognized smclas %d"),
+ abfd, symbol_name, aux->x_csect.x_smclas);
+ bfd_set_error (bfd_error_bad_value);
+ }
+
+ return return_value;
+}
+
+static bfd_boolean
+xcoff_is_lineno_count_overflow (abfd, value)
+ bfd *abfd ATTRIBUTE_UNUSED;
+ bfd_vma value;
+{
+ if (0xffff <= value)
+ return TRUE;
+
+ return FALSE;
+}
+
+static bfd_boolean
+xcoff_is_reloc_count_overflow (abfd, value)
+ bfd *abfd ATTRIBUTE_UNUSED;
+ bfd_vma value;
+{
+ if (0xffff <= value)
+ return TRUE;
+
+ return FALSE;
+}
+
+static bfd_vma
+xcoff_loader_symbol_offset (abfd, ldhdr)
+ bfd *abfd;
+ struct internal_ldhdr *ldhdr ATTRIBUTE_UNUSED;
+{
+ return bfd_xcoff_ldhdrsz (abfd);
+}
+
+static bfd_vma
+xcoff_loader_reloc_offset (abfd, ldhdr)
+ bfd *abfd;
+ struct internal_ldhdr *ldhdr;
+{
+ return bfd_xcoff_ldhdrsz (abfd) + ldhdr->l_nsyms * bfd_xcoff_ldsymsz (abfd);
+}
+
+static bfd_boolean
+xcoff_generate_rtinit (abfd, init, fini, rtld)
+ bfd *abfd;
+ const char *init;
+ const char *fini;
+ bfd_boolean rtld;
+{
+ bfd_byte filehdr_ext[FILHSZ];
+ bfd_byte scnhdr_ext[SCNHSZ];
+ bfd_byte syment_ext[SYMESZ * 10];
+ bfd_byte reloc_ext[RELSZ * 3];
+ bfd_byte *data_buffer;
+ bfd_size_type data_buffer_size;
+ bfd_byte *string_table = NULL, *st_tmp = NULL;
+ bfd_size_type string_table_size;
+ bfd_vma val;
+ size_t initsz, finisz;
+ struct internal_filehdr filehdr;
+ struct internal_scnhdr scnhdr;
+ struct internal_syment syment;
+ union internal_auxent auxent;
+ struct internal_reloc reloc;
+
+ char *data_name = ".data";
+ char *rtinit_name = "__rtinit";
+ char *rtld_name = "__rtld";
+
+ if (! bfd_xcoff_rtinit_size (abfd))
+ return FALSE;
+
+ initsz = (init == NULL ? 0 : 1 + strlen (init));
+ finisz = (fini == NULL ? 0 : 1 + strlen (fini));
+
+ /* file header */
+ memset (filehdr_ext, 0, FILHSZ);
+ memset (&filehdr, 0, sizeof (struct internal_filehdr));
+ filehdr.f_magic = bfd_xcoff_magic_number (abfd);
+ filehdr.f_nscns = 1;
+ filehdr.f_timdat = 0;
+ filehdr.f_nsyms = 0; /* at least 6, no more than 10 */
+ filehdr.f_symptr = 0; /* set below */
+ filehdr.f_opthdr = 0;
+ filehdr.f_flags = 0;
+
+ /* section header */
+ memset (scnhdr_ext, 0, SCNHSZ);
+ memset (&scnhdr, 0, sizeof (struct internal_scnhdr));
+ memcpy (scnhdr.s_name, data_name, strlen (data_name));
+ scnhdr.s_paddr = 0;
+ scnhdr.s_vaddr = 0;
+ scnhdr.s_size = 0; /* set below */
+ scnhdr.s_scnptr = FILHSZ + SCNHSZ;
+ scnhdr.s_relptr = 0; /* set below */
+ scnhdr.s_lnnoptr = 0;
+ scnhdr.s_nreloc = 0; /* either 1 or 2 */
+ scnhdr.s_nlnno = 0;
+ scnhdr.s_flags = STYP_DATA;
+
+ /* .data
+ 0x0000 0x00000000 : rtl
+ 0x0004 0x00000010 : offset to init, or 0
+ 0x0008 0x00000028 : offset to fini, or 0
+ 0x000C 0x0000000C : size of descriptor
+ 0x0010 0x00000000 : init, needs a reloc
+ 0x0014 0x00000040 : offset to init name
+ 0x0018 0x00000000 : flags, padded to a word
+ 0x001C 0x00000000 : empty init
+ 0x0020 0x00000000 :
+ 0x0024 0x00000000 :
+ 0x0028 0x00000000 : fini, needs a reloc
+ 0x002C 0x00000??? : offset to fini name
+ 0x0030 0x00000000 : flags, padded to a word
+ 0x0034 0x00000000 : empty fini
+ 0x0038 0x00000000 :
+ 0x003C 0x00000000 :
+ 0x0040 init name
+ 0x0040 + initsz fini name */
+
+ data_buffer_size = 0x0040 + initsz + finisz;
+ data_buffer_size = (data_buffer_size + 7) &~ (bfd_size_type) 7;
+ data_buffer = NULL;
+ data_buffer = (bfd_byte *) bfd_zmalloc (data_buffer_size);
+ if (data_buffer == NULL)
+ return FALSE;
+
+ if (initsz)
+ {
+ val = 0x10;
+ bfd_h_put_32 (abfd, val, &data_buffer[0x04]);
+ val = 0x40;
+ bfd_h_put_32 (abfd, val, &data_buffer[0x14]);
+ memcpy (&data_buffer[val], init, initsz);
+ }
+
+ if (finisz)
+ {
+ val = 0x28;
+ bfd_h_put_32 (abfd, val, &data_buffer[0x08]);
+ val = 0x40 + initsz;
+ bfd_h_put_32 (abfd, val, &data_buffer[0x2C]);
+ memcpy (&data_buffer[val], fini, finisz);
+ }
+
+ val = 0x0C;
+ bfd_h_put_32 (abfd, val, &data_buffer[0x0C]);
+
+ scnhdr.s_size = data_buffer_size;
+
+ /* string table */
+ string_table_size = 0;
+ if (initsz > 9)
+ string_table_size += initsz;
+ if (finisz > 9)
+ string_table_size += finisz;
+ if (string_table_size)
+ {
+ string_table_size += 4;
+ string_table = (bfd_byte *) bfd_zmalloc (string_table_size);
+ if (string_table == NULL)
+ return FALSE;
+
+ val = string_table_size;
+ bfd_h_put_32 (abfd, val, &string_table[0]);
+ st_tmp = string_table + 4;
+ }
+
+ /* symbols
+ 0. .data csect
+ 2. __rtinit
+ 4. init function
+ 6. fini function
+ 8. __rtld */
+ memset (syment_ext, 0, 10 * SYMESZ);
+ memset (reloc_ext, 0, 3 * RELSZ);
+
+ /* .data csect */
+ memset (&syment, 0, sizeof (struct internal_syment));
+ memset (&auxent, 0, sizeof (union internal_auxent));
+ memcpy (syment._n._n_name, data_name, strlen (data_name));
+ syment.n_scnum = 1;
+ syment.n_sclass = C_HIDEXT;
+ syment.n_numaux = 1;
+ auxent.x_csect.x_scnlen.l = data_buffer_size;
+ auxent.x_csect.x_smtyp = 3 << 3 | XTY_SD;
+ auxent.x_csect.x_smclas = XMC_RW;
+ bfd_coff_swap_sym_out (abfd, &syment,
+ &syment_ext[filehdr.f_nsyms * SYMESZ]);
+ bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
+ syment.n_numaux,
+ &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
+ filehdr.f_nsyms += 2;
+
+ /* __rtinit */
+ memset (&syment, 0, sizeof (struct internal_syment));
+ memset (&auxent, 0, sizeof (union internal_auxent));
+ memcpy (syment._n._n_name, rtinit_name, strlen (rtinit_name));
+ syment.n_scnum = 1;
+ syment.n_sclass = C_EXT;
+ syment.n_numaux = 1;
+ auxent.x_csect.x_smtyp = XTY_LD;
+ auxent.x_csect.x_smclas = XMC_RW;
+ bfd_coff_swap_sym_out (abfd, &syment,
+ &syment_ext[filehdr.f_nsyms * SYMESZ]);
+ bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
+ syment.n_numaux,
+ &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
+ filehdr.f_nsyms += 2;
+
+ /* init */
+ if (initsz)
+ {
+ memset (&syment, 0, sizeof (struct internal_syment));
+ memset (&auxent, 0, sizeof (union internal_auxent));
+
+ if (initsz > 9)
+ {
+ syment._n._n_n._n_offset = st_tmp - string_table;
+ memcpy (st_tmp, init, initsz);
+ st_tmp += initsz;
+ }
+ else
+ memcpy (syment._n._n_name, init, initsz - 1);
+
+ syment.n_sclass = C_EXT;
+ syment.n_numaux = 1;
+ bfd_coff_swap_sym_out (abfd, &syment,
+ &syment_ext[filehdr.f_nsyms * SYMESZ]);
+ bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
+ syment.n_numaux,
+ &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
+
+ /* reloc */
+ memset (&reloc, 0, sizeof (struct internal_reloc));
+ reloc.r_vaddr = 0x0010;
+ reloc.r_symndx = filehdr.f_nsyms;
+ reloc.r_type = R_POS;
+ reloc.r_size = 31;
+ bfd_coff_swap_reloc_out (abfd, &reloc, &reloc_ext[0]);
+
+ filehdr.f_nsyms += 2;
+ scnhdr.s_nreloc += 1;
+ }
+
+ /* fini */
+ if (finisz)
+ {
+ memset (&syment, 0, sizeof (struct internal_syment));
+ memset (&auxent, 0, sizeof (union internal_auxent));
+
+ if (finisz > 9)
+ {
+ syment._n._n_n._n_offset = st_tmp - string_table;
+ memcpy (st_tmp, fini, finisz);
+ st_tmp += finisz;
+ }
+ else
+ memcpy (syment._n._n_name, fini, finisz - 1);
+
+ syment.n_sclass = C_EXT;
+ syment.n_numaux = 1;
+ bfd_coff_swap_sym_out (abfd, &syment,
+ &syment_ext[filehdr.f_nsyms * SYMESZ]);
+ bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
+ syment.n_numaux,
+ &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
+
+ /* reloc */
+ memset (&reloc, 0, sizeof (struct internal_reloc));
+ reloc.r_vaddr = 0x0028;
+ reloc.r_symndx = filehdr.f_nsyms;
+ reloc.r_type = R_POS;
+ reloc.r_size = 31;
+ bfd_coff_swap_reloc_out (abfd, &reloc,
+ &reloc_ext[scnhdr.s_nreloc * RELSZ]);
+
+ filehdr.f_nsyms += 2;
+ scnhdr.s_nreloc += 1;
+ }
+
+ if (rtld)
+ {
+ memset (&syment, 0, sizeof (struct internal_syment));
+ memset (&auxent, 0, sizeof (union internal_auxent));
+ memcpy (syment._n._n_name, rtld_name, strlen (rtld_name));
+ syment.n_sclass = C_EXT;
+ syment.n_numaux = 1;
+ bfd_coff_swap_sym_out (abfd, &syment,
+ &syment_ext[filehdr.f_nsyms * SYMESZ]);
+ bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
+ syment.n_numaux,
+ &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
+
+ /* reloc */
+ memset (&reloc, 0, sizeof (struct internal_reloc));
+ reloc.r_vaddr = 0x0000;
+ reloc.r_symndx = filehdr.f_nsyms;
+ reloc.r_type = R_POS;
+ reloc.r_size = 31;
+ bfd_coff_swap_reloc_out (abfd, &reloc,
+ &reloc_ext[scnhdr.s_nreloc * RELSZ]);
+
+ filehdr.f_nsyms += 2;
+ scnhdr.s_nreloc += 1;
+ }
+
+ scnhdr.s_relptr = scnhdr.s_scnptr + data_buffer_size;
+ filehdr.f_symptr = scnhdr.s_relptr + scnhdr.s_nreloc * RELSZ;
+
+ bfd_coff_swap_filehdr_out (abfd, &filehdr, filehdr_ext);
+ bfd_bwrite (filehdr_ext, FILHSZ, abfd);
+ bfd_coff_swap_scnhdr_out (abfd, &scnhdr, scnhdr_ext);
+ bfd_bwrite (scnhdr_ext, SCNHSZ, abfd);
+ bfd_bwrite (data_buffer, data_buffer_size, abfd);
+ bfd_bwrite (reloc_ext, scnhdr.s_nreloc * RELSZ, abfd);
+ bfd_bwrite (syment_ext, filehdr.f_nsyms * SYMESZ, abfd);
+ bfd_bwrite (string_table, string_table_size, abfd);
+
+ free (data_buffer);
+ data_buffer = NULL;
+
+ return TRUE;
+}
+
+
+static reloc_howto_type xcoff_dynamic_reloc =
+HOWTO (0, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 32, /* bitsize */
+ FALSE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_bitfield, /* complain_on_overflow */
+ 0, /* special_function */
+ "R_POS", /* name */
+ TRUE, /* partial_inplace */
+ 0xffffffff, /* src_mask */
+ 0xffffffff, /* dst_mask */
+ FALSE); /* pcrel_offset */
+
+/* glink
+
+ The first word of global linkage code must be modified by filling in
+ the correct TOC offset. */
+
+static unsigned long xcoff_glink_code[9] =
+ {
+ 0x81820000, /* lwz r12,0(r2) */
+ 0x90410014, /* stw r2,20(r1) */
+ 0x800c0000, /* lwz r0,0(r12) */
+ 0x804c0004, /* lwz r2,4(r12) */
+ 0x7c0903a6, /* mtctr r0 */
+ 0x4e800420, /* bctr */
+ 0x00000000, /* start of traceback table */
+ 0x000c8000, /* traceback table */
+ 0x00000000, /* traceback table */
+ };
+
+
+static const struct xcoff_backend_data_rec bfd_xcoff_backend_data =
+ {
+ { /* COFF backend, defined in libcoff.h. */
+ _bfd_xcoff_swap_aux_in,
+ _bfd_xcoff_swap_sym_in,
+ coff_swap_lineno_in,
+ _bfd_xcoff_swap_aux_out,
+ _bfd_xcoff_swap_sym_out,
+ coff_swap_lineno_out,
+ xcoff_swap_reloc_out,
+ coff_swap_filehdr_out,
+ coff_swap_aouthdr_out,
+ coff_swap_scnhdr_out,
+ FILHSZ,
+ AOUTSZ,
+ SCNHSZ,
+ SYMESZ,
+ AUXESZ,
+ RELSZ,
+ LINESZ,
+ FILNMLEN,
+ TRUE, /* _bfd_coff_long_filenames */
+ XCOFF_NO_LONG_SECTION_NAMES, /* _bfd_coff_long_section_names */
+ 3, /* _bfd_coff_default_section_alignment_power */
+ FALSE, /* _bfd_coff_force_symnames_in_strings */
+ 2, /* _bfd_coff_debug_string_prefix_length */
+ coff_swap_filehdr_in,
+ coff_swap_aouthdr_in,
+ coff_swap_scnhdr_in,
+ xcoff_swap_reloc_in,
+ coff_bad_format_hook,
+ coff_set_arch_mach_hook,
+ coff_mkobject_hook,
+ styp_to_sec_flags,
+ coff_set_alignment_hook,
+ coff_slurp_symbol_table,
+ symname_in_debug_hook,
+ coff_pointerize_aux_hook,
+ coff_print_aux,
+ dummy_reloc16_extra_cases,
+ dummy_reloc16_estimate,
+ NULL, /* bfd_coff_sym_is_global */
+ coff_compute_section_file_positions,
+ NULL, /* _bfd_coff_start_final_link */
+ xcoff_ppc_relocate_section,
+ coff_rtype_to_howto,
+ NULL, /* _bfd_coff_adjust_symndx */
+ _bfd_generic_link_add_one_symbol,
+ coff_link_output_has_begun,
+ coff_final_link_postscript,
+ NULL /* print_pdata. */
+ },
+
+ 0x01DF, /* magic number */
+ bfd_arch_rs6000,
+ bfd_mach_rs6k,
+
+ /* Function pointers to xcoff specific swap routines. */
+ xcoff_swap_ldhdr_in,
+ xcoff_swap_ldhdr_out,
+ xcoff_swap_ldsym_in,
+ xcoff_swap_ldsym_out,
+ xcoff_swap_ldrel_in,
+ xcoff_swap_ldrel_out,
+
+ /* Sizes. */
+ LDHDRSZ,
+ LDSYMSZ,
+ LDRELSZ,
+ 12, /* _xcoff_function_descriptor_size */
+ SMALL_AOUTSZ,
+
+ /* Versions. */
+ 1, /* _xcoff_ldhdr_version */
+
+ _bfd_xcoff_put_symbol_name,
+ _bfd_xcoff_put_ldsymbol_name,
+ &xcoff_dynamic_reloc,
+ xcoff_create_csect_from_smclas,
+
+ /* Lineno and reloc count overflow. */
+ xcoff_is_lineno_count_overflow,
+ xcoff_is_reloc_count_overflow,
+
+ xcoff_loader_symbol_offset,
+ xcoff_loader_reloc_offset,
+
+ /* glink. */
+ &xcoff_glink_code[0],
+ 36, /* _xcoff_glink_size */
+
+ /* rtinit */
+ 64, /* _xcoff_rtinit_size */
+ xcoff_generate_rtinit,
+ };
+
+/* The transfer vector that leads the outside world to all of the above. */
+const bfd_target rs6000coff_vec =
+ {
+ "aixcoff-rs6000",
+ bfd_target_xcoff_flavour,
+ BFD_ENDIAN_BIG, /* data byte order is big */
+ BFD_ENDIAN_BIG, /* header byte order is big */
+
+ (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | DYNAMIC
+ | HAS_SYMS | HAS_LOCALS | WP_TEXT),
+
+ SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA,
+ 0, /* leading char */
+ '/', /* ar_pad_char */
+ 15, /* ar_max_namelen */
+
+ /* data */
+ bfd_getb64,
+ bfd_getb_signed_64,
+ bfd_putb64,
+ bfd_getb32,
+ bfd_getb_signed_32,
+ bfd_putb32,
+ bfd_getb16,
+ bfd_getb_signed_16,
+ bfd_putb16,
+
+ /* hdrs */
+ bfd_getb64,
+ bfd_getb_signed_64,
+ bfd_putb64,
+ bfd_getb32,
+ bfd_getb_signed_32,
+ bfd_putb32,
+ bfd_getb16,
+ bfd_getb_signed_16,
+ bfd_putb16,
+
+ { /* bfd_check_format */
+ _bfd_dummy_target,
+ coff_object_p,
+ _bfd_xcoff_archive_p,
+ CORE_FILE_P
+ },
+
+ { /* bfd_set_format */
+ bfd_false,
+ coff_mkobject,
+ _bfd_generic_mkarchive,
+ bfd_false
+ },
+
+ {/* bfd_write_contents */
+ bfd_false,
+ coff_write_object_contents,
+ _bfd_xcoff_write_archive_contents,
+ bfd_false
+ },
+
+ /* Generic */
+ bfd_true,
+ bfd_true,
+ coff_new_section_hook,
+ _bfd_generic_get_section_contents,
+ _bfd_generic_get_section_contents_in_window,
+
+ /* Copy */
+ _bfd_xcoff_copy_private_bfd_data,
+ ((bfd_boolean (*) (bfd *, bfd *)) bfd_true),
+ _bfd_generic_init_private_section_data,
+ ((bfd_boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true),
+ ((bfd_boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true),
+ ((bfd_boolean (*) (bfd *, bfd *)) bfd_true),
+ ((bfd_boolean (*) (bfd *, flagword)) bfd_true),
+ ((bfd_boolean (*) (bfd *, void * )) bfd_true),
+
+ /* Core */
+ coff_core_file_failing_command,
+ coff_core_file_failing_signal,
+ coff_core_file_matches_executable_p,
+
+ /* Archive */
+ _bfd_xcoff_slurp_armap,
+ bfd_false,
+ ((bfd_boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false),
+ bfd_dont_truncate_arname,
+ _bfd_xcoff_write_armap,
+ _bfd_xcoff_read_ar_hdr,
+ _bfd_xcoff_openr_next_archived_file,
+ _bfd_generic_get_elt_at_index,
+ _bfd_xcoff_stat_arch_elt,
+ bfd_true,
+
+ /* Symbols */
+ coff_get_symtab_upper_bound,
+ coff_canonicalize_symtab,
+ coff_make_empty_symbol,
+ coff_print_symbol,
+ coff_get_symbol_info,
+ _bfd_xcoff_is_local_label_name,
+ coff_bfd_is_target_special_symbol,
+ coff_get_lineno,
+ coff_find_nearest_line,
+ _bfd_generic_find_line,
+ coff_find_inliner_info,
+ coff_bfd_make_debug_symbol,
+ _bfd_generic_read_minisymbols,
+ _bfd_generic_minisymbol_to_symbol,
+
+ /* Reloc */
+ coff_get_reloc_upper_bound,
+ coff_canonicalize_reloc,
+ _bfd_xcoff_reloc_type_lookup,
+ _bfd_xcoff_reloc_name_lookup,
+
+ /* Write */
+ coff_set_arch_mach,
+ coff_set_section_contents,
+
+ /* Link */
+ _bfd_xcoff_sizeof_headers,
+ bfd_generic_get_relocated_section_contents,
+ bfd_generic_relax_section,
+ _bfd_xcoff_bfd_link_hash_table_create,
+ _bfd_generic_link_hash_table_free,
+ _bfd_xcoff_bfd_link_add_symbols,
+ _bfd_generic_link_just_syms,
+ _bfd_xcoff_bfd_final_link,
+ _bfd_generic_link_split_section,
+ bfd_generic_gc_sections,
+ bfd_generic_merge_sections,
+ bfd_generic_is_group_section,
+ bfd_generic_discard_group,
+ _bfd_generic_section_already_linked,
+ _bfd_xcoff_define_common_symbol,
+
+ /* Dynamic */
+ _bfd_xcoff_get_dynamic_symtab_upper_bound,
+ _bfd_xcoff_canonicalize_dynamic_symtab,
+ _bfd_nodynamic_get_synthetic_symtab,
+ _bfd_xcoff_get_dynamic_reloc_upper_bound,
+ _bfd_xcoff_canonicalize_dynamic_reloc,
+
+ /* Opposite endian version, none exists */
+ NULL,
+
+ (void *) &bfd_xcoff_backend_data,
+ };
+
+/* xcoff-powermac target
+ Old target.
+ Only difference between this target and the rs6000 target is the
+ the default architecture and machine type used in coffcode.h
+
+ PowerPC Macs use the same magic numbers as RS/6000
+ (because that's how they were bootstrapped originally),
+ but they are always PowerPC architecture. */
+static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data =
+ {
+ { /* COFF backend, defined in libcoff.h. */
+ _bfd_xcoff_swap_aux_in,
+ _bfd_xcoff_swap_sym_in,
+ coff_swap_lineno_in,
+ _bfd_xcoff_swap_aux_out,
+ _bfd_xcoff_swap_sym_out,
+ coff_swap_lineno_out,
+ xcoff_swap_reloc_out,
+ coff_swap_filehdr_out,
+ coff_swap_aouthdr_out,
+ coff_swap_scnhdr_out,
+ FILHSZ,
+ AOUTSZ,
+ SCNHSZ,
+ SYMESZ,
+ AUXESZ,
+ RELSZ,
+ LINESZ,
+ FILNMLEN,
+ TRUE, /* _bfd_coff_long_filenames */
+ XCOFF_NO_LONG_SECTION_NAMES, /* _bfd_coff_long_section_names */
+ 3, /* _bfd_coff_default_section_alignment_power */
+ FALSE, /* _bfd_coff_force_symnames_in_strings */
+ 2, /* _bfd_coff_debug_string_prefix_length */
+ coff_swap_filehdr_in,
+ coff_swap_aouthdr_in,
+ coff_swap_scnhdr_in,
+ xcoff_swap_reloc_in,
+ coff_bad_format_hook,
+ coff_set_arch_mach_hook,
+ coff_mkobject_hook,
+ styp_to_sec_flags,
+ coff_set_alignment_hook,
+ coff_slurp_symbol_table,
+ symname_in_debug_hook,
+ coff_pointerize_aux_hook,
+ coff_print_aux,
+ dummy_reloc16_extra_cases,
+ dummy_reloc16_estimate,
+ NULL, /* bfd_coff_sym_is_global */
+ coff_compute_section_file_positions,
+ NULL, /* _bfd_coff_start_final_link */
+ xcoff_ppc_relocate_section,
+ coff_rtype_to_howto,
+ NULL, /* _bfd_coff_adjust_symndx */
+ _bfd_generic_link_add_one_symbol,
+ coff_link_output_has_begun,
+ coff_final_link_postscript,
+ NULL /* print_pdata. */
+ },
+
+ 0x01DF, /* magic number */
+ bfd_arch_powerpc,
+ bfd_mach_ppc,
+
+ /* Function pointers to xcoff specific swap routines. */
+ xcoff_swap_ldhdr_in,
+ xcoff_swap_ldhdr_out,
+ xcoff_swap_ldsym_in,
+ xcoff_swap_ldsym_out,
+ xcoff_swap_ldrel_in,
+ xcoff_swap_ldrel_out,
+
+ /* Sizes. */
+ LDHDRSZ,
+ LDSYMSZ,
+ LDRELSZ,
+ 12, /* _xcoff_function_descriptor_size */
+ SMALL_AOUTSZ,
+
+ /* Versions. */
+ 1, /* _xcoff_ldhdr_version */
+
+ _bfd_xcoff_put_symbol_name,
+ _bfd_xcoff_put_ldsymbol_name,
+ &xcoff_dynamic_reloc,
+ xcoff_create_csect_from_smclas,
+
+ /* Lineno and reloc count overflow. */
+ xcoff_is_lineno_count_overflow,
+ xcoff_is_reloc_count_overflow,
+
+ xcoff_loader_symbol_offset,
+ xcoff_loader_reloc_offset,
+
+ /* glink. */
+ &xcoff_glink_code[0],
+ 36, /* _xcoff_glink_size */
+
+ /* rtinit */
+ 0, /* _xcoff_rtinit_size */
+ xcoff_generate_rtinit,
+ };
+
+/* The transfer vector that leads the outside world to all of the above. */
+const bfd_target pmac_xcoff_vec =
+ {
+ "xcoff-powermac",
+ bfd_target_xcoff_flavour,
+ BFD_ENDIAN_BIG, /* data byte order is big */
+ BFD_ENDIAN_BIG, /* header byte order is big */
+
+ (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | DYNAMIC
+ | HAS_SYMS | HAS_LOCALS | WP_TEXT),
+
+ SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA,
+ 0, /* leading char */
+ '/', /* ar_pad_char */
+ 15, /* ar_max_namelen */
+
+ /* data */
+ bfd_getb64,
+ bfd_getb_signed_64,
+ bfd_putb64,
+ bfd_getb32,
+ bfd_getb_signed_32,
+ bfd_putb32,
+ bfd_getb16,
+ bfd_getb_signed_16,
+ bfd_putb16,
+
+ /* hdrs */
+ bfd_getb64,
+ bfd_getb_signed_64,
+ bfd_putb64,
+ bfd_getb32,
+ bfd_getb_signed_32,
+ bfd_putb32,
+ bfd_getb16,
+ bfd_getb_signed_16,
+ bfd_putb16,
+
+ { /* bfd_check_format */
+ _bfd_dummy_target,
+ coff_object_p,
+ _bfd_xcoff_archive_p,
+ CORE_FILE_P
+ },
+
+ { /* bfd_set_format */
+ bfd_false,
+ coff_mkobject,
+ _bfd_generic_mkarchive,
+ bfd_false
+ },
+
+ {/* bfd_write_contents */
+ bfd_false,
+ coff_write_object_contents,
+ _bfd_xcoff_write_archive_contents,
+ bfd_false
+ },
+
+ /* Generic */
+ bfd_true,
+ bfd_true,
+ coff_new_section_hook,
+ _bfd_generic_get_section_contents,
+ _bfd_generic_get_section_contents_in_window,
+
+ /* Copy */
+ _bfd_xcoff_copy_private_bfd_data,
+ ((bfd_boolean (*) (bfd *, bfd *)) bfd_true),
+ _bfd_generic_init_private_section_data,
+ ((bfd_boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true),
+ ((bfd_boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true),
+ ((bfd_boolean (*) (bfd *, bfd *)) bfd_true),
+ ((bfd_boolean (*) (bfd *, flagword)) bfd_true),
+ ((bfd_boolean (*) (bfd *, void * )) bfd_true),
+
+ /* Core */
+ coff_core_file_failing_command,
+ coff_core_file_failing_signal,
+ coff_core_file_matches_executable_p,
+
+ /* Archive */
+ _bfd_xcoff_slurp_armap,
+ bfd_false,
+ ((bfd_boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false),
+ bfd_dont_truncate_arname,
+ _bfd_xcoff_write_armap,
+ _bfd_xcoff_read_ar_hdr,
+ _bfd_xcoff_openr_next_archived_file,
+ _bfd_generic_get_elt_at_index,
+ _bfd_xcoff_stat_arch_elt,
+ bfd_true,
+
+ /* Symbols */
+ coff_get_symtab_upper_bound,
+ coff_canonicalize_symtab,
+ coff_make_empty_symbol,
+ coff_print_symbol,
+ coff_get_symbol_info,
+ _bfd_xcoff_is_local_label_name,
+ coff_bfd_is_target_special_symbol,
+ coff_get_lineno,
+ coff_find_nearest_line,
+ _bfd_generic_find_line,
+ coff_find_inliner_info,
+ coff_bfd_make_debug_symbol,
+ _bfd_generic_read_minisymbols,
+ _bfd_generic_minisymbol_to_symbol,
+
+ /* Reloc */
+ coff_get_reloc_upper_bound,
+ coff_canonicalize_reloc,
+ _bfd_xcoff_reloc_type_lookup,
+ _bfd_xcoff_reloc_name_lookup,
+
+ /* Write */
+ coff_set_arch_mach,
+ coff_set_section_contents,
+
+ /* Link */
+ _bfd_xcoff_sizeof_headers,
+ bfd_generic_get_relocated_section_contents,
+ bfd_generic_relax_section,
+ _bfd_xcoff_bfd_link_hash_table_create,
+ _bfd_generic_link_hash_table_free,
+ _bfd_xcoff_bfd_link_add_symbols,
+ _bfd_generic_link_just_syms,
+ _bfd_xcoff_bfd_final_link,
+ _bfd_generic_link_split_section,
+ bfd_generic_gc_sections,
+ bfd_generic_merge_sections,
+ bfd_generic_is_group_section,
+ bfd_generic_discard_group,
+ _bfd_generic_section_already_linked,
+ _bfd_xcoff_define_common_symbol,
+
+ /* Dynamic */
+ _bfd_xcoff_get_dynamic_symtab_upper_bound,
+ _bfd_xcoff_canonicalize_dynamic_symtab,
+ _bfd_nodynamic_get_synthetic_symtab,
+ _bfd_xcoff_get_dynamic_reloc_upper_bound,
+ _bfd_xcoff_canonicalize_dynamic_reloc,
+
+ /* Opposite endian version, none exists */
+ NULL,
+
+ (void *) &bfd_pmac_xcoff_backend_data,
+ };