summaryrefslogtreecommitdiffstats
path: root/contrib/binutils/bfd
diff options
context:
space:
mode:
authorobrien <obrien@FreeBSD.org>2001-10-13 01:47:52 +0000
committerobrien <obrien@FreeBSD.org>2001-10-13 01:47:52 +0000
commit7734e00828d1a0cbfe8bad4005c310db5ae83187 (patch)
treeb32a6d10e1d7faddb1bb4fd37914636d276b9f34 /contrib/binutils/bfd
parent51c87054921b48ca6ca66bb7929ad4c05a5fe2f1 (diff)
downloadFreeBSD-src-7734e00828d1a0cbfe8bad4005c310db5ae83187.zip
FreeBSD-src-7734e00828d1a0cbfe8bad4005c310db5ae83187.tar.gz
Import the extra bits needed to target IA-64, PowerPC, and sparc64.
(this is Binutils from the FSF 2.11 branch [checked out 19-July-2001])
Diffstat (limited to 'contrib/binutils/bfd')
-rw-r--r--contrib/binutils/bfd/coff-ia64.c201
-rw-r--r--contrib/binutils/bfd/coff-rs6000.c2358
-rw-r--r--contrib/binutils/bfd/cpu-ia64-opc.c589
-rw-r--r--contrib/binutils/bfd/cpu-ia64.c57
-rw-r--r--contrib/binutils/bfd/cpu-rs6000.c116
-rw-r--r--contrib/binutils/bfd/efi-app-ia64.c35
-rw-r--r--contrib/binutils/bfd/elfxx-ia64.c4235
-rw-r--r--contrib/binutils/bfd/libpei.h321
-rw-r--r--contrib/binutils/bfd/peicode.h1324
-rw-r--r--contrib/binutils/bfd/sunos.c102
-rw-r--r--contrib/binutils/bfd/xcoff-target.h194
-rw-r--r--contrib/binutils/bfd/xcofflink.c6631
12 files changed, 16127 insertions, 36 deletions
diff --git a/contrib/binutils/bfd/coff-ia64.c b/contrib/binutils/bfd/coff-ia64.c
new file mode 100644
index 0000000..776d3fa
--- /dev/null
+++ b/contrib/binutils/bfd/coff-ia64.c
@@ -0,0 +1,201 @@
+/* BFD back-end for HP/Intel IA-64 COFF files.
+ Copyright 1999, 2000, 2001 Free Software Foundation, Inc.
+ Contributed by David Mosberger <davidm@hpl.hp.com>
+
+This file is part of BFD, the Binary File Descriptor library.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#include "bfd.h"
+#include "sysdep.h"
+#include "libbfd.h"
+#include "coff/ia64.h"
+#include "coff/internal.h"
+#include "coff/pe.h"
+#include "libcoff.h"
+
+#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2)
+/* The page size is a guess based on ELF. */
+
+#define COFF_PAGE_SIZE 0x1000
+
+static reloc_howto_type howto_table[] =
+{
+ EMPTY_HOWTO (0),
+};
+
+#define BADMAG(x) IA64BADMAG(x)
+#define IA64 1 /* Customize coffcode.h */
+
+#ifdef COFF_WITH_pep
+# undef AOUTSZ
+# define AOUTSZ PEPAOUTSZ
+# define PEAOUTHDR PEPAOUTHDR
+#endif
+
+#define RTYPE2HOWTO(cache_ptr, dst) \
+ (cache_ptr)->howto = howto_table + (dst)->r_type;
+
+#ifdef COFF_WITH_PE
+/* Return true if this relocation should
+ appear in the output .reloc section. */
+
+static boolean
+in_reloc_p(abfd, howto)
+ bfd * abfd ATTRIBUTE_UNUSED;
+ reloc_howto_type *howto ATTRIBUTE_UNUSED;
+{
+ return 0; /* We don't do relocs for now... */
+}
+#endif
+
+#include "coffcode.h"
+
+static const bfd_target *
+ia64coff_object_p (abfd)
+ bfd *abfd;
+{
+#ifdef COFF_IMAGE_WITH_PE
+ {
+ struct external_PEI_DOS_hdr dos_hdr;
+ struct external_PEI_IMAGE_hdr image_hdr;
+ file_ptr offset;
+
+ if (bfd_seek (abfd, 0x00, SEEK_SET) != 0
+ || bfd_read (&dos_hdr, 1, sizeof (dos_hdr), abfd)
+ != sizeof (dos_hdr))
+ {
+ if (bfd_get_error () != bfd_error_system_call)
+ bfd_set_error (bfd_error_wrong_format);
+ return NULL;
+ }
+
+ /* There are really two magic numbers involved; the magic number
+ that says this is a NT executable (PEI) and the magic number
+ that determines the architecture. The former is DOSMAGIC,
+ stored in the e_magic field. The latter is stored in the
+ f_magic field. If the NT magic number isn't valid, the
+ architecture magic number could be mimicked by some other
+ field (specifically, the number of relocs in section 3). Since
+ this routine can only be called correctly for a PEI file, check
+ the e_magic number here, and, if it doesn't match, clobber the
+ f_magic number so that we don't get a false match. */
+ if (bfd_h_get_16 (abfd, (bfd_byte *) dos_hdr.e_magic) != DOSMAGIC)
+ {
+ bfd_set_error (bfd_error_wrong_format);
+ return NULL;
+ }
+
+ offset = bfd_h_get_32 (abfd, (bfd_byte *) dos_hdr.e_lfanew);
+ if (bfd_seek (abfd, (file_ptr) offset, SEEK_SET) != 0
+ || bfd_read (&image_hdr, 1, sizeof (image_hdr), abfd)
+ != sizeof (image_hdr))
+ {
+ if (bfd_get_error () != bfd_error_system_call)
+ bfd_set_error (bfd_error_wrong_format);
+ return NULL;
+ }
+
+ if (bfd_h_get_32 (abfd, (bfd_byte *) image_hdr.nt_signature)
+ != 0x4550)
+ {
+ bfd_set_error (bfd_error_wrong_format);
+ return NULL;
+ }
+
+ /* Here is the hack. coff_object_p wants to read filhsz bytes to
+ pick up the COFF header for PE, see "struct external_PEI_filehdr"
+ in include/coff/pe.h. We adjust so that that will work. */
+ if (bfd_seek (abfd,
+ (file_ptr) (offset - sizeof (dos_hdr)),
+ SEEK_SET)
+ != 0)
+ {
+ if (bfd_get_error () != bfd_error_system_call)
+ bfd_set_error (bfd_error_wrong_format);
+ return NULL;
+ }
+ }
+#endif
+
+ return coff_object_p (abfd);
+}
+
+const bfd_target
+#ifdef TARGET_SYM
+ TARGET_SYM =
+#else
+ ia64coff_vec =
+#endif
+{
+#ifdef TARGET_NAME
+ TARGET_NAME,
+#else
+ "coff-ia64", /* name */
+#endif
+ bfd_target_coff_flavour,
+ BFD_ENDIAN_LITTLE, /* data byte order is little */
+ BFD_ENDIAN_LITTLE, /* header byte order is little */
+
+ (HAS_RELOC | EXEC_P | /* object flags */
+ HAS_LINENO | HAS_DEBUG |
+ HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
+
+#ifndef COFF_WITH_PE
+ (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* section flags */
+ | SEC_CODE | SEC_DATA),
+#else
+ (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* section flags */
+ | SEC_CODE | SEC_DATA
+ | SEC_LINK_ONCE | SEC_LINK_DUPLICATES),
+#endif
+
+#ifdef TARGET_UNDERSCORE
+ TARGET_UNDERSCORE, /* leading underscore */
+#else
+ 0, /* leading underscore */
+#endif
+ '/', /* ar_pad_char */
+ 15, /* ar_max_namelen */
+
+ bfd_getl64, bfd_getl_signed_64, bfd_putl64,
+ bfd_getl32, bfd_getl_signed_32, bfd_putl32,
+ bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
+ bfd_getl64, bfd_getl_signed_64, bfd_putl64,
+ bfd_getl32, bfd_getl_signed_32, bfd_putl32,
+ bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
+
+/* Note that we allow an object file to be treated as a core file as well. */
+ {_bfd_dummy_target, ia64coff_object_p, /* bfd_check_format */
+ bfd_generic_archive_p, ia64coff_object_p},
+ {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
+ bfd_false},
+ {bfd_false, coff_write_object_contents, /* bfd_write_contents */
+ _bfd_write_archive_contents, bfd_false},
+
+ BFD_JUMP_TABLE_GENERIC (coff),
+ BFD_JUMP_TABLE_COPY (coff),
+ BFD_JUMP_TABLE_CORE (_bfd_nocore),
+ BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
+ BFD_JUMP_TABLE_SYMBOLS (coff),
+ BFD_JUMP_TABLE_RELOCS (coff),
+ BFD_JUMP_TABLE_WRITE (coff),
+ BFD_JUMP_TABLE_LINK (coff),
+ BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
+
+ NULL,
+
+ COFF_SWAP_TABLE
+};
diff --git a/contrib/binutils/bfd/coff-rs6000.c b/contrib/binutils/bfd/coff-rs6000.c
new file mode 100644
index 0000000..ed47000
--- /dev/null
+++ b/contrib/binutils/bfd/coff-rs6000.c
@@ -0,0 +1,2358 @@
+/* BFD back-end for IBM RS/6000 "XCOFF" files.
+ Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+ 2000, 2001
+ Free Software Foundation, Inc.
+ FIXME: Can someone provide a transliteration of this name into ASCII?
+ Using the following chars caused a compiler warning on HIUX (so I replaced
+ them with octal escapes), and isn't useful without an understanding of what
+ character set it is.
+ Written by Metin G. Ozisik, Mimi Ph\373\364ng-Th\345o V\365,
+ and John Gilmore.
+ Archive support from Damon A. Permezel.
+ Contributed by IBM Corporation and Cygnus Support.
+
+This file is part of BFD, the Binary File Descriptor library.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#include "bfd.h"
+#include "sysdep.h"
+#include "libbfd.h"
+#include "coff/internal.h"
+#include "coff/rs6000.h"
+#include "libcoff.h"
+#define TARGET_NAME "aixcoff-rs6000"
+#define TARGET_SYM rs6000coff_vec
+#include "xcoff-target.h"
+
+/* The main body of code is in coffcode.h. */
+
+static const char *normalize_filename PARAMS ((bfd *));
+
+/* We use our own tdata type. Its first field is the COFF tdata type,
+ so the COFF routines are compatible. */
+
+boolean
+_bfd_xcoff_mkobject (abfd)
+ bfd *abfd;
+{
+ coff_data_type *coff;
+
+ abfd->tdata.xcoff_obj_data =
+ ((struct xcoff_tdata *)
+ bfd_zalloc (abfd, sizeof (struct xcoff_tdata)));
+ if (abfd->tdata.xcoff_obj_data == NULL)
+ return false;
+ coff = coff_data (abfd);
+ coff->symbols = (coff_symbol_type *) NULL;
+ coff->conversion_table = (unsigned int *) NULL;
+ coff->raw_syments = (struct coff_ptr_struct *) NULL;
+ coff->relocbase = 0;
+
+ xcoff_data (abfd)->modtype = ('1' << 8) | 'L';
+
+ /* We set cputype to -1 to indicate that it has not been
+ initialized. */
+ xcoff_data (abfd)->cputype = -1;
+
+ xcoff_data (abfd)->csects = NULL;
+ xcoff_data (abfd)->debug_indices = NULL;
+
+ return true;
+}
+
+/* Copy XCOFF data from one BFD to another. */
+
+boolean
+_bfd_xcoff_copy_private_bfd_data (ibfd, obfd)
+ bfd *ibfd;
+ bfd *obfd;
+{
+ struct xcoff_tdata *ix, *ox;
+ asection *sec;
+
+ if (ibfd->xvec != obfd->xvec)
+ return true;
+ ix = xcoff_data (ibfd);
+ ox = xcoff_data (obfd);
+ ox->full_aouthdr = ix->full_aouthdr;
+ ox->toc = ix->toc;
+ if (ix->sntoc == 0)
+ ox->sntoc = 0;
+ else
+ {
+ sec = coff_section_from_bfd_index (ibfd, ix->sntoc);
+ if (sec == NULL)
+ ox->sntoc = 0;
+ else
+ ox->sntoc = sec->output_section->target_index;
+ }
+ if (ix->snentry == 0)
+ ox->snentry = 0;
+ else
+ {
+ sec = coff_section_from_bfd_index (ibfd, ix->snentry);
+ if (sec == NULL)
+ ox->snentry = 0;
+ else
+ ox->snentry = sec->output_section->target_index;
+ }
+ ox->text_align_power = ix->text_align_power;
+ ox->data_align_power = ix->data_align_power;
+ ox->modtype = ix->modtype;
+ ox->cputype = ix->cputype;
+ ox->maxdata = ix->maxdata;
+ ox->maxstack = ix->maxstack;
+ return true;
+}
+
+/* I don't think XCOFF really has a notion of local labels based on
+ name. This will mean that ld -X doesn't actually strip anything.
+ The AIX native linker does not have a -X option, and it ignores the
+ -x option. */
+
+boolean
+_bfd_xcoff_is_local_label_name (abfd, name)
+ bfd *abfd ATTRIBUTE_UNUSED;
+ const char *name ATTRIBUTE_UNUSED;
+{
+ return false;
+}
+
+void
+_bfd_xcoff_swap_sym_in (abfd, ext1, in1)
+ bfd *abfd;
+ PTR ext1;
+ PTR in1;
+{
+ SYMENT *ext = (SYMENT *)ext1;
+ struct internal_syment *in = (struct internal_syment *)in1;
+
+ if (ext->e.e_name[0] != 0)
+ {
+ memcpy(in->_n._n_name, ext->e.e_name, SYMNMLEN);
+ }
+ else
+ {
+ in->_n._n_n._n_zeroes = 0;
+ in->_n._n_n._n_offset =
+ bfd_h_get_32(abfd, (bfd_byte *) ext->e.e.e_offset);
+ }
+
+ in->n_value = bfd_h_get_32(abfd, (bfd_byte *) ext->e_value);
+ in->n_scnum = bfd_h_get_16(abfd, (bfd_byte *) ext->e_scnum);
+ in->n_type = bfd_h_get_16(abfd, (bfd_byte *) ext->e_type);
+ in->n_sclass = bfd_h_get_8(abfd, ext->e_sclass);
+ in->n_numaux = bfd_h_get_8(abfd, ext->e_numaux);
+}
+
+unsigned int
+_bfd_xcoff_swap_sym_out (abfd, inp, extp)
+ bfd *abfd;
+ PTR inp;
+ PTR extp;
+{
+ struct internal_syment *in = (struct internal_syment *)inp;
+ SYMENT *ext =(SYMENT *)extp;
+
+ if (in->_n._n_name[0] != 0)
+ {
+ memcpy(ext->e.e_name, in->_n._n_name, SYMNMLEN);
+ }
+ else
+ {
+ bfd_h_put_32(abfd, 0, (bfd_byte *) ext->e.e.e_zeroes);
+ bfd_h_put_32(abfd, in->_n._n_n._n_offset,
+ (bfd_byte *) ext->e.e.e_offset);
+ }
+
+ bfd_h_put_32(abfd, in->n_value , (bfd_byte *) ext->e_value);
+ bfd_h_put_16(abfd, in->n_scnum , (bfd_byte *) ext->e_scnum);
+ bfd_h_put_16(abfd, in->n_type , (bfd_byte *) ext->e_type);
+ bfd_h_put_8(abfd, in->n_sclass , ext->e_sclass);
+ bfd_h_put_8(abfd, in->n_numaux , ext->e_numaux);
+ return bfd_coff_symesz (abfd);
+}
+
+#define PUTWORD bfd_h_put_32
+#define PUTHALF bfd_h_put_16
+#define PUTBYTE bfd_h_put_8
+#define GETWORD bfd_h_get_32
+#define GETHALF bfd_h_get_16
+#define GETBYTE bfd_h_get_8
+
+void
+_bfd_xcoff_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1)
+ bfd *abfd;
+ PTR ext1;
+ int type;
+ int class;
+ int indx;
+ int numaux;
+ PTR in1;
+{
+ AUXENT *ext = (AUXENT *)ext1;
+ union internal_auxent *in = (union internal_auxent *)in1;
+
+ switch (class) {
+ case C_FILE:
+ if (ext->x_file.x_fname[0] == 0) {
+ in->x_file.x_n.x_zeroes = 0;
+ in->x_file.x_n.x_offset =
+ bfd_h_get_32(abfd, (bfd_byte *) ext->x_file.x_n.x_offset);
+ } else {
+ if (numaux > 1)
+ {
+ if (indx == 0)
+ memcpy (in->x_file.x_fname, ext->x_file.x_fname,
+ numaux * sizeof (AUXENT));
+ }
+ else
+ {
+ memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
+ }
+ }
+ goto end;
+
+ /* RS/6000 "csect" auxents */
+ case C_EXT:
+ case C_HIDEXT:
+ if (indx + 1 == numaux)
+ {
+ in->x_csect.x_scnlen.l =
+ bfd_h_get_32 (abfd, ext->x_csect.x_scnlen);
+ in->x_csect.x_parmhash = bfd_h_get_32 (abfd,
+ ext->x_csect.x_parmhash);
+ in->x_csect.x_snhash = bfd_h_get_16 (abfd, ext->x_csect.x_snhash);
+ /* We don't have to hack bitfields in x_smtyp because it's
+ defined by shifts-and-ands, which are equivalent on all
+ byte orders. */
+ in->x_csect.x_smtyp = bfd_h_get_8 (abfd, ext->x_csect.x_smtyp);
+ in->x_csect.x_smclas = bfd_h_get_8 (abfd, ext->x_csect.x_smclas);
+ in->x_csect.x_stab = bfd_h_get_32 (abfd, ext->x_csect.x_stab);
+ in->x_csect.x_snstab = bfd_h_get_16 (abfd, ext->x_csect.x_snstab);
+ goto end;
+ }
+ break;
+
+ case C_STAT:
+ case C_LEAFSTAT:
+ case C_HIDDEN:
+ if (type == T_NULL) {
+ in->x_scn.x_scnlen = bfd_h_get_32(abfd,
+ (bfd_byte *) ext->x_scn.x_scnlen);
+ in->x_scn.x_nreloc = bfd_h_get_16(abfd,
+ (bfd_byte *) ext->x_scn.x_nreloc);
+ in->x_scn.x_nlinno = bfd_h_get_16(abfd,
+ (bfd_byte *) ext->x_scn.x_nlinno);
+ /* PE defines some extra fields; we zero them out for
+ safety. */
+ in->x_scn.x_checksum = 0;
+ in->x_scn.x_associated = 0;
+ in->x_scn.x_comdat = 0;
+
+ goto end;
+ }
+ break;
+ }
+
+ in->x_sym.x_tagndx.l = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_tagndx);
+ in->x_sym.x_tvndx = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_tvndx);
+
+ if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
+ {
+ in->x_sym.x_fcnary.x_fcn.x_lnnoptr = bfd_h_get_32(abfd, (bfd_byte *)
+ ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
+ in->x_sym.x_fcnary.x_fcn.x_endndx.l = bfd_h_get_32(abfd, (bfd_byte *)
+ ext->x_sym.x_fcnary.x_fcn.x_endndx);
+ }
+ else
+ {
+ in->x_sym.x_fcnary.x_ary.x_dimen[0] =
+ bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
+ in->x_sym.x_fcnary.x_ary.x_dimen[1] =
+ bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
+ in->x_sym.x_fcnary.x_ary.x_dimen[2] =
+ bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
+ in->x_sym.x_fcnary.x_ary.x_dimen[3] =
+ bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
+ }
+ if (ISFCN(type)) {
+ in->x_sym.x_misc.x_fsize = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_misc.x_fsize);
+ }
+ else {
+ in->x_sym.x_misc.x_lnsz.x_lnno = bfd_h_get_16(abfd, (bfd_byte *)
+ ext->x_sym.x_misc.x_lnsz.x_lnno);
+ in->x_sym.x_misc.x_lnsz.x_size = bfd_h_get_16(abfd, (bfd_byte *)
+ ext->x_sym.x_misc.x_lnsz.x_size);
+ }
+
+end: ;
+ /* the semicolon is because MSVC doesn't like labels at
+ end of block. */
+
+}
+
+unsigned int
+_bfd_xcoff_swap_aux_out (abfd, inp, type, class, indx, numaux, extp)
+ bfd *abfd;
+ PTR inp;
+ int type;
+ int class;
+ int indx ATTRIBUTE_UNUSED;
+ int numaux ATTRIBUTE_UNUSED;
+ PTR extp;
+{
+ union internal_auxent *in = (union internal_auxent *)inp;
+ AUXENT *ext = (AUXENT *)extp;
+
+ memset((PTR)ext, 0, bfd_coff_auxesz (abfd));
+ switch (class)
+ {
+ case C_FILE:
+ if (in->x_file.x_fname[0] == 0)
+ {
+ PUTWORD(abfd, 0, (bfd_byte *) ext->x_file.x_n.x_zeroes);
+ PUTWORD(abfd,
+ in->x_file.x_n.x_offset,
+ (bfd_byte *) ext->x_file.x_n.x_offset);
+ }
+ else
+ {
+ memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
+ }
+ goto end;
+
+ /* RS/6000 "csect" auxents */
+ case C_EXT:
+ case C_HIDEXT:
+ if (indx + 1 == numaux)
+ {
+ PUTWORD (abfd, in->x_csect.x_scnlen.l,ext->x_csect.x_scnlen);
+ PUTWORD (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash);
+ PUTHALF (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash);
+ /* We don't have to hack bitfields in x_smtyp because it's
+ defined by shifts-and-ands, which are equivalent on all
+ byte orders. */
+ PUTBYTE (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp);
+ PUTBYTE (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas);
+ PUTWORD (abfd, in->x_csect.x_stab, ext->x_csect.x_stab);
+ PUTHALF (abfd, in->x_csect.x_snstab, ext->x_csect.x_snstab);
+ goto end;
+ }
+ break;
+
+ case C_STAT:
+ case C_LEAFSTAT:
+ case C_HIDDEN:
+ if (type == T_NULL) {
+ bfd_h_put_32(abfd, in->x_scn.x_scnlen, (bfd_byte *) ext->x_scn.x_scnlen);
+ bfd_h_put_16(abfd, in->x_scn.x_nreloc, (bfd_byte *) ext->x_scn.x_nreloc);
+ bfd_h_put_16(abfd, in->x_scn.x_nlinno, (bfd_byte *) ext->x_scn.x_nlinno);
+ goto end;
+ }
+ break;
+ }
+
+ PUTWORD(abfd, in->x_sym.x_tagndx.l, (bfd_byte *) ext->x_sym.x_tagndx);
+ bfd_h_put_16 (abfd, in->x_sym.x_tvndx , (bfd_byte *) ext->x_sym.x_tvndx);
+
+ if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
+ {
+ bfd_h_put_32(abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr,
+ (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
+ PUTWORD(abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l,
+ (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx);
+ }
+ else
+ {
+ bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0],
+ (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
+ bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1],
+ (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
+ bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2],
+ (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
+ bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3],
+ (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
+ }
+
+ if (ISFCN (type))
+ PUTWORD (abfd, in->x_sym.x_misc.x_fsize,
+ (bfd_byte *) ext->x_sym.x_misc.x_fsize);
+ else
+ {
+ bfd_h_put_16(abfd, in->x_sym.x_misc.x_lnsz.x_lnno,
+ (bfd_byte *)ext->x_sym.x_misc.x_lnsz.x_lnno);
+ bfd_h_put_16(abfd, in->x_sym.x_misc.x_lnsz.x_size,
+ (bfd_byte *)ext->x_sym.x_misc.x_lnsz.x_size);
+ }
+
+end:
+ return bfd_coff_auxesz (abfd);
+}
+
+/* The XCOFF reloc table. Actually, XCOFF relocations specify the
+ bitsize and whether they are signed or not, along with a
+ conventional type. This table is for the types, which are used for
+ different algorithms for putting in the reloc. Many of these
+ relocs need special_function entries, which I have not written. */
+
+/* In case we're on a 32-bit machine, construct a 64-bit "-1" value
+ from smaller values. Start with zero, widen, *then* decrement. */
+#define MINUS_ONE (((bfd_vma)0) - 1)
+
+reloc_howto_type xcoff_howto_table[] =
+{
+ /* Standard 32 bit relocation. */
+ 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 */
+
+ /* 32 bit relocation, but store negative value. */
+ HOWTO (1, /* 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_NEG", /* name */
+ true, /* partial_inplace */
+ 0xffffffff, /* src_mask */
+ 0xffffffff, /* dst_mask */
+ false), /* pcrel_offset */
+
+ /* 32 bit PC relative relocation. */
+ HOWTO (2, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 32, /* bitsize */
+ true, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_signed, /* complain_on_overflow */
+ 0, /* special_function */
+ "R_REL", /* name */
+ true, /* partial_inplace */
+ 0xffffffff, /* src_mask */
+ 0xffffffff, /* dst_mask */
+ false), /* pcrel_offset */
+
+ /* 16 bit TOC relative relocation. */
+ HOWTO (3, /* type */
+ 0, /* rightshift */
+ 1, /* size (0 = byte, 1 = short, 2 = long) */
+ 16, /* bitsize */
+ false, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_bitfield, /* complain_on_overflow */
+ 0, /* special_function */
+ "R_TOC", /* name */
+ true, /* partial_inplace */
+ 0xffff, /* src_mask */
+ 0xffff, /* dst_mask */
+ false), /* pcrel_offset */
+
+ /* I don't really know what this is. */
+ HOWTO (4, /* type */
+ 1, /* 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_RTB", /* name */
+ true, /* partial_inplace */
+ 0xffffffff, /* src_mask */
+ 0xffffffff, /* dst_mask */
+ false), /* pcrel_offset */
+
+ /* External TOC relative symbol. */
+ HOWTO (5, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 16, /* bitsize */
+ false, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_bitfield, /* complain_on_overflow */
+ 0, /* special_function */
+ "R_GL", /* name */
+ true, /* partial_inplace */
+ 0xffff, /* src_mask */
+ 0xffff, /* dst_mask */
+ false), /* pcrel_offset */
+
+ /* Local TOC relative symbol. */
+ HOWTO (6, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 16, /* bitsize */
+ false, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_bitfield, /* complain_on_overflow */
+ 0, /* special_function */
+ "R_TCL", /* name */
+ true, /* partial_inplace */
+ 0xffff, /* src_mask */
+ 0xffff, /* dst_mask */
+ false), /* pcrel_offset */
+
+ EMPTY_HOWTO (7),
+
+ /* Non modifiable absolute branch. */
+ HOWTO (8, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 26, /* bitsize */
+ false, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_bitfield, /* complain_on_overflow */
+ 0, /* special_function */
+ "R_BA", /* name */
+ true, /* partial_inplace */
+ 0x3fffffc, /* src_mask */
+ 0x3fffffc, /* dst_mask */
+ false), /* pcrel_offset */
+
+ EMPTY_HOWTO (9),
+
+ /* Non modifiable relative branch. */
+ HOWTO (0xa, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 26, /* bitsize */
+ true, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_signed, /* complain_on_overflow */
+ 0, /* special_function */
+ "R_BR", /* name */
+ true, /* partial_inplace */
+ 0x3fffffc, /* src_mask */
+ 0x3fffffc, /* dst_mask */
+ false), /* pcrel_offset */
+
+ EMPTY_HOWTO (0xb),
+
+ /* Indirect load. */
+ HOWTO (0xc, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 16, /* bitsize */
+ false, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_bitfield, /* complain_on_overflow */
+ 0, /* special_function */
+ "R_RL", /* name */
+ true, /* partial_inplace */
+ 0xffff, /* src_mask */
+ 0xffff, /* dst_mask */
+ false), /* pcrel_offset */
+
+ /* Load address. */
+ HOWTO (0xd, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 16, /* bitsize */
+ false, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_bitfield, /* complain_on_overflow */
+ 0, /* special_function */
+ "R_RLA", /* name */
+ true, /* partial_inplace */
+ 0xffff, /* src_mask */
+ 0xffff, /* dst_mask */
+ false), /* pcrel_offset */
+
+ EMPTY_HOWTO (0xe),
+
+ /* Non-relocating reference. */
+ HOWTO (0xf, /* 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_REF", /* name */
+ false, /* partial_inplace */
+ 0, /* src_mask */
+ 0, /* dst_mask */
+ false), /* pcrel_offset */
+
+ EMPTY_HOWTO (0x10),
+ EMPTY_HOWTO (0x11),
+
+ /* TOC relative indirect load. */
+ HOWTO (0x12, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 16, /* bitsize */
+ false, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_bitfield, /* complain_on_overflow */
+ 0, /* special_function */
+ "R_TRL", /* name */
+ true, /* partial_inplace */
+ 0xffff, /* src_mask */
+ 0xffff, /* dst_mask */
+ false), /* pcrel_offset */
+
+ /* TOC relative load address. */
+ HOWTO (0x13, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 16, /* bitsize */
+ false, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_bitfield, /* complain_on_overflow */
+ 0, /* special_function */
+ "R_TRLA", /* name */
+ true, /* partial_inplace */
+ 0xffff, /* src_mask */
+ 0xffff, /* dst_mask */
+ false), /* pcrel_offset */
+
+ /* Modifiable relative branch. */
+ HOWTO (0x14, /* type */
+ 1, /* 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_RRTBI", /* name */
+ true, /* partial_inplace */
+ 0xffffffff, /* src_mask */
+ 0xffffffff, /* dst_mask */
+ false), /* pcrel_offset */
+
+ /* Modifiable absolute branch. */
+ HOWTO (0x15, /* type */
+ 1, /* 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_RRTBA", /* name */
+ true, /* partial_inplace */
+ 0xffffffff, /* src_mask */
+ 0xffffffff, /* dst_mask */
+ false), /* pcrel_offset */
+
+ /* Modifiable call absolute indirect. */
+ HOWTO (0x16, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 16, /* bitsize */
+ false, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_bitfield, /* complain_on_overflow */
+ 0, /* special_function */
+ "R_CAI", /* name */
+ true, /* partial_inplace */
+ 0xffff, /* src_mask */
+ 0xffff, /* dst_mask */
+ false), /* pcrel_offset */
+
+ /* Modifiable call relative. */
+ HOWTO (0x17, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 16, /* bitsize */
+ false, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_bitfield, /* complain_on_overflow */
+ 0, /* special_function */
+ "R_CREL", /* name */
+ true, /* partial_inplace */
+ 0xffff, /* src_mask */
+ 0xffff, /* dst_mask */
+ false), /* pcrel_offset */
+
+ /* Modifiable branch absolute. */
+ HOWTO (0x18, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 26, /* bitsize */
+ false, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_bitfield, /* complain_on_overflow */
+ 0, /* special_function */
+ "R_RBA", /* name */
+ true, /* partial_inplace */
+ 0xffff, /* src_mask */
+ 0xffff, /* dst_mask */
+ false), /* pcrel_offset */
+
+ /* Modifiable branch absolute. */
+ HOWTO (0x19, /* 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_RBAC", /* name */
+ true, /* partial_inplace */
+ 0xffff, /* src_mask */
+ 0xffff, /* dst_mask */
+ false), /* pcrel_offset */
+
+ /* Modifiable branch relative. */
+ HOWTO (0x1a, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 26, /* bitsize */
+ false, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_signed, /* complain_on_overflow */
+ 0, /* special_function */
+ "R_RBR", /* name */
+ true, /* partial_inplace */
+ 0xffff, /* src_mask */
+ 0xffff, /* dst_mask */
+ false), /* pcrel_offset */
+
+ /* Modifiable branch absolute. */
+ HOWTO (0x1b, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 16, /* bitsize */
+ false, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_bitfield, /* complain_on_overflow */
+ 0, /* special_function */
+ "R_RBRC", /* name */
+ true, /* partial_inplace */
+ 0xffff, /* src_mask */
+ 0xffff, /* dst_mask */
+ false), /* pcrel_offset */
+ HOWTO (0, /* type */
+ 0, /* rightshift */
+ 4, /* size (0 = byte, 1 = short, 2 = long) */
+ 64, /* bitsize */
+ false, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_bitfield, /* complain_on_overflow */
+ 0, /* special_function */
+ "R_POS", /* name */
+ true, /* partial_inplace */
+ MINUS_ONE, /* src_mask */
+ MINUS_ONE, /* dst_mask */
+ false) /* pcrel_offset */
+
+};
+
+/* These are the first two like the above but for 16-bit relocs. */
+static reloc_howto_type xcoff_howto_table_16[] =
+{
+ /* Standard 16 bit relocation. */
+ HOWTO (0, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 16, /* bitsize */
+ false, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_bitfield, /* complain_on_overflow */
+ 0, /* special_function */
+ "R_POS_16", /* name */
+ true, /* partial_inplace */
+ 0xffffffff, /* src_mask */
+ 0xffffffff, /* dst_mask */
+ false), /* pcrel_offset */
+
+ /* 16 bit relocation, but store negative value. */
+ HOWTO (1, /* type */
+ 0, /* rightshift */
+ -2, /* size (0 = byte, 1 = short, 2 = long) */
+ 16, /* bitsize */
+ false, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_bitfield, /* complain_on_overflow */
+ 0, /* special_function */
+ "R_NEG_16", /* name */
+ true, /* partial_inplace */
+ 0xffffffff, /* src_mask */
+ 0xffffffff, /* dst_mask */
+ false), /* pcrel_offset */
+
+ /* 16 bit PC relative relocation. */
+ HOWTO (2, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 32, /* bitsize */
+ true, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_signed, /* complain_on_overflow */
+ 0, /* special_function */
+ "R_REL_16", /* name */
+ true, /* partial_inplace */
+ 0xffffffff, /* src_mask */
+ 0xffffffff, /* dst_mask */
+ false) /* pcrel_offset */
+ };
+
+void
+_bfd_xcoff_rtype2howto (relent, internal)
+ arelent *relent;
+ struct internal_reloc *internal;
+{
+ relent->howto = xcoff_howto_table + internal->r_type;
+
+ if (relent->howto->bitsize != ((unsigned int) internal->r_size & 0x1f) + 1
+ && (internal->r_type
+ < sizeof (xcoff_howto_table_16)/sizeof (xcoff_howto_table_16[0])))
+ relent->howto = xcoff_howto_table_16 + internal->r_type;
+
+ /* The r_size field of an XCOFF reloc encodes the bitsize of the
+ relocation, as well as indicating whether it is signed or not.
+ Doublecheck that the relocation information gathered from the
+ type matches this information. The bitsize is not significant
+ for R_REF relocs. */
+ if (relent->howto->dst_mask != 0
+ && (relent->howto->bitsize
+ != ((unsigned int) internal->r_size & 0x3f) + 1))
+ abort ();
+#if 0
+ if ((internal->r_size & 0x80) != 0
+ ? (relent->howto->complain_on_overflow != complain_overflow_signed)
+ : (relent->howto->complain_on_overflow != complain_overflow_bitfield))
+ abort ();
+#endif
+}
+
+reloc_howto_type *
+_bfd_xcoff_reloc_type_lookup (abfd, code)
+ bfd *abfd ATTRIBUTE_UNUSED;
+ bfd_reloc_code_real_type code;
+{
+ switch (code)
+ {
+ case BFD_RELOC_PPC_B26:
+ return &xcoff_howto_table[0xa];
+ case BFD_RELOC_PPC_BA26:
+ return &xcoff_howto_table[8];
+ case BFD_RELOC_PPC_TOC16:
+ return &xcoff_howto_table[3];
+ case BFD_RELOC_32:
+ case BFD_RELOC_CTOR:
+ return &xcoff_howto_table[0];
+ case BFD_RELOC_64:
+ return &xcoff_howto_table[0x1c];
+ default:
+ return NULL;
+ }
+}
+
+/* XCOFF archive support. The original version of this code was by
+ Damon A. Permezel. It was enhanced to permit cross support, and
+ writing archive files, by Ian Lance Taylor, Cygnus Support.
+
+ XCOFF uses its own archive format. Everything is hooked together
+ with file offset links, so it is possible to rapidly update an
+ archive in place. Of course, we don't do that. An XCOFF archive
+ has a real file header, not just an ARMAG string. The structure of
+ the file header and of each archive header appear below.
+
+ An XCOFF archive also has a member table, which is a list of
+ elements in the archive (you can get that by looking through the
+ linked list, but you have to read a lot more of the file). The
+ member table has a normal archive header with an empty name. It is
+ normally (and perhaps must be) the second to last entry in the
+ archive. The member table data is almost printable ASCII. It
+ starts with a 12 character decimal string which is the number of
+ entries in the table. For each entry it has a 12 character decimal
+ string which is the offset in the archive of that member. These
+ entries are followed by a series of null terminated strings which
+ are the member names for each entry.
+
+ Finally, an XCOFF archive has a global symbol table, which is what
+ we call the armap. The global symbol table has a normal archive
+ header with an empty name. It is normally (and perhaps must be)
+ the last entry in the archive. The contents start with a four byte
+ binary number which is the number of entries. This is followed by
+ a that many four byte binary numbers; each is the file offset of an
+ entry in the archive. These numbers are followed by a series of
+ null terminated strings, which are symbol names.
+
+ AIX 4.3 introduced a new archive format which can handle larger
+ files and also 32- and 64-bit objects in the same archive. The
+ things said above remain true except that there is now more than
+ one global symbol table. The one is used to index 32-bit objects,
+ the other for 64-bit objects.
+
+ The new archives (recognizable by the new ARMAG string) has larger
+ field lengths so that we cannot really share any code. Also we have
+ to take care that we are not generating the new form of archives
+ on AIX 4.2 or earlier systems. */
+
+/* XCOFF archives use this as a magic string. Note that both strings
+ have the same length. */
+
+#define XCOFFARMAG "<aiaff>\012"
+#define XCOFFARMAGBIG "<bigaf>\012"
+#define SXCOFFARMAG 8
+
+/* This terminates an XCOFF archive member name. */
+
+#define XCOFFARFMAG "`\012"
+#define SXCOFFARFMAG 2
+
+/* XCOFF archives start with this (printable) structure. */
+
+struct xcoff_ar_file_hdr
+{
+ /* Magic string. */
+ char magic[SXCOFFARMAG];
+
+ /* Offset of the member table (decimal ASCII string). */
+ char memoff[12];
+
+ /* Offset of the global symbol table (decimal ASCII string). */
+ char symoff[12];
+
+ /* Offset of the first member in the archive (decimal ASCII string). */
+ char firstmemoff[12];
+
+ /* Offset of the last member in the archive (decimal ASCII string). */
+ char lastmemoff[12];
+
+ /* Offset of the first member on the free list (decimal ASCII
+ string). */
+ char freeoff[12];
+};
+
+#define SIZEOF_AR_FILE_HDR (5 * 12 + SXCOFFARMAG)
+
+/* This is the equivalent data structure for the big archive format. */
+
+struct xcoff_ar_file_hdr_big
+{
+ /* Magic string. */
+ char magic[SXCOFFARMAG];
+
+ /* Offset of the member table (decimal ASCII string). */
+ char memoff[20];
+
+ /* Offset of the global symbol table for 32-bit objects (decimal ASCII
+ string). */
+ char symoff[20];
+
+ /* Offset of the global symbol table for 64-bit objects (decimal ASCII
+ string). */
+ char symoff64[20];
+
+ /* Offset of the first member in the archive (decimal ASCII string). */
+ char firstmemoff[20];
+
+ /* Offset of the last member in the archive (decimal ASCII string). */
+ char lastmemoff[20];
+
+ /* Offset of the first member on the free list (decimal ASCII
+ string). */
+ char freeoff[20];
+};
+
+#define SIZEOF_AR_FILE_HDR_BIG (6 * 20 + SXCOFFARMAG)
+
+/* Each XCOFF archive member starts with this (printable) structure. */
+
+struct xcoff_ar_hdr
+{
+ /* File size not including the header (decimal ASCII string). */
+ char size[12];
+
+ /* File offset of next archive member (decimal ASCII string). */
+ char nextoff[12];
+
+ /* File offset of previous archive member (decimal ASCII string). */
+ char prevoff[12];
+
+ /* File mtime (decimal ASCII string). */
+ char date[12];
+
+ /* File UID (decimal ASCII string). */
+ char uid[12];
+
+ /* File GID (decimal ASCII string). */
+ char gid[12];
+
+ /* File mode (octal ASCII string). */
+ char mode[12];
+
+ /* Length of file name (decimal ASCII string). */
+ char namlen[4];
+
+ /* This structure is followed by the file name. The length of the
+ name is given in the namlen field. If the length of the name is
+ odd, the name is followed by a null byte. The name and optional
+ null byte are followed by XCOFFARFMAG, which is not included in
+ namlen. The contents of the archive member follow; the number of
+ bytes is given in the size field. */
+};
+
+#define SIZEOF_AR_HDR (7 * 12 + 4)
+
+/* The equivalent for the big archive format. */
+
+struct xcoff_ar_hdr_big
+{
+ /* File size not including the header (decimal ASCII string). */
+ char size[20];
+
+ /* File offset of next archive member (decimal ASCII string). */
+ char nextoff[20];
+
+ /* File offset of previous archive member (decimal ASCII string). */
+ char prevoff[20];
+
+ /* File mtime (decimal ASCII string). */
+ char date[12];
+
+ /* File UID (decimal ASCII string). */
+ char uid[12];
+
+ /* File GID (decimal ASCII string). */
+ char gid[12];
+
+ /* File mode (octal ASCII string). */
+ char mode[12];
+
+ /* Length of file name (decimal ASCII string). */
+ char namlen[4];
+
+ /* This structure is followed by the file name. The length of the
+ name is given in the namlen field. If the length of the name is
+ odd, the name is followed by a null byte. The name and optional
+ null byte are followed by XCOFFARFMAG, which is not included in
+ namlen. The contents of the archive member follow; the number of
+ bytes is given in the size field. */
+};
+
+#define SIZEOF_AR_HDR_BIG (3 * 20 + 4 * 12 + 4)
+
+/* We often have to distinguish between the old and big file format.
+ Make it a bit cleaner. We can use `xcoff_ardata' here because the
+ `hdr' member has the same size and position in both formats. */
+#define xcoff_big_format_p(abfd) \
+ (xcoff_ardata (abfd)->magic[1] == 'b')
+
+/* We store a copy of the xcoff_ar_file_hdr in the tdata field of the
+ artdata structure. Similar for the big archive. */
+#define xcoff_ardata(abfd) \
+ ((struct xcoff_ar_file_hdr *) bfd_ardata (abfd)->tdata)
+#define xcoff_ardata_big(abfd) \
+ ((struct xcoff_ar_file_hdr_big *) bfd_ardata (abfd)->tdata)
+
+/* We store a copy of the xcoff_ar_hdr in the arelt_data field of an
+ archive element. Similar for the big archive. */
+#define arch_eltdata(bfd) ((struct areltdata *) ((bfd)->arelt_data))
+#define arch_xhdr(bfd) \
+ ((struct xcoff_ar_hdr *) arch_eltdata (bfd)->arch_header)
+#define arch_xhdr_big(bfd) \
+ ((struct xcoff_ar_hdr_big *) arch_eltdata (bfd)->arch_header)
+
+/* Read in the armap of an XCOFF archive. */
+
+boolean
+_bfd_xcoff_slurp_armap (abfd)
+ bfd *abfd;
+{
+ file_ptr off;
+ size_t namlen;
+ bfd_size_type sz;
+ bfd_byte *contents, *cend;
+ bfd_vma c, i;
+ carsym *arsym;
+ bfd_byte *p;
+
+ if (xcoff_ardata (abfd) == NULL)
+ {
+ bfd_has_map (abfd) = false;
+ return true;
+ }
+
+ if (! xcoff_big_format_p (abfd))
+ {
+ /* This is for the old format. */
+ struct xcoff_ar_hdr hdr;
+
+ off = strtol (xcoff_ardata (abfd)->symoff, (char **) NULL, 10);
+ if (off == 0)
+ {
+ bfd_has_map (abfd) = false;
+ return true;
+ }
+
+ if (bfd_seek (abfd, off, SEEK_SET) != 0)
+ return false;
+
+ /* The symbol table starts with a normal archive header. */
+ if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR, 1, abfd) != SIZEOF_AR_HDR)
+ return false;
+
+ /* Skip the name (normally empty). */
+ namlen = strtol (hdr.namlen, (char **) NULL, 10);
+ if (bfd_seek (abfd, ((namlen + 1) & ~1) + SXCOFFARFMAG, SEEK_CUR) != 0)
+ return false;
+
+ sz = strtol (hdr.size, (char **) NULL, 10);
+
+ /* Read in the entire symbol table. */
+ contents = (bfd_byte *) bfd_alloc (abfd, sz);
+ if (contents == NULL)
+ return false;
+ if (bfd_read ((PTR) contents, 1, sz, abfd) != sz)
+ return false;
+
+ /* The symbol table starts with a four byte count. */
+ c = bfd_h_get_32 (abfd, contents);
+
+ if (c * 4 >= sz)
+ {
+ bfd_set_error (bfd_error_bad_value);
+ return false;
+ }
+
+ bfd_ardata (abfd)->symdefs = ((carsym *)
+ bfd_alloc (abfd, c * sizeof (carsym)));
+ if (bfd_ardata (abfd)->symdefs == NULL)
+ return false;
+
+ /* After the count comes a list of four byte file offsets. */
+ for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 4;
+ i < c;
+ ++i, ++arsym, p += 4)
+ arsym->file_offset = bfd_h_get_32 (abfd, p);
+ }
+ else
+ {
+ /* This is for the new format. */
+ struct xcoff_ar_hdr_big hdr;
+
+ off = strtol (xcoff_ardata_big (abfd)->symoff, (char **) NULL, 10);
+ if (off == 0)
+ {
+ bfd_has_map (abfd) = false;
+ return true;
+ }
+
+ if (bfd_seek (abfd, off, SEEK_SET) != 0)
+ return false;
+
+ /* The symbol table starts with a normal archive header. */
+ if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR_BIG, 1, abfd)
+ != SIZEOF_AR_HDR_BIG)
+ return false;
+
+ /* Skip the name (normally empty). */
+ namlen = strtol (hdr.namlen, (char **) NULL, 10);
+ if (bfd_seek (abfd, ((namlen + 1) & ~1) + SXCOFFARFMAG, SEEK_CUR) != 0)
+ return false;
+
+ /* XXX This actually has to be a call to strtoll (at least on 32-bit
+ machines) since the field width is 20 and there numbers with more
+ than 32 bits can be represented. */
+ sz = strtol (hdr.size, (char **) NULL, 10);
+
+ /* Read in the entire symbol table. */
+ contents = (bfd_byte *) bfd_alloc (abfd, sz);
+ if (contents == NULL)
+ return false;
+ if (bfd_read ((PTR) contents, 1, sz, abfd) != sz)
+ return false;
+
+ /* The symbol table starts with an eight byte count. */
+ c = bfd_h_get_64 (abfd, contents);
+
+ if (c * 8 >= sz)
+ {
+ bfd_set_error (bfd_error_bad_value);
+ return false;
+ }
+
+ bfd_ardata (abfd)->symdefs = ((carsym *)
+ bfd_alloc (abfd, c * sizeof (carsym)));
+ if (bfd_ardata (abfd)->symdefs == NULL)
+ return false;
+
+ /* After the count comes a list of eight byte file offsets. */
+ for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 8;
+ i < c;
+ ++i, ++arsym, p += 8)
+ arsym->file_offset = bfd_h_get_64 (abfd, p);
+ }
+
+ /* After the file offsets come null terminated symbol names. */
+ cend = contents + sz;
+ for (i = 0, arsym = bfd_ardata (abfd)->symdefs;
+ i < c;
+ ++i, ++arsym, p += strlen ((char *) p) + 1)
+ {
+ if (p >= cend)
+ {
+ bfd_set_error (bfd_error_bad_value);
+ return false;
+ }
+ arsym->name = (char *) p;
+ }
+
+ bfd_ardata (abfd)->symdef_count = c;
+ bfd_has_map (abfd) = true;
+
+ return true;
+}
+
+/* See if this is an XCOFF archive. */
+
+const bfd_target *
+_bfd_xcoff_archive_p (abfd)
+ bfd *abfd;
+{
+ char magic[SXCOFFARMAG];
+
+ if (bfd_read ((PTR) magic, SXCOFFARMAG, 1, abfd) != SXCOFFARMAG)
+ {
+ if (bfd_get_error () != bfd_error_system_call)
+ bfd_set_error (bfd_error_wrong_format);
+ return NULL;
+ }
+
+ if (strncmp (magic, XCOFFARMAG, SXCOFFARMAG) != 0
+ && strncmp (magic, XCOFFARMAGBIG, SXCOFFARMAG) != 0)
+ {
+ bfd_set_error (bfd_error_wrong_format);
+ return NULL;
+ }
+
+ /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
+ involves a cast, we can't do it as the left operand of
+ assignment. */
+ abfd->tdata.aout_ar_data =
+ (struct artdata *) bfd_zalloc (abfd, sizeof (struct artdata));
+
+ if (bfd_ardata (abfd) == (struct artdata *) NULL)
+ return NULL;
+
+ bfd_ardata (abfd)->cache = NULL;
+ bfd_ardata (abfd)->archive_head = NULL;
+ bfd_ardata (abfd)->symdefs = NULL;
+ bfd_ardata (abfd)->extended_names = NULL;
+
+ /* Now handle the two formats. */
+ if (magic[1] != 'b')
+ {
+ /* This is the old format. */
+ struct xcoff_ar_file_hdr hdr;
+
+ /* Copy over the magic string. */
+ memcpy (hdr.magic, magic, SXCOFFARMAG);
+
+ /* Now read the rest of the file header. */
+ if (bfd_read ((PTR) &hdr.memoff, SIZEOF_AR_FILE_HDR - SXCOFFARMAG, 1,
+ abfd) != SIZEOF_AR_FILE_HDR - SXCOFFARMAG)
+ {
+ if (bfd_get_error () != bfd_error_system_call)
+ bfd_set_error (bfd_error_wrong_format);
+ return NULL;
+ }
+
+ bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
+ (char **) NULL, 10);
+
+ bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, SIZEOF_AR_FILE_HDR);
+ if (bfd_ardata (abfd)->tdata == NULL)
+ return NULL;
+
+ memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR);
+ }
+ else
+ {
+ /* This is the new format. */
+ struct xcoff_ar_file_hdr_big hdr;
+
+ /* Copy over the magic string. */
+ memcpy (hdr.magic, magic, SXCOFFARMAG);
+
+ /* Now read the rest of the file header. */
+ if (bfd_read ((PTR) &hdr.memoff, SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG, 1,
+ abfd) != SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG)
+ {
+ if (bfd_get_error () != bfd_error_system_call)
+ bfd_set_error (bfd_error_wrong_format);
+ return NULL;
+ }
+
+ /* XXX This actually has to be a call to strtoll (at least on 32-bit
+ machines) since the field width is 20 and there numbers with more
+ than 32 bits can be represented. */
+ bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
+ (char **) NULL, 10);
+
+ bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, SIZEOF_AR_FILE_HDR_BIG);
+ if (bfd_ardata (abfd)->tdata == NULL)
+ return NULL;
+
+ memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR_BIG);
+ }
+
+ if (! _bfd_xcoff_slurp_armap (abfd))
+ {
+ bfd_release (abfd, bfd_ardata (abfd));
+ abfd->tdata.aout_ar_data = (struct artdata *) NULL;
+ return NULL;
+ }
+
+ return abfd->xvec;
+}
+
+/* Read the archive header in an XCOFF archive. */
+
+PTR
+_bfd_xcoff_read_ar_hdr (abfd)
+ bfd *abfd;
+{
+ size_t namlen;
+ struct areltdata *ret;
+
+ ret = (struct areltdata *) bfd_alloc (abfd, sizeof (struct areltdata));
+ if (ret == NULL)
+ return NULL;
+
+ if (! xcoff_big_format_p (abfd))
+ {
+ struct xcoff_ar_hdr hdr;
+ struct xcoff_ar_hdr *hdrp;
+
+ if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR, 1, abfd) != SIZEOF_AR_HDR)
+ {
+ free (ret);
+ return NULL;
+ }
+
+ namlen = strtol (hdr.namlen, (char **) NULL, 10);
+ hdrp = (struct xcoff_ar_hdr *) bfd_alloc (abfd,
+ SIZEOF_AR_HDR + namlen + 1);
+ if (hdrp == NULL)
+ {
+ free (ret);
+ return NULL;
+ }
+ memcpy (hdrp, &hdr, SIZEOF_AR_HDR);
+ if (bfd_read ((char *) hdrp + SIZEOF_AR_HDR, 1, namlen, abfd) != namlen)
+ {
+ free (ret);
+ return NULL;
+ }
+ ((char *) hdrp)[SIZEOF_AR_HDR + namlen] = '\0';
+
+ ret->arch_header = (char *) hdrp;
+ ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
+ ret->filename = (char *) hdrp + SIZEOF_AR_HDR;
+ }
+ else
+ {
+ struct xcoff_ar_hdr_big hdr;
+ struct xcoff_ar_hdr_big *hdrp;
+
+ if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR_BIG, 1, abfd)
+ != SIZEOF_AR_HDR_BIG)
+ {
+ free (ret);
+ return NULL;
+ }
+
+ namlen = strtol (hdr.namlen, (char **) NULL, 10);
+ hdrp = (struct xcoff_ar_hdr_big *) bfd_alloc (abfd,
+ SIZEOF_AR_HDR_BIG
+ + namlen + 1);
+ if (hdrp == NULL)
+ {
+ free (ret);
+ return NULL;
+ }
+ memcpy (hdrp, &hdr, SIZEOF_AR_HDR_BIG);
+ if (bfd_read ((char *) hdrp + SIZEOF_AR_HDR_BIG, 1, namlen, abfd) != namlen)
+ {
+ free (ret);
+ return NULL;
+ }
+ ((char *) hdrp)[SIZEOF_AR_HDR_BIG + namlen] = '\0';
+
+ ret->arch_header = (char *) hdrp;
+ /* XXX This actually has to be a call to strtoll (at least on 32-bit
+ machines) since the field width is 20 and there numbers with more
+ than 32 bits can be represented. */
+ ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
+ ret->filename = (char *) hdrp + SIZEOF_AR_HDR_BIG;
+ }
+
+ /* Skip over the XCOFFARFMAG at the end of the file name. */
+ if (bfd_seek (abfd, (namlen & 1) + SXCOFFARFMAG, SEEK_CUR) != 0)
+ return NULL;
+
+ return (PTR) ret;
+}
+
+/* Open the next element in an XCOFF archive. */
+
+bfd *
+_bfd_xcoff_openr_next_archived_file (archive, last_file)
+ bfd *archive;
+ bfd *last_file;
+{
+ file_ptr filestart;
+
+ if (xcoff_ardata (archive) == NULL)
+ {
+ bfd_set_error (bfd_error_invalid_operation);
+ return NULL;
+ }
+
+ if (! xcoff_big_format_p (archive))
+ {
+ if (last_file == NULL)
+ filestart = bfd_ardata (archive)->first_file_filepos;
+ else
+ filestart = strtol (arch_xhdr (last_file)->nextoff, (char **) NULL,
+ 10);
+
+ if (filestart == 0
+ || filestart == strtol (xcoff_ardata (archive)->memoff,
+ (char **) NULL, 10)
+ || filestart == strtol (xcoff_ardata (archive)->symoff,
+ (char **) NULL, 10))
+ {
+ bfd_set_error (bfd_error_no_more_archived_files);
+ return NULL;
+ }
+ }
+ else
+ {
+ if (last_file == NULL)
+ filestart = bfd_ardata (archive)->first_file_filepos;
+ else
+ /* XXX These actually have to be a calls to strtoll (at least
+ on 32-bit machines) since the fields's width is 20 and
+ there numbers with more than 32 bits can be represented. */
+ filestart = strtol (arch_xhdr_big (last_file)->nextoff, (char **) NULL,
+ 10);
+
+ /* XXX These actually have to be calls to strtoll (at least on 32-bit
+ machines) since the fields's width is 20 and there numbers with more
+ than 32 bits can be represented. */
+ if (filestart == 0
+ || filestart == strtol (xcoff_ardata_big (archive)->memoff,
+ (char **) NULL, 10)
+ || filestart == strtol (xcoff_ardata_big (archive)->symoff,
+ (char **) NULL, 10))
+ {
+ bfd_set_error (bfd_error_no_more_archived_files);
+ return NULL;
+ }
+ }
+
+ return _bfd_get_elt_at_filepos (archive, filestart);
+}
+
+/* Stat an element in an XCOFF archive. */
+
+int
+_bfd_xcoff_generic_stat_arch_elt (abfd, s)
+ bfd *abfd;
+ struct stat *s;
+{
+ if (abfd->arelt_data == NULL)
+ {
+ bfd_set_error (bfd_error_invalid_operation);
+ return -1;
+ }
+
+ if (! xcoff_big_format_p (abfd))
+ {
+ struct xcoff_ar_hdr *hdrp = arch_xhdr (abfd);
+
+ s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
+ s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
+ s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
+ s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
+ s->st_size = arch_eltdata (abfd)->parsed_size;
+ }
+ else
+ {
+ struct xcoff_ar_hdr_big *hdrp = arch_xhdr_big (abfd);
+
+ s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
+ s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
+ s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
+ s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
+ s->st_size = arch_eltdata (abfd)->parsed_size;
+ }
+
+ return 0;
+}
+
+/* Normalize a file name for inclusion in an archive. */
+
+static const char *
+normalize_filename (abfd)
+ bfd *abfd;
+{
+ const char *file;
+ const char *filename;
+
+ file = bfd_get_filename (abfd);
+ filename = strrchr (file, '/');
+ if (filename != NULL)
+ filename++;
+ else
+ filename = file;
+ return filename;
+}
+
+/* Write out an XCOFF armap. */
+
+static boolean
+xcoff_write_armap_old (abfd, elength, map, orl_count, stridx)
+ bfd *abfd;
+ unsigned int elength ATTRIBUTE_UNUSED;
+ struct orl *map;
+ unsigned int orl_count;
+ int stridx;
+{
+ struct xcoff_ar_hdr hdr;
+ char *p;
+ unsigned char buf[4];
+ bfd *sub;
+ file_ptr fileoff;
+ unsigned int i;
+
+ memset (&hdr, 0, sizeof hdr);
+ sprintf (hdr.size, "%ld", (long) (4 + orl_count * 4 + stridx));
+ sprintf (hdr.nextoff, "%d", 0);
+ memcpy (hdr.prevoff, xcoff_ardata (abfd)->memoff, 12);
+ sprintf (hdr.date, "%d", 0);
+ sprintf (hdr.uid, "%d", 0);
+ sprintf (hdr.gid, "%d", 0);
+ sprintf (hdr.mode, "%d", 0);
+ sprintf (hdr.namlen, "%d", 0);
+
+ /* We need spaces, not null bytes, in the header. */
+ for (p = (char *) &hdr; p < (char *) &hdr + SIZEOF_AR_HDR; p++)
+ if (*p == '\0')
+ *p = ' ';
+
+ if (bfd_write ((PTR) &hdr, SIZEOF_AR_HDR, 1, abfd) != SIZEOF_AR_HDR
+ || bfd_write (XCOFFARFMAG, 1, SXCOFFARFMAG, abfd) != SXCOFFARFMAG)
+ return false;
+
+ bfd_h_put_32 (abfd, orl_count, buf);
+ if (bfd_write (buf, 1, 4, abfd) != 4)
+ return false;
+
+ sub = abfd->archive_head;
+ fileoff = SIZEOF_AR_FILE_HDR;
+ i = 0;
+ while (sub != NULL && i < orl_count)
+ {
+ size_t namlen;
+
+ while (((bfd *) (map[i]).pos) == sub)
+ {
+ bfd_h_put_32 (abfd, fileoff, buf);
+ if (bfd_write (buf, 1, 4, abfd) != 4)
+ return false;
+ ++i;
+ }
+ namlen = strlen (normalize_filename (sub));
+ namlen = (namlen + 1) &~ 1;
+ fileoff += (SIZEOF_AR_HDR
+ + namlen
+ + SXCOFFARFMAG
+ + arelt_size (sub));
+ fileoff = (fileoff + 1) &~ 1;
+ sub = sub->next;
+ }
+
+ for (i = 0; i < orl_count; i++)
+ {
+ const char *name;
+ size_t namlen;
+
+ name = *map[i].name;
+ namlen = strlen (name);
+ if (bfd_write (name, 1, namlen + 1, abfd) != namlen + 1)
+ return false;
+ }
+
+ if ((stridx & 1) != 0)
+ {
+ char b;
+
+ b = '\0';
+ if (bfd_write (&b, 1, 1, abfd) != 1)
+ return false;
+ }
+
+ return true;
+}
+
+/* Write a single armap in the big format. */
+static boolean
+xcoff_write_one_armap_big (abfd, map, orl_count, orl_ccount, stridx, bits64,
+ prevoff, nextoff)
+ bfd *abfd;
+ struct orl *map;
+ unsigned int orl_count;
+ unsigned int orl_ccount;
+ unsigned int stridx;
+ int bits64;
+ const char *prevoff;
+ char *nextoff;
+{
+ struct xcoff_ar_hdr_big hdr;
+ char *p;
+ unsigned char buf[4];
+ const bfd_arch_info_type *arch_info = NULL;
+ bfd *sub;
+ file_ptr fileoff;
+ bfd *object_bfd;
+ unsigned int i;
+
+ memset (&hdr, 0, sizeof hdr);
+ /* XXX This call actually should use %lld (at least on 32-bit
+ machines) since the fields's width is 20 and there numbers with
+ more than 32 bits can be represented. */
+ sprintf (hdr.size, "%ld", (long) (4 + orl_ccount * 4 + stridx));
+ if (bits64)
+ sprintf (hdr.nextoff, "%d", 0);
+ else
+ sprintf (hdr.nextoff, "%ld", (strtol (prevoff, (char **) NULL, 10)
+ + 4 + orl_ccount * 4 + stridx));
+ memcpy (hdr.prevoff, prevoff, sizeof (hdr.prevoff));
+ sprintf (hdr.date, "%d", 0);
+ sprintf (hdr.uid, "%d", 0);
+ sprintf (hdr.gid, "%d", 0);
+ sprintf (hdr.mode, "%d", 0);
+ sprintf (hdr.namlen, "%d", 0);
+
+ /* We need spaces, not null bytes, in the header. */
+ for (p = (char *) &hdr; p < (char *) &hdr + SIZEOF_AR_HDR_BIG; p++)
+ if (*p == '\0')
+ *p = ' ';
+
+ memcpy (nextoff, hdr.nextoff, sizeof (hdr.nextoff));
+
+ if (bfd_write ((PTR) &hdr, SIZEOF_AR_HDR_BIG, 1, abfd) != SIZEOF_AR_HDR_BIG
+ || bfd_write (XCOFFARFMAG, 1, SXCOFFARFMAG, abfd) != SXCOFFARFMAG)
+ return false;
+
+ bfd_h_put_32 (abfd, orl_ccount, buf);
+ if (bfd_write (buf, 1, 4, abfd) != 4)
+ return false;
+
+ sub = abfd->archive_head;
+ fileoff = SIZEOF_AR_FILE_HDR_BIG;
+ i = 0;
+ while (sub != NULL && i < orl_count)
+ {
+ size_t namlen;
+
+ if ((bfd_arch_bits_per_address ((bfd *) map[i].pos) == 64) == bits64)
+ while (((bfd *) (map[i]).pos) == sub)
+ {
+ bfd_h_put_32 (abfd, fileoff, buf);
+ if (bfd_write (buf, 1, 4, abfd) != 4)
+ return false;
+ i++;
+ }
+ else
+ while (((bfd *) (map[i]).pos) == sub)
+ i++;
+
+ namlen = strlen (normalize_filename (sub));
+ namlen = (namlen + 1) &~ 1;
+ fileoff += (SIZEOF_AR_HDR_BIG
+ + namlen
+ + SXCOFFARFMAG
+ + arelt_size (sub));
+ fileoff = (fileoff + 1) &~ 1;
+ sub = sub->next;
+ }
+
+ object_bfd = NULL;
+ for (i = 0; i < orl_count; i++)
+ {
+ const char *name;
+ size_t namlen;
+ bfd *ob = (bfd *)map[i].pos;
+
+ if (ob != object_bfd)
+ arch_info = bfd_get_arch_info (ob);
+
+ if (arch_info && (arch_info->bits_per_address == 64) != bits64)
+ continue;
+
+ name = *map[i].name;
+ namlen = strlen (name);
+ if (bfd_write (name, 1, namlen + 1, abfd) != namlen + 1)
+ return false;
+ }
+
+ if ((stridx & 1) != 0)
+ {
+ char b;
+
+ b = '\0';
+ if (bfd_write (&b, 1, 1, abfd) != 1)
+ return false;
+ }
+
+ return true;
+}
+
+static boolean
+xcoff_write_armap_big (abfd, elength, map, orl_count, stridx)
+ bfd *abfd;
+ unsigned int elength ATTRIBUTE_UNUSED;
+ struct orl *map;
+ unsigned int orl_count;
+ int stridx;
+{
+ unsigned int i;
+ unsigned int orl_count_32, orl_count_64;
+ unsigned int stridx_32, stridx_64;
+ const bfd_arch_info_type *arch_info = NULL;
+ bfd *object_bfd;
+
+ /* First, we look through the symbols and work out which are
+ from 32-bit objects and which from 64-bit ones. */
+ orl_count_32 = 0;
+ orl_count_64 = 0;
+ stridx_32 = 0;
+ stridx_64 = 0;
+ object_bfd = NULL;
+ for (i = 0; i < orl_count; i++)
+ {
+ bfd *ob = (bfd *)map[i].pos;
+ unsigned int len;
+ if (ob != object_bfd)
+ arch_info = bfd_get_arch_info (ob);
+ len = strlen (*map[i].name) + 1;
+ if (arch_info && arch_info->bits_per_address == 64)
+ {
+ orl_count_64++;
+ stridx_64 += len;
+ }
+ else
+ {
+ orl_count_32++;
+ stridx_32 += len;
+ }
+ object_bfd = ob;
+ }
+ /* A quick sanity check... */
+ BFD_ASSERT (orl_count_64 + orl_count_32 == orl_count);
+ BFD_ASSERT (stridx_64 + stridx_32 == stridx);
+
+ /* Now write out each map. */
+ if (! xcoff_write_one_armap_big (abfd, map, orl_count, orl_count_32,
+ stridx_32, false,
+ xcoff_ardata_big (abfd)->memoff,
+ xcoff_ardata_big (abfd)->symoff))
+ return false;
+ if (! xcoff_write_one_armap_big (abfd, map, orl_count, orl_count_64,
+ stridx_64, true,
+ xcoff_ardata_big (abfd)->symoff,
+ xcoff_ardata_big (abfd)->symoff64))
+ return false;
+
+ return true;
+}
+
+boolean
+_bfd_xcoff_write_armap (abfd, elength, map, orl_count, stridx)
+ bfd *abfd;
+ unsigned int elength ATTRIBUTE_UNUSED;
+ struct orl *map;
+ unsigned int orl_count;
+ int stridx;
+{
+ if (! xcoff_big_format_p (abfd))
+ return xcoff_write_armap_old (abfd, elength, map, orl_count, stridx);
+ else
+ return xcoff_write_armap_big (abfd, elength, map, orl_count, stridx);
+}
+
+/* Write out an XCOFF archive. We always write an entire archive,
+ rather than fussing with the freelist and so forth. */
+
+static boolean
+xcoff_write_archive_contents_old (abfd)
+ bfd *abfd;
+{
+ struct xcoff_ar_file_hdr fhdr;
+ size_t count;
+ size_t total_namlen;
+ file_ptr *offsets;
+ boolean makemap;
+ boolean hasobjects;
+ file_ptr prevoff, nextoff;
+ bfd *sub;
+ unsigned int i;
+ struct xcoff_ar_hdr ahdr;
+ bfd_size_type size;
+ char *p;
+ char decbuf[13];
+
+ memset (&fhdr, 0, sizeof fhdr);
+ strncpy (fhdr.magic, XCOFFARMAG, SXCOFFARMAG);
+ sprintf (fhdr.firstmemoff, "%d", SIZEOF_AR_FILE_HDR);
+ sprintf (fhdr.freeoff, "%d", 0);
+
+ count = 0;
+ total_namlen = 0;
+ for (sub = abfd->archive_head; sub != NULL; sub = sub->next)
+ {
+ ++count;
+ total_namlen += strlen (normalize_filename (sub)) + 1;
+ }
+ offsets = (file_ptr *) bfd_alloc (abfd, count * sizeof (file_ptr));
+ if (offsets == NULL)
+ return false;
+
+ if (bfd_seek (abfd, SIZEOF_AR_FILE_HDR, SEEK_SET) != 0)
+ return false;
+
+ makemap = bfd_has_map (abfd);
+ hasobjects = false;
+ prevoff = 0;
+ nextoff = SIZEOF_AR_FILE_HDR;
+ for (sub = abfd->archive_head, i = 0; sub != NULL; sub = sub->next, i++)
+ {
+ const char *name;
+ size_t namlen;
+ struct xcoff_ar_hdr *ahdrp;
+ bfd_size_type remaining;
+
+ if (makemap && ! hasobjects)
+ {
+ if (bfd_check_format (sub, bfd_object))
+ hasobjects = true;
+ }
+
+ name = normalize_filename (sub);
+ namlen = strlen (name);
+
+ if (sub->arelt_data != NULL)
+ ahdrp = arch_xhdr (sub);
+ else
+ ahdrp = NULL;
+
+ if (ahdrp == NULL)
+ {
+ struct stat s;
+
+ memset (&ahdr, 0, sizeof ahdr);
+ ahdrp = &ahdr;
+ if (stat (bfd_get_filename (sub), &s) != 0)
+ {
+ bfd_set_error (bfd_error_system_call);
+ return false;
+ }
+
+ sprintf (ahdrp->size, "%ld", (long) s.st_size);
+ sprintf (ahdrp->date, "%ld", (long) s.st_mtime);
+ sprintf (ahdrp->uid, "%ld", (long) s.st_uid);
+ sprintf (ahdrp->gid, "%ld", (long) s.st_gid);
+ sprintf (ahdrp->mode, "%o", (unsigned int) s.st_mode);
+
+ if (sub->arelt_data == NULL)
+ {
+ sub->arelt_data = bfd_alloc (sub, sizeof (struct areltdata));
+ if (sub->arelt_data == NULL)
+ return false;
+ }
+
+ arch_eltdata (sub)->parsed_size = s.st_size;
+ }
+
+ sprintf (ahdrp->prevoff, "%ld", (long) prevoff);
+ sprintf (ahdrp->namlen, "%ld", (long) namlen);
+
+ /* If the length of the name is odd, we write out the null byte
+ after the name as well. */
+ namlen = (namlen + 1) &~ 1;
+
+ remaining = arelt_size (sub);
+ size = (SIZEOF_AR_HDR
+ + namlen
+ + SXCOFFARFMAG
+ + remaining);
+
+ BFD_ASSERT (nextoff == bfd_tell (abfd));
+
+ offsets[i] = nextoff;
+
+ prevoff = nextoff;
+ nextoff += size + (size & 1);
+
+ sprintf (ahdrp->nextoff, "%ld", (long) nextoff);
+
+ /* We need spaces, not null bytes, in the header. */
+ for (p = (char *) ahdrp; p < (char *) ahdrp + SIZEOF_AR_HDR; p++)
+ if (*p == '\0')
+ *p = ' ';
+
+ if (bfd_write ((PTR) ahdrp, 1, SIZEOF_AR_HDR, abfd) != SIZEOF_AR_HDR
+ || bfd_write ((PTR) name, 1, namlen, abfd) != namlen
+ || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd)
+ != SXCOFFARFMAG))
+ return false;
+
+ if (bfd_seek (sub, (file_ptr) 0, SEEK_SET) != 0)
+ return false;
+ while (remaining != 0)
+ {
+ bfd_size_type amt;
+ bfd_byte buffer[DEFAULT_BUFFERSIZE];
+
+ amt = sizeof buffer;
+ if (amt > remaining)
+ amt = remaining;
+ if (bfd_read (buffer, 1, amt, sub) != amt
+ || bfd_write (buffer, 1, amt, abfd) != amt)
+ return false;
+ remaining -= amt;
+ }
+
+ if ((size & 1) != 0)
+ {
+ bfd_byte b;
+
+ b = '\0';
+ if (bfd_write (&b, 1, 1, abfd) != 1)
+ return false;
+ }
+ }
+
+ sprintf (fhdr.lastmemoff, "%ld", (long) prevoff);
+
+ /* Write out the member table. */
+
+ BFD_ASSERT (nextoff == bfd_tell (abfd));
+ sprintf (fhdr.memoff, "%ld", (long) nextoff);
+
+ memset (&ahdr, 0, sizeof ahdr);
+ sprintf (ahdr.size, "%ld", (long) (12 + count * 12 + total_namlen));
+ sprintf (ahdr.prevoff, "%ld", (long) prevoff);
+ sprintf (ahdr.date, "%d", 0);
+ sprintf (ahdr.uid, "%d", 0);
+ sprintf (ahdr.gid, "%d", 0);
+ sprintf (ahdr.mode, "%d", 0);
+ sprintf (ahdr.namlen, "%d", 0);
+
+ size = (SIZEOF_AR_HDR
+ + 12
+ + count * 12
+ + total_namlen
+ + SXCOFFARFMAG);
+
+ prevoff = nextoff;
+ nextoff += size + (size & 1);
+
+ if (makemap && hasobjects)
+ sprintf (ahdr.nextoff, "%ld", (long) nextoff);
+ else
+ sprintf (ahdr.nextoff, "%d", 0);
+
+ /* We need spaces, not null bytes, in the header. */
+ for (p = (char *) &ahdr; p < (char *) &ahdr + SIZEOF_AR_HDR; p++)
+ if (*p == '\0')
+ *p = ' ';
+
+ if (bfd_write ((PTR) &ahdr, 1, SIZEOF_AR_HDR, abfd) != SIZEOF_AR_HDR
+ || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd)
+ != SXCOFFARFMAG))
+ return false;
+
+ sprintf (decbuf, "%-12ld", (long) count);
+ if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12)
+ return false;
+ for (i = 0; i < count; i++)
+ {
+ sprintf (decbuf, "%-12ld", (long) offsets[i]);
+ if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12)
+ return false;
+ }
+ for (sub = abfd->archive_head; sub != NULL; sub = sub->next)
+ {
+ const char *name;
+ size_t namlen;
+
+ name = normalize_filename (sub);
+ namlen = strlen (name);
+ if (bfd_write ((PTR) name, 1, namlen + 1, abfd) != namlen + 1)
+ return false;
+ }
+ if ((size & 1) != 0)
+ {
+ bfd_byte b;
+
+ b = '\0';
+ if (bfd_write ((PTR) &b, 1, 1, abfd) != 1)
+ return false;
+ }
+
+ /* Write out the armap, if appropriate. */
+
+ if (! makemap || ! hasobjects)
+ sprintf (fhdr.symoff, "%d", 0);
+ else
+ {
+ BFD_ASSERT (nextoff == bfd_tell (abfd));
+ sprintf (fhdr.symoff, "%ld", (long) nextoff);
+ bfd_ardata (abfd)->tdata = (PTR) &fhdr;
+ if (! _bfd_compute_and_write_armap (abfd, 0))
+ return false;
+ }
+
+ /* Write out the archive file header. */
+
+ /* We need spaces, not null bytes, in the header. */
+ for (p = (char *) &fhdr; p < (char *) &fhdr + SIZEOF_AR_FILE_HDR; p++)
+ if (*p == '\0')
+ *p = ' ';
+
+ if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
+ || (bfd_write ((PTR) &fhdr, SIZEOF_AR_FILE_HDR, 1, abfd) !=
+ SIZEOF_AR_FILE_HDR))
+ return false;
+
+ return true;
+}
+
+static boolean
+xcoff_write_archive_contents_big (abfd)
+ bfd *abfd;
+{
+ struct xcoff_ar_file_hdr_big fhdr;
+ size_t count;
+ size_t total_namlen;
+ file_ptr *offsets;
+ boolean makemap;
+ boolean hasobjects;
+ file_ptr prevoff, nextoff;
+ bfd *sub;
+ unsigned int i;
+ struct xcoff_ar_hdr_big ahdr;
+ bfd_size_type size;
+ char *p;
+ char decbuf[13];
+
+ memset (&fhdr, 0, sizeof fhdr);
+ strncpy (fhdr.magic, XCOFFARMAGBIG, SXCOFFARMAG);
+ sprintf (fhdr.firstmemoff, "%d", SIZEOF_AR_FILE_HDR_BIG);
+ sprintf (fhdr.freeoff, "%d", 0);
+
+ count = 0;
+ total_namlen = 0;
+ for (sub = abfd->archive_head; sub != NULL; sub = sub->next)
+ {
+ ++count;
+ total_namlen += strlen (normalize_filename (sub)) + 1;
+ }
+ offsets = (file_ptr *) bfd_alloc (abfd, count * sizeof (file_ptr));
+ if (offsets == NULL)
+ return false;
+
+ if (bfd_seek (abfd, SIZEOF_AR_FILE_HDR_BIG, SEEK_SET) != 0)
+ return false;
+
+ makemap = bfd_has_map (abfd);
+ hasobjects = false;
+ prevoff = 0;
+ nextoff = SIZEOF_AR_FILE_HDR_BIG;
+ for (sub = abfd->archive_head, i = 0; sub != NULL; sub = sub->next, i++)
+ {
+ const char *name;
+ size_t namlen;
+ struct xcoff_ar_hdr_big *ahdrp;
+ bfd_size_type remaining;
+
+ if (makemap && ! hasobjects)
+ {
+ if (bfd_check_format (sub, bfd_object))
+ hasobjects = true;
+ }
+
+ name = normalize_filename (sub);
+ namlen = strlen (name);
+
+ if (sub->arelt_data != NULL)
+ ahdrp = arch_xhdr_big (sub);
+ else
+ ahdrp = NULL;
+
+ if (ahdrp == NULL)
+ {
+ struct stat s;
+
+ memset (&ahdr, 0, sizeof ahdr);
+ ahdrp = &ahdr;
+ /* XXX This should actually be a call to stat64 (at least on
+ 32-bit machines). */
+ if (stat (bfd_get_filename (sub), &s) != 0)
+ {
+ bfd_set_error (bfd_error_system_call);
+ return false;
+ }
+
+ /* XXX This call actually should use %lld (at least on 32-bit
+ machines) since the fields's width is 20 and there numbers with
+ more than 32 bits can be represented. */
+ sprintf (ahdrp->size, "%ld", (long) s.st_size);
+ sprintf (ahdrp->date, "%ld", (long) s.st_mtime);
+ sprintf (ahdrp->uid, "%ld", (long) s.st_uid);
+ sprintf (ahdrp->gid, "%ld", (long) s.st_gid);
+ sprintf (ahdrp->mode, "%o", (unsigned int) s.st_mode);
+
+ if (sub->arelt_data == NULL)
+ {
+ sub->arelt_data = bfd_alloc (sub, sizeof (struct areltdata));
+ if (sub->arelt_data == NULL)
+ return false;
+ }
+
+ arch_eltdata (sub)->parsed_size = s.st_size;
+ }
+
+ /* XXX These calls actually should use %lld (at least on 32-bit
+ machines) since the fields's width is 20 and there numbers with
+ more than 32 bits can be represented. */
+ sprintf (ahdrp->prevoff, "%ld", (long) prevoff);
+ sprintf (ahdrp->namlen, "%ld", (long) namlen);
+
+ /* If the length of the name is odd, we write out the null byte
+ after the name as well. */
+ namlen = (namlen + 1) &~ 1;
+
+ remaining = arelt_size (sub);
+ size = (SIZEOF_AR_HDR_BIG
+ + namlen
+ + SXCOFFARFMAG
+ + remaining);
+
+ BFD_ASSERT (nextoff == bfd_tell (abfd));
+
+ offsets[i] = nextoff;
+
+ prevoff = nextoff;
+ nextoff += size + (size & 1);
+
+ sprintf (ahdrp->nextoff, "%ld", (long) nextoff);
+
+ /* We need spaces, not null bytes, in the header. */
+ for (p = (char *) ahdrp; p < (char *) ahdrp + SIZEOF_AR_HDR_BIG; p++)
+ if (*p == '\0')
+ *p = ' ';
+
+ if (bfd_write ((PTR) ahdrp, 1, SIZEOF_AR_HDR_BIG, abfd)
+ != SIZEOF_AR_HDR_BIG
+ || bfd_write ((PTR) name, 1, namlen, abfd) != namlen
+ || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd)
+ != SXCOFFARFMAG))
+ return false;
+
+ if (bfd_seek (sub, (file_ptr) 0, SEEK_SET) != 0)
+ return false;
+ while (remaining != 0)
+ {
+ bfd_size_type amt;
+ bfd_byte buffer[DEFAULT_BUFFERSIZE];
+
+ amt = sizeof buffer;
+ if (amt > remaining)
+ amt = remaining;
+ if (bfd_read (buffer, 1, amt, sub) != amt
+ || bfd_write (buffer, 1, amt, abfd) != amt)
+ return false;
+ remaining -= amt;
+ }
+
+ if ((size & 1) != 0)
+ {
+ bfd_byte b;
+
+ b = '\0';
+ if (bfd_write (&b, 1, 1, abfd) != 1)
+ return false;
+ }
+ }
+
+ /* XXX This call actually should use %lld (at least on 32-bit
+ machines) since the fields's width is 20 and there numbers with
+ more than 32 bits can be represented. */
+ sprintf (fhdr.lastmemoff, "%ld", (long) prevoff);
+
+ /* Write out the member table. */
+
+ BFD_ASSERT (nextoff == bfd_tell (abfd));
+ /* XXX This call actually should use %lld (at least on 32-bit
+ machines) since the fields's width is 20 and there numbers with
+ more than 32 bits can be represented. */
+ sprintf (fhdr.memoff, "%ld", (long) nextoff);
+
+ memset (&ahdr, 0, sizeof ahdr);
+ /* XXX The next two calls actually should use %lld (at least on 32-bit
+ machines) since the fields's width is 20 and there numbers with
+ more than 32 bits can be represented. */
+ sprintf (ahdr.size, "%ld", (long) (12 + count * 12 + total_namlen));
+ sprintf (ahdr.prevoff, "%ld", (long) prevoff);
+ sprintf (ahdr.date, "%d", 0);
+ sprintf (ahdr.uid, "%d", 0);
+ sprintf (ahdr.gid, "%d", 0);
+ sprintf (ahdr.mode, "%d", 0);
+ sprintf (ahdr.namlen, "%d", 0);
+
+ size = (SIZEOF_AR_HDR_BIG
+ + 12
+ + count * 12
+ + total_namlen
+ + SXCOFFARFMAG);
+
+ prevoff = nextoff;
+ nextoff += size + (size & 1);
+
+ if (makemap && hasobjects)
+ /* XXX This call actually should use %lld (at least on 32-bit
+ machines) since the fields's width is 20 and there numbers with
+ more than 32 bits can be represented. */
+ sprintf (ahdr.nextoff, "%ld", (long) nextoff);
+ else
+ sprintf (ahdr.nextoff, "%d", 0);
+
+ /* We need spaces, not null bytes, in the header. */
+ for (p = (char *) &ahdr; p < (char *) &ahdr + SIZEOF_AR_HDR_BIG; p++)
+ if (*p == '\0')
+ *p = ' ';
+
+ if (bfd_write ((PTR) &ahdr, 1, SIZEOF_AR_HDR_BIG, abfd) != SIZEOF_AR_HDR_BIG
+ || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd)
+ != SXCOFFARFMAG))
+ return false;
+
+ sprintf (decbuf, "%-12ld", (long) count);
+ if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12)
+ return false;
+ for (i = 0; i < count; i++)
+ {
+ sprintf (decbuf, "%-12ld", (long) offsets[i]);
+ if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12)
+ return false;
+ }
+ for (sub = abfd->archive_head; sub != NULL; sub = sub->next)
+ {
+ const char *name;
+ size_t namlen;
+
+ name = normalize_filename (sub);
+ namlen = strlen (name);
+ if (bfd_write ((PTR) name, 1, namlen + 1, abfd) != namlen + 1)
+ return false;
+ }
+ if ((size & 1) != 0)
+ {
+ bfd_byte b;
+
+ b = '\0';
+ if (bfd_write ((PTR) &b, 1, 1, abfd) != 1)
+ return false;
+ }
+
+ /* Write out the armap, if appropriate. */
+
+ if (! makemap || ! hasobjects)
+ sprintf (fhdr.symoff, "%d", 0);
+ else
+ {
+ BFD_ASSERT (nextoff == bfd_tell (abfd));
+ /* XXX This call actually should use %lld (at least on 32-bit
+ machines) since the fields's width is 20 and there numbers with
+ more than 32 bits can be represented. */
+ bfd_ardata (abfd)->tdata = (PTR) &fhdr;
+ if (! _bfd_compute_and_write_armap (abfd, 0))
+ return false;
+ }
+
+ /* Write out the archive file header. */
+
+ /* We need spaces, not null bytes, in the header. */
+ for (p = (char *) &fhdr; p < (char *) &fhdr + SIZEOF_AR_FILE_HDR_BIG; p++)
+ if (*p == '\0')
+ *p = ' ';
+
+ if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
+ || (bfd_write ((PTR) &fhdr, SIZEOF_AR_FILE_HDR_BIG, 1, abfd) !=
+ SIZEOF_AR_FILE_HDR_BIG))
+ return false;
+
+ return true;
+}
+
+boolean
+_bfd_xcoff_write_archive_contents (abfd)
+ bfd *abfd;
+{
+ if (! xcoff_big_format_p (abfd))
+ return xcoff_write_archive_contents_old (abfd);
+ else
+ return xcoff_write_archive_contents_big (abfd);
+}
+
+/* We can't use the usual coff_sizeof_headers routine, because AIX
+ always uses an a.out header. */
+
+int
+_bfd_xcoff_sizeof_headers (abfd, reloc)
+ bfd *abfd;
+ boolean reloc ATTRIBUTE_UNUSED;
+{
+ int size;
+
+ size = FILHSZ;
+ if (xcoff_data (abfd)->full_aouthdr)
+ size += AOUTSZ;
+ else
+ size += SMALL_AOUTSZ;
+ size += abfd->section_count * SCNHSZ;
+ return size;
+}
diff --git a/contrib/binutils/bfd/cpu-ia64-opc.c b/contrib/binutils/bfd/cpu-ia64-opc.c
new file mode 100644
index 0000000..8c22942
--- /dev/null
+++ b/contrib/binutils/bfd/cpu-ia64-opc.c
@@ -0,0 +1,589 @@
+/* Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
+
+This file is part of BFD, the Binary File Descriptor library.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+/* Logically, this code should be part of libopcode but since some of
+ the operand insertion/extraction functions help bfd to implement
+ relocations, this code is included as part of elf64-ia64.c. This
+ avoids circular dependencies between libopcode and libbfd and also
+ obviates the need for applications to link in libopcode when all
+ they really want is libbfd.
+
+ --davidm Mon Apr 13 22:14:02 1998 */
+
+#include "../opcodes/ia64-opc.h"
+
+#define NELEMS(a) ((int) (sizeof (a) / sizeof ((a)[0])))
+
+static const char*
+ins_rsvd (const struct ia64_operand *self ATTRIBUTE_UNUSED,
+ ia64_insn value ATTRIBUTE_UNUSED, ia64_insn *code ATTRIBUTE_UNUSED)
+{
+ return "internal error---this shouldn't happen";
+}
+
+static const char*
+ext_rsvd (const struct ia64_operand *self ATTRIBUTE_UNUSED,
+ ia64_insn code ATTRIBUTE_UNUSED, ia64_insn *valuep ATTRIBUTE_UNUSED)
+{
+ return "internal error---this shouldn't happen";
+}
+
+static const char*
+ins_const (const struct ia64_operand *self ATTRIBUTE_UNUSED,
+ ia64_insn value ATTRIBUTE_UNUSED, ia64_insn *code ATTRIBUTE_UNUSED)
+{
+ return 0;
+}
+
+static const char*
+ext_const (const struct ia64_operand *self ATTRIBUTE_UNUSED,
+ ia64_insn code ATTRIBUTE_UNUSED, ia64_insn *valuep ATTRIBUTE_UNUSED)
+{
+ return 0;
+}
+
+static const char*
+ins_reg (const struct ia64_operand *self, ia64_insn value, ia64_insn *code)
+{
+ if (value >= 1u << self->field[0].bits)
+ return "register number out of range";
+
+ *code |= value << self->field[0].shift;
+ return 0;
+}
+
+static const char*
+ext_reg (const struct ia64_operand *self, ia64_insn code, ia64_insn *valuep)
+{
+ *valuep = ((code >> self->field[0].shift)
+ & ((1u << self->field[0].bits) - 1));
+ return 0;
+}
+
+static const char*
+ins_immu (const struct ia64_operand *self, ia64_insn value, ia64_insn *code)
+{
+ ia64_insn new = 0;
+ int i;
+
+ for (i = 0; i < NELEMS (self->field) && self->field[i].bits; ++i)
+ {
+ new |= ((value & ((((ia64_insn) 1) << self->field[i].bits) - 1))
+ << self->field[i].shift);
+ value >>= self->field[i].bits;
+ }
+ if (value)
+ return "integer operand out of range";
+
+ *code |= new;
+ return 0;
+}
+
+static const char*
+ext_immu (const struct ia64_operand *self, ia64_insn code, ia64_insn *valuep)
+{
+ BFD_HOST_U_64_BIT value = 0;
+ int i, bits = 0, total = 0;
+
+ for (i = 0; i < NELEMS (self->field) && self->field[i].bits; ++i)
+ {
+ bits = self->field[i].bits;
+ value |= ((code >> self->field[i].shift)
+ & ((((BFD_HOST_U_64_BIT) 1) << bits) - 1)) << total;
+ total += bits;
+ }
+ *valuep = value;
+ return 0;
+}
+
+static const char*
+ins_immus8 (const struct ia64_operand *self, ia64_insn value, ia64_insn *code)
+{
+ if (value & 0x7)
+ return "value not an integer multiple of 8";
+ return ins_immu (self, value >> 3, code);
+}
+
+static const char*
+ext_immus8 (const struct ia64_operand *self, ia64_insn code, ia64_insn *valuep)
+{
+ const char *result;
+
+ result = ext_immu (self, code, valuep);
+ if (result)
+ return result;
+
+ *valuep = *valuep << 3;
+ return 0;
+}
+
+static const char*
+ins_imms_scaled (const struct ia64_operand *self, ia64_insn value,
+ ia64_insn *code, int scale)
+{
+ BFD_HOST_64_BIT svalue = value, sign_bit = 0;
+ ia64_insn new = 0;
+ int i;
+
+ svalue >>= scale;
+
+ for (i = 0; i < NELEMS (self->field) && self->field[i].bits; ++i)
+ {
+ new |= ((svalue & ((((ia64_insn) 1) << self->field[i].bits) - 1))
+ << self->field[i].shift);
+ sign_bit = (svalue >> (self->field[i].bits - 1)) & 1;
+ svalue >>= self->field[i].bits;
+ }
+ if ((!sign_bit && svalue != 0) || (sign_bit && svalue != -1))
+ return "integer operand out of range";
+
+ *code |= new;
+ return 0;
+}
+
+static const char*
+ext_imms_scaled (const struct ia64_operand *self, ia64_insn code,
+ ia64_insn *valuep, int scale)
+{
+ int i, bits = 0, total = 0, shift;
+ BFD_HOST_64_BIT val = 0;
+
+ for (i = 0; i < NELEMS (self->field) && self->field[i].bits; ++i)
+ {
+ bits = self->field[i].bits;
+ val |= ((code >> self->field[i].shift)
+ & ((((BFD_HOST_U_64_BIT) 1) << bits) - 1)) << total;
+ total += bits;
+ }
+ /* sign extend: */
+ shift = 8*sizeof (val) - total;
+ val = (val << shift) >> shift;
+
+ *valuep = (val << scale);
+ return 0;
+}
+
+static const char*
+ins_imms (const struct ia64_operand *self, ia64_insn value, ia64_insn *code)
+{
+ return ins_imms_scaled (self, value, code, 0);
+}
+
+static const char*
+ins_immsu4 (const struct ia64_operand *self, ia64_insn value, ia64_insn *code)
+{
+ if (value == (BFD_HOST_U_64_BIT) 0x100000000)
+ value = 0;
+ else
+ value = (((BFD_HOST_64_BIT)value << 32) >> 32);
+
+ return ins_imms_scaled (self, value, code, 0);
+}
+
+static const char*
+ext_imms (const struct ia64_operand *self, ia64_insn code, ia64_insn *valuep)
+{
+ return ext_imms_scaled (self, code, valuep, 0);
+}
+
+static const char*
+ins_immsm1 (const struct ia64_operand *self, ia64_insn value, ia64_insn *code)
+{
+ --value;
+ return ins_imms_scaled (self, value, code, 0);
+}
+
+static const char*
+ins_immsm1u4 (const struct ia64_operand *self, ia64_insn value,
+ ia64_insn *code)
+{
+ if (value == (BFD_HOST_U_64_BIT) 0x100000000)
+ value = 0;
+ else
+ value = (((BFD_HOST_64_BIT)value << 32) >> 32);
+
+ --value;
+ return ins_imms_scaled (self, value, code, 0);
+}
+
+static const char*
+ext_immsm1 (const struct ia64_operand *self, ia64_insn code, ia64_insn *valuep)
+{
+ const char *res = ext_imms_scaled (self, code, valuep, 0);
+
+ ++*valuep;
+ return res;
+}
+
+static const char*
+ins_imms1 (const struct ia64_operand *self, ia64_insn value, ia64_insn *code)
+{
+ return ins_imms_scaled (self, value, code, 1);
+}
+
+static const char*
+ext_imms1 (const struct ia64_operand *self, ia64_insn code, ia64_insn *valuep)
+{
+ return ext_imms_scaled (self, code, valuep, 1);
+}
+
+static const char*
+ins_imms4 (const struct ia64_operand *self, ia64_insn value, ia64_insn *code)
+{
+ return ins_imms_scaled (self, value, code, 4);
+}
+
+static const char*
+ext_imms4 (const struct ia64_operand *self, ia64_insn code, ia64_insn *valuep)
+{
+ return ext_imms_scaled (self, code, valuep, 4);
+}
+
+static const char*
+ins_imms16 (const struct ia64_operand *self, ia64_insn value, ia64_insn *code)
+{
+ return ins_imms_scaled (self, value, code, 16);
+}
+
+static const char*
+ext_imms16 (const struct ia64_operand *self, ia64_insn code, ia64_insn *valuep)
+{
+ return ext_imms_scaled (self, code, valuep, 16);
+}
+
+static const char*
+ins_cimmu (const struct ia64_operand *self, ia64_insn value, ia64_insn *code)
+{
+ ia64_insn mask = (((ia64_insn) 1) << self->field[0].bits) - 1;
+ return ins_immu (self, value ^ mask, code);
+}
+
+static const char*
+ext_cimmu (const struct ia64_operand *self, ia64_insn code, ia64_insn *valuep)
+{
+ const char *result;
+ ia64_insn mask;
+
+ mask = (((ia64_insn) 1) << self->field[0].bits) - 1;
+ result = ext_immu (self, code, valuep);
+ if (!result)
+ {
+ mask = (((ia64_insn) 1) << self->field[0].bits) - 1;
+ *valuep ^= mask;
+ }
+ return result;
+}
+
+static const char*
+ins_cnt (const struct ia64_operand *self, ia64_insn value, ia64_insn *code)
+{
+ --value;
+ if (value >= ((BFD_HOST_U_64_BIT) 1) << self->field[0].bits)
+ return "count out of range";
+
+ *code |= value << self->field[0].shift;
+ return 0;
+}
+
+static const char*
+ext_cnt (const struct ia64_operand *self, ia64_insn code, ia64_insn *valuep)
+{
+ *valuep = ((code >> self->field[0].shift)
+ & ((((BFD_HOST_U_64_BIT) 1) << self->field[0].bits) - 1)) + 1;
+ return 0;
+}
+
+static const char*
+ins_cnt2b (const struct ia64_operand *self, ia64_insn value, ia64_insn *code)
+{
+ --value;
+
+ if (value > 2)
+ return "count must be in range 1..3";
+
+ *code |= value << self->field[0].shift;
+ return 0;
+}
+
+static const char*
+ext_cnt2b (const struct ia64_operand *self, ia64_insn code, ia64_insn *valuep)
+{
+ *valuep = ((code >> self->field[0].shift) & 0x3) + 1;
+ return 0;
+}
+
+static const char*
+ins_cnt2c (const struct ia64_operand *self, ia64_insn value, ia64_insn *code)
+{
+ switch (value)
+ {
+ case 0: value = 0; break;
+ case 7: value = 1; break;
+ case 15: value = 2; break;
+ case 16: value = 3; break;
+ default: return "count must be 0, 7, 15, or 16";
+ }
+ *code |= value << self->field[0].shift;
+ return 0;
+}
+
+static const char*
+ext_cnt2c (const struct ia64_operand *self, ia64_insn code, ia64_insn *valuep)
+{
+ ia64_insn value;
+
+ value = (code >> self->field[0].shift) & 0x3;
+ switch (value)
+ {
+ case 0: value = 0; break;
+ case 1: value = 7; break;
+ case 2: value = 15; break;
+ case 3: value = 16; break;
+ }
+ *valuep = value;
+ return 0;
+}
+
+static const char*
+ins_inc3 (const struct ia64_operand *self, ia64_insn value, ia64_insn *code)
+{
+ BFD_HOST_64_BIT val = value;
+ BFD_HOST_U_64_BIT sign = 0;
+
+ if (val < 0)
+ {
+ sign = 0x4;
+ value = -value;
+ }
+ switch (value)
+ {
+ case 1: value = 3; break;
+ case 4: value = 2; break;
+ case 8: value = 1; break;
+ case 16: value = 0; break;
+ default: return "count must be +/- 1, 4, 8, or 16";
+ }
+ *code |= (sign | value) << self->field[0].shift;
+ return 0;
+}
+
+static const char*
+ext_inc3 (const struct ia64_operand *self, ia64_insn code, ia64_insn *valuep)
+{
+ BFD_HOST_64_BIT val;
+ int negate;
+
+ val = (code >> self->field[0].shift) & 0x7;
+ negate = val & 0x4;
+ switch (val & 0x3)
+ {
+ case 0: val = 16; break;
+ case 1: val = 8; break;
+ case 2: val = 4; break;
+ case 3: val = 1; break;
+ }
+ if (negate)
+ val = -val;
+
+ *valuep = val;
+ return 0;
+}
+
+#define CST IA64_OPND_CLASS_CST
+#define REG IA64_OPND_CLASS_REG
+#define IND IA64_OPND_CLASS_IND
+#define ABS IA64_OPND_CLASS_ABS
+#define REL IA64_OPND_CLASS_REL
+
+#define SDEC IA64_OPND_FLAG_DECIMAL_SIGNED
+#define UDEC IA64_OPND_FLAG_DECIMAL_UNSIGNED
+
+const struct ia64_operand elf64_ia64_operands[IA64_OPND_COUNT] =
+ {
+ /* constants: */
+ { CST, ins_const, ext_const, "NIL", {{ 0, 0}}, 0, "<none>" },
+ { CST, ins_const, ext_const, "ar.ccv", {{ 0, 0}}, 0, "ar.ccv" },
+ { CST, ins_const, ext_const, "ar.pfs", {{ 0, 0}}, 0, "ar.pfs" },
+ { CST, ins_const, ext_const, "1", {{ 0, 0}}, 0, "1" },
+ { CST, ins_const, ext_const, "8", {{ 0, 0}}, 0, "8" },
+ { CST, ins_const, ext_const, "16", {{ 0, 0}}, 0, "16" },
+ { CST, ins_const, ext_const, "r0", {{ 0, 0}}, 0, "r0" },
+ { CST, ins_const, ext_const, "ip", {{ 0, 0}}, 0, "ip" },
+ { CST, ins_const, ext_const, "pr", {{ 0, 0}}, 0, "pr" },
+ { CST, ins_const, ext_const, "pr.rot", {{ 0, 0}}, 0, "pr.rot" },
+ { CST, ins_const, ext_const, "psr", {{ 0, 0}}, 0, "psr" },
+ { CST, ins_const, ext_const, "psr.l", {{ 0, 0}}, 0, "psr.l" },
+ { CST, ins_const, ext_const, "psr.um", {{ 0, 0}}, 0, "psr.um" },
+
+ /* register operands: */
+ { REG, ins_reg, ext_reg, "ar", {{ 7, 20}}, 0, /* AR3 */
+ "an application register" },
+ { REG, ins_reg, ext_reg, "b", {{ 3, 6}}, 0, /* B1 */
+ "a branch register" },
+ { REG, ins_reg, ext_reg, "b", {{ 3, 13}}, 0, /* B2 */
+ "a branch register"},
+ { REG, ins_reg, ext_reg, "cr", {{ 7, 20}}, 0, /* CR */
+ "a control register"},
+ { REG, ins_reg, ext_reg, "f", {{ 7, 6}}, 0, /* F1 */
+ "a floating-point register" },
+ { REG, ins_reg, ext_reg, "f", {{ 7, 13}}, 0, /* F2 */
+ "a floating-point register" },
+ { REG, ins_reg, ext_reg, "f", {{ 7, 20}}, 0, /* F3 */
+ "a floating-point register" },
+ { REG, ins_reg, ext_reg, "f", {{ 7, 27}}, 0, /* F4 */
+ "a floating-point register" },
+ { REG, ins_reg, ext_reg, "p", {{ 6, 6}}, 0, /* P1 */
+ "a predicate register" },
+ { REG, ins_reg, ext_reg, "p", {{ 6, 27}}, 0, /* P2 */
+ "a predicate register" },
+ { REG, ins_reg, ext_reg, "r", {{ 7, 6}}, 0, /* R1 */
+ "a general register" },
+ { REG, ins_reg, ext_reg, "r", {{ 7, 13}}, 0, /* R2 */
+ "a general register" },
+ { REG, ins_reg, ext_reg, "r", {{ 7, 20}}, 0, /* R3 */
+ "a general register" },
+ { REG, ins_reg, ext_reg, "r", {{ 2, 20}}, 0, /* R3_2 */
+ "a general register r0-r3" },
+
+ /* indirect operands: */
+ { IND, ins_reg, ext_reg, "cpuid", {{7, 20}}, 0, /* CPUID_R3 */
+ "a cpuid register" },
+ { IND, ins_reg, ext_reg, "dbr", {{7, 20}}, 0, /* DBR_R3 */
+ "a dbr register" },
+ { IND, ins_reg, ext_reg, "dtr", {{7, 20}}, 0, /* DTR_R3 */
+ "a dtr register" },
+ { IND, ins_reg, ext_reg, "itr", {{7, 20}}, 0, /* ITR_R3 */
+ "an itr register" },
+ { IND, ins_reg, ext_reg, "ibr", {{7, 20}}, 0, /* IBR_R3 */
+ "an ibr register" },
+ { IND, ins_reg, ext_reg, "", {{7, 20}}, 0, /* MR3 */
+ "an indirect memory address" },
+ { IND, ins_reg, ext_reg, "msr", {{7, 20}}, 0, /* MSR_R3 */
+ "an msr register" },
+ { IND, ins_reg, ext_reg, "pkr", {{7, 20}}, 0, /* PKR_R3 */
+ "a pkr register" },
+ { IND, ins_reg, ext_reg, "pmc", {{7, 20}}, 0, /* PMC_R3 */
+ "a pmc register" },
+ { IND, ins_reg, ext_reg, "pmd", {{7, 20}}, 0, /* PMD_R3 */
+ "a pmd register" },
+ { IND, ins_reg, ext_reg, "rr", {{7, 20}}, 0, /* RR_R3 */
+ "an rr register" },
+
+ /* immediate operands: */
+ { ABS, ins_cimmu, ext_cimmu, 0, {{ 5, 20 }}, UDEC, /* CCNT5 */
+ "a 5-bit count (0-31)" },
+ { ABS, ins_cnt, ext_cnt, 0, {{ 2, 27 }}, UDEC, /* CNT2a */
+ "a 2-bit count (1-4)" },
+ { ABS, ins_cnt2b, ext_cnt2b, 0, {{ 2, 27 }}, UDEC, /* CNT2b */
+ "a 2-bit count (1-3)" },
+ { ABS, ins_cnt2c, ext_cnt2c, 0, {{ 2, 30 }}, UDEC, /* CNT2c */
+ "a count (0, 7, 15, or 16)" },
+ { ABS, ins_immu, ext_immu, 0, {{ 5, 14}}, UDEC, /* CNT5 */
+ "a 5-bit count (0-31)" },
+ { ABS, ins_immu, ext_immu, 0, {{ 6, 27}}, UDEC, /* CNT6 */
+ "a 6-bit count (0-63)" },
+ { ABS, ins_cimmu, ext_cimmu, 0, {{ 6, 20}}, UDEC, /* CPOS6a */
+ "a 6-bit bit pos (0-63)" },
+ { ABS, ins_cimmu, ext_cimmu, 0, {{ 6, 14}}, UDEC, /* CPOS6b */
+ "a 6-bit bit pos (0-63)" },
+ { ABS, ins_cimmu, ext_cimmu, 0, {{ 6, 31}}, UDEC, /* CPOS6c */
+ "a 6-bit bit pos (0-63)" },
+ { ABS, ins_imms, ext_imms, 0, {{ 1, 36}}, SDEC, /* IMM1 */
+ "a 1-bit integer (-1, 0)" },
+ { ABS, ins_immu, ext_immu, 0, {{ 2, 13}}, UDEC, /* IMMU2 */
+ "a 2-bit unsigned (0-3)" },
+ { ABS, ins_immu, ext_immu, 0, {{ 7, 13}}, 0, /* IMMU7a */
+ "a 7-bit unsigned (0-127)" },
+ { ABS, ins_immu, ext_immu, 0, {{ 7, 20}}, 0, /* IMMU7b */
+ "a 7-bit unsigned (0-127)" },
+ { ABS, ins_immu, ext_immu, 0, {{ 7, 13}}, UDEC, /* SOF */
+ "a frame size (register count)" },
+ { ABS, ins_immu, ext_immu, 0, {{ 7, 20}}, UDEC, /* SOL */
+ "a local register count" },
+ { ABS, ins_immus8,ext_immus8,0, {{ 4, 27}}, UDEC, /* SOR */
+ "a rotating register count (integer multiple of 8)" },
+ { ABS, ins_imms, ext_imms, 0, /* IMM8 */
+ {{ 7, 13}, { 1, 36}}, SDEC,
+ "an 8-bit integer (-128-127)" },
+ { ABS, ins_immsu4, ext_imms, 0, /* IMM8U4 */
+ {{ 7, 13}, { 1, 36}}, SDEC,
+ "an 8-bit signed integer for 32-bit unsigned compare (-128-127)" },
+ { ABS, ins_immsm1, ext_immsm1, 0, /* IMM8M1 */
+ {{ 7, 13}, { 1, 36}}, SDEC,
+ "an 8-bit integer (-127-128)" },
+ { ABS, ins_immsm1u4, ext_immsm1, 0, /* IMM8M1U4 */
+ {{ 7, 13}, { 1, 36}}, SDEC,
+ "an 8-bit integer for 32-bit unsigned compare (-127-(-1),1-128,0x100000000)" },
+ { ABS, ins_immsm1, ext_immsm1, 0, /* IMM8M1U8 */
+ {{ 7, 13}, { 1, 36}}, SDEC,
+ "an 8-bit integer for 64-bit unsigned compare (-127-(-1),1-128,0x10000000000000000)" },
+ { ABS, ins_immu, ext_immu, 0, {{ 2, 33}, { 7, 20}}, 0, /* IMMU9 */
+ "a 9-bit unsigned (0-511)" },
+ { ABS, ins_imms, ext_imms, 0, /* IMM9a */
+ {{ 7, 6}, { 1, 27}, { 1, 36}}, SDEC,
+ "a 9-bit integer (-256-255)" },
+ { ABS, ins_imms, ext_imms, 0, /* IMM9b */
+ {{ 7, 13}, { 1, 27}, { 1, 36}}, SDEC,
+ "a 9-bit integer (-256-255)" },
+ { ABS, ins_imms, ext_imms, 0, /* IMM14 */
+ {{ 7, 13}, { 6, 27}, { 1, 36}}, SDEC,
+ "a 14-bit integer (-8192-8191)" },
+ { ABS, ins_imms1, ext_imms1, 0, /* IMM17 */
+ {{ 7, 6}, { 8, 24}, { 1, 36}}, 0,
+ "a 17-bit integer (-65536-65535)" },
+ { ABS, ins_immu, ext_immu, 0, {{20, 6}, { 1, 36}}, 0, /* IMMU21 */
+ "a 21-bit unsigned" },
+ { ABS, ins_imms, ext_imms, 0, /* IMM22 */
+ {{ 7, 13}, { 9, 27}, { 5, 22}, { 1, 36}}, SDEC,
+ "a 22-bit signed integer" },
+ { ABS, ins_immu, ext_immu, 0, /* IMMU24 */
+ {{21, 6}, { 2, 31}, { 1, 36}}, 0,
+ "a 24-bit unsigned" },
+ { ABS, ins_imms16,ext_imms16,0, {{27, 6}, { 1, 36}}, 0, /* IMM44 */
+ "a 44-bit unsigned (least 16 bits ignored/zeroes)" },
+ { ABS, ins_rsvd, ext_rsvd, 0, {{0, 0}}, 0, /* IMMU62 */
+ "a 62-bit unsigned" },
+ { ABS, ins_rsvd, ext_rsvd, 0, {{0, 0}}, 0, /* IMMU64 */
+ "a 64-bit unsigned" },
+ { ABS, ins_inc3, ext_inc3, 0, {{ 3, 13}}, SDEC, /* INC3 */
+ "an increment (+/- 1, 4, 8, or 16)" },
+ { ABS, ins_cnt, ext_cnt, 0, {{ 4, 27}}, UDEC, /* LEN4 */
+ "a 4-bit length (1-16)" },
+ { ABS, ins_cnt, ext_cnt, 0, {{ 6, 27}}, UDEC, /* LEN6 */
+ "a 6-bit length (1-64)" },
+ { ABS, ins_immu, ext_immu, 0, {{ 4, 20}}, 0, /* MBTYPE4 */
+ "a mix type (@rev, @mix, @shuf, @alt, or @brcst)" },
+ { ABS, ins_immu, ext_immu, 0, {{ 8, 20}}, 0, /* MBTYPE8 */
+ "an 8-bit mix type" },
+ { ABS, ins_immu, ext_immu, 0, {{ 6, 14}}, UDEC, /* POS6 */
+ "a 6-bit bit pos (0-63)" },
+ { REL, ins_imms4, ext_imms4, 0, {{ 7, 6}, { 2, 33}}, 0, /* TAG13 */
+ "a branch tag" },
+ { REL, ins_imms4, ext_imms4, 0, {{ 9, 24}}, 0, /* TAG13b */
+ "a branch tag" },
+ { REL, ins_imms4, ext_imms4, 0, {{20, 6}, { 1, 36}}, 0, /* TGT25 */
+ "a branch target" },
+ { REL, ins_imms4, ext_imms4, 0, /* TGT25b */
+ {{ 7, 6}, {13, 20}, { 1, 36}}, 0,
+ "a branch target" },
+ { REL, ins_imms4, ext_imms4, 0, {{20, 13}, { 1, 36}}, 0, /* TGT25c */
+ "a branch target" },
+ { REL, ins_rsvd, ext_rsvd, 0, {{0, 0}}, 0, /* TGT64 */
+ "a branch target" },
+ };
diff --git a/contrib/binutils/bfd/cpu-ia64.c b/contrib/binutils/bfd/cpu-ia64.c
new file mode 100644
index 0000000..1f36568
--- /dev/null
+++ b/contrib/binutils/bfd/cpu-ia64.c
@@ -0,0 +1,57 @@
+/* BFD support for the ia64 architecture.
+ Copyright 1998, 1999, 2000 Free Software Foundation, Inc.
+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
+
+This file is part of BFD, the Binary File Descriptor library.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#include "bfd.h"
+#include "sysdep.h"
+#include "libbfd.h"
+
+const bfd_arch_info_type bfd_ia64_elf32_arch =
+ {
+ 64, /* 64 bits in a word */
+ 32, /* 32 bits in an address */
+ 8, /* 8 bits in a byte */
+ bfd_arch_ia64,
+ bfd_mach_ia64_elf32,
+ "ia64",
+ "ia64-elf32",
+ 3, /* log2 of section alignment */
+ true, /* the one and only */
+ bfd_default_compatible,
+ bfd_default_scan ,
+ 0,
+ };
+
+const bfd_arch_info_type bfd_ia64_arch =
+ {
+ 64, /* 64 bits in a word */
+ 64, /* 64 bits in an address */
+ 8, /* 8 bits in a byte */
+ bfd_arch_ia64,
+ bfd_mach_ia64_elf64,
+ "ia64",
+ "ia64-elf64",
+ 3, /* log2 of section alignment */
+ true, /* the one and only */
+ bfd_default_compatible,
+ bfd_default_scan ,
+ &bfd_ia64_elf32_arch,
+ };
+
+#include "cpu-ia64-opc.c"
diff --git a/contrib/binutils/bfd/cpu-rs6000.c b/contrib/binutils/bfd/cpu-rs6000.c
new file mode 100644
index 0000000..89b9230
--- /dev/null
+++ b/contrib/binutils/bfd/cpu-rs6000.c
@@ -0,0 +1,116 @@
+/* BFD back-end for rs6000 support
+ Copyright 1990, 1991, 1993, 1995, 2000 Free Software Foundation, Inc.
+ FIXME: Can someone provide a transliteration of this name into ASCII?
+ Using the following chars caused a compiler warning on HIUX (so I replaced
+ them with octal escapes), and isn't useful without an understanding of what
+ character set it is.
+ Written by Mimi Ph\373\364ng-Th\345o V\365 of IBM
+ and John Gilmore of Cygnus Support.
+
+This file is part of BFD, the Binary File Descriptor library.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#include "bfd.h"
+#include "sysdep.h"
+#include "libbfd.h"
+
+/* The RS/6000 architecture is compatible with the PowerPC common
+ architecture. */
+
+static const bfd_arch_info_type *rs6000_compatible
+ PARAMS ((const bfd_arch_info_type *, const bfd_arch_info_type *));
+
+static const bfd_arch_info_type *
+rs6000_compatible (a,b)
+ const bfd_arch_info_type *a;
+ const bfd_arch_info_type *b;
+{
+ BFD_ASSERT (a->arch == bfd_arch_rs6000);
+ switch (b->arch)
+ {
+ default:
+ return NULL;
+ case bfd_arch_rs6000:
+ return bfd_default_compatible (a, b);
+ case bfd_arch_powerpc:
+ if (b->mach == 0)
+ return b;
+ return NULL;
+ }
+ /*NOTREACHED*/
+}
+
+static const bfd_arch_info_type arch_info_struct[] =
+{
+ {
+ 32, /* 32 bits in a word */
+ 32, /* 32 bits in an address */
+ 8, /* 8 bits in a byte */
+ bfd_arch_rs6000,
+ bfd_mach_rs6k_rs1,
+ "rs6000",
+ "rs6000:rs1",
+ 3,
+ false, /* not the default */
+ rs6000_compatible,
+ bfd_default_scan,
+ &arch_info_struct[1]
+ },
+ {
+ 32, /* 32 bits in a word */
+ 32, /* 32 bits in an address */
+ 8, /* 8 bits in a byte */
+ bfd_arch_rs6000,
+ bfd_mach_rs6k_rsc,
+ "rs6000",
+ "rs6000:rsc",
+ 3,
+ false, /* not the default */
+ rs6000_compatible,
+ bfd_default_scan,
+ &arch_info_struct[2]
+ },
+ {
+ 32, /* 32 bits in a word */
+ 32, /* 32 bits in an address */
+ 8, /* 8 bits in a byte */
+ bfd_arch_rs6000,
+ bfd_mach_rs6k_rs2,
+ "rs6000",
+ "rs6000:rs2",
+ 3,
+ false, /* not the default */
+ rs6000_compatible,
+ bfd_default_scan,
+ 0
+ }
+};
+
+const bfd_arch_info_type bfd_rs6000_arch =
+ {
+ 32, /* 32 bits in a word */
+ 32, /* 32 bits in an address */
+ 8, /* 8 bits in a byte */
+ bfd_arch_rs6000,
+ bfd_mach_rs6k, /* POWER common architecture */
+ "rs6000",
+ "rs6000:6000",
+ 3,
+ true, /* the default */
+ rs6000_compatible,
+ bfd_default_scan,
+ &arch_info_struct[0]
+ };
diff --git a/contrib/binutils/bfd/efi-app-ia64.c b/contrib/binutils/bfd/efi-app-ia64.c
new file mode 100644
index 0000000..6104568
--- /dev/null
+++ b/contrib/binutils/bfd/efi-app-ia64.c
@@ -0,0 +1,35 @@
+/* BFD back-end for HP/Intel IA-64 EFI application files.
+ Copyright 1999, 2000, 2001 Free Software Foundation, Inc.
+ Contributed by David Mosberger <davidm@hpl.hp.com>
+
+This file is part of BFD, the Binary File Descriptor library.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#include "bfd.h"
+#include "sysdep.h"
+
+#define TARGET_SYM bfd_efi_app_ia64_vec
+#define TARGET_NAME "efi-app-ia64"
+#define COFF_IMAGE_WITH_PE
+#define COFF_WITH_PE
+#define COFF_WITH_pep
+#define PCRELOFFSET true
+#define TARGET_UNDERSCORE '_'
+#define COFF_LONG_SECTION_NAMES
+#define PEI_TARGET_SUBSYSTEM IMAGE_SUBSYSTEM_EFI_APPLICATION
+#define PEI_FORCE_MINIMUM_ALIGNMENT
+
+#include "coff-ia64.c"
diff --git a/contrib/binutils/bfd/elfxx-ia64.c b/contrib/binutils/bfd/elfxx-ia64.c
new file mode 100644
index 0000000..c86f7a9
--- /dev/null
+++ b/contrib/binutils/bfd/elfxx-ia64.c
@@ -0,0 +1,4235 @@
+/* IA-64 support for 64-bit ELF
+ Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
+
+This file is part of BFD, the Binary File Descriptor library.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#include "bfd.h"
+#include "sysdep.h"
+#include "libbfd.h"
+#include "elf-bfd.h"
+#include "opcode/ia64.h"
+#include "elf/ia64.h"
+
+/*
+ * THE RULES for all the stuff the linker creates --
+ *
+ * GOT Entries created in response to LTOFF or LTOFF_FPTR
+ * relocations. Dynamic relocs created for dynamic
+ * symbols in an application; REL relocs for locals
+ * in a shared library.
+ *
+ * FPTR The canonical function descriptor. Created for local
+ * symbols in applications. Descriptors for dynamic symbols
+ * and local symbols in shared libraries are created by
+ * ld.so. Thus there are no dynamic relocs against these
+ * objects. The FPTR relocs for such _are_ passed through
+ * to the dynamic relocation tables.
+ *
+ * FULL_PLT Created for a PCREL21B relocation against a dynamic symbol.
+ * Requires the creation of a PLTOFF entry. This does not
+ * require any dynamic relocations.
+ *
+ * PLTOFF Created by PLTOFF relocations. For local symbols, this
+ * is an alternate function descriptor, and in shared libraries
+ * requires two REL relocations. Note that this cannot be
+ * transformed into an FPTR relocation, since it must be in
+ * range of the GP. For dynamic symbols, this is a function
+ * descriptor for a MIN_PLT entry, and requires one IPLT reloc.
+ *
+ * MIN_PLT Created by PLTOFF entries against dynamic symbols. This
+ * does not reqire dynamic relocations.
+ */
+
+#define USE_RELA /* we want RELA relocs, not REL */
+
+#define NELEMS(a) ((int) (sizeof (a) / sizeof ((a)[0])))
+
+typedef struct bfd_hash_entry *(*new_hash_entry_func)
+ PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
+
+/* In dynamically (linker-) created sections, we generally need to keep track
+ of the place a symbol or expression got allocated to. This is done via hash
+ tables that store entries of the following type. */
+
+struct elfNN_ia64_dyn_sym_info
+{
+ /* The addend for which this entry is relevant. */
+ bfd_vma addend;
+
+ /* Next addend in the list. */
+ struct elfNN_ia64_dyn_sym_info *next;
+
+ bfd_vma got_offset;
+ bfd_vma fptr_offset;
+ bfd_vma pltoff_offset;
+ bfd_vma plt_offset;
+ bfd_vma plt2_offset;
+
+ /* The symbol table entry, if any, that this was derrived from. */
+ struct elf_link_hash_entry *h;
+
+ /* Used to count non-got, non-plt relocations for delayed sizing
+ of relocation sections. */
+ struct elfNN_ia64_dyn_reloc_entry
+ {
+ struct elfNN_ia64_dyn_reloc_entry *next;
+ asection *srel;
+ int type;
+ int count;
+ } *reloc_entries;
+
+ /* True when the section contents have been updated. */
+ unsigned got_done : 1;
+ unsigned fptr_done : 1;
+ unsigned pltoff_done : 1;
+
+ /* True for the different kinds of linker data we want created. */
+ unsigned want_got : 1;
+ unsigned want_fptr : 1;
+ unsigned want_ltoff_fptr : 1;
+ unsigned want_plt : 1;
+ unsigned want_plt2 : 1;
+ unsigned want_pltoff : 1;
+};
+
+struct elfNN_ia64_local_hash_entry
+{
+ struct bfd_hash_entry root;
+ struct elfNN_ia64_dyn_sym_info *info;
+};
+
+struct elfNN_ia64_local_hash_table
+{
+ struct bfd_hash_table root;
+ /* No additional fields for now. */
+};
+
+struct elfNN_ia64_link_hash_entry
+{
+ struct elf_link_hash_entry root;
+ struct elfNN_ia64_dyn_sym_info *info;
+};
+
+struct elfNN_ia64_link_hash_table
+{
+ /* The main hash table */
+ struct elf_link_hash_table root;
+
+ asection *got_sec; /* the linkage table section (or NULL) */
+ asection *rel_got_sec; /* dynamic relocation section for same */
+ asection *fptr_sec; /* function descriptor table (or NULL) */
+ asection *plt_sec; /* the primary plt section (or NULL) */
+ asection *pltoff_sec; /* private descriptors for plt (or NULL) */
+ asection *rel_pltoff_sec; /* dynamic relocation section for same */
+
+ bfd_size_type minplt_entries; /* number of minplt entries */
+
+ struct elfNN_ia64_local_hash_table loc_hash_table;
+};
+
+#define elfNN_ia64_hash_table(p) \
+ ((struct elfNN_ia64_link_hash_table *) ((p)->hash))
+
+static bfd_reloc_status_type elfNN_ia64_reloc
+ PARAMS ((bfd *abfd, arelent *reloc, asymbol *sym, PTR data,
+ asection *input_section, bfd *output_bfd, char **error_message));
+static reloc_howto_type * lookup_howto
+ PARAMS ((unsigned int rtype));
+static reloc_howto_type *elfNN_ia64_reloc_type_lookup
+ PARAMS ((bfd *abfd, bfd_reloc_code_real_type bfd_code));
+static void elfNN_ia64_info_to_howto
+ PARAMS ((bfd *abfd, arelent *bfd_reloc, ElfNN_Internal_Rela *elf_reloc));
+static boolean elfNN_ia64_relax_section
+ PARAMS((bfd *abfd, asection *sec, struct bfd_link_info *link_info,
+ boolean *again));
+static boolean is_unwind_section_name
+ PARAMS ((const char *));
+static boolean elfNN_ia64_section_from_shdr
+ PARAMS ((bfd *, ElfNN_Internal_Shdr *, char *));
+static boolean elfNN_ia64_fake_sections
+ PARAMS ((bfd *abfd, ElfNN_Internal_Shdr *hdr, asection *sec));
+static void elfNN_ia64_final_write_processing
+ PARAMS ((bfd *abfd, boolean linker));
+static boolean elfNN_ia64_add_symbol_hook
+ PARAMS ((bfd *abfd, struct bfd_link_info *info, const Elf_Internal_Sym *sym,
+ const char **namep, flagword *flagsp, asection **secp,
+ bfd_vma *valp));
+static int elfNN_ia64_additional_program_headers
+ PARAMS ((bfd *abfd));
+static boolean elfNN_ia64_is_local_label_name
+ PARAMS ((bfd *abfd, const char *name));
+static boolean elfNN_ia64_dynamic_symbol_p
+ PARAMS ((struct elf_link_hash_entry *h, struct bfd_link_info *info));
+static boolean elfNN_ia64_local_hash_table_init
+ PARAMS ((struct elfNN_ia64_local_hash_table *ht, bfd *abfd,
+ new_hash_entry_func new));
+static struct bfd_hash_entry *elfNN_ia64_new_loc_hash_entry
+ PARAMS ((struct bfd_hash_entry *entry, struct bfd_hash_table *table,
+ const char *string));
+static struct bfd_hash_entry *elfNN_ia64_new_elf_hash_entry
+ PARAMS ((struct bfd_hash_entry *entry, struct bfd_hash_table *table,
+ const char *string));
+static struct bfd_link_hash_table *elfNN_ia64_hash_table_create
+ PARAMS ((bfd *abfd));
+static struct elfNN_ia64_local_hash_entry *elfNN_ia64_local_hash_lookup
+ PARAMS ((struct elfNN_ia64_local_hash_table *table, const char *string,
+ boolean create, boolean copy));
+static void elfNN_ia64_dyn_sym_traverse
+ PARAMS ((struct elfNN_ia64_link_hash_table *ia64_info,
+ boolean (*func) (struct elfNN_ia64_dyn_sym_info *, PTR),
+ PTR info));
+static boolean elfNN_ia64_create_dynamic_sections
+ PARAMS ((bfd *abfd, struct bfd_link_info *info));
+static struct elfNN_ia64_dyn_sym_info * get_dyn_sym_info
+ PARAMS ((struct elfNN_ia64_link_hash_table *ia64_info,
+ struct elf_link_hash_entry *h,
+ bfd *abfd, const Elf_Internal_Rela *rel, boolean create));
+static asection *get_got
+ PARAMS ((bfd *abfd, struct bfd_link_info *info,
+ struct elfNN_ia64_link_hash_table *ia64_info));
+static asection *get_fptr
+ PARAMS ((bfd *abfd, struct bfd_link_info *info,
+ struct elfNN_ia64_link_hash_table *ia64_info));
+static asection *get_pltoff
+ PARAMS ((bfd *abfd, struct bfd_link_info *info,
+ struct elfNN_ia64_link_hash_table *ia64_info));
+static asection *get_reloc_section
+ PARAMS ((bfd *abfd, struct elfNN_ia64_link_hash_table *ia64_info,
+ asection *sec, boolean create));
+static boolean count_dyn_reloc
+ PARAMS ((bfd *abfd, struct elfNN_ia64_dyn_sym_info *dyn_i,
+ asection *srel, int type));
+static boolean elfNN_ia64_check_relocs
+ PARAMS ((bfd *abfd, struct bfd_link_info *info, asection *sec,
+ const Elf_Internal_Rela *relocs));
+static boolean elfNN_ia64_adjust_dynamic_symbol
+ PARAMS ((struct bfd_link_info *info, struct elf_link_hash_entry *h));
+static unsigned long global_sym_index
+ PARAMS ((struct elf_link_hash_entry *h));
+static boolean allocate_fptr
+ PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data));
+static boolean allocate_global_data_got
+ PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data));
+static boolean allocate_global_fptr_got
+ PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data));
+static boolean allocate_local_got
+ PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data));
+static boolean allocate_pltoff_entries
+ PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data));
+static boolean allocate_plt_entries
+ PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data));
+static boolean allocate_plt2_entries
+ PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data));
+static boolean allocate_dynrel_entries
+ PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data));
+static boolean elfNN_ia64_size_dynamic_sections
+ PARAMS ((bfd *output_bfd, struct bfd_link_info *info));
+static bfd_reloc_status_type elfNN_ia64_install_value
+ PARAMS ((bfd *abfd, bfd_byte *hit_addr, bfd_vma val, unsigned int r_type));
+static void elfNN_ia64_install_dyn_reloc
+ PARAMS ((bfd *abfd, struct bfd_link_info *info, asection *sec,
+ asection *srel, bfd_vma offset, unsigned int type,
+ long dynindx, bfd_vma addend));
+static bfd_vma set_got_entry
+ PARAMS ((bfd *abfd, struct bfd_link_info *info,
+ struct elfNN_ia64_dyn_sym_info *dyn_i, long dynindx,
+ bfd_vma addend, bfd_vma value, unsigned int dyn_r_type));
+static bfd_vma set_fptr_entry
+ PARAMS ((bfd *abfd, struct bfd_link_info *info,
+ struct elfNN_ia64_dyn_sym_info *dyn_i,
+ bfd_vma value));
+static bfd_vma set_pltoff_entry
+ PARAMS ((bfd *abfd, struct bfd_link_info *info,
+ struct elfNN_ia64_dyn_sym_info *dyn_i,
+ bfd_vma value, boolean));
+static boolean elfNN_ia64_final_link
+ PARAMS ((bfd *abfd, struct bfd_link_info *info));
+static boolean elfNN_ia64_relocate_section
+ PARAMS ((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));
+static boolean elfNN_ia64_finish_dynamic_symbol
+ PARAMS ((bfd *output_bfd, struct bfd_link_info *info,
+ struct elf_link_hash_entry *h, Elf_Internal_Sym *sym));
+static boolean elfNN_ia64_finish_dynamic_sections
+ PARAMS ((bfd *abfd, struct bfd_link_info *info));
+static boolean elfNN_ia64_set_private_flags
+ PARAMS ((bfd *abfd, flagword flags));
+static boolean elfNN_ia64_copy_private_bfd_data
+ PARAMS ((bfd *ibfd, bfd *obfd));
+static boolean elfNN_ia64_merge_private_bfd_data
+ PARAMS ((bfd *ibfd, bfd *obfd));
+static boolean elfNN_ia64_print_private_bfd_data
+ PARAMS ((bfd *abfd, PTR ptr));
+
+/* ia64-specific relocation */
+
+/* Perform a relocation. Not much to do here as all the hard work is
+ done in elfNN_ia64_final_link_relocate. */
+static bfd_reloc_status_type
+elfNN_ia64_reloc (abfd, reloc, sym, data, input_section,
+ output_bfd, error_message)
+ bfd *abfd ATTRIBUTE_UNUSED;
+ arelent *reloc;
+ asymbol *sym ATTRIBUTE_UNUSED;
+ PTR data ATTRIBUTE_UNUSED;
+ asection *input_section;
+ bfd *output_bfd;
+ char **error_message;
+{
+ if (output_bfd)
+ {
+ reloc->address += input_section->output_offset;
+ return bfd_reloc_ok;
+ }
+ *error_message = "Unsupported call to elfNN_ia64_reloc";
+ return bfd_reloc_notsupported;
+}
+
+#define IA64_HOWTO(TYPE, NAME, SIZE, PCREL, IN) \
+ HOWTO (TYPE, 0, SIZE, 0, PCREL, 0, complain_overflow_signed, \
+ elfNN_ia64_reloc, NAME, false, 0, 0, IN)
+
+/* This table has to be sorted according to increasing number of the
+ TYPE field. */
+static reloc_howto_type ia64_howto_table[] =
+ {
+ IA64_HOWTO (R_IA64_NONE, "NONE", 0, false, true),
+
+ IA64_HOWTO (R_IA64_IMM14, "IMM14", 0, false, true),
+ IA64_HOWTO (R_IA64_IMM22, "IMM22", 0, false, true),
+ IA64_HOWTO (R_IA64_IMM64, "IMM64", 0, false, true),
+ IA64_HOWTO (R_IA64_DIR32MSB, "DIR32MSB", 2, false, true),
+ IA64_HOWTO (R_IA64_DIR32LSB, "DIR32LSB", 2, false, true),
+ IA64_HOWTO (R_IA64_DIR64MSB, "DIR64MSB", 4, false, true),
+ IA64_HOWTO (R_IA64_DIR64LSB, "DIR64LSB", 4, false, true),
+
+ IA64_HOWTO (R_IA64_GPREL22, "GPREL22", 0, false, true),
+ IA64_HOWTO (R_IA64_GPREL64I, "GPREL64I", 0, false, true),
+ IA64_HOWTO (R_IA64_GPREL32MSB, "GPREL32MSB", 2, false, true),
+ IA64_HOWTO (R_IA64_GPREL32LSB, "GPREL32LSB", 2, false, true),
+ IA64_HOWTO (R_IA64_GPREL64MSB, "GPREL64MSB", 4, false, true),
+ IA64_HOWTO (R_IA64_GPREL64LSB, "GPREL64LSB", 4, false, true),
+
+ IA64_HOWTO (R_IA64_LTOFF22, "LTOFF22", 0, false, true),
+ IA64_HOWTO (R_IA64_LTOFF64I, "LTOFF64I", 0, false, true),
+
+ IA64_HOWTO (R_IA64_PLTOFF22, "PLTOFF22", 0, false, true),
+ IA64_HOWTO (R_IA64_PLTOFF64I, "PLTOFF64I", 0, false, true),
+ IA64_HOWTO (R_IA64_PLTOFF64MSB, "PLTOFF64MSB", 4, false, true),
+ IA64_HOWTO (R_IA64_PLTOFF64LSB, "PLTOFF64LSB", 4, false, true),
+
+ IA64_HOWTO (R_IA64_FPTR64I, "FPTR64I", 0, false, true),
+ IA64_HOWTO (R_IA64_FPTR32MSB, "FPTR32MSB", 2, false, true),
+ IA64_HOWTO (R_IA64_FPTR32LSB, "FPTR32LSB", 2, false, true),
+ IA64_HOWTO (R_IA64_FPTR64MSB, "FPTR64MSB", 4, false, true),
+ IA64_HOWTO (R_IA64_FPTR64LSB, "FPTR64LSB", 4, false, true),
+
+ IA64_HOWTO (R_IA64_PCREL60B, "PCREL60B", 0, true, true),
+ IA64_HOWTO (R_IA64_PCREL21B, "PCREL21B", 0, true, true),
+ IA64_HOWTO (R_IA64_PCREL21M, "PCREL21M", 0, true, true),
+ IA64_HOWTO (R_IA64_PCREL21F, "PCREL21F", 0, true, true),
+ IA64_HOWTO (R_IA64_PCREL32MSB, "PCREL32MSB", 2, true, true),
+ IA64_HOWTO (R_IA64_PCREL32LSB, "PCREL32LSB", 2, true, true),
+ IA64_HOWTO (R_IA64_PCREL64MSB, "PCREL64MSB", 4, true, true),
+ IA64_HOWTO (R_IA64_PCREL64LSB, "PCREL64LSB", 4, true, true),
+
+ IA64_HOWTO (R_IA64_LTOFF_FPTR22, "LTOFF_FPTR22", 0, false, true),
+ IA64_HOWTO (R_IA64_LTOFF_FPTR64I, "LTOFF_FPTR64I", 0, false, true),
+ IA64_HOWTO (R_IA64_LTOFF_FPTR64MSB, "LTOFF_FPTR64MSB", 4, false, true),
+ IA64_HOWTO (R_IA64_LTOFF_FPTR64LSB, "LTOFF_FPTR64LSB", 4, false, true),
+
+ IA64_HOWTO (R_IA64_SEGREL32MSB, "SEGREL32MSB", 2, false, true),
+ IA64_HOWTO (R_IA64_SEGREL32LSB, "SEGREL32LSB", 2, false, true),
+ IA64_HOWTO (R_IA64_SEGREL64MSB, "SEGREL64MSB", 4, false, true),
+ IA64_HOWTO (R_IA64_SEGREL64LSB, "SEGREL64LSB", 4, false, true),
+
+ IA64_HOWTO (R_IA64_SECREL32MSB, "SECREL32MSB", 2, false, true),
+ IA64_HOWTO (R_IA64_SECREL32LSB, "SECREL32LSB", 2, false, true),
+ IA64_HOWTO (R_IA64_SECREL64MSB, "SECREL64MSB", 4, false, true),
+ IA64_HOWTO (R_IA64_SECREL64LSB, "SECREL64LSB", 4, false, true),
+
+ IA64_HOWTO (R_IA64_REL32MSB, "REL32MSB", 2, false, true),
+ IA64_HOWTO (R_IA64_REL32LSB, "REL32LSB", 2, false, true),
+ IA64_HOWTO (R_IA64_REL64MSB, "REL64MSB", 4, false, true),
+ IA64_HOWTO (R_IA64_REL64LSB, "REL64LSB", 4, false, true),
+
+ IA64_HOWTO (R_IA64_LTV32MSB, "LTV32MSB", 2, false, true),
+ IA64_HOWTO (R_IA64_LTV32LSB, "LTV32LSB", 2, false, true),
+ IA64_HOWTO (R_IA64_LTV64MSB, "LTV64MSB", 4, false, true),
+ IA64_HOWTO (R_IA64_LTV64LSB, "LTV64LSB", 4, false, true),
+
+ IA64_HOWTO (R_IA64_PCREL21BI, "PCREL21BI", 0, true, true),
+ IA64_HOWTO (R_IA64_PCREL22, "PCREL22", 0, true, true),
+ IA64_HOWTO (R_IA64_PCREL64I, "PCREL64I", 0, true, true),
+
+ IA64_HOWTO (R_IA64_IPLTMSB, "IPLTMSB", 4, false, true),
+ IA64_HOWTO (R_IA64_IPLTLSB, "IPLTLSB", 4, false, true),
+ IA64_HOWTO (R_IA64_COPY, "COPY", 4, false, true),
+ IA64_HOWTO (R_IA64_LTOFF22X, "LTOFF22X", 0, false, true),
+ IA64_HOWTO (R_IA64_LDXMOV, "LDXMOV", 0, false, true),
+
+ IA64_HOWTO (R_IA64_TPREL22, "TPREL22", 0, false, false),
+ IA64_HOWTO (R_IA64_TPREL64MSB, "TPREL64MSB", 8, false, false),
+ IA64_HOWTO (R_IA64_TPREL64LSB, "TPREL64LSB", 8, false, false),
+ IA64_HOWTO (R_IA64_LTOFF_TP22, "LTOFF_TP22", 0, false, false),
+ };
+
+static unsigned char elf_code_to_howto_index[R_IA64_MAX_RELOC_CODE + 1];
+
+/* Given a BFD reloc type, return the matching HOWTO structure. */
+
+static reloc_howto_type*
+lookup_howto (rtype)
+ unsigned int rtype;
+{
+ static int inited = 0;
+ int i;
+
+ if (!inited)
+ {
+ inited = 1;
+
+ memset (elf_code_to_howto_index, 0xff, sizeof (elf_code_to_howto_index));
+ for (i = 0; i < NELEMS (ia64_howto_table); ++i)
+ elf_code_to_howto_index[ia64_howto_table[i].type] = i;
+ }
+
+ BFD_ASSERT (rtype <= R_IA64_MAX_RELOC_CODE);
+ i = elf_code_to_howto_index[rtype];
+ if (i >= NELEMS (ia64_howto_table))
+ return 0;
+ return ia64_howto_table + i;
+}
+
+static reloc_howto_type*
+elfNN_ia64_reloc_type_lookup (abfd, bfd_code)
+ bfd *abfd ATTRIBUTE_UNUSED;
+ bfd_reloc_code_real_type bfd_code;
+{
+ unsigned int rtype;
+
+ switch (bfd_code)
+ {
+ case BFD_RELOC_NONE: rtype = R_IA64_NONE; break;
+
+ case BFD_RELOC_IA64_IMM14: rtype = R_IA64_IMM14; break;
+ case BFD_RELOC_IA64_IMM22: rtype = R_IA64_IMM22; break;
+ case BFD_RELOC_IA64_IMM64: rtype = R_IA64_IMM64; break;
+
+ case BFD_RELOC_IA64_DIR32MSB: rtype = R_IA64_DIR32MSB; break;
+ case BFD_RELOC_IA64_DIR32LSB: rtype = R_IA64_DIR32LSB; break;
+ case BFD_RELOC_IA64_DIR64MSB: rtype = R_IA64_DIR64MSB; break;
+ case BFD_RELOC_IA64_DIR64LSB: rtype = R_IA64_DIR64LSB; break;
+
+ case BFD_RELOC_IA64_GPREL22: rtype = R_IA64_GPREL22; break;
+ case BFD_RELOC_IA64_GPREL64I: rtype = R_IA64_GPREL64I; break;
+ case BFD_RELOC_IA64_GPREL32MSB: rtype = R_IA64_GPREL32MSB; break;
+ case BFD_RELOC_IA64_GPREL32LSB: rtype = R_IA64_GPREL32LSB; break;
+ case BFD_RELOC_IA64_GPREL64MSB: rtype = R_IA64_GPREL64MSB; break;
+ case BFD_RELOC_IA64_GPREL64LSB: rtype = R_IA64_GPREL64LSB; break;
+
+ case BFD_RELOC_IA64_LTOFF22: rtype = R_IA64_LTOFF22; break;
+ case BFD_RELOC_IA64_LTOFF64I: rtype = R_IA64_LTOFF64I; break;
+
+ case BFD_RELOC_IA64_PLTOFF22: rtype = R_IA64_PLTOFF22; break;
+ case BFD_RELOC_IA64_PLTOFF64I: rtype = R_IA64_PLTOFF64I; break;
+ case BFD_RELOC_IA64_PLTOFF64MSB: rtype = R_IA64_PLTOFF64MSB; break;
+ case BFD_RELOC_IA64_PLTOFF64LSB: rtype = R_IA64_PLTOFF64LSB; break;
+ case BFD_RELOC_IA64_FPTR64I: rtype = R_IA64_FPTR64I; break;
+ case BFD_RELOC_IA64_FPTR32MSB: rtype = R_IA64_FPTR32MSB; break;
+ case BFD_RELOC_IA64_FPTR32LSB: rtype = R_IA64_FPTR32LSB; break;
+ case BFD_RELOC_IA64_FPTR64MSB: rtype = R_IA64_FPTR64MSB; break;
+ case BFD_RELOC_IA64_FPTR64LSB: rtype = R_IA64_FPTR64LSB; break;
+
+ case BFD_RELOC_IA64_PCREL21B: rtype = R_IA64_PCREL21B; break;
+ case BFD_RELOC_IA64_PCREL21BI: rtype = R_IA64_PCREL21BI; break;
+ case BFD_RELOC_IA64_PCREL21M: rtype = R_IA64_PCREL21M; break;
+ case BFD_RELOC_IA64_PCREL21F: rtype = R_IA64_PCREL21F; break;
+ case BFD_RELOC_IA64_PCREL22: rtype = R_IA64_PCREL22; break;
+ case BFD_RELOC_IA64_PCREL60B: rtype = R_IA64_PCREL60B; break;
+ case BFD_RELOC_IA64_PCREL64I: rtype = R_IA64_PCREL64I; break;
+ case BFD_RELOC_IA64_PCREL32MSB: rtype = R_IA64_PCREL32MSB; break;
+ case BFD_RELOC_IA64_PCREL32LSB: rtype = R_IA64_PCREL32LSB; break;
+ case BFD_RELOC_IA64_PCREL64MSB: rtype = R_IA64_PCREL64MSB; break;
+ case BFD_RELOC_IA64_PCREL64LSB: rtype = R_IA64_PCREL64LSB; break;
+
+ case BFD_RELOC_IA64_LTOFF_FPTR22: rtype = R_IA64_LTOFF_FPTR22; break;
+ case BFD_RELOC_IA64_LTOFF_FPTR64I: rtype = R_IA64_LTOFF_FPTR64I; break;
+ case BFD_RELOC_IA64_LTOFF_FPTR64MSB: rtype = R_IA64_LTOFF_FPTR64MSB; break;
+ case BFD_RELOC_IA64_LTOFF_FPTR64LSB: rtype = R_IA64_LTOFF_FPTR64LSB; break;
+
+ case BFD_RELOC_IA64_SEGREL32MSB: rtype = R_IA64_SEGREL32MSB; break;
+ case BFD_RELOC_IA64_SEGREL32LSB: rtype = R_IA64_SEGREL32LSB; break;
+ case BFD_RELOC_IA64_SEGREL64MSB: rtype = R_IA64_SEGREL64MSB; break;
+ case BFD_RELOC_IA64_SEGREL64LSB: rtype = R_IA64_SEGREL64LSB; break;
+
+ case BFD_RELOC_IA64_SECREL32MSB: rtype = R_IA64_SECREL32MSB; break;
+ case BFD_RELOC_IA64_SECREL32LSB: rtype = R_IA64_SECREL32LSB; break;
+ case BFD_RELOC_IA64_SECREL64MSB: rtype = R_IA64_SECREL64MSB; break;
+ case BFD_RELOC_IA64_SECREL64LSB: rtype = R_IA64_SECREL64LSB; break;
+
+ case BFD_RELOC_IA64_REL32MSB: rtype = R_IA64_REL32MSB; break;
+ case BFD_RELOC_IA64_REL32LSB: rtype = R_IA64_REL32LSB; break;
+ case BFD_RELOC_IA64_REL64MSB: rtype = R_IA64_REL64MSB; break;
+ case BFD_RELOC_IA64_REL64LSB: rtype = R_IA64_REL64LSB; break;
+
+ case BFD_RELOC_IA64_LTV32MSB: rtype = R_IA64_LTV32MSB; break;
+ case BFD_RELOC_IA64_LTV32LSB: rtype = R_IA64_LTV32LSB; break;
+ case BFD_RELOC_IA64_LTV64MSB: rtype = R_IA64_LTV64MSB; break;
+ case BFD_RELOC_IA64_LTV64LSB: rtype = R_IA64_LTV64LSB; break;
+
+ case BFD_RELOC_IA64_IPLTMSB: rtype = R_IA64_IPLTMSB; break;
+ case BFD_RELOC_IA64_IPLTLSB: rtype = R_IA64_IPLTLSB; break;
+ case BFD_RELOC_IA64_COPY: rtype = R_IA64_COPY; break;
+ case BFD_RELOC_IA64_LTOFF22X: rtype = R_IA64_LTOFF22X; break;
+ case BFD_RELOC_IA64_LDXMOV: rtype = R_IA64_LDXMOV; break;
+
+ case BFD_RELOC_IA64_TPREL22: rtype = R_IA64_TPREL22; break;
+ case BFD_RELOC_IA64_TPREL64MSB: rtype = R_IA64_TPREL64MSB; break;
+ case BFD_RELOC_IA64_TPREL64LSB: rtype = R_IA64_TPREL64LSB; break;
+ case BFD_RELOC_IA64_LTOFF_TP22: rtype = R_IA64_LTOFF_TP22; break;
+
+ default: return 0;
+ }
+ return lookup_howto (rtype);
+}
+
+/* Given a ELF reloc, return the matching HOWTO structure. */
+
+static void
+elfNN_ia64_info_to_howto (abfd, bfd_reloc, elf_reloc)
+ bfd *abfd ATTRIBUTE_UNUSED;
+ arelent *bfd_reloc;
+ ElfNN_Internal_Rela *elf_reloc;
+{
+ bfd_reloc->howto = lookup_howto (ELFNN_R_TYPE (elf_reloc->r_info));
+}
+
+#define PLT_HEADER_SIZE (3 * 16)
+#define PLT_MIN_ENTRY_SIZE (1 * 16)
+#define PLT_FULL_ENTRY_SIZE (2 * 16)
+#define PLT_RESERVED_WORDS 3
+
+static const bfd_byte plt_header[PLT_HEADER_SIZE] =
+{
+ 0x0b, 0x10, 0x00, 0x1c, 0x00, 0x21, /* [MMI] mov r2=r14;; */
+ 0xe0, 0x00, 0x08, 0x00, 0x48, 0x00, /* addl r14=0,r2 */
+ 0x00, 0x00, 0x04, 0x00, /* nop.i 0x0;; */
+ 0x0b, 0x80, 0x20, 0x1c, 0x18, 0x14, /* [MMI] ld8 r16=[r14],8;; */
+ 0x10, 0x41, 0x38, 0x30, 0x28, 0x00, /* ld8 r17=[r14],8 */
+ 0x00, 0x00, 0x04, 0x00, /* nop.i 0x0;; */
+ 0x11, 0x08, 0x00, 0x1c, 0x18, 0x10, /* [MIB] ld8 r1=[r14] */
+ 0x60, 0x88, 0x04, 0x80, 0x03, 0x00, /* mov b6=r17 */
+ 0x60, 0x00, 0x80, 0x00 /* br.few b6;; */
+};
+
+static const bfd_byte plt_min_entry[PLT_MIN_ENTRY_SIZE] =
+{
+ 0x11, 0x78, 0x00, 0x00, 0x00, 0x24, /* [MIB] mov r15=0 */
+ 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, /* nop.i 0x0 */
+ 0x00, 0x00, 0x00, 0x40 /* br.few 0 <PLT0>;; */
+};
+
+static const bfd_byte plt_full_entry[PLT_FULL_ENTRY_SIZE] =
+{
+ 0x0b, 0x78, 0x00, 0x02, 0x00, 0x24, /* [MMI] addl r15=0,r1;; */
+ 0x00, 0x41, 0x3c, 0x30, 0x28, 0xc0, /* ld8 r16=[r15],8 */
+ 0x01, 0x08, 0x00, 0x84, /* mov r14=r1;; */
+ 0x11, 0x08, 0x00, 0x1e, 0x18, 0x10, /* [MIB] ld8 r1=[r15] */
+ 0x60, 0x80, 0x04, 0x80, 0x03, 0x00, /* mov b6=r16 */
+ 0x60, 0x00, 0x80, 0x00 /* br.few b6;; */
+};
+
+#define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
+
+/* Select out of range branch fixup type. Note that Itanium does
+ not support brl, and so it gets emulated by the kernel. */
+#undef USE_BRL
+
+static const bfd_byte oor_brl[16] =
+{
+ 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MLX] nop.m 0 */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* brl.sptk.few tgt;; */
+ 0x00, 0x00, 0x00, 0xc0
+};
+
+static const bfd_byte oor_ip[48] =
+{
+ 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MLX] nop.m 0 */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, /* movl r15=0 */
+ 0x01, 0x00, 0x00, 0x60,
+ 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MII] nop.m 0 */
+ 0x00, 0x01, 0x00, 0x60, 0x00, 0x00, /* mov r16=ip;; */
+ 0xf2, 0x80, 0x00, 0x80, /* add r16=r15,r16;; */
+ 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MIB] nop.m 0 */
+ 0x60, 0x80, 0x04, 0x80, 0x03, 0x00, /* mov b6=r16 */
+ 0x60, 0x00, 0x80, 0x00 /* br b6;; */
+};
+
+/* These functions do relaxation for IA-64 ELF.
+
+ This is primarily to support branches to targets out of range;
+ relaxation of R_IA64_LTOFF22X and R_IA64_LDXMOV not yet supported. */
+
+static boolean
+elfNN_ia64_relax_section (abfd, sec, link_info, again)
+ bfd *abfd;
+ asection *sec;
+ struct bfd_link_info *link_info;
+ boolean *again;
+{
+ struct one_fixup
+ {
+ struct one_fixup *next;
+ asection *tsec;
+ bfd_vma toff;
+ bfd_vma trampoff;
+ };
+
+ Elf_Internal_Shdr *symtab_hdr;
+ Elf_Internal_Rela *internal_relocs;
+ Elf_Internal_Rela *free_relocs = NULL;
+ Elf_Internal_Rela *irel, *irelend;
+ bfd_byte *contents;
+ bfd_byte *free_contents = NULL;
+ ElfNN_External_Sym *extsyms;
+ ElfNN_External_Sym *free_extsyms = NULL;
+ struct elfNN_ia64_link_hash_table *ia64_info;
+ struct one_fixup *fixups = NULL;
+ boolean changed_contents = false;
+ boolean changed_relocs = false;
+
+ /* Assume we're not going to change any sizes, and we'll only need
+ one pass. */
+ *again = false;
+
+ /* Nothing to do if there are no relocations. */
+ if ((sec->flags & SEC_RELOC) == 0
+ || sec->reloc_count == 0)
+ return true;
+
+ /* If this is the first time we have been called for this section,
+ initialize the cooked size. */
+ if (sec->_cooked_size == 0)
+ sec->_cooked_size = sec->_raw_size;
+
+ symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+
+ /* Load the relocations for this section. */
+ internal_relocs = (_bfd_elfNN_link_read_relocs
+ (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
+ link_info->keep_memory));
+ if (internal_relocs == NULL)
+ goto error_return;
+
+ if (! link_info->keep_memory)
+ free_relocs = internal_relocs;
+
+ ia64_info = elfNN_ia64_hash_table (link_info);
+ irelend = internal_relocs + sec->reloc_count;
+
+ for (irel = internal_relocs; irel < irelend; irel++)
+ if (ELFNN_R_TYPE (irel->r_info) == (int) R_IA64_PCREL21B)
+ break;
+
+ /* No branch-type relocations. */
+ if (irel == irelend)
+ {
+ if (free_relocs != NULL)
+ free (free_relocs);
+ return true;
+ }
+
+ /* Get the section contents. */
+ if (elf_section_data (sec)->this_hdr.contents != NULL)
+ contents = elf_section_data (sec)->this_hdr.contents;
+ else
+ {
+ contents = (bfd_byte *) bfd_malloc (sec->_raw_size);
+ if (contents == NULL)
+ goto error_return;
+ free_contents = contents;
+
+ if (! bfd_get_section_contents (abfd, sec, contents,
+ (file_ptr) 0, sec->_raw_size))
+ goto error_return;
+ }
+
+ /* Read this BFD's symbols. */
+ if (symtab_hdr->contents != NULL)
+ extsyms = (ElfNN_External_Sym *) symtab_hdr->contents;
+ else
+ {
+ extsyms = (ElfNN_External_Sym *) bfd_malloc (symtab_hdr->sh_size);
+ if (extsyms == NULL)
+ goto error_return;
+ free_extsyms = extsyms;
+ if (bfd_seek (abfd, symtab_hdr->sh_offset, SEEK_SET) != 0
+ || (bfd_read (extsyms, 1, symtab_hdr->sh_size, abfd)
+ != symtab_hdr->sh_size))
+ goto error_return;
+ }
+
+ for (; irel < irelend; irel++)
+ {
+ bfd_vma symaddr, reladdr, trampoff, toff, roff;
+ Elf_Internal_Sym isym;
+ asection *tsec;
+ struct one_fixup *f;
+
+ if (ELFNN_R_TYPE (irel->r_info) != (int) R_IA64_PCREL21B)
+ continue;
+
+ /* Get the value of the symbol referred to by the reloc. */
+ if (ELFNN_R_SYM (irel->r_info) < symtab_hdr->sh_info)
+ {
+ /* A local symbol. */
+ bfd_elfNN_swap_symbol_in (abfd,
+ extsyms + ELFNN_R_SYM (irel->r_info),
+ &isym);
+ if (isym.st_shndx == SHN_UNDEF)
+ continue; /* We can't do anthing with undefined symbols. */
+ else if (isym.st_shndx == SHN_ABS)
+ tsec = bfd_abs_section_ptr;
+ else if (isym.st_shndx == SHN_COMMON)
+ tsec = bfd_com_section_ptr;
+ else if (isym.st_shndx > 0 && isym.st_shndx < SHN_LORESERVE)
+ tsec = bfd_section_from_elf_index (abfd, isym.st_shndx);
+ else
+ continue; /* who knows. */
+
+ toff = isym.st_value;
+ }
+ else
+ {
+ unsigned long indx;
+ struct elf_link_hash_entry *h;
+ struct elfNN_ia64_dyn_sym_info *dyn_i;
+
+ indx = ELFNN_R_SYM (irel->r_info) - symtab_hdr->sh_info;
+ h = elf_sym_hashes (abfd)[indx];
+ BFD_ASSERT (h != NULL);
+
+ while (h->root.type == bfd_link_hash_indirect
+ || h->root.type == bfd_link_hash_warning)
+ h = (struct elf_link_hash_entry *) h->root.u.i.link;
+
+ dyn_i = get_dyn_sym_info (ia64_info, h, abfd, irel, false);
+
+ /* For branches to dynamic symbols, we're interested instead
+ in a branch to the PLT entry. */
+ if (dyn_i && dyn_i->want_plt2)
+ {
+ tsec = ia64_info->plt_sec;
+ toff = dyn_i->plt2_offset;
+ }
+ else
+ {
+ /* We can't do anthing with undefined symbols. */
+ if (h->root.type == bfd_link_hash_undefined
+ || h->root.type == bfd_link_hash_undefweak)
+ continue;
+
+ tsec = h->root.u.def.section;
+ toff = h->root.u.def.value;
+ }
+ }
+
+ symaddr = (tsec->output_section->vma
+ + tsec->output_offset
+ + toff
+ + irel->r_addend);
+
+ roff = irel->r_offset;
+ reladdr = (sec->output_section->vma
+ + sec->output_offset
+ + roff) & -4;
+
+ /* If the branch is in range, no need to do anything. */
+ if ((bfd_signed_vma) (symaddr - reladdr) >= -0x1000000
+ && (bfd_signed_vma) (symaddr - reladdr) <= 0x0FFFFF0)
+ continue;
+
+ /* If the branch and target are in the same section, you've
+ got one honking big section and we can't help you. You'll
+ get an error message later. */
+ if (tsec == sec)
+ continue;
+
+ /* Look for an existing fixup to this address. */
+ for (f = fixups; f ; f = f->next)
+ if (f->tsec == tsec && f->toff == toff)
+ break;
+
+ if (f == NULL)
+ {
+ /* Two alternatives: If it's a branch to a PLT entry, we can
+ make a copy of the FULL_PLT entry. Otherwise, we'll have
+ to use a `brl' insn to get where we're going. */
+
+ int size;
+
+ if (tsec == ia64_info->plt_sec)
+ size = sizeof (plt_full_entry);
+ else
+ {
+#ifdef USE_BRL
+ size = sizeof (oor_brl);
+#else
+ size = sizeof (oor_ip);
+#endif
+ }
+
+ /* Resize the current section to make room for the new branch. */
+ trampoff = (sec->_cooked_size + 15) & -16;
+ contents = (bfd_byte *) bfd_realloc (contents, trampoff + size);
+ if (contents == NULL)
+ goto error_return;
+ sec->_cooked_size = trampoff + size;
+
+ if (tsec == ia64_info->plt_sec)
+ {
+ memcpy (contents + trampoff, plt_full_entry, size);
+
+ /* Hijack the old relocation for use as the PLTOFF reloc. */
+ irel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (irel->r_info),
+ R_IA64_PLTOFF22);
+ irel->r_offset = trampoff;
+ }
+ else
+ {
+#ifdef USE_BRL
+ memcpy (contents + trampoff, oor_brl, size);
+ irel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (irel->r_info),
+ R_IA64_PCREL60B);
+ irel->r_offset = trampoff + 2;
+#else
+ memcpy (contents + trampoff, oor_ip, size);
+ irel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (irel->r_info),
+ R_IA64_PCREL64I);
+ irel->r_addend -= 16;
+ irel->r_offset = trampoff + 2;
+#endif
+ }
+
+ /* Record the fixup so we don't do it again this section. */
+ f = (struct one_fixup *) bfd_malloc (sizeof (*f));
+ f->next = fixups;
+ f->tsec = tsec;
+ f->toff = toff;
+ f->trampoff = trampoff;
+ fixups = f;
+ }
+ else
+ {
+ /* Nop out the reloc, since we're finalizing things here. */
+ irel->r_info = ELFNN_R_INFO (0, R_IA64_NONE);
+ }
+
+ /* Fix up the existing branch to hit the trampoline. Hope like
+ hell this doesn't overflow too. */
+ if (elfNN_ia64_install_value (abfd, contents + roff,
+ f->trampoff - (roff & -4),
+ R_IA64_PCREL21B) != bfd_reloc_ok)
+ goto error_return;
+
+ changed_contents = true;
+ changed_relocs = true;
+ }
+
+ /* Clean up and go home. */
+ while (fixups)
+ {
+ struct one_fixup *f = fixups;
+ fixups = fixups->next;
+ free (f);
+ }
+
+ if (changed_relocs)
+ elf_section_data (sec)->relocs = internal_relocs;
+ else if (free_relocs != NULL)
+ free (free_relocs);
+
+ if (changed_contents)
+ elf_section_data (sec)->this_hdr.contents = contents;
+ else if (free_contents != NULL)
+ {
+ if (! link_info->keep_memory)
+ free (free_contents);
+ else
+ {
+ /* Cache the section contents for elf_link_input_bfd. */
+ elf_section_data (sec)->this_hdr.contents = contents;
+ }
+ }
+
+ if (free_extsyms != NULL)
+ {
+ if (! link_info->keep_memory)
+ free (free_extsyms);
+ else
+ {
+ /* Cache the symbols for elf_link_input_bfd. */
+ symtab_hdr->contents = extsyms;
+ }
+ }
+
+ *again = changed_contents || changed_relocs;
+ return true;
+
+ error_return:
+ if (free_relocs != NULL)
+ free (free_relocs);
+ if (free_contents != NULL)
+ free (free_contents);
+ if (free_extsyms != NULL)
+ free (free_extsyms);
+ return false;
+}
+
+/* Return true if NAME is an unwind table section name. */
+
+static inline boolean
+is_unwind_section_name (name)
+ const char *name;
+{
+ size_t len1, len2, len3;
+
+ len1 = sizeof (ELF_STRING_ia64_unwind) - 1;
+ len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
+ len3 = sizeof (ELF_STRING_ia64_unwind_once) - 1;
+ return ((strncmp (name, ELF_STRING_ia64_unwind, len1) == 0
+ && strncmp (name, ELF_STRING_ia64_unwind_info, len2) != 0)
+ || strncmp (name, ELF_STRING_ia64_unwind_once, len3) == 0);
+}
+
+/* Handle an IA-64 specific section when reading an object file. This
+ is called when elfcode.h finds a section with an unknown type. */
+
+static boolean
+elfNN_ia64_section_from_shdr (abfd, hdr, name)
+ bfd *abfd;
+ ElfNN_Internal_Shdr *hdr;
+ char *name;
+{
+ asection *newsect;
+
+ /* There ought to be a place to keep ELF backend specific flags, but
+ at the moment there isn't one. We just keep track of the
+ sections by their name, instead. Fortunately, the ABI gives
+ suggested names for all the MIPS specific sections, so we will
+ probably get away with this. */
+ switch (hdr->sh_type)
+ {
+ case SHT_IA_64_UNWIND:
+ break;
+
+ case SHT_IA_64_EXT:
+ if (strcmp (name, ELF_STRING_ia64_archext) != 0)
+ return false;
+ break;
+
+ default:
+ return false;
+ }
+
+ if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
+ return false;
+ newsect = hdr->bfd_section;
+
+ return true;
+}
+
+/* Convert IA-64 specific section flags to bfd internal section flags. */
+
+/* ??? There is no bfd internal flag equivalent to the SHF_IA_64_NORECOV
+ flag. */
+
+static boolean
+elfNN_ia64_section_flags (flags, hdr)
+ flagword *flags;
+ ElfNN_Internal_Shdr *hdr;
+{
+ if (hdr->sh_flags & SHF_IA_64_SHORT)
+ *flags |= SEC_SMALL_DATA;
+
+ return true;
+}
+
+/* Set the correct type for an IA-64 ELF section. We do this by the
+ section name, which is a hack, but ought to work. */
+
+static boolean
+elfNN_ia64_fake_sections (abfd, hdr, sec)
+ bfd *abfd ATTRIBUTE_UNUSED;
+ ElfNN_Internal_Shdr *hdr;
+ asection *sec;
+{
+ register const char *name;
+
+ name = bfd_get_section_name (abfd, sec);
+
+ if (is_unwind_section_name (name))
+ {
+ /* We don't have the sections numbered at this point, so sh_info
+ is set later, in elfNN_ia64_final_write_processing. */
+ hdr->sh_type = SHT_IA_64_UNWIND;
+ hdr->sh_flags |= SHF_LINK_ORDER;
+ }
+ else if (strcmp (name, ELF_STRING_ia64_archext) == 0)
+ hdr->sh_type = SHT_IA_64_EXT;
+ else if (strcmp (name, ".reloc") == 0)
+ /*
+ * This is an ugly, but unfortunately necessary hack that is
+ * needed when producing EFI binaries on IA-64. It tells
+ * elf.c:elf_fake_sections() not to consider ".reloc" as a section
+ * containing ELF relocation info. We need this hack in order to
+ * be able to generate ELF binaries that can be translated into
+ * EFI applications (which are essentially COFF objects). Those
+ * files contain a COFF ".reloc" section inside an ELFNN object,
+ * which would normally cause BFD to segfault because it would
+ * attempt to interpret this section as containing relocation
+ * entries for section "oc". With this hack enabled, ".reloc"
+ * will be treated as a normal data section, which will avoid the
+ * segfault. However, you won't be able to create an ELFNN binary
+ * with a section named "oc" that needs relocations, but that's
+ * the kind of ugly side-effects you get when detecting section
+ * types based on their names... In practice, this limitation is
+ * unlikely to bite.
+ */
+ hdr->sh_type = SHT_PROGBITS;
+
+ if (sec->flags & SEC_SMALL_DATA)
+ hdr->sh_flags |= SHF_IA_64_SHORT;
+
+ return true;
+}
+
+/* The final processing done just before writing out an IA-64 ELF
+ object file. */
+
+static void
+elfNN_ia64_final_write_processing (abfd, linker)
+ bfd *abfd;
+ boolean linker ATTRIBUTE_UNUSED;
+{
+ Elf_Internal_Shdr *hdr;
+ const char *sname;
+ asection *text_sect, *s;
+ size_t len;
+
+ for (s = abfd->sections; s; s = s->next)
+ {
+ hdr = &elf_section_data (s)->this_hdr;
+ switch (hdr->sh_type)
+ {
+ case SHT_IA_64_UNWIND:
+ /* See comments in gas/config/tc-ia64.c:dot_endp on why we
+ have to do this. */
+ sname = bfd_get_section_name (abfd, s);
+ len = sizeof (ELF_STRING_ia64_unwind) - 1;
+ if (sname && strncmp (sname, ELF_STRING_ia64_unwind, len) == 0)
+ {
+ sname += len;
+
+ if (sname[0] == '\0')
+ /* .IA_64.unwind -> .text */
+ text_sect = bfd_get_section_by_name (abfd, ".text");
+ else
+ /* .IA_64.unwindFOO -> FOO */
+ text_sect = bfd_get_section_by_name (abfd, sname);
+ }
+ else if (sname
+ && (len = sizeof (ELF_STRING_ia64_unwind_once) - 1,
+ strncmp (sname, ELF_STRING_ia64_unwind_once, len)) == 0)
+ {
+ /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.t.FOO */
+ size_t len2 = sizeof (".gnu.linkonce.t.") - 1;
+ char *once_name = alloca (len2 + strlen (sname) - len + 1);
+
+ memcpy (once_name, ".gnu.linkonce.t.", len2);
+ strcpy (once_name + len2, sname + len);
+ text_sect = bfd_get_section_by_name (abfd, once_name);
+ }
+ else
+ /* last resort: fall back on .text */
+ text_sect = bfd_get_section_by_name (abfd, ".text");
+
+ if (text_sect)
+ {
+ /* The IA-64 processor-specific ABI requires setting
+ sh_link to the unwind section, whereas HP-UX requires
+ sh_info to do so. For maximum compatibility, we'll
+ set both for now... */
+ hdr->sh_link = elf_section_data (text_sect)->this_idx;
+ hdr->sh_info = elf_section_data (text_sect)->this_idx;
+ }
+ break;
+ }
+ }
+}
+
+/* Hook called by the linker routine which adds symbols from an object
+ file. We use it to put .comm items in .sbss, and not .bss. */
+
+static boolean
+elfNN_ia64_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
+ bfd *abfd;
+ struct bfd_link_info *info;
+ const Elf_Internal_Sym *sym;
+ const char **namep ATTRIBUTE_UNUSED;
+ flagword *flagsp ATTRIBUTE_UNUSED;
+ asection **secp;
+ bfd_vma *valp;
+{
+ if (sym->st_shndx == SHN_COMMON
+ && !info->relocateable
+ && sym->st_size <= (unsigned) bfd_get_gp_size (abfd))
+ {
+ /* Common symbols less than or equal to -G nn bytes are
+ automatically put into .sbss. */
+
+ asection *scomm = bfd_get_section_by_name (abfd, ".scommon");
+
+ if (scomm == NULL)
+ {
+ scomm = bfd_make_section (abfd, ".scommon");
+ if (scomm == NULL
+ || !bfd_set_section_flags (abfd, scomm, (SEC_ALLOC
+ | SEC_IS_COMMON
+ | SEC_LINKER_CREATED)))
+ return false;
+ }
+
+ *secp = scomm;
+ *valp = sym->st_size;
+ }
+
+ return true;
+}
+
+/* Return the number of additional phdrs we will need. */
+
+static int
+elfNN_ia64_additional_program_headers (abfd)
+ bfd *abfd;
+{
+ asection *s;
+ int ret = 0;
+
+ /* See if we need a PT_IA_64_ARCHEXT segment. */
+ s = bfd_get_section_by_name (abfd, ELF_STRING_ia64_archext);
+ if (s && (s->flags & SEC_LOAD))
+ ++ret;
+
+ /* Count how many PT_IA_64_UNWIND segments we need. */
+ for (s = abfd->sections; s; s = s->next)
+ if (is_unwind_section_name(s->name) && (s->flags & SEC_LOAD))
+ ++ret;
+
+ return ret;
+}
+
+static boolean
+elfNN_ia64_modify_segment_map (abfd)
+ bfd *abfd;
+{
+ struct elf_segment_map *m, **pm;
+ Elf_Internal_Shdr *hdr;
+ asection *s;
+
+ /* If we need a PT_IA_64_ARCHEXT segment, it must come before
+ all PT_LOAD segments. */
+ s = bfd_get_section_by_name (abfd, ELF_STRING_ia64_archext);
+ if (s && (s->flags & SEC_LOAD))
+ {
+ for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
+ if (m->p_type == PT_IA_64_ARCHEXT)
+ break;
+ if (m == NULL)
+ {
+ m = (struct elf_segment_map *) bfd_zalloc (abfd, sizeof *m);
+ if (m == NULL)
+ return false;
+
+ m->p_type = PT_IA_64_ARCHEXT;
+ m->count = 1;
+ m->sections[0] = s;
+
+ /* We want to put it after the PHDR and INTERP segments. */
+ pm = &elf_tdata (abfd)->segment_map;
+ while (*pm != NULL
+ && ((*pm)->p_type == PT_PHDR
+ || (*pm)->p_type == PT_INTERP))
+ pm = &(*pm)->next;
+
+ m->next = *pm;
+ *pm = m;
+ }
+ }
+
+ /* Install PT_IA_64_UNWIND segments, if needed. */
+ for (s = abfd->sections; s; s = s->next)
+ {
+ hdr = &elf_section_data (s)->this_hdr;
+ if (hdr->sh_type != SHT_IA_64_UNWIND)
+ continue;
+
+ if (s && (s->flags & SEC_LOAD))
+ {
+ for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
+ if (m->p_type == PT_IA_64_UNWIND && m->sections[0] == s)
+ break;
+
+ if (m == NULL)
+ {
+ m = (struct elf_segment_map *) bfd_zalloc (abfd, sizeof *m);
+ if (m == NULL)
+ return false;
+
+ m->p_type = PT_IA_64_UNWIND;
+ m->count = 1;
+ m->sections[0] = s;
+ m->next = NULL;
+
+ /* We want to put it last. */
+ pm = &elf_tdata (abfd)->segment_map;
+ while (*pm != NULL)
+ pm = &(*pm)->next;
+ *pm = m;
+ }
+ }
+ }
+
+ /* Turn on PF_IA_64_NORECOV if needed. This involves traversing all of
+ the input sections for each output section in the segment and testing
+ for SHF_IA_64_NORECOV on each. */
+ for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
+ if (m->p_type == PT_LOAD)
+ {
+ int i;
+ for (i = m->count - 1; i >= 0; --i)
+ {
+ struct bfd_link_order *order = m->sections[i]->link_order_head;
+ while (order)
+ {
+ if (order->type == bfd_indirect_link_order)
+ {
+ asection *is = order->u.indirect.section;
+ bfd_vma flags = elf_section_data(is)->this_hdr.sh_flags;
+ if (flags & SHF_IA_64_NORECOV)
+ {
+ m->p_flags |= PF_IA_64_NORECOV;
+ goto found;
+ }
+ }
+ order = order->next;
+ }
+ }
+ found:;
+ }
+
+ return true;
+}
+
+/* According to the Tahoe assembler spec, all labels starting with a
+ '.' are local. */
+
+static boolean
+elfNN_ia64_is_local_label_name (abfd, name)
+ bfd *abfd ATTRIBUTE_UNUSED;
+ const char *name;
+{
+ return name[0] == '.';
+}
+
+/* Should we do dynamic things to this symbol? */
+
+static boolean
+elfNN_ia64_dynamic_symbol_p (h, info)
+ struct elf_link_hash_entry *h;
+ struct bfd_link_info *info;
+{
+ if (h == NULL)
+ return false;
+
+ while (h->root.type == bfd_link_hash_indirect
+ || h->root.type == bfd_link_hash_warning)
+ h = (struct elf_link_hash_entry *) h->root.u.i.link;
+
+ if (h->dynindx == -1)
+ return false;
+ switch (ELF_ST_VISIBILITY (h->other))
+ {
+ case STV_INTERNAL:
+ case STV_HIDDEN:
+ return false;
+ }
+
+ if (h->root.type == bfd_link_hash_undefweak
+ || h->root.type == bfd_link_hash_defweak)
+ return true;
+
+ if ((info->shared && !info->symbolic)
+ || ((h->elf_link_hash_flags
+ & (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR))
+ == (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR)))
+ return true;
+
+ return false;
+}
+
+static boolean
+elfNN_ia64_local_hash_table_init (ht, abfd, new)
+ struct elfNN_ia64_local_hash_table *ht;
+ bfd *abfd ATTRIBUTE_UNUSED;
+ new_hash_entry_func new;
+{
+ memset (ht, 0, sizeof (*ht));
+ return bfd_hash_table_init (&ht->root, new);
+}
+
+static struct bfd_hash_entry*
+elfNN_ia64_new_loc_hash_entry (entry, table, string)
+ struct bfd_hash_entry *entry;
+ struct bfd_hash_table *table;
+ const char *string;
+{
+ struct elfNN_ia64_local_hash_entry *ret;
+ ret = (struct elfNN_ia64_local_hash_entry *) entry;
+
+ /* Allocate the structure if it has not already been allocated by a
+ subclass. */
+ if (!ret)
+ ret = bfd_hash_allocate (table, sizeof (*ret));
+
+ if (!ret)
+ return 0;
+
+ /* Initialize our local data. All zeros, and definitely easier
+ than setting a handful of bit fields. */
+ memset (ret, 0, sizeof (*ret));
+
+ /* Call the allocation method of the superclass. */
+ ret = ((struct elfNN_ia64_local_hash_entry *)
+ bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
+
+ return (struct bfd_hash_entry *) ret;
+}
+
+static struct bfd_hash_entry*
+elfNN_ia64_new_elf_hash_entry (entry, table, string)
+ struct bfd_hash_entry *entry;
+ struct bfd_hash_table *table;
+ const char *string;
+{
+ struct elfNN_ia64_link_hash_entry *ret;
+ ret = (struct elfNN_ia64_link_hash_entry *) entry;
+
+ /* Allocate the structure if it has not already been allocated by a
+ subclass. */
+ if (!ret)
+ ret = bfd_hash_allocate (table, sizeof (*ret));
+
+ if (!ret)
+ return 0;
+
+ /* Initialize our local data. All zeros, and definitely easier
+ than setting a handful of bit fields. */
+ memset (ret, 0, sizeof (*ret));
+
+ /* Call the allocation method of the superclass. */
+ ret = ((struct elfNN_ia64_link_hash_entry *)
+ _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
+ table, string));
+
+ return (struct bfd_hash_entry *) ret;
+}
+
+static void
+elfNN_ia64_hash_copy_indirect (xdir, xind)
+ struct elf_link_hash_entry *xdir, *xind;
+{
+ struct elfNN_ia64_link_hash_entry *dir, *ind;
+
+ dir = (struct elfNN_ia64_link_hash_entry *)xdir;
+ ind = (struct elfNN_ia64_link_hash_entry *)xind;
+
+ /* Copy down any references that we may have already seen to the
+ symbol which just became indirect. */
+
+ dir->root.elf_link_hash_flags |=
+ (ind->root.elf_link_hash_flags
+ & (ELF_LINK_HASH_REF_DYNAMIC
+ | ELF_LINK_HASH_REF_REGULAR
+ | ELF_LINK_HASH_REF_REGULAR_NONWEAK));
+
+ /* Copy over the got and plt data. This would have been done
+ by check_relocs. */
+
+ if (dir->info == NULL)
+ {
+ struct elfNN_ia64_dyn_sym_info *dyn_i;
+
+ dir->info = dyn_i = ind->info;
+ ind->info = NULL;
+
+ /* Fix up the dyn_sym_info pointers to the global symbol. */
+ for (; dyn_i; dyn_i = dyn_i->next)
+ dyn_i->h = &dir->root;
+ }
+ BFD_ASSERT (ind->info == NULL);
+
+ /* Copy over the dynindx. */
+
+ if (dir->root.dynindx == -1)
+ {
+ dir->root.dynindx = ind->root.dynindx;
+ dir->root.dynstr_index = ind->root.dynstr_index;
+ ind->root.dynindx = -1;
+ ind->root.dynstr_index = 0;
+ }
+ BFD_ASSERT (ind->root.dynindx == -1);
+}
+
+static void
+elfNN_ia64_hash_hide_symbol (info, xh)
+ struct bfd_link_info *info ATTRIBUTE_UNUSED;
+ struct elf_link_hash_entry *xh;
+{
+ struct elfNN_ia64_link_hash_entry *h;
+ struct elfNN_ia64_dyn_sym_info *dyn_i;
+
+ h = (struct elfNN_ia64_link_hash_entry *)xh;
+
+ h->root.elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
+ if ((h->root.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)
+ h->root.dynindx = -1;
+
+ for (dyn_i = h->info; dyn_i; dyn_i = dyn_i->next)
+ dyn_i->want_plt2 = 0;
+}
+
+/* Create the derived linker hash table. The IA-64 ELF port uses this
+ derived hash table to keep information specific to the IA-64 ElF
+ linker (without using static variables). */
+
+static struct bfd_link_hash_table*
+elfNN_ia64_hash_table_create (abfd)
+ bfd *abfd;
+{
+ struct elfNN_ia64_link_hash_table *ret;
+
+ ret = bfd_alloc (abfd, sizeof (*ret));
+ if (!ret)
+ return 0;
+ if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
+ elfNN_ia64_new_elf_hash_entry))
+ {
+ bfd_release (abfd, ret);
+ return 0;
+ }
+
+ if (!elfNN_ia64_local_hash_table_init (&ret->loc_hash_table, abfd,
+ elfNN_ia64_new_loc_hash_entry))
+ return 0;
+ return &ret->root.root;
+}
+
+/* Look up an entry in a Alpha ELF linker hash table. */
+
+static INLINE struct elfNN_ia64_local_hash_entry *
+elfNN_ia64_local_hash_lookup(table, string, create, copy)
+ struct elfNN_ia64_local_hash_table *table;
+ const char *string;
+ boolean create, copy;
+{
+ return ((struct elfNN_ia64_local_hash_entry *)
+ bfd_hash_lookup (&table->root, string, create, copy));
+}
+
+/* Traverse both local and global hash tables. */
+
+struct elfNN_ia64_dyn_sym_traverse_data
+{
+ boolean (*func) PARAMS ((struct elfNN_ia64_dyn_sym_info *, PTR));
+ PTR data;
+};
+
+static boolean
+elfNN_ia64_global_dyn_sym_thunk (xentry, xdata)
+ struct bfd_hash_entry *xentry;
+ PTR xdata;
+{
+ struct elfNN_ia64_link_hash_entry *entry
+ = (struct elfNN_ia64_link_hash_entry *) xentry;
+ struct elfNN_ia64_dyn_sym_traverse_data *data
+ = (struct elfNN_ia64_dyn_sym_traverse_data *) xdata;
+ struct elfNN_ia64_dyn_sym_info *dyn_i;
+
+ for (dyn_i = entry->info; dyn_i; dyn_i = dyn_i->next)
+ if (! (*data->func) (dyn_i, data->data))
+ return false;
+ return true;
+}
+
+static boolean
+elfNN_ia64_local_dyn_sym_thunk (xentry, xdata)
+ struct bfd_hash_entry *xentry;
+ PTR xdata;
+{
+ struct elfNN_ia64_local_hash_entry *entry
+ = (struct elfNN_ia64_local_hash_entry *) xentry;
+ struct elfNN_ia64_dyn_sym_traverse_data *data
+ = (struct elfNN_ia64_dyn_sym_traverse_data *) xdata;
+ struct elfNN_ia64_dyn_sym_info *dyn_i;
+
+ for (dyn_i = entry->info; dyn_i; dyn_i = dyn_i->next)
+ if (! (*data->func) (dyn_i, data->data))
+ return false;
+ return true;
+}
+
+static void
+elfNN_ia64_dyn_sym_traverse (ia64_info, func, data)
+ struct elfNN_ia64_link_hash_table *ia64_info;
+ boolean (*func) PARAMS ((struct elfNN_ia64_dyn_sym_info *, PTR));
+ PTR data;
+{
+ struct elfNN_ia64_dyn_sym_traverse_data xdata;
+
+ xdata.func = func;
+ xdata.data = data;
+
+ elf_link_hash_traverse (&ia64_info->root,
+ elfNN_ia64_global_dyn_sym_thunk, &xdata);
+ bfd_hash_traverse (&ia64_info->loc_hash_table.root,
+ elfNN_ia64_local_dyn_sym_thunk, &xdata);
+}
+
+static boolean
+elfNN_ia64_create_dynamic_sections (abfd, info)
+ bfd *abfd;
+ struct bfd_link_info *info;
+{
+ struct elfNN_ia64_link_hash_table *ia64_info;
+ asection *s;
+
+ if (! _bfd_elf_create_dynamic_sections (abfd, info))
+ return false;
+
+ ia64_info = elfNN_ia64_hash_table (info);
+
+ ia64_info->plt_sec = bfd_get_section_by_name (abfd, ".plt");
+ ia64_info->got_sec = bfd_get_section_by_name (abfd, ".got");
+
+ {
+ flagword flags = bfd_get_section_flags (abfd, ia64_info->got_sec);
+ bfd_set_section_flags (abfd, ia64_info->got_sec, SEC_SMALL_DATA | flags);
+ }
+
+ if (!get_pltoff (abfd, info, ia64_info))
+ return false;
+
+ s = bfd_make_section(abfd, ".rela.IA_64.pltoff");
+ if (s == NULL
+ || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
+ | SEC_HAS_CONTENTS
+ | SEC_IN_MEMORY
+ | SEC_LINKER_CREATED
+ | SEC_READONLY))
+ || !bfd_set_section_alignment (abfd, s, 3))
+ return false;
+ ia64_info->rel_pltoff_sec = s;
+
+ s = bfd_make_section(abfd, ".rela.got");
+ if (s == NULL
+ || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
+ | SEC_HAS_CONTENTS
+ | SEC_IN_MEMORY
+ | SEC_LINKER_CREATED
+ | SEC_READONLY))
+ || !bfd_set_section_alignment (abfd, s, 3))
+ return false;
+ ia64_info->rel_got_sec = s;
+
+ return true;
+}
+
+/* Find and/or create a descriptor for dynamic symbol info. This will
+ vary based on global or local symbol, and the addend to the reloc. */
+
+static struct elfNN_ia64_dyn_sym_info *
+get_dyn_sym_info (ia64_info, h, abfd, rel, create)
+ struct elfNN_ia64_link_hash_table *ia64_info;
+ struct elf_link_hash_entry *h;
+ bfd *abfd;
+ const Elf_Internal_Rela *rel;
+ boolean create;
+{
+ struct elfNN_ia64_dyn_sym_info **pp;
+ struct elfNN_ia64_dyn_sym_info *dyn_i;
+ bfd_vma addend = rel ? rel->r_addend : 0;
+
+ if (h)
+ pp = &((struct elfNN_ia64_link_hash_entry *)h)->info;
+ else
+ {
+ struct elfNN_ia64_local_hash_entry *loc_h;
+ char *addr_name;
+ size_t len;
+
+ /* Construct a string for use in the elfNN_ia64_local_hash_table.
+ The name describes what was once anonymous memory. */
+
+ len = sizeof (void*)*2 + 1 + sizeof (bfd_vma)*4 + 1 + 1;
+ len += 10; /* %p slop */
+
+ addr_name = alloca (len);
+ sprintf (addr_name, "%p:%lx", (void *) abfd, ELFNN_R_SYM (rel->r_info));
+
+ /* Collect the canonical entry data for this address. */
+ loc_h = elfNN_ia64_local_hash_lookup (&ia64_info->loc_hash_table,
+ addr_name, create, create);
+ BFD_ASSERT (loc_h);
+
+ pp = &loc_h->info;
+ }
+
+ for (dyn_i = *pp; dyn_i && dyn_i->addend != addend; dyn_i = *pp)
+ pp = &dyn_i->next;
+
+ if (dyn_i == NULL && create)
+ {
+ dyn_i = (struct elfNN_ia64_dyn_sym_info *)
+ bfd_zalloc (abfd, sizeof *dyn_i);
+ *pp = dyn_i;
+ dyn_i->addend = addend;
+ }
+
+ return dyn_i;
+}
+
+static asection *
+get_got (abfd, info, ia64_info)
+ bfd *abfd;
+ struct bfd_link_info *info;
+ struct elfNN_ia64_link_hash_table *ia64_info;
+{
+ asection *got;
+ bfd *dynobj;
+
+ got = ia64_info->got_sec;
+ if (!got)
+ {
+ flagword flags;
+
+ dynobj = ia64_info->root.dynobj;
+ if (!dynobj)
+ ia64_info->root.dynobj = dynobj = abfd;
+ if (!_bfd_elf_create_got_section (dynobj, info))
+ return 0;
+
+ got = bfd_get_section_by_name (dynobj, ".got");
+ BFD_ASSERT (got);
+ ia64_info->got_sec = got;
+
+ flags = bfd_get_section_flags (abfd, got);
+ bfd_set_section_flags (abfd, got, SEC_SMALL_DATA | flags);
+ }
+
+ return got;
+}
+
+/* Create function descriptor section (.opd). This section is called .opd
+ because it contains "official prodecure descriptors". The "official"
+ refers to the fact that these descriptors are used when taking the address
+ of a procedure, thus ensuring a unique address for each procedure. */
+
+static asection *
+get_fptr (abfd, info, ia64_info)
+ bfd *abfd;
+ struct bfd_link_info *info ATTRIBUTE_UNUSED;
+ struct elfNN_ia64_link_hash_table *ia64_info;
+{
+ asection *fptr;
+ bfd *dynobj;
+
+ fptr = ia64_info->fptr_sec;
+ if (!fptr)
+ {
+ dynobj = ia64_info->root.dynobj;
+ if (!dynobj)
+ ia64_info->root.dynobj = dynobj = abfd;
+
+ fptr = bfd_make_section (dynobj, ".opd");
+ if (!fptr
+ || !bfd_set_section_flags (dynobj, fptr,
+ (SEC_ALLOC
+ | SEC_LOAD
+ | SEC_HAS_CONTENTS
+ | SEC_IN_MEMORY
+ | SEC_READONLY
+ | SEC_LINKER_CREATED))
+ || !bfd_set_section_alignment (abfd, fptr, 4))
+ {
+ BFD_ASSERT (0);
+ return NULL;
+ }
+
+ ia64_info->fptr_sec = fptr;
+ }
+
+ return fptr;
+}
+
+static asection *
+get_pltoff (abfd, info, ia64_info)
+ bfd *abfd;
+ struct bfd_link_info *info ATTRIBUTE_UNUSED;
+ struct elfNN_ia64_link_hash_table *ia64_info;
+{
+ asection *pltoff;
+ bfd *dynobj;
+
+ pltoff = ia64_info->pltoff_sec;
+ if (!pltoff)
+ {
+ dynobj = ia64_info->root.dynobj;
+ if (!dynobj)
+ ia64_info->root.dynobj = dynobj = abfd;
+
+ pltoff = bfd_make_section (dynobj, ELF_STRING_ia64_pltoff);
+ if (!pltoff
+ || !bfd_set_section_flags (dynobj, pltoff,
+ (SEC_ALLOC
+ | SEC_LOAD
+ | SEC_HAS_CONTENTS
+ | SEC_IN_MEMORY
+ | SEC_SMALL_DATA
+ | SEC_LINKER_CREATED))
+ || !bfd_set_section_alignment (abfd, pltoff, 4))
+ {
+ BFD_ASSERT (0);
+ return NULL;
+ }
+
+ ia64_info->pltoff_sec = pltoff;
+ }
+
+ return pltoff;
+}
+
+static asection *
+get_reloc_section (abfd, ia64_info, sec, create)
+ bfd *abfd;
+ struct elfNN_ia64_link_hash_table *ia64_info;
+ asection *sec;
+ boolean create;
+{
+ const char *srel_name;
+ asection *srel;
+ bfd *dynobj;
+
+ srel_name = (bfd_elf_string_from_elf_section
+ (abfd, elf_elfheader(abfd)->e_shstrndx,
+ elf_section_data(sec)->rel_hdr.sh_name));
+ if (srel_name == NULL)
+ return NULL;
+
+ BFD_ASSERT ((strncmp (srel_name, ".rela", 5) == 0
+ && strcmp (bfd_get_section_name (abfd, sec),
+ srel_name+5) == 0)
+ || (strncmp (srel_name, ".rel", 4) == 0
+ && strcmp (bfd_get_section_name (abfd, sec),
+ srel_name+4) == 0));
+
+ dynobj = ia64_info->root.dynobj;
+ if (!dynobj)
+ ia64_info->root.dynobj = dynobj = abfd;
+
+ srel = bfd_get_section_by_name (dynobj, srel_name);
+ if (srel == NULL && create)
+ {
+ srel = bfd_make_section (dynobj, srel_name);
+ if (srel == NULL
+ || !bfd_set_section_flags (dynobj, srel,
+ (SEC_ALLOC
+ | SEC_LOAD
+ | SEC_HAS_CONTENTS
+ | SEC_IN_MEMORY
+ | SEC_LINKER_CREATED
+ | SEC_READONLY))
+ || !bfd_set_section_alignment (dynobj, srel, 3))
+ return NULL;
+ }
+
+ return srel;
+}
+
+static boolean
+count_dyn_reloc (abfd, dyn_i, srel, type)
+ bfd *abfd;
+ struct elfNN_ia64_dyn_sym_info *dyn_i;
+ asection *srel;
+ int type;
+{
+ struct elfNN_ia64_dyn_reloc_entry *rent;
+
+ for (rent = dyn_i->reloc_entries; rent; rent = rent->next)
+ if (rent->srel == srel && rent->type == type)
+ break;
+
+ if (!rent)
+ {
+ rent = (struct elfNN_ia64_dyn_reloc_entry *)
+ bfd_alloc (abfd, sizeof (*rent));
+ if (!rent)
+ return false;
+
+ rent->next = dyn_i->reloc_entries;
+ rent->srel = srel;
+ rent->type = type;
+ rent->count = 0;
+ dyn_i->reloc_entries = rent;
+ }
+ rent->count++;
+
+ return true;
+}
+
+static boolean
+elfNN_ia64_check_relocs (abfd, info, sec, relocs)
+ bfd *abfd;
+ struct bfd_link_info *info;
+ asection *sec;
+ const Elf_Internal_Rela *relocs;
+{
+ struct elfNN_ia64_link_hash_table *ia64_info;
+ const Elf_Internal_Rela *relend;
+ Elf_Internal_Shdr *symtab_hdr;
+ const Elf_Internal_Rela *rel;
+ asection *got, *fptr, *srel;
+
+ if (info->relocateable)
+ return true;
+
+ symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+ ia64_info = elfNN_ia64_hash_table (info);
+
+ got = fptr = srel = NULL;
+
+ relend = relocs + sec->reloc_count;
+ for (rel = relocs; rel < relend; ++rel)
+ {
+ enum {
+ NEED_GOT = 1,
+ NEED_FPTR = 2,
+ NEED_PLTOFF = 4,
+ NEED_MIN_PLT = 8,
+ NEED_FULL_PLT = 16,
+ NEED_DYNREL = 32,
+ NEED_LTOFF_FPTR = 64,
+ };
+
+ struct elf_link_hash_entry *h = NULL;
+ unsigned long r_symndx = ELFNN_R_SYM (rel->r_info);
+ struct elfNN_ia64_dyn_sym_info *dyn_i;
+ int need_entry;
+ boolean maybe_dynamic;
+ int dynrel_type = R_IA64_NONE;
+
+ if (r_symndx >= symtab_hdr->sh_info)
+ {
+ /* We're dealing with a global symbol -- find its hash entry
+ and mark it as being referenced. */
+ long indx = r_symndx - symtab_hdr->sh_info;
+ h = elf_sym_hashes (abfd)[indx];
+ while (h->root.type == bfd_link_hash_indirect
+ || h->root.type == bfd_link_hash_warning)
+ h = (struct elf_link_hash_entry *) h->root.u.i.link;
+
+ h->elf_link_hash_flags |= ELF_LINK_HASH_REF_REGULAR;
+ }
+
+ /* We can only get preliminary data on whether a symbol is
+ locally or externally defined, as not all of the input files
+ have yet been processed. Do something with what we know, as
+ this may help reduce memory usage and processing time later. */
+ maybe_dynamic = false;
+ if (h && ((info->shared && ! info->symbolic)
+ || ! (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)
+ || h->root.type == bfd_link_hash_defweak))
+ maybe_dynamic = true;
+
+ need_entry = 0;
+ switch (ELFNN_R_TYPE (rel->r_info))
+ {
+ case R_IA64_TPREL22:
+ case R_IA64_TPREL64MSB:
+ case R_IA64_TPREL64LSB:
+ case R_IA64_LTOFF_TP22:
+ return false;
+
+ case R_IA64_LTOFF_FPTR22:
+ case R_IA64_LTOFF_FPTR64I:
+ case R_IA64_LTOFF_FPTR64MSB:
+ case R_IA64_LTOFF_FPTR64LSB:
+ need_entry = NEED_FPTR | NEED_GOT | NEED_LTOFF_FPTR;
+ break;
+
+ case R_IA64_FPTR64I:
+ case R_IA64_FPTR32MSB:
+ case R_IA64_FPTR32LSB:
+ case R_IA64_FPTR64MSB:
+ case R_IA64_FPTR64LSB:
+ if (info->shared || h)
+ need_entry = NEED_FPTR | NEED_DYNREL;
+ else
+ need_entry = NEED_FPTR;
+ dynrel_type = R_IA64_FPTR64LSB;
+ break;
+
+ case R_IA64_LTOFF22:
+ case R_IA64_LTOFF22X:
+ case R_IA64_LTOFF64I:
+ need_entry = NEED_GOT;
+ break;
+
+ case R_IA64_PLTOFF22:
+ case R_IA64_PLTOFF64I:
+ case R_IA64_PLTOFF64MSB:
+ case R_IA64_PLTOFF64LSB:
+ need_entry = NEED_PLTOFF;
+ if (h)
+ {
+ if (maybe_dynamic)
+ need_entry |= NEED_MIN_PLT;
+ }
+ else
+ {
+ (*info->callbacks->warning)
+ (info, _("@pltoff reloc against local symbol"), 0,
+ abfd, 0, 0);
+ }
+ break;
+
+ case R_IA64_PCREL21B:
+ case R_IA64_PCREL60B:
+ /* Depending on where this symbol is defined, we may or may not
+ need a full plt entry. Only skip if we know we'll not need
+ the entry -- static or symbolic, and the symbol definition
+ has already been seen. */
+ if (maybe_dynamic && rel->r_addend == 0)
+ need_entry = NEED_FULL_PLT;
+ break;
+
+ case R_IA64_IMM14:
+ case R_IA64_IMM22:
+ case R_IA64_IMM64:
+ case R_IA64_DIR32MSB:
+ case R_IA64_DIR32LSB:
+ case R_IA64_DIR64MSB:
+ case R_IA64_DIR64LSB:
+ /* Shared objects will always need at least a REL relocation. */
+ if (info->shared || maybe_dynamic)
+ need_entry = NEED_DYNREL;
+ dynrel_type = R_IA64_DIR64LSB;
+ break;
+
+ case R_IA64_IPLTMSB:
+ case R_IA64_IPLTLSB:
+ /* Shared objects will always need at least a REL relocation. */
+ if (info->shared || maybe_dynamic)
+ need_entry = NEED_DYNREL;
+ dynrel_type = R_IA64_IPLTLSB;
+ break;
+
+ case R_IA64_PCREL22:
+ case R_IA64_PCREL64I:
+ case R_IA64_PCREL32MSB:
+ case R_IA64_PCREL32LSB:
+ case R_IA64_PCREL64MSB:
+ case R_IA64_PCREL64LSB:
+ if (maybe_dynamic)
+ need_entry = NEED_DYNREL;
+ dynrel_type = R_IA64_PCREL64LSB;
+ break;
+ }
+
+ if (!need_entry)
+ continue;
+
+ if ((need_entry & NEED_FPTR) != 0
+ && rel->r_addend)
+ {
+ (*info->callbacks->warning)
+ (info, _("non-zero addend in @fptr reloc"), 0,
+ abfd, 0, 0);
+ }
+
+ dyn_i = get_dyn_sym_info (ia64_info, h, abfd, rel, true);
+
+ /* Record whether or not this is a local symbol. */
+ dyn_i->h = h;
+
+ /* Create what's needed. */
+ if (need_entry & NEED_GOT)
+ {
+ if (!got)
+ {
+ got = get_got (abfd, info, ia64_info);
+ if (!got)
+ return false;
+ }
+ dyn_i->want_got = 1;
+ }
+ if (need_entry & NEED_FPTR)
+ {
+ if (!fptr)
+ {
+ fptr = get_fptr (abfd, info, ia64_info);
+ if (!fptr)
+ return false;
+ }
+
+ /* FPTRs for shared libraries are allocated by the dynamic
+ linker. Make sure this local symbol will appear in the
+ dynamic symbol table. */
+ if (!h && info->shared)
+ {
+ if (! (_bfd_elfNN_link_record_local_dynamic_symbol
+ (info, abfd, r_symndx)))
+ return false;
+ }
+
+ dyn_i->want_fptr = 1;
+ }
+ if (need_entry & NEED_LTOFF_FPTR)
+ dyn_i->want_ltoff_fptr = 1;
+ if (need_entry & (NEED_MIN_PLT | NEED_FULL_PLT))
+ {
+ if (!ia64_info->root.dynobj)
+ ia64_info->root.dynobj = abfd;
+ h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
+ dyn_i->want_plt = 1;
+ }
+ if (need_entry & NEED_FULL_PLT)
+ dyn_i->want_plt2 = 1;
+ if (need_entry & NEED_PLTOFF)
+ dyn_i->want_pltoff = 1;
+ if ((need_entry & NEED_DYNREL) && (sec->flags & SEC_ALLOC))
+ {
+ if (!srel)
+ {
+ srel = get_reloc_section (abfd, ia64_info, sec, true);
+ if (!srel)
+ return false;
+ }
+ if (!count_dyn_reloc (abfd, dyn_i, srel, dynrel_type))
+ return false;
+ }
+ }
+
+ return true;
+}
+
+struct elfNN_ia64_allocate_data
+{
+ struct bfd_link_info *info;
+ bfd_size_type ofs;
+};
+
+/* For cleanliness, and potentially faster dynamic loading, allocate
+ external GOT entries first. */
+
+static boolean
+allocate_global_data_got (dyn_i, data)
+ struct elfNN_ia64_dyn_sym_info *dyn_i;
+ PTR data;
+{
+ struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data;
+
+ if (dyn_i->want_got
+ && ! dyn_i->want_fptr
+ && elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info))
+ {
+ dyn_i->got_offset = x->ofs;
+ x->ofs += 8;
+ }
+ return true;
+}
+
+/* Next, allocate all the GOT entries used by LTOFF_FPTR relocs. */
+
+static boolean
+allocate_global_fptr_got (dyn_i, data)
+ struct elfNN_ia64_dyn_sym_info *dyn_i;
+ PTR data;
+{
+ struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data;
+
+ if (dyn_i->want_got
+ && dyn_i->want_fptr
+ && elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info))
+ {
+ dyn_i->got_offset = x->ofs;
+ x->ofs += 8;
+ }
+ return true;
+}
+
+/* Lastly, allocate all the GOT entries for local data. */
+
+static boolean
+allocate_local_got (dyn_i, data)
+ struct elfNN_ia64_dyn_sym_info *dyn_i;
+ PTR data;
+{
+ struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data;
+
+ if (dyn_i->want_got
+ && ! elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info))
+ {
+ dyn_i->got_offset = x->ofs;
+ x->ofs += 8;
+ }
+ return true;
+}
+
+/* Search for the index of a global symbol in it's defining object file. */
+
+static unsigned long
+global_sym_index (h)
+ struct elf_link_hash_entry *h;
+{
+ struct elf_link_hash_entry **p;
+ bfd *obj;
+
+ BFD_ASSERT (h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak);
+
+ obj = h->root.u.def.section->owner;
+ for (p = elf_sym_hashes (obj); *p != h; ++p)
+ continue;
+
+ return p - elf_sym_hashes (obj) + elf_tdata (obj)->symtab_hdr.sh_info;
+}
+
+/* Allocate function descriptors. We can do these for every function
+ in a main executable that is not exported. */
+
+static boolean
+allocate_fptr (dyn_i, data)
+ struct elfNN_ia64_dyn_sym_info *dyn_i;
+ PTR data;
+{
+ struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data;
+
+ if (dyn_i->want_fptr)
+ {
+ struct elf_link_hash_entry *h = dyn_i->h;
+
+ if (h)
+ while (h->root.type == bfd_link_hash_indirect
+ || h->root.type == bfd_link_hash_warning)
+ h = (struct elf_link_hash_entry *) h->root.u.i.link;
+
+ if (x->info->shared)
+ {
+ if (h && h->dynindx == -1)
+ {
+ BFD_ASSERT ((h->root.type == bfd_link_hash_defined)
+ || (h->root.type == bfd_link_hash_defweak));
+
+ if (!_bfd_elfNN_link_record_local_dynamic_symbol
+ (x->info, h->root.u.def.section->owner,
+ global_sym_index (h)))
+ return false;
+ }
+
+ dyn_i->want_fptr = 0;
+ }
+ else if (h == NULL || h->dynindx == -1)
+ {
+ dyn_i->fptr_offset = x->ofs;
+ x->ofs += 16;
+ }
+ else
+ dyn_i->want_fptr = 0;
+ }
+ return true;
+}
+
+/* Allocate all the minimal PLT entries. */
+
+static boolean
+allocate_plt_entries (dyn_i, data)
+ struct elfNN_ia64_dyn_sym_info *dyn_i;
+ PTR data;
+{
+ struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data;
+
+ if (dyn_i->want_plt)
+ {
+ struct elf_link_hash_entry *h = dyn_i->h;
+
+ if (h)
+ while (h->root.type == bfd_link_hash_indirect
+ || h->root.type == bfd_link_hash_warning)
+ h = (struct elf_link_hash_entry *) h->root.u.i.link;
+
+ /* ??? Versioned symbols seem to lose ELF_LINK_HASH_NEEDS_PLT. */
+ if (elfNN_ia64_dynamic_symbol_p (h, x->info))
+ {
+ bfd_size_type offset = x->ofs;
+ if (offset == 0)
+ offset = PLT_HEADER_SIZE;
+ dyn_i->plt_offset = offset;
+ x->ofs = offset + PLT_MIN_ENTRY_SIZE;
+
+ dyn_i->want_pltoff = 1;
+ }
+ else
+ {
+ dyn_i->want_plt = 0;
+ dyn_i->want_plt2 = 0;
+ }
+ }
+ return true;
+}
+
+/* Allocate all the full PLT entries. */
+
+static boolean
+allocate_plt2_entries (dyn_i, data)
+ struct elfNN_ia64_dyn_sym_info *dyn_i;
+ PTR data;
+{
+ struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data;
+
+ if (dyn_i->want_plt2)
+ {
+ struct elf_link_hash_entry *h = dyn_i->h;
+ bfd_size_type ofs = x->ofs;
+
+ dyn_i->plt2_offset = ofs;
+ x->ofs = ofs + PLT_FULL_ENTRY_SIZE;
+
+ while (h->root.type == bfd_link_hash_indirect
+ || h->root.type == bfd_link_hash_warning)
+ h = (struct elf_link_hash_entry *) h->root.u.i.link;
+ dyn_i->h->plt.offset = ofs;
+ }
+ return true;
+}
+
+/* Allocate all the PLTOFF entries requested by relocations and
+ plt entries. We can't share space with allocated FPTR entries,
+ because the latter are not necessarily addressable by the GP.
+ ??? Relaxation might be able to determine that they are. */
+
+static boolean
+allocate_pltoff_entries (dyn_i, data)
+ struct elfNN_ia64_dyn_sym_info *dyn_i;
+ PTR data;
+{
+ struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data;
+
+ if (dyn_i->want_pltoff)
+ {
+ dyn_i->pltoff_offset = x->ofs;
+ x->ofs += 16;
+ }
+ return true;
+}
+
+/* Allocate dynamic relocations for those symbols that turned out
+ to be dynamic. */
+
+static boolean
+allocate_dynrel_entries (dyn_i, data)
+ struct elfNN_ia64_dyn_sym_info *dyn_i;
+ PTR data;
+{
+ struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data;
+ struct elfNN_ia64_link_hash_table *ia64_info;
+ struct elfNN_ia64_dyn_reloc_entry *rent;
+ boolean dynamic_symbol, shared;
+
+ ia64_info = elfNN_ia64_hash_table (x->info);
+ dynamic_symbol = elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info);
+ shared = x->info->shared;
+
+ /* Take care of the normal data relocations. */
+
+ for (rent = dyn_i->reloc_entries; rent; rent = rent->next)
+ {
+ int count = rent->count;
+
+ switch (rent->type)
+ {
+ case R_IA64_FPTR64LSB:
+ /* Allocate one iff !want_fptr, which by this point will
+ be true only if we're actually allocating one statically
+ in the main executable. */
+ if (dyn_i->want_fptr)
+ continue;
+ break;
+ case R_IA64_PCREL64LSB:
+ if (!dynamic_symbol)
+ continue;
+ break;
+ case R_IA64_DIR64LSB:
+ if (!dynamic_symbol && !shared)
+ continue;
+ break;
+ case R_IA64_IPLTLSB:
+ if (!dynamic_symbol && !shared)
+ continue;
+ /* Use two REL relocations for IPLT relocations
+ against local symbols. */
+ if (!dynamic_symbol)
+ count *= 2;
+ break;
+ default:
+ abort ();
+ }
+ rent->srel->_raw_size += sizeof (ElfNN_External_Rela) * count;
+ }
+
+ /* Take care of the GOT and PLT relocations. */
+
+ if (((dynamic_symbol || shared) && dyn_i->want_got)
+ || (dyn_i->want_ltoff_fptr && dyn_i->h && dyn_i->h->dynindx != -1))
+ ia64_info->rel_got_sec->_raw_size += sizeof (ElfNN_External_Rela);
+
+ if (dyn_i->want_pltoff)
+ {
+ bfd_size_type t = 0;
+
+ /* Dynamic symbols get one IPLT relocation. Local symbols in
+ shared libraries get two REL relocations. Local symbols in
+ main applications get nothing. */
+ if (dynamic_symbol)
+ t = sizeof (ElfNN_External_Rela);
+ else if (shared)
+ t = 2 * sizeof (ElfNN_External_Rela);
+
+ ia64_info->rel_pltoff_sec->_raw_size += t;
+ }
+
+ return true;
+}
+
+static boolean
+elfNN_ia64_adjust_dynamic_symbol (info, h)
+ struct bfd_link_info *info ATTRIBUTE_UNUSED;
+ struct elf_link_hash_entry *h;
+{
+ /* ??? Undefined symbols with PLT entries should be re-defined
+ to be the PLT entry. */
+
+ /* If this is a weak symbol, and there is a real definition, the
+ processor independent code will have arranged for us to see the
+ real definition first, and we can just use the same value. */
+ if (h->weakdef != NULL)
+ {
+ BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
+ || h->weakdef->root.type == bfd_link_hash_defweak);
+ h->root.u.def.section = h->weakdef->root.u.def.section;
+ h->root.u.def.value = h->weakdef->root.u.def.value;
+ return true;
+ }
+
+ /* If this is a reference to a symbol defined by a dynamic object which
+ is not a function, we might allocate the symbol in our .dynbss section
+ and allocate a COPY dynamic relocation.
+
+ But IA-64 code is canonically PIC, so as a rule we can avoid this sort
+ of hackery. */
+
+ return true;
+}
+
+static boolean
+elfNN_ia64_size_dynamic_sections (output_bfd, info)
+ bfd *output_bfd;
+ struct bfd_link_info *info;
+{
+ struct elfNN_ia64_allocate_data data;
+ struct elfNN_ia64_link_hash_table *ia64_info;
+ asection *sec;
+ bfd *dynobj;
+ boolean reltext = false;
+ boolean relplt = false;
+
+ dynobj = elf_hash_table(info)->dynobj;
+ ia64_info = elfNN_ia64_hash_table (info);
+ BFD_ASSERT(dynobj != NULL);
+ data.info = info;
+
+ /* Set the contents of the .interp section to the interpreter. */
+ if (ia64_info->root.dynamic_sections_created
+ && !info->shared)
+ {
+ sec = bfd_get_section_by_name (dynobj, ".interp");
+ BFD_ASSERT (sec != NULL);
+ sec->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER;
+ sec->_raw_size = strlen (ELF_DYNAMIC_INTERPRETER) + 1;
+ }
+
+ /* Allocate the GOT entries. */
+
+ if (ia64_info->got_sec)
+ {
+ data.ofs = 0;
+ elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_global_data_got, &data);
+ elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_global_fptr_got, &data);
+ elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_local_got, &data);
+ ia64_info->got_sec->_raw_size = data.ofs;
+ }
+
+ /* Allocate the FPTR entries. */
+
+ if (ia64_info->fptr_sec)
+ {
+ data.ofs = 0;
+ elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_fptr, &data);
+ ia64_info->fptr_sec->_raw_size = data.ofs;
+ }
+
+ /* Now that we've seen all of the input files, we can decide which
+ symbols need plt entries. Allocate the minimal PLT entries first.
+ We do this even though dynamic_sections_created may be false, because
+ this has the side-effect of clearing want_plt and want_plt2. */
+
+ data.ofs = 0;
+ elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_plt_entries, &data);
+
+ ia64_info->minplt_entries = 0;
+ if (data.ofs)
+ {
+ ia64_info->minplt_entries
+ = (data.ofs - PLT_HEADER_SIZE) / PLT_MIN_ENTRY_SIZE;
+ }
+
+ /* Align the pointer for the plt2 entries. */
+ data.ofs = (data.ofs + 31) & -32;
+
+ elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_plt2_entries, &data);
+ if (data.ofs != 0)
+ {
+ BFD_ASSERT (ia64_info->root.dynamic_sections_created);
+
+ ia64_info->plt_sec->_raw_size = data.ofs;
+
+ /* If we've got a .plt, we need some extra memory for the dynamic
+ linker. We stuff these in .got.plt. */
+ sec = bfd_get_section_by_name (dynobj, ".got.plt");
+ sec->_raw_size = 8 * PLT_RESERVED_WORDS;
+ }
+
+ /* Allocate the PLTOFF entries. */
+
+ if (ia64_info->pltoff_sec)
+ {
+ data.ofs = 0;
+ elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_pltoff_entries, &data);
+ ia64_info->pltoff_sec->_raw_size = data.ofs;
+ }
+
+ if (ia64_info->root.dynamic_sections_created)
+ {
+ /* Allocate space for the dynamic relocations that turned out to be
+ required. */
+
+ elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_dynrel_entries, &data);
+ }
+
+ /* We have now determined the sizes of the various dynamic sections.
+ Allocate memory for them. */
+ for (sec = dynobj->sections; sec != NULL; sec = sec->next)
+ {
+ boolean strip;
+
+ if (!(sec->flags & SEC_LINKER_CREATED))
+ continue;
+
+ /* If we don't need this section, strip it from the output file.
+ There were several sections primarily related to dynamic
+ linking that must be create before the linker maps input
+ sections to output sections. The linker does that before
+ bfd_elf_size_dynamic_sections is called, and it is that
+ function which decides whether anything needs to go into
+ these sections. */
+
+ strip = (sec->_raw_size == 0);
+
+ if (sec == ia64_info->got_sec)
+ strip = false;
+ else if (sec == ia64_info->rel_got_sec)
+ {
+ if (strip)
+ ia64_info->rel_got_sec = NULL;
+ else
+ /* We use the reloc_count field as a counter if we need to
+ copy relocs into the output file. */
+ sec->reloc_count = 0;
+ }
+ else if (sec == ia64_info->fptr_sec)
+ {
+ if (strip)
+ ia64_info->fptr_sec = NULL;
+ }
+ else if (sec == ia64_info->plt_sec)
+ {
+ if (strip)
+ ia64_info->plt_sec = NULL;
+ }
+ else if (sec == ia64_info->pltoff_sec)
+ {
+ if (strip)
+ ia64_info->pltoff_sec = NULL;
+ }
+ else if (sec == ia64_info->rel_pltoff_sec)
+ {
+ if (strip)
+ ia64_info->rel_pltoff_sec = NULL;
+ else
+ {
+ relplt = true;
+ /* We use the reloc_count field as a counter if we need to
+ copy relocs into the output file. */
+ sec->reloc_count = 0;
+ }
+ }
+ else
+ {
+ const char *name;
+
+ /* It's OK to base decisions on the section name, because none
+ of the dynobj section names depend upon the input files. */
+ name = bfd_get_section_name (dynobj, sec);
+
+ if (strcmp (name, ".got.plt") == 0)
+ strip = false;
+ else if (strncmp (name, ".rel", 4) == 0)
+ {
+ if (!strip)
+ {
+ const char *outname;
+ asection *target;
+
+ /* If this relocation section applies to a read only
+ section, then we probably need a DT_TEXTREL entry. */
+ outname = bfd_get_section_name (output_bfd,
+ sec->output_section);
+ if (outname[4] == 'a')
+ outname += 5;
+ else
+ outname += 4;
+
+ target = bfd_get_section_by_name (output_bfd, outname);
+ if (target != NULL
+ && (target->flags & SEC_READONLY) != 0
+ && (target->flags & SEC_ALLOC) != 0)
+ reltext = true;
+
+ /* We use the reloc_count field as a counter if we need to
+ copy relocs into the output file. */
+ sec->reloc_count = 0;
+ }
+ }
+ else
+ continue;
+ }
+
+ if (strip)
+ _bfd_strip_section_from_output (info, sec);
+ else
+ {
+ /* Allocate memory for the section contents. */
+ sec->contents = (bfd_byte *) bfd_zalloc(dynobj, sec->_raw_size);
+ if (sec->contents == NULL && sec->_raw_size != 0)
+ return false;
+ }
+ }
+
+ if (elf_hash_table (info)->dynamic_sections_created)
+ {
+ /* Add some entries to the .dynamic section. We fill in the values
+ later (in finish_dynamic_sections) but we must add the entries now
+ so that we get the correct size for the .dynamic section. */
+
+ if (!info->shared)
+ {
+ /* The DT_DEBUG entry is filled in by the dynamic linker and used
+ by the debugger. */
+ if (!bfd_elfNN_add_dynamic_entry (info, DT_DEBUG, 0))
+ return false;
+ }
+
+ if (! bfd_elfNN_add_dynamic_entry (info, DT_IA_64_PLT_RESERVE, 0))
+ return false;
+ if (! bfd_elfNN_add_dynamic_entry (info, DT_PLTGOT, 0))
+ return false;
+
+ if (relplt)
+ {
+ if (! bfd_elfNN_add_dynamic_entry (info, DT_PLTRELSZ, 0)
+ || ! bfd_elfNN_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
+ || ! bfd_elfNN_add_dynamic_entry (info, DT_JMPREL, 0))
+ return false;
+ }
+
+ if (! bfd_elfNN_add_dynamic_entry (info, DT_RELA, 0)
+ || ! bfd_elfNN_add_dynamic_entry (info, DT_RELASZ, 0)
+ || ! bfd_elfNN_add_dynamic_entry (info, DT_RELAENT,
+ sizeof (ElfNN_External_Rela)))
+ return false;
+
+ if (reltext)
+ {
+ if (! bfd_elfNN_add_dynamic_entry (info, DT_TEXTREL, 0))
+ return false;
+ info->flags |= DF_TEXTREL;
+ }
+ }
+
+ /* ??? Perhaps force __gp local. */
+
+ return true;
+}
+
+static bfd_reloc_status_type
+elfNN_ia64_install_value (abfd, hit_addr, val, r_type)
+ bfd *abfd;
+ bfd_byte *hit_addr;
+ bfd_vma val;
+ unsigned int r_type;
+{
+ const struct ia64_operand *op;
+ int bigendian = 0, shift = 0;
+ bfd_vma t0, t1, insn, dword;
+ enum ia64_opnd opnd;
+ const char *err;
+ size_t size = 8;
+
+ opnd = IA64_OPND_NIL;
+ switch (r_type)
+ {
+ case R_IA64_NONE:
+ case R_IA64_LDXMOV:
+ return bfd_reloc_ok;
+
+ /* Instruction relocations. */
+
+ case R_IA64_IMM14: opnd = IA64_OPND_IMM14; break;
+
+ case R_IA64_PCREL21F: opnd = IA64_OPND_TGT25; break;
+ case R_IA64_PCREL21M: opnd = IA64_OPND_TGT25b; break;
+ case R_IA64_PCREL60B: opnd = IA64_OPND_TGT64; break;
+ case R_IA64_PCREL21B:
+ case R_IA64_PCREL21BI:
+ opnd = IA64_OPND_TGT25c;
+ break;
+
+ case R_IA64_IMM22:
+ case R_IA64_GPREL22:
+ case R_IA64_LTOFF22:
+ case R_IA64_LTOFF22X:
+ case R_IA64_PLTOFF22:
+ case R_IA64_PCREL22:
+ case R_IA64_LTOFF_FPTR22:
+ opnd = IA64_OPND_IMM22;
+ break;
+
+ case R_IA64_IMM64:
+ case R_IA64_GPREL64I:
+ case R_IA64_LTOFF64I:
+ case R_IA64_PLTOFF64I:
+ case R_IA64_PCREL64I:
+ case R_IA64_FPTR64I:
+ case R_IA64_LTOFF_FPTR64I:
+ opnd = IA64_OPND_IMMU64;
+ break;
+
+ /* Data relocations. */
+
+ case R_IA64_DIR32MSB:
+ case R_IA64_GPREL32MSB:
+ case R_IA64_FPTR32MSB:
+ case R_IA64_PCREL32MSB:
+ case R_IA64_SEGREL32MSB:
+ case R_IA64_SECREL32MSB:
+ case R_IA64_LTV32MSB:
+ size = 4; bigendian = 1;
+ break;
+
+ case R_IA64_DIR32LSB:
+ case R_IA64_GPREL32LSB:
+ case R_IA64_FPTR32LSB:
+ case R_IA64_PCREL32LSB:
+ case R_IA64_SEGREL32LSB:
+ case R_IA64_SECREL32LSB:
+ case R_IA64_LTV32LSB:
+ size = 4; bigendian = 0;
+ break;
+
+ case R_IA64_DIR64MSB:
+ case R_IA64_GPREL64MSB:
+ case R_IA64_PLTOFF64MSB:
+ case R_IA64_FPTR64MSB:
+ case R_IA64_PCREL64MSB:
+ case R_IA64_LTOFF_FPTR64MSB:
+ case R_IA64_SEGREL64MSB:
+ case R_IA64_SECREL64MSB:
+ case R_IA64_LTV64MSB:
+ size = 8; bigendian = 1;
+ break;
+
+ case R_IA64_DIR64LSB:
+ case R_IA64_GPREL64LSB:
+ case R_IA64_PLTOFF64LSB:
+ case R_IA64_FPTR64LSB:
+ case R_IA64_PCREL64LSB:
+ case R_IA64_LTOFF_FPTR64LSB:
+ case R_IA64_SEGREL64LSB:
+ case R_IA64_SECREL64LSB:
+ case R_IA64_LTV64LSB:
+ size = 8; bigendian = 0;
+ break;
+
+ /* Unsupported / Dynamic relocations. */
+ default:
+ return bfd_reloc_notsupported;
+ }
+
+ switch (opnd)
+ {
+ case IA64_OPND_IMMU64:
+ hit_addr -= (long) hit_addr & 0x3;
+ t0 = bfd_get_64 (abfd, hit_addr);
+ t1 = bfd_get_64 (abfd, hit_addr + 8);
+
+ /* tmpl/s: bits 0.. 5 in t0
+ slot 0: bits 5..45 in t0
+ slot 1: bits 46..63 in t0, bits 0..22 in t1
+ slot 2: bits 23..63 in t1 */
+
+ /* First, clear the bits that form the 64 bit constant. */
+ t0 &= ~(0x3ffffLL << 46);
+ t1 &= ~(0x7fffffLL
+ | (( (0x07fLL << 13) | (0x1ffLL << 27)
+ | (0x01fLL << 22) | (0x001LL << 21)
+ | (0x001LL << 36)) << 23));
+
+ t0 |= ((val >> 22) & 0x03ffffLL) << 46; /* 18 lsbs of imm41 */
+ t1 |= ((val >> 40) & 0x7fffffLL) << 0; /* 23 msbs of imm41 */
+ t1 |= ( (((val >> 0) & 0x07f) << 13) /* imm7b */
+ | (((val >> 7) & 0x1ff) << 27) /* imm9d */
+ | (((val >> 16) & 0x01f) << 22) /* imm5c */
+ | (((val >> 21) & 0x001) << 21) /* ic */
+ | (((val >> 63) & 0x001) << 36)) << 23; /* i */
+
+ bfd_put_64 (abfd, t0, hit_addr);
+ bfd_put_64 (abfd, t1, hit_addr + 8);
+ break;
+
+ case IA64_OPND_TGT64:
+ hit_addr -= (long) hit_addr & 0x3;
+ t0 = bfd_get_64 (abfd, hit_addr);
+ t1 = bfd_get_64 (abfd, hit_addr + 8);
+
+ /* tmpl/s: bits 0.. 5 in t0
+ slot 0: bits 5..45 in t0
+ slot 1: bits 46..63 in t0, bits 0..22 in t1
+ slot 2: bits 23..63 in t1 */
+
+ /* First, clear the bits that form the 64 bit constant. */
+ t0 &= ~(0x3ffffLL << 46);
+ t1 &= ~(0x7fffffLL
+ | ((1LL << 36 | 0xfffffLL << 13) << 23));
+
+ val >>= 4;
+ t0 |= ((val >> 20) & 0xffffLL) << 2 << 46; /* 16 lsbs of imm39 */
+ t1 |= ((val >> 36) & 0x7fffffLL) << 0; /* 23 msbs of imm39 */
+ t1 |= ((((val >> 0) & 0xfffffLL) << 13) /* imm20b */
+ | (((val >> 59) & 0x1LL) << 36)) << 23; /* i */
+
+ bfd_put_64 (abfd, t0, hit_addr);
+ bfd_put_64 (abfd, t1, hit_addr + 8);
+ break;
+
+ default:
+ switch ((long) hit_addr & 0x3)
+ {
+ case 0: shift = 5; break;
+ case 1: shift = 14; hit_addr += 3; break;
+ case 2: shift = 23; hit_addr += 6; break;
+ case 3: return bfd_reloc_notsupported; /* shouldn't happen... */
+ }
+ dword = bfd_get_64 (abfd, hit_addr);
+ insn = (dword >> shift) & 0x1ffffffffffLL;
+
+ op = elf64_ia64_operands + opnd;
+ err = (*op->insert) (op, val, &insn);
+ if (err)
+ return bfd_reloc_overflow;
+
+ dword &= ~(0x1ffffffffffLL << shift);
+ dword |= (insn << shift);
+ bfd_put_64 (abfd, dword, hit_addr);
+ break;
+
+ case IA64_OPND_NIL:
+ /* A data relocation. */
+ if (bigendian)
+ if (size == 4)
+ bfd_putb32 (val, hit_addr);
+ else
+ bfd_putb64 (val, hit_addr);
+ else
+ if (size == 4)
+ bfd_putl32 (val, hit_addr);
+ else
+ bfd_putl64 (val, hit_addr);
+ break;
+ }
+
+ return bfd_reloc_ok;
+}
+
+static void
+elfNN_ia64_install_dyn_reloc (abfd, info, sec, srel, offset, type,
+ dynindx, addend)
+ bfd *abfd;
+ struct bfd_link_info *info;
+ asection *sec;
+ asection *srel;
+ bfd_vma offset;
+ unsigned int type;
+ long dynindx;
+ bfd_vma addend;
+{
+ Elf_Internal_Rela outrel;
+
+ outrel.r_offset = (sec->output_section->vma
+ + sec->output_offset
+ + offset);
+
+ BFD_ASSERT (dynindx != -1);
+ outrel.r_info = ELFNN_R_INFO (dynindx, type);
+ outrel.r_addend = addend;
+
+ if (elf_section_data (sec)->stab_info != NULL)
+ {
+ /* This may be NULL for linker-generated relocations, as it is
+ inconvenient to pass all the bits around. And this shouldn't
+ happen. */
+ BFD_ASSERT (info != NULL);
+
+ offset = (_bfd_stab_section_offset
+ (abfd, &elf_hash_table (info)->stab_info, sec,
+ &elf_section_data (sec)->stab_info, offset));
+ if (offset == (bfd_vma) -1)
+ {
+ /* Run for the hills. We shouldn't be outputting a relocation
+ for this. So do what everyone else does and output a no-op. */
+ outrel.r_info = ELFNN_R_INFO (0, R_IA64_NONE);
+ outrel.r_addend = 0;
+ offset = 0;
+ }
+ outrel.r_offset = offset;
+ }
+
+ bfd_elfNN_swap_reloca_out (abfd, &outrel,
+ ((ElfNN_External_Rela *) srel->contents
+ + srel->reloc_count++));
+ BFD_ASSERT (sizeof (ElfNN_External_Rela) * srel->reloc_count
+ <= srel->_cooked_size);
+}
+
+/* Store an entry for target address TARGET_ADDR in the linkage table
+ and return the gp-relative address of the linkage table entry. */
+
+static bfd_vma
+set_got_entry (abfd, info, dyn_i, dynindx, addend, value, dyn_r_type)
+ bfd *abfd;
+ struct bfd_link_info *info;
+ struct elfNN_ia64_dyn_sym_info *dyn_i;
+ long dynindx;
+ bfd_vma addend;
+ bfd_vma value;
+ unsigned int dyn_r_type;
+{
+ struct elfNN_ia64_link_hash_table *ia64_info;
+ asection *got_sec;
+
+ ia64_info = elfNN_ia64_hash_table (info);
+ got_sec = ia64_info->got_sec;
+
+ BFD_ASSERT ((dyn_i->got_offset & 7) == 0);
+
+ if (! dyn_i->got_done)
+ {
+ dyn_i->got_done = true;
+
+ /* Store the target address in the linkage table entry. */
+ bfd_put_64 (abfd, value, got_sec->contents + dyn_i->got_offset);
+
+ /* Install a dynamic relocation if needed. */
+ if (info->shared
+ || elfNN_ia64_dynamic_symbol_p (dyn_i->h, info)
+ || (dynindx != -1 && dyn_r_type == R_IA64_FPTR64LSB))
+ {
+ if (dynindx == -1)
+ {
+ dyn_r_type = R_IA64_REL64LSB;
+ dynindx = 0;
+ addend = value;
+ }
+
+ if (bfd_big_endian (abfd))
+ {
+ switch (dyn_r_type)
+ {
+ case R_IA64_REL64LSB:
+ dyn_r_type = R_IA64_REL64MSB;
+ break;
+ case R_IA64_DIR64LSB:
+ dyn_r_type = R_IA64_DIR64MSB;
+ break;
+ case R_IA64_FPTR64LSB:
+ dyn_r_type = R_IA64_FPTR64MSB;
+ break;
+ default:
+ BFD_ASSERT (false);
+ break;
+ }
+ }
+
+ elfNN_ia64_install_dyn_reloc (abfd, NULL, got_sec,
+ ia64_info->rel_got_sec,
+ dyn_i->got_offset, dyn_r_type,
+ dynindx, addend);
+ }
+ }
+
+ /* Return the address of the linkage table entry. */
+ value = (got_sec->output_section->vma
+ + got_sec->output_offset
+ + dyn_i->got_offset);
+
+ return value;
+}
+
+/* Fill in a function descriptor consisting of the function's code
+ address and its global pointer. Return the descriptor's address. */
+
+static bfd_vma
+set_fptr_entry (abfd, info, dyn_i, value)
+ bfd *abfd;
+ struct bfd_link_info *info;
+ struct elfNN_ia64_dyn_sym_info *dyn_i;
+ bfd_vma value;
+{
+ struct elfNN_ia64_link_hash_table *ia64_info;
+ asection *fptr_sec;
+
+ ia64_info = elfNN_ia64_hash_table (info);
+ fptr_sec = ia64_info->fptr_sec;
+
+ if (!dyn_i->fptr_done)
+ {
+ dyn_i->fptr_done = 1;
+
+ /* Fill in the function descriptor. */
+ bfd_put_64 (abfd, value, fptr_sec->contents + dyn_i->fptr_offset);
+ bfd_put_64 (abfd, _bfd_get_gp_value (abfd),
+ fptr_sec->contents + dyn_i->fptr_offset + 8);
+ }
+
+ /* Return the descriptor's address. */
+ value = (fptr_sec->output_section->vma
+ + fptr_sec->output_offset
+ + dyn_i->fptr_offset);
+
+ return value;
+}
+
+/* Fill in a PLTOFF entry consisting of the function's code address
+ and its global pointer. Return the descriptor's address. */
+
+static bfd_vma
+set_pltoff_entry (abfd, info, dyn_i, value, is_plt)
+ bfd *abfd;
+ struct bfd_link_info *info;
+ struct elfNN_ia64_dyn_sym_info *dyn_i;
+ bfd_vma value;
+ boolean is_plt;
+{
+ struct elfNN_ia64_link_hash_table *ia64_info;
+ asection *pltoff_sec;
+
+ ia64_info = elfNN_ia64_hash_table (info);
+ pltoff_sec = ia64_info->pltoff_sec;
+
+ /* Don't do anything if this symbol uses a real PLT entry. In
+ that case, we'll fill this in during finish_dynamic_symbol. */
+ if ((! dyn_i->want_plt || is_plt)
+ && !dyn_i->pltoff_done)
+ {
+ bfd_vma gp = _bfd_get_gp_value (abfd);
+
+ /* Fill in the function descriptor. */
+ bfd_put_64 (abfd, value, pltoff_sec->contents + dyn_i->pltoff_offset);
+ bfd_put_64 (abfd, gp, pltoff_sec->contents + dyn_i->pltoff_offset + 8);
+
+ /* Install dynamic relocations if needed. */
+ if (!is_plt && info->shared)
+ {
+ unsigned int dyn_r_type;
+
+ if (bfd_big_endian (abfd))
+ dyn_r_type = R_IA64_REL64MSB;
+ else
+ dyn_r_type = R_IA64_REL64LSB;
+
+ elfNN_ia64_install_dyn_reloc (abfd, NULL, pltoff_sec,
+ ia64_info->rel_pltoff_sec,
+ dyn_i->pltoff_offset,
+ dyn_r_type, 0, value);
+ elfNN_ia64_install_dyn_reloc (abfd, NULL, pltoff_sec,
+ ia64_info->rel_pltoff_sec,
+ dyn_i->pltoff_offset + 8,
+ dyn_r_type, 0, gp);
+ }
+
+ dyn_i->pltoff_done = 1;
+ }
+
+ /* Return the descriptor's address. */
+ value = (pltoff_sec->output_section->vma
+ + pltoff_sec->output_offset
+ + dyn_i->pltoff_offset);
+
+ return value;
+}
+
+/* Called through qsort to sort the .IA_64.unwind section during a
+ non-relocatable link. Set elfNN_ia64_unwind_entry_compare_bfd
+ to the output bfd so we can do proper endianness frobbing. */
+
+static bfd *elfNN_ia64_unwind_entry_compare_bfd;
+
+static int
+elfNN_ia64_unwind_entry_compare (a, b)
+ PTR a;
+ PTR b;
+{
+ bfd_vma av, bv;
+
+ av = bfd_get_64 (elfNN_ia64_unwind_entry_compare_bfd, a);
+ bv = bfd_get_64 (elfNN_ia64_unwind_entry_compare_bfd, b);
+
+ return (av < bv ? -1 : av > bv ? 1 : 0);
+}
+
+static boolean
+elfNN_ia64_final_link (abfd, info)
+ bfd *abfd;
+ struct bfd_link_info *info;
+{
+ struct elfNN_ia64_link_hash_table *ia64_info;
+ asection *unwind_output_sec;
+
+ ia64_info = elfNN_ia64_hash_table (info);
+
+ /* Make sure we've got ourselves a nice fat __gp value. */
+ if (!info->relocateable)
+ {
+ bfd_vma min_vma = (bfd_vma) -1, max_vma = 0;
+ bfd_vma min_short_vma = min_vma, max_short_vma = 0;
+ struct elf_link_hash_entry *gp;
+ bfd_vma gp_val;
+ asection *os;
+
+ /* Find the min and max vma of all sections marked short. Also
+ collect min and max vma of any type, for use in selecting a
+ nice gp. */
+ for (os = abfd->sections; os ; os = os->next)
+ {
+ bfd_vma lo, hi;
+
+ if ((os->flags & SEC_ALLOC) == 0)
+ continue;
+
+ lo = os->vma;
+ hi = os->vma + os->_raw_size;
+ if (hi < lo)
+ hi = (bfd_vma) -1;
+
+ if (min_vma > lo)
+ min_vma = lo;
+ if (max_vma < hi)
+ max_vma = hi;
+ if (os->flags & SEC_SMALL_DATA)
+ {
+ if (min_short_vma > lo)
+ min_short_vma = lo;
+ if (max_short_vma < hi)
+ max_short_vma = hi;
+ }
+ }
+
+ /* See if the user wants to force a value. */
+ gp = elf_link_hash_lookup (elf_hash_table (info), "__gp", false,
+ false, false);
+
+ if (gp
+ && (gp->root.type == bfd_link_hash_defined
+ || gp->root.type == bfd_link_hash_defweak))
+ {
+ asection *gp_sec = gp->root.u.def.section;
+ gp_val = (gp->root.u.def.value
+ + gp_sec->output_section->vma
+ + gp_sec->output_offset);
+ }
+ else
+ {
+ /* Pick a sensible value. */
+
+ asection *got_sec = ia64_info->got_sec;
+
+ /* Start with just the address of the .got. */
+ if (got_sec)
+ gp_val = got_sec->output_section->vma;
+ else if (max_short_vma != 0)
+ gp_val = min_short_vma;
+ else
+ gp_val = min_vma;
+
+ /* If it is possible to address the entire image, but we
+ don't with the choice above, adjust. */
+ if (max_vma - min_vma < 0x400000
+ && max_vma - gp_val <= 0x200000
+ && gp_val - min_vma > 0x200000)
+ gp_val = min_vma + 0x200000;
+ else if (max_short_vma != 0)
+ {
+ /* If we don't cover all the short data, adjust. */
+ if (max_short_vma - gp_val >= 0x200000)
+ gp_val = min_short_vma + 0x200000;
+
+ /* If we're addressing stuff past the end, adjust back. */
+ if (gp_val > max_vma)
+ gp_val = max_vma - 0x200000 + 8;
+ }
+ }
+
+ /* Validate whether all SHF_IA_64_SHORT sections are within
+ range of the chosen GP. */
+
+ if (max_short_vma != 0)
+ {
+ if (max_short_vma - min_short_vma >= 0x400000)
+ {
+ (*_bfd_error_handler)
+ (_("%s: short data segment overflowed (0x%lx >= 0x400000)"),
+ bfd_get_filename (abfd),
+ (unsigned long) (max_short_vma - min_short_vma));
+ return false;
+ }
+ else if ((gp_val > min_short_vma
+ && gp_val - min_short_vma > 0x200000)
+ || (gp_val < max_short_vma
+ && max_short_vma - gp_val >= 0x200000))
+ {
+ (*_bfd_error_handler)
+ (_("%s: __gp does not cover short data segment"),
+ bfd_get_filename (abfd));
+ return false;
+ }
+ }
+
+ _bfd_set_gp_value (abfd, gp_val);
+
+ if (gp)
+ {
+ gp->root.type = bfd_link_hash_defined;
+ gp->root.u.def.value = gp_val;
+ gp->root.u.def.section = bfd_abs_section_ptr;
+ }
+ }
+
+ /* If we're producing a final executable, we need to sort the contents
+ of the .IA_64.unwind section. Force this section to be relocated
+ into memory rather than written immediately to the output file. */
+ unwind_output_sec = NULL;
+ if (!info->relocateable)
+ {
+ asection *s = bfd_get_section_by_name (abfd, ELF_STRING_ia64_unwind);
+ if (s)
+ {
+ unwind_output_sec = s->output_section;
+ unwind_output_sec->contents
+ = bfd_malloc (unwind_output_sec->_raw_size);
+ if (unwind_output_sec->contents == NULL)
+ return false;
+ }
+ }
+
+ /* Invoke the regular ELF backend linker to do all the work. */
+ if (!bfd_elfNN_bfd_final_link (abfd, info))
+ return false;
+
+ if (unwind_output_sec)
+ {
+ elfNN_ia64_unwind_entry_compare_bfd = abfd;
+ qsort (unwind_output_sec->contents, unwind_output_sec->_raw_size / 24,
+ 24, elfNN_ia64_unwind_entry_compare);
+
+ if (! bfd_set_section_contents (abfd, unwind_output_sec,
+ unwind_output_sec->contents, 0,
+ unwind_output_sec->_raw_size))
+ return false;
+ }
+
+ return true;
+}
+
+static boolean
+elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
+ contents, relocs, local_syms, local_sections)
+ 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;
+{
+ struct elfNN_ia64_link_hash_table *ia64_info;
+ Elf_Internal_Shdr *symtab_hdr;
+ Elf_Internal_Rela *rel;
+ Elf_Internal_Rela *relend;
+ asection *srel;
+ boolean ret_val = true; /* for non-fatal errors */
+ bfd_vma gp_val;
+
+ symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
+ ia64_info = elfNN_ia64_hash_table (info);
+
+ /* Infect various flags from the input section to the output section. */
+ if (info->relocateable)
+ {
+ bfd_vma flags;
+
+ flags = elf_section_data(input_section)->this_hdr.sh_flags;
+ flags &= SHF_IA_64_NORECOV;
+
+ elf_section_data(input_section->output_section)
+ ->this_hdr.sh_flags |= flags;
+ }
+
+ gp_val = _bfd_get_gp_value (output_bfd);
+ srel = get_reloc_section (input_bfd, ia64_info, input_section, false);
+
+ rel = relocs;
+ relend = relocs + input_section->reloc_count;
+ for (; rel < relend; ++rel)
+ {
+ struct elf_link_hash_entry *h;
+ struct elfNN_ia64_dyn_sym_info *dyn_i;
+ bfd_reloc_status_type r;
+ reloc_howto_type *howto;
+ unsigned long r_symndx;
+ Elf_Internal_Sym *sym;
+ unsigned int r_type;
+ bfd_vma value;
+ asection *sym_sec;
+ bfd_byte *hit_addr;
+ boolean dynamic_symbol_p;
+ boolean undef_weak_ref;
+
+ r_type = ELFNN_R_TYPE (rel->r_info);
+ if (r_type > R_IA64_MAX_RELOC_CODE)
+ {
+ (*_bfd_error_handler)
+ (_("%s: unknown relocation type %d"),
+ bfd_get_filename (input_bfd), (int)r_type);
+ bfd_set_error (bfd_error_bad_value);
+ ret_val = false;
+ continue;
+ }
+ howto = lookup_howto (r_type);
+ r_symndx = ELFNN_R_SYM (rel->r_info);
+
+ if (info->relocateable)
+ {
+ /* This is a relocateable link. We don't have to change
+ anything, unless the reloc is against a section symbol,
+ in which case we have to adjust according to where the
+ section symbol winds up in the output section. */
+ if (r_symndx < symtab_hdr->sh_info)
+ {
+ sym = local_syms + r_symndx;
+ if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
+ {
+ sym_sec = local_sections[r_symndx];
+ rel->r_addend += sym_sec->output_offset;
+ }
+ }
+ continue;
+ }
+
+ /* This is a final link. */
+
+ h = NULL;
+ sym = NULL;
+ sym_sec = NULL;
+ undef_weak_ref = false;
+
+ if (r_symndx < symtab_hdr->sh_info)
+ {
+ /* Reloc against local symbol. */
+ sym = local_syms + r_symndx;
+ sym_sec = local_sections[r_symndx];
+ value = (sym_sec->output_section->vma
+ + sym_sec->output_offset
+ + sym->st_value);
+ }
+ else
+ {
+ long indx;
+
+ /* Reloc against global symbol. */
+ indx = r_symndx - symtab_hdr->sh_info;
+ h = elf_sym_hashes (input_bfd)[indx];
+ while (h->root.type == bfd_link_hash_indirect
+ || h->root.type == bfd_link_hash_warning)
+ h = (struct elf_link_hash_entry *) h->root.u.i.link;
+
+ value = 0;
+ if (h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak)
+ {
+ sym_sec = h->root.u.def.section;
+
+ /* Detect the cases that sym_sec->output_section is
+ expected to be NULL -- all cases in which the symbol
+ is defined in another shared module. This includes
+ PLT relocs for which we've created a PLT entry and
+ other relocs for which we're prepared to create
+ dynamic relocations. */
+ /* ??? Just accept it NULL and continue. */
+
+ if (sym_sec->output_section != NULL)
+ {
+ value = (h->root.u.def.value
+ + sym_sec->output_section->vma
+ + sym_sec->output_offset);
+ }
+ }
+ else if (h->root.type == bfd_link_hash_undefweak)
+ undef_weak_ref = true;
+ else if (info->shared && !info->symbolic
+ && !info->no_undefined
+ && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
+ ;
+ else
+ {
+ if (! ((*info->callbacks->undefined_symbol)
+ (info, h->root.root.string, input_bfd,
+ input_section, rel->r_offset,
+ (!info->shared || info->no_undefined
+ || ELF_ST_VISIBILITY (h->other)))))
+ return false;
+ ret_val = false;
+ continue;
+ }
+ }
+
+ hit_addr = contents + rel->r_offset;
+ value += rel->r_addend;
+ dynamic_symbol_p = elfNN_ia64_dynamic_symbol_p (h, info);
+
+ switch (r_type)
+ {
+ case R_IA64_NONE:
+ case R_IA64_LDXMOV:
+ continue;
+
+ case R_IA64_IMM14:
+ case R_IA64_IMM22:
+ case R_IA64_IMM64:
+ case R_IA64_DIR32MSB:
+ case R_IA64_DIR32LSB:
+ case R_IA64_DIR64MSB:
+ case R_IA64_DIR64LSB:
+ /* Install a dynamic relocation for this reloc. */
+ if ((dynamic_symbol_p || info->shared)
+ && (input_section->flags & SEC_ALLOC) != 0)
+ {
+ unsigned int dyn_r_type;
+ long dynindx;
+ bfd_vma addend;
+
+ BFD_ASSERT (srel != NULL);
+
+ /* If we don't need dynamic symbol lookup, find a
+ matching RELATIVE relocation. */
+ dyn_r_type = r_type;
+ if (dynamic_symbol_p)
+ {
+ dynindx = h->dynindx;
+ addend = rel->r_addend;
+ value = 0;
+ }
+ else
+ {
+ switch (r_type)
+ {
+ case R_IA64_DIR32MSB:
+ dyn_r_type = R_IA64_REL32MSB;
+ break;
+ case R_IA64_DIR32LSB:
+ dyn_r_type = R_IA64_REL32LSB;
+ break;
+ case R_IA64_DIR64MSB:
+ dyn_r_type = R_IA64_REL64MSB;
+ break;
+ case R_IA64_DIR64LSB:
+ dyn_r_type = R_IA64_REL64LSB;
+ break;
+
+ default:
+ /* We can't represent this without a dynamic symbol.
+ Adjust the relocation to be against an output
+ section symbol, which are always present in the
+ dynamic symbol table. */
+ /* ??? People shouldn't be doing non-pic code in
+ shared libraries. Hork. */
+ (*_bfd_error_handler)
+ (_("%s: linking non-pic code in a shared library"),
+ bfd_get_filename (input_bfd));
+ ret_val = false;
+ continue;
+ }
+ dynindx = 0;
+ addend = value;
+ }
+
+ elfNN_ia64_install_dyn_reloc (output_bfd, info, input_section,
+ srel, rel->r_offset, dyn_r_type,
+ dynindx, addend);
+ }
+ /* FALLTHRU */
+
+ case R_IA64_LTV32MSB:
+ case R_IA64_LTV32LSB:
+ case R_IA64_LTV64MSB:
+ case R_IA64_LTV64LSB:
+ r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type);
+ break;
+
+ case R_IA64_GPREL22:
+ case R_IA64_GPREL64I:
+ case R_IA64_GPREL32MSB:
+ case R_IA64_GPREL32LSB:
+ case R_IA64_GPREL64MSB:
+ case R_IA64_GPREL64LSB:
+ if (dynamic_symbol_p)
+ {
+ (*_bfd_error_handler)
+ (_("%s: @gprel relocation against dynamic symbol %s"),
+ bfd_get_filename (input_bfd), h->root.root.string);
+ ret_val = false;
+ continue;
+ }
+ value -= gp_val;
+ r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type);
+ break;
+
+ case R_IA64_LTOFF22:
+ case R_IA64_LTOFF22X:
+ case R_IA64_LTOFF64I:
+ dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, false);
+ value = set_got_entry (input_bfd, info, dyn_i, (h ? h->dynindx : -1),
+ rel->r_addend, value, R_IA64_DIR64LSB);
+ value -= gp_val;
+ r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type);
+ break;
+
+ case R_IA64_PLTOFF22:
+ case R_IA64_PLTOFF64I:
+ case R_IA64_PLTOFF64MSB:
+ case R_IA64_PLTOFF64LSB:
+ dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, false);
+ value = set_pltoff_entry (output_bfd, info, dyn_i, value, false);
+ value -= gp_val;
+ r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type);
+ break;
+
+ case R_IA64_FPTR64I:
+ case R_IA64_FPTR32MSB:
+ case R_IA64_FPTR32LSB:
+ case R_IA64_FPTR64MSB:
+ case R_IA64_FPTR64LSB:
+ dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, false);
+ if (dyn_i->want_fptr)
+ {
+ if (!undef_weak_ref)
+ value = set_fptr_entry (output_bfd, info, dyn_i, value);
+ }
+ else
+ {
+ long dynindx;
+
+ /* Otherwise, we expect the dynamic linker to create
+ the entry. */
+
+ if (h)
+ {
+ if (h->dynindx != -1)
+ dynindx = h->dynindx;
+ else
+ dynindx = (_bfd_elf_link_lookup_local_dynindx
+ (info, h->root.u.def.section->owner,
+ global_sym_index (h)));
+ }
+ else
+ {
+ dynindx = (_bfd_elf_link_lookup_local_dynindx
+ (info, input_bfd, r_symndx));
+ }
+
+ elfNN_ia64_install_dyn_reloc (output_bfd, info, input_section,
+ srel, rel->r_offset, r_type,
+ dynindx, rel->r_addend);
+ value = 0;
+ }
+
+ r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type);
+ break;
+
+ case R_IA64_LTOFF_FPTR22:
+ case R_IA64_LTOFF_FPTR64I:
+ case R_IA64_LTOFF_FPTR64MSB:
+ case R_IA64_LTOFF_FPTR64LSB:
+ {
+ long dynindx;
+
+ dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, false);
+ if (dyn_i->want_fptr)
+ {
+ BFD_ASSERT (h == NULL || h->dynindx == -1)
+ if (!undef_weak_ref)
+ value = set_fptr_entry (output_bfd, info, dyn_i, value);
+ dynindx = -1;
+ }
+ else
+ {
+ /* Otherwise, we expect the dynamic linker to create
+ the entry. */
+ if (h)
+ {
+ if (h->dynindx != -1)
+ dynindx = h->dynindx;
+ else
+ dynindx = (_bfd_elf_link_lookup_local_dynindx
+ (info, h->root.u.def.section->owner,
+ global_sym_index (h)));
+ }
+ else
+ dynindx = (_bfd_elf_link_lookup_local_dynindx
+ (info, input_bfd, r_symndx));
+ value = 0;
+ }
+
+ value = set_got_entry (output_bfd, info, dyn_i, dynindx,
+ rel->r_addend, value, R_IA64_FPTR64LSB);
+ value -= gp_val;
+ r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type);
+ }
+ break;
+
+ case R_IA64_PCREL32MSB:
+ case R_IA64_PCREL32LSB:
+ case R_IA64_PCREL64MSB:
+ case R_IA64_PCREL64LSB:
+ /* Install a dynamic relocation for this reloc. */
+ if (dynamic_symbol_p)
+ {
+ BFD_ASSERT (srel != NULL);
+
+ elfNN_ia64_install_dyn_reloc (output_bfd, info, input_section,
+ srel, rel->r_offset, r_type,
+ h->dynindx, rel->r_addend);
+ }
+ goto finish_pcrel;
+
+ case R_IA64_PCREL21BI:
+ case R_IA64_PCREL21F:
+ case R_IA64_PCREL21M:
+ /* ??? These two are only used for speculation fixup code.
+ They should never be dynamic. */
+ if (dynamic_symbol_p)
+ {
+ (*_bfd_error_handler)
+ (_("%s: dynamic relocation against speculation fixup"),
+ bfd_get_filename (input_bfd));
+ ret_val = false;
+ continue;
+ }
+ if (undef_weak_ref)
+ {
+ (*_bfd_error_handler)
+ (_("%s: speculation fixup against undefined weak symbol"),
+ bfd_get_filename (input_bfd));
+ ret_val = false;
+ continue;
+ }
+ goto finish_pcrel;
+
+ case R_IA64_PCREL21B:
+ case R_IA64_PCREL60B:
+ /* We should have created a PLT entry for any dynamic symbol. */
+ dyn_i = NULL;
+ if (h)
+ dyn_i = get_dyn_sym_info (ia64_info, h, NULL, NULL, false);
+
+ if (dyn_i && dyn_i->want_plt2)
+ {
+ /* Should have caught this earlier. */
+ BFD_ASSERT (rel->r_addend == 0);
+
+ value = (ia64_info->plt_sec->output_section->vma
+ + ia64_info->plt_sec->output_offset
+ + dyn_i->plt2_offset);
+ }
+ else
+ {
+ /* Since there's no PLT entry, Validate that this is
+ locally defined. */
+ BFD_ASSERT (undef_weak_ref || sym_sec->output_section != NULL);
+
+ /* If the symbol is undef_weak, we shouldn't be trying
+ to call it. There's every chance that we'd wind up
+ with an out-of-range fixup here. Don't bother setting
+ any value at all. */
+ if (undef_weak_ref)
+ continue;
+ }
+ goto finish_pcrel;
+
+ case R_IA64_PCREL22:
+ case R_IA64_PCREL64I:
+ finish_pcrel:
+ /* Make pc-relative. */
+ value -= (input_section->output_section->vma
+ + input_section->output_offset
+ + rel->r_offset) & ~ (bfd_vma) 0x3;
+ r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type);
+ break;
+
+ case R_IA64_SEGREL32MSB:
+ case R_IA64_SEGREL32LSB:
+ case R_IA64_SEGREL64MSB:
+ case R_IA64_SEGREL64LSB:
+ {
+ struct elf_segment_map *m;
+ Elf_Internal_Phdr *p;
+
+ /* Find the segment that contains the output_section. */
+ for (m = elf_tdata (output_bfd)->segment_map,
+ p = elf_tdata (output_bfd)->phdr;
+ m != NULL;
+ m = m->next, p++)
+ {
+ int i;
+ for (i = m->count - 1; i >= 0; i--)
+ if (m->sections[i] == sym_sec->output_section)
+ break;
+ if (i >= 0)
+ break;
+ }
+
+ if (m == NULL)
+ {
+ /* If the input section was discarded from the output, then
+ do nothing. */
+
+ if (bfd_is_abs_section (sym_sec->output_section))
+ r = bfd_reloc_ok;
+ else
+ r = bfd_reloc_notsupported;
+ }
+ else
+ {
+ /* The VMA of the segment is the vaddr of the associated
+ program header. */
+ if (value > p->p_vaddr)
+ value -= p->p_vaddr;
+ else
+ value = 0;
+ r = elfNN_ia64_install_value (output_bfd, hit_addr, value,
+ r_type);
+ }
+ break;
+ }
+
+ case R_IA64_SECREL32MSB:
+ case R_IA64_SECREL32LSB:
+ case R_IA64_SECREL64MSB:
+ case R_IA64_SECREL64LSB:
+ /* Make output-section relative. */
+ if (value > input_section->output_section->vma)
+ value -= input_section->output_section->vma;
+ else
+ value = 0;
+ r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type);
+ break;
+
+ case R_IA64_IPLTMSB:
+ case R_IA64_IPLTLSB:
+ /* Install a dynamic relocation for this reloc. */
+ if ((dynamic_symbol_p || info->shared)
+ && (input_section->flags & SEC_ALLOC) != 0)
+ {
+ BFD_ASSERT (srel != NULL);
+
+ /* If we don't need dynamic symbol lookup, install two
+ RELATIVE relocations. */
+ if (! dynamic_symbol_p)
+ {
+ unsigned int dyn_r_type;
+
+ if (r_type == R_IA64_IPLTMSB)
+ dyn_r_type = R_IA64_REL64MSB;
+ else
+ dyn_r_type = R_IA64_REL64LSB;
+
+ elfNN_ia64_install_dyn_reloc (output_bfd, info,
+ input_section,
+ srel, rel->r_offset,
+ dyn_r_type, 0, value);
+ elfNN_ia64_install_dyn_reloc (output_bfd, info,
+ input_section,
+ srel, rel->r_offset + 8,
+ dyn_r_type, 0, gp_val);
+ }
+ else
+ elfNN_ia64_install_dyn_reloc (output_bfd, info, input_section,
+ srel, rel->r_offset, r_type,
+ h->dynindx, rel->r_addend);
+ }
+
+ if (r_type == R_IA64_IPLTMSB)
+ r_type = R_IA64_DIR64MSB;
+ else
+ r_type = R_IA64_DIR64LSB;
+ elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type);
+ r = elfNN_ia64_install_value (output_bfd, hit_addr + 8, gp_val,
+ r_type);
+ break;
+
+ default:
+ r = bfd_reloc_notsupported;
+ break;
+ }
+
+ switch (r)
+ {
+ case bfd_reloc_ok:
+ break;
+
+ case bfd_reloc_undefined:
+ /* This can happen for global table relative relocs if
+ __gp is undefined. This is a panic situation so we
+ don't try to continue. */
+ (*info->callbacks->undefined_symbol)
+ (info, "__gp", input_bfd, input_section, rel->r_offset, 1);
+ return false;
+
+ case bfd_reloc_notsupported:
+ {
+ const char *name;
+
+ if (h)
+ name = h->root.root.string;
+ else
+ {
+ name = bfd_elf_string_from_elf_section (input_bfd,
+ symtab_hdr->sh_link,
+ sym->st_name);
+ if (name == NULL)
+ return false;
+ if (*name == '\0')
+ name = bfd_section_name (input_bfd, input_section);
+ }
+ if (!(*info->callbacks->warning) (info, _("unsupported reloc"),
+ name, input_bfd,
+ input_section, rel->r_offset))
+ return false;
+ ret_val = false;
+ }
+ break;
+
+ case bfd_reloc_dangerous:
+ case bfd_reloc_outofrange:
+ case bfd_reloc_overflow:
+ default:
+ {
+ const char *name;
+
+ if (h)
+ name = h->root.root.string;
+ else
+ {
+ name = bfd_elf_string_from_elf_section (input_bfd,
+ symtab_hdr->sh_link,
+ sym->st_name);
+ if (name == NULL)
+ return false;
+ if (*name == '\0')
+ name = bfd_section_name (input_bfd, input_section);
+ }
+ if (!(*info->callbacks->reloc_overflow) (info, name,
+ howto->name, 0,
+ input_bfd,
+ input_section,
+ rel->r_offset))
+ return false;
+ ret_val = false;
+ }
+ break;
+ }
+ }
+
+ return ret_val;
+}
+
+static boolean
+elfNN_ia64_finish_dynamic_symbol (output_bfd, info, h, sym)
+ bfd *output_bfd;
+ struct bfd_link_info *info;
+ struct elf_link_hash_entry *h;
+ Elf_Internal_Sym *sym;
+{
+ struct elfNN_ia64_link_hash_table *ia64_info;
+ struct elfNN_ia64_dyn_sym_info *dyn_i;
+
+ ia64_info = elfNN_ia64_hash_table (info);
+ dyn_i = get_dyn_sym_info (ia64_info, h, NULL, NULL, false);
+
+ /* Fill in the PLT data, if required. */
+ if (dyn_i && dyn_i->want_plt)
+ {
+ Elf_Internal_Rela outrel;
+ bfd_byte *loc;
+ asection *plt_sec;
+ bfd_vma plt_addr, pltoff_addr, gp_val, index;
+ ElfNN_External_Rela *rel;
+
+ gp_val = _bfd_get_gp_value (output_bfd);
+
+ /* Initialize the minimal PLT entry. */
+
+ index = (dyn_i->plt_offset - PLT_HEADER_SIZE) / PLT_MIN_ENTRY_SIZE;
+ plt_sec = ia64_info->plt_sec;
+ loc = plt_sec->contents + dyn_i->plt_offset;
+
+ memcpy (loc, plt_min_entry, PLT_MIN_ENTRY_SIZE);
+ elfNN_ia64_install_value (output_bfd, loc, index, R_IA64_IMM22);
+ elfNN_ia64_install_value (output_bfd, loc+2, -dyn_i->plt_offset,
+ R_IA64_PCREL21B);
+
+ plt_addr = (plt_sec->output_section->vma
+ + plt_sec->output_offset
+ + dyn_i->plt_offset);
+ pltoff_addr = set_pltoff_entry (output_bfd, info, dyn_i, plt_addr, true);
+
+ /* Initialize the FULL PLT entry, if needed. */
+ if (dyn_i->want_plt2)
+ {
+ loc = plt_sec->contents + dyn_i->plt2_offset;
+
+ memcpy (loc, plt_full_entry, PLT_FULL_ENTRY_SIZE);
+ elfNN_ia64_install_value (output_bfd, loc, pltoff_addr - gp_val,
+ R_IA64_IMM22);
+
+ /* Mark the symbol as undefined, rather than as defined in the
+ plt section. Leave the value alone. */
+ /* ??? We didn't redefine it in adjust_dynamic_symbol in the
+ first place. But perhaps elflink.h did some for us. */
+ if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
+ sym->st_shndx = SHN_UNDEF;
+ }
+
+ /* Create the dynamic relocation. */
+ outrel.r_offset = pltoff_addr;
+ if (bfd_little_endian (output_bfd))
+ outrel.r_info = ELFNN_R_INFO (h->dynindx, R_IA64_IPLTLSB);
+ else
+ outrel.r_info = ELFNN_R_INFO (h->dynindx, R_IA64_IPLTMSB);
+ outrel.r_addend = 0;
+
+ /* This is fun. In the .IA_64.pltoff section, we've got entries
+ that correspond both to real PLT entries, and those that
+ happened to resolve to local symbols but need to be created
+ to satisfy @pltoff relocations. The .rela.IA_64.pltoff
+ relocations for the real PLT should come at the end of the
+ section, so that they can be indexed by plt entry at runtime.
+
+ We emitted all of the relocations for the non-PLT @pltoff
+ entries during relocate_section. So we can consider the
+ existing sec->reloc_count to be the base of the array of
+ PLT relocations. */
+
+ rel = (ElfNN_External_Rela *)ia64_info->rel_pltoff_sec->contents;
+ rel += ia64_info->rel_pltoff_sec->reloc_count;
+
+ bfd_elfNN_swap_reloca_out (output_bfd, &outrel, rel + index);
+ }
+
+ /* Mark some specially defined symbols as absolute. */
+ if (strcmp (h->root.root.string, "_DYNAMIC") == 0
+ || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
+ || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
+ sym->st_shndx = SHN_ABS;
+
+ return true;
+}
+
+static boolean
+elfNN_ia64_finish_dynamic_sections (abfd, info)
+ bfd *abfd;
+ struct bfd_link_info *info;
+{
+ struct elfNN_ia64_link_hash_table *ia64_info;
+ bfd *dynobj;
+
+ ia64_info = elfNN_ia64_hash_table (info);
+ dynobj = ia64_info->root.dynobj;
+
+ if (elf_hash_table (info)->dynamic_sections_created)
+ {
+ ElfNN_External_Dyn *dyncon, *dynconend;
+ asection *sdyn, *sgotplt;
+ bfd_vma gp_val;
+
+ sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
+ sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
+ BFD_ASSERT (sdyn != NULL);
+ dyncon = (ElfNN_External_Dyn *) sdyn->contents;
+ dynconend = (ElfNN_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
+
+ gp_val = _bfd_get_gp_value (abfd);
+
+ for (; dyncon < dynconend; dyncon++)
+ {
+ Elf_Internal_Dyn dyn;
+
+ bfd_elfNN_swap_dyn_in (dynobj, dyncon, &dyn);
+
+ switch (dyn.d_tag)
+ {
+ case DT_PLTGOT:
+ dyn.d_un.d_ptr = gp_val;
+ break;
+
+ case DT_PLTRELSZ:
+ dyn.d_un.d_val = (ia64_info->minplt_entries
+ * sizeof (ElfNN_External_Rela));
+ break;
+
+ case DT_JMPREL:
+ /* See the comment above in finish_dynamic_symbol. */
+ dyn.d_un.d_ptr = (ia64_info->rel_pltoff_sec->output_section->vma
+ + ia64_info->rel_pltoff_sec->output_offset
+ + (ia64_info->rel_pltoff_sec->reloc_count
+ * sizeof (ElfNN_External_Rela)));
+ break;
+
+ case DT_IA_64_PLT_RESERVE:
+ dyn.d_un.d_ptr = (sgotplt->output_section->vma
+ + sgotplt->output_offset);
+ break;
+
+ case DT_RELASZ:
+ /* Do not have RELASZ include JMPREL. This makes things
+ easier on ld.so. This is not what the rest of BFD set up. */
+ dyn.d_un.d_val -= (ia64_info->minplt_entries
+ * sizeof (ElfNN_External_Rela));
+ break;
+ }
+
+ bfd_elfNN_swap_dyn_out (abfd, &dyn, dyncon);
+ }
+
+ /* Initialize the PLT0 entry */
+ if (ia64_info->plt_sec)
+ {
+ bfd_byte *loc = ia64_info->plt_sec->contents;
+ bfd_vma pltres;
+
+ memcpy (loc, plt_header, PLT_HEADER_SIZE);
+
+ pltres = (sgotplt->output_section->vma
+ + sgotplt->output_offset
+ - gp_val);
+
+ elfNN_ia64_install_value (abfd, loc+1, pltres, R_IA64_GPREL22);
+ }
+ }
+
+ return true;
+}
+
+/* ELF file flag handling: */
+
+/* Function to keep IA-64 specific file flags. */
+static boolean
+elfNN_ia64_set_private_flags (abfd, flags)
+ bfd *abfd;
+ flagword flags;
+{
+ BFD_ASSERT (!elf_flags_init (abfd)
+ || elf_elfheader (abfd)->e_flags == flags);
+
+ elf_elfheader (abfd)->e_flags = flags;
+ elf_flags_init (abfd) = true;
+ return true;
+}
+
+/* Copy backend specific data from one object module to another */
+static boolean
+elfNN_ia64_copy_private_bfd_data (ibfd, obfd)
+ bfd *ibfd, *obfd;
+{
+ if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
+ || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
+ return true;
+
+ BFD_ASSERT (!elf_flags_init (obfd)
+ || (elf_elfheader (obfd)->e_flags
+ == elf_elfheader (ibfd)->e_flags));
+
+ elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
+ elf_flags_init (obfd) = true;
+ return true;
+}
+
+/* Merge backend specific data from an object file to the output
+ object file when linking. */
+static boolean
+elfNN_ia64_merge_private_bfd_data (ibfd, obfd)
+ bfd *ibfd, *obfd;
+{
+ flagword out_flags;
+ flagword in_flags;
+ boolean ok = true;
+
+ /* Don't even pretend to support mixed-format linking. */
+ if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
+ || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
+ return false;
+
+ in_flags = elf_elfheader (ibfd)->e_flags;
+ out_flags = elf_elfheader (obfd)->e_flags;
+
+ if (! elf_flags_init (obfd))
+ {
+ elf_flags_init (obfd) = true;
+ elf_elfheader (obfd)->e_flags = in_flags;
+
+ if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
+ && bfd_get_arch_info (obfd)->the_default)
+ {
+ return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
+ bfd_get_mach (ibfd));
+ }
+
+ return true;
+ }
+
+ /* Check flag compatibility. */
+ if (in_flags == out_flags)
+ return true;
+
+ /* Output has EF_IA_64_REDUCEDFP set only if all inputs have it set. */
+ if (!(in_flags & EF_IA_64_REDUCEDFP) && (out_flags & EF_IA_64_REDUCEDFP))
+ elf_elfheader (obfd)->e_flags &= ~EF_IA_64_REDUCEDFP;
+
+ if ((in_flags & EF_IA_64_TRAPNIL) != (out_flags & EF_IA_64_TRAPNIL))
+ {
+ (*_bfd_error_handler)
+ (_("%s: linking trap-on-NULL-dereference with non-trapping files"),
+ bfd_get_filename (ibfd));
+
+ bfd_set_error (bfd_error_bad_value);
+ ok = false;
+ }
+ if ((in_flags & EF_IA_64_BE) != (out_flags & EF_IA_64_BE))
+ {
+ (*_bfd_error_handler)
+ (_("%s: linking big-endian files with little-endian files"),
+ bfd_get_filename (ibfd));
+
+ bfd_set_error (bfd_error_bad_value);
+ ok = false;
+ }
+ if ((in_flags & EF_IA_64_ABI64) != (out_flags & EF_IA_64_ABI64))
+ {
+ (*_bfd_error_handler)
+ (_("%s: linking 64-bit files with 32-bit files"),
+ bfd_get_filename (ibfd));
+
+ bfd_set_error (bfd_error_bad_value);
+ ok = false;
+ }
+ if ((in_flags & EF_IA_64_CONS_GP) != (out_flags & EF_IA_64_CONS_GP))
+ {
+ (*_bfd_error_handler)
+ (_("%s: linking constant-gp files with non-constant-gp files"),
+ bfd_get_filename (ibfd));
+
+ bfd_set_error (bfd_error_bad_value);
+ ok = false;
+ }
+ if ((in_flags & EF_IA_64_NOFUNCDESC_CONS_GP)
+ != (out_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
+ {
+ (*_bfd_error_handler)
+ (_("%s: linking auto-pic files with non-auto-pic files"),
+ bfd_get_filename (ibfd));
+
+ bfd_set_error (bfd_error_bad_value);
+ ok = false;
+ }
+
+ return ok;
+}
+
+static boolean
+elfNN_ia64_print_private_bfd_data (abfd, ptr)
+ bfd *abfd;
+ PTR ptr;
+{
+ FILE *file = (FILE *) ptr;
+ flagword flags = elf_elfheader (abfd)->e_flags;
+
+ BFD_ASSERT (abfd != NULL && ptr != NULL);
+
+ fprintf (file, "private flags = %s%s%s%s%s%s%s%s\n",
+ (flags & EF_IA_64_TRAPNIL) ? "TRAPNIL, " : "",
+ (flags & EF_IA_64_EXT) ? "EXT, " : "",
+ (flags & EF_IA_64_BE) ? "BE, " : "LE, ",
+ (flags & EF_IA_64_REDUCEDFP) ? "REDUCEDFP, " : "",
+ (flags & EF_IA_64_CONS_GP) ? "CONS_GP, " : "",
+ (flags & EF_IA_64_NOFUNCDESC_CONS_GP) ? "NOFUNCDESC_CONS_GP, " : "",
+ (flags & EF_IA_64_ABSOLUTE) ? "ABSOLUTE, " : "",
+ (flags & EF_IA_64_ABI64) ? "ABI64" : "ABI32");
+
+ _bfd_elf_print_private_bfd_data (abfd, ptr);
+ return true;
+}
+
+#define TARGET_LITTLE_SYM bfd_elfNN_ia64_little_vec
+#define TARGET_LITTLE_NAME "elfNN-ia64-little"
+#define TARGET_BIG_SYM bfd_elfNN_ia64_big_vec
+#define TARGET_BIG_NAME "elfNN-ia64-big"
+#define ELF_ARCH bfd_arch_ia64
+#define ELF_MACHINE_CODE EM_IA_64
+#define ELF_MACHINE_ALT1 1999 /* EAS2.3 */
+#define ELF_MACHINE_ALT2 1998 /* EAS2.2 */
+#define ELF_MAXPAGESIZE 0x10000 /* 64KB */
+
+#define elf_backend_section_from_shdr \
+ elfNN_ia64_section_from_shdr
+#define elf_backend_section_flags \
+ elfNN_ia64_section_flags
+#define elf_backend_fake_sections \
+ elfNN_ia64_fake_sections
+#define elf_backend_final_write_processing \
+ elfNN_ia64_final_write_processing
+#define elf_backend_add_symbol_hook \
+ elfNN_ia64_add_symbol_hook
+#define elf_backend_additional_program_headers \
+ elfNN_ia64_additional_program_headers
+#define elf_backend_modify_segment_map \
+ elfNN_ia64_modify_segment_map
+#define elf_info_to_howto \
+ elfNN_ia64_info_to_howto
+
+#define bfd_elfNN_bfd_reloc_type_lookup \
+ elfNN_ia64_reloc_type_lookup
+#define bfd_elfNN_bfd_is_local_label_name \
+ elfNN_ia64_is_local_label_name
+#define bfd_elfNN_bfd_relax_section \
+ elfNN_ia64_relax_section
+
+/* Stuff for the BFD linker: */
+#define bfd_elfNN_bfd_link_hash_table_create \
+ elfNN_ia64_hash_table_create
+#define elf_backend_create_dynamic_sections \
+ elfNN_ia64_create_dynamic_sections
+#define elf_backend_check_relocs \
+ elfNN_ia64_check_relocs
+#define elf_backend_adjust_dynamic_symbol \
+ elfNN_ia64_adjust_dynamic_symbol
+#define elf_backend_size_dynamic_sections \
+ elfNN_ia64_size_dynamic_sections
+#define elf_backend_relocate_section \
+ elfNN_ia64_relocate_section
+#define elf_backend_finish_dynamic_symbol \
+ elfNN_ia64_finish_dynamic_symbol
+#define elf_backend_finish_dynamic_sections \
+ elfNN_ia64_finish_dynamic_sections
+#define bfd_elfNN_bfd_final_link \
+ elfNN_ia64_final_link
+
+#define bfd_elfNN_bfd_copy_private_bfd_data \
+ elfNN_ia64_copy_private_bfd_data
+#define bfd_elfNN_bfd_merge_private_bfd_data \
+ elfNN_ia64_merge_private_bfd_data
+#define bfd_elfNN_bfd_set_private_flags \
+ elfNN_ia64_set_private_flags
+#define bfd_elfNN_bfd_print_private_bfd_data \
+ elfNN_ia64_print_private_bfd_data
+
+#define elf_backend_plt_readonly 1
+#define elf_backend_want_plt_sym 0
+#define elf_backend_plt_alignment 5
+#define elf_backend_got_header_size 0
+#define elf_backend_plt_header_size PLT_HEADER_SIZE
+#define elf_backend_want_got_plt 1
+#define elf_backend_may_use_rel_p 1
+#define elf_backend_may_use_rela_p 1
+#define elf_backend_default_use_rela_p 1
+#define elf_backend_want_dynbss 0
+#define elf_backend_copy_indirect_symbol elfNN_ia64_hash_copy_indirect
+#define elf_backend_hide_symbol elfNN_ia64_hash_hide_symbol
+
+#include "elfNN-target.h"
diff --git a/contrib/binutils/bfd/libpei.h b/contrib/binutils/bfd/libpei.h
new file mode 100644
index 0000000..5b9cc04
--- /dev/null
+++ b/contrib/binutils/bfd/libpei.h
@@ -0,0 +1,321 @@
+/* Support for the generic parts of PE/PEI; common header information.
+ Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001
+ Free Software Foundation, Inc.
+ Written by Cygnus Solutions.
+
+This file is part of BFD, the Binary File Descriptor library.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+/*
+Most of this hacked by Steve Chamberlain,
+ sac@cygnus.com
+
+PE/PEI rearrangement (and code added): Donn Terry
+ Softway Systems, Inc.
+*/
+
+/* Hey look, some documentation [and in a place you expect to find it]!
+
+ The main reference for the pei format is "Microsoft Portable Executable
+ and Common Object File Format Specification 4.1". Get it if you need to
+ do some serious hacking on this code.
+
+ Another reference:
+ "Peering Inside the PE: A Tour of the Win32 Portable Executable
+ File Format", MSJ 1994, Volume 9.
+
+ The *sole* difference between the pe format and the pei format is that the
+ latter has an MSDOS 2.0 .exe header on the front that prints the message
+ "This app must be run under Windows." (or some such).
+ (FIXME: Whether that statement is *really* true or not is unknown.
+ Are there more subtle differences between pe and pei formats?
+ For now assume there aren't. If you find one, then for God sakes
+ document it here!)
+
+ The Microsoft docs use the word "image" instead of "executable" because
+ the former can also refer to a DLL (shared library). Confusion can arise
+ because the `i' in `pei' also refers to "image". The `pe' format can
+ also create images (i.e. executables), it's just that to run on a win32
+ system you need to use the pei format.
+
+ FIXME: Please add more docs here so the next poor fool that has to hack
+ on this code has a chance of getting something accomplished without
+ wasting too much time.
+*/
+
+#ifndef GET_FCN_LNNOPTR
+#define GET_FCN_LNNOPTR(abfd, ext) \
+ bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
+#endif
+
+#ifndef GET_FCN_ENDNDX
+#define GET_FCN_ENDNDX(abfd, ext) \
+ bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
+#endif
+
+#ifndef PUT_FCN_LNNOPTR
+#define PUT_FCN_LNNOPTR(abfd, in, ext) bfd_h_put_32(abfd, in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
+#endif
+#ifndef PUT_FCN_ENDNDX
+#define PUT_FCN_ENDNDX(abfd, in, ext) bfd_h_put_32(abfd, in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
+#endif
+#ifndef GET_LNSZ_LNNO
+#define GET_LNSZ_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_lnno)
+#endif
+#ifndef GET_LNSZ_SIZE
+#define GET_LNSZ_SIZE(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_size)
+#endif
+#ifndef PUT_LNSZ_LNNO
+#define PUT_LNSZ_LNNO(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_sym.x_misc.x_lnsz.x_lnno)
+#endif
+#ifndef PUT_LNSZ_SIZE
+#define PUT_LNSZ_SIZE(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte*) ext->x_sym.x_misc.x_lnsz.x_size)
+#endif
+#ifndef GET_SCN_SCNLEN
+#define GET_SCN_SCNLEN(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_scn.x_scnlen)
+#endif
+#ifndef GET_SCN_NRELOC
+#define GET_SCN_NRELOC(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nreloc)
+#endif
+#ifndef GET_SCN_NLINNO
+#define GET_SCN_NLINNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nlinno)
+#endif
+#ifndef PUT_SCN_SCNLEN
+#define PUT_SCN_SCNLEN(abfd,in, ext) bfd_h_put_32(abfd, in, (bfd_byte *) ext->x_scn.x_scnlen)
+#endif
+#ifndef PUT_SCN_NRELOC
+#define PUT_SCN_NRELOC(abfd,in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_scn.x_nreloc)
+#endif
+#ifndef PUT_SCN_NLINNO
+#define PUT_SCN_NLINNO(abfd,in, ext) bfd_h_put_16(abfd,in, (bfd_byte *) ext->x_scn.x_nlinno)
+#endif
+#ifndef GET_LINENO_LNNO
+#define GET_LINENO_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) (ext->l_lnno));
+#endif
+#ifndef PUT_LINENO_LNNO
+#define PUT_LINENO_LNNO(abfd,val, ext) bfd_h_put_16(abfd,val, (bfd_byte *) (ext->l_lnno));
+#endif
+
+/* The f_symptr field in the filehdr is sometimes 64 bits. */
+#ifndef GET_FILEHDR_SYMPTR
+#define GET_FILEHDR_SYMPTR bfd_h_get_32
+#endif
+#ifndef PUT_FILEHDR_SYMPTR
+#define PUT_FILEHDR_SYMPTR bfd_h_put_32
+#endif
+
+/* Some fields in the aouthdr are sometimes 64 bits. */
+#ifndef GET_AOUTHDR_TSIZE
+#define GET_AOUTHDR_TSIZE bfd_h_get_32
+#endif
+#ifndef PUT_AOUTHDR_TSIZE
+#define PUT_AOUTHDR_TSIZE bfd_h_put_32
+#endif
+#ifndef GET_AOUTHDR_DSIZE
+#define GET_AOUTHDR_DSIZE bfd_h_get_32
+#endif
+#ifndef PUT_AOUTHDR_DSIZE
+#define PUT_AOUTHDR_DSIZE bfd_h_put_32
+#endif
+#ifndef GET_AOUTHDR_BSIZE
+#define GET_AOUTHDR_BSIZE bfd_h_get_32
+#endif
+#ifndef PUT_AOUTHDR_BSIZE
+#define PUT_AOUTHDR_BSIZE bfd_h_put_32
+#endif
+#ifndef GET_AOUTHDR_ENTRY
+#define GET_AOUTHDR_ENTRY bfd_h_get_32
+#endif
+#ifndef PUT_AOUTHDR_ENTRY
+#define PUT_AOUTHDR_ENTRY bfd_h_put_32
+#endif
+#ifndef GET_AOUTHDR_TEXT_START
+#define GET_AOUTHDR_TEXT_START bfd_h_get_32
+#endif
+#ifndef PUT_AOUTHDR_TEXT_START
+#define PUT_AOUTHDR_TEXT_START bfd_h_put_32
+#endif
+#ifndef GET_AOUTHDR_DATA_START
+#define GET_AOUTHDR_DATA_START bfd_h_get_32
+#endif
+#ifndef PUT_AOUTHDR_DATA_START
+#define PUT_AOUTHDR_DATA_START bfd_h_put_32
+#endif
+
+/* Some fields in the scnhdr are sometimes 64 bits. */
+#ifndef GET_SCNHDR_PADDR
+#define GET_SCNHDR_PADDR bfd_h_get_32
+#endif
+#ifndef PUT_SCNHDR_PADDR
+#define PUT_SCNHDR_PADDR bfd_h_put_32
+#endif
+#ifndef GET_SCNHDR_VADDR
+#define GET_SCNHDR_VADDR bfd_h_get_32
+#endif
+#ifndef PUT_SCNHDR_VADDR
+#define PUT_SCNHDR_VADDR bfd_h_put_32
+#endif
+#ifndef GET_SCNHDR_SIZE
+#define GET_SCNHDR_SIZE bfd_h_get_32
+#endif
+#ifndef PUT_SCNHDR_SIZE
+#define PUT_SCNHDR_SIZE bfd_h_put_32
+#endif
+#ifndef GET_SCNHDR_SCNPTR
+#define GET_SCNHDR_SCNPTR bfd_h_get_32
+#endif
+#ifndef PUT_SCNHDR_SCNPTR
+#define PUT_SCNHDR_SCNPTR bfd_h_put_32
+#endif
+#ifndef GET_SCNHDR_RELPTR
+#define GET_SCNHDR_RELPTR bfd_h_get_32
+#endif
+#ifndef PUT_SCNHDR_RELPTR
+#define PUT_SCNHDR_RELPTR bfd_h_put_32
+#endif
+#ifndef GET_SCNHDR_LNNOPTR
+#define GET_SCNHDR_LNNOPTR bfd_h_get_32
+#endif
+#ifndef PUT_SCNHDR_LNNOPTR
+#define PUT_SCNHDR_LNNOPTR bfd_h_put_32
+#endif
+
+#ifdef COFF_WITH_pep
+
+#define GET_OPTHDR_IMAGE_BASE bfd_h_get_64
+#define PUT_OPTHDR_IMAGE_BASE bfd_h_put_64
+#define GET_OPTHDR_SIZE_OF_STACK_RESERVE bfd_h_get_64
+#define PUT_OPTHDR_SIZE_OF_STACK_RESERVE bfd_h_put_64
+#define GET_OPTHDR_SIZE_OF_STACK_COMMIT bfd_h_get_64
+#define PUT_OPTHDR_SIZE_OF_STACK_COMMIT bfd_h_put_64
+#define GET_OPTHDR_SIZE_OF_HEAP_RESERVE bfd_h_get_64
+#define PUT_OPTHDR_SIZE_OF_HEAP_RESERVE bfd_h_put_64
+#define GET_OPTHDR_SIZE_OF_HEAP_COMMIT bfd_h_get_64
+#define PUT_OPTHDR_SIZE_OF_HEAP_COMMIT bfd_h_put_64
+#define GET_PDATA_ENTRY bfd_get_64
+
+#define _bfd_XX_bfd_copy_private_bfd_data_common _bfd_pep_bfd_copy_private_bfd_data_common
+#define _bfd_XX_bfd_copy_private_section_data _bfd_pep_bfd_copy_private_section_data
+#define _bfd_XX_get_symbol_info _bfd_pep_get_symbol_info
+#define _bfd_XX_only_swap_filehdr_out _bfd_pep_only_swap_filehdr_out
+#define _bfd_XX_print_private_bfd_data_common _bfd_pep_print_private_bfd_data_common
+#define _bfd_XXi_final_link_postscript _bfd_pepi_final_link_postscript
+#define _bfd_XXi_final_link_postscript _bfd_pepi_final_link_postscript
+#define _bfd_XXi_only_swap_filehdr_out _bfd_pepi_only_swap_filehdr_out
+#define _bfd_XXi_swap_aouthdr_in _bfd_pepi_swap_aouthdr_in
+#define _bfd_XXi_swap_aouthdr_out _bfd_pepi_swap_aouthdr_out
+#define _bfd_XXi_swap_aux_in _bfd_pepi_swap_aux_in
+#define _bfd_XXi_swap_aux_out _bfd_pepi_swap_aux_out
+#define _bfd_XXi_swap_lineno_in _bfd_pepi_swap_lineno_in
+#define _bfd_XXi_swap_lineno_out _bfd_pepi_swap_lineno_out
+#define _bfd_XXi_swap_scnhdr_out _bfd_pepi_swap_scnhdr_out
+#define _bfd_XXi_swap_sym_in _bfd_pepi_swap_sym_in
+#define _bfd_XXi_swap_sym_out _bfd_pepi_swap_sym_out
+
+#else /* !COFF_WITH_pep */
+
+#define GET_OPTHDR_IMAGE_BASE bfd_h_get_32
+#define PUT_OPTHDR_IMAGE_BASE bfd_h_put_32
+#define GET_OPTHDR_SIZE_OF_STACK_RESERVE bfd_h_get_32
+#define PUT_OPTHDR_SIZE_OF_STACK_RESERVE bfd_h_put_32
+#define GET_OPTHDR_SIZE_OF_STACK_COMMIT bfd_h_get_32
+#define PUT_OPTHDR_SIZE_OF_STACK_COMMIT bfd_h_put_32
+#define GET_OPTHDR_SIZE_OF_HEAP_RESERVE bfd_h_get_32
+#define PUT_OPTHDR_SIZE_OF_HEAP_RESERVE bfd_h_put_32
+#define GET_OPTHDR_SIZE_OF_HEAP_COMMIT bfd_h_get_32
+#define PUT_OPTHDR_SIZE_OF_HEAP_COMMIT bfd_h_put_32
+#define GET_PDATA_ENTRY bfd_get_32
+
+#define _bfd_XX_bfd_copy_private_bfd_data_common _bfd_pe_bfd_copy_private_bfd_data_common
+#define _bfd_XX_bfd_copy_private_section_data _bfd_pe_bfd_copy_private_section_data
+#define _bfd_XX_get_symbol_info _bfd_pe_get_symbol_info
+#define _bfd_XX_only_swap_filehdr_out _bfd_pe_only_swap_filehdr_out
+#define _bfd_XX_print_private_bfd_data_common _bfd_pe_print_private_bfd_data_common
+#define _bfd_XXi_final_link_postscript _bfd_pei_final_link_postscript
+#define _bfd_XXi_final_link_postscript _bfd_pei_final_link_postscript
+#define _bfd_XXi_only_swap_filehdr_out _bfd_pei_only_swap_filehdr_out
+#define _bfd_XXi_swap_aouthdr_in _bfd_pei_swap_aouthdr_in
+#define _bfd_XXi_swap_aouthdr_out _bfd_pei_swap_aouthdr_out
+#define _bfd_XXi_swap_aux_in _bfd_pei_swap_aux_in
+#define _bfd_XXi_swap_aux_out _bfd_pei_swap_aux_out
+#define _bfd_XXi_swap_lineno_in _bfd_pei_swap_lineno_in
+#define _bfd_XXi_swap_lineno_out _bfd_pei_swap_lineno_out
+#define _bfd_XXi_swap_scnhdr_out _bfd_pei_swap_scnhdr_out
+#define _bfd_XXi_swap_sym_in _bfd_pei_swap_sym_in
+#define _bfd_XXi_swap_sym_out _bfd_pei_swap_sym_out
+
+#endif /* !COFF_WITH_pep */
+
+/* These functions are architecture dependent, and are in peicode.h:
+ coff_swap_reloc_in
+ int coff_swap_reloc_out
+ coff_swap_filehdr_in
+ coff_swap_scnhdr_in
+ pe_mkobject
+ pe_mkobject_hook */
+
+/* The functions described below are common across all PE/PEI
+ implementations architecture types, and actually appear in
+ peigen.c. */
+
+void _bfd_XXi_swap_sym_in PARAMS ((bfd*, PTR, PTR));
+#define coff_swap_sym_in _bfd_XXi_swap_sym_in
+
+unsigned int _bfd_XXi_swap_sym_out PARAMS ((bfd*, PTR, PTR));
+#define coff_swap_sym_out _bfd_XXi_swap_sym_out
+
+void _bfd_XXi_swap_aux_in PARAMS ((bfd *, PTR, int, int, int, int, PTR));
+#define coff_swap_aux_in _bfd_XXi_swap_aux_in
+
+unsigned int _bfd_XXi_swap_aux_out \
+ PARAMS ((bfd *, PTR, int, int, int, int, PTR));
+#define coff_swap_aux_out _bfd_XXi_swap_aux_out
+
+void _bfd_XXi_swap_lineno_in PARAMS ((bfd*, PTR, PTR));
+#define coff_swap_lineno_in _bfd_XXi_swap_lineno_in
+
+unsigned int _bfd_XXi_swap_lineno_out PARAMS ((bfd*, PTR, PTR));
+#define coff_swap_lineno_out _bfd_XXi_swap_lineno_out
+
+void _bfd_XXi_swap_aouthdr_in PARAMS ((bfd*, PTR, PTR));
+#define coff_swap_aouthdr_in _bfd_XXi_swap_aouthdr_in
+
+unsigned int _bfd_XXi_swap_aouthdr_out PARAMS ((bfd *, PTR, PTR));
+#define coff_swap_aouthdr_out _bfd_XXi_swap_aouthdr_out
+
+unsigned int _bfd_XXi_swap_scnhdr_out PARAMS ((bfd *, PTR, PTR));
+#define coff_swap_scnhdr_out _bfd_XXi_swap_scnhdr_out
+
+boolean _bfd_XX_print_private_bfd_data_common PARAMS ((bfd *, PTR));
+
+boolean _bfd_XX_bfd_copy_private_bfd_data_common PARAMS ((bfd *, bfd *));
+
+void _bfd_XX_get_symbol_info PARAMS ((bfd *, asymbol *, symbol_info *));
+
+boolean _bfd_XXi_final_link_postscript
+ PARAMS ((bfd *, struct coff_final_link_info *));
+
+#ifndef coff_final_link_postscript
+#define coff_final_link_postscript _bfd_XXi_final_link_postscript
+#endif
+/* The following are needed only for ONE of pe or pei, but don't
+ otherwise vary; peicode.h fixes up ifdefs but we provide the
+ prototype. */
+
+unsigned int _bfd_XX_only_swap_filehdr_out PARAMS ((bfd*, PTR, PTR));
+unsigned int _bfd_XXi_only_swap_filehdr_out PARAMS ((bfd*, PTR, PTR));
+boolean _bfd_XX_bfd_copy_private_section_data
+ PARAMS ((bfd *, asection *, bfd *, asection *));
diff --git a/contrib/binutils/bfd/peicode.h b/contrib/binutils/bfd/peicode.h
new file mode 100644
index 0000000..20fe01c
--- /dev/null
+++ b/contrib/binutils/bfd/peicode.h
@@ -0,0 +1,1324 @@
+/* Support for the generic parts of PE/PEI, for BFD.
+ Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001
+ Free Software Foundation, Inc.
+ Written by Cygnus Solutions.
+
+This file is part of BFD, the Binary File Descriptor library.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+/*
+Most of this hacked by Steve Chamberlain,
+ sac@cygnus.com
+
+PE/PEI rearrangement (and code added): Donn Terry
+ Softway Systems, Inc.
+*/
+
+/* Hey look, some documentation [and in a place you expect to find it]!
+
+ The main reference for the pei format is "Microsoft Portable Executable
+ and Common Object File Format Specification 4.1". Get it if you need to
+ do some serious hacking on this code.
+
+ Another reference:
+ "Peering Inside the PE: A Tour of the Win32 Portable Executable
+ File Format", MSJ 1994, Volume 9.
+
+ The *sole* difference between the pe format and the pei format is that the
+ latter has an MSDOS 2.0 .exe header on the front that prints the message
+ "This app must be run under Windows." (or some such).
+ (FIXME: Whether that statement is *really* true or not is unknown.
+ Are there more subtle differences between pe and pei formats?
+ For now assume there aren't. If you find one, then for God sakes
+ document it here!)
+
+ The Microsoft docs use the word "image" instead of "executable" because
+ the former can also refer to a DLL (shared library). Confusion can arise
+ because the `i' in `pei' also refers to "image". The `pe' format can
+ also create images (i.e. executables), it's just that to run on a win32
+ system you need to use the pei format.
+
+ FIXME: Please add more docs here so the next poor fool that has to hack
+ on this code has a chance of getting something accomplished without
+ wasting too much time.
+*/
+
+#include "libpei.h"
+
+static boolean (*pe_saved_coff_bfd_print_private_bfd_data)
+ PARAMS ((bfd *, PTR)) =
+#ifndef coff_bfd_print_private_bfd_data
+ NULL;
+#else
+ coff_bfd_print_private_bfd_data;
+#undef coff_bfd_print_private_bfd_data
+#endif
+
+static boolean pe_print_private_bfd_data PARAMS ((bfd *, PTR));
+#define coff_bfd_print_private_bfd_data pe_print_private_bfd_data
+
+static boolean (*pe_saved_coff_bfd_copy_private_bfd_data)
+ PARAMS ((bfd *, bfd *)) =
+#ifndef coff_bfd_copy_private_bfd_data
+ NULL;
+#else
+ coff_bfd_copy_private_bfd_data;
+#undef coff_bfd_copy_private_bfd_data
+#endif
+
+static boolean pe_bfd_copy_private_bfd_data PARAMS ((bfd *, bfd *));
+#define coff_bfd_copy_private_bfd_data pe_bfd_copy_private_bfd_data
+
+#define coff_mkobject pe_mkobject
+#define coff_mkobject_hook pe_mkobject_hook
+
+#ifndef NO_COFF_RELOCS
+static void coff_swap_reloc_in PARAMS ((bfd *, PTR, PTR));
+static unsigned int coff_swap_reloc_out PARAMS ((bfd *, PTR, PTR));
+#endif
+static void coff_swap_filehdr_in PARAMS ((bfd *, PTR, PTR));
+static void coff_swap_scnhdr_in PARAMS ((bfd *, PTR, PTR));
+static boolean pe_mkobject PARAMS ((bfd *));
+static PTR pe_mkobject_hook PARAMS ((bfd *, PTR, PTR));
+
+#ifdef COFF_IMAGE_WITH_PE
+/* This structure contains static variables used by the ILF code. */
+typedef asection * asection_ptr;
+
+typedef struct
+{
+ bfd * abfd;
+ bfd_byte * data;
+ struct bfd_in_memory * bim;
+ unsigned short magic;
+
+ arelent * reltab;
+ unsigned int relcount;
+
+ coff_symbol_type * sym_cache;
+ coff_symbol_type * sym_ptr;
+ unsigned int sym_index;
+
+ unsigned int * sym_table;
+ unsigned int * table_ptr;
+
+ combined_entry_type * native_syms;
+ combined_entry_type * native_ptr;
+
+ coff_symbol_type ** sym_ptr_table;
+ coff_symbol_type ** sym_ptr_ptr;
+
+ unsigned int sec_index;
+
+ char * string_table;
+ char * string_ptr;
+ char * end_string_ptr;
+
+ SYMENT * esym_table;
+ SYMENT * esym_ptr;
+
+ struct internal_reloc * int_reltab;
+}
+pe_ILF_vars;
+
+static asection_ptr pe_ILF_make_a_section PARAMS ((pe_ILF_vars *, const char *, unsigned int, flagword));
+static void pe_ILF_make_a_reloc PARAMS ((pe_ILF_vars *, bfd_vma, bfd_reloc_code_real_type, asection_ptr));
+static void pe_ILF_make_a_symbol PARAMS ((pe_ILF_vars *, const char *, const char *, asection_ptr, flagword));
+static void pe_ILF_save_relocs PARAMS ((pe_ILF_vars *, asection_ptr));
+static void pe_ILF_make_a_symbol_reloc PARAMS ((pe_ILF_vars *, bfd_vma, bfd_reloc_code_real_type, struct symbol_cache_entry **, unsigned int));
+static boolean pe_ILF_build_a_bfd PARAMS ((bfd *, unsigned short, bfd_byte *, bfd_byte *, unsigned int, unsigned int));
+static const bfd_target * pe_ILF_object_p PARAMS ((bfd *));
+static const bfd_target * pe_bfd_object_p PARAMS ((bfd *));
+#endif /* COFF_IMAGE_WITH_PE */
+
+/**********************************************************************/
+
+#ifndef NO_COFF_RELOCS
+static void
+coff_swap_reloc_in (abfd, src, dst)
+ bfd *abfd;
+ PTR src;
+ PTR dst;
+{
+ RELOC *reloc_src = (RELOC *) src;
+ struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
+
+ reloc_dst->r_vaddr = bfd_h_get_32(abfd, (bfd_byte *)reloc_src->r_vaddr);
+ reloc_dst->r_symndx = bfd_h_get_signed_32(abfd, (bfd_byte *) reloc_src->r_symndx);
+
+ reloc_dst->r_type = bfd_h_get_16(abfd, (bfd_byte *) reloc_src->r_type);
+
+#ifdef SWAP_IN_RELOC_OFFSET
+ reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET(abfd,
+ (bfd_byte *) reloc_src->r_offset);
+#endif
+}
+
+static unsigned int
+coff_swap_reloc_out (abfd, src, dst)
+ bfd *abfd;
+ PTR src;
+ PTR dst;
+{
+ struct internal_reloc *reloc_src = (struct internal_reloc *)src;
+ struct external_reloc *reloc_dst = (struct external_reloc *)dst;
+ bfd_h_put_32(abfd, reloc_src->r_vaddr, (bfd_byte *) reloc_dst->r_vaddr);
+ bfd_h_put_32(abfd, reloc_src->r_symndx, (bfd_byte *) reloc_dst->r_symndx);
+
+ bfd_h_put_16(abfd, reloc_src->r_type, (bfd_byte *)
+ reloc_dst->r_type);
+
+#ifdef SWAP_OUT_RELOC_OFFSET
+ SWAP_OUT_RELOC_OFFSET(abfd,
+ reloc_src->r_offset,
+ (bfd_byte *) reloc_dst->r_offset);
+#endif
+#ifdef SWAP_OUT_RELOC_EXTRA
+ SWAP_OUT_RELOC_EXTRA(abfd,reloc_src, reloc_dst);
+#endif
+ return RELSZ;
+}
+#endif /* not NO_COFF_RELOCS */
+
+static void
+coff_swap_filehdr_in (abfd, src, dst)
+ bfd *abfd;
+ PTR src;
+ PTR dst;
+{
+ FILHDR *filehdr_src = (FILHDR *) src;
+ struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
+ filehdr_dst->f_magic = bfd_h_get_16(abfd, (bfd_byte *) filehdr_src->f_magic);
+ filehdr_dst->f_nscns = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_nscns);
+ filehdr_dst->f_timdat = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_timdat);
+
+ filehdr_dst->f_nsyms = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_nsyms);
+ filehdr_dst->f_flags = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_flags);
+ filehdr_dst->f_symptr = bfd_h_get_32 (abfd, (bfd_byte *) filehdr_src->f_symptr);
+
+ /* Other people's tools sometimes generate headers with an nsyms but
+ a zero symptr. */
+ if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
+ {
+ filehdr_dst->f_nsyms = 0;
+ filehdr_dst->f_flags |= F_LSYMS;
+ }
+
+ filehdr_dst->f_opthdr = bfd_h_get_16(abfd,
+ (bfd_byte *)filehdr_src-> f_opthdr);
+}
+
+#ifdef COFF_IMAGE_WITH_PE
+# define coff_swap_filehdr_out _bfd_XXi_only_swap_filehdr_out
+#else
+# define coff_swap_filehdr_out _bfd_pe_only_swap_filehdr_out
+#endif
+
+static void
+coff_swap_scnhdr_in (abfd, ext, in)
+ bfd *abfd;
+ PTR ext;
+ PTR in;
+{
+ SCNHDR *scnhdr_ext = (SCNHDR *) ext;
+ struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
+
+ memcpy(scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
+ scnhdr_int->s_vaddr =
+ GET_SCNHDR_VADDR (abfd, (bfd_byte *) scnhdr_ext->s_vaddr);
+ scnhdr_int->s_paddr =
+ GET_SCNHDR_PADDR (abfd, (bfd_byte *) scnhdr_ext->s_paddr);
+ scnhdr_int->s_size =
+ GET_SCNHDR_SIZE (abfd, (bfd_byte *) scnhdr_ext->s_size);
+ scnhdr_int->s_scnptr =
+ GET_SCNHDR_SCNPTR (abfd, (bfd_byte *) scnhdr_ext->s_scnptr);
+ scnhdr_int->s_relptr =
+ GET_SCNHDR_RELPTR (abfd, (bfd_byte *) scnhdr_ext->s_relptr);
+ scnhdr_int->s_lnnoptr =
+ GET_SCNHDR_LNNOPTR (abfd, (bfd_byte *) scnhdr_ext->s_lnnoptr);
+ scnhdr_int->s_flags = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_flags);
+
+ /* MS handles overflow of line numbers by carrying into the reloc
+ field (it appears). Since it's supposed to be zero for PE
+ *IMAGE* format, that's safe. This is still a bit iffy. */
+#ifdef COFF_IMAGE_WITH_PE
+ scnhdr_int->s_nlnno =
+ (bfd_h_get_16 (abfd, (bfd_byte *) scnhdr_ext->s_nlnno)
+ + (bfd_h_get_16 (abfd, (bfd_byte *) scnhdr_ext->s_nreloc) << 16));
+ scnhdr_int->s_nreloc = 0;
+#else
+ scnhdr_int->s_nreloc = bfd_h_get_16 (abfd,
+ (bfd_byte *) scnhdr_ext->s_nreloc);
+ scnhdr_int->s_nlnno = bfd_h_get_16 (abfd,
+ (bfd_byte *) scnhdr_ext->s_nlnno);
+#endif
+
+ if (scnhdr_int->s_vaddr != 0)
+ {
+ scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
+ scnhdr_int->s_vaddr &= 0xffffffff;
+ }
+
+#ifndef COFF_NO_HACK_SCNHDR_SIZE
+ /* If this section holds uninitialized data, use the virtual size
+ (stored in s_paddr) instead of the physical size. */
+ if ((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
+ && (scnhdr_int->s_paddr > 0))
+ {
+ scnhdr_int->s_size = scnhdr_int->s_paddr;
+ /* This code used to set scnhdr_int->s_paddr to 0. However,
+ coff_set_alignment_hook stores s_paddr in virt_size, which
+ only works if it correctly holds the virtual size of the
+ section. */
+ }
+#endif
+}
+
+static boolean
+pe_mkobject (abfd)
+ bfd * abfd;
+{
+ pe_data_type *pe;
+ abfd->tdata.pe_obj_data =
+ (struct pe_tdata *) bfd_zalloc (abfd, sizeof (pe_data_type));
+
+ if (abfd->tdata.pe_obj_data == 0)
+ return false;
+
+ pe = pe_data (abfd);
+
+ pe->coff.pe = 1;
+
+ /* in_reloc_p is architecture dependent. */
+ pe->in_reloc_p = in_reloc_p;
+
+#ifdef PEI_FORCE_MINIMUM_ALIGNMENT
+ pe->force_minimum_alignment = 1;
+#endif
+#ifdef PEI_TARGET_SUBSYSTEM
+ pe->target_subsystem = PEI_TARGET_SUBSYSTEM;
+#endif
+
+ return true;
+}
+
+/* Create the COFF backend specific information. */
+static PTR
+pe_mkobject_hook (abfd, filehdr, aouthdr)
+ bfd * abfd;
+ PTR filehdr;
+ PTR aouthdr ATTRIBUTE_UNUSED;
+{
+ struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
+ pe_data_type *pe;
+
+ if (pe_mkobject (abfd) == false)
+ return NULL;
+
+ pe = pe_data (abfd);
+ pe->coff.sym_filepos = internal_f->f_symptr;
+ /* These members communicate important constants about the symbol
+ table to GDB's symbol-reading code. These `constants'
+ unfortunately vary among coff implementations... */
+ pe->coff.local_n_btmask = N_BTMASK;
+ pe->coff.local_n_btshft = N_BTSHFT;
+ pe->coff.local_n_tmask = N_TMASK;
+ pe->coff.local_n_tshift = N_TSHIFT;
+ pe->coff.local_symesz = SYMESZ;
+ pe->coff.local_auxesz = AUXESZ;
+ pe->coff.local_linesz = LINESZ;
+
+ pe->coff.timestamp = internal_f->f_timdat;
+
+ obj_raw_syment_count (abfd) =
+ obj_conv_table_size (abfd) =
+ internal_f->f_nsyms;
+
+ pe->real_flags = internal_f->f_flags;
+
+ if ((internal_f->f_flags & F_DLL) != 0)
+ pe->dll = 1;
+
+ if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
+ abfd->flags |= HAS_DEBUG;
+
+#ifdef COFF_IMAGE_WITH_PE
+ if (aouthdr)
+ pe->pe_opthdr = ((struct internal_aouthdr *)aouthdr)->pe;
+#endif
+
+#ifdef ARM
+ if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
+ coff_data (abfd) ->flags = 0;
+#endif
+
+ return (PTR) pe;
+}
+
+static boolean
+pe_print_private_bfd_data (abfd, vfile)
+ bfd *abfd;
+ PTR vfile;
+{
+ FILE *file = (FILE *) vfile;
+
+ if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
+ return false;
+
+ if (pe_saved_coff_bfd_print_private_bfd_data != NULL)
+ {
+ fputc ('\n', file);
+
+ return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
+ }
+
+ return true;
+}
+
+/* Copy any private info we understand from the input bfd
+ to the output bfd. */
+
+static boolean
+pe_bfd_copy_private_bfd_data (ibfd, obfd)
+ bfd *ibfd, *obfd;
+{
+ if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
+ return false;
+
+ if (pe_saved_coff_bfd_copy_private_bfd_data)
+ return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
+
+ return true;
+}
+
+#define coff_bfd_copy_private_section_data \
+ _bfd_XX_bfd_copy_private_section_data
+
+#define coff_get_symbol_info _bfd_XX_get_symbol_info
+
+#ifdef COFF_IMAGE_WITH_PE
+
+/* Code to handle Microsoft's Image Library Format.
+ Also known as LINK6 format.
+ Documentation about this format can be found at:
+
+ http://msdn.microsoft.com/library/specs/pecoff_section8.htm */
+
+/* The following constants specify the sizes of the various data
+ structures that we have to create in order to build a bfd describing
+ an ILF object file. The final "+ 1" in the definitions of SIZEOF_IDATA6
+ and SIZEOF_IDATA7 below is to allow for the possibility that we might
+ need a padding byte in order to ensure 16 bit alignment for the section's
+ contents.
+
+ The value for SIZEOF_ILF_STRINGS is computed as follows:
+
+ There will be NUM_ILF_SECTIONS section symbols. Allow 9 characters
+ per symbol for their names (longest section name is .idata$x).
+
+ There will be two symbols for the imported value, one the symbol name
+ and one with _imp__ prefixed. Allowing for the terminating nul's this
+ is strlen (symbol_name) * 2 + 8 + 21 + strlen (source_dll).
+
+ The strings in the string table must start STRING__SIZE_SIZE bytes into
+ the table in order to for the string lookup code in coffgen/coffcode to
+ work. */
+#define NUM_ILF_RELOCS 8
+#define NUM_ILF_SECTIONS 6
+#define NUM_ILF_SYMS (2 + NUM_ILF_SECTIONS)
+
+#define SIZEOF_ILF_SYMS (NUM_ILF_SYMS * sizeof (* vars.sym_cache))
+#define SIZEOF_ILF_SYM_TABLE (NUM_ILF_SYMS * sizeof (* vars.sym_table))
+#define SIZEOF_ILF_NATIVE_SYMS (NUM_ILF_SYMS * sizeof (* vars.native_syms))
+#define SIZEOF_ILF_SYM_PTR_TABLE (NUM_ILF_SYMS * sizeof (* vars.sym_ptr_table))
+#define SIZEOF_ILF_EXT_SYMS (NUM_ILF_SYMS * sizeof (* vars.esym_table))
+#define SIZEOF_ILF_RELOCS (NUM_ILF_RELOCS * sizeof (* vars.reltab))
+#define SIZEOF_ILF_INT_RELOCS (NUM_ILF_RELOCS * sizeof (* vars.int_reltab))
+#define SIZEOF_ILF_STRINGS (strlen (symbol_name) * 2 + 8 \
+ + 21 + strlen (source_dll) \
+ + NUM_ILF_SECTIONS * 9 \
+ + STRING_SIZE_SIZE)
+#define SIZEOF_IDATA2 (5 * 4)
+#define SIZEOF_IDATA4 (1 * 4)
+#define SIZEOF_IDATA5 (1 * 4)
+#define SIZEOF_IDATA6 (2 + strlen (symbol_name) + 1 + 1)
+#define SIZEOF_IDATA7 (strlen (source_dll) + 1 + 1)
+#define SIZEOF_ILF_SECTIONS (NUM_ILF_SECTIONS * sizeof (struct coff_section_tdata))
+
+#define ILF_DATA_SIZE \
+ sizeof (* vars.bim) \
+ + SIZEOF_ILF_SYMS \
+ + SIZEOF_ILF_SYM_TABLE \
+ + SIZEOF_ILF_NATIVE_SYMS \
+ + SIZEOF_ILF_SYM_PTR_TABLE \
+ + SIZEOF_ILF_EXT_SYMS \
+ + SIZEOF_ILF_RELOCS \
+ + SIZEOF_ILF_INT_RELOCS \
+ + SIZEOF_ILF_STRINGS \
+ + SIZEOF_IDATA2 \
+ + SIZEOF_IDATA4 \
+ + SIZEOF_IDATA5 \
+ + SIZEOF_IDATA6 \
+ + SIZEOF_IDATA7 \
+ + SIZEOF_ILF_SECTIONS \
+ + MAX_TEXT_SECTION_SIZE
+
+/* Create an empty relocation against the given symbol. */
+static void
+pe_ILF_make_a_symbol_reloc (pe_ILF_vars * vars,
+ bfd_vma address,
+ bfd_reloc_code_real_type reloc,
+ struct symbol_cache_entry ** sym,
+ unsigned int sym_index)
+{
+ arelent * entry;
+ struct internal_reloc * internal;
+
+ entry = vars->reltab + vars->relcount;
+ internal = vars->int_reltab + vars->relcount;
+
+ entry->address = address;
+ entry->addend = 0;
+ entry->howto = bfd_reloc_type_lookup (vars->abfd, reloc);
+ entry->sym_ptr_ptr = sym;
+
+ internal->r_vaddr = address;
+ internal->r_symndx = sym_index;
+ internal->r_type = entry->howto->type;
+#if 0 /* These fields do not need to be initialised. */
+ internal->r_size = 0;
+ internal->r_extern = 0;
+ internal->r_offset = 0;
+#endif
+
+ vars->relcount ++;
+
+ BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
+}
+
+/* Create an empty relocation against the given section. */
+static void
+pe_ILF_make_a_reloc (pe_ILF_vars * vars,
+ bfd_vma address,
+ bfd_reloc_code_real_type reloc,
+ asection_ptr sec)
+{
+ pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
+ coff_section_data (vars->abfd, sec)->i);
+}
+
+/* Move the queued relocs into the given section. */
+static void
+pe_ILF_save_relocs (pe_ILF_vars * vars,
+ asection_ptr sec)
+{
+ /* Make sure that there is somewhere to store the internal relocs. */
+ if (coff_section_data (vars->abfd, sec) == NULL)
+ /* We should probably return an error indication here. */
+ abort ();
+
+ coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
+ coff_section_data (vars->abfd, sec)->keep_relocs = true;
+
+ sec->relocation = vars->reltab;
+ sec->reloc_count = vars->relcount;
+ sec->flags |= SEC_RELOC;
+
+ vars->reltab += vars->relcount;
+ vars->int_reltab += vars->relcount;
+ vars->relcount = 0;
+
+ BFD_ASSERT ((bfd_byte *)vars->int_reltab < (bfd_byte *)vars->string_table);
+}
+
+/* Create a global symbol and add it to the relevant tables. */
+static void
+pe_ILF_make_a_symbol (pe_ILF_vars * vars,
+ const char * prefix,
+ const char * symbol_name,
+ asection_ptr section,
+ flagword extra_flags)
+{
+ coff_symbol_type * sym;
+ combined_entry_type * ent;
+ SYMENT * esym;
+ unsigned short sclass;
+
+ if (extra_flags & BSF_LOCAL)
+ sclass = C_STAT;
+ else
+ sclass = C_EXT;
+
+#ifdef THUMBPEMAGIC
+ if (vars->magic == THUMBPEMAGIC)
+ {
+ if (extra_flags & BSF_FUNCTION)
+ sclass = C_THUMBEXTFUNC;
+ else if (extra_flags & BSF_LOCAL)
+ sclass = C_THUMBSTAT;
+ else
+ sclass = C_THUMBEXT;
+ }
+#endif
+
+ BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
+
+ sym = vars->sym_ptr;
+ ent = vars->native_ptr;
+ esym = vars->esym_ptr;
+
+ /* Copy the symbol's name into the string table. */
+ sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
+
+ if (section == NULL)
+ section = (asection_ptr) & bfd_und_section;
+
+ /* Initialise the external symbol. */
+ bfd_h_put_32 (vars->abfd, vars->string_ptr - vars->string_table, (bfd_byte *) esym->e.e.e_offset);
+ bfd_h_put_16 (vars->abfd, section->target_index, (bfd_byte *) esym->e_scnum);
+ esym->e_sclass[0] = sclass;
+
+ /* The following initialisations are unnecessary - the memory is
+ zero initialised. They are just kept here as reminders. */
+#if 0
+ esym->e.e.e_zeroes = 0;
+ esym->e_value = 0;
+ esym->e_type = T_NULL;
+ esym->e_numaux = 0;
+#endif
+
+ /* Initialise the internal symbol structure. */
+ ent->u.syment.n_sclass = sclass;
+ ent->u.syment.n_scnum = section->target_index;
+ ent->u.syment._n._n_n._n_offset = (long) sym;
+
+#if 0 /* See comment above. */
+ ent->u.syment.n_value = 0;
+ ent->u.syment.n_flags = 0;
+ ent->u.syment.n_type = T_NULL;
+ ent->u.syment.n_numaux = 0;
+ ent->fix_value = 0;
+#endif
+
+ sym->symbol.the_bfd = vars->abfd;
+ sym->symbol.name = vars->string_ptr;
+ sym->symbol.flags = BSF_EXPORT | BSF_GLOBAL | extra_flags;
+ sym->symbol.section = section;
+ sym->native = ent;
+
+#if 0 /* See comment above. */
+ sym->symbol.value = 0;
+ sym->symbol.udata.i = 0;
+ sym->done_lineno = false;
+ sym->lineno = NULL;
+#endif
+
+ * vars->table_ptr = vars->sym_index;
+ * vars->sym_ptr_ptr = sym;
+
+ /* Adjust pointers for the next symbol. */
+ vars->sym_index ++;
+ vars->sym_ptr ++;
+ vars->sym_ptr_ptr ++;
+ vars->table_ptr ++;
+ vars->native_ptr ++;
+ vars->esym_ptr ++;
+ vars->string_ptr += strlen (symbol_name) + strlen (prefix) + 1;
+
+ BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
+}
+
+/* Create a section. */
+static asection_ptr
+pe_ILF_make_a_section (pe_ILF_vars * vars,
+ const char * name,
+ unsigned int size,
+ flagword extra_flags)
+{
+ asection_ptr sec;
+ flagword flags;
+
+ sec = bfd_make_section_old_way (vars->abfd, name);
+ if (sec == NULL)
+ return NULL;
+
+ flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
+
+ bfd_set_section_flags (vars->abfd, sec, flags | extra_flags);
+
+ bfd_set_section_alignment (vars->abfd, sec, 2);
+
+ /* Check that we will not run out of space. */
+ BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
+
+ /* Set the section size and contents. The actual
+ contents are filled in by our parent. */
+ bfd_set_section_size (vars->abfd, sec, size);
+ sec->contents = vars->data;
+ sec->target_index = vars->sec_index ++;
+
+ /* Advance data pointer in the vars structure. */
+ vars->data += size;
+
+ /* Skip the padding byte if it was not needed.
+ The logic here is that if the string length is odd,
+ then the entire string length, including the null byte,
+ is even and so the extra, padding byte, is not needed. */
+ if (size & 1)
+ vars->data --;
+
+ /* Create a coff_section_tdata structure for our use. */
+ sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
+ vars->data += sizeof (struct coff_section_tdata);
+
+ BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
+
+ /* Create a symbol to refer to this section. */
+ pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
+
+ /* Cache the index to the symbol in the coff_section_data structure. */
+ coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
+
+ return sec;
+}
+
+/* This structure contains the code that goes into the .text section
+ in order to perform a jump into the DLL lookup table. The entries
+ in the table are index by the magic number used to represent the
+ machine type in the PE file. The contents of the data[] arrays in
+ these entries are stolen from the jtab[] arrays in ld/pe-dll.c.
+ The SIZE field says how many bytes in the DATA array are actually
+ used. The OFFSET field says where in the data array the address
+ of the .idata$5 section should be placed. */
+#define MAX_TEXT_SECTION_SIZE 32
+
+typedef struct
+{
+ unsigned short magic;
+ unsigned char data[MAX_TEXT_SECTION_SIZE];
+ unsigned int size;
+ unsigned int offset;
+}
+jump_table;
+
+static jump_table jtab[] =
+{
+#ifdef I386MAGIC
+ { I386MAGIC,
+ { 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 0x90, 0x90 },
+ 8, 2
+ },
+#endif
+
+#ifdef MC68MAGIC
+ { MC68MAGIC, { /* XXX fill me in */ }, 0, 0 },
+#endif
+#ifdef MIPS_ARCH_MAGIC_WINCE
+ { MIPS_ARCH_MAGIC_WINCE,
+ { 0x00, 0x00, 0x08, 0x3c, 0x00, 0x00, 0x08, 0x8d,
+ 0x08, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 },
+ 16, 0
+ },
+#endif
+
+#ifdef SH_ARCH_MAGIC_WINCE
+ { SH_ARCH_MAGIC_WINCE,
+ { 0x01, 0xd0, 0x02, 0x60, 0x2b, 0x40,
+ 0x09, 0x00, 0x00, 0x00, 0x00, 0x00 },
+ 12, 8
+ },
+#endif
+
+#ifdef ARMPEMAGIC
+ { ARMPEMAGIC,
+ { 0x00, 0xc0, 0x9f, 0xe5, 0x00, 0xf0,
+ 0x9c, 0xe5, 0x00, 0x00, 0x00, 0x00},
+ 12, 8
+ },
+#endif
+
+#ifdef THUMBPEMAGIC
+ { THUMBPEMAGIC,
+ { 0x40, 0xb4, 0x02, 0x4e, 0x36, 0x68, 0xb4, 0x46,
+ 0x40, 0xbc, 0x60, 0x47, 0x00, 0x00, 0x00, 0x00 },
+ 16, 12
+ },
+#endif
+ { 0, { 0 }, 0, 0 }
+};
+
+#ifndef NUM_ENTRIES
+#define NUM_ENTRIES(a) (sizeof (a) / sizeof (a)[0])
+#endif
+
+/* Build a full BFD from the information supplied in a ILF object. */
+static boolean
+pe_ILF_build_a_bfd (bfd * abfd,
+ unsigned short magic,
+ bfd_byte * symbol_name,
+ bfd_byte * source_dll,
+ unsigned int ordinal,
+ unsigned int types)
+{
+ bfd_byte * ptr;
+ pe_ILF_vars vars;
+ struct internal_filehdr internal_f;
+ unsigned int import_type;
+ unsigned int import_name_type;
+ asection_ptr id4, id5, id6 = NULL, text = NULL;
+ coff_symbol_type ** imp_sym;
+ unsigned int imp_index;
+
+ /* Decode and verify the types field of the ILF structure. */
+ import_type = types & 0x3;
+ import_name_type = (types & 0x1c) >> 2;
+
+ switch (import_type)
+ {
+ case IMPORT_CODE:
+ case IMPORT_DATA:
+ break;
+
+ case IMPORT_CONST:
+ /* XXX code yet to be written. */
+ _bfd_error_handler (_("%s: Unhandled import type; %x"),
+ bfd_get_filename (abfd), import_type);
+ return false;
+
+ default:
+ _bfd_error_handler (_("%s: Unrecognised import type; %x"),
+ bfd_get_filename (abfd), import_type);
+ return false;
+ }
+
+ switch (import_name_type)
+ {
+ case IMPORT_ORDINAL:
+ case IMPORT_NAME:
+ case IMPORT_NAME_NOPREFIX:
+ case IMPORT_NAME_UNDECORATE:
+ break;
+
+ default:
+ _bfd_error_handler (_("%s: Unrecognised import name type; %x"),
+ bfd_get_filename (abfd), import_name_type);
+ return false;
+ }
+
+ /* Initialise local variables.
+
+ Note these are kept in a structure rather than being
+ declared as statics since bfd frowns on global variables.
+
+ We are going to construct the contents of the BFD in memory,
+ so allocate all the space that we will need right now. */
+ ptr = bfd_zalloc (abfd, ILF_DATA_SIZE);
+ if (ptr == NULL)
+ return false;
+
+ /* Create a bfd_in_memory structure. */
+ vars.bim = (struct bfd_in_memory *) ptr;
+ vars.bim->buffer = ptr;
+ vars.bim->size = ILF_DATA_SIZE;
+ ptr += sizeof (* vars.bim);
+
+ /* Initialise the pointers to regions of the memory and the
+ other contents of the pe_ILF_vars structure as well. */
+ vars.sym_cache = (coff_symbol_type *) ptr;
+ vars.sym_ptr = (coff_symbol_type *) ptr;
+ vars.sym_index = 0;
+ ptr += SIZEOF_ILF_SYMS;
+
+ vars.sym_table = (unsigned int *) ptr;
+ vars.table_ptr = (unsigned int *) ptr;
+ ptr += SIZEOF_ILF_SYM_TABLE;
+
+ vars.native_syms = (combined_entry_type *) ptr;
+ vars.native_ptr = (combined_entry_type *) ptr;
+ ptr += SIZEOF_ILF_NATIVE_SYMS;
+
+ vars.sym_ptr_table = (coff_symbol_type **) ptr;
+ vars.sym_ptr_ptr = (coff_symbol_type **) ptr;
+ ptr += SIZEOF_ILF_SYM_PTR_TABLE;
+
+ vars.esym_table = (SYMENT *) ptr;
+ vars.esym_ptr = (SYMENT *) ptr;
+ ptr += SIZEOF_ILF_EXT_SYMS;
+
+ vars.reltab = (arelent *) ptr;
+ vars.relcount = 0;
+ ptr += SIZEOF_ILF_RELOCS;
+
+ vars.int_reltab = (struct internal_reloc *) ptr;
+ ptr += SIZEOF_ILF_INT_RELOCS;
+
+ vars.string_table = ptr;
+ vars.string_ptr = ptr + STRING_SIZE_SIZE;
+ ptr += SIZEOF_ILF_STRINGS;
+ vars.end_string_ptr = ptr;
+
+ /* The remaining space in bim->buffer is used
+ by the pe_ILF_make_a_section() function. */
+ vars.data = ptr;
+ vars.abfd = abfd;
+ vars.sec_index = 0;
+ vars.magic = magic;
+
+ /* Create the initial .idata$<n> sections:
+ [.idata$2: Import Directory Table -- not needed]
+ .idata$4: Import Lookup Table
+ .idata$5: Import Address Table
+
+ Note we do not create a .idata$3 section as this is
+ created for us by the linker script. */
+ id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
+ id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
+ if (id4 == NULL || id5 == NULL)
+ return false;
+
+ /* Fill in the contents of these sections. */
+ if (import_name_type == IMPORT_ORDINAL)
+ {
+ if (ordinal == 0)
+ /* XXX - treat as IMPORT_NAME ??? */
+ abort ();
+
+ * (unsigned int *) id4->contents = ordinal | 0x80000000;
+ * (unsigned int *) id5->contents = ordinal | 0x80000000;
+ }
+ else
+ {
+ char * symbol;
+
+ /* Create .idata$6 - the Hint Name Table. */
+ id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
+ if (id6 == NULL)
+ return false;
+
+ /* If necessary, trim the import symbol name. */
+ symbol = symbol_name;
+
+ if (import_name_type != IMPORT_NAME)
+ /* Skip any prefix in symbol_name. */
+ while (*symbol == '@' || * symbol == '?' || * symbol == '_')
+ ++ symbol;
+
+ if (import_name_type == IMPORT_NAME_UNDECORATE)
+ {
+ /* Truncate at the first '@' */
+ while (* symbol != 0 && * symbol != '@')
+ symbol ++;
+
+ * symbol = 0;
+ }
+
+ id6->contents[0] = ordinal & 0xff;
+ id6->contents[1] = ordinal >> 8;
+
+ strcpy (id6->contents + 2, symbol);
+ }
+
+ if (import_name_type != IMPORT_ORDINAL)
+ {
+ pe_ILF_make_a_reloc (& vars, 0, BFD_RELOC_RVA, id6);
+ pe_ILF_save_relocs (& vars, id4);
+
+ pe_ILF_make_a_reloc (& vars, 0, BFD_RELOC_RVA, id6);
+ pe_ILF_save_relocs (& vars, id5);
+ }
+
+ /* Create extra sections depending upon the type of import we are dealing with. */
+ switch (import_type)
+ {
+ int i;
+
+ case IMPORT_CODE:
+ /* Create a .text section.
+ First we need to look up its contents in the jump table. */
+ for (i = NUM_ENTRIES (jtab); i--;)
+ {
+ if (jtab[i].size == 0)
+ continue;
+ if (jtab[i].magic == magic)
+ break;
+ }
+ /* If we did not find a matching entry something is wrong. */
+ if (i < 0)
+ abort ();
+
+ /* Create the .text section. */
+ text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
+ if (text == NULL)
+ return false;
+
+ /* Copy in the jump code. */
+ memcpy (text->contents, jtab[i].data, jtab[i].size);
+
+ /* Create an import symbol. */
+ pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
+ imp_sym = vars.sym_ptr_ptr - 1;
+ imp_index = vars.sym_index - 1;
+
+ /* Create a reloc for the data in the text section. */
+#ifdef MIPS_ARCH_MAGIC_WINCE
+ if (magic == MIPS_ARCH_MAGIC_WINCE)
+ {
+ pe_ILF_make_a_symbol_reloc (& vars, 0, BFD_RELOC_HI16_S,
+ (struct symbol_cache_entry **) imp_sym, imp_index);
+ pe_ILF_make_a_reloc (& vars, 0, BFD_RELOC_LO16, text);
+ pe_ILF_make_a_symbol_reloc (& vars, 4, BFD_RELOC_LO16,
+ (struct symbol_cache_entry **) imp_sym, imp_index);
+ }
+ else
+#endif
+ pe_ILF_make_a_symbol_reloc (& vars, jtab[i].offset, BFD_RELOC_32,
+ (asymbol **) imp_sym, imp_index);
+
+ pe_ILF_save_relocs (& vars, text);
+ break;
+
+ case IMPORT_DATA:
+ break;
+
+ default:
+ /* XXX code not yet written. */
+ abort ();
+ }
+
+ /* Initialise the bfd. */
+ memset (& internal_f, 0, sizeof (internal_f));
+
+ internal_f.f_magic = magic;
+ internal_f.f_symptr = 0;
+ internal_f.f_nsyms = 0;
+ internal_f.f_flags = F_AR32WR | F_LNNO; /* XXX is this correct ? */
+
+ if ( ! bfd_set_start_address (abfd, 0)
+ || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
+ return false;
+
+ if (bfd_coff_mkobject_hook (abfd, (PTR) & internal_f, NULL) == NULL)
+ return false;
+
+ coff_data (abfd)->pe = 1;
+#ifdef THUMBPEMAGIC
+ if (vars.magic == THUMBPEMAGIC)
+ /* Stop some linker warnings about thumb code not supporting interworking. */
+ coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
+#endif
+
+ /* Switch from file contents to memory contents. */
+ bfd_cache_close (abfd);
+
+ abfd->iostream = (PTR) vars.bim;
+ abfd->flags |= BFD_IN_MEMORY /* | HAS_LOCALS */;
+ abfd->where = 0;
+ obj_sym_filepos (abfd) = 0;
+
+ /* Now create a symbol describing the imported value. */
+ switch (import_type)
+ {
+ bfd_byte * ptr;
+
+ case IMPORT_CODE:
+ pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
+ BSF_NOT_AT_END | BSF_FUNCTION);
+
+ /* Create an import symbol for the DLL, without the
+ .dll suffix. */
+ ptr = strrchr (source_dll, '.');
+ if (ptr)
+ * ptr = 0;
+ pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
+ if (ptr)
+ * ptr = '.';
+ break;
+
+ case IMPORT_DATA:
+ /* Nothing to do here. */
+ break;
+
+ default:
+ /* XXX code not yet written. */
+ abort ();
+ }
+
+ /* Point the bfd at the symbol table. */
+ obj_symbols (abfd) = vars.sym_cache;
+ bfd_get_symcount (abfd) = vars.sym_index;
+
+ obj_raw_syments (abfd) = vars.native_syms;
+ obj_raw_syment_count (abfd) = vars.sym_index;
+
+ obj_coff_external_syms (abfd) = (PTR) vars.esym_table;
+ obj_coff_keep_syms (abfd) = true;
+
+ obj_convert (abfd) = vars.sym_table;
+ obj_conv_table_size (abfd) = vars.sym_index;
+
+ obj_coff_strings (abfd) = vars.string_table;
+ obj_coff_keep_strings (abfd) = true;
+
+ abfd->flags |= HAS_SYMS;
+
+ return true;
+}
+
+/* We have detected a Image Library Format archive element.
+ Decode the element and return the appropriate target. */
+static const bfd_target *
+pe_ILF_object_p (bfd * abfd)
+{
+ bfd_byte buffer[16];
+ bfd_byte * ptr;
+ bfd_byte * symbol_name;
+ bfd_byte * source_dll;
+ unsigned int machine;
+ unsigned long size;
+ unsigned int ordinal;
+ unsigned int types;
+ unsigned short magic;
+
+ /* Upon entry the first four buyes of the ILF header have
+ already been read. Now read the rest of the header. */
+ if (bfd_read (buffer, 1, 16, abfd) != 16)
+ return NULL;
+
+ ptr = buffer;
+
+ /* We do not bother to check the version number.
+ version = bfd_h_get_16 (abfd, ptr); */
+ ptr += 2;
+
+ machine = bfd_h_get_16 (abfd, ptr);
+ ptr += 2;
+
+ /* Check that the machine type is recognised. */
+ magic = 0;
+
+ switch (machine)
+ {
+ case IMAGE_FILE_MACHINE_UNKNOWN:
+ case IMAGE_FILE_MACHINE_ALPHA:
+ case IMAGE_FILE_MACHINE_ALPHA64:
+ case IMAGE_FILE_MACHINE_IA64:
+ break;
+
+ case IMAGE_FILE_MACHINE_I386:
+#ifdef I386MAGIC
+ magic = I386MAGIC;
+#endif
+ break;
+
+ case IMAGE_FILE_MACHINE_M68K:
+#ifdef MC68AGIC
+ magic = MC68MAGIC;
+#endif
+ break;
+
+ case IMAGE_FILE_MACHINE_R3000:
+ case IMAGE_FILE_MACHINE_R4000:
+ case IMAGE_FILE_MACHINE_R10000:
+
+ case IMAGE_FILE_MACHINE_MIPS16:
+ case IMAGE_FILE_MACHINE_MIPSFPU:
+ case IMAGE_FILE_MACHINE_MIPSFPU16:
+#ifdef MIPS_ARCH_MAGIC_WINCE
+ magic = MIPS_ARCH_MAGIC_WINCE;
+#endif
+ break;
+
+ case IMAGE_FILE_MACHINE_SH3:
+ case IMAGE_FILE_MACHINE_SH4:
+#ifdef SH_ARCH_MAGIC_WINCE
+ magic = SH_ARCH_MAGIC_WINCE;
+#endif
+ break;
+
+ case IMAGE_FILE_MACHINE_ARM:
+#ifdef ARMPEMAGIC
+ magic = ARMPEMAGIC;
+#endif
+ break;
+
+ case IMAGE_FILE_MACHINE_THUMB:
+#ifdef THUMBPEMAGIC
+ {
+ extern const bfd_target TARGET_LITTLE_SYM;
+
+ if (abfd->xvec == & TARGET_LITTLE_SYM)
+ magic = THUMBPEMAGIC;
+ }
+#endif
+ break;
+
+ case IMAGE_FILE_MACHINE_POWERPC:
+ /* We no longer support PowerPC. */
+ default:
+ _bfd_error_handler
+ (
+_("%s: Unrecognised machine type (0x%x) in Import Library Format archive"),
+ bfd_get_filename (abfd), machine);
+ bfd_set_error (bfd_error_malformed_archive);
+
+ return NULL;
+ break;
+ }
+
+ if (magic == 0)
+ {
+ _bfd_error_handler
+ (
+_("%s: Recognised but unhandled machine type (0x%x) in Import Library Format archive"),
+ bfd_get_filename (abfd), machine);
+ bfd_set_error (bfd_error_wrong_format);
+
+ return NULL;
+ }
+
+ /* We do not bother to check the date.
+ date = bfd_h_get_32 (abfd, ptr); */
+ ptr += 4;
+
+ size = bfd_h_get_32 (abfd, ptr);
+ ptr += 4;
+
+ if (size == 0)
+ {
+ _bfd_error_handler
+ (_("%s: size field is zero in Import Library Format header"),
+ bfd_get_filename (abfd));
+ bfd_set_error (bfd_error_malformed_archive);
+
+ return NULL;
+ }
+
+ ordinal = bfd_h_get_16 (abfd, ptr);
+ ptr += 2;
+
+ types = bfd_h_get_16 (abfd, ptr);
+ /* ptr += 2; */
+
+ /* Now read in the two strings that follow. */
+ ptr = bfd_alloc (abfd, size);
+ if (ptr == NULL)
+ return NULL;
+
+ if (bfd_read (ptr, 1, size, abfd) != size)
+ return NULL;
+
+ symbol_name = ptr;
+ source_dll = ptr + strlen (ptr) + 1;
+
+ /* Verify that the strings are null terminated. */
+ if (ptr[size - 1] != 0 || ((unsigned long) (source_dll - ptr) >= size))
+ {
+ _bfd_error_handler
+ (_("%s: string not null terminated in ILF object file."),
+ bfd_get_filename (abfd));
+ bfd_set_error (bfd_error_malformed_archive);
+
+ return NULL;
+ }
+
+ /* Now construct the bfd. */
+ if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
+ source_dll, ordinal, types))
+ return NULL;
+
+ return abfd->xvec;
+}
+
+static const bfd_target *
+pe_bfd_object_p (bfd * abfd)
+{
+ bfd_byte buffer[4];
+ struct external_PEI_DOS_hdr dos_hdr;
+ struct external_PEI_IMAGE_hdr image_hdr;
+ file_ptr offset;
+
+ /* Detect if this a Microsoft Import Library Format element. */
+ if (bfd_seek (abfd, 0x00, SEEK_SET) != 0
+ || bfd_read (buffer, 1, 4, abfd) != 4)
+ {
+ if (bfd_get_error () != bfd_error_system_call)
+ bfd_set_error (bfd_error_wrong_format);
+ return NULL;
+ }
+
+ if (bfd_h_get_32 (abfd, buffer) == 0xffff0000)
+ return pe_ILF_object_p (abfd);
+
+ if (bfd_seek (abfd, 0x00, SEEK_SET) != 0
+ || bfd_read (&dos_hdr, 1, sizeof (dos_hdr), abfd)
+ != sizeof (dos_hdr))
+ {
+ if (bfd_get_error () != bfd_error_system_call)
+ bfd_set_error (bfd_error_wrong_format);
+ return NULL;
+ }
+
+ /* There are really two magic numbers involved; the magic number
+ that says this is a NT executable (PEI) and the magic number that
+ determines the architecture. The former is DOSMAGIC, stored in
+ the e_magic field. The latter is stored in the f_magic field.
+ If the NT magic number isn't valid, the architecture magic number
+ could be mimicked by some other field (specifically, the number
+ of relocs in section 3). Since this routine can only be called
+ correctly for a PEI file, check the e_magic number here, and, if
+ it doesn't match, clobber the f_magic number so that we don't get
+ a false match. */
+ if (bfd_h_get_16 (abfd, (bfd_byte *) dos_hdr.e_magic) != DOSMAGIC)
+ {
+ bfd_set_error (bfd_error_wrong_format);
+ return NULL;
+ }
+
+ offset = bfd_h_get_32 (abfd, (bfd_byte *) dos_hdr.e_lfanew);
+ if (bfd_seek (abfd, (file_ptr) offset, SEEK_SET) != 0
+ || bfd_read (&image_hdr, 1, sizeof (image_hdr), abfd)
+ != sizeof (image_hdr))
+ {
+ if (bfd_get_error () != bfd_error_system_call)
+ bfd_set_error (bfd_error_wrong_format);
+ return NULL;
+ }
+
+ if (bfd_h_get_32 (abfd, (bfd_byte *) image_hdr.nt_signature)
+ != 0x4550)
+ {
+ bfd_set_error (bfd_error_wrong_format);
+ return NULL;
+ }
+
+ /* Here is the hack. coff_object_p wants to read filhsz bytes to
+ pick up the COFF header for PE, see "struct external_PEI_filehdr"
+ in include/coff/pe.h. We adjust so that that will work. */
+ if (bfd_seek (abfd,
+ (file_ptr) (offset - sizeof (dos_hdr)),
+ SEEK_SET)
+ != 0)
+ {
+ if (bfd_get_error () != bfd_error_system_call)
+ bfd_set_error (bfd_error_wrong_format);
+ return NULL;
+ }
+
+ return coff_object_p (abfd);
+}
+
+#define coff_object_p pe_bfd_object_p
+#endif /* COFF_IMAGE_WITH_PE */
diff --git a/contrib/binutils/bfd/sunos.c b/contrib/binutils/bfd/sunos.c
index 45e0cba..f4ada70 100644
--- a/contrib/binutils/bfd/sunos.c
+++ b/contrib/binutils/bfd/sunos.c
@@ -1,5 +1,5 @@
/* BFD backend for SunOS binaries.
- Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97, 1998
+ Copyright 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 2000
Free Software Foundation, Inc.
Written by Cygnus Support.
@@ -84,12 +84,17 @@ static boolean sunos_finish_dynamic_link
(((mtype) == M_SPARC && bfd_lookup_arch (bfd_arch_sparc, 0) != NULL) \
|| ((mtype) == M_SPARCLET \
&& bfd_lookup_arch (bfd_arch_sparc, bfd_mach_sparc_sparclet) != NULL) \
+ || ((mtype) == M_SPARCLITE_LE \
+ && bfd_lookup_arch (bfd_arch_sparc, bfd_mach_sparc_sparclet) != NULL) \
|| (((mtype) == M_UNKNOWN || (mtype) == M_68010 || (mtype) == M_68020) \
&& bfd_lookup_arch (bfd_arch_m68k, 0) != NULL))
/* Include the usual a.out support. */
#include "aoutf1.h"
+/* The SunOS 4.1.4 /usr/include/locale.h defines valid as a macro. */
+#undef valid
+
/* SunOS shared library support. We store a pointer to this structure
in obj_aout_dynamic_info (abfd). */
@@ -503,7 +508,7 @@ sunos_canonicalize_dynamic_reloc (abfd, storage, syms)
* sizeof (arelent))));
if (info->canonical_dynrel == NULL && info->dynrel_count != 0)
return -1;
-
+
to = info->canonical_dynrel;
if (obj_reloc_entry_size (abfd) == RELOC_EXT_SIZE)
@@ -1252,7 +1257,7 @@ sunos_add_one_symbol (info, abfd, name, flags, section, value, string,
/*ARGSUSED*/
struct bfd_link_needed_list *
bfd_sunos_get_needed_list (abfd, info)
- bfd *abfd;
+ bfd *abfd ATTRIBUTE_UNUSED;
struct bfd_link_info *info;
{
if (info->hash->creator != &MY(vec))
@@ -1416,7 +1421,7 @@ bfd_sunos_size_dynamic_sections (output_bfd, info, sdynptr, sneedptr,
s->contents = (bfd_byte *) bfd_alloc (output_bfd, s->_raw_size);
if (s->contents == NULL && s->_raw_size != 0)
return false;
-
+
/* The number of buckets is just the number of symbols divided
by four. To compute the final size of the hash table, we
must actually compute the hash table. Normally we need
@@ -1602,7 +1607,7 @@ static boolean
sunos_scan_std_relocs (info, abfd, sec, relocs, rel_size)
struct bfd_link_info *info;
bfd *abfd;
- asection *sec;
+ asection *sec ATTRIBUTE_UNUSED;
const struct reloc_std_external *relocs;
bfd_size_type rel_size;
{
@@ -1762,7 +1767,7 @@ static boolean
sunos_scan_ext_relocs (info, abfd, sec, relocs, rel_size)
struct bfd_link_info *info;
bfd *abfd;
- asection *sec;
+ asection *sec ATTRIBUTE_UNUSED;
const struct reloc_ext_external *relocs;
bfd_size_type rel_size;
{
@@ -2168,8 +2173,8 @@ sunos_scan_dynamic_symbol (h, data)
/*ARGSUSED*/
static boolean
sunos_link_dynamic_object (info, abfd)
- struct bfd_link_info *info;
- bfd *abfd;
+ struct bfd_link_info *info ATTRIBUTE_UNUSED;
+ bfd *abfd ATTRIBUTE_UNUSED;
{
return true;
}
@@ -2269,16 +2274,16 @@ sunos_write_dynamic_symbol (output_bfd, info, harg)
PUT_WORD (output_bfd, r_address, srel->r_address);
if (bfd_header_big_endian (output_bfd))
{
- srel->r_index[0] = (bfd_byte)(h->dynindx >> 16);
- srel->r_index[1] = (bfd_byte)(h->dynindx >> 8);
- srel->r_index[2] = (bfd_byte)(h->dynindx);
+ srel->r_index[0] = (bfd_byte) (h->dynindx >> 16);
+ srel->r_index[1] = (bfd_byte) (h->dynindx >> 8);
+ srel->r_index[2] = (bfd_byte) (h->dynindx);
srel->r_type[0] = (RELOC_STD_BITS_EXTERN_BIG
| RELOC_STD_BITS_JMPTABLE_BIG);
}
else
{
- srel->r_index[2] = (bfd_byte)(h->dynindx >> 16);
- srel->r_index[1] = (bfd_byte)(h->dynindx >> 8);
+ srel->r_index[2] = (bfd_byte) (h->dynindx >> 16);
+ srel->r_index[1] = (bfd_byte) (h->dynindx >> 8);
srel->r_index[0] = (bfd_byte)h->dynindx;
srel->r_type[0] = (RELOC_STD_BITS_EXTERN_LITTLE
| RELOC_STD_BITS_JMPTABLE_LITTLE);
@@ -2292,8 +2297,8 @@ sunos_write_dynamic_symbol (output_bfd, info, harg)
PUT_WORD (output_bfd, r_address, erel->r_address);
if (bfd_header_big_endian (output_bfd))
{
- erel->r_index[0] = (bfd_byte)(h->dynindx >> 16);
- erel->r_index[1] = (bfd_byte)(h->dynindx >> 8);
+ erel->r_index[0] = (bfd_byte) (h->dynindx >> 16);
+ erel->r_index[1] = (bfd_byte) (h->dynindx >> 8);
erel->r_index[2] = (bfd_byte)h->dynindx;
erel->r_type[0] =
(RELOC_EXT_BITS_EXTERN_BIG
@@ -2301,8 +2306,8 @@ sunos_write_dynamic_symbol (output_bfd, info, harg)
}
else
{
- erel->r_index[2] = (bfd_byte)(h->dynindx >> 16);
- erel->r_index[1] = (bfd_byte)(h->dynindx >> 8);
+ erel->r_index[2] = (bfd_byte) (h->dynindx >> 16);
+ erel->r_index[1] = (bfd_byte) (h->dynindx >> 8);
erel->r_index[0] = (bfd_byte)h->dynindx;
erel->r_type[0] =
(RELOC_EXT_BITS_EXTERN_LITTLE
@@ -2422,7 +2427,7 @@ sunos_check_dynamic_reloc (info, input_bfd, input_section, harg, reloc,
asection *input_section;
struct aout_link_hash_entry *harg;
PTR reloc;
- bfd_byte *contents;
+ bfd_byte *contents ATTRIBUTE_UNUSED;
boolean *skip;
bfd_vma *relocationp;
{
@@ -2430,6 +2435,7 @@ sunos_check_dynamic_reloc (info, input_bfd, input_section, harg, reloc,
bfd *dynobj;
boolean baserel;
boolean jmptbl;
+ boolean pcrel;
asection *s;
bfd_byte *p;
long indx;
@@ -2438,7 +2444,10 @@ sunos_check_dynamic_reloc (info, input_bfd, input_section, harg, reloc,
dynobj = sunos_hash_table (info)->dynobj;
- if (h != NULL && h->plt_offset != 0)
+ if (h != NULL
+ && h->plt_offset != 0
+ && (info->shared
+ || (h->flags & SUNOS_DEF_REGULAR) == 0))
{
asection *splt;
@@ -2458,11 +2467,13 @@ sunos_check_dynamic_reloc (info, input_bfd, input_section, harg, reloc,
{
baserel = (0 != (srel->r_type[0] & RELOC_STD_BITS_BASEREL_BIG));
jmptbl = (0 != (srel->r_type[0] & RELOC_STD_BITS_JMPTABLE_BIG));
+ pcrel = (0 != (srel->r_type[0] & RELOC_STD_BITS_PCREL_BIG));
}
else
{
baserel = (0 != (srel->r_type[0] & RELOC_STD_BITS_BASEREL_LITTLE));
jmptbl = (0 != (srel->r_type[0] & RELOC_STD_BITS_JMPTABLE_LITTLE));
+ pcrel = (0 != (srel->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE));
}
}
else
@@ -2481,6 +2492,13 @@ sunos_check_dynamic_reloc (info, input_bfd, input_section, harg, reloc,
|| r_type == RELOC_BASE13
|| r_type == RELOC_BASE22);
jmptbl = r_type == RELOC_JMP_TBL;
+ pcrel = (r_type == RELOC_DISP8
+ || r_type == RELOC_DISP16
+ || r_type == RELOC_DISP32
+ || r_type == RELOC_WDISP30
+ || r_type == RELOC_WDISP22);
+ /* We don't consider the PC10 and PC22 types to be PC relative,
+ because they are pcrel_offset. */
}
if (baserel)
@@ -2576,8 +2594,8 @@ sunos_check_dynamic_reloc (info, input_bfd, input_section, harg, reloc,
srel->r_address);
if (bfd_header_big_endian (dynobj))
{
- srel->r_index[0] = (bfd_byte)(indx >> 16);
- srel->r_index[1] = (bfd_byte)(indx >> 8);
+ srel->r_index[0] = (bfd_byte) (indx >> 16);
+ srel->r_index[1] = (bfd_byte) (indx >> 8);
srel->r_index[2] = (bfd_byte)indx;
if (h == NULL)
srel->r_type[0] = 2 << RELOC_STD_BITS_LENGTH_SH_BIG;
@@ -2590,8 +2608,8 @@ sunos_check_dynamic_reloc (info, input_bfd, input_section, harg, reloc,
}
else
{
- srel->r_index[2] = (bfd_byte)(indx >> 16);
- srel->r_index[1] = (bfd_byte)(indx >> 8);
+ srel->r_index[2] = (bfd_byte) (indx >> 16);
+ srel->r_index[1] = (bfd_byte) (indx >> 8);
srel->r_index[0] = (bfd_byte)indx;
if (h == NULL)
srel->r_type[0] = 2 << RELOC_STD_BITS_LENGTH_SH_LITTLE;
@@ -2615,8 +2633,8 @@ sunos_check_dynamic_reloc (info, input_bfd, input_section, harg, reloc,
erel->r_address);
if (bfd_header_big_endian (dynobj))
{
- erel->r_index[0] = (bfd_byte)(indx >> 16);
- erel->r_index[1] = (bfd_byte)(indx >> 8);
+ erel->r_index[0] = (bfd_byte) (indx >> 16);
+ erel->r_index[1] = (bfd_byte) (indx >> 8);
erel->r_index[2] = (bfd_byte)indx;
if (h == NULL)
erel->r_type[0] =
@@ -2628,8 +2646,8 @@ sunos_check_dynamic_reloc (info, input_bfd, input_section, harg, reloc,
}
else
{
- erel->r_index[2] = (bfd_byte)(indx >> 16);
- erel->r_index[1] = (bfd_byte)(indx >> 8);
+ erel->r_index[2] = (bfd_byte) (indx >> 16);
+ erel->r_index[1] = (bfd_byte) (indx >> 8);
erel->r_index[0] = (bfd_byte)indx;
if (h == NULL)
erel->r_type[0] =
@@ -2708,16 +2726,18 @@ sunos_check_dynamic_reloc (info, input_bfd, input_section, harg, reloc,
srel->r_address);
if (bfd_header_big_endian (dynobj))
{
- srel->r_index[0] = (bfd_byte)(indx >> 16);
- srel->r_index[1] = (bfd_byte)(indx >> 8);
+ srel->r_index[0] = (bfd_byte) (indx >> 16);
+ srel->r_index[1] = (bfd_byte) (indx >> 8);
srel->r_index[2] = (bfd_byte)indx;
}
else
{
- srel->r_index[2] = (bfd_byte)(indx >> 16);
- srel->r_index[1] = (bfd_byte)(indx >> 8);
+ srel->r_index[2] = (bfd_byte) (indx >> 16);
+ srel->r_index[1] = (bfd_byte) (indx >> 8);
srel->r_index[0] = (bfd_byte)indx;
}
+ /* FIXME: We may have to change the addend for a PC relative
+ reloc. */
}
else
{
@@ -2731,16 +2751,26 @@ sunos_check_dynamic_reloc (info, input_bfd, input_section, harg, reloc,
erel->r_address);
if (bfd_header_big_endian (dynobj))
{
- erel->r_index[0] = (bfd_byte)(indx >> 16);
- erel->r_index[1] = (bfd_byte)(indx >> 8);
+ erel->r_index[0] = (bfd_byte) (indx >> 16);
+ erel->r_index[1] = (bfd_byte) (indx >> 8);
erel->r_index[2] = (bfd_byte)indx;
}
else
{
- erel->r_index[2] = (bfd_byte)(indx >> 16);
- erel->r_index[1] = (bfd_byte)(indx >> 8);
+ erel->r_index[2] = (bfd_byte) (indx >> 16);
+ erel->r_index[1] = (bfd_byte) (indx >> 8);
erel->r_index[0] = (bfd_byte)indx;
}
+ if (pcrel && h != NULL)
+ {
+ /* Adjust the addend for the change in address. */
+ PUT_WORD (dynobj,
+ (GET_WORD (dynobj, erel->r_addend)
+ - (input_section->output_section->vma
+ + input_section->output_offset
+ - input_section->vma)),
+ erel->r_addend);
+ }
}
++s->reloc_count;
@@ -2903,7 +2933,7 @@ sunos_finish_dynamic_link (abfd, info)
PUT_WORD (dynobj,
BFD_ALIGN (obj_textsec (abfd)->_raw_size, 0x2000),
esdl.ld_text);
-
+
if (! bfd_set_section_contents (abfd, sdyn->output_section, &esdl,
(sdyn->output_offset
+ sizeof esd
diff --git a/contrib/binutils/bfd/xcoff-target.h b/contrib/binutils/bfd/xcoff-target.h
new file mode 100644
index 0000000..a3cc0c0
--- /dev/null
+++ b/contrib/binutils/bfd/xcoff-target.h
@@ -0,0 +1,194 @@
+/* Common definitions for backends based on IBM RS/6000 "XCOFF64" files.
+ Copyright 2000, 2001
+ Free Software Foundation, Inc.
+ Contributed by Cygnus Support.
+
+This file is part of BFD, the Binary File Descriptor library.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+/* Internalcoff.h and coffcode.h modify themselves based on this flag. */
+#define RS6000COFF_C 1
+
+#define SELECT_RELOC(internal, howto) \
+ { \
+ internal.r_type = howto->type; \
+ internal.r_size = \
+ ((howto->complain_on_overflow == complain_overflow_signed \
+ ? 0x80 \
+ : 0) \
+ | (howto->bitsize - 1)); \
+ }
+
+#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
+
+#define COFF_LONG_FILENAMES
+
+#define NO_COFF_SYMBOLS
+
+#define RTYPE2HOWTO(cache_ptr, dst) _bfd_xcoff_rtype2howto (cache_ptr, dst)
+
+#define coff_mkobject _bfd_xcoff_mkobject
+#define coff_bfd_copy_private_bfd_data _bfd_xcoff_copy_private_bfd_data
+#define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
+#define coff_bfd_reloc_type_lookup _bfd_xcoff_reloc_type_lookup
+#define coff_relocate_section _bfd_ppc_xcoff_relocate_section
+
+#define CORE_FILE_P _bfd_dummy_target
+
+#define coff_core_file_failing_command _bfd_nocore_core_file_failing_command
+#define coff_core_file_failing_signal _bfd_nocore_core_file_failing_signal
+#define coff_core_file_matches_executable_p \
+ _bfd_nocore_core_file_matches_executable_p
+
+#ifdef AIX_CORE
+#undef CORE_FILE_P
+#define CORE_FILE_P rs6000coff_core_p
+extern const bfd_target * rs6000coff_core_p ();
+extern boolean rs6000coff_core_file_matches_executable_p ();
+
+#undef coff_core_file_matches_executable_p
+#define coff_core_file_matches_executable_p \
+ rs6000coff_core_file_matches_executable_p
+
+extern char *rs6000coff_core_file_failing_command PARAMS ((bfd *abfd));
+#undef coff_core_file_failing_command
+#define coff_core_file_failing_command rs6000coff_core_file_failing_command
+
+extern int rs6000coff_core_file_failing_signal PARAMS ((bfd *abfd));
+#undef coff_core_file_failing_signal
+#define coff_core_file_failing_signal rs6000coff_core_file_failing_signal
+#endif /* AIX_CORE */
+
+#ifdef LYNX_CORE
+
+#undef CORE_FILE_P
+#define CORE_FILE_P lynx_core_file_p
+extern const bfd_target *lynx_core_file_p PARAMS ((bfd *abfd));
+
+extern boolean lynx_core_file_matches_executable_p PARAMS ((bfd *core_bfd,
+ bfd *exec_bfd));
+#undef coff_core_file_matches_executable_p
+#define coff_core_file_matches_executable_p lynx_core_file_matches_executable_p
+
+extern char *lynx_core_file_failing_command PARAMS ((bfd *abfd));
+#undef coff_core_file_failing_command
+#define coff_core_file_failing_command lynx_core_file_failing_command
+
+extern int lynx_core_file_failing_signal PARAMS ((bfd *abfd));
+#undef coff_core_file_failing_signal
+#define coff_core_file_failing_signal lynx_core_file_failing_signal
+
+#endif /* LYNX_CORE */
+
+#define _bfd_xcoff_bfd_get_relocated_section_contents \
+ coff_bfd_get_relocated_section_contents
+#define _bfd_xcoff_bfd_relax_section coff_bfd_relax_section
+#define _bfd_xcoff_bfd_gc_sections coff_bfd_gc_sections
+#define _bfd_xcoff_bfd_link_split_section coff_bfd_link_split_section
+
+/* XCOFF archives do not have anything which corresponds to an
+ extended name table. */
+
+#define _bfd_xcoff_slurp_extended_name_table bfd_false
+#define _bfd_xcoff_construct_extended_name_table \
+ ((boolean (*) PARAMS ((bfd *, char **, bfd_size_type *, const char **))) \
+ bfd_false)
+#define _bfd_xcoff_truncate_arname bfd_dont_truncate_arname
+
+/* We can use the standard get_elt_at_index routine. */
+
+#define _bfd_xcoff_get_elt_at_index _bfd_generic_get_elt_at_index
+
+/* XCOFF archives do not have a timestamp. */
+
+#define _bfd_xcoff_update_armap_timestamp bfd_true
+
+extern boolean _bfd_xcoff_mkobject PARAMS ((bfd *));
+extern boolean _bfd_xcoff_copy_private_bfd_data PARAMS ((bfd *, bfd *));
+extern boolean _bfd_xcoff_is_local_label_name PARAMS ((bfd *, const char *));
+extern void _bfd_xcoff_rtype2howto
+ PARAMS ((arelent *, struct internal_reloc *));
+extern reloc_howto_type *_bfd_xcoff_reloc_type_lookup
+ PARAMS ((bfd *, bfd_reloc_code_real_type));
+extern boolean _bfd_xcoff_slurp_armap PARAMS ((bfd *));
+extern const bfd_target *_bfd_xcoff_archive_p PARAMS ((bfd *));
+extern PTR _bfd_xcoff_read_ar_hdr PARAMS ((bfd *));
+extern bfd *_bfd_xcoff_openr_next_archived_file PARAMS ((bfd *, bfd *));
+extern int _bfd_xcoff_generic_stat_arch_elt PARAMS ((bfd *, struct stat *));
+extern boolean _bfd_xcoff_write_armap
+ PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
+extern boolean _bfd_xcoff_write_archive_contents PARAMS ((bfd *));
+extern int _bfd_xcoff_sizeof_headers PARAMS ((bfd *, boolean));
+extern void _bfd_xcoff_swap_sym_in PARAMS ((bfd *, PTR, PTR));
+extern unsigned int _bfd_xcoff_swap_sym_out PARAMS ((bfd *, PTR, PTR));
+extern void _bfd_xcoff_swap_aux_in PARAMS ((bfd *, PTR, int, int, int, int, PTR));
+extern unsigned int _bfd_xcoff_swap_aux_out PARAMS ((bfd *, PTR, int, int, int, int, PTR));
+
+#ifndef coff_SWAP_sym_in
+#define coff_SWAP_sym_in _bfd_xcoff_swap_sym_in
+#define coff_SWAP_sym_out _bfd_xcoff_swap_sym_out
+#define coff_SWAP_aux_in _bfd_xcoff_swap_aux_in
+#define coff_SWAP_aux_out _bfd_xcoff_swap_aux_out
+#endif
+
+#include "coffcode.h"
+
+/* The transfer vector that leads the outside world to all of the above. */
+
+const bfd_target TARGET_SYM =
+{
+ TARGET_NAME,
+ bfd_target_xcoff_flavour,
+ BFD_ENDIAN_BIG, /* data byte order is big */
+ BFD_ENDIAN_BIG, /* header byte order is big */
+
+ (HAS_RELOC | EXEC_P | /* object flags */
+ HAS_LINENO | HAS_DEBUG | DYNAMIC |
+ HAS_SYMS | HAS_LOCALS | WP_TEXT),
+
+ (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
+ 0, /* leading char */
+ '/', /* ar_pad_char */
+ 15, /* ar_max_namelen??? FIXMEmgo */
+
+ bfd_getb64, bfd_getb_signed_64, bfd_putb64,
+ bfd_getb32, bfd_getb_signed_32, bfd_putb32,
+ bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* 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_dummy_target, coff_object_p, /* bfd_check_format */
+ _bfd_xcoff_archive_p, CORE_FILE_P},
+ {bfd_false, coff_mkobject, /* bfd_set_format */
+ _bfd_generic_mkarchive, bfd_false},
+ {bfd_false, coff_write_object_contents, /* bfd_write_contents */
+ _bfd_xcoff_write_archive_contents, bfd_false},
+
+ BFD_JUMP_TABLE_GENERIC (coff),
+ BFD_JUMP_TABLE_COPY (coff),
+ BFD_JUMP_TABLE_CORE (coff),
+ BFD_JUMP_TABLE_ARCHIVE (_bfd_xcoff),
+ BFD_JUMP_TABLE_SYMBOLS (coff),
+ BFD_JUMP_TABLE_RELOCS (coff),
+ BFD_JUMP_TABLE_WRITE (coff),
+ BFD_JUMP_TABLE_LINK (_bfd_xcoff),
+ BFD_JUMP_TABLE_DYNAMIC (_bfd_xcoff),
+
+ NULL,
+
+ COFF_SWAP_TABLE
+};
diff --git a/contrib/binutils/bfd/xcofflink.c b/contrib/binutils/bfd/xcofflink.c
new file mode 100644
index 0000000..5580e9b
--- /dev/null
+++ b/contrib/binutils/bfd/xcofflink.c
@@ -0,0 +1,6631 @@
+/* POWER/PowerPC XCOFF linker support.
+ Copyright 1995, 1996, 1997, 1998, 1999, 2000
+ Free Software Foundation, Inc.
+ Written by Ian Lance Taylor <ian@cygnus.com>, Cygnus Support.
+
+This file is part of BFD, the Binary File Descriptor library.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#include "bfd.h"
+#include "sysdep.h"
+#include "bfdlink.h"
+#include "libbfd.h"
+#include "coff/internal.h"
+#include "libcoff.h"
+
+/* This file holds the XCOFF linker code. */
+
+#define STRING_SIZE_SIZE (4)
+
+/* Get the XCOFF hash table entries for a BFD. */
+#define obj_xcoff_sym_hashes(bfd) \
+ ((struct xcoff_link_hash_entry **) obj_coff_sym_hashes (bfd))
+
+/* XCOFF relocation types. These probably belong in a header file
+ somewhere. The relocations are described in the function
+ _bfd_ppc_xcoff_relocate_section in this file. */
+
+#define R_POS (0x00)
+#define R_NEG (0x01)
+#define R_REL (0x02)
+#define R_TOC (0x03)
+#define R_RTB (0x04)
+#define R_GL (0x05)
+#define R_TCL (0x06)
+#define R_BA (0x08)
+#define R_BR (0x0a)
+#define R_RL (0x0c)
+#define R_RLA (0x0d)
+#define R_REF (0x0f)
+#define R_TRL (0x12)
+#define R_TRLA (0x13)
+#define R_RRTBI (0x14)
+#define R_RRTBA (0x15)
+#define R_CAI (0x16)
+#define R_CREL (0x17)
+#define R_RBA (0x18)
+#define R_RBAC (0x19)
+#define R_RBR (0x1a)
+#define R_RBRC (0x1b)
+
+/* The first word of global linkage code. This must be modified by
+ filling in the correct TOC offset. */
+
+#define XCOFF_GLINK_FIRST (0x81820000) /* lwz r12,0(r2) */
+
+/* The remaining words of global linkage code. */
+
+static unsigned long xcoff_glink_code[] = {
+ 0x90410014, /* stw r2,20(r1) */
+ 0x800c0000, /* lwz r0,0(r12) */
+ 0x804c0004, /* lwz r2,4(r12) */
+ 0x7c0903a6, /* mtctr r0 */
+ 0x4e800420, /* bctr */
+ 0x0, /* start of traceback table */
+ 0x000c8000, /* traceback table */
+ 0x0 /* traceback table */
+};
+
+#define XCOFF_GLINK_SIZE \
+ (((sizeof xcoff_glink_code / sizeof xcoff_glink_code[0]) * 4) + 4)
+
+/* We reuse the SEC_ROM flag as a mark flag for garbage collection.
+ This flag will only be used on input sections. */
+
+#define SEC_MARK (SEC_ROM)
+
+/* The ldhdr structure. This appears at the start of the .loader
+ section. */
+
+struct internal_ldhdr {
+ /* The version number: currently always 1. */
+ unsigned long l_version;
+ /* The number of symbol table entries. */
+ bfd_size_type l_nsyms;
+ /* The number of relocation table entries. */
+ bfd_size_type l_nreloc;
+ /* The length of the import file string table. */
+ bfd_size_type l_istlen;
+ /* The number of import files. */
+ bfd_size_type l_nimpid;
+ /* The offset from the start of the .loader section to the first
+ entry in the import file table. */
+ bfd_size_type l_impoff;
+ /* The length of the string table. */
+ bfd_size_type l_stlen;
+ /* The offset from the start of the .loader section to the first
+ entry in the string table. */
+ bfd_size_type l_stoff;
+};
+
+struct external_ldhdr {
+ bfd_byte l_version[4];
+ bfd_byte l_nsyms[4];
+ bfd_byte l_nreloc[4];
+ bfd_byte l_istlen[4];
+ bfd_byte l_nimpid[4];
+ bfd_byte l_impoff[4];
+ bfd_byte l_stlen[4];
+ bfd_byte l_stoff[4];
+};
+
+#define LDHDRSZ (8 * 4)
+
+/* The ldsym structure. This is used to represent a symbol in the
+ .loader section. */
+
+struct internal_ldsym {
+ union {
+ /* The symbol name if <= SYMNMLEN characters. */
+ char _l_name[SYMNMLEN];
+ struct {
+ /* Zero if the symbol name is more than SYMNMLEN characters. */
+ long _l_zeroes;
+ /* The offset in the string table if the symbol name is more
+ than SYMNMLEN characters. */
+ long _l_offset;
+ } _l_l;
+ } _l;
+ /* The symbol value. */
+ bfd_vma l_value;
+ /* The symbol section number. */
+ short l_scnum;
+ /* The symbol type and flags. */
+ char l_smtype;
+ /* The symbol storage class. */
+ char l_smclas;
+ /* The import file ID. */
+ bfd_size_type l_ifile;
+ /* Offset to the parameter type check string. */
+ bfd_size_type l_parm;
+};
+
+struct external_ldsym {
+ union {
+ bfd_byte _l_name[SYMNMLEN];
+ struct {
+ bfd_byte _l_zeroes[4];
+ bfd_byte _l_offset[4];
+ } _l_l;
+ } _l;
+ bfd_byte l_value[4];
+ bfd_byte l_scnum[2];
+ bfd_byte l_smtype[1];
+ bfd_byte l_smclas[1];
+ bfd_byte l_ifile[4];
+ bfd_byte l_parm[4];
+};
+
+#define LDSYMSZ (8 + 3 * 4 + 2 + 2)
+
+/* These flags are for the l_smtype field (the lower three bits are an
+ XTY_* value). */
+
+/* Imported symbol. */
+#define L_IMPORT (0x40)
+/* Entry point. */
+#define L_ENTRY (0x20)
+/* Exported symbol. */
+#define L_EXPORT (0x10)
+
+/* The ldrel structure. This is used to represent a reloc in the
+ .loader section. */
+
+struct internal_ldrel {
+ /* The reloc address. */
+ bfd_vma l_vaddr;
+ /* The symbol table index in the .loader section symbol table. */
+ bfd_size_type l_symndx;
+ /* The relocation type and size. */
+ short l_rtype;
+ /* The section number this relocation applies to. */
+ short l_rsecnm;
+};
+
+struct external_ldrel {
+ bfd_byte l_vaddr[4];
+ bfd_byte l_symndx[4];
+ bfd_byte l_rtype[2];
+ bfd_byte l_rsecnm[2];
+};
+
+#define LDRELSZ (2 * 4 + 2 * 2)
+
+/* The list of import files. */
+
+struct xcoff_import_file {
+ /* The next entry in the list. */
+ struct xcoff_import_file *next;
+ /* The path. */
+ const char *path;
+ /* The file name. */
+ const char *file;
+ /* The member name. */
+ const char *member;
+};
+
+/* An entry in the XCOFF linker hash table. */
+
+struct xcoff_link_hash_entry {
+ struct bfd_link_hash_entry root;
+
+ /* Symbol index in output file. Set to -1 initially. Set to -2 if
+ there is a reloc against this symbol. */
+ long indx;
+
+ /* If we have created a TOC entry for this symbol, this is the .tc
+ section which holds it. */
+ asection *toc_section;
+
+ union {
+ /* If we have created a TOC entry (the XCOFF_SET_TOC flag is set),
+ this is the offset in toc_section. */
+ bfd_vma toc_offset;
+ /* If the TOC entry comes from an input file, this is set to the
+ symbol index of the C_HIDEXT XMC_TC or XMC_TD symbol. */
+ long toc_indx;
+ } u;
+
+ /* If this symbol is a function entry point which is called, this
+ field holds a pointer to the function descriptor. If this symbol
+ is a function descriptor, this field holds a pointer to the
+ function entry point. */
+ struct xcoff_link_hash_entry *descriptor;
+
+ /* The .loader symbol table entry, if there is one. */
+ struct internal_ldsym *ldsym;
+
+ /* If XCOFF_BUILT_LDSYM is set, this is the .loader symbol table
+ index. If XCOFF_BUILD_LDSYM is clear, and XCOFF_IMPORT is set,
+ this is the l_ifile value. */
+ long ldindx;
+
+ /* Some linker flags. */
+ unsigned short flags;
+ /* Symbol is referenced by a regular object. */
+#define XCOFF_REF_REGULAR (01)
+ /* Symbol is defined by a regular object. */
+#define XCOFF_DEF_REGULAR (02)
+ /* Symbol is defined by a dynamic object. */
+#define XCOFF_DEF_DYNAMIC (04)
+ /* Symbol is used in a reloc being copied into the .loader section. */
+#define XCOFF_LDREL (010)
+ /* Symbol is the entry point. */
+#define XCOFF_ENTRY (020)
+ /* Symbol is called; this is, it appears in a R_BR reloc. */
+#define XCOFF_CALLED (040)
+ /* Symbol needs the TOC entry filled in. */
+#define XCOFF_SET_TOC (0100)
+ /* Symbol is explicitly imported. */
+#define XCOFF_IMPORT (0200)
+ /* Symbol is explicitly exported. */
+#define XCOFF_EXPORT (0400)
+ /* Symbol has been processed by xcoff_build_ldsyms. */
+#define XCOFF_BUILT_LDSYM (01000)
+ /* Symbol is mentioned by a section which was not garbage collected. */
+#define XCOFF_MARK (02000)
+ /* Symbol size is recorded in size_list list from hash table. */
+#define XCOFF_HAS_SIZE (04000)
+ /* Symbol is a function descriptor. */
+#define XCOFF_DESCRIPTOR (010000)
+ /* Multiple definitions have been for the symbol. */
+#define XCOFF_MULTIPLY_DEFINED (020000)
+
+ /* The storage mapping class. */
+ unsigned char smclas;
+};
+
+/* The XCOFF linker hash table. */
+
+struct xcoff_link_hash_table {
+ struct bfd_link_hash_table root;
+
+ /* The .debug string hash table. We need to compute this while
+ reading the input files, so that we know how large the .debug
+ section will be before we assign section positions. */
+ struct bfd_strtab_hash *debug_strtab;
+
+ /* The .debug section we will use for the final output. */
+ asection *debug_section;
+
+ /* The .loader section we will use for the final output. */
+ asection *loader_section;
+
+ /* A count of non TOC relative relocs which will need to be
+ allocated in the .loader section. */
+ size_t ldrel_count;
+
+ /* The .loader section header. */
+ struct internal_ldhdr ldhdr;
+
+ /* The .gl section we use to hold global linkage code. */
+ asection *linkage_section;
+
+ /* The .tc section we use to hold toc entries we build for global
+ linkage code. */
+ asection *toc_section;
+
+ /* The .ds section we use to hold function descriptors which we
+ create for exported symbols. */
+ asection *descriptor_section;
+
+ /* The list of import files. */
+ struct xcoff_import_file *imports;
+
+ /* Required alignment of sections within the output file. */
+ unsigned long file_align;
+
+ /* Whether the .text section must be read-only. */
+ boolean textro;
+
+ /* Whether garbage collection was done. */
+ boolean gc;
+
+ /* A linked list of symbols for which we have size information. */
+ struct xcoff_link_size_list {
+ struct xcoff_link_size_list *next;
+ struct xcoff_link_hash_entry *h;
+ bfd_size_type size;
+ } *size_list;
+
+ /* Magic sections: _text, _etext, _data, _edata, _end, end. */
+ asection *special_sections[6];
+};
+
+/* Information we keep for each section in the output file during the
+ final link phase. */
+
+struct xcoff_link_section_info {
+ /* The relocs to be output. */
+ struct internal_reloc *relocs;
+ /* For each reloc against a global symbol whose index was not known
+ when the reloc was handled, the global hash table entry. */
+ struct xcoff_link_hash_entry **rel_hashes;
+ /* If there is a TOC relative reloc against a global symbol, and the
+ index of the TOC symbol is not known when the reloc was handled,
+ an entry is added to this linked list. This is not an array,
+ like rel_hashes, because this case is quite uncommon. */
+ struct xcoff_toc_rel_hash {
+ struct xcoff_toc_rel_hash *next;
+ struct xcoff_link_hash_entry *h;
+ struct internal_reloc *rel;
+ } *toc_rel_hashes;
+};
+
+/* Information that we pass around while doing the final link step. */
+
+struct xcoff_final_link_info {
+ /* General link information. */
+ struct bfd_link_info *info;
+ /* Output BFD. */
+ bfd *output_bfd;
+ /* Hash table for long symbol names. */
+ struct bfd_strtab_hash *strtab;
+ /* Array of information kept for each output section, indexed by the
+ target_index field. */
+ struct xcoff_link_section_info *section_info;
+ /* Symbol index of last C_FILE symbol (-1 if none). */
+ long last_file_index;
+ /* Contents of last C_FILE symbol. */
+ struct internal_syment last_file;
+ /* Symbol index of TOC symbol. */
+ long toc_symindx;
+ /* Start of .loader symbols. */
+ struct external_ldsym *ldsym;
+ /* Next .loader reloc to swap out. */
+ struct external_ldrel *ldrel;
+ /* File position of start of line numbers. */
+ file_ptr line_filepos;
+ /* Buffer large enough to hold swapped symbols of any input file. */
+ struct internal_syment *internal_syms;
+ /* Buffer large enough to hold output indices of symbols of any
+ input file. */
+ long *sym_indices;
+ /* Buffer large enough to hold output symbols for any input file. */
+ bfd_byte *outsyms;
+ /* Buffer large enough to hold external line numbers for any input
+ section. */
+ bfd_byte *linenos;
+ /* Buffer large enough to hold any input section. */
+ bfd_byte *contents;
+ /* Buffer large enough to hold external relocs of any input section. */
+ bfd_byte *external_relocs;
+};
+
+static void xcoff_swap_ldhdr_in
+ PARAMS ((bfd *, const struct external_ldhdr *, struct internal_ldhdr *));
+static void xcoff_swap_ldhdr_out
+ PARAMS ((bfd *, const struct internal_ldhdr *, struct external_ldhdr *));
+static void xcoff_swap_ldsym_in
+ PARAMS ((bfd *, const struct external_ldsym *, struct internal_ldsym *));
+static void xcoff_swap_ldsym_out
+ PARAMS ((bfd *, const struct internal_ldsym *, struct external_ldsym *));
+static void xcoff_swap_ldrel_in
+ PARAMS ((bfd *, const struct external_ldrel *, struct internal_ldrel *));
+static void xcoff_swap_ldrel_out
+ PARAMS ((bfd *, const struct internal_ldrel *, struct external_ldrel *));
+static struct bfd_hash_entry *xcoff_link_hash_newfunc
+ PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
+static boolean xcoff_get_section_contents PARAMS ((bfd *, asection *));
+static struct internal_reloc *xcoff_read_internal_relocs
+ PARAMS ((bfd *, asection *, boolean, bfd_byte *, boolean,
+ struct internal_reloc *));
+static boolean xcoff_link_add_object_symbols
+ PARAMS ((bfd *, struct bfd_link_info *));
+static boolean xcoff_link_check_archive_element
+ PARAMS ((bfd *, struct bfd_link_info *, boolean *));
+static boolean xcoff_link_check_ar_symbols
+ PARAMS ((bfd *, struct bfd_link_info *, boolean *));
+static boolean xcoff_link_check_dynamic_ar_symbols
+ PARAMS ((bfd *, struct bfd_link_info *, boolean *));
+static bfd_size_type xcoff_find_reloc
+ PARAMS ((struct internal_reloc *, bfd_size_type, bfd_vma));
+static boolean xcoff_link_add_symbols PARAMS ((bfd *, struct bfd_link_info *));
+static boolean xcoff_link_add_dynamic_symbols
+ PARAMS ((bfd *, struct bfd_link_info *));
+static boolean xcoff_mark_symbol
+ PARAMS ((struct bfd_link_info *, struct xcoff_link_hash_entry *));
+static boolean xcoff_mark PARAMS ((struct bfd_link_info *, asection *));
+static void xcoff_sweep PARAMS ((struct bfd_link_info *));
+static boolean xcoff_build_ldsyms
+ PARAMS ((struct xcoff_link_hash_entry *, PTR));
+static boolean xcoff_link_input_bfd
+ PARAMS ((struct xcoff_final_link_info *, bfd *));
+static boolean xcoff_write_global_symbol
+ PARAMS ((struct xcoff_link_hash_entry *, PTR));
+static boolean xcoff_reloc_link_order
+ PARAMS ((bfd *, struct xcoff_final_link_info *, asection *,
+ struct bfd_link_order *));
+static int xcoff_sort_relocs PARAMS ((const PTR, const PTR));
+
+/* Routines to swap information in the XCOFF .loader section. If we
+ ever need to write an XCOFF loader, this stuff will need to be
+ moved to another file shared by the linker (which XCOFF calls the
+ ``binder'') and the loader. */
+
+/* Swap in the ldhdr structure. */
+
+static void
+xcoff_swap_ldhdr_in (abfd, src, dst)
+ bfd *abfd;
+ const struct external_ldhdr *src;
+ struct internal_ldhdr *dst;
+{
+ dst->l_version = bfd_get_32 (abfd, src->l_version);
+ dst->l_nsyms = bfd_get_32 (abfd, src->l_nsyms);
+ dst->l_nreloc = bfd_get_32 (abfd, src->l_nreloc);
+ dst->l_istlen = bfd_get_32 (abfd, src->l_istlen);
+ dst->l_nimpid = bfd_get_32 (abfd, src->l_nimpid);
+ dst->l_impoff = bfd_get_32 (abfd, src->l_impoff);
+ dst->l_stlen = bfd_get_32 (abfd, src->l_stlen);
+ dst->l_stoff = bfd_get_32 (abfd, src->l_stoff);
+}
+
+/* Swap out the ldhdr structure. */
+
+static void
+xcoff_swap_ldhdr_out (abfd, src, dst)
+ bfd *abfd;
+ const struct internal_ldhdr *src;
+ struct external_ldhdr *dst;
+{
+ bfd_put_32 (abfd, src->l_version, dst->l_version);
+ bfd_put_32 (abfd, src->l_nsyms, dst->l_nsyms);
+ bfd_put_32 (abfd, src->l_nreloc, dst->l_nreloc);
+ bfd_put_32 (abfd, src->l_istlen, dst->l_istlen);
+ bfd_put_32 (abfd, src->l_nimpid, dst->l_nimpid);
+ bfd_put_32 (abfd, src->l_impoff, dst->l_impoff);
+ bfd_put_32 (abfd, src->l_stlen, dst->l_stlen);
+ bfd_put_32 (abfd, src->l_stoff, dst->l_stoff);
+}
+
+/* Swap in the ldsym structure. */
+
+static void
+xcoff_swap_ldsym_in (abfd, src, dst)
+ bfd *abfd;
+ const struct external_ldsym *src;
+ struct internal_ldsym *dst;
+{
+ if (bfd_get_32 (abfd, src->_l._l_l._l_zeroes) != 0)
+ memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
+ else
+ {
+ dst->_l._l_l._l_zeroes = 0;
+ dst->_l._l_l._l_offset = bfd_get_32 (abfd, src->_l._l_l._l_offset);
+ }
+ dst->l_value = bfd_get_32 (abfd, src->l_value);
+ dst->l_scnum = bfd_get_16 (abfd, src->l_scnum);
+ dst->l_smtype = bfd_get_8 (abfd, src->l_smtype);
+ dst->l_smclas = bfd_get_8 (abfd, src->l_smclas);
+ dst->l_ifile = bfd_get_32 (abfd, src->l_ifile);
+ dst->l_parm = bfd_get_32 (abfd, src->l_parm);
+}
+
+/* Swap out the ldsym structure. */
+
+static void
+xcoff_swap_ldsym_out (abfd, src, dst)
+ bfd *abfd;
+ const struct internal_ldsym *src;
+ struct external_ldsym *dst;
+{
+ if (src->_l._l_l._l_zeroes != 0)
+ memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
+ else
+ {
+ bfd_put_32 (abfd, 0, dst->_l._l_l._l_zeroes);
+ bfd_put_32 (abfd, src->_l._l_l._l_offset, dst->_l._l_l._l_offset);
+ }
+ bfd_put_32 (abfd, src->l_value, dst->l_value);
+ bfd_put_16 (abfd, src->l_scnum, dst->l_scnum);
+ bfd_put_8 (abfd, src->l_smtype, dst->l_smtype);
+ bfd_put_8 (abfd, src->l_smclas, dst->l_smclas);
+ bfd_put_32 (abfd, src->l_ifile, dst->l_ifile);
+ bfd_put_32 (abfd, src->l_parm, dst->l_parm);
+}
+
+/* Swap in the ldrel structure. */
+
+static void
+xcoff_swap_ldrel_in (abfd, src, dst)
+ bfd *abfd;
+ const struct external_ldrel *src;
+ struct internal_ldrel *dst;
+{
+ 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, dst)
+ bfd *abfd;
+ const struct internal_ldrel *src;
+ struct external_ldrel *dst;
+{
+ bfd_put_32 (abfd, src->l_vaddr, dst->l_vaddr);
+ bfd_put_32 (abfd, src->l_symndx, dst->l_symndx);
+ bfd_put_16 (abfd, src->l_rtype, dst->l_rtype);
+ bfd_put_16 (abfd, src->l_rsecnm, dst->l_rsecnm);
+}
+
+/* Routines to read XCOFF dynamic information. This don't really
+ belong here, but we already have the ldsym manipulation routines
+ here. */
+
+/* Read the contents of a section. */
+
+static boolean
+xcoff_get_section_contents (abfd, sec)
+ bfd *abfd;
+ asection *sec;
+{
+ if (coff_section_data (abfd, sec) == NULL)
+ {
+ sec->used_by_bfd = bfd_zalloc (abfd,
+ sizeof (struct coff_section_tdata));
+ if (sec->used_by_bfd == NULL)
+ return false;
+ }
+
+ if (coff_section_data (abfd, sec)->contents == NULL)
+ {
+ coff_section_data (abfd, sec)->contents =
+ (bfd_byte *) bfd_malloc (sec->_raw_size);
+ if (coff_section_data (abfd, sec)->contents == NULL)
+ return false;
+
+ if (! bfd_get_section_contents (abfd, sec,
+ coff_section_data (abfd, sec)->contents,
+ (file_ptr) 0, sec->_raw_size))
+ return false;
+ }
+
+ return true;
+}
+
+/* Get the size required to hold the dynamic symbols. */
+
+long
+_bfd_xcoff_get_dynamic_symtab_upper_bound (abfd)
+ bfd *abfd;
+{
+ asection *lsec;
+ bfd_byte *contents;
+ struct internal_ldhdr ldhdr;
+
+ if ((abfd->flags & DYNAMIC) == 0)
+ {
+ bfd_set_error (bfd_error_invalid_operation);
+ return -1;
+ }
+
+ lsec = bfd_get_section_by_name (abfd, ".loader");
+ if (lsec == NULL)
+ {
+ bfd_set_error (bfd_error_no_symbols);
+ return -1;
+ }
+
+ if (! xcoff_get_section_contents (abfd, lsec))
+ return -1;
+ contents = coff_section_data (abfd, lsec)->contents;
+
+ xcoff_swap_ldhdr_in (abfd, (struct external_ldhdr *) contents, &ldhdr);
+
+ return (ldhdr.l_nsyms + 1) * sizeof (asymbol *);
+}
+
+/* Get the dynamic symbols. */
+
+long
+_bfd_xcoff_canonicalize_dynamic_symtab (abfd, psyms)
+ bfd *abfd;
+ asymbol **psyms;
+{
+ asection *lsec;
+ bfd_byte *contents;
+ struct internal_ldhdr ldhdr;
+ const char *strings;
+ struct external_ldsym *elsym, *elsymend;
+ coff_symbol_type *symbuf;
+
+ if ((abfd->flags & DYNAMIC) == 0)
+ {
+ bfd_set_error (bfd_error_invalid_operation);
+ return -1;
+ }
+
+ lsec = bfd_get_section_by_name (abfd, ".loader");
+ if (lsec == NULL)
+ {
+ bfd_set_error (bfd_error_no_symbols);
+ return -1;
+ }
+
+ if (! xcoff_get_section_contents (abfd, lsec))
+ return -1;
+ contents = coff_section_data (abfd, lsec)->contents;
+
+ coff_section_data (abfd, lsec)->keep_contents = true;
+
+ xcoff_swap_ldhdr_in (abfd, (struct external_ldhdr *) contents, &ldhdr);
+
+ strings = (char *) contents + ldhdr.l_stoff;
+
+ symbuf = ((coff_symbol_type *)
+ bfd_zalloc (abfd, ldhdr.l_nsyms * sizeof (coff_symbol_type)));
+ if (symbuf == NULL)
+ return -1;
+
+ elsym = (struct external_ldsym *) (contents + LDHDRSZ);
+ elsymend = elsym + ldhdr.l_nsyms;
+ for (; elsym < elsymend; elsym++, symbuf++, psyms++)
+ {
+ struct internal_ldsym ldsym;
+
+ xcoff_swap_ldsym_in (abfd, elsym, &ldsym);
+
+ symbuf->symbol.the_bfd = abfd;
+
+ if (ldsym._l._l_l._l_zeroes == 0)
+ symbuf->symbol.name = strings + ldsym._l._l_l._l_offset;
+ else
+ {
+ int i;
+
+ for (i = 0; i < SYMNMLEN; i++)
+ if (ldsym._l._l_name[i] == '\0')
+ break;
+ if (i < SYMNMLEN)
+ symbuf->symbol.name = (char *) elsym->_l._l_name;
+ else
+ {
+ char *c;
+
+ c = bfd_alloc (abfd, SYMNMLEN + 1);
+ if (c == NULL)
+ return -1;
+ memcpy (c, ldsym._l._l_name, SYMNMLEN);
+ c[SYMNMLEN] = '\0';
+ symbuf->symbol.name = c;
+ }
+ }
+
+ if (ldsym.l_smclas == XMC_XO)
+ symbuf->symbol.section = bfd_abs_section_ptr;
+ else
+ symbuf->symbol.section = coff_section_from_bfd_index (abfd,
+ ldsym.l_scnum);
+ symbuf->symbol.value = ldsym.l_value - symbuf->symbol.section->vma;
+
+ symbuf->symbol.flags = BSF_NO_FLAGS;
+ if ((ldsym.l_smtype & L_EXPORT) != 0)
+ symbuf->symbol.flags |= BSF_GLOBAL;
+
+ /* FIXME: We have no way to record the other information stored
+ with the loader symbol. */
+
+ *psyms = (asymbol *) symbuf;
+ }
+
+ *psyms = NULL;
+
+ return ldhdr.l_nsyms;
+}
+
+/* Get the size required to hold the dynamic relocs. */
+
+long
+_bfd_xcoff_get_dynamic_reloc_upper_bound (abfd)
+ bfd *abfd;
+{
+ asection *lsec;
+ bfd_byte *contents;
+ struct internal_ldhdr ldhdr;
+
+ if ((abfd->flags & DYNAMIC) == 0)
+ {
+ bfd_set_error (bfd_error_invalid_operation);
+ return -1;
+ }
+
+ lsec = bfd_get_section_by_name (abfd, ".loader");
+ if (lsec == NULL)
+ {
+ bfd_set_error (bfd_error_no_symbols);
+ return -1;
+ }
+
+ if (! xcoff_get_section_contents (abfd, lsec))
+ return -1;
+ contents = coff_section_data (abfd, lsec)->contents;
+
+ xcoff_swap_ldhdr_in (abfd, (struct external_ldhdr *) contents, &ldhdr);
+
+ return (ldhdr.l_nreloc + 1) * sizeof (arelent *);
+}
+
+/* The typical dynamic reloc. */
+
+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 */
+
+/* Get the dynamic relocs. */
+
+long
+_bfd_xcoff_canonicalize_dynamic_reloc (abfd, prelocs, syms)
+ bfd *abfd;
+ arelent **prelocs;
+ asymbol **syms;
+{
+ asection *lsec;
+ bfd_byte *contents;
+ struct internal_ldhdr ldhdr;
+ arelent *relbuf;
+ struct external_ldrel *elrel, *elrelend;
+
+ if ((abfd->flags & DYNAMIC) == 0)
+ {
+ bfd_set_error (bfd_error_invalid_operation);
+ return -1;
+ }
+
+ lsec = bfd_get_section_by_name (abfd, ".loader");
+ if (lsec == NULL)
+ {
+ bfd_set_error (bfd_error_no_symbols);
+ return -1;
+ }
+
+ if (! xcoff_get_section_contents (abfd, lsec))
+ return -1;
+ contents = coff_section_data (abfd, lsec)->contents;
+
+ xcoff_swap_ldhdr_in (abfd, (struct external_ldhdr *) contents, &ldhdr);
+
+ relbuf = (arelent *) bfd_alloc (abfd, ldhdr.l_nreloc * sizeof (arelent));
+ if (relbuf == NULL)
+ return -1;
+
+ elrel = ((struct external_ldrel *)
+ (contents + LDHDRSZ + ldhdr.l_nsyms * LDSYMSZ));
+ elrelend = elrel + ldhdr.l_nreloc;
+ for (; elrel < elrelend; elrel++, relbuf++, prelocs++)
+ {
+ struct internal_ldrel ldrel;
+
+ xcoff_swap_ldrel_in (abfd, elrel, &ldrel);
+
+ if (ldrel.l_symndx >= 3)
+ relbuf->sym_ptr_ptr = syms + (ldrel.l_symndx - 3);
+ else
+ {
+ const char *name;
+ asection *sec;
+
+ switch (ldrel.l_symndx)
+ {
+ case 0:
+ name = ".text";
+ break;
+ case 1:
+ name = ".data";
+ break;
+ case 2:
+ name = ".bss";
+ break;
+ default:
+ abort ();
+ break;
+ }
+
+ sec = bfd_get_section_by_name (abfd, name);
+ if (sec == NULL)
+ {
+ bfd_set_error (bfd_error_bad_value);
+ return -1;
+ }
+
+ relbuf->sym_ptr_ptr = sec->symbol_ptr_ptr;
+ }
+
+ relbuf->address = ldrel.l_vaddr;
+ relbuf->addend = 0;
+
+ /* Most dynamic relocs have the same type. FIXME: This is only
+ correct if ldrel.l_rtype == 0. In other cases, we should use
+ a different howto. */
+ relbuf->howto = &xcoff_dynamic_reloc;
+
+ /* FIXME: We have no way to record the l_rsecnm field. */
+
+ *prelocs = relbuf;
+ }
+
+ *prelocs = NULL;
+
+ return ldhdr.l_nreloc;
+}
+
+/* Routine to create an entry in an XCOFF link hash table. */
+
+static struct bfd_hash_entry *
+xcoff_link_hash_newfunc (entry, table, string)
+ struct bfd_hash_entry *entry;
+ struct bfd_hash_table *table;
+ const char *string;
+{
+ struct xcoff_link_hash_entry *ret = (struct xcoff_link_hash_entry *) entry;
+
+ /* Allocate the structure if it has not already been allocated by a
+ subclass. */
+ if (ret == (struct xcoff_link_hash_entry *) NULL)
+ ret = ((struct xcoff_link_hash_entry *)
+ bfd_hash_allocate (table, sizeof (struct xcoff_link_hash_entry)));
+ if (ret == (struct xcoff_link_hash_entry *) NULL)
+ return (struct bfd_hash_entry *) ret;
+
+ /* Call the allocation method of the superclass. */
+ ret = ((struct xcoff_link_hash_entry *)
+ _bfd_link_hash_newfunc ((struct bfd_hash_entry *) ret,
+ table, string));
+ if (ret != NULL)
+ {
+ /* Set local fields. */
+ ret->indx = -1;
+ ret->toc_section = NULL;
+ ret->u.toc_indx = -1;
+ ret->descriptor = NULL;
+ ret->ldsym = NULL;
+ ret->ldindx = -1;
+ ret->flags = 0;
+ ret->smclas = XMC_UA;
+ }
+
+ return (struct bfd_hash_entry *) ret;
+}
+
+/* Create a XCOFF link hash table. */
+
+struct bfd_link_hash_table *
+_bfd_xcoff_bfd_link_hash_table_create (abfd)
+ bfd *abfd;
+{
+ struct xcoff_link_hash_table *ret;
+
+ ret = ((struct xcoff_link_hash_table *)
+ bfd_alloc (abfd, sizeof (struct xcoff_link_hash_table)));
+ if (ret == (struct xcoff_link_hash_table *) NULL)
+ return (struct bfd_link_hash_table *) NULL;
+ if (! _bfd_link_hash_table_init (&ret->root, abfd, xcoff_link_hash_newfunc))
+ {
+ bfd_release (abfd, ret);
+ return (struct bfd_link_hash_table *) NULL;
+ }
+
+ ret->debug_strtab = _bfd_xcoff_stringtab_init ();
+ ret->debug_section = NULL;
+ ret->loader_section = NULL;
+ ret->ldrel_count = 0;
+ memset (&ret->ldhdr, 0, sizeof (struct internal_ldhdr));
+ ret->linkage_section = NULL;
+ ret->toc_section = NULL;
+ ret->descriptor_section = NULL;
+ ret->imports = NULL;
+ ret->file_align = 0;
+ ret->textro = false;
+ ret->gc = false;
+ memset (ret->special_sections, 0, sizeof ret->special_sections);
+
+ /* The linker will always generate a full a.out header. We need to
+ record that fact now, before the sizeof_headers routine could be
+ called. */
+ xcoff_data (abfd)->full_aouthdr = true;
+
+ return &ret->root;
+}
+
+/* Look up an entry in an XCOFF link hash table. */
+
+#define xcoff_link_hash_lookup(table, string, create, copy, follow) \
+ ((struct xcoff_link_hash_entry *) \
+ bfd_link_hash_lookup (&(table)->root, (string), (create), (copy),\
+ (follow)))
+
+/* Traverse an XCOFF link hash table. */
+
+#define xcoff_link_hash_traverse(table, func, info) \
+ (bfd_link_hash_traverse \
+ (&(table)->root, \
+ (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
+ (info)))
+
+/* Get the XCOFF link hash table from the info structure. This is
+ just a cast. */
+
+#define xcoff_hash_table(p) ((struct xcoff_link_hash_table *) ((p)->hash))
+
+/* Read internal relocs for an XCOFF csect. This is a wrapper around
+ _bfd_coff_read_internal_relocs which tries to take advantage of any
+ relocs which may have been cached for the enclosing section. */
+
+static struct internal_reloc *
+xcoff_read_internal_relocs (abfd, sec, cache, external_relocs,
+ require_internal, internal_relocs)
+ bfd *abfd;
+ asection *sec;
+ boolean cache;
+ bfd_byte *external_relocs;
+ boolean require_internal;
+ struct internal_reloc *internal_relocs;
+{
+ if (coff_section_data (abfd, sec) != NULL
+ && coff_section_data (abfd, sec)->relocs == NULL
+ && xcoff_section_data (abfd, sec) != NULL)
+ {
+ asection *enclosing;
+
+ enclosing = xcoff_section_data (abfd, sec)->enclosing;
+
+ if (enclosing != NULL
+ && (coff_section_data (abfd, enclosing) == NULL
+ || coff_section_data (abfd, enclosing)->relocs == NULL)
+ && cache
+ && enclosing->reloc_count > 0)
+ {
+ if (_bfd_coff_read_internal_relocs (abfd, enclosing, true,
+ external_relocs, false,
+ (struct internal_reloc *) NULL)
+ == NULL)
+ return NULL;
+ }
+
+ if (enclosing != NULL
+ && coff_section_data (abfd, enclosing) != NULL
+ && coff_section_data (abfd, enclosing)->relocs != NULL)
+ {
+ size_t off;
+
+ off = ((sec->rel_filepos - enclosing->rel_filepos)
+ / bfd_coff_relsz (abfd));
+ if (! require_internal)
+ return coff_section_data (abfd, enclosing)->relocs + off;
+ memcpy (internal_relocs,
+ coff_section_data (abfd, enclosing)->relocs + off,
+ sec->reloc_count * sizeof (struct internal_reloc));
+ return internal_relocs;
+ }
+ }
+
+ return _bfd_coff_read_internal_relocs (abfd, sec, cache, external_relocs,
+ require_internal, internal_relocs);
+}
+
+/* Given an XCOFF BFD, add symbols to the global hash table as
+ appropriate. */
+
+boolean
+_bfd_xcoff_bfd_link_add_symbols (abfd, info)
+ bfd *abfd;
+ struct bfd_link_info *info;
+{
+ switch (bfd_get_format (abfd))
+ {
+ case bfd_object:
+ return xcoff_link_add_object_symbols (abfd, info);
+
+ case bfd_archive:
+ /* If the archive has a map, do the usual search. We then need
+ to check the archive for stripped dynamic objects, because
+ they will not appear in the archive map even though they
+ should, perhaps, be included. If the archive has no map, we
+ just consider each object file in turn, since that apparently
+ is what the AIX native linker does. */
+ if (bfd_has_map (abfd))
+ {
+ if (! (_bfd_generic_link_add_archive_symbols
+ (abfd, info, xcoff_link_check_archive_element)))
+ return false;
+ }
+
+ {
+ bfd *member;
+
+ member = bfd_openr_next_archived_file (abfd, (bfd *) NULL);
+ while (member != NULL)
+ {
+ if (bfd_check_format (member, bfd_object)
+ && (! bfd_has_map (abfd)
+ || ((member->flags & DYNAMIC) != 0
+ && (member->flags & HAS_SYMS) == 0)))
+ {
+ boolean needed;
+
+ if (! xcoff_link_check_archive_element (member, info, &needed))
+ return false;
+ if (needed)
+ member->archive_pass = -1;
+ }
+ member = bfd_openr_next_archived_file (abfd, member);
+ }
+ }
+
+ return true;
+
+ default:
+ bfd_set_error (bfd_error_wrong_format);
+ return false;
+ }
+}
+
+/* Add symbols from an XCOFF object file. */
+
+static boolean
+xcoff_link_add_object_symbols (abfd, info)
+ bfd *abfd;
+ struct bfd_link_info *info;
+{
+ if (! _bfd_coff_get_external_symbols (abfd))
+ return false;
+ if (! xcoff_link_add_symbols (abfd, info))
+ return false;
+ if (! info->keep_memory)
+ {
+ if (! _bfd_coff_free_symbols (abfd))
+ return false;
+ }
+ return true;
+}
+
+/* Check a single archive element to see if we need to include it in
+ the link. *PNEEDED is set according to whether this element is
+ needed in the link or not. This is called via
+ _bfd_generic_link_add_archive_symbols. */
+
+static boolean
+xcoff_link_check_archive_element (abfd, info, pneeded)
+ bfd *abfd;
+ struct bfd_link_info *info;
+ boolean *pneeded;
+{
+ if (! _bfd_coff_get_external_symbols (abfd))
+ return false;
+
+ if (! xcoff_link_check_ar_symbols (abfd, info, pneeded))
+ return false;
+
+ if (*pneeded)
+ {
+ if (! xcoff_link_add_symbols (abfd, info))
+ return false;
+ }
+
+ if (! info->keep_memory || ! *pneeded)
+ {
+ if (! _bfd_coff_free_symbols (abfd))
+ return false;
+ }
+
+ return true;
+}
+
+/* Look through the symbols to see if this object file should be
+ included in the link. */
+
+static boolean
+xcoff_link_check_ar_symbols (abfd, info, pneeded)
+ bfd *abfd;
+ struct bfd_link_info *info;
+ boolean *pneeded;
+{
+ bfd_size_type symesz;
+ bfd_byte *esym;
+ bfd_byte *esym_end;
+
+ *pneeded = false;
+
+ if ((abfd->flags & DYNAMIC) != 0
+ && ! info->static_link
+ && info->hash->creator == abfd->xvec)
+ return xcoff_link_check_dynamic_ar_symbols (abfd, info, pneeded);
+
+ symesz = bfd_coff_symesz (abfd);
+ esym = (bfd_byte *) obj_coff_external_syms (abfd);
+ esym_end = esym + obj_raw_syment_count (abfd) * symesz;
+ while (esym < esym_end)
+ {
+ struct internal_syment sym;
+
+ bfd_coff_swap_sym_in (abfd, (PTR) esym, (PTR) &sym);
+
+ if (sym.n_sclass == C_EXT && sym.n_scnum != N_UNDEF)
+ {
+ const char *name;
+ char buf[SYMNMLEN + 1];
+ struct bfd_link_hash_entry *h;
+
+ /* This symbol is externally visible, and is defined by this
+ object file. */
+
+ name = _bfd_coff_internal_syment_name (abfd, &sym, buf);
+ if (name == NULL)
+ return false;
+ h = bfd_link_hash_lookup (info->hash, name, false, false, true);
+
+ /* We are only interested in symbols that are currently
+ undefined. If a symbol is currently known to be common,
+ XCOFF linkers do not bring in an object file which
+ defines it. We also don't bring in symbols to satisfy
+ undefined references in shared objects. */
+ if (h != (struct bfd_link_hash_entry *) NULL
+ && h->type == bfd_link_hash_undefined
+ && (info->hash->creator != abfd->xvec
+ || (((struct xcoff_link_hash_entry *) h)->flags
+ & XCOFF_DEF_DYNAMIC) == 0))
+ {
+ if (! (*info->callbacks->add_archive_element) (info, abfd, name))
+ return false;
+ *pneeded = true;
+ return true;
+ }
+ }
+
+ esym += (sym.n_numaux + 1) * symesz;
+ }
+
+ /* We do not need this object file. */
+ return true;
+}
+
+/* Look through the loader symbols to see if this dynamic object
+ should be included in the link. The native linker uses the loader
+ symbols, not the normal symbol table, so we do too. */
+
+static boolean
+xcoff_link_check_dynamic_ar_symbols (abfd, info, pneeded)
+ bfd *abfd;
+ struct bfd_link_info *info;
+ boolean *pneeded;
+{
+ asection *lsec;
+ bfd_byte *buf;
+ struct internal_ldhdr ldhdr;
+ const char *strings;
+ struct external_ldsym *elsym, *elsymend;
+
+ *pneeded = false;
+
+ lsec = bfd_get_section_by_name (abfd, ".loader");
+ if (lsec == NULL)
+ {
+ /* There are no symbols, so don't try to include it. */
+ return true;
+ }
+
+ if (! xcoff_get_section_contents (abfd, lsec))
+ return false;
+ buf = coff_section_data (abfd, lsec)->contents;
+
+ xcoff_swap_ldhdr_in (abfd, (struct external_ldhdr *) buf, &ldhdr);
+
+ strings = (char *) buf + ldhdr.l_stoff;
+
+ elsym = (struct external_ldsym *) (buf + LDHDRSZ);
+ elsymend = elsym + ldhdr.l_nsyms;
+ for (; elsym < elsymend; elsym++)
+ {
+ struct internal_ldsym ldsym;
+ char nambuf[SYMNMLEN + 1];
+ const char *name;
+ struct bfd_link_hash_entry *h;
+
+ xcoff_swap_ldsym_in (abfd, elsym, &ldsym);
+
+ /* We are only interested in exported symbols. */
+ if ((ldsym.l_smtype & L_EXPORT) == 0)
+ continue;
+
+ if (ldsym._l._l_l._l_zeroes == 0)
+ name = strings + ldsym._l._l_l._l_offset;
+ else
+ {
+ memcpy (nambuf, ldsym._l._l_name, SYMNMLEN);
+ nambuf[SYMNMLEN] = '\0';
+ name = nambuf;
+ }
+
+ h = bfd_link_hash_lookup (info->hash, name, false, false, true);
+
+ /* We are only interested in symbols that are currently
+ undefined. At this point we know that we are using an XCOFF
+ hash table. */
+ if (h != NULL
+ && h->type == bfd_link_hash_undefined
+ && (((struct xcoff_link_hash_entry *) h)->flags
+ & XCOFF_DEF_DYNAMIC) == 0)
+ {
+ if (! (*info->callbacks->add_archive_element) (info, abfd, name))
+ return false;
+ *pneeded = true;
+ return true;
+ }
+ }
+
+ /* We do not need this shared object. */
+
+ if (buf != NULL && ! coff_section_data (abfd, lsec)->keep_contents)
+ {
+ free (coff_section_data (abfd, lsec)->contents);
+ coff_section_data (abfd, lsec)->contents = NULL;
+ }
+
+ return true;
+}
+
+/* Returns the index of reloc in RELOCS with the least address greater
+ than or equal to ADDRESS. The relocs are sorted by address. */
+
+static bfd_size_type
+xcoff_find_reloc (relocs, count, address)
+ struct internal_reloc *relocs;
+ bfd_size_type count;
+ bfd_vma address;
+{
+ bfd_size_type min, max, this;
+
+ if (count < 2)
+ {
+ if (count == 1 && relocs[0].r_vaddr < address)
+ return 1;
+ else
+ return 0;
+ }
+
+ min = 0;
+ max = count;
+
+ /* Do a binary search over (min,max]. */
+ while (min + 1 < max)
+ {
+ bfd_vma raddr;
+
+ this = (max + min) / 2;
+ raddr = relocs[this].r_vaddr;
+ if (raddr > address)
+ max = this;
+ else if (raddr < address)
+ min = this;
+ else
+ {
+ min = this;
+ break;
+ }
+ }
+
+ if (relocs[min].r_vaddr < address)
+ return min + 1;
+
+ while (min > 0
+ && relocs[min - 1].r_vaddr == address)
+ --min;
+
+ return min;
+}
+
+/* Add all the symbols from an object file to the hash table.
+
+ XCOFF is a weird format. A normal XCOFF .o files will have three
+ COFF sections--.text, .data, and .bss--but each COFF section will
+ contain many csects. These csects are described in the symbol
+ table. From the linker's point of view, each csect must be
+ considered a section in its own right. For example, a TOC entry is
+ handled as a small XMC_TC csect. The linker must be able to merge
+ different TOC entries together, which means that it must be able to
+ extract the XMC_TC csects from the .data section of the input .o
+ file.
+
+ From the point of view of our linker, this is, of course, a hideous
+ nightmare. We cope by actually creating sections for each csect,
+ and discarding the original sections. We then have to handle the
+ relocation entries carefully, since the only way to tell which
+ csect they belong to is to examine the address. */
+
+static boolean
+xcoff_link_add_symbols (abfd, info)
+ bfd *abfd;
+ struct bfd_link_info *info;
+{
+ unsigned int n_tmask;
+ unsigned int n_btshft;
+ boolean default_copy;
+ bfd_size_type symcount;
+ struct xcoff_link_hash_entry **sym_hash;
+ asection **csect_cache;
+ bfd_size_type linesz;
+ asection *o;
+ asection *last_real;
+ boolean keep_syms;
+ asection *csect;
+ unsigned int csect_index;
+ asection *first_csect;
+ bfd_size_type symesz;
+ bfd_byte *esym;
+ bfd_byte *esym_end;
+ struct reloc_info_struct
+ {
+ struct internal_reloc *relocs;
+ asection **csects;
+ bfd_byte *linenos;
+ } *reloc_info = NULL;
+
+ keep_syms = obj_coff_keep_syms (abfd);
+
+ if ((abfd->flags & DYNAMIC) != 0
+ && ! info->static_link)
+ {
+ if (! xcoff_link_add_dynamic_symbols (abfd, info))
+ return false;
+ }
+
+ if (info->hash->creator == abfd->xvec)
+ {
+ /* We need to build a .loader section, so we do it here. This
+ won't work if we're producing an XCOFF output file with no
+ XCOFF input files. FIXME. */
+ if (xcoff_hash_table (info)->loader_section == NULL)
+ {
+ asection *lsec;
+
+ lsec = bfd_make_section_anyway (abfd, ".loader");
+ if (lsec == NULL)
+ goto error_return;
+ xcoff_hash_table (info)->loader_section = lsec;
+ lsec->flags |= SEC_HAS_CONTENTS | SEC_IN_MEMORY;
+ }
+ /* Likewise for the linkage section. */
+ if (xcoff_hash_table (info)->linkage_section == NULL)
+ {
+ asection *lsec;
+
+ lsec = bfd_make_section_anyway (abfd, ".gl");
+ if (lsec == NULL)
+ goto error_return;
+ xcoff_hash_table (info)->linkage_section = lsec;
+ lsec->flags |= (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
+ | SEC_IN_MEMORY);
+ lsec->alignment_power = 2;
+ }
+ /* Likewise for the TOC section. */
+ if (xcoff_hash_table (info)->toc_section == NULL)
+ {
+ asection *tsec;
+
+ tsec = bfd_make_section_anyway (abfd, ".tc");
+ if (tsec == NULL)
+ goto error_return;
+ xcoff_hash_table (info)->toc_section = tsec;
+ tsec->flags |= (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
+ | SEC_IN_MEMORY);
+ tsec->alignment_power = 2;
+ }
+ /* Likewise for the descriptor section. */
+ if (xcoff_hash_table (info)->descriptor_section == NULL)
+ {
+ asection *dsec;
+
+ dsec = bfd_make_section_anyway (abfd, ".ds");
+ if (dsec == NULL)
+ goto error_return;
+ xcoff_hash_table (info)->descriptor_section = dsec;
+ dsec->flags |= (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
+ | SEC_IN_MEMORY);
+ dsec->alignment_power = 2;
+ }
+ /* Likewise for the .debug section. */
+ if (xcoff_hash_table (info)->debug_section == NULL
+ && info->strip != strip_all)
+ {
+ asection *dsec;
+
+ dsec = bfd_make_section_anyway (abfd, ".debug");
+ if (dsec == NULL)
+ goto error_return;
+ xcoff_hash_table (info)->debug_section = dsec;
+ dsec->flags |= SEC_HAS_CONTENTS | SEC_IN_MEMORY;
+ }
+ }
+
+ if ((abfd->flags & DYNAMIC) != 0
+ && ! info->static_link)
+ return true;
+
+ n_tmask = coff_data (abfd)->local_n_tmask;
+ n_btshft = coff_data (abfd)->local_n_btshft;
+
+ /* Define macros so that ISFCN, et. al., macros work correctly. */
+#define N_TMASK n_tmask
+#define N_BTSHFT n_btshft
+
+ if (info->keep_memory)
+ default_copy = false;
+ else
+ default_copy = true;
+
+ symcount = obj_raw_syment_count (abfd);
+
+ /* We keep a list of the linker hash table entries that correspond
+ to each external symbol. */
+ sym_hash = ((struct xcoff_link_hash_entry **)
+ bfd_alloc (abfd,
+ (symcount
+ * sizeof (struct xcoff_link_hash_entry *))));
+ if (sym_hash == NULL && symcount != 0)
+ goto error_return;
+ coff_data (abfd)->sym_hashes = (struct coff_link_hash_entry **) sym_hash;
+ memset (sym_hash, 0,
+ (size_t) symcount * sizeof (struct xcoff_link_hash_entry *));
+
+ /* Because of the weird stuff we are doing with XCOFF csects, we can
+ not easily determine which section a symbol is in, so we store
+ the information in the tdata for the input file. */
+ csect_cache = ((asection **)
+ bfd_alloc (abfd, symcount * sizeof (asection *)));
+ if (csect_cache == NULL && symcount != 0)
+ goto error_return;
+ xcoff_data (abfd)->csects = csect_cache;
+ memset (csect_cache, 0, (size_t) symcount * sizeof (asection *));
+
+ /* While splitting sections into csects, we need to assign the
+ relocs correctly. The relocs and the csects must both be in
+ order by VMA within a given section, so we handle this by
+ scanning along the relocs as we process the csects. We index
+ into reloc_info using the section target_index. */
+ reloc_info = ((struct reloc_info_struct *)
+ bfd_malloc ((abfd->section_count + 1)
+ * sizeof (struct reloc_info_struct)));
+ if (reloc_info == NULL)
+ goto error_return;
+ memset ((PTR) reloc_info, 0,
+ (abfd->section_count + 1) * sizeof (struct reloc_info_struct));
+
+ /* Read in the relocs and line numbers for each section. */
+ linesz = bfd_coff_linesz (abfd);
+ last_real = NULL;
+ for (o = abfd->sections; o != NULL; o = o->next)
+ {
+ last_real = o;
+ if ((o->flags & SEC_RELOC) != 0)
+ {
+ reloc_info[o->target_index].relocs =
+ xcoff_read_internal_relocs (abfd, o, true, (bfd_byte *) NULL,
+ false, (struct internal_reloc *) NULL);
+ reloc_info[o->target_index].csects =
+ (asection **) bfd_malloc (o->reloc_count * sizeof (asection *));
+ if (reloc_info[o->target_index].csects == NULL)
+ goto error_return;
+ memset (reloc_info[o->target_index].csects, 0,
+ o->reloc_count * sizeof (asection *));
+ }
+
+ if ((info->strip == strip_none || info->strip == strip_some)
+ && o->lineno_count > 0)
+ {
+ bfd_byte *linenos;
+
+ linenos = (bfd_byte *) bfd_malloc (o->lineno_count * linesz);
+ if (linenos == NULL)
+ goto error_return;
+ reloc_info[o->target_index].linenos = linenos;
+ if (bfd_seek (abfd, o->line_filepos, SEEK_SET) != 0
+ || (bfd_read (linenos, linesz, o->lineno_count, abfd)
+ != linesz * o->lineno_count))
+ goto error_return;
+ }
+ }
+
+ /* Don't let the linker relocation routines discard the symbols. */
+ obj_coff_keep_syms (abfd) = true;
+
+ csect = NULL;
+ csect_index = 0;
+ first_csect = NULL;
+
+ symesz = bfd_coff_symesz (abfd);
+ BFD_ASSERT (symesz == bfd_coff_auxesz (abfd));
+ esym = (bfd_byte *) obj_coff_external_syms (abfd);
+ esym_end = esym + symcount * symesz;
+ while (esym < esym_end)
+ {
+ struct internal_syment sym;
+ union internal_auxent aux;
+ const char *name;
+ char buf[SYMNMLEN + 1];
+ int smtyp;
+ flagword flags;
+ asection *section;
+ bfd_vma value;
+ struct xcoff_link_hash_entry *set_toc;
+
+ bfd_coff_swap_sym_in (abfd, (PTR) esym, (PTR) &sym);
+
+ /* In this pass we are only interested in symbols with csect
+ information. */
+ if (sym.n_sclass != C_EXT && sym.n_sclass != C_HIDEXT)
+ {
+ if (sym.n_sclass == C_FILE && csect != NULL)
+ {
+ xcoff_section_data (abfd, csect)->last_symndx =
+ ((esym
+ - (bfd_byte *) obj_coff_external_syms (abfd))
+ / symesz);
+ csect = NULL;
+ }
+
+ if (csect != NULL)
+ *csect_cache = csect;
+ else if (first_csect == NULL || sym.n_sclass == C_FILE)
+ *csect_cache = coff_section_from_bfd_index (abfd, sym.n_scnum);
+ else
+ *csect_cache = NULL;
+ esym += (sym.n_numaux + 1) * symesz;
+ sym_hash += sym.n_numaux + 1;
+ csect_cache += sym.n_numaux + 1;
+ continue;
+ }
+
+ name = _bfd_coff_internal_syment_name (abfd, &sym, buf);
+ if (name == NULL)
+ goto error_return;
+
+ /* If this symbol has line number information attached to it,
+ and we're not stripping it, count the number of entries and
+ add them to the count for this csect. In the final link pass
+ we are going to attach line number information by symbol,
+ rather than by section, in order to more easily handle
+ garbage collection. */
+ if ((info->strip == strip_none || info->strip == strip_some)
+ && sym.n_numaux > 1
+ && csect != NULL
+ && ISFCN (sym.n_type))
+ {
+ union internal_auxent auxlin;
+
+ bfd_coff_swap_aux_in (abfd, (PTR) (esym + symesz),
+ sym.n_type, sym.n_sclass,
+ 0, sym.n_numaux, (PTR) &auxlin);
+ if (auxlin.x_sym.x_fcnary.x_fcn.x_lnnoptr != 0)
+ {
+ asection *enclosing;
+ bfd_size_type linoff;
+
+ enclosing = xcoff_section_data (abfd, csect)->enclosing;
+ if (enclosing == NULL)
+ {
+ (*_bfd_error_handler)
+ (_("%s: `%s' has line numbers but no enclosing section"),
+ bfd_get_filename (abfd), name);
+ bfd_set_error (bfd_error_bad_value);
+ goto error_return;
+ }
+ linoff = (auxlin.x_sym.x_fcnary.x_fcn.x_lnnoptr
+ - enclosing->line_filepos);
+ if (linoff < enclosing->lineno_count * linesz)
+ {
+ struct internal_lineno lin;
+ bfd_byte *linpstart;
+
+ linpstart = (reloc_info[enclosing->target_index].linenos
+ + linoff);
+ bfd_coff_swap_lineno_in (abfd, (PTR) linpstart, (PTR) &lin);
+ if (lin.l_lnno == 0
+ && ((bfd_size_type) lin.l_addr.l_symndx
+ == ((esym
+ - (bfd_byte *) obj_coff_external_syms (abfd))
+ / symesz)))
+ {
+ bfd_byte *linpend, *linp;
+
+ linpend = (reloc_info[enclosing->target_index].linenos
+ + enclosing->lineno_count * linesz);
+ for (linp = linpstart + linesz;
+ linp < linpend;
+ linp += linesz)
+ {
+ bfd_coff_swap_lineno_in (abfd, (PTR) linp,
+ (PTR) &lin);
+ if (lin.l_lnno == 0)
+ break;
+ }
+ csect->lineno_count += (linp - linpstart) / linesz;
+ /* The setting of line_filepos will only be
+ useful if all the line number entries for a
+ csect are contiguous; this only matters for
+ error reporting. */
+ if (csect->line_filepos == 0)
+ csect->line_filepos =
+ auxlin.x_sym.x_fcnary.x_fcn.x_lnnoptr;
+ }
+ }
+ }
+ }
+
+ /* Pick up the csect auxiliary information. */
+
+ if (sym.n_numaux == 0)
+ {
+ (*_bfd_error_handler)
+ (_("%s: class %d symbol `%s' has no aux entries"),
+ bfd_get_filename (abfd), sym.n_sclass, name);
+ bfd_set_error (bfd_error_bad_value);
+ goto error_return;
+ }
+
+ bfd_coff_swap_aux_in (abfd,
+ (PTR) (esym + symesz * sym.n_numaux),
+ sym.n_type, sym.n_sclass,
+ sym.n_numaux - 1, sym.n_numaux,
+ (PTR) &aux);
+
+ smtyp = SMTYP_SMTYP (aux.x_csect.x_smtyp);
+
+ flags = BSF_GLOBAL;
+ section = NULL;
+ value = 0;
+ set_toc = NULL;
+
+ switch (smtyp)
+ {
+ default:
+ (*_bfd_error_handler)
+ (_("%s: symbol `%s' has unrecognized csect type %d"),
+ bfd_get_filename (abfd), name, smtyp);
+ bfd_set_error (bfd_error_bad_value);
+ goto error_return;
+
+ case XTY_ER:
+ /* This is an external reference. */
+ if (sym.n_sclass == C_HIDEXT
+ || sym.n_scnum != N_UNDEF
+ || aux.x_csect.x_scnlen.l != 0)
+ {
+ (*_bfd_error_handler)
+ (_("%s: bad XTY_ER symbol `%s': class %d scnum %d scnlen %d"),
+ bfd_get_filename (abfd), name, sym.n_sclass, sym.n_scnum,
+ aux.x_csect.x_scnlen.l);
+ bfd_set_error (bfd_error_bad_value);
+ goto error_return;
+ }
+
+ /* An XMC_XO external reference is actually a reference to
+ an absolute location. */
+ if (aux.x_csect.x_smclas != XMC_XO)
+ section = bfd_und_section_ptr;
+ else
+ {
+ section = bfd_abs_section_ptr;
+ value = sym.n_value;
+ }
+ break;
+
+ case XTY_SD:
+ /* This is a csect definition. */
+
+ if (csect != NULL)
+ {
+ xcoff_section_data (abfd, csect)->last_symndx =
+ ((esym
+ - (bfd_byte *) obj_coff_external_syms (abfd))
+ / symesz);
+ }
+
+ csect = NULL;
+ csect_index = -1;
+
+ /* When we see a TOC anchor, we record the TOC value. */
+ if (aux.x_csect.x_smclas == XMC_TC0)
+ {
+ if (sym.n_sclass != C_HIDEXT
+ || aux.x_csect.x_scnlen.l != 0)
+ {
+ (*_bfd_error_handler)
+ (_("%s: XMC_TC0 symbol `%s' is class %d scnlen %d"),
+ bfd_get_filename (abfd), name, sym.n_sclass,
+ aux.x_csect.x_scnlen.l);
+ bfd_set_error (bfd_error_bad_value);
+ goto error_return;
+ }
+ xcoff_data (abfd)->toc = sym.n_value;
+ }
+
+ /* We must merge TOC entries for the same symbol. We can
+ merge two TOC entries if they are both C_HIDEXT, they
+ both have the same name, they are both 4 bytes long, and
+ they both have a relocation table entry for an external
+ symbol with the same name. Unfortunately, this means
+ that we must look through the relocations. Ick. */
+ if (aux.x_csect.x_smclas == XMC_TC
+ && sym.n_sclass == C_HIDEXT
+ && aux.x_csect.x_scnlen.l == 4
+ && info->hash->creator == abfd->xvec)
+ {
+ asection *enclosing;
+ struct internal_reloc *relocs;
+ bfd_size_type relindx;
+ struct internal_reloc *rel;
+
+ enclosing = coff_section_from_bfd_index (abfd, sym.n_scnum);
+ if (enclosing == NULL)
+ goto error_return;
+
+ relocs = reloc_info[enclosing->target_index].relocs;
+ relindx = xcoff_find_reloc (relocs, enclosing->reloc_count,
+ sym.n_value);
+ rel = relocs + relindx;
+ if (relindx < enclosing->reloc_count
+ && rel->r_vaddr == (bfd_vma) sym.n_value
+ && rel->r_size == 31
+ && rel->r_type == R_POS)
+ {
+ bfd_byte *erelsym;
+ struct internal_syment relsym;
+
+ erelsym = ((bfd_byte *) obj_coff_external_syms (abfd)
+ + rel->r_symndx * symesz);
+ bfd_coff_swap_sym_in (abfd, (PTR) erelsym, (PTR) &relsym);
+ if (relsym.n_sclass == C_EXT)
+ {
+ const char *relname;
+ char relbuf[SYMNMLEN + 1];
+ boolean copy;
+ struct xcoff_link_hash_entry *h;
+
+ /* At this point we know that the TOC entry is
+ for an externally visible symbol. */
+ relname = _bfd_coff_internal_syment_name (abfd, &relsym,
+ relbuf);
+ if (relname == NULL)
+ goto error_return;
+
+ /* We only merge TOC entries if the TC name is
+ the same as the symbol name. This handles
+ the normal case, but not common cases like
+ SYM.P4 which gcc generates to store SYM + 4
+ in the TOC. FIXME. */
+ if (strcmp (name, relname) == 0)
+ {
+ copy = (! info->keep_memory
+ || relsym._n._n_n._n_zeroes != 0
+ || relsym._n._n_n._n_offset == 0);
+ h = xcoff_link_hash_lookup (xcoff_hash_table (info),
+ relname, true, copy,
+ false);
+ if (h == NULL)
+ goto error_return;
+
+ /* At this point h->root.type could be
+ bfd_link_hash_new. That should be OK,
+ since we know for sure that we will come
+ across this symbol as we step through the
+ file. */
+
+ /* We store h in *sym_hash for the
+ convenience of the relocate_section
+ function. */
+ *sym_hash = h;
+
+ if (h->toc_section != NULL)
+ {
+ asection **rel_csects;
+
+ /* We already have a TOC entry for this
+ symbol, so we can just ignore this
+ one. */
+ rel_csects =
+ reloc_info[enclosing->target_index].csects;
+ rel_csects[relindx] = bfd_und_section_ptr;
+ break;
+ }
+
+ /* We are about to create a TOC entry for
+ this symbol. */
+ set_toc = h;
+ }
+ }
+ }
+ }
+
+ /* We need to create a new section. We get the name from
+ the csect storage mapping class, so that the linker can
+ accumulate similar csects together. */
+ {
+ static const char *csect_name_by_class[] = {
+ ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
+ ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL, ".tc0",
+ ".td"
+ };
+ const char *csect_name;
+ asection *enclosing;
+
+ if ((aux.x_csect.x_smclas >=
+ sizeof csect_name_by_class / sizeof csect_name_by_class[0])
+ || csect_name_by_class[aux.x_csect.x_smclas] == NULL)
+ {
+ (*_bfd_error_handler)
+ (_("%s: symbol `%s' has unrecognized smclas %d"),
+ bfd_get_filename (abfd), name, aux.x_csect.x_smclas);
+ bfd_set_error (bfd_error_bad_value);
+ goto error_return;
+ }
+
+ csect_name = csect_name_by_class[aux.x_csect.x_smclas];
+ csect = bfd_make_section_anyway (abfd, csect_name);
+ if (csect == NULL)
+ goto error_return;
+ enclosing = coff_section_from_bfd_index (abfd, sym.n_scnum);
+ if (enclosing == NULL)
+ goto error_return;
+ if (! bfd_is_abs_section (enclosing)
+ && ((bfd_vma) sym.n_value < enclosing->vma
+ || ((bfd_vma) sym.n_value + aux.x_csect.x_scnlen.l
+ > enclosing->vma + enclosing->_raw_size)))
+ {
+ (*_bfd_error_handler)
+ (_("%s: csect `%s' not in enclosing section"),
+ bfd_get_filename (abfd), name);
+ bfd_set_error (bfd_error_bad_value);
+ goto error_return;
+ }
+ csect->vma = sym.n_value;
+ csect->filepos = (enclosing->filepos
+ + sym.n_value
+ - enclosing->vma);
+ csect->_raw_size = aux.x_csect.x_scnlen.l;
+ csect->flags |= SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS;
+ csect->alignment_power = SMTYP_ALIGN (aux.x_csect.x_smtyp);
+
+ /* Record the enclosing section in the tdata for this new
+ section. */
+ csect->used_by_bfd =
+ (PTR) bfd_zalloc (abfd, sizeof (struct coff_section_tdata));
+ if (csect->used_by_bfd == NULL)
+ goto error_return;
+ coff_section_data (abfd, csect)->tdata =
+ bfd_zalloc (abfd, sizeof (struct xcoff_section_tdata));
+ if (coff_section_data (abfd, csect)->tdata == NULL)
+ goto error_return;
+ xcoff_section_data (abfd, csect)->enclosing = enclosing;
+ xcoff_section_data (abfd, csect)->lineno_count =
+ enclosing->lineno_count;
+
+ if (enclosing->owner == abfd)
+ {
+ struct internal_reloc *relocs;
+ bfd_size_type relindx;
+ struct internal_reloc *rel;
+ asection **rel_csect;
+
+ relocs = reloc_info[enclosing->target_index].relocs;
+ relindx = xcoff_find_reloc (relocs, enclosing->reloc_count,
+ csect->vma);
+ rel = relocs + relindx;
+ rel_csect = (reloc_info[enclosing->target_index].csects
+ + relindx);
+ csect->rel_filepos = (enclosing->rel_filepos
+ + relindx * bfd_coff_relsz (abfd));
+ while (relindx < enclosing->reloc_count
+ && *rel_csect == NULL
+ && rel->r_vaddr < csect->vma + csect->_raw_size)
+ {
+ *rel_csect = csect;
+ csect->flags |= SEC_RELOC;
+ ++csect->reloc_count;
+ ++relindx;
+ ++rel;
+ ++rel_csect;
+ }
+ }
+
+ /* There are a number of other fields and section flags
+ which we do not bother to set. */
+
+ csect_index = ((esym
+ - (bfd_byte *) obj_coff_external_syms (abfd))
+ / symesz);
+
+ xcoff_section_data (abfd, csect)->first_symndx = csect_index;
+
+ if (first_csect == NULL)
+ first_csect = csect;
+
+ /* If this symbol is C_EXT, we treat it as starting at the
+ beginning of the newly created section. */
+ if (sym.n_sclass == C_EXT)
+ {
+ section = csect;
+ value = 0;
+ }
+
+ /* If this is a TOC section for a symbol, record it. */
+ if (set_toc != NULL)
+ set_toc->toc_section = csect;
+ }
+ break;
+
+ case XTY_LD:
+ /* This is a label definition. The x_scnlen field is the
+ symbol index of the csect. I believe that this must
+ always follow the appropriate XTY_SD symbol, so I will
+ insist on it. */
+ {
+ boolean bad;
+
+ bad = false;
+ if (aux.x_csect.x_scnlen.l < 0
+ || (aux.x_csect.x_scnlen.l
+ >= esym - (bfd_byte *) obj_coff_external_syms (abfd)))
+ bad = true;
+ if (! bad)
+ {
+ section = xcoff_data (abfd)->csects[aux.x_csect.x_scnlen.l];
+ if (section == NULL
+ || (section->flags & SEC_HAS_CONTENTS) == 0)
+ bad = true;
+ }
+ if (bad)
+ {
+ (*_bfd_error_handler)
+ (_("%s: misplaced XTY_LD `%s'"),
+ bfd_get_filename (abfd), name);
+ bfd_set_error (bfd_error_bad_value);
+ goto error_return;
+ }
+
+ value = sym.n_value - csect->vma;
+ }
+ break;
+
+ case XTY_CM:
+ /* This is an unitialized csect. We could base the name on
+ the storage mapping class, but we don't bother except for
+ an XMC_TD symbol. If this csect is externally visible,
+ it is a common symbol. We put XMC_TD symbols in sections
+ named .tocbss, and rely on the linker script to put that
+ in the TOC area. */
+
+ if (csect != NULL)
+ {
+ xcoff_section_data (abfd, csect)->last_symndx =
+ ((esym
+ - (bfd_byte *) obj_coff_external_syms (abfd))
+ / symesz);
+ }
+
+ if (aux.x_csect.x_smclas == XMC_TD)
+ csect = bfd_make_section_anyway (abfd, ".tocbss");
+ else
+ csect = bfd_make_section_anyway (abfd, ".bss");
+ if (csect == NULL)
+ goto error_return;
+ csect->vma = sym.n_value;
+ csect->_raw_size = aux.x_csect.x_scnlen.l;
+ csect->flags |= SEC_ALLOC;
+ csect->alignment_power = SMTYP_ALIGN (aux.x_csect.x_smtyp);
+ /* There are a number of other fields and section flags
+ which we do not bother to set. */
+
+ csect_index = ((esym
+ - (bfd_byte *) obj_coff_external_syms (abfd))
+ / symesz);
+
+ csect->used_by_bfd =
+ (PTR) bfd_zalloc (abfd, sizeof (struct coff_section_tdata));
+ if (csect->used_by_bfd == NULL)
+ goto error_return;
+ coff_section_data (abfd, csect)->tdata =
+ bfd_zalloc (abfd, sizeof (struct xcoff_section_tdata));
+ if (coff_section_data (abfd, csect)->tdata == NULL)
+ goto error_return;
+ xcoff_section_data (abfd, csect)->first_symndx = csect_index;
+
+ if (first_csect == NULL)
+ first_csect = csect;
+
+ if (sym.n_sclass == C_EXT)
+ {
+ csect->flags |= SEC_IS_COMMON;
+ csect->_raw_size = 0;
+ section = csect;
+ value = aux.x_csect.x_scnlen.l;
+ }
+
+ break;
+ }
+
+ /* Check for magic symbol names. */
+ if ((smtyp == XTY_SD || smtyp == XTY_CM)
+ && aux.x_csect.x_smclas != XMC_TC
+ && aux.x_csect.x_smclas != XMC_TD)
+ {
+ int i;
+
+ i = -1;
+ if (name[0] == '_')
+ {
+ if (strcmp (name, "_text") == 0)
+ i = 0;
+ else if (strcmp (name, "_etext") == 0)
+ i = 1;
+ else if (strcmp (name, "_data") == 0)
+ i = 2;
+ else if (strcmp (name, "_edata") == 0)
+ i = 3;
+ else if (strcmp (name, "_end") == 0)
+ i = 4;
+ }
+ else if (name[0] == 'e' && strcmp (name, "end") == 0)
+ i = 5;
+
+ if (i != -1)
+ xcoff_hash_table (info)->special_sections[i] = csect;
+ }
+
+ /* Now we have enough information to add the symbol to the
+ linker hash table. */
+
+ if (sym.n_sclass == C_EXT)
+ {
+ boolean copy;
+
+ BFD_ASSERT (section != NULL);
+
+ /* We must copy the name into memory if we got it from the
+ syment itself, rather than the string table. */
+ copy = default_copy;
+ if (sym._n._n_n._n_zeroes != 0
+ || sym._n._n_n._n_offset == 0)
+ copy = true;
+
+ /* The AIX linker appears to only detect multiple symbol
+ definitions when there is a reference to the symbol. If
+ a symbol is defined multiple times, and the only
+ references are from the same object file, the AIX linker
+ appears to permit it. It does not merge the different
+ definitions, but handles them independently. On the
+ other hand, if there is a reference, the linker reports
+ an error.
+
+ This matters because the AIX <net/net_globals.h> header
+ file actually defines an initialized array, so we have to
+ actually permit that to work.
+
+ Just to make matters even more confusing, the AIX linker
+ appears to permit multiple symbol definitions whenever
+ the second definition is in an archive rather than an
+ object file. This may be a consequence of the manner in
+ which it handles archives: I think it may load the entire
+ archive in as separate csects, and then let garbage
+ collection discard symbols.
+
+ We also have to handle the case of statically linking a
+ shared object, which will cause symbol redefinitions,
+ although this is an easier case to detect. */
+
+ if (info->hash->creator == abfd->xvec)
+ {
+ if (! bfd_is_und_section (section))
+ *sym_hash = xcoff_link_hash_lookup (xcoff_hash_table (info),
+ name, true, copy, false);
+ else
+ *sym_hash = ((struct xcoff_link_hash_entry *)
+ bfd_wrapped_link_hash_lookup (abfd, info, name,
+ true, copy, false));
+ if (*sym_hash == NULL)
+ goto error_return;
+ if (((*sym_hash)->root.type == bfd_link_hash_defined
+ || (*sym_hash)->root.type == bfd_link_hash_defweak)
+ && ! bfd_is_und_section (section)
+ && ! bfd_is_com_section (section))
+ {
+ /* This is a second definition of a defined symbol. */
+ if ((abfd->flags & DYNAMIC) != 0
+ && ((*sym_hash)->smclas != XMC_GL
+ || aux.x_csect.x_smclas == XMC_GL
+ || ((*sym_hash)->root.u.def.section->owner->flags
+ & DYNAMIC) == 0))
+ {
+ /* The new symbol is from a shared library, and
+ either the existing symbol is not global
+ linkage code or this symbol is global linkage
+ code. If the existing symbol is global
+ linkage code and the new symbol is not, then
+ we want to use the new symbol. */
+ section = bfd_und_section_ptr;
+ value = 0;
+ }
+ else if (((*sym_hash)->root.u.def.section->owner->flags
+ & DYNAMIC) != 0)
+ {
+ /* The existing symbol is from a shared library.
+ Replace it. */
+ (*sym_hash)->root.type = bfd_link_hash_undefined;
+ (*sym_hash)->root.u.undef.abfd =
+ (*sym_hash)->root.u.def.section->owner;
+ }
+ else if (abfd->my_archive != NULL)
+ {
+ /* This is a redefinition in an object contained
+ in an archive. Just ignore it. See the
+ comment above. */
+ section = bfd_und_section_ptr;
+ value = 0;
+ }
+ else if ((*sym_hash)->root.next != NULL
+ || info->hash->undefs_tail == &(*sym_hash)->root)
+ {
+ /* This symbol has been referenced. In this
+ case, we just continue and permit the
+ multiple definition error. See the comment
+ above about the behaviour of the AIX linker. */
+ }
+ else if ((*sym_hash)->smclas == aux.x_csect.x_smclas)
+ {
+ /* The symbols are both csects of the same
+ class. There is at least a chance that this
+ is a semi-legitimate redefinition. */
+ section = bfd_und_section_ptr;
+ value = 0;
+ (*sym_hash)->flags |= XCOFF_MULTIPLY_DEFINED;
+ }
+ }
+ else if (((*sym_hash)->flags & XCOFF_MULTIPLY_DEFINED) != 0
+ && ((*sym_hash)->root.type == bfd_link_hash_defined
+ || (*sym_hash)->root.type == bfd_link_hash_defweak)
+ && (bfd_is_und_section (section)
+ || bfd_is_com_section (section)))
+ {
+ /* This is a reference to a multiply defined symbol.
+ Report the error now. See the comment above
+ about the behaviour of the AIX linker. We could
+ also do this with warning symbols, but I'm not
+ sure the XCOFF linker is wholly prepared to
+ handle them, and that would only be a warning,
+ not an error. */
+ if (! ((*info->callbacks->multiple_definition)
+ (info, (*sym_hash)->root.root.string,
+ (bfd *) NULL, (asection *) NULL, 0,
+ (*sym_hash)->root.u.def.section->owner,
+ (*sym_hash)->root.u.def.section,
+ (*sym_hash)->root.u.def.value)))
+ goto error_return;
+ /* Try not to give this error too many times. */
+ (*sym_hash)->flags &= ~XCOFF_MULTIPLY_DEFINED;
+ }
+ }
+
+ /* _bfd_generic_link_add_one_symbol may call the linker to
+ generate an error message, and the linker may try to read
+ the symbol table to give a good error. Right now, the
+ line numbers are in an inconsistent state, since they are
+ counted both in the real sections and in the new csects.
+ We need to leave the count in the real sections so that
+ the linker can report the line number of the error
+ correctly, so temporarily clobber the link to the csects
+ so that the linker will not try to read the line numbers
+ a second time from the csects. */
+ BFD_ASSERT (last_real->next == first_csect);
+ last_real->next = NULL;
+ if (! (_bfd_generic_link_add_one_symbol
+ (info, abfd, name, flags, section, value,
+ (const char *) NULL, copy, true,
+ (struct bfd_link_hash_entry **) sym_hash)))
+ goto error_return;
+ last_real->next = first_csect;
+
+ if (smtyp == XTY_CM)
+ {
+ if ((*sym_hash)->root.type != bfd_link_hash_common
+ || (*sym_hash)->root.u.c.p->section != csect)
+ {
+ /* We don't need the common csect we just created. */
+ csect->_raw_size = 0;
+ }
+ else
+ {
+ (*sym_hash)->root.u.c.p->alignment_power
+ = csect->alignment_power;
+ }
+ }
+
+ if (info->hash->creator == abfd->xvec)
+ {
+ int flag;
+
+ if (smtyp == XTY_ER || smtyp == XTY_CM)
+ flag = XCOFF_REF_REGULAR;
+ else
+ flag = XCOFF_DEF_REGULAR;
+ (*sym_hash)->flags |= flag;
+
+ if ((*sym_hash)->smclas == XMC_UA
+ || flag == XCOFF_DEF_REGULAR)
+ (*sym_hash)->smclas = aux.x_csect.x_smclas;
+ }
+ }
+
+ *csect_cache = csect;
+
+ esym += (sym.n_numaux + 1) * symesz;
+ sym_hash += sym.n_numaux + 1;
+ csect_cache += sym.n_numaux + 1;
+ }
+
+ BFD_ASSERT (last_real == NULL || last_real->next == first_csect);
+
+ /* Make sure that we have seen all the relocs. */
+ for (o = abfd->sections; o != first_csect; o = o->next)
+ {
+ /* Reset the section size and the line number count, since the
+ data is now attached to the csects. Don't reset the size of
+ the .debug section, since we need to read it below in
+ bfd_xcoff_size_dynamic_sections. */
+ if (strcmp (bfd_get_section_name (abfd, o), ".debug") != 0)
+ o->_raw_size = 0;
+ o->lineno_count = 0;
+
+ if ((o->flags & SEC_RELOC) != 0)
+ {
+ bfd_size_type i;
+ struct internal_reloc *rel;
+ asection **rel_csect;
+
+ rel = reloc_info[o->target_index].relocs;
+ rel_csect = reloc_info[o->target_index].csects;
+ for (i = 0; i < o->reloc_count; i++, rel++, rel_csect++)
+ {
+ if (*rel_csect == NULL)
+ {
+ (*_bfd_error_handler)
+ (_("%s: reloc %s:%d not in csect"),
+ bfd_get_filename (abfd), o->name, i);
+ bfd_set_error (bfd_error_bad_value);
+ goto error_return;
+ }
+
+ /* We identify all symbols which are called, so that we
+ can create glue code for calls to functions imported
+ from dynamic objects. */
+ if (info->hash->creator == abfd->xvec
+ && *rel_csect != bfd_und_section_ptr
+ && (rel->r_type == R_BR
+ || rel->r_type == R_RBR)
+ && obj_xcoff_sym_hashes (abfd)[rel->r_symndx] != NULL)
+ {
+ struct xcoff_link_hash_entry *h;
+
+ h = obj_xcoff_sym_hashes (abfd)[rel->r_symndx];
+ h->flags |= XCOFF_CALLED;
+ /* If the symbol name starts with a period, it is
+ the code of a function. If the symbol is
+ currently undefined, then add an undefined symbol
+ for the function descriptor. This should do no
+ harm, because any regular object that defines the
+ function should also define the function
+ descriptor. It helps, because it means that we
+ will identify the function descriptor with a
+ dynamic object if a dynamic object defines it. */
+ if (h->root.root.string[0] == '.'
+ && h->descriptor == NULL)
+ {
+ struct xcoff_link_hash_entry *hds;
+
+ hds = xcoff_link_hash_lookup (xcoff_hash_table (info),
+ h->root.root.string + 1,
+ true, false, true);
+ if (hds == NULL)
+ goto error_return;
+ if (hds->root.type == bfd_link_hash_new)
+ {
+ if (! (_bfd_generic_link_add_one_symbol
+ (info, abfd, hds->root.root.string,
+ (flagword) 0, bfd_und_section_ptr,
+ (bfd_vma) 0, (const char *) NULL, false,
+ true,
+ (struct bfd_link_hash_entry **) &hds)))
+ goto error_return;
+ }
+ hds->flags |= XCOFF_DESCRIPTOR;
+ BFD_ASSERT ((hds->flags & XCOFF_CALLED) == 0
+ && (h->flags & XCOFF_DESCRIPTOR) == 0);
+ hds->descriptor = h;
+ h->descriptor = hds;
+ }
+ }
+ }
+
+ free (reloc_info[o->target_index].csects);
+ reloc_info[o->target_index].csects = NULL;
+
+ /* Reset SEC_RELOC and the reloc_count, since the reloc
+ information is now attached to the csects. */
+ o->flags &= ~SEC_RELOC;
+ o->reloc_count = 0;
+
+ /* If we are not keeping memory, free the reloc information. */
+ if (! info->keep_memory
+ && coff_section_data (abfd, o) != NULL
+ && coff_section_data (abfd, o)->relocs != NULL
+ && ! coff_section_data (abfd, o)->keep_relocs)
+ {
+ free (coff_section_data (abfd, o)->relocs);
+ coff_section_data (abfd, o)->relocs = NULL;
+ }
+ }
+
+ /* Free up the line numbers. FIXME: We could cache these
+ somewhere for the final link, to avoid reading them again. */
+ if (reloc_info[o->target_index].linenos != NULL)
+ {
+ free (reloc_info[o->target_index].linenos);
+ reloc_info[o->target_index].linenos = NULL;
+ }
+ }
+
+ free (reloc_info);
+
+ obj_coff_keep_syms (abfd) = keep_syms;
+
+ return true;
+
+ error_return:
+ if (reloc_info != NULL)
+ {
+ for (o = abfd->sections; o != NULL; o = o->next)
+ {
+ if (reloc_info[o->target_index].csects != NULL)
+ free (reloc_info[o->target_index].csects);
+ if (reloc_info[o->target_index].linenos != NULL)
+ free (reloc_info[o->target_index].linenos);
+ }
+ free (reloc_info);
+ }
+ obj_coff_keep_syms (abfd) = keep_syms;
+ return false;
+}
+
+#undef N_TMASK
+#undef N_BTSHFT
+
+/* This function is used to add symbols from a dynamic object to the
+ global symbol table. */
+
+static boolean
+xcoff_link_add_dynamic_symbols (abfd, info)
+ bfd *abfd;
+ struct bfd_link_info *info;
+{
+ asection *lsec;
+ bfd_byte *buf;
+ struct internal_ldhdr ldhdr;
+ const char *strings;
+ struct external_ldsym *elsym, *elsymend;
+ struct xcoff_import_file *n;
+ const char *bname;
+ const char *mname;
+ const char *s;
+ unsigned int c;
+ struct xcoff_import_file **pp;
+
+ /* We can only handle a dynamic object if we are generating an XCOFF
+ output file. */
+ if (info->hash->creator != abfd->xvec)
+ {
+ (*_bfd_error_handler)
+ (_("%s: XCOFF shared object when not producing XCOFF output"),
+ bfd_get_filename (abfd));
+ bfd_set_error (bfd_error_invalid_operation);
+ return false;
+ }
+
+ /* The symbols we use from a dynamic object are not the symbols in
+ the normal symbol table, but, rather, the symbols in the export
+ table. If there is a global symbol in a dynamic object which is
+ not in the export table, the loader will not be able to find it,
+ so we don't want to find it either. Also, on AIX 4.1.3, shr.o in
+ libc.a has symbols in the export table which are not in the
+ symbol table. */
+
+ /* Read in the .loader section. FIXME: We should really use the
+ o_snloader field in the a.out header, rather than grabbing the
+ section by name. */
+ lsec = bfd_get_section_by_name (abfd, ".loader");
+ if (lsec == NULL)
+ {
+ (*_bfd_error_handler)
+ (_("%s: dynamic object with no .loader section"),
+ bfd_get_filename (abfd));
+ bfd_set_error (bfd_error_no_symbols);
+ return false;
+ }
+
+ if (! xcoff_get_section_contents (abfd, lsec))
+ return false;
+ buf = coff_section_data (abfd, lsec)->contents;
+
+ /* Remove the sections from this object, so that they do not get
+ included in the link. */
+ abfd->sections = NULL;
+
+ xcoff_swap_ldhdr_in (abfd, (struct external_ldhdr *) buf, &ldhdr);
+
+ strings = (char *) buf + ldhdr.l_stoff;
+
+ elsym = (struct external_ldsym *) (buf + LDHDRSZ);
+ elsymend = elsym + ldhdr.l_nsyms;
+ BFD_ASSERT (sizeof (struct external_ldsym) == LDSYMSZ);
+ for (; elsym < elsymend; elsym++)
+ {
+ struct internal_ldsym ldsym;
+ char nambuf[SYMNMLEN + 1];
+ const char *name;
+ struct xcoff_link_hash_entry *h;
+
+ xcoff_swap_ldsym_in (abfd, elsym, &ldsym);
+
+ /* We are only interested in exported symbols. */
+ if ((ldsym.l_smtype & L_EXPORT) == 0)
+ continue;
+
+ if (ldsym._l._l_l._l_zeroes == 0)
+ name = strings + ldsym._l._l_l._l_offset;
+ else
+ {
+ memcpy (nambuf, ldsym._l._l_name, SYMNMLEN);
+ nambuf[SYMNMLEN] = '\0';
+ name = nambuf;
+ }
+
+ /* Normally we could not call xcoff_link_hash_lookup in an add
+ symbols routine, since we might not be using an XCOFF hash
+ table. However, we verified above that we are using an XCOFF
+ hash table. */
+
+ h = xcoff_link_hash_lookup (xcoff_hash_table (info), name, true,
+ true, true);
+ if (h == NULL)
+ return false;
+
+ h->flags |= XCOFF_DEF_DYNAMIC;
+
+ /* If the symbol is undefined, and the BFD it was found in is
+ not a dynamic object, change the BFD to this dynamic object,
+ so that we can get the correct import file ID. */
+ if ((h->root.type == bfd_link_hash_undefined
+ || h->root.type == bfd_link_hash_undefweak)
+ && (h->root.u.undef.abfd == NULL
+ || (h->root.u.undef.abfd->flags & DYNAMIC) == 0))
+ h->root.u.undef.abfd = abfd;
+
+ if (h->root.type == bfd_link_hash_new)
+ {
+ h->root.type = bfd_link_hash_undefined;
+ h->root.u.undef.abfd = abfd;
+ /* We do not want to add this to the undefined symbol list. */
+ }
+
+ if (h->smclas == XMC_UA
+ || h->root.type == bfd_link_hash_undefined
+ || h->root.type == bfd_link_hash_undefweak)
+ h->smclas = ldsym.l_smclas;
+
+ /* Unless this is an XMC_XO symbol, we don't bother to actually
+ define it, since we don't have a section to put it in anyhow.
+ Instead, the relocation routines handle the DEF_DYNAMIC flag
+ correctly. */
+
+ if (h->smclas == XMC_XO
+ && (h->root.type == bfd_link_hash_undefined
+ || h->root.type == bfd_link_hash_undefweak))
+ {
+ /* This symbol has an absolute value. */
+ h->root.type = bfd_link_hash_defined;
+ h->root.u.def.section = bfd_abs_section_ptr;
+ h->root.u.def.value = ldsym.l_value;
+ }
+
+ /* If this symbol defines a function descriptor, then it
+ implicitly defines the function code as well. */
+ if (h->smclas == XMC_DS
+ || (h->smclas == XMC_XO && name[0] != '.'))
+ h->flags |= XCOFF_DESCRIPTOR;
+ if ((h->flags & XCOFF_DESCRIPTOR) != 0)
+ {
+ struct xcoff_link_hash_entry *hds;
+
+ hds = h->descriptor;
+ if (hds == NULL)
+ {
+ char *dsnm;
+
+ dsnm = bfd_malloc (strlen (name) + 2);
+ if (dsnm == NULL)
+ return false;
+ dsnm[0] = '.';
+ strcpy (dsnm + 1, name);
+ hds = xcoff_link_hash_lookup (xcoff_hash_table (info), dsnm,
+ true, true, true);
+ free (dsnm);
+ if (hds == NULL)
+ return false;
+
+ if (hds->root.type == bfd_link_hash_new)
+ {
+ hds->root.type = bfd_link_hash_undefined;
+ hds->root.u.undef.abfd = abfd;
+ /* We do not want to add this to the undefined
+ symbol list. */
+ }
+
+ hds->descriptor = h;
+ h->descriptor = hds;
+ }
+
+ hds->flags |= XCOFF_DEF_DYNAMIC;
+ if (hds->smclas == XMC_UA)
+ hds->smclas = XMC_PR;
+
+ /* An absolute symbol appears to actually define code, not a
+ function descriptor. This is how some math functions are
+ implemented on AIX 4.1. */
+ if (h->smclas == XMC_XO
+ && (hds->root.type == bfd_link_hash_undefined
+ || hds->root.type == bfd_link_hash_undefweak))
+ {
+ hds->smclas = XMC_XO;
+ hds->root.type = bfd_link_hash_defined;
+ hds->root.u.def.section = bfd_abs_section_ptr;
+ hds->root.u.def.value = ldsym.l_value;
+ }
+ }
+ }
+
+ if (buf != NULL && ! coff_section_data (abfd, lsec)->keep_contents)
+ {
+ free (coff_section_data (abfd, lsec)->contents);
+ coff_section_data (abfd, lsec)->contents = NULL;
+ }
+
+ /* Record this file in the import files. */
+
+ n = ((struct xcoff_import_file *)
+ bfd_alloc (abfd, sizeof (struct xcoff_import_file)));
+ if (n == NULL)
+ return false;
+ n->next = NULL;
+
+ /* For some reason, the path entry in the import file list for a
+ shared object appears to always be empty. The file name is the
+ base name. */
+ n->path = "";
+ if (abfd->my_archive == NULL)
+ {
+ bname = bfd_get_filename (abfd);
+ mname = "";
+ }
+ else
+ {
+ bname = bfd_get_filename (abfd->my_archive);
+ mname = bfd_get_filename (abfd);
+ }
+ s = strrchr (bname, '/');
+ if (s != NULL)
+ bname = s + 1;
+ n->file = bname;
+ n->member = mname;
+
+ /* We start c at 1 because the first import file number is reserved
+ for LIBPATH. */
+ for (pp = &xcoff_hash_table (info)->imports, c = 1;
+ *pp != NULL;
+ pp = &(*pp)->next, ++c)
+ ;
+ *pp = n;
+
+ xcoff_data (abfd)->import_file_id = c;
+
+ return true;
+}
+
+/* Routines that are called after all the input files have been
+ handled, but before the sections are laid out in memory. */
+
+/* Mark a symbol as not being garbage, including the section in which
+ it is defined. */
+
+static INLINE boolean
+xcoff_mark_symbol (info, h)
+ struct bfd_link_info *info;
+ struct xcoff_link_hash_entry *h;
+{
+ if ((h->flags & XCOFF_MARK) != 0)
+ return true;
+
+ h->flags |= XCOFF_MARK;
+ if (h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak)
+ {
+ asection *hsec;
+
+ hsec = h->root.u.def.section;
+ if (! bfd_is_abs_section (hsec)
+ && (hsec->flags & SEC_MARK) == 0)
+ {
+ if (! xcoff_mark (info, hsec))
+ return false;
+ }
+ }
+
+ if (h->toc_section != NULL
+ && (h->toc_section->flags & SEC_MARK) == 0)
+ {
+ if (! xcoff_mark (info, h->toc_section))
+ return false;
+ }
+
+ return true;
+}
+
+/* The mark phase of garbage collection. For a given section, mark
+ it, and all the sections which define symbols to which it refers.
+ Because this function needs to look at the relocs, we also count
+ the number of relocs which need to be copied into the .loader
+ section. */
+
+static boolean
+xcoff_mark (info, sec)
+ struct bfd_link_info *info;
+ asection *sec;
+{
+ if (bfd_is_abs_section (sec)
+ || (sec->flags & SEC_MARK) != 0)
+ return true;
+
+ sec->flags |= SEC_MARK;
+
+ if (sec->owner->xvec == info->hash->creator
+ && coff_section_data (sec->owner, sec) != NULL
+ && xcoff_section_data (sec->owner, sec) != NULL)
+ {
+ register struct xcoff_link_hash_entry **hp, **hpend;
+ struct internal_reloc *rel, *relend;
+
+ /* Mark all the symbols in this section. */
+
+ hp = (obj_xcoff_sym_hashes (sec->owner)
+ + xcoff_section_data (sec->owner, sec)->first_symndx);
+ hpend = (obj_xcoff_sym_hashes (sec->owner)
+ + xcoff_section_data (sec->owner, sec)->last_symndx);
+ for (; hp < hpend; hp++)
+ {
+ register struct xcoff_link_hash_entry *h;
+
+ h = *hp;
+ if (h != NULL
+ && (h->flags & XCOFF_MARK) == 0)
+ {
+ if (! xcoff_mark_symbol (info, h))
+ return false;
+ }
+ }
+
+ /* Look through the section relocs. */
+
+ if ((sec->flags & SEC_RELOC) != 0
+ && sec->reloc_count > 0)
+ {
+ rel = xcoff_read_internal_relocs (sec->owner, sec, true,
+ (bfd_byte *) NULL, false,
+ (struct internal_reloc *) NULL);
+ if (rel == NULL)
+ return false;
+ relend = rel + sec->reloc_count;
+ for (; rel < relend; rel++)
+ {
+ asection *rsec;
+ struct xcoff_link_hash_entry *h;
+
+ if ((unsigned int) rel->r_symndx
+ > obj_raw_syment_count (sec->owner))
+ continue;
+
+ h = obj_xcoff_sym_hashes (sec->owner)[rel->r_symndx];
+ if (h != NULL
+ && (h->flags & XCOFF_MARK) == 0)
+ {
+ if (! xcoff_mark_symbol (info, h))
+ return false;
+ }
+
+ rsec = xcoff_data (sec->owner)->csects[rel->r_symndx];
+ if (rsec != NULL
+ && (rsec->flags & SEC_MARK) == 0)
+ {
+ if (! xcoff_mark (info, rsec))
+ return false;
+ }
+
+ /* See if this reloc needs to be copied into the .loader
+ section. */
+ switch (rel->r_type)
+ {
+ default:
+ if (h == NULL
+ || h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak
+ || h->root.type == bfd_link_hash_common
+ || ((h->flags & XCOFF_CALLED) != 0
+ && (h->root.type == bfd_link_hash_undefined
+ || h->root.type == bfd_link_hash_undefweak)
+ && h->root.root.string[0] == '.'
+ && h->descriptor != NULL
+ && ((h->descriptor->flags & XCOFF_DEF_DYNAMIC) != 0
+ || ((h->descriptor->flags & XCOFF_IMPORT) != 0
+ && (h->descriptor->flags
+ & XCOFF_DEF_REGULAR) == 0))))
+ break;
+ /* Fall through. */
+ case R_POS:
+ case R_NEG:
+ case R_RL:
+ case R_RLA:
+ ++xcoff_hash_table (info)->ldrel_count;
+ if (h != NULL)
+ h->flags |= XCOFF_LDREL;
+ break;
+ case R_TOC:
+ case R_GL:
+ case R_TCL:
+ case R_TRL:
+ case R_TRLA:
+ /* We should never need a .loader reloc for a TOC
+ relative reloc. */
+ break;
+ }
+ }
+
+ if (! info->keep_memory
+ && coff_section_data (sec->owner, sec) != NULL
+ && coff_section_data (sec->owner, sec)->relocs != NULL
+ && ! coff_section_data (sec->owner, sec)->keep_relocs)
+ {
+ free (coff_section_data (sec->owner, sec)->relocs);
+ coff_section_data (sec->owner, sec)->relocs = NULL;
+ }
+ }
+ }
+
+ return true;
+}
+
+/* The sweep phase of garbage collection. Remove all garbage
+ sections. */
+
+static void
+xcoff_sweep (info)
+ struct bfd_link_info *info;
+{
+ bfd *sub;
+
+ for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
+ {
+ asection *o;
+
+ for (o = sub->sections; o != NULL; o = o->next)
+ {
+ if ((o->flags & SEC_MARK) == 0)
+ {
+ /* Keep all sections from non-XCOFF input files. Keep
+ special sections. Keep .debug sections for the
+ moment. */
+ if (sub->xvec != info->hash->creator
+ || o == xcoff_hash_table (info)->debug_section
+ || o == xcoff_hash_table (info)->loader_section
+ || o == xcoff_hash_table (info)->linkage_section
+ || o == xcoff_hash_table (info)->toc_section
+ || o == xcoff_hash_table (info)->descriptor_section
+ || strcmp (o->name, ".debug") == 0)
+ o->flags |= SEC_MARK;
+ else
+ {
+ o->_raw_size = 0;
+ o->reloc_count = 0;
+ o->lineno_count = 0;
+ }
+ }
+ }
+ }
+}
+
+/* Record the number of elements in a set. This is used to output the
+ correct csect length. */
+
+boolean
+bfd_xcoff_link_record_set (output_bfd, info, harg, size)
+ bfd *output_bfd;
+ struct bfd_link_info *info;
+ struct bfd_link_hash_entry *harg;
+ bfd_size_type size;
+{
+ struct xcoff_link_hash_entry *h = (struct xcoff_link_hash_entry *) harg;
+ struct xcoff_link_size_list *n;
+
+ if (bfd_get_flavour (output_bfd) != bfd_target_xcoff_flavour)
+ return true;
+
+ /* This will hardly ever be called. I don't want to burn four bytes
+ per global symbol, so instead the size is kept on a linked list
+ attached to the hash table. */
+
+ n = ((struct xcoff_link_size_list *)
+ bfd_alloc (output_bfd, sizeof (struct xcoff_link_size_list)));
+ if (n == NULL)
+ return false;
+ n->next = xcoff_hash_table (info)->size_list;
+ n->h = h;
+ n->size = size;
+ xcoff_hash_table (info)->size_list = n;
+
+ h->flags |= XCOFF_HAS_SIZE;
+
+ return true;
+}
+
+/* Import a symbol. */
+
+boolean
+bfd_xcoff_import_symbol (output_bfd, info, harg, val, imppath, impfile,
+ impmember)
+ bfd *output_bfd;
+ struct bfd_link_info *info;
+ struct bfd_link_hash_entry *harg;
+ bfd_vma val;
+ const char *imppath;
+ const char *impfile;
+ const char *impmember;
+{
+ struct xcoff_link_hash_entry *h = (struct xcoff_link_hash_entry *) harg;
+
+ if (bfd_get_flavour (output_bfd) != bfd_target_xcoff_flavour)
+ return true;
+
+ /* A symbol name which starts with a period is the code for a
+ function. If the symbol is undefined, then add an undefined
+ symbol for the function descriptor, and import that instead. */
+ if (h->root.root.string[0] == '.'
+ && h->root.type == bfd_link_hash_undefined
+ && val == (bfd_vma) -1)
+ {
+ struct xcoff_link_hash_entry *hds;
+
+ hds = h->descriptor;
+ if (hds == NULL)
+ {
+ hds = xcoff_link_hash_lookup (xcoff_hash_table (info),
+ h->root.root.string + 1,
+ true, false, true);
+ if (hds == NULL)
+ return false;
+ if (hds->root.type == bfd_link_hash_new)
+ {
+ hds->root.type = bfd_link_hash_undefined;
+ hds->root.u.undef.abfd = h->root.u.undef.abfd;
+ }
+ hds->flags |= XCOFF_DESCRIPTOR;
+ BFD_ASSERT ((hds->flags & XCOFF_CALLED) == 0
+ && (h->flags & XCOFF_DESCRIPTOR) == 0);
+ hds->descriptor = h;
+ h->descriptor = hds;
+ }
+
+ /* Now, if the descriptor is undefined, import the descriptor
+ rather than the symbol we were told to import. FIXME: Is
+ this correct in all cases? */
+ if (hds->root.type == bfd_link_hash_undefined)
+ h = hds;
+ }
+
+ h->flags |= XCOFF_IMPORT;
+
+ if (val != (bfd_vma) -1)
+ {
+ if (h->root.type == bfd_link_hash_defined
+ && (! bfd_is_abs_section (h->root.u.def.section)
+ || h->root.u.def.value != val))
+ {
+ if (! ((*info->callbacks->multiple_definition)
+ (info, h->root.root.string, h->root.u.def.section->owner,
+ h->root.u.def.section, h->root.u.def.value,
+ output_bfd, bfd_abs_section_ptr, val)))
+ return false;
+ }
+
+ h->root.type = bfd_link_hash_defined;
+ h->root.u.def.section = bfd_abs_section_ptr;
+ h->root.u.def.value = val;
+ }
+
+ /* We overload the ldindx field to hold the l_ifile value for this
+ symbol. */
+ BFD_ASSERT (h->ldsym == NULL);
+ BFD_ASSERT ((h->flags & XCOFF_BUILT_LDSYM) == 0);
+ if (imppath == NULL)
+ h->ldindx = -1;
+ else
+ {
+ unsigned int c;
+ struct xcoff_import_file **pp;
+
+ /* We start c at 1 because the first entry in the import list is
+ reserved for the library search path. */
+ for (pp = &xcoff_hash_table (info)->imports, c = 1;
+ *pp != NULL;
+ pp = &(*pp)->next, ++c)
+ {
+ if (strcmp ((*pp)->path, imppath) == 0
+ && strcmp ((*pp)->file, impfile) == 0
+ && strcmp ((*pp)->member, impmember) == 0)
+ break;
+ }
+
+ if (*pp == NULL)
+ {
+ struct xcoff_import_file *n;
+
+ n = ((struct xcoff_import_file *)
+ bfd_alloc (output_bfd, sizeof (struct xcoff_import_file)));
+ if (n == NULL)
+ return false;
+ n->next = NULL;
+ n->path = imppath;
+ n->file = impfile;
+ n->member = impmember;
+ *pp = n;
+ }
+
+ h->ldindx = c;
+ }
+
+ return true;
+}
+
+/* Export a symbol. */
+
+boolean
+bfd_xcoff_export_symbol (output_bfd, info, harg, syscall)
+ bfd *output_bfd;
+ struct bfd_link_info *info;
+ struct bfd_link_hash_entry *harg;
+ boolean syscall ATTRIBUTE_UNUSED;
+{
+ struct xcoff_link_hash_entry *h = (struct xcoff_link_hash_entry *) harg;
+
+ if (bfd_get_flavour (output_bfd) != bfd_target_xcoff_flavour)
+ return true;
+
+ h->flags |= XCOFF_EXPORT;
+
+ /* FIXME: I'm not at all sure what syscall is supposed to mean, so
+ I'm just going to ignore it until somebody explains it. */
+
+ /* See if this is a function descriptor. It may be one even though
+ it is not so marked. */
+ if ((h->flags & XCOFF_DESCRIPTOR) == 0
+ && h->root.root.string[0] != '.')
+ {
+ char *fnname;
+ struct xcoff_link_hash_entry *hfn;
+
+ fnname = (char *) bfd_malloc (strlen (h->root.root.string) + 2);
+ if (fnname == NULL)
+ return false;
+ fnname[0] = '.';
+ strcpy (fnname + 1, h->root.root.string);
+ hfn = xcoff_link_hash_lookup (xcoff_hash_table (info),
+ fnname, false, false, true);
+ free (fnname);
+ if (hfn != NULL
+ && hfn->smclas == XMC_PR
+ && (hfn->root.type == bfd_link_hash_defined
+ || hfn->root.type == bfd_link_hash_defweak))
+ {
+ h->flags |= XCOFF_DESCRIPTOR;
+ h->descriptor = hfn;
+ hfn->descriptor = h;
+ }
+ }
+
+ /* Make sure we don't garbage collect this symbol. */
+ if (! xcoff_mark_symbol (info, h))
+ return false;
+
+ /* If this is a function descriptor, make sure we don't garbage
+ collect the associated function code. We normally don't have to
+ worry about this, because the descriptor will be attached to a
+ section with relocs, but if we are creating the descriptor
+ ourselves those relocs will not be visible to the mark code. */
+ if ((h->flags & XCOFF_DESCRIPTOR) != 0)
+ {
+ if (! xcoff_mark_symbol (info, h->descriptor))
+ return false;
+ }
+
+ return true;
+}
+
+/* Count a reloc against a symbol. This is called for relocs
+ generated by the linker script, typically for global constructors
+ and destructors. */
+
+boolean
+bfd_xcoff_link_count_reloc (output_bfd, info, name)
+ bfd *output_bfd;
+ struct bfd_link_info *info;
+ const char *name;
+{
+ struct xcoff_link_hash_entry *h;
+
+ if (bfd_get_flavour (output_bfd) != bfd_target_xcoff_flavour)
+ return true;
+
+ h = ((struct xcoff_link_hash_entry *)
+ bfd_wrapped_link_hash_lookup (output_bfd, info, name, false, false,
+ false));
+ if (h == NULL)
+ {
+ (*_bfd_error_handler) (_("%s: no such symbol"), name);
+ bfd_set_error (bfd_error_no_symbols);
+ return false;
+ }
+
+ h->flags |= XCOFF_REF_REGULAR | XCOFF_LDREL;
+ ++xcoff_hash_table (info)->ldrel_count;
+
+ /* Mark the symbol to avoid garbage collection. */
+ if (! xcoff_mark_symbol (info, h))
+ return false;
+
+ return true;
+}
+
+/* This function is called for each symbol to which the linker script
+ assigns a value. */
+
+boolean
+bfd_xcoff_record_link_assignment (output_bfd, info, name)
+ bfd *output_bfd;
+ struct bfd_link_info *info;
+ const char *name;
+{
+ struct xcoff_link_hash_entry *h;
+
+ if (bfd_get_flavour (output_bfd) != bfd_target_xcoff_flavour)
+ return true;
+
+ h = xcoff_link_hash_lookup (xcoff_hash_table (info), name, true, true,
+ false);
+ if (h == NULL)
+ return false;
+
+ h->flags |= XCOFF_DEF_REGULAR;
+
+ return true;
+}
+
+/* This structure is used to pass information through
+ xcoff_link_hash_traverse. */
+
+struct xcoff_loader_info {
+ /* Set if a problem occurred. */
+ boolean failed;
+ /* Output BFD. */
+ bfd *output_bfd;
+ /* Link information structure. */
+ struct bfd_link_info *info;
+ /* Whether all defined symbols should be exported. */
+ boolean export_defineds;
+ /* Number of ldsym structures. */
+ size_t ldsym_count;
+ /* Size of string table. */
+ size_t string_size;
+ /* String table. */
+ bfd_byte *strings;
+ /* Allocated size of string table. */
+ size_t string_alc;
+};
+
+/* Build the .loader section. This is called by the XCOFF linker
+ emulation before_allocation routine. We must set the size of the
+ .loader section before the linker lays out the output file.
+ LIBPATH is the library path to search for shared objects; this is
+ normally built from the -L arguments passed to the linker. ENTRY
+ is the name of the entry point symbol (the -e linker option).
+ FILE_ALIGN is the alignment to use for sections within the file
+ (the -H linker option). MAXSTACK is the maximum stack size (the
+ -bmaxstack linker option). MAXDATA is the maximum data size (the
+ -bmaxdata linker option). GC is whether to do garbage collection
+ (the -bgc linker option). MODTYPE is the module type (the
+ -bmodtype linker option). TEXTRO is whether the text section must
+ be read only (the -btextro linker option). EXPORT_DEFINEDS is
+ whether all defined symbols should be exported (the -unix linker
+ option). SPECIAL_SECTIONS is set by this routine to csects with
+ magic names like _end. */
+
+boolean
+bfd_xcoff_size_dynamic_sections (output_bfd, info, libpath, entry,
+ file_align, maxstack, maxdata, gc,
+ modtype, textro, export_defineds,
+ special_sections)
+ bfd *output_bfd;
+ struct bfd_link_info *info;
+ const char *libpath;
+ const char *entry;
+ unsigned long file_align;
+ unsigned long maxstack;
+ unsigned long maxdata;
+ boolean gc;
+ int modtype;
+ boolean textro;
+ boolean export_defineds;
+ asection **special_sections;
+{
+ struct xcoff_link_hash_entry *hentry;
+ asection *lsec;
+ struct xcoff_loader_info ldinfo;
+ int i;
+ size_t impsize, impcount;
+ struct xcoff_import_file *fl;
+ struct internal_ldhdr *ldhdr;
+ bfd_size_type stoff;
+ register char *out;
+ asection *sec;
+ bfd *sub;
+ struct bfd_strtab_hash *debug_strtab;
+ bfd_byte *debug_contents = NULL;
+
+ if (bfd_get_flavour (output_bfd) != bfd_target_xcoff_flavour)
+ {
+ for (i = 0; i < 6; i++)
+ special_sections[i] = NULL;
+ return true;
+ }
+
+ ldinfo.failed = false;
+ ldinfo.output_bfd = output_bfd;
+ ldinfo.info = info;
+ ldinfo.export_defineds = export_defineds;
+ ldinfo.ldsym_count = 0;
+ ldinfo.string_size = 0;
+ ldinfo.strings = NULL;
+ ldinfo.string_alc = 0;
+
+ xcoff_data (output_bfd)->maxstack = maxstack;
+ xcoff_data (output_bfd)->maxdata = maxdata;
+ xcoff_data (output_bfd)->modtype = modtype;
+
+ xcoff_hash_table (info)->file_align = file_align;
+ xcoff_hash_table (info)->textro = textro;
+
+ if (entry == NULL)
+ hentry = NULL;
+ else
+ {
+ hentry = xcoff_link_hash_lookup (xcoff_hash_table (info), entry,
+ false, false, true);
+ if (hentry != NULL)
+ hentry->flags |= XCOFF_ENTRY;
+ }
+
+ /* Garbage collect unused sections. */
+ if (info->relocateable
+ || ! gc
+ || hentry == NULL
+ || (hentry->root.type != bfd_link_hash_defined
+ && hentry->root.type != bfd_link_hash_defweak))
+ {
+ gc = false;
+ xcoff_hash_table (info)->gc = false;
+
+ /* We still need to call xcoff_mark, in order to set ldrel_count
+ correctly. */
+ for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
+ {
+ asection *o;
+
+ for (o = sub->sections; o != NULL; o = o->next)
+ {
+ if ((o->flags & SEC_MARK) == 0)
+ {
+ if (! xcoff_mark (info, o))
+ goto error_return;
+ }
+ }
+ }
+ }
+ else
+ {
+ if (! xcoff_mark (info, hentry->root.u.def.section))
+ goto error_return;
+ xcoff_sweep (info);
+ xcoff_hash_table (info)->gc = true;
+ }
+
+ /* Return special sections to the caller. */
+ for (i = 0; i < 6; i++)
+ {
+ asection *sec;
+
+ sec = xcoff_hash_table (info)->special_sections[i];
+ if (sec != NULL
+ && gc
+ && (sec->flags & SEC_MARK) == 0)
+ sec = NULL;
+ special_sections[i] = sec;
+ }
+
+ if (info->input_bfds == NULL)
+ {
+ /* I'm not sure what to do in this bizarre case. */
+ return true;
+ }
+
+ xcoff_link_hash_traverse (xcoff_hash_table (info), xcoff_build_ldsyms,
+ (PTR) &ldinfo);
+ if (ldinfo.failed)
+ goto error_return;
+
+ /* Work out the size of the import file names. Each import file ID
+ consists of three null terminated strings: the path, the file
+ name, and the archive member name. The first entry in the list
+ of names is the path to use to find objects, which the linker has
+ passed in as the libpath argument. For some reason, the path
+ entry in the other import file names appears to always be empty. */
+ impsize = strlen (libpath) + 3;
+ impcount = 1;
+ for (fl = xcoff_hash_table (info)->imports; fl != NULL; fl = fl->next)
+ {
+ ++impcount;
+ impsize += (strlen (fl->path)
+ + strlen (fl->file)
+ + strlen (fl->member)
+ + 3);
+ }
+
+ /* Set up the .loader section header. */
+ ldhdr = &xcoff_hash_table (info)->ldhdr;
+ ldhdr->l_version = 1;
+ ldhdr->l_nsyms = ldinfo.ldsym_count;
+ ldhdr->l_nreloc = xcoff_hash_table (info)->ldrel_count;
+ ldhdr->l_istlen = impsize;
+ ldhdr->l_nimpid = impcount;
+ ldhdr->l_impoff = (LDHDRSZ
+ + ldhdr->l_nsyms * LDSYMSZ
+ + ldhdr->l_nreloc * LDRELSZ);
+ ldhdr->l_stlen = ldinfo.string_size;
+ stoff = ldhdr->l_impoff + impsize;
+ if (ldinfo.string_size == 0)
+ ldhdr->l_stoff = 0;
+ else
+ ldhdr->l_stoff = stoff;
+
+ /* We now know the final size of the .loader section. Allocate
+ space for it. */
+ lsec = xcoff_hash_table (info)->loader_section;
+ lsec->_raw_size = stoff + ldhdr->l_stlen;
+ lsec->contents = (bfd_byte *) bfd_zalloc (output_bfd, lsec->_raw_size);
+ if (lsec->contents == NULL)
+ goto error_return;
+
+ /* Set up the header. */
+ xcoff_swap_ldhdr_out (output_bfd, ldhdr,
+ (struct external_ldhdr *) lsec->contents);
+
+ /* Set up the import file names. */
+ out = (char *) lsec->contents + ldhdr->l_impoff;
+ strcpy (out, libpath);
+ out += strlen (libpath) + 1;
+ *out++ = '\0';
+ *out++ = '\0';
+ for (fl = xcoff_hash_table (info)->imports; fl != NULL; fl = fl->next)
+ {
+ register const char *s;
+
+ s = fl->path;
+ while ((*out++ = *s++) != '\0')
+ ;
+ s = fl->file;
+ while ((*out++ = *s++) != '\0')
+ ;
+ s = fl->member;
+ while ((*out++ = *s++) != '\0')
+ ;
+ }
+
+ BFD_ASSERT ((bfd_size_type) ((bfd_byte *) out - lsec->contents) == stoff);
+
+ /* Set up the symbol string table. */
+ if (ldinfo.string_size > 0)
+ {
+ memcpy (out, ldinfo.strings, ldinfo.string_size);
+ free (ldinfo.strings);
+ ldinfo.strings = NULL;
+ }
+
+ /* We can't set up the symbol table or the relocs yet, because we
+ don't yet know the final position of the various sections. The
+ .loader symbols are written out when the corresponding normal
+ symbols are written out in xcoff_link_input_bfd or
+ xcoff_write_global_symbol. The .loader relocs are written out
+ when the corresponding normal relocs are handled in
+ xcoff_link_input_bfd. */
+
+ /* Allocate space for the magic sections. */
+ sec = xcoff_hash_table (info)->linkage_section;
+ if (sec->_raw_size > 0)
+ {
+ sec->contents = (bfd_byte *) bfd_zalloc (output_bfd, sec->_raw_size);
+ if (sec->contents == NULL)
+ goto error_return;
+ }
+ sec = xcoff_hash_table (info)->toc_section;
+ if (sec->_raw_size > 0)
+ {
+ sec->contents = (bfd_byte *) bfd_zalloc (output_bfd, sec->_raw_size);
+ if (sec->contents == NULL)
+ goto error_return;
+ }
+ sec = xcoff_hash_table (info)->descriptor_section;
+ if (sec->_raw_size > 0)
+ {
+ sec->contents = (bfd_byte *) bfd_zalloc (output_bfd, sec->_raw_size);
+ if (sec->contents == NULL)
+ goto error_return;
+ }
+
+ /* Now that we've done garbage collection, figure out the contents
+ of the .debug section. */
+ debug_strtab = xcoff_hash_table (info)->debug_strtab;
+
+ for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
+ {
+ asection *subdeb;
+ bfd_size_type symcount;
+ unsigned long *debug_index;
+ asection **csectpp;
+ bfd_byte *esym, *esymend;
+ bfd_size_type symesz;
+
+ if (sub->xvec != info->hash->creator)
+ continue;
+ subdeb = bfd_get_section_by_name (sub, ".debug");
+ if (subdeb == NULL || subdeb->_raw_size == 0)
+ continue;
+
+ if (info->strip == strip_all
+ || info->strip == strip_debugger
+ || info->discard == discard_all)
+ {
+ subdeb->_raw_size = 0;
+ continue;
+ }
+
+ if (! _bfd_coff_get_external_symbols (sub))
+ goto error_return;
+
+ symcount = obj_raw_syment_count (sub);
+ debug_index = ((unsigned long *)
+ bfd_zalloc (sub, symcount * sizeof (unsigned long)));
+ if (debug_index == NULL)
+ goto error_return;
+ xcoff_data (sub)->debug_indices = debug_index;
+
+ /* Grab the contents of the .debug section. We use malloc and
+ copy the names into the debug stringtab, rather than
+ bfd_alloc, because I expect that, when linking many files
+ together, many of the strings will be the same. Storing the
+ strings in the hash table should save space in this case. */
+ debug_contents = (bfd_byte *) bfd_malloc (subdeb->_raw_size);
+ if (debug_contents == NULL)
+ goto error_return;
+ if (! bfd_get_section_contents (sub, subdeb, (PTR) debug_contents,
+ (file_ptr) 0, subdeb->_raw_size))
+ goto error_return;
+
+ csectpp = xcoff_data (sub)->csects;
+
+ symesz = bfd_coff_symesz (sub);
+ esym = (bfd_byte *) obj_coff_external_syms (sub);
+ esymend = esym + symcount * symesz;
+ while (esym < esymend)
+ {
+ struct internal_syment sym;
+
+ bfd_coff_swap_sym_in (sub, (PTR) esym, (PTR) &sym);
+
+ *debug_index = (unsigned long) -1;
+
+ if (sym._n._n_n._n_zeroes == 0
+ && *csectpp != NULL
+ && (! gc
+ || ((*csectpp)->flags & SEC_MARK) != 0
+ || *csectpp == bfd_abs_section_ptr)
+ && bfd_coff_symname_in_debug (sub, &sym))
+ {
+ char *name;
+ bfd_size_type indx;
+
+ name = (char *) debug_contents + sym._n._n_n._n_offset;
+ indx = _bfd_stringtab_add (debug_strtab, name, true, true);
+ if (indx == (bfd_size_type) -1)
+ goto error_return;
+ *debug_index = indx;
+ }
+
+ esym += (sym.n_numaux + 1) * symesz;
+ csectpp += sym.n_numaux + 1;
+ debug_index += sym.n_numaux + 1;
+ }
+
+ free (debug_contents);
+ debug_contents = NULL;
+
+ /* Clear the size of subdeb, so that it is not included directly
+ in the output file. */
+ subdeb->_raw_size = 0;
+
+ if (! info->keep_memory)
+ {
+ if (! _bfd_coff_free_symbols (sub))
+ goto error_return;
+ }
+ }
+
+ if (info->strip != strip_all)
+ xcoff_hash_table (info)->debug_section->_raw_size =
+ _bfd_stringtab_size (debug_strtab);
+
+ return true;
+
+ error_return:
+ if (ldinfo.strings != NULL)
+ free (ldinfo.strings);
+ if (debug_contents != NULL)
+ free (debug_contents);
+ return false;
+}
+
+/* Add a symbol to the .loader symbols, if necessary. */
+
+static boolean
+xcoff_build_ldsyms (h, p)
+ struct xcoff_link_hash_entry *h;
+ PTR p;
+{
+ struct xcoff_loader_info *ldinfo = (struct xcoff_loader_info *) p;
+ size_t len;
+
+ /* If this is a final link, and the symbol was defined as a common
+ symbol in a regular object file, and there was no definition in
+ any dynamic object, then the linker will have allocated space for
+ the symbol in a common section but the XCOFF_DEF_REGULAR flag
+ will not have been set. */
+ if (h->root.type == bfd_link_hash_defined
+ && (h->flags & XCOFF_DEF_REGULAR) == 0
+ && (h->flags & XCOFF_REF_REGULAR) != 0
+ && (h->flags & XCOFF_DEF_DYNAMIC) == 0
+ && (bfd_is_abs_section (h->root.u.def.section)
+ || (h->root.u.def.section->owner->flags & DYNAMIC) == 0))
+ h->flags |= XCOFF_DEF_REGULAR;
+
+ /* If all defined symbols should be exported, mark them now. We
+ don't want to export the actual functions, just the function
+ descriptors. */
+ if (ldinfo->export_defineds
+ && (h->flags & XCOFF_DEF_REGULAR) != 0
+ && h->root.root.string[0] != '.')
+ {
+ boolean export;
+
+ /* We don't export a symbol which is being defined by an object
+ included from an archive which contains a shared object. The
+ rationale is that if an archive contains both an unshared and
+ a shared object, then there must be some reason that the
+ unshared object is unshared, and we don't want to start
+ providing a shared version of it. In particular, this solves
+ a bug involving the _savefNN set of functions. gcc will call
+ those functions without providing a slot to restore the TOC,
+ so it is essential that these functions be linked in directly
+ and not from a shared object, which means that a shared
+ object which also happens to link them in must not export
+ them. This is confusing, but I haven't been able to think of
+ a different approach. Note that the symbols can, of course,
+ be exported explicitly. */
+ export = true;
+ if ((h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak)
+ && h->root.u.def.section->owner != NULL
+ && h->root.u.def.section->owner->my_archive != NULL)
+ {
+ bfd *arbfd, *member;
+
+ arbfd = h->root.u.def.section->owner->my_archive;
+ member = bfd_openr_next_archived_file (arbfd, (bfd *) NULL);
+ while (member != NULL)
+ {
+ if ((member->flags & DYNAMIC) != 0)
+ {
+ export = false;
+ break;
+ }
+ member = bfd_openr_next_archived_file (arbfd, member);
+ }
+ }
+
+ if (export)
+ h->flags |= XCOFF_EXPORT;
+ }
+
+ /* We don't want to garbage collect symbols which are not defined in
+ XCOFF files. This is a convenient place to mark them. */
+ if (xcoff_hash_table (ldinfo->info)->gc
+ && (h->flags & XCOFF_MARK) == 0
+ && (h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak)
+ && (h->root.u.def.section->owner == NULL
+ || (h->root.u.def.section->owner->xvec
+ != ldinfo->info->hash->creator)))
+ h->flags |= XCOFF_MARK;
+
+ /* If this symbol is called and defined in a dynamic object, or it
+ is imported, then we need to set up global linkage code for it.
+ (Unless we did garbage collection and we didn't need this
+ symbol.) */
+ if ((h->flags & XCOFF_CALLED) != 0
+ && (h->root.type == bfd_link_hash_undefined
+ || h->root.type == bfd_link_hash_undefweak)
+ && h->root.root.string[0] == '.'
+ && h->descriptor != NULL
+ && ((h->descriptor->flags & XCOFF_DEF_DYNAMIC) != 0
+ || ((h->descriptor->flags & XCOFF_IMPORT) != 0
+ && (h->descriptor->flags & XCOFF_DEF_REGULAR) == 0))
+ && (! xcoff_hash_table (ldinfo->info)->gc
+ || (h->flags & XCOFF_MARK) != 0))
+ {
+ asection *sec;
+ struct xcoff_link_hash_entry *hds;
+
+ sec = xcoff_hash_table (ldinfo->info)->linkage_section;
+ h->root.type = bfd_link_hash_defined;
+ h->root.u.def.section = sec;
+ h->root.u.def.value = sec->_raw_size;
+ h->smclas = XMC_GL;
+ h->flags |= XCOFF_DEF_REGULAR;
+ sec->_raw_size += XCOFF_GLINK_SIZE;
+
+ /* The global linkage code requires a TOC entry for the
+ descriptor. */
+ hds = h->descriptor;
+ BFD_ASSERT ((hds->root.type == bfd_link_hash_undefined
+ || hds->root.type == bfd_link_hash_undefweak)
+ && (hds->flags & XCOFF_DEF_REGULAR) == 0);
+ hds->flags |= XCOFF_MARK;
+ if (hds->toc_section == NULL)
+ {
+ hds->toc_section = xcoff_hash_table (ldinfo->info)->toc_section;
+ hds->u.toc_offset = hds->toc_section->_raw_size;
+ hds->toc_section->_raw_size += 4;
+ ++xcoff_hash_table (ldinfo->info)->ldrel_count;
+ ++hds->toc_section->reloc_count;
+ hds->indx = -2;
+ hds->flags |= XCOFF_SET_TOC | XCOFF_LDREL;
+
+ /* We need to call xcoff_build_ldsyms recursively here,
+ because we may already have passed hds on the traversal. */
+ xcoff_build_ldsyms (hds, p);
+ }
+ }
+
+ /* If this symbol is exported, but not defined, we need to try to
+ define it. */
+ if ((h->flags & XCOFF_EXPORT) != 0
+ && (h->flags & XCOFF_IMPORT) == 0
+ && (h->flags & XCOFF_DEF_REGULAR) == 0
+ && (h->flags & XCOFF_DEF_DYNAMIC) == 0
+ && (h->root.type == bfd_link_hash_undefined
+ || h->root.type == bfd_link_hash_undefweak))
+ {
+ if ((h->flags & XCOFF_DESCRIPTOR) != 0
+ && (h->descriptor->root.type == bfd_link_hash_defined
+ || h->descriptor->root.type == bfd_link_hash_defweak))
+ {
+ asection *sec;
+
+ /* This is an undefined function descriptor associated with
+ a defined entry point. We can build up a function
+ descriptor ourselves. Believe it or not, the AIX linker
+ actually does this, and there are cases where we need to
+ do it as well. */
+ sec = xcoff_hash_table (ldinfo->info)->descriptor_section;
+ h->root.type = bfd_link_hash_defined;
+ h->root.u.def.section = sec;
+ h->root.u.def.value = sec->_raw_size;
+ h->smclas = XMC_DS;
+ h->flags |= XCOFF_DEF_REGULAR;
+ sec->_raw_size += 12;
+
+ /* A function descriptor uses two relocs: one for the
+ associated code, and one for the TOC address. */
+ xcoff_hash_table (ldinfo->info)->ldrel_count += 2;
+ sec->reloc_count += 2;
+
+ /* We handle writing out the contents of the descriptor in
+ xcoff_write_global_symbol. */
+ }
+ else
+ {
+ (*_bfd_error_handler)
+ (_("warning: attempt to export undefined symbol `%s'"),
+ h->root.root.string);
+ h->ldsym = NULL;
+ return true;
+ }
+ }
+
+ /* If this is still a common symbol, and it wasn't garbage
+ collected, we need to actually allocate space for it in the .bss
+ section. */
+ if (h->root.type == bfd_link_hash_common
+ && (! xcoff_hash_table (ldinfo->info)->gc
+ || (h->flags & XCOFF_MARK) != 0)
+ && h->root.u.c.p->section->_raw_size == 0)
+ {
+ BFD_ASSERT (bfd_is_com_section (h->root.u.c.p->section));
+ h->root.u.c.p->section->_raw_size = h->root.u.c.size;
+ }
+
+ /* We need to add a symbol to the .loader section if it is mentioned
+ in a reloc which we are copying to the .loader section and it was
+ not defined or common, or if it is the entry point, or if it is
+ being exported. */
+
+ if (((h->flags & XCOFF_LDREL) == 0
+ || h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak
+ || h->root.type == bfd_link_hash_common)
+ && (h->flags & XCOFF_ENTRY) == 0
+ && (h->flags & XCOFF_EXPORT) == 0)
+ {
+ h->ldsym = NULL;
+ return true;
+ }
+
+ /* We don't need to add this symbol if we did garbage collection and
+ we did not mark this symbol. */
+ if (xcoff_hash_table (ldinfo->info)->gc
+ && (h->flags & XCOFF_MARK) == 0)
+ {
+ h->ldsym = NULL;
+ return true;
+ }
+
+ /* We may have already processed this symbol due to the recursive
+ call above. */
+ if ((h->flags & XCOFF_BUILT_LDSYM) != 0)
+ return true;
+
+ /* We need to add this symbol to the .loader symbols. */
+
+ BFD_ASSERT (h->ldsym == NULL);
+ h->ldsym = ((struct internal_ldsym *)
+ bfd_zalloc (ldinfo->output_bfd,
+ sizeof (struct internal_ldsym)));
+ if (h->ldsym == NULL)
+ {
+ ldinfo->failed = true;
+ return false;
+ }
+
+ if ((h->flags & XCOFF_IMPORT) != 0)
+ h->ldsym->l_ifile = h->ldindx;
+
+ /* The first 3 symbol table indices are reserved to indicate the
+ sections. */
+ h->ldindx = ldinfo->ldsym_count + 3;
+
+ ++ldinfo->ldsym_count;
+
+ len = strlen (h->root.root.string);
+ if (len <= SYMNMLEN)
+ strncpy (h->ldsym->_l._l_name, h->root.root.string, SYMNMLEN);
+ else
+ {
+ if (ldinfo->string_size + len + 3 > ldinfo->string_alc)
+ {
+ size_t newalc;
+ bfd_byte *newstrings;
+
+ newalc = ldinfo->string_alc * 2;
+ if (newalc == 0)
+ newalc = 32;
+ while (ldinfo->string_size + len + 3 > newalc)
+ newalc *= 2;
+
+ newstrings = ((bfd_byte *)
+ bfd_realloc ((PTR) ldinfo->strings, newalc));
+ if (newstrings == NULL)
+ {
+ ldinfo->failed = true;
+ return false;
+ }
+ ldinfo->string_alc = newalc;
+ ldinfo->strings = newstrings;
+ }
+
+ bfd_put_16 (ldinfo->output_bfd, len + 1,
+ ldinfo->strings + ldinfo->string_size);
+ strcpy (ldinfo->strings + ldinfo->string_size + 2, h->root.root.string);
+ h->ldsym->_l._l_l._l_zeroes = 0;
+ h->ldsym->_l._l_l._l_offset = ldinfo->string_size + 2;
+ ldinfo->string_size += len + 3;
+ }
+
+ h->flags |= XCOFF_BUILT_LDSYM;
+
+ return true;
+}
+
+/* Do the final link step. */
+
+boolean
+_bfd_xcoff_bfd_final_link (abfd, info)
+ bfd *abfd;
+ struct bfd_link_info *info;
+{
+ bfd_size_type symesz;
+ struct xcoff_final_link_info finfo;
+ asection *o;
+ struct bfd_link_order *p;
+ size_t max_contents_size;
+ size_t max_sym_count;
+ size_t max_lineno_count;
+ size_t max_reloc_count;
+ size_t max_output_reloc_count;
+ file_ptr rel_filepos;
+ unsigned int relsz;
+ file_ptr line_filepos;
+ unsigned int linesz;
+ bfd *sub;
+ bfd_byte *external_relocs = NULL;
+ char strbuf[STRING_SIZE_SIZE];
+
+ if (info->shared)
+ abfd->flags |= DYNAMIC;
+
+ symesz = bfd_coff_symesz (abfd);
+
+ finfo.info = info;
+ finfo.output_bfd = abfd;
+ finfo.strtab = NULL;
+ finfo.section_info = NULL;
+ finfo.last_file_index = -1;
+ finfo.toc_symindx = -1;
+ finfo.internal_syms = NULL;
+ finfo.sym_indices = NULL;
+ finfo.outsyms = NULL;
+ finfo.linenos = NULL;
+ finfo.contents = NULL;
+ finfo.external_relocs = NULL;
+
+ finfo.ldsym = ((struct external_ldsym *)
+ (xcoff_hash_table (info)->loader_section->contents
+ + LDHDRSZ));
+ finfo.ldrel = ((struct external_ldrel *)
+ (xcoff_hash_table (info)->loader_section->contents
+ + LDHDRSZ
+ + xcoff_hash_table (info)->ldhdr.l_nsyms * LDSYMSZ));
+
+ xcoff_data (abfd)->coff.link_info = info;
+
+ finfo.strtab = _bfd_stringtab_init ();
+ if (finfo.strtab == NULL)
+ goto error_return;
+
+ /* Count the line number and relocation entries required for the
+ output file. Determine a few maximum sizes. */
+ max_contents_size = 0;
+ max_lineno_count = 0;
+ max_reloc_count = 0;
+ for (o = abfd->sections; o != NULL; o = o->next)
+ {
+ o->reloc_count = 0;
+ o->lineno_count = 0;
+ for (p = o->link_order_head; p != NULL; p = p->next)
+ {
+ if (p->type == bfd_indirect_link_order)
+ {
+ asection *sec;
+
+ sec = p->u.indirect.section;
+
+ /* Mark all sections which are to be included in the
+ link. This will normally be every section. We need
+ to do this so that we can identify any sections which
+ the linker has decided to not include. */
+ sec->linker_mark = true;
+
+ if (info->strip == strip_none
+ || info->strip == strip_some)
+ o->lineno_count += sec->lineno_count;
+
+ o->reloc_count += sec->reloc_count;
+
+ if (sec->_raw_size > max_contents_size)
+ max_contents_size = sec->_raw_size;
+ if (sec->lineno_count > max_lineno_count)
+ max_lineno_count = sec->lineno_count;
+ if (coff_section_data (sec->owner, sec) != NULL
+ && xcoff_section_data (sec->owner, sec) != NULL
+ && (xcoff_section_data (sec->owner, sec)->lineno_count
+ > max_lineno_count))
+ max_lineno_count =
+ xcoff_section_data (sec->owner, sec)->lineno_count;
+ if (sec->reloc_count > max_reloc_count)
+ max_reloc_count = sec->reloc_count;
+ }
+ else if (p->type == bfd_section_reloc_link_order
+ || p->type == bfd_symbol_reloc_link_order)
+ ++o->reloc_count;
+ }
+ }
+
+ /* Compute the file positions for all the sections. */
+ if (abfd->output_has_begun)
+ {
+ if (xcoff_hash_table (info)->file_align != 0)
+ abort ();
+ }
+ else
+ {
+ bfd_vma file_align;
+
+ file_align = xcoff_hash_table (info)->file_align;
+ if (file_align != 0)
+ {
+ boolean saw_contents;
+ int indx;
+ asection **op;
+ file_ptr sofar;
+
+ /* Insert .pad sections before every section which has
+ contents and is loaded, if it is preceded by some other
+ section which has contents and is loaded. */
+ saw_contents = true;
+ for (op = &abfd->sections; *op != NULL; op = &(*op)->next)
+ {
+ if (strcmp ((*op)->name, ".pad") == 0)
+ saw_contents = false;
+ else if (((*op)->flags & SEC_HAS_CONTENTS) != 0
+ && ((*op)->flags & SEC_LOAD) != 0)
+ {
+ if (! saw_contents)
+ saw_contents = true;
+ else
+ {
+ asection *n, *hold;
+
+ hold = *op;
+ *op = NULL;
+ n = bfd_make_section_anyway (abfd, ".pad");
+ BFD_ASSERT (*op == n);
+ n->next = hold;
+ n->flags = SEC_HAS_CONTENTS;
+ n->alignment_power = 0;
+ saw_contents = false;
+ }
+ }
+ }
+
+ /* Reset the section indices after inserting the new
+ sections. */
+ indx = 0;
+ for (o = abfd->sections; o != NULL; o = o->next)
+ {
+ ++indx;
+ o->target_index = indx;
+ }
+ BFD_ASSERT ((unsigned int) indx == abfd->section_count);
+
+ /* Work out appropriate sizes for the .pad sections to force
+ each section to land on a page boundary. This bit of
+ code knows what compute_section_file_positions is going
+ to do. */
+ sofar = bfd_coff_filhsz (abfd);
+ sofar += bfd_coff_aoutsz (abfd);
+ sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
+ for (o = abfd->sections; o != NULL; o = o->next)
+ if (o->reloc_count >= 0xffff || o->lineno_count >= 0xffff)
+ sofar += bfd_coff_scnhsz (abfd);
+
+ for (o = abfd->sections; o != NULL; o = o->next)
+ {
+ if (strcmp (o->name, ".pad") == 0)
+ {
+ bfd_vma pageoff;
+
+ BFD_ASSERT (o->_raw_size == 0);
+ pageoff = sofar & (file_align - 1);
+ if (pageoff != 0)
+ {
+ o->_raw_size = file_align - pageoff;
+ sofar += file_align - pageoff;
+ o->flags |= SEC_HAS_CONTENTS;
+ }
+ }
+ else
+ {
+ if ((o->flags & SEC_HAS_CONTENTS) != 0)
+ sofar += BFD_ALIGN (o->_raw_size,
+ 1 << o->alignment_power);
+ }
+ }
+ }
+
+ if (! bfd_coff_compute_section_file_positions (abfd))
+ goto error_return;
+ }
+
+ /* Allocate space for the pointers we need to keep for the relocs. */
+ {
+ unsigned int i;
+
+ /* We use section_count + 1, rather than section_count, because
+ the target_index fields are 1 based. */
+ finfo.section_info =
+ ((struct xcoff_link_section_info *)
+ bfd_malloc ((abfd->section_count + 1)
+ * sizeof (struct xcoff_link_section_info)));
+ if (finfo.section_info == NULL)
+ goto error_return;
+ for (i = 0; i <= abfd->section_count; i++)
+ {
+ finfo.section_info[i].relocs = NULL;
+ finfo.section_info[i].rel_hashes = NULL;
+ finfo.section_info[i].toc_rel_hashes = NULL;
+ }
+ }
+
+ /* Set the file positions for the relocs. */
+ rel_filepos = obj_relocbase (abfd);
+ relsz = bfd_coff_relsz (abfd);
+ max_output_reloc_count = 0;
+ for (o = abfd->sections; o != NULL; o = o->next)
+ {
+ if (o->reloc_count == 0)
+ o->rel_filepos = 0;
+ else
+ {
+ /* A stripped file has no relocs. However, we still
+ allocate the buffers, so that later code doesn't have to
+ worry about whether we are stripping or not. */
+ if (info->strip == strip_all)
+ o->rel_filepos = 0;
+ else
+ {
+ o->flags |= SEC_RELOC;
+ o->rel_filepos = rel_filepos;
+ rel_filepos += o->reloc_count * relsz;
+ }
+
+ /* We don't know the indices of global symbols until we have
+ written out all the local symbols. For each section in
+ the output file, we keep an array of pointers to hash
+ table entries. Each entry in the array corresponds to a
+ reloc. When we find a reloc against a global symbol, we
+ set the corresponding entry in this array so that we can
+ fix up the symbol index after we have written out all the
+ local symbols.
+
+ Because of this problem, we also keep the relocs in
+ memory until the end of the link. This wastes memory.
+ We could backpatch the file later, I suppose, although it
+ would be slow. */
+ finfo.section_info[o->target_index].relocs =
+ ((struct internal_reloc *)
+ bfd_malloc (o->reloc_count * sizeof (struct internal_reloc)));
+ finfo.section_info[o->target_index].rel_hashes =
+ ((struct xcoff_link_hash_entry **)
+ bfd_malloc (o->reloc_count
+ * sizeof (struct xcoff_link_hash_entry *)));
+ if (finfo.section_info[o->target_index].relocs == NULL
+ || finfo.section_info[o->target_index].rel_hashes == NULL)
+ goto error_return;
+
+ if (o->reloc_count > max_output_reloc_count)
+ max_output_reloc_count = o->reloc_count;
+ }
+ }
+
+ /* We now know the size of the relocs, so we can determine the file
+ positions of the line numbers. */
+ line_filepos = rel_filepos;
+ finfo.line_filepos = line_filepos;
+ linesz = bfd_coff_linesz (abfd);
+ for (o = abfd->sections; o != NULL; o = o->next)
+ {
+ if (o->lineno_count == 0)
+ o->line_filepos = 0;
+ else
+ {
+ o->line_filepos = line_filepos;
+ line_filepos += o->lineno_count * linesz;
+ }
+
+ /* Reset the reloc and lineno counts, so that we can use them to
+ count the number of entries we have output so far. */
+ o->reloc_count = 0;
+ o->lineno_count = 0;
+ }
+
+ obj_sym_filepos (abfd) = line_filepos;
+
+ /* Figure out the largest number of symbols in an input BFD. Take
+ the opportunity to clear the output_has_begun fields of all the
+ input BFD's. We want at least 6 symbols, since that is the
+ number which xcoff_write_global_symbol may need. */
+ max_sym_count = 6;
+ for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
+ {
+ size_t sz;
+
+ sub->output_has_begun = false;
+ sz = obj_raw_syment_count (sub);
+ if (sz > max_sym_count)
+ max_sym_count = sz;
+ }
+
+ /* Allocate some buffers used while linking. */
+ finfo.internal_syms = ((struct internal_syment *)
+ bfd_malloc (max_sym_count
+ * sizeof (struct internal_syment)));
+ finfo.sym_indices = (long *) bfd_malloc (max_sym_count * sizeof (long));
+ finfo.outsyms = ((bfd_byte *)
+ bfd_malloc ((size_t) ((max_sym_count + 1) * symesz)));
+ finfo.linenos = (bfd_byte *) bfd_malloc (max_lineno_count
+ * bfd_coff_linesz (abfd));
+ finfo.contents = (bfd_byte *) bfd_malloc (max_contents_size);
+ finfo.external_relocs = (bfd_byte *) bfd_malloc (max_reloc_count * relsz);
+ if ((finfo.internal_syms == NULL && max_sym_count > 0)
+ || (finfo.sym_indices == NULL && max_sym_count > 0)
+ || finfo.outsyms == NULL
+ || (finfo.linenos == NULL && max_lineno_count > 0)
+ || (finfo.contents == NULL && max_contents_size > 0)
+ || (finfo.external_relocs == NULL && max_reloc_count > 0))
+ goto error_return;
+
+ obj_raw_syment_count (abfd) = 0;
+ xcoff_data (abfd)->toc = (bfd_vma) -1;
+
+ /* We now know the position of everything in the file, except that
+ we don't know the size of the symbol table and therefore we don't
+ know where the string table starts. We just build the string
+ table in memory as we go along. We process all the relocations
+ for a single input file at once. */
+ for (o = abfd->sections; o != NULL; o = o->next)
+ {
+ for (p = o->link_order_head; p != NULL; p = p->next)
+ {
+ if (p->type == bfd_indirect_link_order
+ && p->u.indirect.section->owner->xvec == abfd->xvec)
+ {
+ sub = p->u.indirect.section->owner;
+ if (! sub->output_has_begun)
+ {
+ if (! xcoff_link_input_bfd (&finfo, sub))
+ goto error_return;
+ sub->output_has_begun = true;
+ }
+ }
+ else if (p->type == bfd_section_reloc_link_order
+ || p->type == bfd_symbol_reloc_link_order)
+ {
+ if (! xcoff_reloc_link_order (abfd, &finfo, o, p))
+ goto error_return;
+ }
+ else
+ {
+ if (! _bfd_default_link_order (abfd, info, o, p))
+ goto error_return;
+ }
+ }
+ }
+
+ /* Free up the buffers used by xcoff_link_input_bfd. */
+
+ if (finfo.internal_syms != NULL)
+ {
+ free (finfo.internal_syms);
+ finfo.internal_syms = NULL;
+ }
+ if (finfo.sym_indices != NULL)
+ {
+ free (finfo.sym_indices);
+ finfo.sym_indices = NULL;
+ }
+ if (finfo.linenos != NULL)
+ {
+ free (finfo.linenos);
+ finfo.linenos = NULL;
+ }
+ if (finfo.contents != NULL)
+ {
+ free (finfo.contents);
+ finfo.contents = NULL;
+ }
+ if (finfo.external_relocs != NULL)
+ {
+ free (finfo.external_relocs);
+ finfo.external_relocs = NULL;
+ }
+
+ /* The value of the last C_FILE symbol is supposed to be -1. Write
+ it out again. */
+ if (finfo.last_file_index != -1)
+ {
+ finfo.last_file.n_value = -1;
+ bfd_coff_swap_sym_out (abfd, (PTR) &finfo.last_file,
+ (PTR) finfo.outsyms);
+ if (bfd_seek (abfd,
+ (obj_sym_filepos (abfd)
+ + finfo.last_file_index * symesz),
+ SEEK_SET) != 0
+ || bfd_write (finfo.outsyms, symesz, 1, abfd) != symesz)
+ goto error_return;
+ }
+
+ /* Write out all the global symbols which do not come from XCOFF
+ input files. */
+ xcoff_link_hash_traverse (xcoff_hash_table (info),
+ xcoff_write_global_symbol,
+ (PTR) &finfo);
+
+ if (finfo.outsyms != NULL)
+ {
+ free (finfo.outsyms);
+ finfo.outsyms = NULL;
+ }
+
+ /* Now that we have written out all the global symbols, we know the
+ symbol indices to use for relocs against them, and we can finally
+ write out the relocs. */
+ external_relocs = (bfd_byte *) bfd_malloc (max_output_reloc_count * relsz);
+ if (external_relocs == NULL && max_output_reloc_count != 0)
+ goto error_return;
+
+ for (o = abfd->sections; o != NULL; o = o->next)
+ {
+ struct internal_reloc *irel;
+ struct internal_reloc *irelend;
+ struct xcoff_link_hash_entry **rel_hash;
+ struct xcoff_toc_rel_hash *toc_rel_hash;
+ bfd_byte *erel;
+
+ /* A stripped file has no relocs. */
+ if (info->strip == strip_all)
+ {
+ o->reloc_count = 0;
+ continue;
+ }
+
+ if (o->reloc_count == 0)
+ continue;
+
+ irel = finfo.section_info[o->target_index].relocs;
+ irelend = irel + o->reloc_count;
+ rel_hash = finfo.section_info[o->target_index].rel_hashes;
+ for (; irel < irelend; irel++, rel_hash++, erel += relsz)
+ {
+ if (*rel_hash != NULL)
+ {
+ if ((*rel_hash)->indx < 0)
+ {
+ if (! ((*info->callbacks->unattached_reloc)
+ (info, (*rel_hash)->root.root.string,
+ (bfd *) NULL, o, irel->r_vaddr)))
+ goto error_return;
+ (*rel_hash)->indx = 0;
+ }
+ irel->r_symndx = (*rel_hash)->indx;
+ }
+ }
+
+ for (toc_rel_hash = finfo.section_info[o->target_index].toc_rel_hashes;
+ toc_rel_hash != NULL;
+ toc_rel_hash = toc_rel_hash->next)
+ {
+ if (toc_rel_hash->h->u.toc_indx < 0)
+ {
+ if (! ((*info->callbacks->unattached_reloc)
+ (info, toc_rel_hash->h->root.root.string,
+ (bfd *) NULL, o, toc_rel_hash->rel->r_vaddr)))
+ goto error_return;
+ toc_rel_hash->h->u.toc_indx = 0;
+ }
+ toc_rel_hash->rel->r_symndx = toc_rel_hash->h->u.toc_indx;
+ }
+
+ /* XCOFF requires that the relocs be sorted by address. We tend
+ to produce them in the order in which their containing csects
+ appear in the symbol table, which is not necessarily by
+ address. So we sort them here. There may be a better way to
+ do this. */
+ qsort ((PTR) finfo.section_info[o->target_index].relocs,
+ o->reloc_count, sizeof (struct internal_reloc),
+ xcoff_sort_relocs);
+
+ irel = finfo.section_info[o->target_index].relocs;
+ irelend = irel + o->reloc_count;
+ erel = external_relocs;
+ for (; irel < irelend; irel++, rel_hash++, erel += relsz)
+ bfd_coff_swap_reloc_out (abfd, (PTR) irel, (PTR) erel);
+
+ if (bfd_seek (abfd, o->rel_filepos, SEEK_SET) != 0
+ || bfd_write ((PTR) external_relocs, relsz, o->reloc_count,
+ abfd) != relsz * o->reloc_count)
+ goto error_return;
+ }
+
+ if (external_relocs != NULL)
+ {
+ free (external_relocs);
+ external_relocs = NULL;
+ }
+
+ /* Free up the section information. */
+ if (finfo.section_info != NULL)
+ {
+ unsigned int i;
+
+ for (i = 0; i < abfd->section_count; i++)
+ {
+ if (finfo.section_info[i].relocs != NULL)
+ free (finfo.section_info[i].relocs);
+ if (finfo.section_info[i].rel_hashes != NULL)
+ free (finfo.section_info[i].rel_hashes);
+ }
+ free (finfo.section_info);
+ finfo.section_info = NULL;
+ }
+
+ /* Write out the loader section contents. */
+ BFD_ASSERT ((bfd_byte *) finfo.ldrel
+ == (xcoff_hash_table (info)->loader_section->contents
+ + xcoff_hash_table (info)->ldhdr.l_impoff));
+ o = xcoff_hash_table (info)->loader_section;
+ if (! bfd_set_section_contents (abfd, o->output_section,
+ o->contents, o->output_offset,
+ o->_raw_size))
+ goto error_return;
+
+ /* Write out the magic sections. */
+ o = xcoff_hash_table (info)->linkage_section;
+ if (o->_raw_size > 0
+ && ! bfd_set_section_contents (abfd, o->output_section, o->contents,
+ o->output_offset, o->_raw_size))
+ goto error_return;
+ o = xcoff_hash_table (info)->toc_section;
+ if (o->_raw_size > 0
+ && ! bfd_set_section_contents (abfd, o->output_section, o->contents,
+ o->output_offset, o->_raw_size))
+ goto error_return;
+ o = xcoff_hash_table (info)->descriptor_section;
+ if (o->_raw_size > 0
+ && ! bfd_set_section_contents (abfd, o->output_section, o->contents,
+ o->output_offset, o->_raw_size))
+ goto error_return;
+
+ /* Write out the string table. */
+ if (bfd_seek (abfd,
+ (obj_sym_filepos (abfd)
+ + obj_raw_syment_count (abfd) * symesz),
+ SEEK_SET) != 0)
+ goto error_return;
+ bfd_h_put_32 (abfd,
+ _bfd_stringtab_size (finfo.strtab) + STRING_SIZE_SIZE,
+ (bfd_byte *) strbuf);
+ if (bfd_write (strbuf, 1, STRING_SIZE_SIZE, abfd) != STRING_SIZE_SIZE)
+ goto error_return;
+ if (! _bfd_stringtab_emit (abfd, finfo.strtab))
+ goto error_return;
+
+ _bfd_stringtab_free (finfo.strtab);
+
+ /* Write out the debugging string table. */
+ o = xcoff_hash_table (info)->debug_section;
+ if (o != NULL)
+ {
+ struct bfd_strtab_hash *debug_strtab;
+
+ debug_strtab = xcoff_hash_table (info)->debug_strtab;
+ BFD_ASSERT (o->output_section->_raw_size - o->output_offset
+ >= _bfd_stringtab_size (debug_strtab));
+ if (bfd_seek (abfd,
+ o->output_section->filepos + o->output_offset,
+ SEEK_SET) != 0)
+ goto error_return;
+ if (! _bfd_stringtab_emit (abfd, debug_strtab))
+ goto error_return;
+ }
+
+ /* Setting bfd_get_symcount to 0 will cause write_object_contents to
+ not try to write out the symbols. */
+ bfd_get_symcount (abfd) = 0;
+
+ return true;
+
+ error_return:
+ if (finfo.strtab != NULL)
+ _bfd_stringtab_free (finfo.strtab);
+ if (finfo.section_info != NULL)
+ {
+ unsigned int i;
+
+ for (i = 0; i < abfd->section_count; i++)
+ {
+ if (finfo.section_info[i].relocs != NULL)
+ free (finfo.section_info[i].relocs);
+ if (finfo.section_info[i].rel_hashes != NULL)
+ free (finfo.section_info[i].rel_hashes);
+ }
+ free (finfo.section_info);
+ }
+ if (finfo.internal_syms != NULL)
+ free (finfo.internal_syms);
+ if (finfo.sym_indices != NULL)
+ free (finfo.sym_indices);
+ if (finfo.outsyms != NULL)
+ free (finfo.outsyms);
+ if (finfo.linenos != NULL)
+ free (finfo.linenos);
+ if (finfo.contents != NULL)
+ free (finfo.contents);
+ if (finfo.external_relocs != NULL)
+ free (finfo.external_relocs);
+ if (external_relocs != NULL)
+ free (external_relocs);
+ return false;
+}
+
+/* Link an input file into the linker output file. This function
+ handles all the sections and relocations of the input file at once. */
+
+static boolean
+xcoff_link_input_bfd (finfo, input_bfd)
+ struct xcoff_final_link_info *finfo;
+ bfd *input_bfd;
+{
+ bfd *output_bfd;
+ const char *strings;
+ bfd_size_type syment_base;
+ unsigned int n_tmask;
+ unsigned int n_btshft;
+ boolean copy, hash;
+ bfd_size_type isymesz;
+ bfd_size_type osymesz;
+ bfd_size_type linesz;
+ bfd_byte *esym;
+ bfd_byte *esym_end;
+ struct xcoff_link_hash_entry **sym_hash;
+ struct internal_syment *isymp;
+ asection **csectpp;
+ unsigned long *debug_index;
+ long *indexp;
+ unsigned long output_index;
+ bfd_byte *outsym;
+ unsigned int incls;
+ asection *oline;
+ boolean keep_syms;
+ asection *o;
+
+ /* We can just skip DYNAMIC files, unless this is a static link. */
+ if ((input_bfd->flags & DYNAMIC) != 0
+ && ! finfo->info->static_link)
+ return true;
+
+ /* Move all the symbols to the output file. */
+
+ output_bfd = finfo->output_bfd;
+ strings = NULL;
+ syment_base = obj_raw_syment_count (output_bfd);
+ isymesz = bfd_coff_symesz (input_bfd);
+ osymesz = bfd_coff_symesz (output_bfd);
+ linesz = bfd_coff_linesz (input_bfd);
+ BFD_ASSERT (linesz == bfd_coff_linesz (output_bfd));
+
+ n_tmask = coff_data (input_bfd)->local_n_tmask;
+ n_btshft = coff_data (input_bfd)->local_n_btshft;
+
+ /* Define macros so that ISFCN, et. al., macros work correctly. */
+#define N_TMASK n_tmask
+#define N_BTSHFT n_btshft
+
+ copy = false;
+ if (! finfo->info->keep_memory)
+ copy = true;
+ hash = true;
+ if ((output_bfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
+ hash = false;
+
+ if (! _bfd_coff_get_external_symbols (input_bfd))
+ return false;
+
+ esym = (bfd_byte *) obj_coff_external_syms (input_bfd);
+ esym_end = esym + obj_raw_syment_count (input_bfd) * isymesz;
+ sym_hash = obj_xcoff_sym_hashes (input_bfd);
+ csectpp = xcoff_data (input_bfd)->csects;
+ debug_index = xcoff_data (input_bfd)->debug_indices;
+ isymp = finfo->internal_syms;
+ indexp = finfo->sym_indices;
+ output_index = syment_base;
+ outsym = finfo->outsyms;
+ incls = 0;
+ oline = NULL;
+
+ while (esym < esym_end)
+ {
+ struct internal_syment isym;
+ union internal_auxent aux;
+ int smtyp = 0;
+ boolean skip;
+ boolean require;
+ int add;
+
+ bfd_coff_swap_sym_in (input_bfd, (PTR) esym, (PTR) isymp);
+
+ /* If this is a C_EXT or C_HIDEXT symbol, we need the csect
+ information. */
+ if (isymp->n_sclass == C_EXT || isymp->n_sclass == C_HIDEXT)
+ {
+ BFD_ASSERT (isymp->n_numaux > 0);
+ bfd_coff_swap_aux_in (input_bfd,
+ (PTR) (esym + isymesz * isymp->n_numaux),
+ isymp->n_type, isymp->n_sclass,
+ isymp->n_numaux - 1, isymp->n_numaux,
+ (PTR) &aux);
+ smtyp = SMTYP_SMTYP (aux.x_csect.x_smtyp);
+ }
+
+ /* Make a copy of *isymp so that the relocate_section function
+ always sees the original values. This is more reliable than
+ always recomputing the symbol value even if we are stripping
+ the symbol. */
+ isym = *isymp;
+
+ /* If this symbol is in the .loader section, swap out the
+ .loader symbol information. If this is an external symbol
+ reference to a defined symbol, though, then wait until we get
+ to the definition. */
+ if (isym.n_sclass == C_EXT
+ && *sym_hash != NULL
+ && (*sym_hash)->ldsym != NULL
+ && (smtyp != XTY_ER
+ || (*sym_hash)->root.type == bfd_link_hash_undefined))
+ {
+ struct xcoff_link_hash_entry *h;
+ struct internal_ldsym *ldsym;
+
+ h = *sym_hash;
+ ldsym = h->ldsym;
+ if (isym.n_scnum > 0)
+ {
+ ldsym->l_scnum = (*csectpp)->output_section->target_index;
+ ldsym->l_value = (isym.n_value
+ + (*csectpp)->output_section->vma
+ + (*csectpp)->output_offset
+ - (*csectpp)->vma);
+ }
+ else
+ {
+ ldsym->l_scnum = isym.n_scnum;
+ ldsym->l_value = isym.n_value;
+ }
+
+ ldsym->l_smtype = smtyp;
+ if (((h->flags & XCOFF_DEF_REGULAR) == 0
+ && (h->flags & XCOFF_DEF_DYNAMIC) != 0)
+ || (h->flags & XCOFF_IMPORT) != 0)
+ ldsym->l_smtype |= L_IMPORT;
+ if (((h->flags & XCOFF_DEF_REGULAR) != 0
+ && (h->flags & XCOFF_DEF_DYNAMIC) != 0)
+ || (h->flags & XCOFF_EXPORT) != 0)
+ ldsym->l_smtype |= L_EXPORT;
+ if ((h->flags & XCOFF_ENTRY) != 0)
+ ldsym->l_smtype |= L_ENTRY;
+
+ ldsym->l_smclas = aux.x_csect.x_smclas;
+
+ if (ldsym->l_ifile == (bfd_size_type) -1)
+ ldsym->l_ifile = 0;
+ else if (ldsym->l_ifile == 0)
+ {
+ if ((ldsym->l_smtype & L_IMPORT) == 0)
+ ldsym->l_ifile = 0;
+ else
+ {
+ bfd *impbfd;
+
+ if (h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak)
+ impbfd = h->root.u.def.section->owner;
+ else if (h->root.type == bfd_link_hash_undefined
+ || h->root.type == bfd_link_hash_undefweak)
+ impbfd = h->root.u.undef.abfd;
+ else
+ impbfd = NULL;
+
+ if (impbfd == NULL)
+ ldsym->l_ifile = 0;
+ else
+ {
+ BFD_ASSERT (impbfd->xvec == finfo->output_bfd->xvec);
+ ldsym->l_ifile = xcoff_data (impbfd)->import_file_id;
+ }
+ }
+ }
+
+ ldsym->l_parm = 0;
+
+ BFD_ASSERT (h->ldindx >= 0);
+ BFD_ASSERT (LDSYMSZ == sizeof (struct external_ldsym));
+ xcoff_swap_ldsym_out (finfo->output_bfd, ldsym,
+ finfo->ldsym + h->ldindx - 3);
+ h->ldsym = NULL;
+
+ /* Fill in snentry now that we know the target_index. */
+ if ((h->flags & XCOFF_ENTRY) != 0
+ && (h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak))
+ xcoff_data (output_bfd)->snentry =
+ h->root.u.def.section->output_section->target_index;
+ }
+
+ *indexp = -1;
+
+ skip = false;
+ require = false;
+ add = 1 + isym.n_numaux;
+
+ /* If we are skipping this csect, we want to skip this symbol. */
+ if (*csectpp == NULL)
+ skip = true;
+
+ /* If we garbage collected this csect, we want to skip this
+ symbol. */
+ if (! skip
+ && xcoff_hash_table (finfo->info)->gc
+ && ((*csectpp)->flags & SEC_MARK) == 0
+ && *csectpp != bfd_abs_section_ptr)
+ skip = true;
+
+ /* An XCOFF linker always skips C_STAT symbols. */
+ if (! skip
+ && isymp->n_sclass == C_STAT)
+ skip = true;
+
+ /* We skip all but the first TOC anchor. */
+ if (! skip
+ && isymp->n_sclass == C_HIDEXT
+ && aux.x_csect.x_smclas == XMC_TC0)
+ {
+ if (finfo->toc_symindx != -1)
+ skip = true;
+ else
+ {
+ bfd_vma tocval, tocend;
+ bfd *inp;
+
+ tocval = ((*csectpp)->output_section->vma
+ + (*csectpp)->output_offset
+ + isym.n_value
+ - (*csectpp)->vma);
+
+ /* We want to find out if tocval is a good value to use
+ as the TOC anchor--that is, whether we can access all
+ of the TOC using a 16 bit offset from tocval. This
+ test assumes that the TOC comes at the end of the
+ output section, as it does in the default linker
+ script. */
+ tocend = ((*csectpp)->output_section->vma
+ + (*csectpp)->output_section->_raw_size);
+ for (inp = finfo->info->input_bfds;
+ inp != NULL;
+ inp = inp->link_next)
+ {
+ asection *o;
+
+ for (o = inp->sections; o != NULL; o = o->next)
+ if (strcmp (o->name, ".tocbss") == 0)
+ {
+ bfd_vma new_toc_end;
+ new_toc_end = (o->output_section->vma
+ + o->output_offset
+ + o->_cooked_size);
+ if (new_toc_end > tocend)
+ tocend = new_toc_end;
+ }
+
+ }
+
+ if (tocval + 0x10000 < tocend)
+ {
+ (*_bfd_error_handler)
+ (_("TOC overflow: 0x%lx > 0x10000; try -mminimal-toc when compiling"),
+ (unsigned long) (tocend - tocval));
+ bfd_set_error (bfd_error_file_too_big);
+ return false;
+ }
+
+ if (tocval + 0x8000 < tocend)
+ {
+ bfd_vma tocadd;
+
+ tocadd = tocend - (tocval + 0x8000);
+ tocval += tocadd;
+ isym.n_value += tocadd;
+ }
+
+ finfo->toc_symindx = output_index;
+ xcoff_data (finfo->output_bfd)->toc = tocval;
+ xcoff_data (finfo->output_bfd)->sntoc =
+ (*csectpp)->output_section->target_index;
+ require = true;
+ }
+ }
+
+ /* If we are stripping all symbols, we want to skip this one. */
+ if (! skip
+ && finfo->info->strip == strip_all)
+ skip = true;
+
+ /* We can skip resolved external references. */
+ if (! skip
+ && isym.n_sclass == C_EXT
+ && smtyp == XTY_ER
+ && (*sym_hash)->root.type != bfd_link_hash_undefined)
+ skip = true;
+
+ /* We can skip common symbols if they got defined somewhere
+ else. */
+ if (! skip
+ && isym.n_sclass == C_EXT
+ && smtyp == XTY_CM
+ && ((*sym_hash)->root.type != bfd_link_hash_common
+ || (*sym_hash)->root.u.c.p->section != *csectpp)
+ && ((*sym_hash)->root.type != bfd_link_hash_defined
+ || (*sym_hash)->root.u.def.section != *csectpp))
+ skip = true;
+
+ /* Skip local symbols if we are discarding them. */
+ if (! skip
+ && finfo->info->discard == discard_all
+ && isym.n_sclass != C_EXT
+ && (isym.n_sclass != C_HIDEXT
+ || smtyp != XTY_SD))
+ skip = true;
+
+ /* If we stripping debugging symbols, and this is a debugging
+ symbol, then skip it. */
+ if (! skip
+ && finfo->info->strip == strip_debugger
+ && isym.n_scnum == N_DEBUG)
+ skip = true;
+
+ /* If some symbols are stripped based on the name, work out the
+ name and decide whether to skip this symbol. We don't handle
+ this correctly for symbols whose names are in the .debug
+ section; to get it right we would need a new bfd_strtab_hash
+ function to return the string given the index. */
+ if (! skip
+ && (finfo->info->strip == strip_some
+ || finfo->info->discard == discard_l)
+ && (debug_index == NULL || *debug_index == (unsigned long) -1))
+ {
+ const char *name;
+ char buf[SYMNMLEN + 1];
+
+ name = _bfd_coff_internal_syment_name (input_bfd, &isym, buf);
+ if (name == NULL)
+ return false;
+
+ if ((finfo->info->strip == strip_some
+ && (bfd_hash_lookup (finfo->info->keep_hash, name, false,
+ false) == NULL))
+ || (finfo->info->discard == discard_l
+ && (isym.n_sclass != C_EXT
+ && (isym.n_sclass != C_HIDEXT
+ || smtyp != XTY_SD))
+ && bfd_is_local_label_name (input_bfd, name)))
+ skip = true;
+ }
+
+ /* We can not skip the first TOC anchor. */
+ if (skip
+ && require
+ && finfo->info->strip != strip_all)
+ skip = false;
+
+ /* We now know whether we are to skip this symbol or not. */
+ if (! skip)
+ {
+ /* Adjust the symbol in order to output it. */
+
+ if (isym._n._n_n._n_zeroes == 0
+ && isym._n._n_n._n_offset != 0)
+ {
+ /* This symbol has a long name. Enter it in the string
+ table we are building. If *debug_index != -1, the
+ name has already been entered in the .debug section. */
+ if (debug_index != NULL && *debug_index != (unsigned long) -1)
+ isym._n._n_n._n_offset = *debug_index;
+ else
+ {
+ const char *name;
+ bfd_size_type indx;
+
+ name = _bfd_coff_internal_syment_name (input_bfd, &isym,
+ (char *) NULL);
+ if (name == NULL)
+ return false;
+ indx = _bfd_stringtab_add (finfo->strtab, name, hash, copy);
+ if (indx == (bfd_size_type) -1)
+ return false;
+ isym._n._n_n._n_offset = STRING_SIZE_SIZE + indx;
+ }
+ }
+
+ if (isym.n_sclass != C_BSTAT
+ && isym.n_sclass != C_ESTAT
+ && isym.n_sclass != C_DECL
+ && isym.n_scnum > 0)
+ {
+ isym.n_scnum = (*csectpp)->output_section->target_index;
+ isym.n_value += ((*csectpp)->output_section->vma
+ + (*csectpp)->output_offset
+ - (*csectpp)->vma);
+ }
+
+ /* The value of a C_FILE symbol is the symbol index of the
+ next C_FILE symbol. The value of the last C_FILE symbol
+ is -1. We try to get this right, below, just before we
+ write the symbols out, but in the general case we may
+ have to write the symbol out twice. */
+ if (isym.n_sclass == C_FILE)
+ {
+ if (finfo->last_file_index != -1
+ && finfo->last_file.n_value != (long) output_index)
+ {
+ /* We must correct the value of the last C_FILE entry. */
+ finfo->last_file.n_value = output_index;
+ if ((bfd_size_type) finfo->last_file_index >= syment_base)
+ {
+ /* The last C_FILE symbol is in this input file. */
+ bfd_coff_swap_sym_out (output_bfd,
+ (PTR) &finfo->last_file,
+ (PTR) (finfo->outsyms
+ + ((finfo->last_file_index
+ - syment_base)
+ * osymesz)));
+ }
+ else
+ {
+ /* We have already written out the last C_FILE
+ symbol. We need to write it out again. We
+ borrow *outsym temporarily. */
+ bfd_coff_swap_sym_out (output_bfd,
+ (PTR) &finfo->last_file,
+ (PTR) outsym);
+ if (bfd_seek (output_bfd,
+ (obj_sym_filepos (output_bfd)
+ + finfo->last_file_index * osymesz),
+ SEEK_SET) != 0
+ || (bfd_write (outsym, osymesz, 1, output_bfd)
+ != osymesz))
+ return false;
+ }
+ }
+
+ finfo->last_file_index = output_index;
+ finfo->last_file = isym;
+ }
+
+ /* The value of a C_BINCL or C_EINCL symbol is a file offset
+ into the line numbers. We update the symbol values when
+ we handle the line numbers. */
+ if (isym.n_sclass == C_BINCL
+ || isym.n_sclass == C_EINCL)
+ {
+ isym.n_value = finfo->line_filepos;
+ ++incls;
+ }
+
+ /* Output the symbol. */
+
+ bfd_coff_swap_sym_out (output_bfd, (PTR) &isym, (PTR) outsym);
+
+ *indexp = output_index;
+
+ if (isym.n_sclass == C_EXT)
+ {
+ long indx;
+ struct xcoff_link_hash_entry *h;
+
+ indx = ((esym - (bfd_byte *) obj_coff_external_syms (input_bfd))
+ / isymesz);
+ h = obj_xcoff_sym_hashes (input_bfd)[indx];
+ BFD_ASSERT (h != NULL);
+ h->indx = output_index;
+ }
+
+ /* If this is a symbol in the TOC which we may have merged
+ (class XMC_TC), remember the symbol index of the TOC
+ symbol. */
+ if (isym.n_sclass == C_HIDEXT
+ && aux.x_csect.x_smclas == XMC_TC
+ && *sym_hash != NULL)
+ {
+ BFD_ASSERT (((*sym_hash)->flags & XCOFF_SET_TOC) == 0);
+ BFD_ASSERT ((*sym_hash)->toc_section != NULL);
+ (*sym_hash)->u.toc_indx = output_index;
+ }
+
+ output_index += add;
+ outsym += add * osymesz;
+ }
+
+ esym += add * isymesz;
+ isymp += add;
+ csectpp += add;
+ sym_hash += add;
+ if (debug_index != NULL)
+ debug_index += add;
+ ++indexp;
+ for (--add; add > 0; --add)
+ *indexp++ = -1;
+ }
+
+ /* Fix up the aux entries and the C_BSTAT symbols. This must be
+ done in a separate pass, because we don't know the correct symbol
+ indices until we have already decided which symbols we are going
+ to keep. */
+
+ esym = (bfd_byte *) obj_coff_external_syms (input_bfd);
+ esym_end = esym + obj_raw_syment_count (input_bfd) * isymesz;
+ isymp = finfo->internal_syms;
+ indexp = finfo->sym_indices;
+ csectpp = xcoff_data (input_bfd)->csects;
+ outsym = finfo->outsyms;
+ while (esym < esym_end)
+ {
+ int add;
+
+ add = 1 + isymp->n_numaux;
+
+ if (*indexp < 0)
+ esym += add * isymesz;
+ else
+ {
+ int i;
+
+ if (isymp->n_sclass == C_BSTAT)
+ {
+ struct internal_syment isym;
+ unsigned long indx;
+
+ /* The value of a C_BSTAT symbol is the symbol table
+ index of the containing csect. */
+ bfd_coff_swap_sym_in (output_bfd, (PTR) outsym, (PTR) &isym);
+ indx = isym.n_value;
+ if (indx < obj_raw_syment_count (input_bfd))
+ {
+ long symindx;
+
+ symindx = finfo->sym_indices[indx];
+ if (symindx < 0)
+ isym.n_value = 0;
+ else
+ isym.n_value = symindx;
+ bfd_coff_swap_sym_out (output_bfd, (PTR) &isym,
+ (PTR) outsym);
+ }
+ }
+
+ esym += isymesz;
+ outsym += osymesz;
+
+ for (i = 0; i < isymp->n_numaux && esym < esym_end; i++)
+ {
+ union internal_auxent aux;
+
+ bfd_coff_swap_aux_in (input_bfd, (PTR) esym, isymp->n_type,
+ isymp->n_sclass, i, isymp->n_numaux,
+ (PTR) &aux);
+
+ if (isymp->n_sclass == C_FILE)
+ {
+ /* This is the file name (or some comment put in by
+ the compiler). If it is long, we must put it in
+ the string table. */
+ if (aux.x_file.x_n.x_zeroes == 0
+ && aux.x_file.x_n.x_offset != 0)
+ {
+ const char *filename;
+ bfd_size_type indx;
+
+ BFD_ASSERT (aux.x_file.x_n.x_offset
+ >= STRING_SIZE_SIZE);
+ if (strings == NULL)
+ {
+ strings = _bfd_coff_read_string_table (input_bfd);
+ if (strings == NULL)
+ return false;
+ }
+ filename = strings + aux.x_file.x_n.x_offset;
+ indx = _bfd_stringtab_add (finfo->strtab, filename,
+ hash, copy);
+ if (indx == (bfd_size_type) -1)
+ return false;
+ aux.x_file.x_n.x_offset = STRING_SIZE_SIZE + indx;
+ }
+ }
+ else if ((isymp->n_sclass == C_EXT
+ || isymp->n_sclass == C_HIDEXT)
+ && i + 1 == isymp->n_numaux)
+ {
+ /* We don't support type checking. I don't know if
+ anybody does. */
+ aux.x_csect.x_parmhash = 0;
+ /* I don't think anybody uses these fields, but we'd
+ better clobber them just in case. */
+ aux.x_csect.x_stab = 0;
+ aux.x_csect.x_snstab = 0;
+ if (SMTYP_SMTYP (aux.x_csect.x_smtyp) == XTY_LD)
+ {
+ unsigned long indx;
+
+ indx = aux.x_csect.x_scnlen.l;
+ if (indx < obj_raw_syment_count (input_bfd))
+ {
+ long symindx;
+
+ symindx = finfo->sym_indices[indx];
+ if (symindx < 0)
+ aux.x_sym.x_tagndx.l = 0;
+ else
+ aux.x_sym.x_tagndx.l = symindx;
+ }
+ }
+ }
+ else if (isymp->n_sclass != C_STAT || isymp->n_type != T_NULL)
+ {
+ unsigned long indx;
+
+ if (ISFCN (isymp->n_type)
+ || ISTAG (isymp->n_sclass)
+ || isymp->n_sclass == C_BLOCK
+ || isymp->n_sclass == C_FCN)
+ {
+ indx = aux.x_sym.x_fcnary.x_fcn.x_endndx.l;
+ if (indx > 0
+ && indx < obj_raw_syment_count (input_bfd))
+ {
+ /* We look forward through the symbol for
+ the index of the next symbol we are going
+ to include. I don't know if this is
+ entirely right. */
+ while (finfo->sym_indices[indx] < 0
+ && indx < obj_raw_syment_count (input_bfd))
+ ++indx;
+ if (indx >= obj_raw_syment_count (input_bfd))
+ indx = output_index;
+ else
+ indx = finfo->sym_indices[indx];
+ aux.x_sym.x_fcnary.x_fcn.x_endndx.l = indx;
+ }
+ }
+
+ indx = aux.x_sym.x_tagndx.l;
+ if (indx > 0 && indx < obj_raw_syment_count (input_bfd))
+ {
+ long symindx;
+
+ symindx = finfo->sym_indices[indx];
+ if (symindx < 0)
+ aux.x_sym.x_tagndx.l = 0;
+ else
+ aux.x_sym.x_tagndx.l = symindx;
+ }
+ }
+
+ /* Copy over the line numbers, unless we are stripping
+ them. We do this on a symbol by symbol basis in
+ order to more easily handle garbage collection. */
+ if ((isymp->n_sclass == C_EXT
+ || isymp->n_sclass == C_HIDEXT)
+ && i == 0
+ && isymp->n_numaux > 1
+ && ISFCN (isymp->n_type)
+ && aux.x_sym.x_fcnary.x_fcn.x_lnnoptr != 0)
+ {
+ if (finfo->info->strip != strip_none
+ && finfo->info->strip != strip_some)
+ aux.x_sym.x_fcnary.x_fcn.x_lnnoptr = 0;
+ else
+ {
+ asection *enclosing;
+ unsigned int enc_count;
+ bfd_size_type linoff;
+ struct internal_lineno lin;
+
+ o = *csectpp;
+ enclosing = xcoff_section_data (abfd, o)->enclosing;
+ enc_count = xcoff_section_data (abfd, o)->lineno_count;
+ if (oline != enclosing)
+ {
+ if (bfd_seek (input_bfd,
+ enclosing->line_filepos,
+ SEEK_SET) != 0
+ || (bfd_read (finfo->linenos, linesz,
+ enc_count, input_bfd)
+ != linesz * enc_count))
+ return false;
+ oline = enclosing;
+ }
+
+ linoff = (aux.x_sym.x_fcnary.x_fcn.x_lnnoptr
+ - enclosing->line_filepos);
+
+ bfd_coff_swap_lineno_in (input_bfd,
+ (PTR) (finfo->linenos + linoff),
+ (PTR) &lin);
+ if (lin.l_lnno != 0
+ || ((bfd_size_type) lin.l_addr.l_symndx
+ != ((esym
+ - isymesz
+ - ((bfd_byte *)
+ obj_coff_external_syms (input_bfd)))
+ / isymesz)))
+ aux.x_sym.x_fcnary.x_fcn.x_lnnoptr = 0;
+ else
+ {
+ bfd_byte *linpend, *linp;
+ bfd_vma offset;
+ bfd_size_type count;
+
+ lin.l_addr.l_symndx = *indexp;
+ bfd_coff_swap_lineno_out (output_bfd, (PTR) &lin,
+ (PTR) (finfo->linenos
+ + linoff));
+
+ linpend = (finfo->linenos
+ + enc_count * linesz);
+ offset = (o->output_section->vma
+ + o->output_offset
+ - o->vma);
+ for (linp = finfo->linenos + linoff + linesz;
+ linp < linpend;
+ linp += linesz)
+ {
+ bfd_coff_swap_lineno_in (input_bfd, (PTR) linp,
+ (PTR) &lin);
+ if (lin.l_lnno == 0)
+ break;
+ lin.l_addr.l_paddr += offset;
+ bfd_coff_swap_lineno_out (output_bfd,
+ (PTR) &lin,
+ (PTR) linp);
+ }
+
+ count = (linp - (finfo->linenos + linoff)) / linesz;
+
+ aux.x_sym.x_fcnary.x_fcn.x_lnnoptr =
+ (o->output_section->line_filepos
+ + o->output_section->lineno_count * linesz);
+
+ if (bfd_seek (output_bfd,
+ aux.x_sym.x_fcnary.x_fcn.x_lnnoptr,
+ SEEK_SET) != 0
+ || (bfd_write (finfo->linenos + linoff,
+ linesz, count, output_bfd)
+ != linesz * count))
+ return false;
+
+ o->output_section->lineno_count += count;
+
+ if (incls > 0)
+ {
+ struct internal_syment *iisp, *iispend;
+ long *iindp;
+ bfd_byte *oos;
+ int iiadd;
+
+ /* Update any C_BINCL or C_EINCL symbols
+ that refer to a line number in the
+ range we just output. */
+ iisp = finfo->internal_syms;
+ iispend = (iisp
+ + obj_raw_syment_count (input_bfd));
+ iindp = finfo->sym_indices;
+ oos = finfo->outsyms;
+ while (iisp < iispend)
+ {
+ if (*iindp >= 0
+ && (iisp->n_sclass == C_BINCL
+ || iisp->n_sclass == C_EINCL)
+ && ((bfd_size_type) iisp->n_value
+ >= enclosing->line_filepos + linoff)
+ && ((bfd_size_type) iisp->n_value
+ < (enclosing->line_filepos
+ + enc_count * linesz)))
+ {
+ struct internal_syment iis;
+
+ bfd_coff_swap_sym_in (output_bfd,
+ (PTR) oos,
+ (PTR) &iis);
+ iis.n_value =
+ (iisp->n_value
+ - enclosing->line_filepos
+ - linoff
+ + aux.x_sym.x_fcnary.x_fcn.x_lnnoptr);
+ bfd_coff_swap_sym_out (output_bfd,
+ (PTR) &iis,
+ (PTR) oos);
+ --incls;
+ }
+
+ iiadd = 1 + iisp->n_numaux;
+ if (*iindp >= 0)
+ oos += iiadd * osymesz;
+ iisp += iiadd;
+ iindp += iiadd;
+ }
+ }
+ }
+ }
+ }
+
+ bfd_coff_swap_aux_out (output_bfd, (PTR) &aux, isymp->n_type,
+ isymp->n_sclass, i, isymp->n_numaux,
+ (PTR) outsym);
+ outsym += osymesz;
+ esym += isymesz;
+ }
+ }
+
+ indexp += add;
+ isymp += add;
+ csectpp += add;
+ }
+
+ /* If we swapped out a C_FILE symbol, guess that the next C_FILE
+ symbol will be the first symbol in the next input file. In the
+ normal case, this will save us from writing out the C_FILE symbol
+ again. */
+ if (finfo->last_file_index != -1
+ && (bfd_size_type) finfo->last_file_index >= syment_base)
+ {
+ finfo->last_file.n_value = output_index;
+ bfd_coff_swap_sym_out (output_bfd, (PTR) &finfo->last_file,
+ (PTR) (finfo->outsyms
+ + ((finfo->last_file_index - syment_base)
+ * osymesz)));
+ }
+
+ /* Write the modified symbols to the output file. */
+ if (outsym > finfo->outsyms)
+ {
+ if (bfd_seek (output_bfd,
+ obj_sym_filepos (output_bfd) + syment_base * osymesz,
+ SEEK_SET) != 0
+ || (bfd_write (finfo->outsyms, outsym - finfo->outsyms, 1,
+ output_bfd)
+ != (bfd_size_type) (outsym - finfo->outsyms)))
+ return false;
+
+ BFD_ASSERT ((obj_raw_syment_count (output_bfd)
+ + (outsym - finfo->outsyms) / osymesz)
+ == output_index);
+
+ obj_raw_syment_count (output_bfd) = output_index;
+ }
+
+ /* Don't let the linker relocation routines discard the symbols. */
+ keep_syms = obj_coff_keep_syms (input_bfd);
+ obj_coff_keep_syms (input_bfd) = true;
+
+ /* Relocate the contents of each section. */
+ for (o = input_bfd->sections; o != NULL; o = o->next)
+ {
+ bfd_byte *contents;
+
+ if (! o->linker_mark)
+ {
+ /* This section was omitted from the link. */
+ continue;
+ }
+
+ if ((o->flags & SEC_HAS_CONTENTS) == 0
+ || o->_raw_size == 0
+ || (o->flags & SEC_IN_MEMORY) != 0)
+ continue;
+
+ /* We have set filepos correctly for the sections we created to
+ represent csects, so bfd_get_section_contents should work. */
+ if (coff_section_data (input_bfd, o) != NULL
+ && coff_section_data (input_bfd, o)->contents != NULL)
+ contents = coff_section_data (input_bfd, o)->contents;
+ else
+ {
+ if (! bfd_get_section_contents (input_bfd, o, finfo->contents,
+ (file_ptr) 0, o->_raw_size))
+ return false;
+ contents = finfo->contents;
+ }
+
+ if ((o->flags & SEC_RELOC) != 0)
+ {
+ int target_index;
+ struct internal_reloc *internal_relocs;
+ struct internal_reloc *irel;
+ bfd_vma offset;
+ struct internal_reloc *irelend;
+ struct xcoff_link_hash_entry **rel_hash;
+ long r_symndx;
+
+ /* Read in the relocs. */
+ target_index = o->output_section->target_index;
+ internal_relocs = (xcoff_read_internal_relocs
+ (input_bfd, o, false, finfo->external_relocs,
+ true,
+ (finfo->section_info[target_index].relocs
+ + o->output_section->reloc_count)));
+ if (internal_relocs == NULL)
+ return false;
+
+ /* Call processor specific code to relocate the section
+ contents. */
+ if (! bfd_coff_relocate_section (output_bfd, finfo->info,
+ input_bfd, o,
+ contents,
+ internal_relocs,
+ finfo->internal_syms,
+ xcoff_data (input_bfd)->csects))
+ return false;
+
+ offset = o->output_section->vma + o->output_offset - o->vma;
+ irel = internal_relocs;
+ irelend = irel + o->reloc_count;
+ rel_hash = (finfo->section_info[target_index].rel_hashes
+ + o->output_section->reloc_count);
+ for (; irel < irelend; irel++, rel_hash++)
+ {
+ struct xcoff_link_hash_entry *h = NULL;
+ struct internal_ldrel ldrel;
+ boolean quiet;
+
+ *rel_hash = NULL;
+
+ /* Adjust the reloc address and symbol index. */
+
+ irel->r_vaddr += offset;
+
+ r_symndx = irel->r_symndx;
+
+ if (r_symndx == -1)
+ h = NULL;
+ else
+ h = obj_xcoff_sym_hashes (input_bfd)[r_symndx];
+
+ if (r_symndx != -1 && finfo->info->strip != strip_all)
+ {
+ if (h != NULL
+ && h->smclas != XMC_TD
+ && (irel->r_type == R_TOC
+ || irel->r_type == R_GL
+ || irel->r_type == R_TCL
+ || irel->r_type == R_TRL
+ || irel->r_type == R_TRLA))
+ {
+ /* This is a TOC relative reloc with a symbol
+ attached. The symbol should be the one which
+ this reloc is for. We want to make this
+ reloc against the TOC address of the symbol,
+ not the symbol itself. */
+ BFD_ASSERT (h->toc_section != NULL);
+ BFD_ASSERT ((h->flags & XCOFF_SET_TOC) == 0);
+ if (h->u.toc_indx != -1)
+ irel->r_symndx = h->u.toc_indx;
+ else
+ {
+ struct xcoff_toc_rel_hash *n;
+ struct xcoff_link_section_info *si;
+
+ n = ((struct xcoff_toc_rel_hash *)
+ bfd_alloc (finfo->output_bfd,
+ sizeof (struct xcoff_toc_rel_hash)));
+ if (n == NULL)
+ return false;
+ si = finfo->section_info + target_index;
+ n->next = si->toc_rel_hashes;
+ n->h = h;
+ n->rel = irel;
+ si->toc_rel_hashes = n;
+ }
+ }
+ else if (h != NULL)
+ {
+ /* This is a global symbol. */
+ if (h->indx >= 0)
+ irel->r_symndx = h->indx;
+ else
+ {
+ /* This symbol is being written at the end
+ of the file, and we do not yet know the
+ symbol index. We save the pointer to the
+ hash table entry in the rel_hash list.
+ We set the indx field to -2 to indicate
+ that this symbol must not be stripped. */
+ *rel_hash = h;
+ h->indx = -2;
+ }
+ }
+ else
+ {
+ long indx;
+
+ indx = finfo->sym_indices[r_symndx];
+
+ if (indx == -1)
+ {
+ struct internal_syment *is;
+
+ /* Relocations against a TC0 TOC anchor are
+ automatically transformed to be against
+ the TOC anchor in the output file. */
+ is = finfo->internal_syms + r_symndx;
+ if (is->n_sclass == C_HIDEXT
+ && is->n_numaux > 0)
+ {
+ PTR auxptr;
+ union internal_auxent aux;
+
+ auxptr = ((PTR)
+ (((bfd_byte *)
+ obj_coff_external_syms (input_bfd))
+ + ((r_symndx + is->n_numaux)
+ * isymesz)));
+ bfd_coff_swap_aux_in (input_bfd, auxptr,
+ is->n_type, is->n_sclass,
+ is->n_numaux - 1,
+ is->n_numaux,
+ (PTR) &aux);
+ if (SMTYP_SMTYP (aux.x_csect.x_smtyp) == XTY_SD
+ && aux.x_csect.x_smclas == XMC_TC0)
+ indx = finfo->toc_symindx;
+ }
+ }
+
+ if (indx != -1)
+ irel->r_symndx = indx;
+ else
+ {
+ struct internal_syment *is;
+ const char *name;
+ char buf[SYMNMLEN + 1];
+
+ /* This reloc is against a symbol we are
+ stripping. It would be possible to handle
+ this case, but I don't think it's worth it. */
+ is = finfo->internal_syms + r_symndx;
+
+ name = (_bfd_coff_internal_syment_name
+ (input_bfd, is, buf));
+ if (name == NULL)
+ return false;
+
+ if (! ((*finfo->info->callbacks->unattached_reloc)
+ (finfo->info, name, input_bfd, o,
+ irel->r_vaddr)))
+ return false;
+ }
+ }
+ }
+
+ quiet = false;
+ switch (irel->r_type)
+ {
+ default:
+ if (h == NULL
+ || h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak
+ || h->root.type == bfd_link_hash_common)
+ break;
+ /* Fall through. */
+ case R_POS:
+ case R_NEG:
+ case R_RL:
+ case R_RLA:
+ /* This reloc needs to be copied into the .loader
+ section. */
+ ldrel.l_vaddr = irel->r_vaddr;
+ if (r_symndx == -1)
+ ldrel.l_symndx = -1;
+ else if (h == NULL
+ || (h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak
+ || h->root.type == bfd_link_hash_common))
+ {
+ asection *sec;
+
+ if (h == NULL)
+ sec = xcoff_data (input_bfd)->csects[r_symndx];
+ else if (h->root.type == bfd_link_hash_common)
+ sec = h->root.u.c.p->section;
+ else
+ sec = h->root.u.def.section;
+ sec = sec->output_section;
+
+ if (strcmp (sec->name, ".text") == 0)
+ ldrel.l_symndx = 0;
+ else if (strcmp (sec->name, ".data") == 0)
+ ldrel.l_symndx = 1;
+ else if (strcmp (sec->name, ".bss") == 0)
+ ldrel.l_symndx = 2;
+ else
+ {
+ (*_bfd_error_handler)
+ (_("%s: loader reloc in unrecognized section `%s'"),
+ bfd_get_filename (input_bfd),
+ sec->name);
+ bfd_set_error (bfd_error_nonrepresentable_section);
+ return false;
+ }
+ }
+ else
+ {
+ if (! finfo->info->relocateable
+ && (h->flags & XCOFF_DEF_DYNAMIC) == 0
+ && (h->flags & XCOFF_IMPORT) == 0)
+ {
+ /* We already called the undefined_symbol
+ callback for this relocation, in
+ _bfd_ppc_xcoff_relocate_section. Don't
+ issue any more warnings. */
+ quiet = true;
+ }
+ if (h->ldindx < 0 && ! quiet)
+ {
+ (*_bfd_error_handler)
+ (_("%s: `%s' in loader reloc but not loader sym"),
+ bfd_get_filename (input_bfd),
+ h->root.root.string);
+ bfd_set_error (bfd_error_bad_value);
+ return false;
+ }
+ ldrel.l_symndx = h->ldindx;
+ }
+ ldrel.l_rtype = (irel->r_size << 8) | irel->r_type;
+ ldrel.l_rsecnm = o->output_section->target_index;
+ if (xcoff_hash_table (finfo->info)->textro
+ && strcmp (o->output_section->name, ".text") == 0
+ && ! quiet)
+ {
+ (*_bfd_error_handler)
+ (_("%s: loader reloc in read-only section %s"),
+ bfd_get_filename (input_bfd),
+ bfd_get_section_name (finfo->output_bfd,
+ o->output_section));
+ bfd_set_error (bfd_error_invalid_operation);
+ return false;
+ }
+ xcoff_swap_ldrel_out (output_bfd, &ldrel,
+ finfo->ldrel);
+ BFD_ASSERT (sizeof (struct external_ldrel) == LDRELSZ);
+ ++finfo->ldrel;
+ break;
+
+ case R_TOC:
+ case R_GL:
+ case R_TCL:
+ case R_TRL:
+ case R_TRLA:
+ /* We should never need a .loader reloc for a TOC
+ relative reloc. */
+ break;
+ }
+ }
+
+ o->output_section->reloc_count += o->reloc_count;
+ }
+
+ /* Write out the modified section contents. */
+ if (! bfd_set_section_contents (output_bfd, o->output_section,
+ contents, o->output_offset,
+ (o->_cooked_size != 0
+ ? o->_cooked_size
+ : o->_raw_size)))
+ return false;
+ }
+
+ obj_coff_keep_syms (input_bfd) = keep_syms;
+
+ if (! finfo->info->keep_memory)
+ {
+ if (! _bfd_coff_free_symbols (input_bfd))
+ return false;
+ }
+
+ return true;
+}
+
+#undef N_TMASK
+#undef N_BTSHFT
+
+/* Write out a non-XCOFF global symbol. */
+
+static boolean
+xcoff_write_global_symbol (h, p)
+ struct xcoff_link_hash_entry *h;
+ PTR p;
+{
+ struct xcoff_final_link_info *finfo = (struct xcoff_final_link_info *) p;
+ bfd *output_bfd;
+ bfd_byte *outsym;
+ struct internal_syment isym;
+ union internal_auxent aux;
+
+ output_bfd = finfo->output_bfd;
+ outsym = finfo->outsyms;
+
+ /* If this symbol was garbage collected, just skip it. */
+ if (xcoff_hash_table (finfo->info)->gc
+ && (h->flags & XCOFF_MARK) == 0)
+ return true;
+
+ /* If we need a .loader section entry, write it out. */
+ if (h->ldsym != NULL)
+ {
+ struct internal_ldsym *ldsym;
+ bfd *impbfd;
+
+ ldsym = h->ldsym;
+
+ if (h->root.type == bfd_link_hash_undefined
+ || h->root.type == bfd_link_hash_undefweak)
+ {
+ ldsym->l_value = 0;
+ ldsym->l_scnum = N_UNDEF;
+ ldsym->l_smtype = XTY_ER;
+ impbfd = h->root.u.undef.abfd;
+ }
+ else if (h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak)
+ {
+ asection *sec;
+
+ sec = h->root.u.def.section;
+ ldsym->l_value = (sec->output_section->vma
+ + sec->output_offset
+ + h->root.u.def.value);
+ ldsym->l_scnum = sec->output_section->target_index;
+ ldsym->l_smtype = XTY_SD;
+ impbfd = sec->owner;
+ }
+ else
+ abort ();
+
+ if (((h->flags & XCOFF_DEF_REGULAR) == 0
+ && (h->flags & XCOFF_DEF_DYNAMIC) != 0)
+ || (h->flags & XCOFF_IMPORT) != 0)
+ ldsym->l_smtype |= L_IMPORT;
+ if (((h->flags & XCOFF_DEF_REGULAR) != 0
+ && (h->flags & XCOFF_DEF_DYNAMIC) != 0)
+ || (h->flags & XCOFF_EXPORT) != 0)
+ ldsym->l_smtype |= L_EXPORT;
+ if ((h->flags & XCOFF_ENTRY) != 0)
+ ldsym->l_smtype |= L_ENTRY;
+
+ ldsym->l_smclas = h->smclas;
+
+ if (ldsym->l_ifile == (bfd_size_type) -1)
+ ldsym->l_ifile = 0;
+ else if (ldsym->l_ifile == 0)
+ {
+ if ((ldsym->l_smtype & L_IMPORT) == 0)
+ ldsym->l_ifile = 0;
+ else if (impbfd == NULL)
+ ldsym->l_ifile = 0;
+ else
+ {
+ BFD_ASSERT (impbfd->xvec == output_bfd->xvec);
+ ldsym->l_ifile = xcoff_data (impbfd)->import_file_id;
+ }
+ }
+
+ ldsym->l_parm = 0;
+
+ BFD_ASSERT (h->ldindx >= 0);
+ BFD_ASSERT (LDSYMSZ == sizeof (struct external_ldsym));
+ xcoff_swap_ldsym_out (output_bfd, ldsym, finfo->ldsym + h->ldindx - 3);
+ h->ldsym = NULL;
+ }
+
+ /* If this symbol needs global linkage code, write it out. */
+ if (h->root.type == bfd_link_hash_defined
+ && (h->root.u.def.section
+ == xcoff_hash_table (finfo->info)->linkage_section))
+ {
+ bfd_byte *p;
+ bfd_vma tocoff;
+ unsigned int i;
+
+ p = h->root.u.def.section->contents + h->root.u.def.value;
+
+ /* The first instruction in the global linkage code loads a
+ specific TOC element. */
+ tocoff = (h->descriptor->toc_section->output_section->vma
+ + h->descriptor->toc_section->output_offset
+ - xcoff_data (output_bfd)->toc);
+ if ((h->descriptor->flags & XCOFF_SET_TOC) != 0)
+ tocoff += h->descriptor->u.toc_offset;
+ bfd_put_32 (output_bfd, XCOFF_GLINK_FIRST | (tocoff & 0xffff), p);
+ for (i = 0, p += 4;
+ i < sizeof xcoff_glink_code / sizeof xcoff_glink_code[0];
+ i++, p += 4)
+ bfd_put_32 (output_bfd, xcoff_glink_code[i], p);
+ }
+
+ /* If we created a TOC entry for this symbol, write out the required
+ relocs. */
+ if ((h->flags & XCOFF_SET_TOC) != 0)
+ {
+ asection *tocsec;
+ asection *osec;
+ int oindx;
+ struct internal_reloc *irel;
+ struct internal_ldrel ldrel;
+ struct internal_syment irsym;
+ union internal_auxent iraux;
+
+ tocsec = h->toc_section;
+ osec = tocsec->output_section;
+ oindx = osec->target_index;
+ irel = finfo->section_info[oindx].relocs + osec->reloc_count;
+ irel->r_vaddr = (osec->vma
+ + tocsec->output_offset
+ + h->u.toc_offset);
+ if (h->indx >= 0)
+ irel->r_symndx = h->indx;
+ else
+ {
+ h->indx = -2;
+ irel->r_symndx = obj_raw_syment_count (output_bfd);
+ }
+ irel->r_type = R_POS;
+ irel->r_size = 31;
+ finfo->section_info[oindx].rel_hashes[osec->reloc_count] = NULL;
+ ++osec->reloc_count;
+
+ BFD_ASSERT (h->ldindx >= 0);
+ ldrel.l_vaddr = irel->r_vaddr;
+ ldrel.l_symndx = h->ldindx;
+ ldrel.l_rtype = (31 << 8) | R_POS;
+ ldrel.l_rsecnm = oindx;
+ xcoff_swap_ldrel_out (output_bfd, &ldrel, finfo->ldrel);
+ ++finfo->ldrel;
+
+ /* We need to emit a symbol to define a csect which holds the
+ reloc. */
+ if (finfo->info->strip != strip_all)
+ {
+ if (strlen (h->root.root.string) <= SYMNMLEN)
+ strncpy (irsym._n._n_name, h->root.root.string, SYMNMLEN);
+ else
+ {
+ boolean hash;
+ bfd_size_type indx;
+
+ hash = true;
+ if ((output_bfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
+ hash = false;
+ indx = _bfd_stringtab_add (finfo->strtab, h->root.root.string,
+ hash, false);
+ if (indx == (bfd_size_type) -1)
+ return false;
+ irsym._n._n_n._n_zeroes = 0;
+ irsym._n._n_n._n_offset = STRING_SIZE_SIZE + indx;
+ }
+
+ irsym.n_value = irel->r_vaddr;
+ irsym.n_scnum = osec->target_index;
+ irsym.n_sclass = C_HIDEXT;
+ irsym.n_type = T_NULL;
+ irsym.n_numaux = 1;
+
+ bfd_coff_swap_sym_out (output_bfd, (PTR) &irsym, (PTR) outsym);
+ outsym += bfd_coff_symesz (output_bfd);
+
+ memset (&iraux, 0, sizeof iraux);
+ iraux.x_csect.x_smtyp = XTY_SD;
+ iraux.x_csect.x_scnlen.l = 4;
+ iraux.x_csect.x_smclas = XMC_TC;
+
+ bfd_coff_swap_aux_out (output_bfd, (PTR) &iraux, T_NULL, C_HIDEXT,
+ 0, 1, (PTR) outsym);
+ outsym += bfd_coff_auxesz (output_bfd);
+
+ if (h->indx >= 0)
+ {
+ /* We aren't going to write out the symbols below, so we
+ need to write them out now. */
+ if (bfd_seek (output_bfd,
+ (obj_sym_filepos (output_bfd)
+ + (obj_raw_syment_count (output_bfd)
+ * bfd_coff_symesz (output_bfd))),
+ SEEK_SET) != 0
+ || (bfd_write (finfo->outsyms, outsym - finfo->outsyms, 1,
+ output_bfd)
+ != (bfd_size_type) (outsym - finfo->outsyms)))
+ return false;
+ obj_raw_syment_count (output_bfd) +=
+ (outsym - finfo->outsyms) / bfd_coff_symesz (output_bfd);
+
+ outsym = finfo->outsyms;
+ }
+ }
+ }
+
+ /* If this symbol is a specially defined function descriptor, write
+ it out. The first word is the address of the function code
+ itself, the second word is the address of the TOC, and the third
+ word is zero. */
+ if ((h->flags & XCOFF_DESCRIPTOR) != 0
+ && h->root.type == bfd_link_hash_defined
+ && (h->root.u.def.section
+ == xcoff_hash_table (finfo->info)->descriptor_section))
+ {
+ asection *sec;
+ asection *osec;
+ int oindx;
+ bfd_byte *p;
+ struct xcoff_link_hash_entry *hentry;
+ asection *esec;
+ struct internal_reloc *irel;
+ struct internal_ldrel ldrel;
+ asection *tsec;
+
+ sec = h->root.u.def.section;
+ osec = sec->output_section;
+ oindx = osec->target_index;
+ p = sec->contents + h->root.u.def.value;
+
+ hentry = h->descriptor;
+ BFD_ASSERT (hentry != NULL
+ && (hentry->root.type == bfd_link_hash_defined
+ || hentry->root.type == bfd_link_hash_defweak));
+ esec = hentry->root.u.def.section;
+ bfd_put_32 (output_bfd,
+ (esec->output_section->vma
+ + esec->output_offset
+ + hentry->root.u.def.value),
+ p);
+
+ irel = finfo->section_info[oindx].relocs + osec->reloc_count;
+ irel->r_vaddr = (osec->vma
+ + sec->output_offset
+ + h->root.u.def.value);
+ irel->r_symndx = esec->output_section->target_index;
+ irel->r_type = R_POS;
+ irel->r_size = 31;
+ finfo->section_info[oindx].rel_hashes[osec->reloc_count] = NULL;
+ ++osec->reloc_count;
+
+ ldrel.l_vaddr = irel->r_vaddr;
+ if (strcmp (esec->output_section->name, ".text") == 0)
+ ldrel.l_symndx = 0;
+ else if (strcmp (esec->output_section->name, ".data") == 0)
+ ldrel.l_symndx = 1;
+ else if (strcmp (esec->output_section->name, ".bss") == 0)
+ ldrel.l_symndx = 2;
+ else
+ {
+ (*_bfd_error_handler)
+ (_("%s: loader reloc in unrecognized section `%s'"),
+ bfd_get_filename (output_bfd),
+ esec->output_section->name);
+ bfd_set_error (bfd_error_nonrepresentable_section);
+ return false;
+ }
+ ldrel.l_rtype = (31 << 8) | R_POS;
+ ldrel.l_rsecnm = oindx;
+ xcoff_swap_ldrel_out (output_bfd, &ldrel, finfo->ldrel);
+ ++finfo->ldrel;
+
+ bfd_put_32 (output_bfd, xcoff_data (output_bfd)->toc, p + 4);
+
+ tsec = coff_section_from_bfd_index (output_bfd,
+ xcoff_data (output_bfd)->sntoc);
+
+ ++irel;
+ irel->r_vaddr = (osec->vma
+ + sec->output_offset
+ + h->root.u.def.value
+ + 4);
+ irel->r_symndx = tsec->output_section->target_index;
+ irel->r_type = R_POS;
+ irel->r_size = 31;
+ finfo->section_info[oindx].rel_hashes[osec->reloc_count] = NULL;
+ ++osec->reloc_count;
+
+ ldrel.l_vaddr = irel->r_vaddr;
+ if (strcmp (tsec->output_section->name, ".text") == 0)
+ ldrel.l_symndx = 0;
+ else if (strcmp (tsec->output_section->name, ".data") == 0)
+ ldrel.l_symndx = 1;
+ else if (strcmp (tsec->output_section->name, ".bss") == 0)
+ ldrel.l_symndx = 2;
+ else
+ {
+ (*_bfd_error_handler)
+ (_("%s: loader reloc in unrecognized section `%s'"),
+ bfd_get_filename (output_bfd),
+ tsec->output_section->name);
+ bfd_set_error (bfd_error_nonrepresentable_section);
+ return false;
+ }
+ ldrel.l_rtype = (31 << 8) | R_POS;
+ ldrel.l_rsecnm = oindx;
+ xcoff_swap_ldrel_out (output_bfd, &ldrel, finfo->ldrel);
+ ++finfo->ldrel;
+ }
+
+ if (h->indx >= 0 || finfo->info->strip == strip_all)
+ {
+ BFD_ASSERT (outsym == finfo->outsyms);
+ return true;
+ }
+
+ if (h->indx != -2
+ && (finfo->info->strip == strip_all
+ || (finfo->info->strip == strip_some
+ && (bfd_hash_lookup (finfo->info->keep_hash,
+ h->root.root.string, false, false)
+ == NULL))))
+ {
+ BFD_ASSERT (outsym == finfo->outsyms);
+ return true;
+ }
+
+ if (h->indx != -2
+ && (h->flags & (XCOFF_REF_REGULAR | XCOFF_DEF_REGULAR)) == 0)
+ {
+ BFD_ASSERT (outsym == finfo->outsyms);
+ return true;
+ }
+
+ memset (&aux, 0, sizeof aux);
+
+ h->indx = obj_raw_syment_count (output_bfd);
+
+ if (strlen (h->root.root.string) <= SYMNMLEN)
+ strncpy (isym._n._n_name, h->root.root.string, SYMNMLEN);
+ else
+ {
+ boolean hash;
+ bfd_size_type indx;
+
+ hash = true;
+ if ((output_bfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
+ hash = false;
+ indx = _bfd_stringtab_add (finfo->strtab, h->root.root.string, hash,
+ false);
+ if (indx == (bfd_size_type) -1)
+ return false;
+ isym._n._n_n._n_zeroes = 0;
+ isym._n._n_n._n_offset = STRING_SIZE_SIZE + indx;
+ }
+
+ if (h->root.type == bfd_link_hash_undefined
+ || h->root.type == bfd_link_hash_undefweak)
+ {
+ isym.n_value = 0;
+ isym.n_scnum = N_UNDEF;
+ isym.n_sclass = C_EXT;
+ aux.x_csect.x_smtyp = XTY_ER;
+ }
+ else if ((h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak)
+ && h->smclas == XMC_XO)
+ {
+ BFD_ASSERT (bfd_is_abs_section (h->root.u.def.section));
+ isym.n_value = h->root.u.def.value;
+ isym.n_scnum = N_UNDEF;
+ isym.n_sclass = C_EXT;
+ aux.x_csect.x_smtyp = XTY_ER;
+ }
+ else if (h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak)
+ {
+ struct xcoff_link_size_list *l;
+
+ isym.n_value = (h->root.u.def.section->output_section->vma
+ + h->root.u.def.section->output_offset
+ + h->root.u.def.value);
+ isym.n_scnum = h->root.u.def.section->output_section->target_index;
+ isym.n_sclass = C_HIDEXT;
+ aux.x_csect.x_smtyp = XTY_SD;
+
+ if ((h->flags & XCOFF_HAS_SIZE) != 0)
+ {
+ for (l = xcoff_hash_table (finfo->info)->size_list;
+ l != NULL;
+ l = l->next)
+ {
+ if (l->h == h)
+ {
+ aux.x_csect.x_scnlen.l = l->size;
+ break;
+ }
+ }
+ }
+ }
+ else if (h->root.type == bfd_link_hash_common)
+ {
+ isym.n_value = (h->root.u.c.p->section->output_section->vma
+ + h->root.u.c.p->section->output_offset);
+ isym.n_scnum = h->root.u.c.p->section->output_section->target_index;
+ isym.n_sclass = C_EXT;
+ aux.x_csect.x_smtyp = XTY_CM;
+ aux.x_csect.x_scnlen.l = h->root.u.c.size;
+ }
+ else
+ abort ();
+
+ isym.n_type = T_NULL;
+ isym.n_numaux = 1;
+
+ bfd_coff_swap_sym_out (output_bfd, (PTR) &isym, (PTR) outsym);
+ outsym += bfd_coff_symesz (output_bfd);
+
+ aux.x_csect.x_smclas = h->smclas;
+
+ bfd_coff_swap_aux_out (output_bfd, (PTR) &aux, T_NULL, isym.n_sclass, 0, 1,
+ (PTR) outsym);
+ outsym += bfd_coff_auxesz (output_bfd);
+
+ if ((h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak)
+ && h->smclas != XMC_XO)
+ {
+ /* We just output an SD symbol. Now output an LD symbol. */
+
+ h->indx += 2;
+
+ isym.n_sclass = C_EXT;
+ bfd_coff_swap_sym_out (output_bfd, (PTR) &isym, (PTR) outsym);
+ outsym += bfd_coff_symesz (output_bfd);
+
+ aux.x_csect.x_smtyp = XTY_LD;
+ aux.x_csect.x_scnlen.l = obj_raw_syment_count (output_bfd);
+
+ bfd_coff_swap_aux_out (output_bfd, (PTR) &aux, T_NULL, C_EXT, 0, 1,
+ (PTR) outsym);
+ outsym += bfd_coff_auxesz (output_bfd);
+ }
+
+ if (bfd_seek (output_bfd,
+ (obj_sym_filepos (output_bfd)
+ + (obj_raw_syment_count (output_bfd)
+ * bfd_coff_symesz (output_bfd))),
+ SEEK_SET) != 0
+ || (bfd_write (finfo->outsyms, outsym - finfo->outsyms, 1, output_bfd)
+ != (bfd_size_type) (outsym - finfo->outsyms)))
+ return false;
+ obj_raw_syment_count (output_bfd) +=
+ (outsym - finfo->outsyms) / bfd_coff_symesz (output_bfd);
+
+ return true;
+}
+
+/* Handle a link order which is supposed to generate a reloc. */
+
+static boolean
+xcoff_reloc_link_order (output_bfd, finfo, output_section, link_order)
+ bfd *output_bfd;
+ struct xcoff_final_link_info *finfo;
+ asection *output_section;
+ struct bfd_link_order *link_order;
+{
+ reloc_howto_type *howto;
+ struct xcoff_link_hash_entry *h;
+ asection *hsec;
+ bfd_vma hval;
+ bfd_vma addend;
+ struct internal_reloc *irel;
+ struct xcoff_link_hash_entry **rel_hash_ptr;
+ struct internal_ldrel ldrel;
+
+ if (link_order->type == bfd_section_reloc_link_order)
+ {
+ /* We need to somehow locate a symbol in the right section. The
+ symbol must either have a value of zero, or we must adjust
+ the addend by the value of the symbol. FIXME: Write this
+ when we need it. The old linker couldn't handle this anyhow. */
+ abort ();
+ }
+
+ howto = bfd_reloc_type_lookup (output_bfd, link_order->u.reloc.p->reloc);
+ if (howto == NULL)
+ {
+ bfd_set_error (bfd_error_bad_value);
+ return false;
+ }
+
+ h = ((struct xcoff_link_hash_entry *)
+ bfd_wrapped_link_hash_lookup (output_bfd, finfo->info,
+ link_order->u.reloc.p->u.name,
+ false, false, true));
+ if (h == NULL)
+ {
+ if (! ((*finfo->info->callbacks->unattached_reloc)
+ (finfo->info, link_order->u.reloc.p->u.name, (bfd *) NULL,
+ (asection *) NULL, (bfd_vma) 0)))
+ return false;
+ return true;
+ }
+
+ if (h->root.type == bfd_link_hash_common)
+ {
+ hsec = h->root.u.c.p->section;
+ hval = 0;
+ }
+ else if (h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak)
+ {
+ hsec = h->root.u.def.section;
+ hval = h->root.u.def.value;
+ }
+ else
+ {
+ hsec = NULL;
+ hval = 0;
+ }
+
+ addend = link_order->u.reloc.p->addend;
+ if (hsec != NULL)
+ addend += (hsec->output_section->vma
+ + hsec->output_offset
+ + hval);
+
+ if (addend != 0)
+ {
+ bfd_size_type size;
+ bfd_byte *buf;
+ bfd_reloc_status_type rstat;
+ boolean ok;
+
+ size = bfd_get_reloc_size (howto);
+ buf = (bfd_byte *) bfd_zmalloc (size);
+ if (buf == NULL)
+ return false;
+
+ rstat = _bfd_relocate_contents (howto, output_bfd, addend, buf);
+ switch (rstat)
+ {
+ case bfd_reloc_ok:
+ break;
+ default:
+ case bfd_reloc_outofrange:
+ abort ();
+ case bfd_reloc_overflow:
+ if (! ((*finfo->info->callbacks->reloc_overflow)
+ (finfo->info, link_order->u.reloc.p->u.name,
+ howto->name, addend, (bfd *) NULL, (asection *) NULL,
+ (bfd_vma) 0)))
+ {
+ free (buf);
+ return false;
+ }
+ break;
+ }
+ ok = bfd_set_section_contents (output_bfd, output_section, (PTR) buf,
+ (file_ptr) link_order->offset, size);
+ free (buf);
+ if (! ok)
+ return false;
+ }
+
+ /* Store the reloc information in the right place. It will get
+ swapped and written out at the end of the final_link routine. */
+
+ irel = (finfo->section_info[output_section->target_index].relocs
+ + output_section->reloc_count);
+ rel_hash_ptr = (finfo->section_info[output_section->target_index].rel_hashes
+ + output_section->reloc_count);
+
+ memset (irel, 0, sizeof (struct internal_reloc));
+ *rel_hash_ptr = NULL;
+
+ irel->r_vaddr = output_section->vma + link_order->offset;
+
+ if (h->indx >= 0)
+ irel->r_symndx = h->indx;
+ else
+ {
+ /* Set the index to -2 to force this symbol to get written out. */
+ h->indx = -2;
+ *rel_hash_ptr = h;
+ irel->r_symndx = 0;
+ }
+
+ irel->r_type = howto->type;
+ irel->r_size = howto->bitsize - 1;
+ if (howto->complain_on_overflow == complain_overflow_signed)
+ irel->r_size |= 0x80;
+
+ ++output_section->reloc_count;
+
+ /* Now output the reloc to the .loader section. */
+
+ ldrel.l_vaddr = irel->r_vaddr;
+
+ if (hsec != NULL)
+ {
+ const char *secname;
+
+ secname = hsec->output_section->name;
+
+ if (strcmp (secname, ".text") == 0)
+ ldrel.l_symndx = 0;
+ else if (strcmp (secname, ".data") == 0)
+ ldrel.l_symndx = 1;
+ else if (strcmp (secname, ".bss") == 0)
+ ldrel.l_symndx = 2;
+ else
+ {
+ (*_bfd_error_handler)
+ (_("%s: loader reloc in unrecognized section `%s'"),
+ bfd_get_filename (output_bfd), secname);
+ bfd_set_error (bfd_error_nonrepresentable_section);
+ return false;
+ }
+ }
+ else
+ {
+ if (h->ldindx < 0)
+ {
+ (*_bfd_error_handler)
+ (_("%s: `%s' in loader reloc but not loader sym"),
+ bfd_get_filename (output_bfd),
+ h->root.root.string);
+ bfd_set_error (bfd_error_bad_value);
+ return false;
+ }
+ ldrel.l_symndx = h->ldindx;
+ }
+
+ ldrel.l_rtype = (irel->r_size << 8) | irel->r_type;
+ ldrel.l_rsecnm = output_section->target_index;
+ xcoff_swap_ldrel_out (output_bfd, &ldrel, finfo->ldrel);
+ ++finfo->ldrel;
+
+ return true;
+}
+
+/* Sort relocs by VMA. This is called via qsort. */
+
+static int
+xcoff_sort_relocs (p1, p2)
+ const PTR p1;
+ const PTR p2;
+{
+ const struct internal_reloc *r1 = (const struct internal_reloc *) p1;
+ const struct internal_reloc *r2 = (const struct internal_reloc *) p2;
+
+ if (r1->r_vaddr > r2->r_vaddr)
+ return 1;
+ else if (r1->r_vaddr < r2->r_vaddr)
+ return -1;
+ else
+ return 0;
+}
+
+/* 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. */
+
+boolean
+_bfd_ppc_xcoff_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_reloc_status_type rstat;
+
+ /* 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;
+
+ symndx = rel->r_symndx;
+
+ if (symndx == -1)
+ {
+ h = NULL;
+ sym = NULL;
+ addend = 0;
+ }
+ else
+ {
+ h = obj_xcoff_sym_hashes (input_bfd)[symndx];
+ sym = syms + symndx;
+ addend = - sym->n_value;
+ }
+
+ /* We build the howto information on the fly. */
+
+ howto.type = rel->r_type;
+ howto.rightshift = 0;
+ howto.size = 2;
+ howto.bitsize = (rel->r_size & 0x1f) + 1;
+ howto.pc_relative = false;
+ howto.bitpos = 0;
+ if ((rel->r_size & 0x80) != 0)
+ howto.complain_on_overflow = complain_overflow_signed;
+ else
+ howto.complain_on_overflow = complain_overflow_bitfield;
+ howto.special_function = NULL;
+ howto.name = "internal";
+ howto.partial_inplace = true;
+ if (howto.bitsize == 32)
+ howto.src_mask = howto.dst_mask = 0xffffffff;
+ else
+ {
+ howto.src_mask = howto.dst_mask = (1 << howto.bitsize) - 1;
+ if (howto.bitsize == 16)
+ howto.size = 1;
+ }
+ howto.pcrel_offset = false;
+
+ val = 0;
+
+ if (h == NULL)
+ {
+ asection *sec;
+
+ if (symndx == -1)
+ {
+ sec = bfd_abs_section_ptr;
+ val = 0;
+ }
+ else
+ {
+ 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 (h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak)
+ {
+ asection *sec;
+
+ 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)
+ {
+ asection *sec;
+
+ sec = h->root.u.c.p->section;
+ val = (sec->output_section->vma
+ + sec->output_offset);
+ }
+ else if ((h->flags & XCOFF_DEF_DYNAMIC) != 0
+ || (h->flags & XCOFF_IMPORT) != 0)
+ {
+ /* Every symbol in a shared object is defined somewhere. */
+ val = 0;
+ }
+ else if (! info->relocateable)
+ {
+ if (! ((*info->callbacks->undefined_symbol)
+ (info, h->root.root.string, input_bfd, input_section,
+ rel->r_vaddr - input_section->vma, true)))
+ return false;
+
+ /* Don't try to process the reloc. It can't help, and
+ it may generate another error. */
+ continue;
+ }
+ }
+
+ /* 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. */
+
+ switch (rel->r_type)
+ {
+ case R_RTB:
+ case R_RRTBI:
+ case 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. */
+ default:
+ (*_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;
+ case R_POS:
+ /* Simple positive relocation. */
+ break;
+ case R_NEG:
+ /* Simple negative relocation. */
+ val = - val;
+ break;
+ case R_REL:
+ /* Simple PC relative relocation. */
+ howto.pc_relative = true;
+ break;
+ case 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.
+ */
+ case R_GL:
+ /* Global linkage relocation. The value of this relocation
+ is the address of the entry in the TOC section. */
+ case R_TCL:
+ /* Local object TOC address. I can't figure out the
+ difference between this and case R_GL. */
+ case 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. */
+ case 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. */
+ 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);
+ }
+
+ val = ((val - xcoff_data (output_bfd)->toc)
+ - (sym->n_value - xcoff_data (input_bfd)->toc));
+ addend = 0;
+ break;
+ case R_BA:
+ /* Absolute branch. We don't want to mess with the lower
+ two bits of the instruction. */
+ case 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. */
+ case R_RBA:
+ /* Absolute branch which may be modified to become a
+ relative branch. */
+ case 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. */
+ case 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. */
+ howto.src_mask &= ~3;
+ howto.dst_mask = howto.src_mask;
+ break;
+ case R_BR:
+ /* Relative branch. We don't want to mess with the lower
+ two bits of the instruction. */
+ case 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. */
+ case R_RBR:
+ /* A relative branch which may be modified to become an
+ absolute branch. FIXME: We don't implement this,
+ although we should for symbols of storage mapping class
+ XMC_XO. */
+ howto.pc_relative = true;
+ howto.src_mask &= ~3;
+ howto.dst_mask = howto.src_mask;
+ break;
+ case 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. */
+ break;
+ case 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. */
+ break;
+ }
+
+ /* 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 ((rel->r_type == R_BR || rel->r_type == R_RBR)
+ && h != NULL
+ && h->root.type == bfd_link_hash_defined
+ && (rel->r_vaddr - input_section->vma + 8
+ <= input_section->_cooked_size))
+ {
+ bfd_byte *pnext;
+ unsigned long next;
+
+ pnext = contents + (rel->r_vaddr - input_section->vma) + 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 r1,20(r1) */
+ }
+ else
+ {
+ if (next == 0x80410014) /* lwz r1,20(r1) */
+ bfd_put_32 (input_bfd, 0x60000000, pnext); /* ori r0,r0,0 */
+ }
+ }
+
+ /* A PC relative reloc includes the section address. */
+ if (howto.pc_relative)
+ addend += input_section->vma;
+
+ rstat = _bfd_final_link_relocate (&howto, input_bfd, input_section,
+ contents,
+ rel->r_vaddr - input_section->vma,
+ val, addend);
+
+ switch (rstat)
+ {
+ default:
+ abort ();
+ case bfd_reloc_ok:
+ break;
+ case bfd_reloc_overflow:
+ {
+ const char *name;
+ char buf[SYMNMLEN + 1];
+ char howto_name[10];
+
+ if (symndx == -1)
+ name = "*ABS*";
+ else if (h != NULL)
+ name = h->root.root.string;
+ else
+ {
+ name = _bfd_coff_internal_syment_name (input_bfd, sym, buf);
+ if (name == NULL)
+ return false;
+ }
+ sprintf (howto_name, "0x%02x", rel->r_type);
+
+ if (! ((*info->callbacks->reloc_overflow)
+ (info, name, howto_name, (bfd_vma) 0, input_bfd,
+ input_section, rel->r_vaddr - input_section->vma)))
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
OpenPOWER on IntegriCloud