summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/binutils
diff options
context:
space:
mode:
authorFederico G. Schwindt <fgsch@cvs.openbsd.org>2002-05-13 13:25:59 +0000
committerFederico G. Schwindt <fgsch@cvs.openbsd.org>2002-05-13 13:25:59 +0000
commit0f55f72ef05860bfbd055d0776381ea319b02857 (patch)
treeab0eb23e0943549ab9a20408b5320d6ad373e10c /gnu/usr.bin/binutils
parentf4ec76371a086d48b89738f6a387421a21045ab4 (diff)
Import binutils-2.11.2
- only the binutils package (no gdb here) - don't import libiberty and texinfo, they are elsewhere - remove all .info* generated files
Diffstat (limited to 'gnu/usr.bin/binutils')
-rw-r--r--gnu/usr.bin/binutils/bfd/elf64-hppa.c832
-rw-r--r--gnu/usr.bin/binutils/bfd/elf64-x86-64.c2965
-rw-r--r--gnu/usr.bin/binutils/bfd/elfxx-ia64.c2960
3 files changed, 2506 insertions, 4251 deletions
diff --git a/gnu/usr.bin/binutils/bfd/elf64-hppa.c b/gnu/usr.bin/binutils/bfd/elf64-hppa.c
index 76dcc18b243..4a87358c9df 100644
--- a/gnu/usr.bin/binutils/bfd/elf64-hppa.c
+++ b/gnu/usr.bin/binutils/bfd/elf64-hppa.c
@@ -1,22 +1,21 @@
/* Support for HPPA 64-bit ELF
- Copyright 1999, 2000, 2001, 2002, 2003, 2004
- Free Software Foundation, Inc.
+ Copyright 1999, 2000, 2001 Free Software Foundation, Inc.
- This file is part of BFD, the Binary File Descriptor library.
+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 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.
+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. */
+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 "alloca-conf.h"
#include "bfd.h"
@@ -63,7 +62,7 @@ struct elf64_hppa_dyn_hash_entry
/* The index of the (possibly local) symbol in the input bfd and its
associated BFD. Needed so that we can have relocs against local
symbols in shared libraries. */
- long sym_indx;
+ unsigned long sym_indx;
bfd *owner;
/* Dynamic symbols may need to have two different values. One for
@@ -157,7 +156,7 @@ struct elf64_hppa_link_hash_table
typedef struct bfd_hash_entry *(*new_hash_entry_func)
PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
-static bfd_boolean elf64_hppa_dyn_hash_table_init
+static boolean elf64_hppa_dyn_hash_table_init
PARAMS ((struct elf64_hppa_dyn_hash_table *ht, bfd *abfd,
new_hash_entry_func new));
static struct bfd_hash_entry *elf64_hppa_new_dyn_hash_entry
@@ -167,118 +166,102 @@ static struct bfd_link_hash_table *elf64_hppa_hash_table_create
PARAMS ((bfd *abfd));
static struct elf64_hppa_dyn_hash_entry *elf64_hppa_dyn_hash_lookup
PARAMS ((struct elf64_hppa_dyn_hash_table *table, const char *string,
- bfd_boolean create, bfd_boolean copy));
+ boolean create, boolean copy));
static void elf64_hppa_dyn_hash_traverse
PARAMS ((struct elf64_hppa_dyn_hash_table *table,
- bfd_boolean (*func) (struct elf64_hppa_dyn_hash_entry *, PTR),
+ boolean (*func) (struct elf64_hppa_dyn_hash_entry *, PTR),
PTR info));
static const char *get_dyn_name
- PARAMS ((bfd *, struct elf_link_hash_entry *,
+ PARAMS ((asection *, struct elf_link_hash_entry *,
const Elf_Internal_Rela *, char **, size_t *));
/* This must follow the definitions of the various derived linker
hash tables and shared functions. */
#include "elf-hppa.h"
-static bfd_boolean elf64_hppa_object_p
+static boolean elf64_hppa_object_p
PARAMS ((bfd *));
-static bfd_boolean elf64_hppa_section_from_shdr
- PARAMS ((bfd *, Elf_Internal_Shdr *, const char *));
+static boolean elf64_hppa_section_from_shdr
+ PARAMS ((bfd *, Elf64_Internal_Shdr *, char *));
static void elf64_hppa_post_process_headers
PARAMS ((bfd *, struct bfd_link_info *));
-static bfd_boolean elf64_hppa_create_dynamic_sections
+static boolean elf64_hppa_create_dynamic_sections
PARAMS ((bfd *, struct bfd_link_info *));
-static bfd_boolean elf64_hppa_adjust_dynamic_symbol
+static boolean elf64_hppa_adjust_dynamic_symbol
PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
-static bfd_boolean elf64_hppa_mark_milli_and_exported_functions
- PARAMS ((struct elf_link_hash_entry *, PTR));
-
-static bfd_boolean elf64_hppa_size_dynamic_sections
+static boolean elf64_hppa_size_dynamic_sections
PARAMS ((bfd *, struct bfd_link_info *));
-static bfd_boolean elf64_hppa_link_output_symbol_hook
- PARAMS ((struct bfd_link_info *, const char *, Elf_Internal_Sym *,
- asection *, struct elf_link_hash_entry *));
-
-static bfd_boolean elf64_hppa_finish_dynamic_symbol
+static boolean elf64_hppa_finish_dynamic_symbol
PARAMS ((bfd *, struct bfd_link_info *,
struct elf_link_hash_entry *, Elf_Internal_Sym *));
-static int elf64_hppa_additional_program_headers
- PARAMS ((bfd *));
-
-static bfd_boolean elf64_hppa_modify_segment_map
+static boolean elf64_hppa_finish_dynamic_sections
PARAMS ((bfd *, struct bfd_link_info *));
-static enum elf_reloc_type_class elf64_hppa_reloc_type_class
- PARAMS ((const Elf_Internal_Rela *));
-
-static bfd_boolean elf64_hppa_finish_dynamic_sections
- PARAMS ((bfd *, struct bfd_link_info *));
-
-static bfd_boolean elf64_hppa_check_relocs
+static boolean elf64_hppa_check_relocs
PARAMS ((bfd *, struct bfd_link_info *,
asection *, const Elf_Internal_Rela *));
-static bfd_boolean elf64_hppa_dynamic_symbol_p
+static boolean elf64_hppa_dynamic_symbol_p
PARAMS ((struct elf_link_hash_entry *, struct bfd_link_info *));
-static bfd_boolean elf64_hppa_mark_exported_functions
+static boolean elf64_hppa_mark_exported_functions
PARAMS ((struct elf_link_hash_entry *, PTR));
-static bfd_boolean elf64_hppa_finalize_opd
+static boolean elf64_hppa_finalize_opd
PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
-static bfd_boolean elf64_hppa_finalize_dlt
+static boolean elf64_hppa_finalize_dlt
PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
-static bfd_boolean allocate_global_data_dlt
+static boolean allocate_global_data_dlt
PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
-static bfd_boolean allocate_global_data_plt
+static boolean allocate_global_data_plt
PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
-static bfd_boolean allocate_global_data_stub
+static boolean allocate_global_data_stub
PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
-static bfd_boolean allocate_global_data_opd
+static boolean allocate_global_data_opd
PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
-static bfd_boolean get_reloc_section
+static boolean get_reloc_section
PARAMS ((bfd *, struct elf64_hppa_link_hash_table *, asection *));
-static bfd_boolean count_dyn_reloc
+static boolean count_dyn_reloc
PARAMS ((bfd *, struct elf64_hppa_dyn_hash_entry *,
int, asection *, int, bfd_vma, bfd_vma));
-static bfd_boolean allocate_dynrel_entries
+static boolean allocate_dynrel_entries
PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
-static bfd_boolean elf64_hppa_finalize_dynreloc
+static boolean elf64_hppa_finalize_dynreloc
PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
-static bfd_boolean get_opd
+static boolean get_opd
PARAMS ((bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *));
-static bfd_boolean get_plt
+static boolean get_plt
PARAMS ((bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *));
-static bfd_boolean get_dlt
+static boolean get_dlt
PARAMS ((bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *));
-static bfd_boolean get_stub
+static boolean get_stub
PARAMS ((bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *));
static int elf64_hppa_elf_get_symbol_type
PARAMS ((Elf_Internal_Sym *, int));
-static bfd_boolean
+static boolean
elf64_hppa_dyn_hash_table_init (ht, abfd, new)
struct elf64_hppa_dyn_hash_table *ht;
bfd *abfd ATTRIBUTE_UNUSED;
@@ -326,7 +309,7 @@ elf64_hppa_hash_table_create (abfd)
{
struct elf64_hppa_link_hash_table *ret;
- ret = bfd_zalloc (abfd, (bfd_size_type) sizeof (*ret));
+ ret = bfd_zalloc (abfd, sizeof (*ret));
if (!ret)
return 0;
if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
@@ -348,7 +331,7 @@ static struct elf64_hppa_dyn_hash_entry *
elf64_hppa_dyn_hash_lookup(table, string, create, copy)
struct elf64_hppa_dyn_hash_table *table;
const char *string;
- bfd_boolean create, copy;
+ boolean create, copy;
{
return ((struct elf64_hppa_dyn_hash_entry *)
bfd_hash_lookup (&table->root, string, create, copy));
@@ -359,19 +342,19 @@ elf64_hppa_dyn_hash_lookup(table, string, create, copy)
static void
elf64_hppa_dyn_hash_traverse (table, func, info)
struct elf64_hppa_dyn_hash_table *table;
- bfd_boolean (*func) PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
+ boolean (*func) PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
PTR info;
{
(bfd_hash_traverse
(&table->root,
- (bfd_boolean (*) PARAMS ((struct bfd_hash_entry *, PTR))) func,
+ (boolean (*) PARAMS ((struct bfd_hash_entry *, PTR))) func,
info));
}
/* Return nonzero if ABFD represents a PA2.0 ELF64 file.
Additionally we set the default architecture and machine. */
-static bfd_boolean
+static boolean
elf64_hppa_object_p (abfd)
bfd *abfd;
{
@@ -381,16 +364,13 @@ elf64_hppa_object_p (abfd)
i_ehdrp = elf_elfheader (abfd);
if (strcmp (bfd_get_target (abfd), "elf64-hppa-linux") == 0)
{
- /* GCC on hppa-linux produces binaries with OSABI=Linux,
- but the kernel produces corefiles with OSABI=SysV. */
- if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_LINUX &&
- i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_NONE) /* aka SYSV */
- return FALSE;
+ if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_LINUX)
+ return false;
}
else
{
if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_HPUX)
- return FALSE;
+ return false;
}
flags = i_ehdrp->e_flags;
@@ -406,16 +386,16 @@ elf64_hppa_object_p (abfd)
return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 25);
}
/* Don't be fussy. */
- return TRUE;
+ return true;
}
/* Given section type (hdr->sh_type), return a boolean indicating
whether or not the section is an elf64-hppa specific section. */
-static bfd_boolean
+static boolean
elf64_hppa_section_from_shdr (abfd, hdr, name)
bfd *abfd;
- Elf_Internal_Shdr *hdr;
- const char *name;
+ Elf64_Internal_Shdr *hdr;
+ char *name;
{
asection *newsect;
@@ -423,23 +403,23 @@ elf64_hppa_section_from_shdr (abfd, hdr, name)
{
case SHT_PARISC_EXT:
if (strcmp (name, ".PARISC.archext") != 0)
- return FALSE;
+ return false;
break;
case SHT_PARISC_UNWIND:
if (strcmp (name, ".PARISC.unwind") != 0)
- return FALSE;
+ return false;
break;
case SHT_PARISC_DOC:
case SHT_PARISC_ANNOT:
default:
- return FALSE;
+ return false;
}
if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
- return FALSE;
+ return false;
newsect = hdr->bfd_section;
- return TRUE;
+ return true;
}
/* Construct a string for use in the elf64_hppa_dyn_hash_table. The
@@ -447,14 +427,13 @@ elf64_hppa_section_from_shdr (abfd, hdr, name)
allocate memory as necessary, possibly reusing PBUF/PLEN. */
static const char *
-get_dyn_name (abfd, h, rel, pbuf, plen)
- bfd *abfd;
+get_dyn_name (sec, h, rel, pbuf, plen)
+ asection *sec;
struct elf_link_hash_entry *h;
const Elf_Internal_Rela *rel;
char **pbuf;
size_t *plen;
{
- asection *sec = abfd->sections;
size_t nlen, tlen;
char *buf;
size_t len;
@@ -504,7 +483,7 @@ get_dyn_name (abfd, h, rel, pbuf, plen)
/* SEC is a section containing relocs for an input BFD when linking; return
a suitable section for holding relocs in the output BFD for a link. */
-static bfd_boolean
+static boolean
get_reloc_section (abfd, hppa_info, sec)
bfd *abfd;
struct elf64_hppa_link_hash_table *hppa_info;
@@ -518,7 +497,7 @@ get_reloc_section (abfd, hppa_info, sec)
(abfd, elf_elfheader(abfd)->e_shstrndx,
elf_section_data(sec)->rel_hdr.sh_name));
if (srel_name == NULL)
- return FALSE;
+ return false;
BFD_ASSERT ((strncmp (srel_name, ".rela", 5) == 0
&& strcmp (bfd_get_section_name (abfd, sec),
@@ -544,11 +523,11 @@ get_reloc_section (abfd, hppa_info, sec)
| SEC_LINKER_CREATED
| SEC_READONLY))
|| !bfd_set_section_alignment (dynobj, srel, 3))
- return FALSE;
+ return false;
}
hppa_info->other_rel_sec = srel;
- return TRUE;
+ return true;
}
/* Add a new entry to the list of dynamic relocations against DYN_H.
@@ -557,7 +536,7 @@ get_reloc_section (abfd, hppa_info, sec)
particular symbol so that we can create FPTR relocations in the
output file. */
-static bfd_boolean
+static boolean
count_dyn_reloc (abfd, dyn_h, type, sec, sec_symndx, offset, addend)
bfd *abfd;
struct elf64_hppa_dyn_hash_entry *dyn_h;
@@ -570,9 +549,9 @@ count_dyn_reloc (abfd, dyn_h, type, sec, sec_symndx, offset, addend)
struct elf64_hppa_dyn_reloc_entry *rent;
rent = (struct elf64_hppa_dyn_reloc_entry *)
- bfd_alloc (abfd, (bfd_size_type) sizeof (*rent));
+ bfd_alloc (abfd, sizeof (*rent));
if (!rent)
- return FALSE;
+ return false;
rent->next = dyn_h->reloc_entries;
rent->type = type;
@@ -582,13 +561,13 @@ count_dyn_reloc (abfd, dyn_h, type, sec, sec_symndx, offset, addend)
rent->addend = addend;
dyn_h->reloc_entries = rent;
- return TRUE;
+ return true;
}
/* Scan the RELOCS and record the type of dynamic entries that each
referenced symbol needs. */
-static bfd_boolean
+static boolean
elf64_hppa_check_relocs (abfd, info, sec, relocs)
bfd *abfd;
struct bfd_link_info *info;
@@ -604,30 +583,29 @@ elf64_hppa_check_relocs (abfd, info, sec, relocs)
size_t buf_len;
int sec_symndx;
- if (info->relocatable)
- return TRUE;
+ if (info->relocateable)
+ return true;
/* If this is the first dynamic object found in the link, create
the special sections required for dynamic linking. */
if (! elf_hash_table (info)->dynamic_sections_created)
{
- if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
- return FALSE;
+ if (! bfd_elf64_link_create_dynamic_sections (abfd, info))
+ return false;
}
hppa_info = elf64_hppa_hash_table (info);
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
/* If necessary, build a new table holding section symbols indices
- for this BFD. */
+ for this BFD. This is disgusting. */
if (info->shared && hppa_info->section_syms_bfd != abfd)
{
unsigned long i;
- unsigned int highest_shndx;
- Elf_Internal_Sym *local_syms = NULL;
- Elf_Internal_Sym *isym, *isymend;
- bfd_size_type amt;
+ int highest_shndx;
+ Elf_Internal_Sym *local_syms, *isym;
+ Elf64_External_Sym *ext_syms, *esym;
/* We're done with the old cache of section index to section symbol
index information. Free it.
@@ -637,54 +615,65 @@ elf64_hppa_check_relocs (abfd, info, sec, relocs)
if (hppa_info->section_syms)
free (hppa_info->section_syms);
- /* Read this BFD's local symbols. */
- if (symtab_hdr->sh_info != 0)
+ /* Allocate memory for the internal and external symbols. */
+ local_syms
+ = (Elf_Internal_Sym *) bfd_malloc (symtab_hdr->sh_info
+ * sizeof (Elf_Internal_Sym));
+ if (local_syms == NULL)
+ return false;
+
+ ext_syms
+ = (Elf64_External_Sym *) bfd_malloc (symtab_hdr->sh_info
+ * sizeof (Elf64_External_Sym));
+ if (ext_syms == NULL)
{
- local_syms = (Elf_Internal_Sym *) symtab_hdr->contents;
- if (local_syms == NULL)
- local_syms = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- symtab_hdr->sh_info, 0,
- NULL, NULL, NULL);
- if (local_syms == NULL)
- return FALSE;
+ free (local_syms);
+ return false;
}
- /* Record the highest section index referenced by the local symbols. */
+ /* Read in the local symbols. */
+ if (bfd_seek (abfd, symtab_hdr->sh_offset, SEEK_SET) != 0
+ || bfd_read (ext_syms, 1,
+ (symtab_hdr->sh_info
+ * sizeof (Elf64_External_Sym)), abfd)
+ != (symtab_hdr->sh_info * sizeof (Elf64_External_Sym)))
+ {
+ free (local_syms);
+ free (ext_syms);
+ return false;
+ }
+
+ /* Swap in the local symbols, also record the highest section index
+ referenced by the local symbols. */
+ isym = local_syms;
+ esym = ext_syms;
highest_shndx = 0;
- isymend = local_syms + symtab_hdr->sh_info;
- for (isym = local_syms; isym < isymend; isym++)
+ for (i = 0; i < symtab_hdr->sh_info; i++, esym++, isym++)
{
+ bfd_elf64_swap_symbol_in (abfd, esym, isym);
if (isym->st_shndx > highest_shndx)
highest_shndx = isym->st_shndx;
}
+ /* Now we can free the external symbols. */
+ free (ext_syms);
+
/* Allocate an array to hold the section index to section symbol index
mapping. Bump by one since we start counting at zero. */
highest_shndx++;
- amt = highest_shndx;
- amt *= sizeof (int);
- hppa_info->section_syms = (int *) bfd_malloc (amt);
+ hppa_info->section_syms = (int *) bfd_malloc (highest_shndx
+ * sizeof (int));
/* Now walk the local symbols again. If we find a section symbol,
record the index of the symbol into the section_syms array. */
- for (i = 0, isym = local_syms; isym < isymend; i++, isym++)
+ for (isym = local_syms, i = 0; i < symtab_hdr->sh_info; i++, isym++)
{
if (ELF_ST_TYPE (isym->st_info) == STT_SECTION)
hppa_info->section_syms[isym->st_shndx] = i;
}
- /* We are finished with the local symbols. */
- if (local_syms != NULL
- && symtab_hdr->contents != (unsigned char *) local_syms)
- {
- if (! info->keep_memory)
- free (local_syms);
- else
- {
- /* Cache the symbols for elf_link_input_bfd. */
- symtab_hdr->contents = (unsigned char *) local_syms;
- }
- }
+ /* We are finished with the local symbols. Get rid of them. */
+ free (local_syms);
/* Record which BFD we built the section_syms mapping for. */
hppa_info->section_syms_bfd = abfd;
@@ -701,7 +690,7 @@ elf64_hppa_check_relocs (abfd, info, sec, relocs)
/* If we did not find a section symbol for this section, then
something went terribly wrong above. */
if (sec_symndx == -1)
- return FALSE;
+ return false;
sec_symndx = hppa_info->section_syms[sec_symndx];
}
@@ -715,21 +704,20 @@ elf64_hppa_check_relocs (abfd, info, sec, relocs)
relend = relocs + sec->reloc_count;
for (rel = relocs; rel < relend; ++rel)
{
- enum
- {
- NEED_DLT = 1,
- NEED_PLT = 2,
- NEED_STUB = 4,
- NEED_OPD = 8,
- NEED_DYNREL = 16,
- };
+ enum {
+ NEED_DLT = 1,
+ NEED_PLT = 2,
+ NEED_STUB = 4,
+ NEED_OPD = 8,
+ NEED_DYNREL = 16,
+ };
struct elf_link_hash_entry *h = NULL;
unsigned long r_symndx = ELF64_R_SYM (rel->r_info);
struct elf64_hppa_dyn_hash_entry *dyn_h;
int need_entry;
const char *addr_name;
- bfd_boolean maybe_dynamic;
+ boolean maybe_dynamic;
int dynrel_type = R_PARISC_NONE;
static reloc_howto_type *howto;
@@ -750,12 +738,11 @@ elf64_hppa_check_relocs (abfd, info, sec, relocs)
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 || info->unresolved_syms_in_shared_libs == RM_IGNORE))
+ 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;
+ maybe_dynamic = true;
howto = elf_hppa_howto_table + ELF64_R_TYPE (rel->r_info);
need_entry = 0;
@@ -860,11 +847,11 @@ elf64_hppa_check_relocs (abfd, info, sec, relocs)
continue;
/* Collect a canonical name for this address. */
- addr_name = get_dyn_name (abfd, h, rel, &buf, &buf_len);
+ addr_name = get_dyn_name (sec, h, rel, &buf, &buf_len);
/* Collect the canonical entry data for this address. */
dyn_h = elf64_hppa_dyn_hash_lookup (&hppa_info->dyn_hash_table,
- addr_name, TRUE, TRUE);
+ addr_name, true, true);
BFD_ASSERT (dyn_h);
/* Stash away enough information to be able to find this symbol
@@ -933,20 +920,20 @@ elf64_hppa_check_relocs (abfd, info, sec, relocs)
section symbol for this section ends up in the dynamic
symbol table. */
if (info->shared && dynrel_type == R_PARISC_FPTR64
- && ! (bfd_elf_link_record_local_dynamic_symbol
+ && ! (_bfd_elf64_link_record_local_dynamic_symbol
(info, abfd, sec_symndx)))
- return FALSE;
+ return false;
}
}
if (buf)
free (buf);
- return TRUE;
+ return true;
err_out:
if (buf)
free (buf);
- return FALSE;
+ return false;
}
struct elf64_hppa_allocate_data
@@ -957,30 +944,41 @@ struct elf64_hppa_allocate_data
/* Should we do dynamic things to this symbol? */
-static bfd_boolean
+static boolean
elf64_hppa_dynamic_symbol_p (h, info)
struct elf_link_hash_entry *h;
struct bfd_link_info *info;
{
- /* ??? What, if anything, needs to happen wrt STV_PROTECTED symbols
- and relocations that retrieve a function descriptor? Assume the
- worst for now. */
- if (_bfd_elf_dynamic_symbol_p (h, info, 1))
- {
- /* ??? Why is this here and not elsewhere is_local_label_name. */
- if (h->root.root.string[0] == '$' && h->root.root.string[1] == '$')
- return FALSE;
+ if (h == NULL)
+ return false;
- return TRUE;
- }
- else
- 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;
+
+ if (h->root.type == bfd_link_hash_undefweak
+ || h->root.type == bfd_link_hash_defweak)
+ return true;
+
+ if (h->root.root.string[0] == '$' && h->root.root.string[1] == '$')
+ return false;
+
+ 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;
}
-/* Mark all functions exported by this file so that we can later allocate
+/* Mark all funtions exported by this file so that we can later allocate
entries in .opd for them. */
-static bfd_boolean
+static boolean
elf64_hppa_mark_exported_functions (h, data)
struct elf_link_hash_entry *h;
PTR data;
@@ -990,9 +988,6 @@ elf64_hppa_mark_exported_functions (h, data)
hppa_info = elf64_hppa_hash_table (info);
- if (h->root.type == bfd_link_hash_warning)
- h = (struct elf_link_hash_entry *) h->root.u.i.link;
-
if (h
&& (h->root.type == bfd_link_hash_defined
|| h->root.type == bfd_link_hash_defweak)
@@ -1003,13 +998,13 @@ elf64_hppa_mark_exported_functions (h, data)
/* Add this symbol to the PA64 linker hash table. */
dyn_h = elf64_hppa_dyn_hash_lookup (&hppa_info->dyn_hash_table,
- h->root.root.string, TRUE, TRUE);
+ h->root.root.string, true, true);
BFD_ASSERT (dyn_h);
dyn_h->h = h;
if (! hppa_info->opd_sec
&& ! get_opd (hppa_info->root.dynobj, info, hppa_info))
- return FALSE;
+ return false;
dyn_h->want_opd = 1;
/* Put a flag here for output_symbol_hook. */
@@ -1017,12 +1012,12 @@ elf64_hppa_mark_exported_functions (h, data)
h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
}
- return TRUE;
+ return true;
}
/* Allocate space for a DLT entry. */
-static bfd_boolean
+static boolean
allocate_global_data_dlt (dyn_h, data)
struct elf64_hppa_dyn_hash_entry *dyn_h;
PTR data;
@@ -1039,26 +1034,26 @@ allocate_global_data_dlt (dyn_h, data)
table since we might need to create a dynamic relocation
against it. */
if (! h
- || (h->dynindx == -1 && h->type != STT_PARISC_MILLI))
+ || (h && h->dynindx == -1))
{
bfd *owner;
owner = (h ? h->root.u.def.section->owner : dyn_h->owner);
- if (! (bfd_elf_link_record_local_dynamic_symbol
- (x->info, owner, dyn_h->sym_indx)))
- return FALSE;
+ if (!_bfd_elf64_link_record_local_dynamic_symbol
+ (x->info, owner, dyn_h->sym_indx))
+ return false;
}
}
dyn_h->dlt_offset = x->ofs;
x->ofs += DLT_ENTRY_SIZE;
}
- return TRUE;
+ return true;
}
/* Allocate space for a DLT.PLT entry. */
-static bfd_boolean
+static boolean
allocate_global_data_plt (dyn_h, data)
struct elf64_hppa_dyn_hash_entry *dyn_h;
PTR data;
@@ -1079,12 +1074,12 @@ allocate_global_data_plt (dyn_h, data)
else
dyn_h->want_plt = 0;
- return TRUE;
+ return true;
}
/* Allocate space for a STUB entry. */
-static bfd_boolean
+static boolean
allocate_global_data_stub (dyn_h, data)
struct elf64_hppa_dyn_hash_entry *dyn_h;
PTR data;
@@ -1102,12 +1097,12 @@ allocate_global_data_stub (dyn_h, data)
}
else
dyn_h->want_stub = 0;
- return TRUE;
+ return true;
}
/* Allocate space for a FPTR entry. */
-static bfd_boolean
+static boolean
allocate_global_data_opd (dyn_h, data)
struct elf64_hppa_dyn_hash_entry *dyn_h;
PTR data;
@@ -1125,8 +1120,7 @@ allocate_global_data_opd (dyn_h, data)
/* We never need an opd entry for a symbol which is not
defined by this output file. */
- if (h && (h->root.type == bfd_link_hash_undefined
- || h->root.u.def.section->output_section == NULL))
+ if (h && h->root.type == bfd_link_hash_undefined)
dyn_h->want_opd = 0;
/* If we are creating a shared library, took the address of a local
@@ -1134,9 +1128,10 @@ allocate_global_data_opd (dyn_h, data)
we have to create an opd descriptor. */
else if (x->info->shared
|| h == NULL
- || (h->dynindx == -1 && h->type != STT_PARISC_MILLI)
- || (h->root.type == bfd_link_hash_defined
- || h->root.type == bfd_link_hash_defweak))
+ || h->dynindx == -1
+ || ((h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak)
+ && h->root.u.def.section->output_section != NULL))
{
/* If we are creating a shared library, then we will have to
create a runtime relocation for the symbol to properly
@@ -1148,9 +1143,9 @@ allocate_global_data_opd (dyn_h, data)
bfd *owner;
owner = (h ? h->root.u.def.section->owner : dyn_h->owner);
- if (!bfd_elf_link_record_local_dynamic_symbol
+ if (!_bfd_elf64_link_record_local_dynamic_symbol
(x->info, owner, dyn_h->sym_indx))
- return FALSE;
+ return false;
}
/* This may not be necessary or desirable anymore now that
@@ -1168,14 +1163,14 @@ allocate_global_data_opd (dyn_h, data)
strcpy (new_name + 1, h->root.root.string);
nh = elf_link_hash_lookup (elf_hash_table (x->info),
- new_name, TRUE, TRUE, TRUE);
+ new_name, true, true, true);
nh->root.type = h->root.type;
nh->root.u.def.value = h->root.u.def.value;
nh->root.u.def.section = h->root.u.def.section;
- if (! bfd_elf_link_record_dynamic_symbol (x->info, nh))
- return FALSE;
+ if (! bfd_elf64_link_record_dynamic_symbol (x->info, nh))
+ return false;
}
dyn_h->opd_offset = x->ofs;
@@ -1186,7 +1181,7 @@ allocate_global_data_opd (dyn_h, data)
else
dyn_h->want_opd = 0;
}
- return TRUE;
+ return true;
}
/* HP requires the EI_OSABI field to be filled in. The assignment to
@@ -1213,11 +1208,11 @@ elf64_hppa_post_process_headers (abfd, link_info)
}
/* Create function descriptor section (.opd). This section is called .opd
- because it contains "official procedure descriptors". The "official"
+ 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 bfd_boolean
+static boolean
get_opd (abfd, info, hppa_info)
bfd *abfd;
struct bfd_link_info *info ATTRIBUTE_UNUSED;
@@ -1244,18 +1239,18 @@ get_opd (abfd, info, hppa_info)
|| !bfd_set_section_alignment (abfd, opd, 3))
{
BFD_ASSERT (0);
- return FALSE;
+ return false;
}
hppa_info->opd_sec = opd;
}
- return TRUE;
+ return true;
}
/* Create the PLT section. */
-static bfd_boolean
+static boolean
get_plt (abfd, info, hppa_info)
bfd *abfd;
struct bfd_link_info *info ATTRIBUTE_UNUSED;
@@ -1282,18 +1277,18 @@ get_plt (abfd, info, hppa_info)
|| !bfd_set_section_alignment (abfd, plt, 3))
{
BFD_ASSERT (0);
- return FALSE;
+ return false;
}
hppa_info->plt_sec = plt;
}
- return TRUE;
+ return true;
}
/* Create the DLT section. */
-static bfd_boolean
+static boolean
get_dlt (abfd, info, hppa_info)
bfd *abfd;
struct bfd_link_info *info ATTRIBUTE_UNUSED;
@@ -1320,18 +1315,18 @@ get_dlt (abfd, info, hppa_info)
|| !bfd_set_section_alignment (abfd, dlt, 3))
{
BFD_ASSERT (0);
- return FALSE;
+ return false;
}
hppa_info->dlt_sec = dlt;
}
- return TRUE;
+ return true;
}
/* Create the stubs section. */
-static bfd_boolean
+static boolean
get_stub (abfd, info, hppa_info)
bfd *abfd;
struct bfd_link_info *info ATTRIBUTE_UNUSED;
@@ -1359,13 +1354,13 @@ get_stub (abfd, info, hppa_info)
|| !bfd_set_section_alignment (abfd, stub, 3))
{
BFD_ASSERT (0);
- return FALSE;
+ return false;
}
hppa_info->stub_sec = stub;
}
- return TRUE;
+ return true;
}
/* Create sections necessary for dynamic linking. This is only a rough
@@ -1406,7 +1401,7 @@ get_stub (abfd, info, hppa_info)
.rela.opd:
EPLT relocations for symbols exported from shared libraries. */
-static bfd_boolean
+static boolean
elf64_hppa_create_dynamic_sections (abfd, info)
bfd *abfd;
struct bfd_link_info *info;
@@ -1414,16 +1409,16 @@ elf64_hppa_create_dynamic_sections (abfd, info)
asection *s;
if (! get_stub (abfd, info, elf64_hppa_hash_table (info)))
- return FALSE;
+ return false;
if (! get_dlt (abfd, info, elf64_hppa_hash_table (info)))
- return FALSE;
+ return false;
if (! get_plt (abfd, info, elf64_hppa_hash_table (info)))
- return FALSE;
+ return false;
if (! get_opd (abfd, info, elf64_hppa_hash_table (info)))
- return FALSE;
+ return false;
s = bfd_make_section(abfd, ".rela.dlt");
if (s == NULL
@@ -1433,7 +1428,7 @@ elf64_hppa_create_dynamic_sections (abfd, info)
| SEC_READONLY
| SEC_LINKER_CREATED))
|| !bfd_set_section_alignment (abfd, s, 3))
- return FALSE;
+ return false;
elf64_hppa_hash_table (info)->dlt_rel_sec = s;
s = bfd_make_section(abfd, ".rela.plt");
@@ -1444,7 +1439,7 @@ elf64_hppa_create_dynamic_sections (abfd, info)
| SEC_READONLY
| SEC_LINKER_CREATED))
|| !bfd_set_section_alignment (abfd, s, 3))
- return FALSE;
+ return false;
elf64_hppa_hash_table (info)->plt_rel_sec = s;
s = bfd_make_section(abfd, ".rela.data");
@@ -1455,7 +1450,7 @@ elf64_hppa_create_dynamic_sections (abfd, info)
| SEC_READONLY
| SEC_LINKER_CREATED))
|| !bfd_set_section_alignment (abfd, s, 3))
- return FALSE;
+ return false;
elf64_hppa_hash_table (info)->other_rel_sec = s;
s = bfd_make_section(abfd, ".rela.opd");
@@ -1466,16 +1461,16 @@ elf64_hppa_create_dynamic_sections (abfd, info)
| SEC_READONLY
| SEC_LINKER_CREATED))
|| !bfd_set_section_alignment (abfd, s, 3))
- return FALSE;
+ return false;
elf64_hppa_hash_table (info)->opd_rel_sec = s;
- return TRUE;
+ return true;
}
/* Allocate dynamic relocations for those symbols that turned out
to be dynamic. */
-static bfd_boolean
+static boolean
allocate_dynrel_entries (dyn_h, data)
struct elf64_hppa_dyn_hash_entry *dyn_h;
PTR data;
@@ -1483,7 +1478,7 @@ allocate_dynrel_entries (dyn_h, data)
struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data;
struct elf64_hppa_link_hash_table *hppa_info;
struct elf64_hppa_dyn_reloc_entry *rent;
- bfd_boolean dynamic_symbol, shared;
+ boolean dynamic_symbol, shared;
hppa_info = elf64_hppa_hash_table (x->info);
dynamic_symbol = elf64_hppa_dynamic_symbol_p (dyn_h->h, x->info);
@@ -1492,27 +1487,31 @@ allocate_dynrel_entries (dyn_h, data)
/* We may need to allocate relocations for a non-dynamic symbol
when creating a shared library. */
if (!dynamic_symbol && !shared)
- return TRUE;
+ return true;
/* Take care of the normal data relocations. */
for (rent = dyn_h->reloc_entries; rent; rent = rent->next)
{
- /* Allocate one iff we are building a shared library, the relocation
- isn't a R_PARISC_FPTR64, or we don't want an opd entry. */
- if (!shared && rent->type == R_PARISC_FPTR64 && dyn_h->want_opd)
- continue;
-
+ switch (rent->type)
+ {
+ case R_PARISC_FPTR64:
+ /* Allocate one iff we are not building a shared library and
+ !want_opd, which by this point will be true only if we're
+ actually allocating one statically in the main executable. */
+ if (!x->info->shared && dyn_h->want_opd)
+ continue;
+ break;
+ }
hppa_info->other_rel_sec->_raw_size += sizeof (Elf64_External_Rela);
/* Make sure this symbol gets into the dynamic symbol table if it is
not already recorded. ?!? This should not be in the loop since
the symbol need only be added once. */
- if (dyn_h->h == 0
- || (dyn_h->h->dynindx == -1 && dyn_h->h->type != STT_PARISC_MILLI))
- if (!bfd_elf_link_record_local_dynamic_symbol
+ if (dyn_h->h == 0 || dyn_h->h->dynindx == -1)
+ if (!_bfd_elf64_link_record_local_dynamic_symbol
(x->info, rent->sec->owner, dyn_h->sym_indx))
- return FALSE;
+ return false;
}
/* Take care of the GOT and PLT relocations. */
@@ -1541,13 +1540,13 @@ allocate_dynrel_entries (dyn_h, data)
hppa_info->plt_rel_sec->_raw_size += t;
}
- return TRUE;
+ return true;
}
/* Adjust a symbol defined by a dynamic object and referenced by a
regular object. */
-static bfd_boolean
+static boolean
elf64_hppa_adjust_dynamic_symbol (info, h)
struct bfd_link_info *info ATTRIBUTE_UNUSED;
struct elf_link_hash_entry *h;
@@ -1564,7 +1563,7 @@ elf64_hppa_adjust_dynamic_symbol (info, h)
|| 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;
+ return true;
}
/* If this is a reference to a symbol defined by a dynamic object which
@@ -1574,52 +1573,22 @@ elf64_hppa_adjust_dynamic_symbol (info, h)
But PA64 code is canonically PIC, so as a rule we can avoid this sort
of hackery. */
- return TRUE;
-}
-
-/* This function is called via elf_link_hash_traverse to mark millicode
- symbols with a dynindx of -1 and to remove the string table reference
- from the dynamic symbol table. If the symbol is not a millicode symbol,
- elf64_hppa_mark_exported_functions is called. */
-
-static bfd_boolean
-elf64_hppa_mark_milli_and_exported_functions (h, data)
- struct elf_link_hash_entry *h;
- PTR data;
-{
- struct bfd_link_info *info = (struct bfd_link_info *)data;
- struct elf_link_hash_entry *elf = h;
-
- if (elf->root.type == bfd_link_hash_warning)
- elf = (struct elf_link_hash_entry *) elf->root.u.i.link;
-
- if (elf->type == STT_PARISC_MILLI)
- {
- if (elf->dynindx != -1)
- {
- elf->dynindx = -1;
- _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
- elf->dynstr_index);
- }
- return TRUE;
- }
-
- return elf64_hppa_mark_exported_functions (h, data);
+ return true;
}
/* Set the final sizes of the dynamic sections and allocate memory for
the contents of our special sections. */
-static bfd_boolean
+static boolean
elf64_hppa_size_dynamic_sections (output_bfd, info)
bfd *output_bfd;
struct bfd_link_info *info;
{
bfd *dynobj;
asection *s;
- bfd_boolean plt;
- bfd_boolean relocs;
- bfd_boolean reltext;
+ boolean plt;
+ boolean relocs;
+ boolean reltext;
struct elf64_hppa_allocate_data data;
struct elf64_hppa_link_hash_table *hppa_info;
@@ -1628,23 +1597,10 @@ elf64_hppa_size_dynamic_sections (output_bfd, info)
dynobj = elf_hash_table (info)->dynobj;
BFD_ASSERT (dynobj != NULL);
- /* Mark each function this program exports so that we will allocate
- space in the .opd section for each function's FPTR. If we are
- creating dynamic sections, change the dynamic index of millicode
- symbols to -1 and remove them from the string table for .dynstr.
-
- We have to traverse the main linker hash table since we have to
- find functions which may not have been mentioned in any relocs. */
- elf_link_hash_traverse (elf_hash_table (info),
- (elf_hash_table (info)->dynamic_sections_created
- ? elf64_hppa_mark_milli_and_exported_functions
- : elf64_hppa_mark_exported_functions),
- info);
-
if (elf_hash_table (info)->dynamic_sections_created)
{
/* Set the contents of the .interp section to the interpreter. */
- if (info->executable)
+ if (! info->shared)
{
s = bfd_get_section_by_name (dynobj, ".interp");
BFD_ASSERT (s != NULL);
@@ -1685,6 +1641,15 @@ elf64_hppa_size_dynamic_sections (output_bfd, info)
hppa_info->stub_sec->_raw_size = data.ofs;
}
+ /* Mark each function this program exports so that we will allocate
+ space in the .opd section for each function's FPTR.
+
+ We have to traverse the main linker hash table since we have to
+ find functions which may not have been mentioned in any relocs. */
+ elf_link_hash_traverse (elf_hash_table (info),
+ elf64_hppa_mark_exported_functions,
+ info);
+
/* Allocate space for entries in the .opd section. */
if (elf64_hppa_hash_table (info)->opd_sec)
{
@@ -1700,13 +1665,13 @@ elf64_hppa_size_dynamic_sections (output_bfd, info)
allocate_dynrel_entries, &data);
/* The sizes of all the sections are set. Allocate memory for them. */
- plt = FALSE;
- relocs = FALSE;
- reltext = FALSE;
+ plt = false;
+ relocs = false;
+ reltext = false;
for (s = dynobj->sections; s != NULL; s = s->next)
{
const char *name;
- bfd_boolean strip;
+ boolean strip;
if ((s->flags & SEC_LINKER_CREATED) == 0)
continue;
@@ -1719,42 +1684,38 @@ elf64_hppa_size_dynamic_sections (output_bfd, info)
if (strcmp (name, ".plt") == 0)
{
- /* Strip this section if we don't need it; see the comment below. */
if (s->_raw_size == 0)
{
- strip = TRUE;
+ /* Strip this section if we don't need it; see the
+ comment below. */
+ strip = true;
}
else
{
/* Remember whether there is a PLT. */
- plt = TRUE;
+ plt = true;
}
}
else if (strcmp (name, ".dlt") == 0)
{
- /* Strip this section if we don't need it; see the comment below. */
if (s->_raw_size == 0)
{
- strip = TRUE;
+ /* Strip this section if we don't need it; see the
+ comment below. */
+ strip = true;
}
}
else if (strcmp (name, ".opd") == 0)
{
- /* Strip this section if we don't need it; see the comment below. */
if (s->_raw_size == 0)
{
- strip = TRUE;
+ /* Strip this section if we don't need it; see the
+ comment below. */
+ strip = true;
}
}
- else if (strncmp (name, ".rela", 5) == 0)
+ else if (strncmp (name, ".rela", 4) == 0)
{
- /* If we don't need this section, strip it from the output file.
- This is mostly to handle .rela.bss and .rela.plt. We must
- create both sections in create_dynamic_sections, because they
- must be created before the linker maps input sections to output
- sections. The linker does that before adjust_dynamic_symbol
- is called, and it is that function which decides whether
- anything needs to go into these sections. */
if (s->_raw_size == 0)
{
/* If we don't need this section, strip it from the
@@ -1766,7 +1727,7 @@ elf64_hppa_size_dynamic_sections (output_bfd, info)
adjust_dynamic_symbol is called, and it is that
function which decides whether anything needs to go
into these sections. */
- strip = TRUE;
+ strip = true;
}
else
{
@@ -1778,7 +1739,7 @@ elf64_hppa_size_dynamic_sections (output_bfd, info)
{
const char *outname;
- relocs = TRUE;
+ relocs = true;
/* If this relocation section applies to a read only
section, then we probably need a DT_TEXTREL
@@ -1791,7 +1752,7 @@ elf64_hppa_size_dynamic_sections (output_bfd, info)
if (target != NULL
&& (target->flags & SEC_READONLY) != 0
&& (target->flags & SEC_ALLOC) != 0)
- reltext = TRUE;
+ reltext = true;
}
/* We use the reloc_count field as a counter if we need
@@ -1823,7 +1784,7 @@ elf64_hppa_size_dynamic_sections (output_bfd, info)
{
s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
if (s->contents == NULL && s->_raw_size != 0)
- return FALSE;
+ return false;
}
}
@@ -1832,12 +1793,9 @@ elf64_hppa_size_dynamic_sections (output_bfd, info)
/* Always create a DT_PLTGOT. It actually has nothing to do with
the PLT, it is how we communicate the __gp value of a load
module to the dynamic linker. */
-#define add_dynamic_entry(TAG, VAL) \
- _bfd_elf_add_dynamic_entry (info, TAG, VAL)
-
- if (!add_dynamic_entry (DT_HP_DLD_FLAGS, 0)
- || !add_dynamic_entry (DT_PLTGOT, 0))
- return FALSE;
+ if (! bfd_elf64_add_dynamic_entry (info, DT_HP_DLD_FLAGS, 0)
+ || ! bfd_elf64_add_dynamic_entry (info, DT_PLTGOT, 0))
+ return false;
/* Add some entries to the .dynamic section. We fill in the
values later, in elf64_hppa_finish_dynamic_sections, but we
@@ -1846,43 +1804,38 @@ elf64_hppa_size_dynamic_sections (output_bfd, info)
dynamic linker and used by the debugger. */
if (! info->shared)
{
- if (!add_dynamic_entry (DT_DEBUG, 0)
- || !add_dynamic_entry (DT_HP_DLD_HOOK, 0)
- || !add_dynamic_entry (DT_HP_LOAD_MAP, 0))
- return FALSE;
+ if (! bfd_elf64_add_dynamic_entry (info, DT_DEBUG, 0)
+ || ! bfd_elf64_add_dynamic_entry (info, DT_HP_DLD_HOOK, 0)
+ || ! bfd_elf64_add_dynamic_entry (info, DT_HP_LOAD_MAP, 0))
+ return false;
}
- /* Force DT_FLAGS to always be set.
- Required by HPUX 11.00 patch PHSS_26559. */
- if (!add_dynamic_entry (DT_FLAGS, (info)->flags))
- return FALSE;
-
if (plt)
{
- if (!add_dynamic_entry (DT_PLTRELSZ, 0)
- || !add_dynamic_entry (DT_PLTREL, DT_RELA)
- || !add_dynamic_entry (DT_JMPREL, 0))
- return FALSE;
+ if (! bfd_elf64_add_dynamic_entry (info, DT_PLTRELSZ, 0)
+ || ! bfd_elf64_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
+ || ! bfd_elf64_add_dynamic_entry (info, DT_JMPREL, 0))
+ return false;
}
if (relocs)
{
- if (!add_dynamic_entry (DT_RELA, 0)
- || !add_dynamic_entry (DT_RELASZ, 0)
- || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
- return FALSE;
+ if (! bfd_elf64_add_dynamic_entry (info, DT_RELA, 0)
+ || ! bfd_elf64_add_dynamic_entry (info, DT_RELASZ, 0)
+ || ! bfd_elf64_add_dynamic_entry (info, DT_RELAENT,
+ sizeof (Elf64_External_Rela)))
+ return false;
}
if (reltext)
{
- if (!add_dynamic_entry (DT_TEXTREL, 0))
- return FALSE;
+ if (! bfd_elf64_add_dynamic_entry (info, DT_TEXTREL, 0))
+ return false;
info->flags |= DF_TEXTREL;
}
}
-#undef add_dynamic_entry
- return TRUE;
+ return true;
}
/* Called after we have output the symbol into the dynamic symbol
@@ -1894,13 +1847,13 @@ elf64_hppa_size_dynamic_sections (output_bfd, info)
the symbols have their expected value in the normal symbol
table. Ick. */
-static bfd_boolean
-elf64_hppa_link_output_symbol_hook (info, name, sym, input_sec, h)
+static boolean
+elf64_hppa_link_output_symbol_hook (abfd, info, name, sym, input_sec)
+ bfd *abfd ATTRIBUTE_UNUSED;
struct bfd_link_info *info;
const char *name;
Elf_Internal_Sym *sym;
asection *input_sec ATTRIBUTE_UNUSED;
- struct elf_link_hash_entry *h;
{
struct elf64_hppa_link_hash_table *hppa_info;
struct elf64_hppa_dyn_hash_entry *dyn_h;
@@ -1908,14 +1861,12 @@ elf64_hppa_link_output_symbol_hook (info, name, sym, input_sec, h)
/* We may be called with the file symbol or section symbols.
They never need munging, so it is safe to ignore them. */
if (!name)
- return TRUE;
+ return true;
/* Get the PA dyn_symbol (if any) associated with NAME. */
hppa_info = elf64_hppa_hash_table (info);
dyn_h = elf64_hppa_dyn_hash_lookup (&hppa_info->dyn_hash_table,
- name, FALSE, FALSE);
- if (!dyn_h || dyn_h->h != h)
- return TRUE;
+ name, false, false);
/* Function symbols for which we created .opd entries *may* have been
munged by finish_dynamic_symbol and have to be un-munged here.
@@ -1924,20 +1875,20 @@ elf64_hppa_link_output_symbol_hook (info, name, sym, input_sec, h)
into non-dynamic ones, so we initialize st_shndx to -1 in
mark_exported_functions and check to see if it was overwritten
here instead of just checking dyn_h->h->dynindx. */
- if (dyn_h->want_opd && dyn_h->st_shndx != -1)
+ if (dyn_h && dyn_h->want_opd && dyn_h->st_shndx != -1)
{
/* Restore the saved value and section index. */
sym->st_value = dyn_h->st_value;
sym->st_shndx = dyn_h->st_shndx;
}
- return TRUE;
+ return true;
}
/* Finish up dynamic symbol handling. We set the contents of various
dynamic sections here. */
-static bfd_boolean
+static boolean
elf64_hppa_finish_dynamic_symbol (output_bfd, info, h, sym)
bfd *output_bfd;
struct bfd_link_info *info;
@@ -1950,7 +1901,7 @@ elf64_hppa_finish_dynamic_symbol (output_bfd, info, h, sym)
hppa_info = elf64_hppa_hash_table (info);
dyn_h = elf64_hppa_dyn_hash_lookup (&hppa_info->dyn_hash_table,
- h->root.root.string, FALSE, FALSE);
+ h->root.root.string, false, false);
stub = hppa_info->stub_sec;
splt = hppa_info->plt_sec;
@@ -1959,6 +1910,9 @@ elf64_hppa_finish_dynamic_symbol (output_bfd, info, h, sym)
spltrel = hppa_info->plt_rel_sec;
sdltrel = hppa_info->dlt_rel_sec;
+ BFD_ASSERT (stub != NULL && splt != NULL
+ && sopd != NULL && sdlt != NULL)
+
/* Incredible. It is actually necessary to NOT use the symbol's real
value when building the dynamic symbol table for a shared library.
At least for symbols that refer to functions.
@@ -1968,8 +1922,6 @@ elf64_hppa_finish_dynamic_symbol (output_bfd, info, h, sym)
the original values (in elf64_hppa_link_output_symbol_hook). */
if (dyn_h && dyn_h->want_opd)
{
- BFD_ASSERT (sopd != NULL)
-
/* Save away the original value and section index so that we
can restore them later. */
dyn_h->st_value = sym->st_value;
@@ -1990,9 +1942,6 @@ elf64_hppa_finish_dynamic_symbol (output_bfd, info, h, sym)
{
bfd_vma value;
Elf_Internal_Rela rel;
- bfd_byte *loc;
-
- BFD_ASSERT (splt != NULL && spltrel != NULL)
/* We do not actually care about the value in the PLT entry
if we are creating a shared library and the symbol is
@@ -2029,9 +1978,11 @@ elf64_hppa_finish_dynamic_symbol (output_bfd, info, h, sym)
rel.r_info = ELF64_R_INFO (h->dynindx, R_PARISC_IPLT);
rel.r_addend = 0;
- loc = spltrel->contents;
- loc += spltrel->reloc_count++ * sizeof (Elf64_External_Rela);
- bfd_elf64_swap_reloca_out (splt->output_section->owner, &rel, loc);
+ bfd_elf64_swap_reloca_out (splt->output_section->owner, &rel,
+ (((Elf64_External_Rela *)
+ spltrel->contents)
+ + spltrel->reloc_count));
+ spltrel->reloc_count++;
}
/* Initialize an external call stub entry if requested. */
@@ -2042,8 +1993,6 @@ elf64_hppa_finish_dynamic_symbol (output_bfd, info, h, sym)
int insn;
unsigned int max_offset;
- BFD_ASSERT (stub != NULL)
-
/* Install the generic stub template.
We are modifying the contents of the stub section, so we do not
@@ -2069,13 +2018,13 @@ elf64_hppa_finish_dynamic_symbol (output_bfd, info, h, sym)
/* Wide mode allows 16 bit offsets. */
max_offset = 32768;
insn &= ~ 0xfff1;
- insn |= re_assemble_16 ((int) value);
+ insn |= re_assemble_16 (value);
}
else
{
max_offset = 8192;
insn &= ~ 0x3ff1;
- insn |= re_assemble_14 ((int) value);
+ insn |= re_assemble_14 (value);
}
if ((value & 7) || value + max_offset >= 2*max_offset - 8)
@@ -2083,10 +2032,10 @@ elf64_hppa_finish_dynamic_symbol (output_bfd, info, h, sym)
(*_bfd_error_handler) (_("stub entry for %s cannot load .plt, dp offset = %ld"),
dyn_h->root.string,
(long) value);
- return FALSE;
+ return false;
}
- bfd_put_32 (stub->owner, (bfd_vma) insn,
+ bfd_put_32 (stub->owner, insn,
stub->contents + dyn_h->stub_offset);
/* Fix up the second ldd instruction. */
@@ -2095,31 +2044,36 @@ elf64_hppa_finish_dynamic_symbol (output_bfd, info, h, sym)
if (output_bfd->arch_info->mach >= 25)
{
insn &= ~ 0xfff1;
- insn |= re_assemble_16 ((int) value);
+ insn |= re_assemble_16 (value);
}
else
{
insn &= ~ 0x3ff1;
- insn |= re_assemble_14 ((int) value);
+ insn |= re_assemble_14 (value);
}
- bfd_put_32 (stub->owner, (bfd_vma) insn,
+ bfd_put_32 (stub->owner, insn,
stub->contents + dyn_h->stub_offset + 8);
}
- return TRUE;
+ /* Millicode symbols should not be put in the dynamic
+ symbol table under any circumstances. */
+ if (ELF_ST_TYPE (sym->st_info) == STT_PARISC_MILLI)
+ h->dynindx = -1;
+
+ return true;
}
/* The .opd section contains FPTRs for each function this file
exports. Initialize the FPTR entries. */
-static bfd_boolean
+static boolean
elf64_hppa_finalize_opd (dyn_h, data)
struct elf64_hppa_dyn_hash_entry *dyn_h;
PTR data;
{
struct bfd_link_info *info = (struct bfd_link_info *)data;
struct elf64_hppa_link_hash_table *hppa_info;
- struct elf_link_hash_entry *h = dyn_h ? dyn_h->h : NULL;
+ struct elf_link_hash_entry *h = dyn_h->h;
asection *sopd;
asection *sopdrel;
@@ -2127,7 +2081,7 @@ elf64_hppa_finalize_opd (dyn_h, data)
sopd = hppa_info->opd_sec;
sopdrel = hppa_info->opd_rel_sec;
- if (h && dyn_h->want_opd)
+ if (h && dyn_h && dyn_h->want_opd)
{
bfd_vma value;
@@ -2154,8 +2108,7 @@ elf64_hppa_finalize_opd (dyn_h, data)
had their address taken). */
if (info->shared && dyn_h && dyn_h->want_opd)
{
- Elf_Internal_Rela rel;
- bfd_byte *loc;
+ Elf64_Internal_Rela rel;
int dynindx;
/* We may need to do a relocation against a local symbol, in
@@ -2210,7 +2163,7 @@ elf64_hppa_finalize_opd (dyn_h, data)
strcpy (new_name + 1, h->root.root.string);
nh = elf_link_hash_lookup (elf_hash_table (info),
- new_name, FALSE, FALSE, FALSE);
+ new_name, false, false, false);
/* All we really want from the new symbol is its dynamic
symbol index. */
@@ -2220,18 +2173,20 @@ elf64_hppa_finalize_opd (dyn_h, data)
rel.r_addend = 0;
rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_EPLT);
- loc = sopdrel->contents;
- loc += sopdrel->reloc_count++ * sizeof (Elf64_External_Rela);
- bfd_elf64_swap_reloca_out (sopd->output_section->owner, &rel, loc);
+ bfd_elf64_swap_reloca_out (sopd->output_section->owner, &rel,
+ (((Elf64_External_Rela *)
+ sopdrel->contents)
+ + sopdrel->reloc_count));
+ sopdrel->reloc_count++;
}
- return TRUE;
+ return true;
}
/* The .dlt section contains addresses for items referenced through the
dlt. Note that we can have a DLTIND relocation for a local symbol, thus
we can not depend on finish_dynamic_symbol to initialize the .dlt. */
-static bfd_boolean
+static boolean
elf64_hppa_finalize_dlt (dyn_h, data)
struct elf64_hppa_dyn_hash_entry *dyn_h;
PTR data;
@@ -2239,7 +2194,7 @@ elf64_hppa_finalize_dlt (dyn_h, data)
struct bfd_link_info *info = (struct bfd_link_info *)data;
struct elf64_hppa_link_hash_table *hppa_info;
asection *sdlt, *sdltrel;
- struct elf_link_hash_entry *h = dyn_h ? dyn_h->h : NULL;
+ struct elf_link_hash_entry *h = dyn_h->h;
hppa_info = elf64_hppa_hash_table (info);
@@ -2250,7 +2205,7 @@ elf64_hppa_finalize_dlt (dyn_h, data)
address, so there is no need to create a relocation. Just install
the proper value into the DLT, note this shortcut can not be
skipped when building a shared library. */
- if (! info->shared && h && dyn_h->want_dlt)
+ if (! info->shared && h && dyn_h && dyn_h->want_dlt)
{
bfd_vma value;
@@ -2266,32 +2221,28 @@ elf64_hppa_finalize_dlt (dyn_h, data)
+ hppa_info->opd_sec->output_offset
+ hppa_info->opd_sec->output_section->vma);
}
- else if ((h->root.type == bfd_link_hash_defined
- || h->root.type == bfd_link_hash_defweak)
- && h->root.u.def.section)
+ else
{
- value = h->root.u.def.value + h->root.u.def.section->output_offset;
+ value = (h->root.u.def.value
+ + h->root.u.def.section->output_offset);
+
if (h->root.u.def.section->output_section)
value += h->root.u.def.section->output_section->vma;
else
value += h->root.u.def.section->vma;
}
- else
- /* We have an undefined function reference. */
- value = 0;
/* We do not need to include the output offset of the DLT section
here because we are modifying the in-memory contents. */
bfd_put_64 (sdlt->owner, value, sdlt->contents + dyn_h->dlt_offset);
}
- /* Create a relocation for the DLT entry associated with this symbol.
+ /* Create a relocation for the DLT entry assocated with this symbol.
When building a shared library the symbol does not have to be dynamic. */
if (dyn_h->want_dlt
&& (elf64_hppa_dynamic_symbol_p (dyn_h->h, info) || info->shared))
{
- Elf_Internal_Rela rel;
- bfd_byte *loc;
+ Elf64_Internal_Rela rel;
int dynindx;
/* We may need to do a relocation against a local symbol, in
@@ -2315,17 +2266,19 @@ elf64_hppa_finalize_dlt (dyn_h, data)
rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_DIR64);
rel.r_addend = 0;
- loc = sdltrel->contents;
- loc += sdltrel->reloc_count++ * sizeof (Elf64_External_Rela);
- bfd_elf64_swap_reloca_out (sdlt->output_section->owner, &rel, loc);
+ bfd_elf64_swap_reloca_out (sdlt->output_section->owner, &rel,
+ (((Elf64_External_Rela *)
+ sdltrel->contents)
+ + sdltrel->reloc_count));
+ sdltrel->reloc_count++;
}
- return TRUE;
+ return true;
}
/* Finalize the dynamic relocations. Specifically the FPTR relocations
for dynamic functions used to initialize static data. */
-static bfd_boolean
+static boolean
elf64_hppa_finalize_dynreloc (dyn_h, data)
struct elf64_hppa_dyn_hash_entry *dyn_h;
PTR data;
@@ -2338,7 +2291,7 @@ elf64_hppa_finalize_dynreloc (dyn_h, data)
dynamic_symbol = elf64_hppa_dynamic_symbol_p (dyn_h->h, info);
if (!dynamic_symbol && !info->shared)
- return TRUE;
+ return true;
if (dyn_h->reloc_entries)
{
@@ -2360,13 +2313,18 @@ elf64_hppa_finalize_dynreloc (dyn_h, data)
for (rent = dyn_h->reloc_entries; rent; rent = rent->next)
{
- Elf_Internal_Rela rel;
- bfd_byte *loc;
+ Elf64_Internal_Rela rel;
- /* Allocate one iff we are building a shared library, the relocation
- isn't a R_PARISC_FPTR64, or we don't want an opd entry. */
- if (!info->shared && rent->type == R_PARISC_FPTR64 && dyn_h->want_opd)
- continue;
+ switch (rent->type)
+ {
+ case R_PARISC_FPTR64:
+ /* Allocate one iff we are not building a shared library and
+ !want_opd, which by this point will be true only if we're
+ actually allocating one statically in the main executable. */
+ if (!info->shared && dyn_h->want_opd)
+ continue;
+ break;
+ }
/* Create a dynamic relocation for this entry.
@@ -2395,7 +2353,7 @@ elf64_hppa_finalize_dynreloc (dyn_h, data)
We use a section symbol recorded by check_relocs as the
base symbol for the relocation. The addend is the difference
between the section symbol and the address of the .opd entry. */
- if (info->shared && rent->type == R_PARISC_FPTR64 && dyn_h->want_opd)
+ if (info->shared && rent->type == R_PARISC_FPTR64)
{
bfd_vma value, value2;
@@ -2428,41 +2386,21 @@ elf64_hppa_finalize_dynreloc (dyn_h, data)
rel.r_info = ELF64_R_INFO (dynindx, rent->type);
- loc = hppa_info->other_rel_sec->contents;
- loc += (hppa_info->other_rel_sec->reloc_count++
- * sizeof (Elf64_External_Rela));
bfd_elf64_swap_reloca_out (hppa_info->other_rel_sec->output_section->owner,
- &rel, loc);
+ &rel,
+ (((Elf64_External_Rela *)
+ hppa_info->other_rel_sec->contents)
+ + hppa_info->other_rel_sec->reloc_count));
+ hppa_info->other_rel_sec->reloc_count++;
}
}
- return TRUE;
-}
-
-/* Used to decide how to sort relocs in an optimal manner for the
- dynamic linker, before writing them out. */
-
-static enum elf_reloc_type_class
-elf64_hppa_reloc_type_class (rela)
- const Elf_Internal_Rela *rela;
-{
- if (ELF64_R_SYM (rela->r_info) == 0)
- return reloc_class_relative;
-
- switch ((int) ELF64_R_TYPE (rela->r_info))
- {
- case R_PARISC_IPLT:
- return reloc_class_plt;
- case R_PARISC_COPY:
- return reloc_class_copy;
- default:
- return reloc_class_normal;
- }
+ return true;
}
/* Finish up the dynamic sections. */
-static bfd_boolean
+static boolean
elf64_hppa_finish_dynamic_sections (output_bfd, info)
bfd *output_bfd;
struct bfd_link_info *info;
@@ -2543,10 +2481,8 @@ elf64_hppa_finish_dynamic_sections (output_bfd, info)
case DT_RELA:
s = hppa_info->other_rel_sec;
- if (! s || ! s->_raw_size)
+ if (! s)
s = hppa_info->dlt_rel_sec;
- if (! s || ! s->_raw_size)
- s = hppa_info->opd_rel_sec;
dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
break;
@@ -2570,7 +2506,7 @@ elf64_hppa_finish_dynamic_sections (output_bfd, info)
}
}
- return TRUE;
+ return true;
}
/* Return the number of additional phdrs we will need.
@@ -2612,10 +2548,9 @@ elf64_hppa_additional_program_headers (abfd)
to guess whether or not we are building a shared library based on the
existence of a .interp section. */
-static bfd_boolean
-elf64_hppa_modify_segment_map (abfd, info)
+static boolean
+elf64_hppa_modify_segment_map (abfd)
bfd *abfd;
- struct bfd_link_info *info ATTRIBUTE_UNUSED;
{
struct elf_segment_map *m;
asection *s;
@@ -2628,10 +2563,9 @@ elf64_hppa_modify_segment_map (abfd, info)
break;
if (m == NULL)
{
- m = ((struct elf_segment_map *)
- bfd_zalloc (abfd, (bfd_size_type) sizeof *m));
+ m = (struct elf_segment_map *) bfd_zalloc (abfd, sizeof *m);
if (m == NULL)
- return FALSE;
+ return false;
m->p_type = PT_PHDR;
m->p_flags = PF_R | PF_X;
@@ -2662,7 +2596,7 @@ elf64_hppa_modify_segment_map (abfd, info)
}
}
- return TRUE;
+ return true;
}
/* Called when writing out an object file to decide the type of a
@@ -2678,13 +2612,6 @@ elf64_hppa_elf_get_symbol_type (elf_sym, type)
return type;
}
-static struct bfd_elf_special_section const elf64_hppa_special_sections[]=
-{
- { ".fini", 5, 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
- { ".init", 5, 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
- { NULL, 0, 0, 0, 0 }
-};
-
/* The hash bucket size is the standard one, namely 4. */
const struct elf_size_info hppa64_elf_size_info =
@@ -2699,21 +2626,20 @@ const struct elf_size_info hppa64_elf_size_info =
sizeof (Elf_External_Note),
4,
1,
- 64, 3,
+ 64, 8,
ELFCLASS64, EV_CURRENT,
bfd_elf64_write_out_phdrs,
bfd_elf64_write_shdrs_and_ehdr,
bfd_elf64_write_relocs,
- bfd_elf64_swap_symbol_in,
bfd_elf64_swap_symbol_out,
bfd_elf64_slurp_reloc_table,
bfd_elf64_slurp_symbol_table,
bfd_elf64_swap_dyn_in,
bfd_elf64_swap_dyn_out,
- bfd_elf64_swap_reloc_in,
- bfd_elf64_swap_reloc_out,
- bfd_elf64_swap_reloca_in,
- bfd_elf64_swap_reloca_out
+ NULL,
+ NULL,
+ NULL,
+ NULL
};
#define TARGET_BIG_SYM bfd_elf64_hppa_vec
@@ -2732,10 +2658,10 @@ const struct elf_size_info hppa64_elf_size_info =
#define elf_backend_object_p elf64_hppa_object_p
#define elf_backend_final_write_processing \
elf_hppa_final_write_processing
-#define elf_backend_fake_sections elf_hppa_fake_sections
+#define elf_backend_fake_sections elf_hppa_fake_sections
#define elf_backend_add_symbol_hook elf_hppa_add_symbol_hook
-#define elf_backend_relocate_section elf_hppa_relocate_section
+#define elf_backend_relocate_section elf_hppa_relocate_section
#define bfd_elf64_bfd_final_link elf_hppa_final_link
@@ -2777,11 +2703,9 @@ const struct elf_size_info hppa64_elf_size_info =
#define elf_backend_plt_readonly 0
#define elf_backend_want_plt_sym 0
#define elf_backend_got_header_size 0
-#define elf_backend_type_change_ok TRUE
-#define elf_backend_get_symbol_type elf64_hppa_elf_get_symbol_type
-#define elf_backend_reloc_type_class elf64_hppa_reloc_type_class
-#define elf_backend_rela_normal 1
-#define elf_backend_special_sections elf64_hppa_special_sections
+#define elf_backend_plt_header_size 0
+#define elf_backend_type_change_ok true
+#define elf_backend_get_symbol_type elf64_hppa_elf_get_symbol_type
#include "elf64-target.h"
@@ -2790,7 +2714,5 @@ const struct elf_size_info hppa64_elf_size_info =
#undef TARGET_BIG_NAME
#define TARGET_BIG_NAME "elf64-hppa-linux"
-#undef elf_backend_special_sections
-
#define INCLUDED_TARGET_FILE 1
#include "elf64-target.h"
diff --git a/gnu/usr.bin/binutils/bfd/elf64-x86-64.c b/gnu/usr.bin/binutils/bfd/elf64-x86-64.c
index a1d62501f96..206e70c3a69 100644
--- a/gnu/usr.bin/binutils/bfd/elf64-x86-64.c
+++ b/gnu/usr.bin/binutils/bfd/elf64-x86-64.c
@@ -1,31 +1,33 @@
/* X86-64 specific support for 64-bit ELF
- Copyright 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ Copyright 2000, 2001 Free Software Foundation, Inc.
Contributed by Jan Hubicka <jh@suse.cz>.
- This file is part of BFD, the Binary File Descriptor library.
+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 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.
+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. */
+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 "elf-bfd.h"
#include "elf/x86-64.h"
+/* We use only the RELA entries. */
+#define USE_RELA
+
/* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
#define MINUS_ONE (~ (bfd_vma) 0)
@@ -34,83 +36,50 @@
special_function, name, partial_inplace, src_mask, dst_pack, pcrel_offset. */
static reloc_howto_type x86_64_elf_howto_table[] =
{
- HOWTO(R_X86_64_NONE, 0, 0, 0, FALSE, 0, complain_overflow_dont,
- bfd_elf_generic_reloc, "R_X86_64_NONE", FALSE, 0x00000000, 0x00000000,
- FALSE),
- HOWTO(R_X86_64_64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
- bfd_elf_generic_reloc, "R_X86_64_64", FALSE, MINUS_ONE, MINUS_ONE,
- FALSE),
- HOWTO(R_X86_64_PC32, 0, 2, 32, TRUE, 0, complain_overflow_signed,
- bfd_elf_generic_reloc, "R_X86_64_PC32", FALSE, 0xffffffff, 0xffffffff,
- TRUE),
- HOWTO(R_X86_64_GOT32, 0, 2, 32, FALSE, 0, complain_overflow_signed,
- bfd_elf_generic_reloc, "R_X86_64_GOT32", FALSE, 0xffffffff, 0xffffffff,
- FALSE),
- HOWTO(R_X86_64_PLT32, 0, 2, 32, TRUE, 0, complain_overflow_signed,
- bfd_elf_generic_reloc, "R_X86_64_PLT32", FALSE, 0xffffffff, 0xffffffff,
- TRUE),
- HOWTO(R_X86_64_COPY, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
- bfd_elf_generic_reloc, "R_X86_64_COPY", FALSE, 0xffffffff, 0xffffffff,
- FALSE),
- HOWTO(R_X86_64_GLOB_DAT, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
- bfd_elf_generic_reloc, "R_X86_64_GLOB_DAT", FALSE, MINUS_ONE,
- MINUS_ONE, FALSE),
- HOWTO(R_X86_64_JUMP_SLOT, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
- bfd_elf_generic_reloc, "R_X86_64_JUMP_SLOT", FALSE, MINUS_ONE,
- MINUS_ONE, FALSE),
- HOWTO(R_X86_64_RELATIVE, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
- bfd_elf_generic_reloc, "R_X86_64_RELATIVE", FALSE, MINUS_ONE,
- MINUS_ONE, FALSE),
- HOWTO(R_X86_64_GOTPCREL, 0, 2, 32, TRUE, 0, complain_overflow_signed,
- bfd_elf_generic_reloc, "R_X86_64_GOTPCREL", FALSE, 0xffffffff,
- 0xffffffff, TRUE),
- HOWTO(R_X86_64_32, 0, 2, 32, FALSE, 0, complain_overflow_unsigned,
- bfd_elf_generic_reloc, "R_X86_64_32", FALSE, 0xffffffff, 0xffffffff,
- FALSE),
- HOWTO(R_X86_64_32S, 0, 2, 32, FALSE, 0, complain_overflow_signed,
- bfd_elf_generic_reloc, "R_X86_64_32S", FALSE, 0xffffffff, 0xffffffff,
- FALSE),
- HOWTO(R_X86_64_16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,
- bfd_elf_generic_reloc, "R_X86_64_16", FALSE, 0xffff, 0xffff, FALSE),
- HOWTO(R_X86_64_PC16,0, 1, 16, TRUE, 0, complain_overflow_bitfield,
- bfd_elf_generic_reloc, "R_X86_64_PC16", FALSE, 0xffff, 0xffff, TRUE),
- HOWTO(R_X86_64_8, 0, 0, 8, FALSE, 0, complain_overflow_signed,
- bfd_elf_generic_reloc, "R_X86_64_8", FALSE, 0xff, 0xff, FALSE),
- HOWTO(R_X86_64_PC8, 0, 0, 8, TRUE, 0, complain_overflow_signed,
- bfd_elf_generic_reloc, "R_X86_64_PC8", FALSE, 0xff, 0xff, TRUE),
- HOWTO(R_X86_64_DTPMOD64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
- bfd_elf_generic_reloc, "R_X86_64_DTPMOD64", FALSE, MINUS_ONE,
- MINUS_ONE, FALSE),
- HOWTO(R_X86_64_DTPOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
- bfd_elf_generic_reloc, "R_X86_64_DTPOFF64", FALSE, MINUS_ONE,
- MINUS_ONE, FALSE),
- HOWTO(R_X86_64_TPOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
- bfd_elf_generic_reloc, "R_X86_64_TPOFF64", FALSE, MINUS_ONE,
- MINUS_ONE, FALSE),
- HOWTO(R_X86_64_TLSGD, 0, 2, 32, TRUE, 0, complain_overflow_signed,
- bfd_elf_generic_reloc, "R_X86_64_TLSGD", FALSE, 0xffffffff,
- 0xffffffff, TRUE),
- HOWTO(R_X86_64_TLSLD, 0, 2, 32, TRUE, 0, complain_overflow_signed,
- bfd_elf_generic_reloc, "R_X86_64_TLSLD", FALSE, 0xffffffff,
- 0xffffffff, TRUE),
- HOWTO(R_X86_64_DTPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
- bfd_elf_generic_reloc, "R_X86_64_DTPOFF32", FALSE, 0xffffffff,
- 0xffffffff, FALSE),
- HOWTO(R_X86_64_GOTTPOFF, 0, 2, 32, TRUE, 0, complain_overflow_signed,
- bfd_elf_generic_reloc, "R_X86_64_GOTTPOFF", FALSE, 0xffffffff,
- 0xffffffff, TRUE),
- HOWTO(R_X86_64_TPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_signed,
- bfd_elf_generic_reloc, "R_X86_64_TPOFF32", FALSE, 0xffffffff,
- 0xffffffff, FALSE),
-
-/* GNU extension to record C++ vtable hierarchy. */
- HOWTO (R_X86_64_GNU_VTINHERIT, 0, 4, 0, FALSE, 0, complain_overflow_dont,
- NULL, "R_X86_64_GNU_VTINHERIT", FALSE, 0, 0, FALSE),
-
-/* GNU extension to record C++ vtable member usage. */
- HOWTO (R_X86_64_GNU_VTENTRY, 0, 4, 0, FALSE, 0, complain_overflow_dont,
- _bfd_elf_rel_vtable_reloc_fn, "R_X86_64_GNU_VTENTRY", FALSE, 0, 0,
- FALSE)
+ HOWTO(R_X86_64_NONE, 0, 0, 0, false, 0, complain_overflow_dont,
+ bfd_elf_generic_reloc, "R_X86_64_NONE", false, 0x00000000, 0x00000000,
+ false),
+ HOWTO(R_X86_64_64, 0, 4, 64, false, 0, complain_overflow_bitfield,
+ bfd_elf_generic_reloc, "R_X86_64_64", false, MINUS_ONE, MINUS_ONE,
+ false),
+ HOWTO(R_X86_64_PC32, 0, 4, 32, true, 0, complain_overflow_signed,
+ bfd_elf_generic_reloc, "R_X86_64_PC32", false, 0xffffffff, 0xffffffff,
+ true),
+ HOWTO(R_X86_64_GOT32, 0, 4, 32, false, 0, complain_overflow_signed,
+ bfd_elf_generic_reloc, "R_X86_64_GOT32", false, 0xffffffff, 0xffffffff,
+ false),
+ HOWTO(R_X86_64_PLT32, 0, 4, 32, true, 0, complain_overflow_signed,
+ bfd_elf_generic_reloc, "R_X86_64_PLT32", false, 0xffffffff, 0xffffffff,
+ true),
+ HOWTO(R_X86_64_COPY, 0, 4, 32, false, 0, complain_overflow_bitfield,
+ bfd_elf_generic_reloc, "R_X86_64_COPY", false, 0xffffffff, 0xffffffff,
+ false),
+ HOWTO(R_X86_64_GLOB_DAT, 0, 4, 64, false, 0, complain_overflow_bitfield,
+ bfd_elf_generic_reloc, "R_X86_64_GLOB_DAT", false, MINUS_ONE,
+ MINUS_ONE, false),
+ HOWTO(R_X86_64_JUMP_SLOT, 0, 4, 64, false, 0, complain_overflow_bitfield,
+ bfd_elf_generic_reloc, "R_X86_64_JUMP_SLOT", false, MINUS_ONE,
+ MINUS_ONE, false),
+ HOWTO(R_X86_64_RELATIVE, 0, 4, 64, false, 0, complain_overflow_bitfield,
+ bfd_elf_generic_reloc, "R_X86_64_RELATIVE", false, MINUS_ONE,
+ MINUS_ONE, false),
+ HOWTO(R_X86_64_GOTPCREL, 0, 4, 32, true,0 , complain_overflow_signed,
+ bfd_elf_generic_reloc, "R_X86_64_GOTPCREL", false, 0xffffffff,
+ 0xffffffff, true),
+ HOWTO(R_X86_64_32, 0, 4, 32, false, 0, complain_overflow_unsigned,
+ bfd_elf_generic_reloc, "R_X86_64_32", false, 0xffffffff, 0xffffffff,
+ false),
+ HOWTO(R_X86_64_32S, 0, 4, 32, false, 0, complain_overflow_signed,
+ bfd_elf_generic_reloc, "R_X86_64_32S", false, 0xffffffff, 0xffffffff,
+ false),
+ HOWTO(R_X86_64_16, 0, 1, 16, false, 0, complain_overflow_bitfield,
+ bfd_elf_generic_reloc, "R_X86_64_16", false, 0xffff, 0xffff, false),
+ HOWTO(R_X86_64_PC16,0, 1, 16, true, 0, complain_overflow_bitfield,
+ bfd_elf_generic_reloc, "R_X86_64_PC16", false, 0xffff, 0xffff, true),
+ HOWTO(R_X86_64_8, 0, 0, 8, false, 0, complain_overflow_signed,
+ bfd_elf_generic_reloc, "R_X86_64_8", false, 0xff, 0xff, false),
+ HOWTO(R_X86_64_PC8, 0, 0, 8, true, 0, complain_overflow_signed,
+ bfd_elf_generic_reloc, "R_X86_64_PC8", false, 0xff, 0xff, true)
};
/* Map BFD relocs to the x86_64 elf relocs. */
@@ -120,7 +89,7 @@ struct elf_reloc_map
unsigned char elf_reloc_val;
};
-static const struct elf_reloc_map x86_64_reloc_map[] =
+static CONST struct elf_reloc_map x86_64_reloc_map[] =
{
{ BFD_RELOC_NONE, R_X86_64_NONE, },
{ BFD_RELOC_64, R_X86_64_64, },
@@ -138,31 +107,44 @@ static const struct elf_reloc_map x86_64_reloc_map[] =
{ BFD_RELOC_16_PCREL, R_X86_64_PC16, },
{ BFD_RELOC_8, R_X86_64_8, },
{ BFD_RELOC_8_PCREL, R_X86_64_PC8, },
- { BFD_RELOC_X86_64_DTPMOD64, R_X86_64_DTPMOD64, },
- { BFD_RELOC_X86_64_DTPOFF64, R_X86_64_DTPOFF64, },
- { BFD_RELOC_X86_64_TPOFF64, R_X86_64_TPOFF64, },
- { BFD_RELOC_X86_64_TLSGD, R_X86_64_TLSGD, },
- { BFD_RELOC_X86_64_TLSLD, R_X86_64_TLSLD, },
- { BFD_RELOC_X86_64_DTPOFF32, R_X86_64_DTPOFF32, },
- { BFD_RELOC_X86_64_GOTTPOFF, R_X86_64_GOTTPOFF, },
- { BFD_RELOC_X86_64_TPOFF32, R_X86_64_TPOFF32, },
- { BFD_RELOC_VTABLE_INHERIT, R_X86_64_GNU_VTINHERIT, },
- { BFD_RELOC_VTABLE_ENTRY, R_X86_64_GNU_VTENTRY, },
};
+static reloc_howto_type *elf64_x86_64_reloc_type_lookup
+ PARAMS ((bfd *, bfd_reloc_code_real_type));
+static void elf64_x86_64_info_to_howto
+ PARAMS ((bfd *, arelent *, Elf64_Internal_Rela *));
+static struct bfd_link_hash_table *elf64_x86_64_link_hash_table_create
+ PARAMS ((bfd *));
+
+static struct bfd_hash_entry *elf64_x86_64_link_hash_newfunc
+ PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
+static boolean elf64_x86_64_adjust_dynamic_symbol
+ PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
+
+static boolean elf64_x86_64_size_dynamic_sections
+ PARAMS ((bfd *, struct bfd_link_info *));
+static boolean elf64_x86_64_relocate_section
+ PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
+ Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
+static boolean elf64_x86_64_finish_dynamic_symbol
+ PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
+ Elf_Internal_Sym *sym));
+static boolean elf64_x86_64_finish_dynamic_sections
+ PARAMS ((bfd *, struct bfd_link_info *));
/* Given a BFD reloc type, return a HOWTO structure. */
static reloc_howto_type *
-elf64_x86_64_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
- bfd_reloc_code_real_type code)
+elf64_x86_64_reloc_type_lookup (abfd, code)
+ bfd *abfd ATTRIBUTE_UNUSED;
+ bfd_reloc_code_real_type code;
{
unsigned int i;
-
for (i = 0; i < sizeof (x86_64_reloc_map) / sizeof (struct elf_reloc_map);
i++)
{
if (x86_64_reloc_map[i].bfd_reloc_val == code)
- return &x86_64_elf_howto_table[i];
+ return &x86_64_elf_howto_table[(int)
+ x86_64_reloc_map[i].elf_reloc_val];
}
return 0;
}
@@ -170,89 +152,19 @@ elf64_x86_64_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
/* Given an x86_64 ELF reloc type, fill in an arelent structure. */
static void
-elf64_x86_64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
- Elf_Internal_Rela *dst)
+elf64_x86_64_info_to_howto (abfd, cache_ptr, dst)
+ bfd *abfd ATTRIBUTE_UNUSED;
+ arelent *cache_ptr;
+ Elf64_Internal_Rela *dst;
{
- unsigned r_type, i;
+ unsigned r_type;
r_type = ELF64_R_TYPE (dst->r_info);
- if (r_type < (unsigned int) R_X86_64_GNU_VTINHERIT)
- {
- BFD_ASSERT (r_type <= (unsigned int) R_X86_64_TPOFF32);
- i = r_type;
- }
- else
- {
- BFD_ASSERT (r_type < (unsigned int) R_X86_64_max);
- i = r_type - ((unsigned int) R_X86_64_GNU_VTINHERIT - R_X86_64_TPOFF32 - 1);
- }
- cache_ptr->howto = &x86_64_elf_howto_table[i];
+ BFD_ASSERT (r_type < (unsigned int) R_X86_64_max);
+ cache_ptr->howto = &x86_64_elf_howto_table[r_type];
BFD_ASSERT (r_type == cache_ptr->howto->type);
}
-/* Support for core dump NOTE sections. */
-static bfd_boolean
-elf64_x86_64_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
-{
- int offset;
- size_t raw_size;
-
- switch (note->descsz)
- {
- default:
- return FALSE;
-
- case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */
- /* pr_cursig */
- elf_tdata (abfd)->core_signal
- = bfd_get_16 (abfd, note->descdata + 12);
-
- /* pr_pid */
- elf_tdata (abfd)->core_pid
- = bfd_get_32 (abfd, note->descdata + 32);
-
- /* pr_reg */
- offset = 112;
- raw_size = 216;
-
- break;
- }
-
- /* Make a ".reg/999" section. */
- return _bfd_elfcore_make_pseudosection (abfd, ".reg",
- raw_size, note->descpos + offset);
-}
-
-static bfd_boolean
-elf64_x86_64_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
-{
- switch (note->descsz)
- {
- default:
- return FALSE;
-
- case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */
- elf_tdata (abfd)->core_program
- = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
- elf_tdata (abfd)->core_command
- = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
- }
-
- /* Note that for some reason, a spurious space is tacked
- onto the end of the args in some (at least one anyway)
- implementations, so strip it off if it exists. */
-
- {
- char *command = elf_tdata (abfd)->core_command;
- int n = strlen (command);
-
- if (0 < n && command[n - 1] == ' ')
- command[n - 1] = '\0';
- }
-
- return TRUE;
-}
-
/* Functions for the x86-64 ELF linker. */
/* The name of the dynamic interpreter. This is put in the .interp
@@ -260,12 +172,6 @@ elf64_x86_64_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
#define ELF_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
-/* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
- copying dynamic variables from a shared lib into an app's dynbss
- section, and instead use a dynamic relocation to point into the
- shared lib. */
-#define ELIMINATE_COPY_RELOCS 1
-
/* The size in bytes of an entry in the global offset table. */
#define GOT_ENTRY_SIZE 8
@@ -297,83 +203,53 @@ static const bfd_byte elf64_x86_64_plt_entry[PLT_ENTRY_SIZE] =
};
/* The x86-64 linker needs to keep track of the number of relocs that
- it decides to copy as dynamic relocs in check_relocs for each symbol.
- This is so that it can later discard them if they are found to be
- unnecessary. We store the information in a field extending the
- regular ELF linker hash table. */
+ it decides to copy in check_relocs for each symbol. This is so
+ that it can discard PC relative relocs if it doesn't need them when
+ linking with -Bsymbolic. We store the information in a field
+ extending the regular ELF linker hash table. */
-struct elf64_x86_64_dyn_relocs
+/* This structure keeps track of the number of PC relative relocs we
+ have copied for a given symbol. */
+
+struct elf64_x86_64_pcrel_relocs_copied
{
/* Next section. */
- struct elf64_x86_64_dyn_relocs *next;
-
- /* The input section of the reloc. */
- asection *sec;
-
- /* Total number of relocs copied for the input section. */
+ struct elf64_x86_64_pcrel_relocs_copied *next;
+ /* A section in dynobj. */
+ asection *section;
+ /* Number of relocs copied in this section. */
bfd_size_type count;
-
- /* Number of pc-relative relocs copied for the input section. */
- bfd_size_type pc_count;
};
/* x86-64 ELF linker hash entry. */
struct elf64_x86_64_link_hash_entry
{
- struct elf_link_hash_entry elf;
-
- /* Track dynamic relocs copied for this symbol. */
- struct elf64_x86_64_dyn_relocs *dyn_relocs;
+ struct elf_link_hash_entry root;
-#define GOT_UNKNOWN 0
-#define GOT_NORMAL 1
-#define GOT_TLS_GD 2
-#define GOT_TLS_IE 3
- unsigned char tls_type;
+ /* Number of PC relative relocs copied for this symbol. */
+ struct elf64_x86_64_pcrel_relocs_copied *pcrel_relocs_copied;
};
-#define elf64_x86_64_hash_entry(ent) \
- ((struct elf64_x86_64_link_hash_entry *)(ent))
+/* x86-64 ELF linker hash table. */
-struct elf64_x86_64_obj_tdata
+struct elf64_x86_64_link_hash_table
{
- struct elf_obj_tdata root;
-
- /* tls_type for each local got entry. */
- char *local_got_tls_type;
+ struct elf_link_hash_table root;
};
-#define elf64_x86_64_tdata(abfd) \
- ((struct elf64_x86_64_obj_tdata *) (abfd)->tdata.any)
-
-#define elf64_x86_64_local_got_tls_type(abfd) \
- (elf64_x86_64_tdata (abfd)->local_got_tls_type)
+/* Declare this now that the above structures are defined. */
+static boolean elf64_x86_64_discard_copies
+ PARAMS ((struct elf64_x86_64_link_hash_entry *, PTR));
-/* x86-64 ELF linker hash table. */
+/* Traverse an x86-64 ELF linker hash table. */
-struct elf64_x86_64_link_hash_table
-{
- struct elf_link_hash_table elf;
-
- /* Short-cuts to get to dynamic linker sections. */
- asection *sgot;
- asection *sgotplt;
- asection *srelgot;
- asection *splt;
- asection *srelplt;
- asection *sdynbss;
- asection *srelbss;
-
- union {
- bfd_signed_vma refcount;
- bfd_vma offset;
- } tls_ld_got;
-
- /* Small local sym to section mapping cache. */
- struct sym_sec_cache sym_sec;
-};
+#define elf64_x86_64_link_hash_traverse(table, func, info) \
+ (elf_link_hash_traverse \
+ (&(table)->root, \
+ (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
+ (info)))
/* Get the x86-64 ELF linker hash table from a link_info structure. */
@@ -383,377 +259,203 @@ struct elf64_x86_64_link_hash_table
/* Create an entry in an x86-64 ELF linker hash table. */
static struct bfd_hash_entry *
-link_hash_newfunc (struct bfd_hash_entry *entry, struct bfd_hash_table *table,
- const char *string)
+elf64_x86_64_link_hash_newfunc (entry, table, string)
+ struct bfd_hash_entry *entry;
+ struct bfd_hash_table *table;
+ const char *string;
{
+ struct elf64_x86_64_link_hash_entry *ret =
+ (struct elf64_x86_64_link_hash_entry *) entry;
+
/* Allocate the structure if it has not already been allocated by a
- subclass. */
- if (entry == NULL)
- {
- entry = bfd_hash_allocate (table,
- sizeof (struct elf64_x86_64_link_hash_entry));
- if (entry == NULL)
- return entry;
- }
+ subclass. */
+ if (ret == (struct elf64_x86_64_link_hash_entry *) NULL)
+ ret = ((struct elf64_x86_64_link_hash_entry *)
+ bfd_hash_allocate (table,
+ sizeof (struct elf64_x86_64_link_hash_entry)));
+ if (ret == (struct elf64_x86_64_link_hash_entry *) NULL)
+ return (struct bfd_hash_entry *) ret;
/* Call the allocation method of the superclass. */
- entry = _bfd_elf_link_hash_newfunc (entry, table, string);
- if (entry != NULL)
+ ret = ((struct elf64_x86_64_link_hash_entry *)
+ _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
+ table, string));
+ if (ret != (struct elf64_x86_64_link_hash_entry *) NULL)
{
- struct elf64_x86_64_link_hash_entry *eh;
-
- eh = (struct elf64_x86_64_link_hash_entry *) entry;
- eh->dyn_relocs = NULL;
- eh->tls_type = GOT_UNKNOWN;
+ ret->pcrel_relocs_copied = NULL;
}
- return entry;
+ return (struct bfd_hash_entry *) ret;
}
/* Create an X86-64 ELF linker hash table. */
static struct bfd_link_hash_table *
-elf64_x86_64_link_hash_table_create (bfd *abfd)
+elf64_x86_64_link_hash_table_create (abfd)
+ bfd *abfd;
{
struct elf64_x86_64_link_hash_table *ret;
- bfd_size_type amt = sizeof (struct elf64_x86_64_link_hash_table);
- ret = (struct elf64_x86_64_link_hash_table *) bfd_malloc (amt);
- if (ret == NULL)
+ ret = ((struct elf64_x86_64_link_hash_table *)
+ bfd_alloc (abfd, sizeof (struct elf64_x86_64_link_hash_table)));
+ if (ret == (struct elf64_x86_64_link_hash_table *) NULL)
return NULL;
- if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc))
+ if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
+ elf64_x86_64_link_hash_newfunc))
{
- free (ret);
+ bfd_release (abfd, ret);
return NULL;
}
- ret->sgot = NULL;
- ret->sgotplt = NULL;
- ret->srelgot = NULL;
- ret->splt = NULL;
- ret->srelplt = NULL;
- ret->sdynbss = NULL;
- ret->srelbss = NULL;
- ret->sym_sec.abfd = NULL;
- ret->tls_ld_got.refcount = 0;
-
- return &ret->elf.root;
-}
-
-/* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
- shortcuts to them in our hash table. */
-
-static bfd_boolean
-create_got_section (bfd *dynobj, struct bfd_link_info *info)
-{
- struct elf64_x86_64_link_hash_table *htab;
-
- if (! _bfd_elf_create_got_section (dynobj, info))
- return FALSE;
-
- htab = elf64_x86_64_hash_table (info);
- htab->sgot = bfd_get_section_by_name (dynobj, ".got");
- htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
- if (!htab->sgot || !htab->sgotplt)
- abort ();
-
- htab->srelgot = bfd_make_section (dynobj, ".rela.got");
- if (htab->srelgot == NULL
- || ! bfd_set_section_flags (dynobj, htab->srelgot,
- (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
- | SEC_IN_MEMORY | SEC_LINKER_CREATED
- | SEC_READONLY))
- || ! bfd_set_section_alignment (dynobj, htab->srelgot, 3))
- return FALSE;
- return TRUE;
-}
-
-/* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
- .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
- hash table. */
-
-static bfd_boolean
-elf64_x86_64_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
-{
- struct elf64_x86_64_link_hash_table *htab;
-
- htab = elf64_x86_64_hash_table (info);
- if (!htab->sgot && !create_got_section (dynobj, info))
- return FALSE;
-
- if (!_bfd_elf_create_dynamic_sections (dynobj, info))
- return FALSE;
-
- htab->splt = bfd_get_section_by_name (dynobj, ".plt");
- htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt");
- htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
- if (!info->shared)
- htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss");
-
- if (!htab->splt || !htab->srelplt || !htab->sdynbss
- || (!info->shared && !htab->srelbss))
- abort ();
-
- return TRUE;
-}
-
-/* Copy the extra info we tack onto an elf_link_hash_entry. */
-
-static void
-elf64_x86_64_copy_indirect_symbol (const struct elf_backend_data *bed,
- struct elf_link_hash_entry *dir,
- struct elf_link_hash_entry *ind)
-{
- struct elf64_x86_64_link_hash_entry *edir, *eind;
-
- edir = (struct elf64_x86_64_link_hash_entry *) dir;
- eind = (struct elf64_x86_64_link_hash_entry *) ind;
-
- if (eind->dyn_relocs != NULL)
- {
- if (edir->dyn_relocs != NULL)
- {
- struct elf64_x86_64_dyn_relocs **pp;
- struct elf64_x86_64_dyn_relocs *p;
-
- if (ind->root.type == bfd_link_hash_indirect)
- abort ();
-
- /* Add reloc counts against the weak sym to the strong sym
- list. Merge any entries against the same section. */
- for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
- {
- struct elf64_x86_64_dyn_relocs *q;
-
- for (q = edir->dyn_relocs; q != NULL; q = q->next)
- if (q->sec == p->sec)
- {
- q->pc_count += p->pc_count;
- q->count += p->count;
- *pp = p->next;
- break;
- }
- if (q == NULL)
- pp = &p->next;
- }
- *pp = edir->dyn_relocs;
- }
-
- edir->dyn_relocs = eind->dyn_relocs;
- eind->dyn_relocs = NULL;
- }
-
- if (ind->root.type == bfd_link_hash_indirect
- && dir->got.refcount <= 0)
- {
- edir->tls_type = eind->tls_type;
- eind->tls_type = GOT_UNKNOWN;
- }
-
- if (ELIMINATE_COPY_RELOCS
- && ind->root.type != bfd_link_hash_indirect
- && (dir->elf_link_hash_flags & ELF_LINK_HASH_DYNAMIC_ADJUSTED) != 0)
- /* If called to transfer flags for a weakdef during processing
- of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF.
- We clear it ourselves for ELIMINATE_COPY_RELOCS. */
- dir->elf_link_hash_flags |=
- (ind->elf_link_hash_flags & (ELF_LINK_HASH_REF_DYNAMIC
- | ELF_LINK_HASH_REF_REGULAR
- | ELF_LINK_HASH_REF_REGULAR_NONWEAK
- | ELF_LINK_HASH_NEEDS_PLT));
- else
- _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
+ return &ret->root.root;
}
-static bfd_boolean
-elf64_x86_64_mkobject (bfd *abfd)
-{
- bfd_size_type amt = sizeof (struct elf64_x86_64_obj_tdata);
- abfd->tdata.any = bfd_zalloc (abfd, amt);
- if (abfd->tdata.any == NULL)
- return FALSE;
- return TRUE;
-}
-
-static bfd_boolean
-elf64_x86_64_elf_object_p (bfd *abfd)
+boolean
+elf64_x86_64_elf_object_p (abfd)
+ bfd *abfd;
{
/* Set the right machine number for an x86-64 elf64 file. */
bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_64);
- return TRUE;
-}
-
-static int
-elf64_x86_64_tls_transition (struct bfd_link_info *info, int r_type, int is_local)
-{
- if (info->shared)
- return r_type;
-
- switch (r_type)
- {
- case R_X86_64_TLSGD:
- case R_X86_64_GOTTPOFF:
- if (is_local)
- return R_X86_64_TPOFF32;
- return R_X86_64_GOTTPOFF;
- case R_X86_64_TLSLD:
- return R_X86_64_TPOFF32;
- }
-
- return r_type;
+ return true;
}
/* Look through the relocs for a section during the first phase, and
- calculate needed space in the global offset table, procedure
- linkage table, and dynamic reloc sections. */
-
-static bfd_boolean
-elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
- const Elf_Internal_Rela *relocs)
+ allocate space in the global offset table or procedure linkage
+ table. */
+
+static boolean
+elf64_x86_64_check_relocs (abfd, info, sec, relocs)
+ bfd *abfd;
+ struct bfd_link_info *info;
+ asection *sec;
+ const Elf_Internal_Rela *relocs;
{
- struct elf64_x86_64_link_hash_table *htab;
+ bfd *dynobj;
Elf_Internal_Shdr *symtab_hdr;
struct elf_link_hash_entry **sym_hashes;
+ bfd_signed_vma *local_got_refcounts;
const Elf_Internal_Rela *rel;
const Elf_Internal_Rela *rel_end;
+ asection *sgot;
+ asection *srelgot;
asection *sreloc;
- if (info->relocatable)
- return TRUE;
+ if (info->relocateable)
+ return true;
- htab = elf64_x86_64_hash_table (info);
+ dynobj = elf_hash_table (info)->dynobj;
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
sym_hashes = elf_sym_hashes (abfd);
+ local_got_refcounts = elf_local_got_refcounts (abfd);
- sreloc = NULL;
-
+ sgot = srelgot = sreloc = NULL;
rel_end = relocs + sec->reloc_count;
for (rel = relocs; rel < rel_end; rel++)
{
- unsigned int r_type;
unsigned long r_symndx;
struct elf_link_hash_entry *h;
r_symndx = ELF64_R_SYM (rel->r_info);
- r_type = ELF64_R_TYPE (rel->r_info);
-
- if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
- {
- (*_bfd_error_handler) (_("%s: bad symbol index: %d"),
- bfd_archive_filename (abfd),
- r_symndx);
- return FALSE;
- }
-
if (r_symndx < symtab_hdr->sh_info)
h = NULL;
else
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
- r_type = elf64_x86_64_tls_transition (info, r_type, h == NULL);
- switch (r_type)
+ /* Some relocs require a global offset table. */
+ if (dynobj == NULL)
{
- case R_X86_64_TLSLD:
- htab->tls_ld_got.refcount += 1;
- goto create_got;
-
- case R_X86_64_TPOFF32:
- if (info->shared)
+ switch (ELF64_R_TYPE (rel->r_info))
{
- (*_bfd_error_handler)
- (_("%s: relocation %s can not be used when making a shared object; recompile with -fPIC"),
- bfd_archive_filename (abfd),
- x86_64_elf_howto_table[r_type].name);
- bfd_set_error (bfd_error_bad_value);
- return FALSE;
+ case R_X86_64_GOT32:
+ case R_X86_64_GOTPCREL:
+ elf_hash_table (info)->dynobj = dynobj = abfd;
+ if (! _bfd_elf_create_got_section (dynobj, info))
+ return false;
+ break;
}
- break;
-
- case R_X86_64_GOTTPOFF:
- if (info->shared)
- info->flags |= DF_STATIC_TLS;
- /* Fall through */
+ }
- case R_X86_64_GOT32:
+ switch (ELF64_R_TYPE (rel->r_info))
+ {
case R_X86_64_GOTPCREL:
- case R_X86_64_TLSGD:
+ case R_X86_64_GOT32:
/* This symbol requires a global offset table entry. */
- {
- int tls_type, old_tls_type;
- switch (r_type)
- {
- default: tls_type = GOT_NORMAL; break;
- case R_X86_64_TLSGD: tls_type = GOT_TLS_GD; break;
- case R_X86_64_GOTTPOFF: tls_type = GOT_TLS_IE; break;
- }
-
- if (h != NULL)
- {
- h->got.refcount += 1;
- old_tls_type = elf64_x86_64_hash_entry (h)->tls_type;
- }
- else
- {
- bfd_signed_vma *local_got_refcounts;
+ if (sgot == NULL)
+ {
+ sgot = bfd_get_section_by_name (dynobj, ".got");
+ BFD_ASSERT (sgot != NULL);
+ }
- /* This is a global offset table entry for a local symbol. */
- local_got_refcounts = elf_local_got_refcounts (abfd);
- if (local_got_refcounts == NULL)
- {
- bfd_size_type size;
-
- size = symtab_hdr->sh_info;
- size *= sizeof (bfd_signed_vma) + sizeof (char);
- local_got_refcounts = ((bfd_signed_vma *)
- bfd_zalloc (abfd, size));
- if (local_got_refcounts == NULL)
- return FALSE;
- elf_local_got_refcounts (abfd) = local_got_refcounts;
- elf64_x86_64_local_got_tls_type (abfd)
- = (char *) (local_got_refcounts + symtab_hdr->sh_info);
- }
- local_got_refcounts[r_symndx] += 1;
- old_tls_type
- = elf64_x86_64_local_got_tls_type (abfd) [r_symndx];
- }
+ if (srelgot == NULL && (h != NULL || info->shared))
+ {
+ srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
+ if (srelgot == NULL)
+ {
+ srelgot = bfd_make_section (dynobj, ".rela.got");
+ if (srelgot == NULL
+ || ! bfd_set_section_flags (dynobj, srelgot,
+ (SEC_ALLOC
+ | SEC_LOAD
+ | SEC_HAS_CONTENTS
+ | SEC_IN_MEMORY
+ | SEC_LINKER_CREATED
+ | SEC_READONLY))
+ || ! bfd_set_section_alignment (dynobj, srelgot, 3))
+ return false;
+ }
+ }
- /* If a TLS symbol is accessed using IE at least once,
- there is no point to use dynamic model for it. */
- if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
- && (old_tls_type != GOT_TLS_GD || tls_type != GOT_TLS_IE))
- {
- if (old_tls_type == GOT_TLS_IE && tls_type == GOT_TLS_GD)
- tls_type = old_tls_type;
- else
- {
- (*_bfd_error_handler)
- (_("%s: %s' accessed both as normal and thread local symbol"),
- bfd_archive_filename (abfd),
- h ? h->root.root.string : "<local>");
- return FALSE;
- }
- }
+ if (h != NULL)
+ {
+ if (h->got.refcount == -1)
+ {
+ h->got.refcount = 1;
- if (old_tls_type != tls_type)
- {
- if (h != NULL)
- elf64_x86_64_hash_entry (h)->tls_type = tls_type;
- else
- elf64_x86_64_local_got_tls_type (abfd) [r_symndx] = tls_type;
- }
- }
- /* Fall through */
+ /* Make sure this symbol is output as a dynamic symbol. */
+ if (h->dynindx == -1)
+ {
+ if (! bfd_elf64_link_record_dynamic_symbol (info, h))
+ return false;
+ }
- //case R_X86_64_GOTPCREL:
- create_got:
- if (htab->sgot == NULL)
+ sgot->_raw_size += GOT_ENTRY_SIZE;
+ srelgot->_raw_size += sizeof (Elf64_External_Rela);
+ }
+ else
+ h->got.refcount += 1;
+ }
+ else
{
- if (htab->elf.dynobj == NULL)
- htab->elf.dynobj = abfd;
- if (!create_got_section (htab->elf.dynobj, info))
- return FALSE;
+ /* This is a global offset table entry for a local symbol. */
+ if (local_got_refcounts == NULL)
+ {
+ size_t size;
+
+ size = symtab_hdr->sh_info * sizeof (bfd_signed_vma);
+ local_got_refcounts = ((bfd_signed_vma *)
+ bfd_alloc (abfd, size));
+ if (local_got_refcounts == NULL)
+ return false;
+ elf_local_got_refcounts (abfd) = local_got_refcounts;
+ memset (local_got_refcounts, -1, size);
+ }
+ if (local_got_refcounts[r_symndx] == -1)
+ {
+ local_got_refcounts[r_symndx] = 1;
+
+ sgot->_raw_size += GOT_ENTRY_SIZE;
+ if (info->shared)
+ {
+ /* If we are generating a shared object, we need to
+ output a R_X86_64_RELATIVE reloc so that the dynamic
+ linker can adjust this GOT entry. */
+ srelgot->_raw_size += sizeof (Elf64_External_Rela);
+ }
+ }
+ else
+ local_got_refcounts[r_symndx] += 1;
}
break;
@@ -771,48 +473,20 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
continue;
h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
- h->plt.refcount += 1;
+ if (h->plt.refcount == -1)
+ h->plt.refcount = 1;
+ else
+ h->plt.refcount += 1;
break;
case R_X86_64_8:
case R_X86_64_16:
case R_X86_64_32:
+ case R_X86_64_64:
case R_X86_64_32S:
- /* Let's help debug shared library creation. These relocs
- cannot be used in shared libs. Don't error out for
- sections we don't care about, such as debug sections or
- non-constant sections. */
- if (info->shared
- && (sec->flags & SEC_ALLOC) != 0
- && (sec->flags & SEC_READONLY) != 0)
- {
- (*_bfd_error_handler)
- (_("%s: relocation %s can not be used when making a shared object; recompile with -fPIC"),
- bfd_archive_filename (abfd),
- x86_64_elf_howto_table[r_type].name);
- bfd_set_error (bfd_error_bad_value);
- return FALSE;
- }
- /* Fall through. */
-
- case R_X86_64_PC8:
- case R_X86_64_PC16:
case R_X86_64_PC32:
- case R_X86_64_64:
- if (h != NULL && !info->shared)
- {
- /* If this reloc is in a read-only section, we might
- need a copy reloc. We can't check reliably at this
- stage whether the section is read-only, as input
- sections have not yet been mapped to output sections.
- Tentatively set the flag for now, and correct in
- adjust_dynamic_symbol. */
- h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
-
- /* We may need a .plt entry if the function this reloc
- refers to is in a shared lib. */
- h->plt.refcount += 1;
- }
+ if (h != NULL)
+ h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
/* If we are creating a shared library, and this is a reloc
against a global symbol, or a non PC relative reloc
@@ -823,67 +497,38 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
including in the link (i.e., DEF_REGULAR is set). At
this point we have not seen all the input files, so it is
possible that DEF_REGULAR is not set now but will be set
- later (it is never cleared). In case of a weak definition,
- DEF_REGULAR may be cleared later by a strong definition in
- a shared library. We account for that possibility below by
- storing information in the relocs_copied field of the hash
- table entry. A similar situation occurs when creating
- shared libraries and symbol visibility changes render the
- symbol local.
-
- If on the other hand, we are creating an executable, we
- may need to keep relocations for symbols satisfied by a
- dynamic library if we manage to avoid copy relocs for the
- symbol. */
- if ((info->shared
- && (sec->flags & SEC_ALLOC) != 0
- && (((r_type != R_X86_64_PC8)
- && (r_type != R_X86_64_PC16)
- && (r_type != R_X86_64_PC32))
- || (h != NULL
- && (! info->symbolic
- || h->root.type == bfd_link_hash_defweak
- || (h->elf_link_hash_flags
- & ELF_LINK_HASH_DEF_REGULAR) == 0))))
- || (ELIMINATE_COPY_RELOCS
- && !info->shared
- && (sec->flags & SEC_ALLOC) != 0
- && h != NULL
- && (h->root.type == bfd_link_hash_defweak
- || (h->elf_link_hash_flags
- & ELF_LINK_HASH_DEF_REGULAR) == 0)))
+ later (it is never cleared). We account for that
+ possibility below by storing information in the
+ pcrel_relocs_copied field of the hash table entry.
+ A similar situation occurs when creating shared libraries
+ and symbol visibility changes render the symbol local. */
+ if (info->shared
+ && (sec->flags & SEC_ALLOC) != 0
+ && (((ELF64_R_TYPE (rel->r_info) != R_X86_64_PC8)
+ && (ELF64_R_TYPE (rel->r_info) != R_X86_64_PC16)
+ && (ELF64_R_TYPE (rel->r_info) != R_X86_64_PC32))
+ || (h != NULL
+ && (! info->symbolic
+ || (h->elf_link_hash_flags
+ & ELF_LINK_HASH_DEF_REGULAR) == 0))))
{
- struct elf64_x86_64_dyn_relocs *p;
- struct elf64_x86_64_dyn_relocs **head;
-
- /* We must copy these reloc types into the output file.
- Create a reloc section in dynobj and make room for
- this reloc. */
+ /* When creating a shared object, we must copy these
+ reloc types into the output file. We create a reloc
+ section in dynobj and make room for this reloc. */
if (sreloc == NULL)
{
const char *name;
- bfd *dynobj;
name = (bfd_elf_string_from_elf_section
(abfd,
elf_elfheader (abfd)->e_shstrndx,
elf_section_data (sec)->rel_hdr.sh_name));
if (name == NULL)
- return FALSE;
-
- if (strncmp (name, ".rela", 5) != 0
- || strcmp (bfd_get_section_name (abfd, sec),
- name + 5) != 0)
- {
- (*_bfd_error_handler)
- (_("%s: bad relocation section name `%s\'"),
- bfd_archive_filename (abfd), name);
- }
+ return false;
- if (htab->elf.dynobj == NULL)
- htab->elf.dynobj = abfd;
-
- dynobj = htab->elf.dynobj;
+ BFD_ASSERT (strncmp (name, ".rela", 5) == 0
+ && strcmp (bfd_get_section_name (abfd, sec),
+ name + 5) == 0);
sreloc = bfd_get_section_by_name (dynobj, name);
if (sreloc == NULL)
@@ -898,211 +543,174 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
if (sreloc == NULL
|| ! bfd_set_section_flags (dynobj, sreloc, flags)
|| ! bfd_set_section_alignment (dynobj, sreloc, 3))
- return FALSE;
+ return false;
}
- elf_section_data (sec)->sreloc = sreloc;
}
- /* If this is a global symbol, we count the number of
- relocations we need for this symbol. */
- if (h != NULL)
+ sreloc->_raw_size += sizeof (Elf64_External_Rela);
+
+ /* If this is a global symbol, we count the number of PC
+ relative relocations we have entered for this symbol,
+ so that we can discard them later as necessary. Note
+ that this function is only called if we are using an
+ elf64_x86_64 linker hash table, which means that h is
+ really a pointer to an elf64_x86_64_link_hash_entry. */
+ if (h != NULL
+ && ((ELF64_R_TYPE (rel->r_info) == R_X86_64_PC8)
+ || (ELF64_R_TYPE (rel->r_info) == R_X86_64_PC16)
+ || (ELF64_R_TYPE (rel->r_info) == R_X86_64_PC32)))
{
- head = &((struct elf64_x86_64_link_hash_entry *) h)->dyn_relocs;
- }
- else
- {
- /* Track dynamic relocs needed for local syms too.
- We really need local syms available to do this
- easily. Oh well. */
-
- asection *s;
- s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
- sec, r_symndx);
- if (s == NULL)
- return FALSE;
-
- head = ((struct elf64_x86_64_dyn_relocs **)
- &elf_section_data (s)->local_dynrel);
- }
+ struct elf64_x86_64_link_hash_entry *eh;
+ struct elf64_x86_64_pcrel_relocs_copied *p;
- p = *head;
- if (p == NULL || p->sec != sec)
- {
- bfd_size_type amt = sizeof *p;
- p = ((struct elf64_x86_64_dyn_relocs *)
- bfd_alloc (htab->elf.dynobj, amt));
- if (p == NULL)
- return FALSE;
- p->next = *head;
- *head = p;
- p->sec = sec;
- p->count = 0;
- p->pc_count = 0;
- }
-
- p->count += 1;
- if (r_type == R_X86_64_PC8
- || r_type == R_X86_64_PC16
- || r_type == R_X86_64_PC32)
- p->pc_count += 1;
- }
- break;
+ eh = (struct elf64_x86_64_link_hash_entry *) h;
- /* This relocation describes the C++ object vtable hierarchy.
- Reconstruct it for later use during GC. */
- case R_X86_64_GNU_VTINHERIT:
- if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
- return FALSE;
- break;
+ for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next)
+ if (p->section == sreloc)
+ break;
- /* This relocation describes which C++ vtable entries are actually
- used. Record for later use during GC. */
- case R_X86_64_GNU_VTENTRY:
- if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
- return FALSE;
- break;
+ if (p == NULL)
+ {
+ p = ((struct elf64_x86_64_pcrel_relocs_copied *)
+ bfd_alloc (dynobj, sizeof *p));
+ if (p == NULL)
+ return false;
+ p->next = eh->pcrel_relocs_copied;
+ eh->pcrel_relocs_copied = p;
+ p->section = sreloc;
+ p->count = 0;
+ }
- default:
+ ++p->count;
+ }
+ }
break;
}
}
- return TRUE;
+ return true;
}
/* Return the section that should be marked against GC for a given
relocation. */
static asection *
-elf64_x86_64_gc_mark_hook (asection *sec,
- struct bfd_link_info *info ATTRIBUTE_UNUSED,
- Elf_Internal_Rela *rel,
- struct elf_link_hash_entry *h,
- Elf_Internal_Sym *sym)
+elf64_x86_64_gc_mark_hook (abfd, info, rel, h, sym)
+ bfd *abfd;
+ struct bfd_link_info *info ATTRIBUTE_UNUSED;
+ Elf_Internal_Rela *rel ATTRIBUTE_UNUSED;
+ struct elf_link_hash_entry *h;
+ Elf_Internal_Sym *sym;
{
if (h != NULL)
{
- switch (ELF64_R_TYPE (rel->r_info))
+ switch (h->root.type)
{
- case R_X86_64_GNU_VTINHERIT:
- case R_X86_64_GNU_VTENTRY:
- break;
+ case bfd_link_hash_defined:
+ case bfd_link_hash_defweak:
+ return h->root.u.def.section;
- default:
- switch (h->root.type)
- {
- case bfd_link_hash_defined:
- case bfd_link_hash_defweak:
- return h->root.u.def.section;
-
- case bfd_link_hash_common:
- return h->root.u.c.p->section;
+ case bfd_link_hash_common:
+ return h->root.u.c.p->section;
- default:
- break;
- }
+ default:
+ break;
}
}
else
- return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
+ {
+ if (!(elf_bad_symtab (abfd)
+ && ELF_ST_BIND (sym->st_info) != STB_LOCAL)
+ && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)
+ && sym->st_shndx != SHN_COMMON))
+ {
+ return bfd_section_from_elf_index (abfd, sym->st_shndx);
+ }
+ }
return NULL;
}
/* Update the got entry reference counts for the section being removed. */
-static bfd_boolean
-elf64_x86_64_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
- asection *sec, const Elf_Internal_Rela *relocs)
+static boolean
+elf64_x86_64_gc_sweep_hook (abfd, info, sec, relocs)
+ bfd *abfd;
+ struct bfd_link_info *info ATTRIBUTE_UNUSED;
+ asection *sec;
+ const Elf_Internal_Rela *relocs;
{
Elf_Internal_Shdr *symtab_hdr;
struct elf_link_hash_entry **sym_hashes;
bfd_signed_vma *local_got_refcounts;
const Elf_Internal_Rela *rel, *relend;
-
- elf_section_data (sec)->local_dynrel = NULL;
+ unsigned long r_symndx;
+ struct elf_link_hash_entry *h;
+ bfd *dynobj;
+ asection *sgot;
+ asection *srelgot;
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
sym_hashes = elf_sym_hashes (abfd);
local_got_refcounts = elf_local_got_refcounts (abfd);
- relend = relocs + sec->reloc_count;
- for (rel = relocs; rel < relend; rel++)
- {
- unsigned long r_symndx;
- unsigned int r_type;
- struct elf_link_hash_entry *h = NULL;
-
- r_symndx = ELF64_R_SYM (rel->r_info);
- if (r_symndx >= symtab_hdr->sh_info)
- {
- struct elf64_x86_64_link_hash_entry *eh;
- struct elf64_x86_64_dyn_relocs **pp;
- struct elf64_x86_64_dyn_relocs *p;
+ dynobj = elf_hash_table (info)->dynobj;
+ if (dynobj == NULL)
+ return true;
- h = sym_hashes[r_symndx - symtab_hdr->sh_info];
- eh = (struct elf64_x86_64_link_hash_entry *) h;
+ sgot = bfd_get_section_by_name (dynobj, ".got");
+ srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
- for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
- if (p->sec == sec)
+ relend = relocs + sec->reloc_count;
+ for (rel = relocs; rel < relend; rel++)
+ switch (ELF64_R_TYPE (rel->r_info))
+ {
+ case R_X86_64_GOT32:
+ case R_X86_64_GOTPCREL:
+ r_symndx = ELF64_R_SYM (rel->r_info);
+ if (r_symndx >= symtab_hdr->sh_info)
+ {
+ h = sym_hashes[r_symndx - symtab_hdr->sh_info];
+ if (h->got.refcount > 0)
{
- /* Everything must go for SEC. */
- *pp = p->next;
- break;
- }
- }
-
- r_type = ELF64_R_TYPE (rel->r_info);
- r_type = elf64_x86_64_tls_transition (info, r_type, h != NULL);
- switch (r_type)
- {
- case R_X86_64_TLSLD:
- if (elf64_x86_64_hash_table (info)->tls_ld_got.refcount > 0)
- elf64_x86_64_hash_table (info)->tls_ld_got.refcount -= 1;
- break;
-
- case R_X86_64_TLSGD:
- case R_X86_64_GOTTPOFF:
- case R_X86_64_GOT32:
- case R_X86_64_GOTPCREL:
- if (h != NULL)
- {
- if (h->got.refcount > 0)
h->got.refcount -= 1;
- }
- else if (local_got_refcounts != NULL)
- {
- if (local_got_refcounts[r_symndx] > 0)
+ if (h->got.refcount == 0)
+ {
+ sgot->_raw_size -= GOT_ENTRY_SIZE;
+ srelgot->_raw_size -= sizeof (Elf64_External_Rela);
+ }
+ }
+ }
+ else if (local_got_refcounts != NULL)
+ {
+ if (local_got_refcounts[r_symndx] > 0)
+ {
local_got_refcounts[r_symndx] -= 1;
- }
- break;
-
- case R_X86_64_8:
- case R_X86_64_16:
- case R_X86_64_32:
- case R_X86_64_64:
- case R_X86_64_32S:
- case R_X86_64_PC8:
- case R_X86_64_PC16:
- case R_X86_64_PC32:
- if (info->shared)
- break;
- /* Fall thru */
+ if (local_got_refcounts[r_symndx] == 0)
+ {
+ sgot->_raw_size -= GOT_ENTRY_SIZE;
+ if (info->shared)
+ srelgot->_raw_size -= sizeof (Elf64_External_Rela);
+ }
+ }
+ }
+ break;
- case R_X86_64_PLT32:
- if (h != NULL)
- {
- if (h->plt.refcount > 0)
- h->plt.refcount -= 1;
- }
- break;
+ case R_X86_64_PLT32:
+ r_symndx = ELF64_R_SYM (rel->r_info);
+ if (r_symndx >= symtab_hdr->sh_info)
+ {
+ h = sym_hashes[r_symndx - symtab_hdr->sh_info];
+ if (h->plt.refcount > 0)
+ h->plt.refcount -= 1;
+ }
+ break;
- default:
- break;
- }
- }
+ default:
+ break;
+ }
- return TRUE;
+ return true;
}
/* Adjust a symbol defined by a dynamic object and referenced by a
@@ -1111,24 +719,38 @@ elf64_x86_64_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
change the definition to something the rest of the link can
understand. */
-static bfd_boolean
-elf64_x86_64_adjust_dynamic_symbol (struct bfd_link_info *info,
- struct elf_link_hash_entry *h)
+static boolean
+elf64_x86_64_adjust_dynamic_symbol (info, h)
+ struct bfd_link_info *info;
+ struct elf_link_hash_entry *h;
{
- struct elf64_x86_64_link_hash_table *htab;
+ bfd *dynobj;
asection *s;
unsigned int power_of_two;
+ dynobj = elf_hash_table (info)->dynobj;
+
+ /* Make sure we know what is going on here. */
+ BFD_ASSERT (dynobj != NULL
+ && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
+ || h->weakdef != NULL
+ || ((h->elf_link_hash_flags
+ & ELF_LINK_HASH_DEF_DYNAMIC) != 0
+ && (h->elf_link_hash_flags
+ & ELF_LINK_HASH_REF_REGULAR) != 0
+ && (h->elf_link_hash_flags
+ & ELF_LINK_HASH_DEF_REGULAR) == 0)));
+
/* If this is a function, put it in the procedure linkage table. We
will fill in the contents of the procedure linkage table later,
when we know the address of the .got section. */
if (h->type == STT_FUNC
|| (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
{
- if (h->plt.refcount <= 0
- || SYMBOL_CALLS_LOCAL (info, h)
- || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
- && h->root.type == bfd_link_hash_undefweak))
+ if ((! info->shared
+ && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
+ && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0)
+ || (info->shared && h->plt.refcount <= 0))
{
/* This case can occur if we saw a PLT32 reloc in an input
file, but the symbol was never referred to by a dynamic
@@ -1137,17 +759,54 @@ elf64_x86_64_adjust_dynamic_symbol (struct bfd_link_info *info,
linkage table, and we can just do a PC32 reloc instead. */
h->plt.offset = (bfd_vma) -1;
h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
+ return true;
}
- return TRUE;
+ /* Make sure this symbol is output as a dynamic symbol. */
+ if (h->dynindx == -1)
+ {
+ if (! bfd_elf64_link_record_dynamic_symbol (info, h))
+ return false;
+ }
+
+ s = bfd_get_section_by_name (dynobj, ".plt");
+ BFD_ASSERT (s != NULL);
+
+ /* If this is the first .plt entry, make room for the special
+ first entry. */
+ if (s->_raw_size == 0)
+ s->_raw_size = PLT_ENTRY_SIZE;
+
+ /* If this symbol is not defined in a regular file, and we are
+ not generating a shared library, then set the symbol to this
+ location in the .plt. This is required to make function
+ pointers compare as equal between the normal executable and
+ the shared library. */
+ if (! info->shared
+ && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
+ {
+ h->root.u.def.section = s;
+ h->root.u.def.value = s->_raw_size;
+ }
+
+ h->plt.offset = s->_raw_size;
+
+ /* Make room for this entry. */
+ s->_raw_size += PLT_ENTRY_SIZE;
+
+ /* We also need to make an entry in the .got.plt section, which
+ will be placed in the .got section by the linker script. */
+ s = bfd_get_section_by_name (dynobj, ".got.plt");
+ BFD_ASSERT (s != NULL);
+ s->_raw_size += GOT_ENTRY_SIZE;
+
+ /* We also need to make an entry in the .rela.plt section. */
+ s = bfd_get_section_by_name (dynobj, ".rela.plt");
+ BFD_ASSERT (s != NULL);
+ s->_raw_size += sizeof (Elf64_External_Rela);
+
+ return true;
}
- else
- /* It's possible that we incorrectly decided a .plt reloc was
- needed for an R_X86_64_PC32 reloc to a non-function sym in
- check_relocs. We can't decide accurately between function and
- non-function syms in check-relocs; Objects loaded later in
- the link may change h->type. So fix it now. */
- h->plt.offset = (bfd_vma) -1;
/* If this is a weak symbol, and there is a real definition, the
processor independent code will have arranged for us to see the
@@ -1158,11 +817,7 @@ elf64_x86_64_adjust_dynamic_symbol (struct bfd_link_info *info,
|| 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;
- if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
- h->elf_link_hash_flags
- = ((h->elf_link_hash_flags & ~ELF_LINK_NON_GOT_REF)
- | (h->weakdef->elf_link_hash_flags & ELF_LINK_NON_GOT_REF));
- return TRUE;
+ return true;
}
/* This is a reference to a symbol defined by a dynamic object which
@@ -1173,41 +828,12 @@ elf64_x86_64_adjust_dynamic_symbol (struct bfd_link_info *info,
For such cases we need not do anything here; the relocations will
be handled correctly by relocate_section. */
if (info->shared)
- return TRUE;
+ return true;
/* If there are no references to this symbol that do not use the
GOT, we don't need to generate a copy reloc. */
if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
- return TRUE;
-
- /* If -z nocopyreloc was given, we won't generate them either. */
- if (info->nocopyreloc)
- {
- h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
- return TRUE;
- }
-
- if (ELIMINATE_COPY_RELOCS)
- {
- struct elf64_x86_64_link_hash_entry * eh;
- struct elf64_x86_64_dyn_relocs *p;
-
- eh = (struct elf64_x86_64_link_hash_entry *) h;
- for (p = eh->dyn_relocs; p != NULL; p = p->next)
- {
- s = p->sec->output_section;
- if (s != NULL && (s->flags & SEC_READONLY) != 0)
- break;
- }
-
- /* If we didn't find any dynamic relocs in read-only sections, then
- we'll be keeping the dynamic relocs and avoiding the copy reloc. */
- if (p == NULL)
- {
- h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
- return TRUE;
- }
- }
+ return true;
/* We must allocate the symbol in our .dynbss section, which will
become part of the .bss section of the executable. There will be
@@ -1219,14 +845,20 @@ elf64_x86_64_adjust_dynamic_symbol (struct bfd_link_info *info,
both the dynamic object and the regular object will refer to the
same memory location for the variable. */
- htab = elf64_x86_64_hash_table (info);
+ s = bfd_get_section_by_name (dynobj, ".dynbss");
+ BFD_ASSERT (s != NULL);
/* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
to copy the initial value out of the dynamic object and into the
- runtime process image. */
+ runtime process image. We need to remember the offset into the
+ .rela.bss section we are going to use. */
if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
{
- htab->srelbss->_raw_size += sizeof (Elf64_External_Rela);
+ asection *srel;
+
+ srel = bfd_get_section_by_name (dynobj, ".rela.bss");
+ BFD_ASSERT (srel != NULL);
+ srel->_raw_size += sizeof (Elf64_External_Rela);
h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
}
@@ -1240,12 +872,11 @@ elf64_x86_64_adjust_dynamic_symbol (struct bfd_link_info *info,
power_of_two = 4;
/* Apply the required alignment. */
- s = htab->sdynbss;
s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two));
- if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
+ if (power_of_two > bfd_get_section_alignment (dynobj, s))
{
- if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
- return FALSE;
+ if (! bfd_set_section_alignment (dynobj, s, power_of_two))
+ return false;
}
/* Define the symbol as being at this point in the section. */
@@ -1255,401 +886,142 @@ elf64_x86_64_adjust_dynamic_symbol (struct bfd_link_info *info,
/* Increment the section size to make room for the symbol. */
s->_raw_size += h->size;
- return TRUE;
-}
-
-/* Allocate space in .plt, .got and associated reloc sections for
- dynamic relocs. */
-
-static bfd_boolean
-allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
-{
- struct bfd_link_info *info;
- struct elf64_x86_64_link_hash_table *htab;
- struct elf64_x86_64_link_hash_entry *eh;
- struct elf64_x86_64_dyn_relocs *p;
-
- if (h->root.type == bfd_link_hash_indirect)
- return TRUE;
-
- if (h->root.type == bfd_link_hash_warning)
- h = (struct elf_link_hash_entry *) h->root.u.i.link;
-
- info = (struct bfd_link_info *) inf;
- htab = elf64_x86_64_hash_table (info);
-
- if (htab->elf.dynamic_sections_created
- && h->plt.refcount > 0)
- {
- /* Make sure this symbol is output as a dynamic symbol.
- Undefined weak syms won't yet be marked as dynamic. */
- if (h->dynindx == -1
- && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
- {
- if (! bfd_elf_link_record_dynamic_symbol (info, h))
- return FALSE;
- }
-
- if (info->shared
- || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
- {
- asection *s = htab->splt;
-
- /* If this is the first .plt entry, make room for the special
- first entry. */
- if (s->_raw_size == 0)
- s->_raw_size += PLT_ENTRY_SIZE;
-
- h->plt.offset = s->_raw_size;
-
- /* If this symbol is not defined in a regular file, and we are
- not generating a shared library, then set the symbol to this
- location in the .plt. This is required to make function
- pointers compare as equal between the normal executable and
- the shared library. */
- if (! info->shared
- && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
- {
- h->root.u.def.section = s;
- h->root.u.def.value = h->plt.offset;
- }
-
- /* Make room for this entry. */
- s->_raw_size += PLT_ENTRY_SIZE;
-
- /* We also need to make an entry in the .got.plt section, which
- will be placed in the .got section by the linker script. */
- htab->sgotplt->_raw_size += GOT_ENTRY_SIZE;
-
- /* We also need to make an entry in the .rela.plt section. */
- htab->srelplt->_raw_size += sizeof (Elf64_External_Rela);
- }
- else
- {
- h->plt.offset = (bfd_vma) -1;
- h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
- }
- }
- else
- {
- h->plt.offset = (bfd_vma) -1;
- h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
- }
-
- /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
- make it a R_X86_64_TPOFF32 requiring no GOT entry. */
- if (h->got.refcount > 0
- && !info->shared
- && h->dynindx == -1
- && elf64_x86_64_hash_entry (h)->tls_type == GOT_TLS_IE)
- h->got.offset = (bfd_vma) -1;
- else if (h->got.refcount > 0)
- {
- asection *s;
- bfd_boolean dyn;
- int tls_type = elf64_x86_64_hash_entry (h)->tls_type;
-
- /* Make sure this symbol is output as a dynamic symbol.
- Undefined weak syms won't yet be marked as dynamic. */
- if (h->dynindx == -1
- && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
- {
- if (! bfd_elf_link_record_dynamic_symbol (info, h))
- return FALSE;
- }
-
- s = htab->sgot;
- h->got.offset = s->_raw_size;
- s->_raw_size += GOT_ENTRY_SIZE;
- /* R_X86_64_TLSGD needs 2 consecutive GOT slots. */
- if (tls_type == GOT_TLS_GD)
- s->_raw_size += GOT_ENTRY_SIZE;
- dyn = htab->elf.dynamic_sections_created;
- /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
- and two if global.
- R_X86_64_GOTTPOFF needs one dynamic relocation. */
- if ((tls_type == GOT_TLS_GD && h->dynindx == -1)
- || tls_type == GOT_TLS_IE)
- htab->srelgot->_raw_size += sizeof (Elf64_External_Rela);
- else if (tls_type == GOT_TLS_GD)
- htab->srelgot->_raw_size += 2 * sizeof (Elf64_External_Rela);
- else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
- || h->root.type != bfd_link_hash_undefweak)
- && (info->shared
- || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
- htab->srelgot->_raw_size += sizeof (Elf64_External_Rela);
- }
- else
- h->got.offset = (bfd_vma) -1;
-
- eh = (struct elf64_x86_64_link_hash_entry *) h;
- if (eh->dyn_relocs == NULL)
- return TRUE;
-
- /* In the shared -Bsymbolic case, discard space allocated for
- dynamic pc-relative relocs against symbols which turn out to be
- defined in regular objects. For the normal shared case, discard
- space for pc-relative relocs that have become local due to symbol
- visibility changes. */
-
- if (info->shared)
- {
- /* Relocs that use pc_count are those that appear on a call
- insn, or certain REL relocs that can generated via assembly.
- We want calls to protected symbols to resolve directly to the
- function rather than going via the plt. If people want
- function pointer comparisons to work as expected then they
- should avoid writing weird assembly. */
- if (SYMBOL_CALLS_LOCAL (info, h))
- {
- struct elf64_x86_64_dyn_relocs **pp;
-
- for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
- {
- p->count -= p->pc_count;
- p->pc_count = 0;
- if (p->count == 0)
- *pp = p->next;
- else
- pp = &p->next;
- }
- }
-
- /* Also discard relocs on undefined weak syms with non-default
- visibility. */
- if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
- && h->root.type == bfd_link_hash_undefweak)
- eh->dyn_relocs = NULL;
- }
- else if (ELIMINATE_COPY_RELOCS)
- {
- /* For the non-shared case, discard space for relocs against
- symbols which turn out to need copy relocs or are not
- dynamic. */
-
- if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
- && (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
- && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
- || (htab->elf.dynamic_sections_created
- && (h->root.type == bfd_link_hash_undefweak
- || h->root.type == bfd_link_hash_undefined))))
- {
- /* Make sure this symbol is output as a dynamic symbol.
- Undefined weak syms won't yet be marked as dynamic. */
- if (h->dynindx == -1
- && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
- {
- if (! bfd_elf_link_record_dynamic_symbol (info, h))
- return FALSE;
- }
-
- /* If that succeeded, we know we'll be keeping all the
- relocs. */
- if (h->dynindx != -1)
- goto keep;
- }
-
- eh->dyn_relocs = NULL;
-
- keep: ;
- }
-
- /* Finally, allocate space. */
- for (p = eh->dyn_relocs; p != NULL; p = p->next)
- {
- asection *sreloc = elf_section_data (p->sec)->sreloc;
- sreloc->_raw_size += p->count * sizeof (Elf64_External_Rela);
- }
-
- return TRUE;
-}
-
-/* Find any dynamic relocs that apply to read-only sections. */
-
-static bfd_boolean
-readonly_dynrelocs (struct elf_link_hash_entry *h, void * inf)
-{
- struct elf64_x86_64_link_hash_entry *eh;
- struct elf64_x86_64_dyn_relocs *p;
-
- if (h->root.type == bfd_link_hash_warning)
- h = (struct elf_link_hash_entry *) h->root.u.i.link;
-
- eh = (struct elf64_x86_64_link_hash_entry *) h;
- for (p = eh->dyn_relocs; p != NULL; p = p->next)
- {
- asection *s = p->sec->output_section;
-
- if (s != NULL && (s->flags & SEC_READONLY) != 0)
- {
- struct bfd_link_info *info = (struct bfd_link_info *) inf;
-
- info->flags |= DF_TEXTREL;
-
- /* Not an error, just cut short the traversal. */
- return FALSE;
- }
- }
- return TRUE;
+ return true;
}
/* Set the sizes of the dynamic sections. */
-static bfd_boolean
-elf64_x86_64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
- struct bfd_link_info *info)
+static boolean
+elf64_x86_64_size_dynamic_sections (output_bfd, info)
+ bfd *output_bfd;
+ struct bfd_link_info *info;
{
- struct elf64_x86_64_link_hash_table *htab;
bfd *dynobj;
asection *s;
- bfd_boolean relocs;
- bfd *ibfd;
+ boolean plt;
+ boolean relocs;
+ boolean reltext;
- htab = elf64_x86_64_hash_table (info);
- dynobj = htab->elf.dynobj;
- if (dynobj == NULL)
- abort ();
+ dynobj = elf_hash_table (info)->dynobj;
+ BFD_ASSERT (dynobj != NULL);
- if (htab->elf.dynamic_sections_created)
+ if (elf_hash_table (info)->dynamic_sections_created)
{
/* Set the contents of the .interp section to the interpreter. */
- if (info->executable)
+ if (! info->shared)
{
s = bfd_get_section_by_name (dynobj, ".interp");
- if (s == NULL)
- abort ();
+ BFD_ASSERT (s != NULL);
s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
}
}
+ else
+ {
+ /* We may have created entries in the .rela.got section.
+ However, if we are not creating the dynamic sections, we will
+ not actually use these entries. Reset the size of .rela.got,
+ which will cause it to get stripped from the output file
+ below. */
+ s = bfd_get_section_by_name (dynobj, ".rela.got");
+ if (s != NULL)
+ s->_raw_size = 0;
+ }
- /* Set up .got offsets for local syms, and space for local dynamic
- relocs. */
- for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
+ /* If this is a -Bsymbolic shared link, then we need to discard all
+ PC relative relocs against symbols defined in a regular object.
+ We allocated space for them in the check_relocs routine, but we
+ will not fill them in in the relocate_section routine. */
+ if (info->shared)
+ elf64_x86_64_link_hash_traverse (elf64_x86_64_hash_table (info),
+ elf64_x86_64_discard_copies,
+ (PTR) info);
+
+ /* The check_relocs and adjust_dynamic_symbol entry points have
+ determined the sizes of the various dynamic sections. Allocate
+ memory for them. */
+ plt = relocs = reltext = false;
+ for (s = dynobj->sections; s != NULL; s = s->next)
{
- bfd_signed_vma *local_got;
- bfd_signed_vma *end_local_got;
- char *local_tls_type;
- bfd_size_type locsymcount;
- Elf_Internal_Shdr *symtab_hdr;
- asection *srel;
+ const char *name;
+ boolean strip;
- if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
+ if ((s->flags & SEC_LINKER_CREATED) == 0)
continue;
- for (s = ibfd->sections; s != NULL; s = s->next)
- {
- struct elf64_x86_64_dyn_relocs *p;
+ /* 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, s);
- for (p = *((struct elf64_x86_64_dyn_relocs **)
- &elf_section_data (s)->local_dynrel);
- p != NULL;
- p = p->next)
+ strip = false;
+ if (strcmp (name, ".plt") == 0)
+ {
+ if (s->_raw_size == 0)
{
- if (!bfd_is_abs_section (p->sec)
- && bfd_is_abs_section (p->sec->output_section))
- {
- /* Input section has been discarded, either because
- it is a copy of a linkonce section or due to
- linker script /DISCARD/, so we'll be discarding
- the relocs too. */
- }
- else if (p->count != 0)
- {
- srel = elf_section_data (p->sec)->sreloc;
- srel->_raw_size += p->count * sizeof (Elf64_External_Rela);
- if ((p->sec->output_section->flags & SEC_READONLY) != 0)
- info->flags |= DF_TEXTREL;
-
- }
+ /* Strip this section if we don't need it; see the
+ comment below. */
+ strip = true;
+ }
+ else
+ {
+ /* Remember whether there is a PLT. */
+ plt = true;
}
}
-
- local_got = elf_local_got_refcounts (ibfd);
- if (!local_got)
- continue;
-
- symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
- locsymcount = symtab_hdr->sh_info;
- end_local_got = local_got + locsymcount;
- local_tls_type = elf64_x86_64_local_got_tls_type (ibfd);
- s = htab->sgot;
- srel = htab->srelgot;
- for (; local_got < end_local_got; ++local_got, ++local_tls_type)
+ else if (strncmp (name, ".rela", 5) == 0)
{
- if (*local_got > 0)
+ if (s->_raw_size == 0)
{
- *local_got = s->_raw_size;
- s->_raw_size += GOT_ENTRY_SIZE;
- if (*local_tls_type == GOT_TLS_GD)
- s->_raw_size += GOT_ENTRY_SIZE;
- if (info->shared
- || *local_tls_type == GOT_TLS_GD
- || *local_tls_type == GOT_TLS_IE)
- srel->_raw_size += sizeof (Elf64_External_Rela);
+ /* If we don't need this section, strip it from the
+ output file. This is mostly to handle .rela.bss and
+ .rela.plt. We must create both sections in
+ create_dynamic_sections, because they must be created
+ before the linker maps input sections to output
+ sections. The linker does that before
+ adjust_dynamic_symbol is called, and it is that
+ function which decides whether anything needs to go
+ into these sections. */
+ strip = true;
}
else
- *local_got = (bfd_vma) -1;
- }
- }
-
- if (htab->tls_ld_got.refcount > 0)
- {
- /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
- relocs. */
- htab->tls_ld_got.offset = htab->sgot->_raw_size;
- htab->sgot->_raw_size += 2 * GOT_ENTRY_SIZE;
- htab->srelgot->_raw_size += sizeof (Elf64_External_Rela);
- }
- else
- htab->tls_ld_got.offset = -1;
-
- /* Allocate global sym .plt and .got entries, and space for global
- sym dynamic relocs. */
- elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info);
-
- /* We now have determined the sizes of the various dynamic sections.
- Allocate memory for them. */
- relocs = FALSE;
- for (s = dynobj->sections; s != NULL; s = s->next)
- {
- if ((s->flags & SEC_LINKER_CREATED) == 0)
- continue;
+ {
+ asection *target;
- if (s == htab->splt
- || s == htab->sgot
- || s == htab->sgotplt)
- {
- /* Strip this section if we don't need it; see the
- comment below. */
- }
- else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
- {
- if (s->_raw_size != 0 && s != htab->srelplt)
- relocs = TRUE;
+ /* Remember whether there are any reloc sections other
+ than .rela.plt. */
+ if (strcmp (name, ".rela.plt") != 0)
+ {
+ const char *outname;
+
+ relocs = true;
+
+ /* If this relocation section applies to a read only
+ section, then we probably need a DT_TEXTREL
+ entry. The entries in the .rela.plt section
+ really apply to the .got section, which we
+ created ourselves and so know is not readonly. */
+ outname = bfd_get_section_name (output_bfd,
+ s->output_section);
+ target = bfd_get_section_by_name (output_bfd, outname + 5);
+ 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. */
- s->reloc_count = 0;
+ /* We use the reloc_count field as a counter if we need
+ to copy relocs into the output file. */
+ s->reloc_count = 0;
+ }
}
- else
+ else if (strncmp (name, ".got", 4) != 0)
{
/* It's not one of our sections, so don't allocate space. */
continue;
}
- if (s->_raw_size == 0)
+ if (strip)
{
- /* If we don't need this section, strip it from the
- output file. This is mostly to handle .rela.bss and
- .rela.plt. We must create both sections in
- create_dynamic_sections, because they must be created
- before the linker maps input sections to output
- sections. The linker does that before
- adjust_dynamic_symbol is called, and it is that
- function which decides whether anything needs to go
- into these sections. */
-
_bfd_strip_section_from_output (info, s);
continue;
}
@@ -1660,160 +1032,249 @@ elf64_x86_64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
but this way if it does, we get a R_X86_64_NONE reloc instead
of garbage. */
s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
- if (s->contents == NULL)
- return FALSE;
+ if (s->contents == NULL && s->_raw_size != 0)
+ return false;
}
- if (htab->elf.dynamic_sections_created)
+ if (elf_hash_table (info)->dynamic_sections_created)
{
/* Add some entries to the .dynamic section. We fill in the
values later, in elf64_x86_64_finish_dynamic_sections, but we
must add the entries now so that we get the correct size for
the .dynamic section. The DT_DEBUG entry is filled in by the
dynamic linker and used by the debugger. */
-#define add_dynamic_entry(TAG, VAL) \
- _bfd_elf_add_dynamic_entry (info, TAG, VAL)
-
- if (info->executable)
+ if (! info->shared)
{
- if (!add_dynamic_entry (DT_DEBUG, 0))
- return FALSE;
+ if (! bfd_elf64_add_dynamic_entry (info, DT_DEBUG, 0))
+ return false;
}
- if (htab->splt->_raw_size != 0)
+ if (plt)
{
- if (!add_dynamic_entry (DT_PLTGOT, 0)
- || !add_dynamic_entry (DT_PLTRELSZ, 0)
- || !add_dynamic_entry (DT_PLTREL, DT_RELA)
- || !add_dynamic_entry (DT_JMPREL, 0))
- return FALSE;
+ if (! bfd_elf64_add_dynamic_entry (info, DT_PLTGOT, 0)
+ || ! bfd_elf64_add_dynamic_entry (info, DT_PLTRELSZ, 0)
+ || ! bfd_elf64_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
+ || ! bfd_elf64_add_dynamic_entry (info, DT_JMPREL, 0))
+ return false;
}
if (relocs)
{
- if (!add_dynamic_entry (DT_RELA, 0)
- || !add_dynamic_entry (DT_RELASZ, 0)
- || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
- return FALSE;
-
- /* If any dynamic relocs apply to a read-only section,
- then we need a DT_TEXTREL entry. */
- if ((info->flags & DF_TEXTREL) == 0)
- elf_link_hash_traverse (&htab->elf, readonly_dynrelocs,
- (PTR) info);
-
- if ((info->flags & DF_TEXTREL) != 0)
- {
- if (!add_dynamic_entry (DT_TEXTREL, 0))
- return FALSE;
- }
+ if (! bfd_elf64_add_dynamic_entry (info, DT_RELA, 0)
+ || ! bfd_elf64_add_dynamic_entry (info, DT_RELASZ, 0)
+ || ! bfd_elf64_add_dynamic_entry (info, DT_RELAENT,
+ sizeof (Elf64_External_Rela)))
+ return false;
}
- }
-#undef add_dynamic_entry
- return TRUE;
-}
-
-/* Return the base VMA address which should be subtracted from real addresses
- when resolving @dtpoff relocation.
- This is PT_TLS segment p_vaddr. */
+ if (reltext)
+ {
+ if (! bfd_elf64_add_dynamic_entry (info, DT_TEXTREL, 0))
+ return false;
+ info->flags |= DF_TEXTREL;
+ }
+ }
-static bfd_vma
-dtpoff_base (struct bfd_link_info *info)
-{
- /* If tls_sec is NULL, we should have signalled an error already. */
- if (elf_hash_table (info)->tls_sec == NULL)
- return 0;
- return elf_hash_table (info)->tls_sec->vma;
+ return true;
}
-/* Return the relocation value for @tpoff relocation
- if STT_TLS virtual address is ADDRESS. */
-
-static bfd_vma
-tpoff (struct bfd_link_info *info, bfd_vma address)
+/* This function is called via elf64_x86_64_link_hash_traverse if we are
+ creating a shared object. In the -Bsymbolic case, it discards the
+ space allocated to copy PC relative relocs against symbols which
+ are defined in regular objects. For the normal non-symbolic case,
+ we also discard space for relocs that have become local due to
+ symbol visibility changes. We allocated space for them in the
+ check_relocs routine, but we won't fill them in in the
+ relocate_section routine. */
+
+static boolean
+elf64_x86_64_discard_copies (h, inf)
+ struct elf64_x86_64_link_hash_entry *h;
+ PTR inf;
{
- struct elf_link_hash_table *htab = elf_hash_table (info);
+ struct elf64_x86_64_pcrel_relocs_copied *s;
+ struct bfd_link_info *info = (struct bfd_link_info *) inf;
+
+ /* If a symbol has been forced local or we have found a regular
+ definition for the symbolic link case, then we won't be needing
+ any relocs. */
+ if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
+ && ((h->root.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
+ || info->symbolic))
+ {
+ for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)
+ s->section->_raw_size -= s->count * sizeof (Elf64_External_Rela);
+ }
- /* If tls_segment is NULL, we should have signalled an error already. */
- if (htab->tls_sec == NULL)
- return 0;
- return address - htab->tls_size - htab->tls_sec->vma;
+ return true;
}
/* Relocate an x86_64 ELF section. */
-static bfd_boolean
-elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
- bfd *input_bfd, asection *input_section,
- bfd_byte *contents, Elf_Internal_Rela *relocs,
- Elf_Internal_Sym *local_syms,
- asection **local_sections)
+static boolean
+elf64_x86_64_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 elf64_x86_64_link_hash_table *htab;
+ bfd *dynobj;
Elf_Internal_Shdr *symtab_hdr;
struct elf_link_hash_entry **sym_hashes;
bfd_vma *local_got_offsets;
- Elf_Internal_Rela *rel;
+ asection *sgot;
+ asection *splt;
+ asection *sreloc;
+ Elf_Internal_Rela *rela;
Elf_Internal_Rela *relend;
- if (info->relocatable)
- return TRUE;
-
- htab = elf64_x86_64_hash_table (info);
+ dynobj = elf_hash_table (info)->dynobj;
symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
sym_hashes = elf_sym_hashes (input_bfd);
local_got_offsets = elf_local_got_offsets (input_bfd);
- rel = relocs;
+ sreloc = splt = sgot = NULL;
+ if (dynobj != NULL)
+ {
+ splt = bfd_get_section_by_name (dynobj, ".plt");
+ sgot = bfd_get_section_by_name (dynobj, ".got");
+ }
+
+ rela = relocs;
relend = relocs + input_section->reloc_count;
- for (; rel < relend; rel++)
+ for (; rela < relend; rela++)
{
- unsigned int r_type;
+ int r_type;
reloc_howto_type *howto;
unsigned long r_symndx;
struct elf_link_hash_entry *h;
Elf_Internal_Sym *sym;
asection *sec;
- bfd_vma off;
bfd_vma relocation;
- bfd_boolean unresolved_reloc;
bfd_reloc_status_type r;
- int tls_type;
+ unsigned int indx;
- r_type = ELF64_R_TYPE (rel->r_info);
- if (r_type == (int) R_X86_64_GNU_VTINHERIT
- || r_type == (int) R_X86_64_GNU_VTENTRY)
- continue;
+ r_type = ELF64_R_TYPE (rela->r_info);
- if (r_type >= R_X86_64_max)
+ if ((indx = (unsigned) r_type) >= R_X86_64_max)
{
bfd_set_error (bfd_error_bad_value);
- return FALSE;
+ return false;
}
+ howto = x86_64_elf_howto_table + indx;
- howto = x86_64_elf_howto_table + r_type;
- r_symndx = ELF64_R_SYM (rel->r_info);
+ r_symndx = ELF64_R_SYM (rela->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)
+ {
+ sec = local_sections[r_symndx];
+ rela->r_addend += sec->output_offset + sym->st_value;
+ }
+ }
+
+ continue;
+ }
+
+ /* This is a final link. */
h = NULL;
sym = NULL;
sec = NULL;
- unresolved_reloc = FALSE;
if (r_symndx < symtab_hdr->sh_info)
{
sym = local_syms + r_symndx;
sec = local_sections[r_symndx];
-
- relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
+ relocation = (sec->output_section->vma
+ + sec->output_offset
+ + sym->st_value);
}
else
{
- bfd_boolean warned;
-
- RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
- r_symndx, symtab_hdr, sym_hashes,
- h, sec, relocation,
- unresolved_reloc, warned);
+ h = sym_hashes[r_symndx - symtab_hdr->sh_info];
+ 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->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak)
+ {
+ sec = h->root.u.def.section;
+ if ((r_type == R_X86_64_PLT32
+ && splt != NULL
+ && h->plt.offset != (bfd_vma) -1)
+ || ((r_type == R_X86_64_GOT32 || r_type == R_X86_64_GOTPCREL)
+ && elf_hash_table (info)->dynamic_sections_created
+ && (!info->shared
+ || (! info->symbolic && h->dynindx != -1)
+ || (h->elf_link_hash_flags
+ & ELF_LINK_HASH_DEF_REGULAR) == 0))
+ || (info->shared
+ && ((! info->symbolic && h->dynindx != -1)
+ || (h->elf_link_hash_flags
+ & ELF_LINK_HASH_DEF_REGULAR) == 0)
+ && (r_type == R_X86_64_8
+ || r_type == R_X86_64_16
+ || r_type == R_X86_64_32
+ || r_type == R_X86_64_64
+ || r_type == R_X86_64_PC8
+ || r_type == R_X86_64_PC16
+ || r_type == R_X86_64_PC32)
+ && ((input_section->flags & SEC_ALLOC) != 0
+ /* DWARF will emit R_X86_64_32 relocations in its
+ sections against symbols defined externally
+ in shared libraries. We can't do anything
+ with them here. */
+ || ((input_section->flags & SEC_DEBUGGING) != 0
+ && (h->elf_link_hash_flags
+ & ELF_LINK_HASH_DEF_DYNAMIC) != 0))))
+ {
+ /* In these cases, we don't need the relocation
+ value. We check specially because in some
+ obscure cases sec->output_section will be NULL. */
+ relocation = 0;
+ }
+ else if (sec->output_section == NULL)
+ {
+ (*_bfd_error_handler)
+ (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"),
+ bfd_get_filename (input_bfd), h->root.root.string,
+ bfd_get_section_name (input_bfd, input_section));
+ relocation = 0;
+ }
+ else
+ relocation = (h->root.u.def.value
+ + sec->output_section->vma
+ + sec->output_offset);
+ }
+ else if (h->root.type == bfd_link_hash_undefweak)
+ relocation = 0;
+ else if (info->shared && !info->symbolic && !info->no_undefined
+ && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
+ relocation = 0;
+ else
+ {
+ if (! ((*info->callbacks->undefined_symbol)
+ (info, h->root.root.string, input_bfd,
+ input_section, rela->r_offset,
+ (!info->shared || info->no_undefined
+ || ELF_ST_VISIBILITY (h->other)))))
+ return false;
+ relocation = 0;
+ }
}
+
/* When generating a shared object, the relocations handled here are
copied into the output file to be resolved at run time. */
switch (r_type)
@@ -1823,21 +1284,17 @@ elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
offset table. */
case R_X86_64_GOTPCREL:
/* Use global offset table as symbol value. */
- if (htab->sgot == NULL)
- abort ();
+ BFD_ASSERT (sgot != NULL);
if (h != NULL)
{
- bfd_boolean dyn;
+ bfd_vma off = h->got.offset;
+ BFD_ASSERT (off != (bfd_vma) -1);
- off = h->got.offset;
- dyn = htab->elf.dynamic_sections_created;
-
- if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
+ if (! elf_hash_table (info)->dynamic_sections_created
|| (info->shared
- && SYMBOL_REFERENCES_LOCAL (info, h))
- || (ELF_ST_VISIBILITY (h->other)
- && h->root.type == bfd_link_hash_undefweak))
+ && (info->symbolic || h->dynindx == -1)
+ && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
{
/* This is actually a static link, or it is a -Bsymbolic
link and the symbol is defined locally, or the symbol
@@ -1855,17 +1312,21 @@ elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
else
{
bfd_put_64 (output_bfd, relocation,
- htab->sgot->contents + off);
+ sgot->contents + off);
h->got.offset |= 1;
}
}
+ if (r_type == R_X86_64_GOTPCREL)
+ relocation = sgot->output_section->vma + sgot->output_offset + off;
else
- unresolved_reloc = FALSE;
+ relocation = sgot->output_offset + off;
}
else
{
- if (local_got_offsets == NULL)
- abort ();
+ bfd_vma off;
+
+ BFD_ASSERT (local_got_offsets != NULL
+ && local_got_offsets[r_symndx] != (bfd_vma) -1);
off = local_got_offsets[r_symndx];
@@ -1876,41 +1337,38 @@ elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
off &= ~1;
else
{
- bfd_put_64 (output_bfd, relocation,
- htab->sgot->contents + off);
+ bfd_put_64 (output_bfd, relocation, sgot->contents + off);
if (info->shared)
{
- asection *s;
+ asection *srelgot;
Elf_Internal_Rela outrel;
- bfd_byte *loc;
/* We need to generate a R_X86_64_RELATIVE reloc
for the dynamic linker. */
- s = htab->srelgot;
- if (s == NULL)
- abort ();
+ srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
+ BFD_ASSERT (srelgot != NULL);
- outrel.r_offset = (htab->sgot->output_section->vma
- + htab->sgot->output_offset
+ outrel.r_offset = (sgot->output_section->vma
+ + sgot->output_offset
+ off);
outrel.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
outrel.r_addend = relocation;
- loc = s->contents;
- loc += s->reloc_count++ * sizeof (Elf64_External_Rela);
- bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
+ bfd_elf64_swap_reloca_out (output_bfd, &outrel,
+ (((Elf64_External_Rela *)
+ srelgot->contents)
+ + srelgot->reloc_count));
+ ++srelgot->reloc_count;
}
local_got_offsets[r_symndx] |= 1;
}
- }
- if (off >= (bfd_vma) -2)
- abort ();
-
- relocation = htab->sgot->output_offset + off;
- if (r_type == R_X86_64_GOTPCREL)
- relocation += htab->sgot->output_section->vma;
+ if (r_type == R_X86_64_GOTPCREL)
+ relocation = sgot->output_section->vma + sgot->output_offset + off;
+ else
+ relocation = sgot->output_offset + off;
+ }
break;
@@ -1923,8 +1381,7 @@ elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
if (h == NULL)
break;
- if (h->plt.offset == (bfd_vma) -1
- || htab->splt == NULL)
+ if (h->plt.offset == (bfd_vma) -1 || splt == NULL)
{
/* We didn't make a PLT entry for this symbol. This
happens when statically linking PIC code, or when
@@ -1932,130 +1389,147 @@ elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
break;
}
- relocation = (htab->splt->output_section->vma
- + htab->splt->output_offset
+ relocation = (splt->output_section->vma
+ + splt->output_offset
+ h->plt.offset);
- unresolved_reloc = FALSE;
break;
case R_X86_64_PC8:
case R_X86_64_PC16:
case R_X86_64_PC32:
+ if (h == NULL)
+ break;
+ /* Fall through. */
case R_X86_64_8:
case R_X86_64_16:
case R_X86_64_32:
case R_X86_64_64:
/* FIXME: The ABI says the linker should make sure the value is
the same when it's zeroextended to 64 bit. */
+ if (info->shared
+ && (input_section->flags & SEC_ALLOC) != 0
+ && ((r_type != R_X86_64_PC8
+ && r_type != R_X86_64_PC16
+ && r_type != R_X86_64_PC32)
+ || (! info->symbolic
+ || (h->elf_link_hash_flags
+ & ELF_LINK_HASH_DEF_REGULAR) == 0)))
- /* r_symndx will be zero only for relocs against symbols
- from removed linkonce sections, or sections discarded by
- a linker script. */
- if (r_symndx == 0
- || (input_section->flags & SEC_ALLOC) == 0)
- break;
-
- if ((info->shared
- && (h == NULL
- || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
- || h->root.type != bfd_link_hash_undefweak)
- && ((r_type != R_X86_64_PC8
- && r_type != R_X86_64_PC16
- && r_type != R_X86_64_PC32)
- || !SYMBOL_CALLS_LOCAL (info, h)))
- || (ELIMINATE_COPY_RELOCS
- && !info->shared
- && h != NULL
- && h->dynindx != -1
- && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
- && (((h->elf_link_hash_flags
- & ELF_LINK_HASH_DEF_DYNAMIC) != 0
- && (h->elf_link_hash_flags
- & ELF_LINK_HASH_DEF_REGULAR) == 0)
- || h->root.type == bfd_link_hash_undefweak
- || h->root.type == bfd_link_hash_undefined)))
{
Elf_Internal_Rela outrel;
- bfd_byte *loc;
- bfd_boolean skip, relocate;
- asection *sreloc;
+ boolean skip, relocate;
/* When generating a shared object, these relocations
are copied into the output file to be resolved at run
time. */
- skip = FALSE;
- relocate = FALSE;
- outrel.r_offset =
- _bfd_elf_section_offset (output_bfd, info, input_section,
- rel->r_offset);
- if (outrel.r_offset == (bfd_vma) -1)
- skip = TRUE;
- else if (outrel.r_offset == (bfd_vma) -2)
- skip = TRUE, relocate = TRUE;
+ if (sreloc == NULL)
+ {
+ const char *name;
+
+ name = (bfd_elf_string_from_elf_section
+ (input_bfd,
+ elf_elfheader (input_bfd)->e_shstrndx,
+ elf_section_data (input_section)->rel_hdr.sh_name));
+ if (name == NULL)
+ return false;
+
+ BFD_ASSERT (strncmp (name, ".rela", 5) == 0
+ && strcmp (bfd_get_section_name (input_bfd,
+ input_section),
+ name + 5) == 0);
+
+ sreloc = bfd_get_section_by_name (dynobj, name);
+ BFD_ASSERT (sreloc != NULL);
+ }
+
+ skip = false;
+
+ if (elf_section_data (input_section)->stab_info == NULL)
+ outrel.r_offset = rela->r_offset;
+ else
+ {
+ bfd_vma off;
+
+ off = (_bfd_stab_section_offset
+ (output_bfd, &elf_hash_table (info)->stab_info,
+ input_section,
+ &elf_section_data (input_section)->stab_info,
+ rela->r_offset));
+ if (off == (bfd_vma) -1)
+ skip = true;
+ outrel.r_offset = off;
+ }
outrel.r_offset += (input_section->output_section->vma
+ input_section->output_offset);
if (skip)
- memset (&outrel, 0, sizeof outrel);
-
+ {
+ memset (&outrel, 0, sizeof outrel);
+ relocate = false;
+ }
/* h->dynindx may be -1 if this symbol was marked to
become local. */
else if (h != NULL
- && h->dynindx != -1
- && (r_type == R_X86_64_PC8
- || r_type == R_X86_64_PC16
- || r_type == R_X86_64_PC32
- || !info->shared
- || !info->symbolic
+ && ((! info->symbolic && h->dynindx != -1)
|| (h->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR) == 0))
{
+ BFD_ASSERT (h->dynindx != -1);
+ relocate = false;
outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
- outrel.r_addend = rel->r_addend;
+ outrel.r_addend = relocation + rela->r_addend;
}
else
{
- /* This symbol is local, or marked to become local. */
if (r_type == R_X86_64_64)
{
- relocate = TRUE;
+ relocate = true;
outrel.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
- outrel.r_addend = relocation + rel->r_addend;
+ outrel.r_addend = relocation + rela->r_addend;
}
else
{
- long sindx;
+ long indx;
- if (bfd_is_abs_section (sec))
- sindx = 0;
+ if (h == NULL)
+ sec = local_sections[r_symndx];
+ else
+ {
+ BFD_ASSERT (h->root.type == bfd_link_hash_defined
+ || (h->root.type
+ == bfd_link_hash_defweak));
+ sec = h->root.u.def.section;
+ }
+ if (sec != NULL && bfd_is_abs_section (sec))
+ indx = 0;
else if (sec == NULL || sec->owner == NULL)
{
bfd_set_error (bfd_error_bad_value);
- return FALSE;
+ return false;
}
else
{
asection *osec;
osec = sec->output_section;
- sindx = elf_section_data (osec)->dynindx;
- BFD_ASSERT (sindx > 0);
+ indx = elf_section_data (osec)->dynindx;
+ BFD_ASSERT (indx > 0);
}
- outrel.r_info = ELF64_R_INFO (sindx, r_type);
- outrel.r_addend = relocation + rel->r_addend;
- }
- }
+ relocate = false;
+ outrel.r_info = ELF64_R_INFO (indx, r_type);
+ outrel.r_addend = relocation + rela->r_addend;
+ }
- sreloc = elf_section_data (input_section)->sreloc;
- if (sreloc == NULL)
- abort ();
+ }
- loc = sreloc->contents;
- loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
- bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
+ bfd_elf64_swap_reloca_out (output_bfd, &outrel,
+ (((Elf64_External_Rela *)
+ sreloc->contents)
+ + sreloc->reloc_count));
+ ++sreloc->reloc_count;
/* If this reloc is against an external symbol, we do
not want to fiddle with the addend. Otherwise, we
@@ -2067,402 +1541,82 @@ elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
break;
- case R_X86_64_TLSGD:
- case R_X86_64_GOTTPOFF:
- r_type = elf64_x86_64_tls_transition (info, r_type, h == NULL);
- tls_type = GOT_UNKNOWN;
- if (h == NULL && local_got_offsets)
- tls_type = elf64_x86_64_local_got_tls_type (input_bfd) [r_symndx];
- else if (h != NULL)
- {
- tls_type = elf64_x86_64_hash_entry (h)->tls_type;
- if (!info->shared && h->dynindx == -1 && tls_type == GOT_TLS_IE)
- r_type = R_X86_64_TPOFF32;
- }
- if (r_type == R_X86_64_TLSGD)
- {
- if (tls_type == GOT_TLS_IE)
- r_type = R_X86_64_GOTTPOFF;
- }
-
- if (r_type == R_X86_64_TPOFF32)
- {
- BFD_ASSERT (! unresolved_reloc);
- if (ELF64_R_TYPE (rel->r_info) == R_X86_64_TLSGD)
- {
- unsigned int i;
- static unsigned char tlsgd[8]
- = { 0x66, 0x48, 0x8d, 0x3d, 0x66, 0x66, 0x48, 0xe8 };
-
- /* GD->LE transition.
- .byte 0x66; leaq foo@tlsgd(%rip), %rdi
- .word 0x6666; rex64; call __tls_get_addr@plt
- Change it into:
- movq %fs:0, %rax
- leaq foo@tpoff(%rax), %rax */
- BFD_ASSERT (rel->r_offset >= 4);
- for (i = 0; i < 4; i++)
- BFD_ASSERT (bfd_get_8 (input_bfd,
- contents + rel->r_offset - 4 + i)
- == tlsgd[i]);
- BFD_ASSERT (rel->r_offset + 12 <= input_section->_raw_size);
- for (i = 0; i < 4; i++)
- BFD_ASSERT (bfd_get_8 (input_bfd,
- contents + rel->r_offset + 4 + i)
- == tlsgd[i+4]);
- BFD_ASSERT (rel + 1 < relend);
- BFD_ASSERT (ELF64_R_TYPE (rel[1].r_info) == R_X86_64_PLT32);
- memcpy (contents + rel->r_offset - 4,
- "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
- 16);
- bfd_put_32 (output_bfd, tpoff (info, relocation),
- contents + rel->r_offset + 8);
- /* Skip R_X86_64_PLT32. */
- rel++;
- continue;
- }
- else
- {
- unsigned int val, type, reg;
-
- /* IE->LE transition:
- Originally it can be one of:
- movq foo@gottpoff(%rip), %reg
- addq foo@gottpoff(%rip), %reg
- We change it into:
- movq $foo, %reg
- leaq foo(%reg), %reg
- addq $foo, %reg. */
- BFD_ASSERT (rel->r_offset >= 3);
- val = bfd_get_8 (input_bfd, contents + rel->r_offset - 3);
- BFD_ASSERT (val == 0x48 || val == 0x4c);
- type = bfd_get_8 (input_bfd, contents + rel->r_offset - 2);
- BFD_ASSERT (type == 0x8b || type == 0x03);
- reg = bfd_get_8 (input_bfd, contents + rel->r_offset - 1);
- BFD_ASSERT ((reg & 0xc7) == 5);
- reg >>= 3;
- BFD_ASSERT (rel->r_offset + 4 <= input_section->_raw_size);
- if (type == 0x8b)
- {
- /* movq */
- if (val == 0x4c)
- bfd_put_8 (output_bfd, 0x49,
- contents + rel->r_offset - 3);
- bfd_put_8 (output_bfd, 0xc7,
- contents + rel->r_offset - 2);
- bfd_put_8 (output_bfd, 0xc0 | reg,
- contents + rel->r_offset - 1);
- }
- else if (reg == 4)
- {
- /* addq -> addq - addressing with %rsp/%r12 is
- special */
- if (val == 0x4c)
- bfd_put_8 (output_bfd, 0x49,
- contents + rel->r_offset - 3);
- bfd_put_8 (output_bfd, 0x81,
- contents + rel->r_offset - 2);
- bfd_put_8 (output_bfd, 0xc0 | reg,
- contents + rel->r_offset - 1);
- }
- else
- {
- /* addq -> leaq */
- if (val == 0x4c)
- bfd_put_8 (output_bfd, 0x4d,
- contents + rel->r_offset - 3);
- bfd_put_8 (output_bfd, 0x8d,
- contents + rel->r_offset - 2);
- bfd_put_8 (output_bfd, 0x80 | reg | (reg << 3),
- contents + rel->r_offset - 1);
- }
- bfd_put_32 (output_bfd, tpoff (info, relocation),
- contents + rel->r_offset);
- continue;
- }
- }
-
- if (htab->sgot == NULL)
- abort ();
-
- if (h != NULL)
- off = h->got.offset;
- else
- {
- if (local_got_offsets == NULL)
- abort ();
-
- off = local_got_offsets[r_symndx];
- }
-
- if ((off & 1) != 0)
- off &= ~1;
- else
- {
- Elf_Internal_Rela outrel;
- bfd_byte *loc;
- int dr_type, indx;
-
- if (htab->srelgot == NULL)
- abort ();
-
- outrel.r_offset = (htab->sgot->output_section->vma
- + htab->sgot->output_offset + off);
-
- indx = h && h->dynindx != -1 ? h->dynindx : 0;
- if (r_type == R_X86_64_TLSGD)
- dr_type = R_X86_64_DTPMOD64;
- else
- dr_type = R_X86_64_TPOFF64;
-
- bfd_put_64 (output_bfd, 0, htab->sgot->contents + off);
- outrel.r_addend = 0;
- if (dr_type == R_X86_64_TPOFF64 && indx == 0)
- outrel.r_addend = relocation - dtpoff_base (info);
- outrel.r_info = ELF64_R_INFO (indx, dr_type);
-
- loc = htab->srelgot->contents;
- loc += htab->srelgot->reloc_count++ * sizeof (Elf64_External_Rela);
- bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
-
- if (r_type == R_X86_64_TLSGD)
- {
- if (indx == 0)
- {
- BFD_ASSERT (! unresolved_reloc);
- bfd_put_64 (output_bfd,
- relocation - dtpoff_base (info),
- htab->sgot->contents + off + GOT_ENTRY_SIZE);
- }
- else
- {
- bfd_put_64 (output_bfd, 0,
- htab->sgot->contents + off + GOT_ENTRY_SIZE);
- outrel.r_info = ELF64_R_INFO (indx,
- R_X86_64_DTPOFF64);
- outrel.r_offset += GOT_ENTRY_SIZE;
- htab->srelgot->reloc_count++;
- loc += sizeof (Elf64_External_Rela);
- bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
- }
- }
-
- if (h != NULL)
- h->got.offset |= 1;
- else
- local_got_offsets[r_symndx] |= 1;
- }
-
- if (off >= (bfd_vma) -2)
- abort ();
- if (r_type == ELF64_R_TYPE (rel->r_info))
- {
- relocation = htab->sgot->output_section->vma
- + htab->sgot->output_offset + off;
- unresolved_reloc = FALSE;
- }
- else
- {
- unsigned int i;
- static unsigned char tlsgd[8]
- = { 0x66, 0x48, 0x8d, 0x3d, 0x66, 0x66, 0x48, 0xe8 };
-
- /* GD->IE transition.
- .byte 0x66; leaq foo@tlsgd(%rip), %rdi
- .word 0x6666; rex64; call __tls_get_addr@plt
- Change it into:
- movq %fs:0, %rax
- addq foo@gottpoff(%rip), %rax */
- BFD_ASSERT (rel->r_offset >= 4);
- for (i = 0; i < 4; i++)
- BFD_ASSERT (bfd_get_8 (input_bfd,
- contents + rel->r_offset - 4 + i)
- == tlsgd[i]);
- BFD_ASSERT (rel->r_offset + 12 <= input_section->_raw_size);
- for (i = 0; i < 4; i++)
- BFD_ASSERT (bfd_get_8 (input_bfd,
- contents + rel->r_offset + 4 + i)
- == tlsgd[i+4]);
- BFD_ASSERT (rel + 1 < relend);
- BFD_ASSERT (ELF64_R_TYPE (rel[1].r_info) == R_X86_64_PLT32);
- memcpy (contents + rel->r_offset - 4,
- "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
- 16);
-
- relocation = (htab->sgot->output_section->vma
- + htab->sgot->output_offset + off
- - rel->r_offset
- - input_section->output_section->vma
- - input_section->output_offset
- - 12);
- bfd_put_32 (output_bfd, relocation,
- contents + rel->r_offset + 8);
- /* Skip R_X86_64_PLT32. */
- rel++;
- continue;
- }
- break;
-
- case R_X86_64_TLSLD:
- if (! info->shared)
- {
- /* LD->LE transition:
- Ensure it is:
- leaq foo@tlsld(%rip), %rdi; call __tls_get_addr@plt.
- We change it into:
- .word 0x6666; .byte 0x66; movl %fs:0, %rax. */
- BFD_ASSERT (rel->r_offset >= 3);
- BFD_ASSERT (bfd_get_8 (input_bfd, contents + rel->r_offset - 3)
- == 0x48);
- BFD_ASSERT (bfd_get_8 (input_bfd, contents + rel->r_offset - 2)
- == 0x8d);
- BFD_ASSERT (bfd_get_8 (input_bfd, contents + rel->r_offset - 1)
- == 0x3d);
- BFD_ASSERT (rel->r_offset + 9 <= input_section->_raw_size);
- BFD_ASSERT (bfd_get_8 (input_bfd, contents + rel->r_offset + 4)
- == 0xe8);
- BFD_ASSERT (rel + 1 < relend);
- BFD_ASSERT (ELF64_R_TYPE (rel[1].r_info) == R_X86_64_PLT32);
- memcpy (contents + rel->r_offset - 3,
- "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
- /* Skip R_X86_64_PLT32. */
- rel++;
- continue;
- }
-
- if (htab->sgot == NULL)
- abort ();
-
- off = htab->tls_ld_got.offset;
- if (off & 1)
- off &= ~1;
- else
- {
- Elf_Internal_Rela outrel;
- bfd_byte *loc;
-
- if (htab->srelgot == NULL)
- abort ();
-
- outrel.r_offset = (htab->sgot->output_section->vma
- + htab->sgot->output_offset + off);
-
- bfd_put_64 (output_bfd, 0,
- htab->sgot->contents + off);
- bfd_put_64 (output_bfd, 0,
- htab->sgot->contents + off + GOT_ENTRY_SIZE);
- outrel.r_info = ELF64_R_INFO (0, R_X86_64_DTPMOD64);
- outrel.r_addend = 0;
- loc = htab->srelgot->contents;
- loc += htab->srelgot->reloc_count++ * sizeof (Elf64_External_Rela);
- bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
- htab->tls_ld_got.offset |= 1;
- }
- relocation = htab->sgot->output_section->vma
- + htab->sgot->output_offset + off;
- unresolved_reloc = FALSE;
- break;
-
- case R_X86_64_DTPOFF32:
- if (info->shared || (input_section->flags & SEC_CODE) == 0)
- relocation -= dtpoff_base (info);
- else
- relocation = tpoff (info, relocation);
- break;
-
- case R_X86_64_TPOFF32:
- BFD_ASSERT (! info->shared);
- relocation = tpoff (info, relocation);
- break;
-
default:
break;
}
- /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
- because such sections are not SEC_ALLOC and thus ld.so will
- not process them. */
- if (unresolved_reloc
- && !((input_section->flags & SEC_DEBUGGING) != 0
- && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
- (*_bfd_error_handler)
- (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
- bfd_archive_filename (input_bfd),
- bfd_get_section_name (input_bfd, input_section),
- (long) rel->r_offset,
- h->root.root.string);
-
r = _bfd_final_link_relocate (howto, input_bfd, input_section,
- contents, rel->r_offset,
- relocation, rel->r_addend);
+ contents, rela->r_offset,
+ relocation, rela->r_addend);
if (r != bfd_reloc_ok)
{
- const char *name;
-
- if (h != NULL)
- 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, sec);
- }
-
- if (r == bfd_reloc_overflow)
+ switch (r)
{
+ default:
+ case bfd_reloc_outofrange:
+ abort ();
+ case bfd_reloc_overflow:
+ {
+ const char *name;
- if (! ((*info->callbacks->reloc_overflow)
- (info, name, howto->name, (bfd_vma) 0,
- input_bfd, input_section, rel->r_offset)))
- return FALSE;
- }
- else
- {
- (*_bfd_error_handler)
- (_("%s(%s+0x%lx): reloc against `%s': error %d"),
- bfd_archive_filename (input_bfd),
- bfd_get_section_name (input_bfd, input_section),
- (long) rel->r_offset, name, (int) r);
- return FALSE;
+ if (h != NULL)
+ 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, sec);
+ }
+ if (! ((*info->callbacks->reloc_overflow)
+ (info, name, howto->name, (bfd_vma) 0,
+ input_bfd, input_section, rela->r_offset)))
+ return false;
+ }
+ break;
}
}
}
- return TRUE;
+ return true;
}
/* Finish up dynamic symbol handling. We set the contents of various
dynamic sections here. */
-static bfd_boolean
-elf64_x86_64_finish_dynamic_symbol (bfd *output_bfd,
- struct bfd_link_info *info,
- struct elf_link_hash_entry *h,
- Elf_Internal_Sym *sym)
+static boolean
+elf64_x86_64_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 elf64_x86_64_link_hash_table *htab;
+ bfd *dynobj;
- htab = elf64_x86_64_hash_table (info);
+ dynobj = elf_hash_table (info)->dynobj;
if (h->plt.offset != (bfd_vma) -1)
{
+ asection *splt;
+ asection *sgot;
+ asection *srela;
bfd_vma plt_index;
bfd_vma got_offset;
Elf_Internal_Rela rela;
- bfd_byte *loc;
/* This symbol has an entry in the procedure linkage table. Set
it up. */
- if (h->dynindx == -1
- || htab->splt == NULL
- || htab->sgotplt == NULL
- || htab->srelplt == NULL)
- abort ();
+
+ BFD_ASSERT (h->dynindx != -1);
+
+ splt = bfd_get_section_by_name (dynobj, ".plt");
+ sgot = bfd_get_section_by_name (dynobj, ".got.plt");
+ srela = bfd_get_section_by_name (dynobj, ".rela.plt");
+ BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
/* Get the index in the procedure linkage table which
corresponds to this symbol. This is the index of this symbol
@@ -2476,7 +1630,7 @@ elf64_x86_64_finish_dynamic_symbol (bfd *output_bfd,
got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
/* Fill in the entry in the procedure linkage table. */
- memcpy (htab->splt->contents + h->plt.offset, elf64_x86_64_plt_entry,
+ memcpy (splt->contents + h->plt.offset, elf64_x86_64_plt_entry,
PLT_ENTRY_SIZE);
/* Insert the relocation positions of the plt section. The magic
@@ -2485,71 +1639,78 @@ elf64_x86_64_finish_dynamic_symbol (bfd *output_bfd,
/* Put offset for jmp *name@GOTPCREL(%rip), since the
instruction uses 6 bytes, subtract this value. */
bfd_put_32 (output_bfd,
- (htab->sgotplt->output_section->vma
- + htab->sgotplt->output_offset
+ (sgot->output_section->vma
+ + sgot->output_offset
+ got_offset
- - htab->splt->output_section->vma
- - htab->splt->output_offset
+ - splt->output_section->vma
+ - splt->output_offset
- h->plt.offset
- 6),
- htab->splt->contents + h->plt.offset + 2);
+ splt->contents + h->plt.offset + 2);
/* Put relocation index. */
bfd_put_32 (output_bfd, plt_index,
- htab->splt->contents + h->plt.offset + 7);
+ splt->contents + h->plt.offset + 7);
/* Put offset for jmp .PLT0. */
bfd_put_32 (output_bfd, - (h->plt.offset + PLT_ENTRY_SIZE),
- htab->splt->contents + h->plt.offset + 12);
+ splt->contents + h->plt.offset + 12);
/* Fill in the entry in the global offset table, initially this
points to the pushq instruction in the PLT which is at offset 6. */
- bfd_put_64 (output_bfd, (htab->splt->output_section->vma
- + htab->splt->output_offset
+ bfd_put_64 (output_bfd, (splt->output_section->vma + splt->output_offset
+ h->plt.offset + 6),
- htab->sgotplt->contents + got_offset);
+ sgot->contents + got_offset);
/* Fill in the entry in the .rela.plt section. */
- rela.r_offset = (htab->sgotplt->output_section->vma
- + htab->sgotplt->output_offset
+ rela.r_offset = (sgot->output_section->vma
+ + sgot->output_offset
+ got_offset);
rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_JUMP_SLOT);
rela.r_addend = 0;
- loc = htab->srelplt->contents + plt_index * sizeof (Elf64_External_Rela);
- bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
+ bfd_elf64_swap_reloca_out (output_bfd, &rela,
+ ((Elf64_External_Rela *) srela->contents
+ + plt_index));
if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
{
/* Mark the symbol as undefined, rather than as defined in
- the .plt section. Leave the value alone. This is a clue
- for the dynamic linker, to make function pointer
- comparisons work between an application and shared
- library. */
+ the .plt section. Leave the value alone. */
sym->st_shndx = SHN_UNDEF;
+ /* If the symbol is weak, we do need to clear the value.
+ Otherwise, the PLT entry would provide a definition for
+ the symbol even if the symbol wasn't defined anywhere,
+ and so the symbol would never be NULL. */
+ if ((h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR_NONWEAK)
+ == 0)
+ sym->st_value = 0;
}
}
- if (h->got.offset != (bfd_vma) -1
- && elf64_x86_64_hash_entry (h)->tls_type != GOT_TLS_GD
- && elf64_x86_64_hash_entry (h)->tls_type != GOT_TLS_IE)
+ if (h->got.offset != (bfd_vma) -1)
{
+ asection *sgot;
+ asection *srela;
Elf_Internal_Rela rela;
- bfd_byte *loc;
/* This symbol has an entry in the global offset table. Set it
- up. */
- if (htab->sgot == NULL || htab->srelgot == NULL)
- abort ();
+ up. */
+
+ sgot = bfd_get_section_by_name (dynobj, ".got");
+ srela = bfd_get_section_by_name (dynobj, ".rela.got");
+ BFD_ASSERT (sgot != NULL && srela != NULL);
- rela.r_offset = (htab->sgot->output_section->vma
- + htab->sgot->output_offset
- + (h->got.offset &~ (bfd_vma) 1));
+ rela.r_offset = (sgot->output_section->vma
+ + sgot->output_offset
+ + (h->got.offset &~ 1));
/* If this is a static link, or it is a -Bsymbolic link and the
symbol is defined locally or was forced to be local because
of a version file, we just want to emit a RELATIVE reloc.
The entry in the global offset table will already have been
initialized in the relocate_section function. */
- if (info->shared
- && SYMBOL_REFERENCES_LOCAL (info, h))
+ if (! elf_hash_table (info)->dynamic_sections_created
+ || (info->shared
+ && (info->symbolic || h->dynindx == -1)
+ && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
{
BFD_ASSERT((h->got.offset & 1) != 0);
rela.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
@@ -2560,38 +1721,41 @@ elf64_x86_64_finish_dynamic_symbol (bfd *output_bfd,
else
{
BFD_ASSERT((h->got.offset & 1) == 0);
- bfd_put_64 (output_bfd, (bfd_vma) 0,
- htab->sgot->contents + h->got.offset);
+ bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_GLOB_DAT);
rela.r_addend = 0;
}
- loc = htab->srelgot->contents;
- loc += htab->srelgot->reloc_count++ * sizeof (Elf64_External_Rela);
- bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
+ bfd_elf64_swap_reloca_out (output_bfd, &rela,
+ ((Elf64_External_Rela *) srela->contents
+ + srela->reloc_count));
+ ++srela->reloc_count;
}
if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
{
+ asection *s;
Elf_Internal_Rela rela;
- bfd_byte *loc;
/* This symbol needs a copy reloc. Set it up. */
- if (h->dynindx == -1
- || (h->root.type != bfd_link_hash_defined
- && h->root.type != bfd_link_hash_defweak)
- || htab->srelbss == NULL)
- abort ();
+ BFD_ASSERT (h->dynindx != -1
+ && (h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak));
+
+ s = bfd_get_section_by_name (h->root.u.def.section->owner,
+ ".rela.bss");
+ BFD_ASSERT (s != NULL);
rela.r_offset = (h->root.u.def.value
+ h->root.u.def.section->output_section->vma
+ h->root.u.def.section->output_offset);
rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_COPY);
rela.r_addend = 0;
- loc = htab->srelbss->contents;
- loc += htab->srelbss->reloc_count++ * sizeof (Elf64_External_Rela);
- bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
+ bfd_elf64_swap_reloca_out (output_bfd, &rela,
+ ((Elf64_External_Rela *) s->contents
+ + s->reloc_count));
+ ++s->reloc_count;
}
/* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
@@ -2599,53 +1763,39 @@ elf64_x86_64_finish_dynamic_symbol (bfd *output_bfd,
|| strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
sym->st_shndx = SHN_ABS;
- return TRUE;
-}
-
-/* Used to decide how to sort relocs in an optimal manner for the
- dynamic linker, before writing them out. */
-
-static enum elf_reloc_type_class
-elf64_x86_64_reloc_type_class (const Elf_Internal_Rela *rela)
-{
- switch ((int) ELF64_R_TYPE (rela->r_info))
- {
- case R_X86_64_RELATIVE:
- return reloc_class_relative;
- case R_X86_64_JUMP_SLOT:
- return reloc_class_plt;
- case R_X86_64_COPY:
- return reloc_class_copy;
- default:
- return reloc_class_normal;
- }
+ return true;
}
/* Finish up the dynamic sections. */
-static bfd_boolean
-elf64_x86_64_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
+static boolean
+elf64_x86_64_finish_dynamic_sections (output_bfd, info)
+ bfd *output_bfd;
+ struct bfd_link_info *info;
{
- struct elf64_x86_64_link_hash_table *htab;
bfd *dynobj;
asection *sdyn;
+ asection *sgot;
+
+ dynobj = elf_hash_table (info)->dynobj;
- htab = elf64_x86_64_hash_table (info);
- dynobj = htab->elf.dynobj;
+ sgot = bfd_get_section_by_name (dynobj, ".got.plt");
+ BFD_ASSERT (sgot != NULL);
sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
- if (htab->elf.dynamic_sections_created)
+ if (elf_hash_table (info)->dynamic_sections_created)
{
+ asection *splt;
Elf64_External_Dyn *dyncon, *dynconend;
- if (sdyn == NULL || htab->sgot == NULL)
- abort ();
+ BFD_ASSERT (sdyn != NULL);
dyncon = (Elf64_External_Dyn *) sdyn->contents;
dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
for (; dyncon < dynconend; dyncon++)
{
Elf_Internal_Dyn dyn;
+ const char *name;
asection *s;
bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
@@ -2656,98 +1806,97 @@ elf64_x86_64_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *inf
continue;
case DT_PLTGOT:
- dyn.d_un.d_ptr = htab->sgot->output_section->vma;
- break;
+ name = ".got";
+ goto get_vma;
case DT_JMPREL:
- dyn.d_un.d_ptr = htab->srelplt->output_section->vma;
- break;
+ name = ".rela.plt";
- case DT_PLTRELSZ:
- s = htab->srelplt->output_section;
- if (s->_cooked_size != 0)
- dyn.d_un.d_val = s->_cooked_size;
- else
- dyn.d_un.d_val = s->_raw_size;
+ get_vma:
+ s = bfd_get_section_by_name (output_bfd, name);
+ BFD_ASSERT (s != NULL);
+ dyn.d_un.d_ptr = s->vma;
break;
case DT_RELASZ:
- /* The procedure linkage table relocs (DT_JMPREL) should
- not be included in the overall relocs (DT_RELA).
- Therefore, we override the DT_RELASZ entry here to
- make it not include the JMPREL relocs. Since the
- linker script arranges for .rela.plt to follow all
- other relocation sections, we don't have to worry
- about changing the DT_RELA entry. */
- if (htab->srelplt != NULL)
+ /* FIXME: This comment and code is from elf64-alpha.c: */
+ /* My interpretation of the TIS v1.1 ELF document indicates
+ that RELASZ should not include JMPREL. This is not what
+ the rest of the BFD does. It is, however, what the
+ glibc ld.so wants. Do this fixup here until we found
+ out who is right. */
+ s = bfd_get_section_by_name (output_bfd, ".rela.plt");
+ if (s)
{
- s = htab->srelplt->output_section;
- if (s->_cooked_size != 0)
- dyn.d_un.d_val -= s->_cooked_size;
- else
- dyn.d_un.d_val -= s->_raw_size;
+ /* Subtract JMPREL size from RELASZ. */
+ dyn.d_un.d_val -=
+ (s->_cooked_size ? s->_cooked_size : s->_raw_size);
}
break;
- }
+ case DT_PLTRELSZ:
+ s = bfd_get_section_by_name (output_bfd, ".rela.plt");
+ BFD_ASSERT (s != NULL);
+ dyn.d_un.d_val =
+ (s->_cooked_size != 0 ? s->_cooked_size : s->_raw_size);
+ break;
+ }
bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
}
- /* Fill in the special first entry in the procedure linkage table. */
- if (htab->splt && htab->splt->_raw_size > 0)
+ /* Initialize the contents of the .plt section. */
+ splt = bfd_get_section_by_name (dynobj, ".plt");
+ BFD_ASSERT (splt != NULL);
+ if (splt->_raw_size > 0)
{
/* Fill in the first entry in the procedure linkage table. */
- memcpy (htab->splt->contents, elf64_x86_64_plt0_entry,
- PLT_ENTRY_SIZE);
+ memcpy (splt->contents, elf64_x86_64_plt0_entry, PLT_ENTRY_SIZE);
/* Add offset for pushq GOT+8(%rip), since the instruction
uses 6 bytes subtract this value. */
bfd_put_32 (output_bfd,
- (htab->sgotplt->output_section->vma
- + htab->sgotplt->output_offset
+ (sgot->output_section->vma
+ + sgot->output_offset
+ 8
- - htab->splt->output_section->vma
- - htab->splt->output_offset
+ - splt->output_section->vma
+ - splt->output_offset
- 6),
- htab->splt->contents + 2);
+ splt->contents + 2);
/* Add offset for jmp *GOT+16(%rip). The 12 is the offset to
the end of the instruction. */
bfd_put_32 (output_bfd,
- (htab->sgotplt->output_section->vma
- + htab->sgotplt->output_offset
+ (sgot->output_section->vma
+ + sgot->output_offset
+ 16
- - htab->splt->output_section->vma
- - htab->splt->output_offset
+ - splt->output_section->vma
+ - splt->output_offset
- 12),
- htab->splt->contents + 8);
+ splt->contents + 8);
- elf_section_data (htab->splt->output_section)->this_hdr.sh_entsize =
- PLT_ENTRY_SIZE;
}
+
+ elf_section_data (splt->output_section)->this_hdr.sh_entsize =
+ PLT_ENTRY_SIZE;
}
- if (htab->sgotplt)
+ /* Set the first entry in the global offset table to the address of
+ the dynamic section. */
+ if (sgot->_raw_size > 0)
{
- /* Fill in the first three entries in the global offset table. */
- if (htab->sgotplt->_raw_size > 0)
- {
- /* Set the first entry in the global offset table to the address of
- the dynamic section. */
- if (sdyn == NULL)
- bfd_put_64 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents);
- else
- bfd_put_64 (output_bfd,
- sdyn->output_section->vma + sdyn->output_offset,
- htab->sgotplt->contents);
- /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
- bfd_put_64 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + GOT_ENTRY_SIZE);
- bfd_put_64 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + GOT_ENTRY_SIZE*2);
- }
-
- elf_section_data (htab->sgotplt->output_section)->this_hdr.sh_entsize =
- GOT_ENTRY_SIZE;
+ if (sdyn == NULL)
+ bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents);
+ else
+ bfd_put_64 (output_bfd,
+ sdyn->output_section->vma + sdyn->output_offset,
+ sgot->contents);
+ /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
+ bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + GOT_ENTRY_SIZE);
+ bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + GOT_ENTRY_SIZE*2);
}
- return TRUE;
+ elf_section_data (sgot->output_section)->this_hdr.sh_entsize =
+ GOT_ENTRY_SIZE;
+
+ return true;
}
@@ -2758,33 +1907,29 @@ elf64_x86_64_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *inf
#define ELF_MAXPAGESIZE 0x100000
#define elf_backend_can_gc_sections 1
-#define elf_backend_can_refcount 1
#define elf_backend_want_got_plt 1
#define elf_backend_plt_readonly 1
#define elf_backend_want_plt_sym 0
#define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
-#define elf_backend_rela_normal 1
+#define elf_backend_plt_header_size PLT_ENTRY_SIZE
#define elf_info_to_howto elf64_x86_64_info_to_howto
+#define bfd_elf64_bfd_final_link _bfd_elf64_gc_common_final_link
#define bfd_elf64_bfd_link_hash_table_create \
elf64_x86_64_link_hash_table_create
#define bfd_elf64_bfd_reloc_type_lookup elf64_x86_64_reloc_type_lookup
#define elf_backend_adjust_dynamic_symbol elf64_x86_64_adjust_dynamic_symbol
#define elf_backend_check_relocs elf64_x86_64_check_relocs
-#define elf_backend_copy_indirect_symbol elf64_x86_64_copy_indirect_symbol
-#define elf_backend_create_dynamic_sections elf64_x86_64_create_dynamic_sections
-#define elf_backend_finish_dynamic_sections elf64_x86_64_finish_dynamic_sections
+#define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
+#define elf_backend_finish_dynamic_sections \
+ elf64_x86_64_finish_dynamic_sections
#define elf_backend_finish_dynamic_symbol elf64_x86_64_finish_dynamic_symbol
#define elf_backend_gc_mark_hook elf64_x86_64_gc_mark_hook
#define elf_backend_gc_sweep_hook elf64_x86_64_gc_sweep_hook
-#define elf_backend_grok_prstatus elf64_x86_64_grok_prstatus
-#define elf_backend_grok_psinfo elf64_x86_64_grok_psinfo
-#define elf_backend_reloc_type_class elf64_x86_64_reloc_type_class
#define elf_backend_relocate_section elf64_x86_64_relocate_section
#define elf_backend_size_dynamic_sections elf64_x86_64_size_dynamic_sections
#define elf_backend_object_p elf64_x86_64_elf_object_p
-#define bfd_elf64_mkobject elf64_x86_64_mkobject
#include "elf64-target.h"
diff --git a/gnu/usr.bin/binutils/bfd/elfxx-ia64.c b/gnu/usr.bin/binutils/bfd/elfxx-ia64.c
index b19aac2c55d..c86f7a9eed2 100644
--- a/gnu/usr.bin/binutils/bfd/elfxx-ia64.c
+++ b/gnu/usr.bin/binutils/bfd/elfxx-ia64.c
@@ -1,23 +1,22 @@
/* IA-64 support for 64-bit ELF
- Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004
- Free Software Foundation, Inc.
+ 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 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 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.
+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. */
+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"
@@ -25,36 +24,38 @@
#include "elf-bfd.h"
#include "opcode/ia64.h"
#include "elf/ia64.h"
-#include "objalloc.h"
-#include "hashtab.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 require dynamic relocations. */
+/*
+ * 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])))
@@ -78,11 +79,8 @@ struct elfNN_ia64_dyn_sym_info
bfd_vma pltoff_offset;
bfd_vma plt_offset;
bfd_vma plt2_offset;
- bfd_vma tprel_offset;
- bfd_vma dtpmod_offset;
- bfd_vma dtprel_offset;
- /* The symbol table entry, if any, that this was derived from. */
+ /* 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
@@ -93,41 +91,32 @@ struct elfNN_ia64_dyn_sym_info
asection *srel;
int type;
int count;
-
- /* Is this reloc against readonly section? */
- bfd_boolean reltext;
} *reloc_entries;
- /* TRUE when the section contents have been updated. */
+ /* True when the section contents have been updated. */
unsigned got_done : 1;
unsigned fptr_done : 1;
unsigned pltoff_done : 1;
- unsigned tprel_done : 1;
- unsigned dtpmod_done : 1;
- unsigned dtprel_done : 1;
- /* TRUE for the different kinds of linker data we want created. */
+ /* True for the different kinds of linker data we want created. */
unsigned want_got : 1;
- unsigned want_gotx : 1;
unsigned want_fptr : 1;
unsigned want_ltoff_fptr : 1;
unsigned want_plt : 1;
unsigned want_plt2 : 1;
unsigned want_pltoff : 1;
- unsigned want_tprel : 1;
- unsigned want_dtpmod : 1;
- unsigned want_dtprel : 1;
};
struct elfNN_ia64_local_hash_entry
{
- int id;
- unsigned int r_sym;
+ struct bfd_hash_entry root;
struct elfNN_ia64_dyn_sym_info *info;
+};
- /* TRUE if this hash entry's addends was translated for
- SHF_MERGE optimization. */
- unsigned sec_merge_done : 1;
+struct elfNN_ia64_local_hash_table
+{
+ struct bfd_hash_table root;
+ /* No additional fields for now. */
};
struct elfNN_ia64_link_hash_entry
@@ -138,30 +127,19 @@ struct elfNN_ia64_link_hash_entry
struct elfNN_ia64_link_hash_table
{
- /* The main 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 *rel_fptr_sec; /* dynamic relocation section for same */
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 */
- unsigned reltext : 1; /* are there relocs against readonly sections? */
- unsigned self_dtpmod_done : 1;/* has self DTPMOD entry been finished? */
- bfd_vma self_dtpmod_offset; /* .got offset to self DTPMOD entry */
- htab_t loc_hash_table;
- void *loc_hash_memory;
-};
-
-struct elfNN_ia64_allocate_data
-{
- struct bfd_link_info *info;
- bfd_size_type ofs;
+ struct elfNN_ia64_local_hash_table loc_hash_table;
};
#define elfNN_ia64_hash_table(p) \
@@ -175,66 +153,52 @@ static reloc_howto_type * lookup_howto
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, Elf_Internal_Rela *elf_reloc));
-static bfd_boolean elfNN_ia64_relax_section
+ 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,
- bfd_boolean *again));
-static void elfNN_ia64_relax_ldxmov
- PARAMS((bfd *abfd, bfd_byte *contents, bfd_vma off));
-static bfd_boolean is_unwind_section_name
- PARAMS ((bfd *abfd, const char *));
-static bfd_boolean elfNN_ia64_section_from_shdr
- PARAMS ((bfd *, Elf_Internal_Shdr *, const char *));
-static bfd_boolean elfNN_ia64_section_flags
- PARAMS ((flagword *, Elf_Internal_Shdr *));
-static bfd_boolean elfNN_ia64_fake_sections
- PARAMS ((bfd *abfd, Elf_Internal_Shdr *hdr, asection *sec));
+ 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, bfd_boolean linker));
-static bfd_boolean elfNN_ia64_add_symbol_hook
- PARAMS ((bfd *abfd, struct bfd_link_info *info, Elf_Internal_Sym *sym,
+ 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 bfd_boolean elfNN_ia64_modify_segment_map
- PARAMS ((bfd *, struct bfd_link_info *));
-static bfd_boolean elfNN_ia64_is_local_label_name
+static boolean elfNN_ia64_is_local_label_name
PARAMS ((bfd *abfd, const char *name));
-static bfd_boolean elfNN_ia64_dynamic_symbol_p
- PARAMS ((struct elf_link_hash_entry *h, struct bfd_link_info *info, int));
+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 void elfNN_ia64_hash_copy_indirect
- PARAMS ((const struct elf_backend_data *, struct elf_link_hash_entry *,
- struct elf_link_hash_entry *));
-static void elfNN_ia64_hash_hide_symbol
- PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *, bfd_boolean));
-static hashval_t elfNN_ia64_local_htab_hash PARAMS ((const void *));
-static int elfNN_ia64_local_htab_eq PARAMS ((const void *ptr1,
- const void *ptr2));
static struct bfd_link_hash_table *elfNN_ia64_hash_table_create
PARAMS ((bfd *abfd));
-static void elfNN_ia64_hash_table_free
- PARAMS ((struct bfd_link_hash_table *hash));
-static bfd_boolean elfNN_ia64_global_dyn_sym_thunk
- PARAMS ((struct bfd_hash_entry *, PTR));
-static int elfNN_ia64_local_dyn_sym_thunk
- PARAMS ((void **, PTR));
+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,
- bfd_boolean (*func) (struct elfNN_ia64_dyn_sym_info *, PTR),
+ boolean (*func) (struct elfNN_ia64_dyn_sym_info *, PTR),
PTR info));
-static bfd_boolean elfNN_ia64_create_dynamic_sections
+static boolean elfNN_ia64_create_dynamic_sections
PARAMS ((bfd *abfd, struct bfd_link_info *info));
-static struct elfNN_ia64_local_hash_entry * get_local_sym_hash
- PARAMS ((struct elfNN_ia64_link_hash_table *ia64_info,
- bfd *abfd, const Elf_Internal_Rela *rel, bfd_boolean create));
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, bfd_boolean create));
+ 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));
@@ -246,31 +210,34 @@ static asection *get_pltoff
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, bfd_boolean create));
-static bfd_boolean elfNN_ia64_check_relocs
+ 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 bfd_boolean elfNN_ia64_adjust_dynamic_symbol
+static boolean elfNN_ia64_adjust_dynamic_symbol
PARAMS ((struct bfd_link_info *info, struct elf_link_hash_entry *h));
-static long global_sym_index
+static unsigned long global_sym_index
PARAMS ((struct elf_link_hash_entry *h));
-static bfd_boolean allocate_fptr
+static boolean allocate_fptr
PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data));
-static bfd_boolean allocate_global_data_got
+static boolean allocate_global_data_got
PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data));
-static bfd_boolean allocate_global_fptr_got
+static boolean allocate_global_fptr_got
PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data));
-static bfd_boolean allocate_local_got
+static boolean allocate_local_got
PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data));
-static bfd_boolean allocate_pltoff_entries
+static boolean allocate_pltoff_entries
PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data));
-static bfd_boolean allocate_plt_entries
+static boolean allocate_plt_entries
PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data));
-static bfd_boolean allocate_plt2_entries
+static boolean allocate_plt2_entries
PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data));
-static bfd_boolean allocate_dynrel_entries
+static boolean allocate_dynrel_entries
PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data));
-static bfd_boolean elfNN_ia64_size_dynamic_sections
+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));
@@ -289,43 +256,29 @@ static bfd_vma set_fptr_entry
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, bfd_boolean));
-static bfd_vma elfNN_ia64_tprel_base
- PARAMS ((struct bfd_link_info *info));
-static bfd_vma elfNN_ia64_dtprel_base
- PARAMS ((struct bfd_link_info *info));
-static int elfNN_ia64_unwind_entry_compare
- PARAMS ((const PTR, const PTR));
-static bfd_boolean elfNN_ia64_choose_gp
- PARAMS ((bfd *abfd, struct bfd_link_info *info));
-static bfd_boolean elfNN_ia64_final_link
+ bfd_vma value, boolean));
+static boolean elfNN_ia64_final_link
PARAMS ((bfd *abfd, struct bfd_link_info *info));
-static bfd_boolean elfNN_ia64_relocate_section
+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 bfd_boolean elfNN_ia64_finish_dynamic_symbol
+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 bfd_boolean elfNN_ia64_finish_dynamic_sections
+static boolean elfNN_ia64_finish_dynamic_sections
PARAMS ((bfd *abfd, struct bfd_link_info *info));
-static bfd_boolean elfNN_ia64_set_private_flags
+static boolean elfNN_ia64_set_private_flags
PARAMS ((bfd *abfd, flagword flags));
-static bfd_boolean elfNN_ia64_merge_private_bfd_data
+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 bfd_boolean elfNN_ia64_print_private_bfd_data
+static boolean elfNN_ia64_print_private_bfd_data
PARAMS ((bfd *abfd, PTR ptr));
-static enum elf_reloc_type_class elfNN_ia64_reloc_type_class
- PARAMS ((const Elf_Internal_Rela *));
-static bfd_boolean elfNN_ia64_hpux_vec
- PARAMS ((const bfd_target *vec));
-static void elfNN_hpux_post_process_headers
- PARAMS ((bfd *abfd, struct bfd_link_info *info));
-bfd_boolean elfNN_hpux_backend_section_from_bfd_section
- PARAMS ((bfd *abfd, asection *sec, int *retval));
-/* ia64-specific relocation. */
+/* ia64-specific relocation */
/* Perform a relocation. Not much to do here as all the hard work is
done in elfNN_ia64_final_link_relocate. */
@@ -345,125 +298,104 @@ elfNN_ia64_reloc (abfd, reloc, sym, data, input_section,
reloc->address += input_section->output_offset;
return bfd_reloc_ok;
}
-
- if (input_section->flags & SEC_DEBUGGING)
- return bfd_reloc_continue;
-
*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, -1, IN)
+ 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_FPTR32MSB, "LTOFF_FPTR32MSB", 2, FALSE, TRUE),
- IA64_HOWTO (R_IA64_LTOFF_FPTR32LSB, "LTOFF_FPTR32LSB", 2, 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_TPREL14, "TPREL14", 0, FALSE, FALSE),
- IA64_HOWTO (R_IA64_TPREL22, "TPREL22", 0, FALSE, FALSE),
- IA64_HOWTO (R_IA64_TPREL64I, "TPREL64I", 0, FALSE, FALSE),
- IA64_HOWTO (R_IA64_TPREL64MSB, "TPREL64MSB", 4, FALSE, FALSE),
- IA64_HOWTO (R_IA64_TPREL64LSB, "TPREL64LSB", 4, FALSE, FALSE),
- IA64_HOWTO (R_IA64_LTOFF_TPREL22, "LTOFF_TPREL22", 0, FALSE, FALSE),
-
- IA64_HOWTO (R_IA64_DTPMOD64MSB, "TPREL64MSB", 4, FALSE, FALSE),
- IA64_HOWTO (R_IA64_DTPMOD64LSB, "TPREL64LSB", 4, FALSE, FALSE),
- IA64_HOWTO (R_IA64_LTOFF_DTPMOD22, "LTOFF_DTPMOD22", 0, FALSE, FALSE),
-
- IA64_HOWTO (R_IA64_DTPREL14, "DTPREL14", 0, FALSE, FALSE),
- IA64_HOWTO (R_IA64_DTPREL22, "DTPREL22", 0, FALSE, FALSE),
- IA64_HOWTO (R_IA64_DTPREL64I, "DTPREL64I", 0, FALSE, FALSE),
- IA64_HOWTO (R_IA64_DTPREL32MSB, "DTPREL32MSB", 2, FALSE, FALSE),
- IA64_HOWTO (R_IA64_DTPREL32LSB, "DTPREL32LSB", 2, FALSE, FALSE),
- IA64_HOWTO (R_IA64_DTPREL64MSB, "DTPREL64MSB", 4, FALSE, FALSE),
- IA64_HOWTO (R_IA64_DTPREL64LSB, "DTPREL64LSB", 4, FALSE, FALSE),
- IA64_HOWTO (R_IA64_LTOFF_DTPREL22, "LTOFF_DTPREL22", 0, FALSE, FALSE),
+ 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 *
+static reloc_howto_type*
lookup_howto (rtype)
unsigned int rtype;
{
@@ -540,8 +472,6 @@ elfNN_ia64_reloc_type_lookup (abfd, bfd_code)
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_FPTR32MSB: rtype = R_IA64_LTOFF_FPTR32MSB; break;
- case BFD_RELOC_IA64_LTOFF_FPTR32LSB: rtype = R_IA64_LTOFF_FPTR32LSB; 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;
@@ -571,25 +501,10 @@ elfNN_ia64_reloc_type_lookup (abfd, bfd_code)
case BFD_RELOC_IA64_LTOFF22X: rtype = R_IA64_LTOFF22X; break;
case BFD_RELOC_IA64_LDXMOV: rtype = R_IA64_LDXMOV; break;
- case BFD_RELOC_IA64_TPREL14: rtype = R_IA64_TPREL14; break;
case BFD_RELOC_IA64_TPREL22: rtype = R_IA64_TPREL22; break;
- case BFD_RELOC_IA64_TPREL64I: rtype = R_IA64_TPREL64I; 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_TPREL22: rtype = R_IA64_LTOFF_TPREL22; break;
-
- case BFD_RELOC_IA64_DTPMOD64MSB: rtype = R_IA64_DTPMOD64MSB; break;
- case BFD_RELOC_IA64_DTPMOD64LSB: rtype = R_IA64_DTPMOD64LSB; break;
- case BFD_RELOC_IA64_LTOFF_DTPMOD22: rtype = R_IA64_LTOFF_DTPMOD22; break;
-
- case BFD_RELOC_IA64_DTPREL14: rtype = R_IA64_DTPREL14; break;
- case BFD_RELOC_IA64_DTPREL22: rtype = R_IA64_DTPREL22; break;
- case BFD_RELOC_IA64_DTPREL64I: rtype = R_IA64_DTPREL64I; break;
- case BFD_RELOC_IA64_DTPREL32MSB: rtype = R_IA64_DTPREL32MSB; break;
- case BFD_RELOC_IA64_DTPREL32LSB: rtype = R_IA64_DTPREL32LSB; break;
- case BFD_RELOC_IA64_DTPREL64MSB: rtype = R_IA64_DTPREL64MSB; break;
- case BFD_RELOC_IA64_DTPREL64LSB: rtype = R_IA64_DTPREL64LSB; break;
- case BFD_RELOC_IA64_LTOFF_DTPREL22: rtype = R_IA64_LTOFF_DTPREL22; break;
+ case BFD_RELOC_IA64_LTOFF_TP22: rtype = R_IA64_LTOFF_TP22; break;
default: return 0;
}
@@ -602,10 +517,9 @@ static void
elfNN_ia64_info_to_howto (abfd, bfd_reloc, elf_reloc)
bfd *abfd ATTRIBUTE_UNUSED;
arelent *bfd_reloc;
- Elf_Internal_Rela *elf_reloc;
+ ElfNN_Internal_Rela *elf_reloc;
{
- bfd_reloc->howto
- = lookup_howto ((unsigned int) ELFNN_R_TYPE (elf_reloc->r_info));
+ bfd_reloc->howto = lookup_howto (ELFNN_R_TYPE (elf_reloc->r_info));
}
#define PLT_HEADER_SIZE (3 * 16)
@@ -636,7 +550,7 @@ static const bfd_byte plt_min_entry[PLT_MIN_ENTRY_SIZE] =
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, 0x70, 0x29, 0xc0, /* ld8.acq r16=[r15],8*/
+ 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 */
@@ -645,6 +559,10 @@ static const bfd_byte plt_full_entry[PLT_FULL_ENTRY_SIZE] =
#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 */
@@ -664,54 +582,18 @@ static const bfd_byte oor_ip[48] =
0x60, 0x80, 0x04, 0x80, 0x03, 0x00, /* mov b6=r16 */
0x60, 0x00, 0x80, 0x00 /* br b6;; */
};
-
-static size_t oor_branch_size = sizeof (oor_brl);
-
-void
-bfd_elfNN_ia64_after_parse (int itanium)
-{
- oor_branch_size = itanium ? sizeof (oor_ip) : sizeof (oor_brl);
-}
-
-static void
-elfNN_ia64_relax_brl (bfd *abfd, bfd_byte *contents, bfd_vma off)
-{
- int template;
- bfd_byte *hit_addr;
- bfd_vma t0, t1, i0, i1, i2;
-
- hit_addr = (bfd_byte *) (contents + off);
- hit_addr -= (long) hit_addr & 0x3;
- t0 = bfd_get_64 (abfd, hit_addr);
- t1 = bfd_get_64 (abfd, hit_addr + 8);
-
- /* Keep the instruction in slot 0. */
- i0 = (t0 >> 5) & 0x1ffffffffffLL;
- /* Use nop.b for slot 1. */
- i1 = 0x4000000000LL;
- /* For slot 2, turn brl into br by masking out bit 40. */
- i2 = (t1 >> 23) & 0x0ffffffffffLL;
-
- /* Turn a MLX bundle into a MBB bundle with the same stop-bit
- variety. */
- template = 0x12;
- if ((t0 & 0x1fLL) == 5)
- template += 1;
- t0 = (i1 << 46) | (i0 << 5) | template;
- t1 = (i2 << 23) | (i1 >> 18);
-
- bfd_put_64 (abfd, t0, hit_addr);
- bfd_put_64 (abfd, t1, hit_addr + 8);
-}
-/* These functions do relaxation for IA-64 ELF. */
+/* 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 bfd_boolean
+static boolean
elfNN_ia64_relax_section (abfd, sec, link_info, again)
bfd *abfd;
asection *sec;
struct bfd_link_info *link_info;
- bfd_boolean *again;
+ boolean *again;
{
struct one_fixup
{
@@ -723,31 +605,25 @@ elfNN_ia64_relax_section (abfd, sec, link_info, again)
Elf_Internal_Shdr *symtab_hdr;
Elf_Internal_Rela *internal_relocs;
+ Elf_Internal_Rela *free_relocs = NULL;
Elf_Internal_Rela *irel, *irelend;
bfd_byte *contents;
- Elf_Internal_Sym *isymbuf = NULL;
+ 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;
- bfd_boolean changed_contents = FALSE;
- bfd_boolean changed_relocs = FALSE;
- bfd_boolean changed_got = FALSE;
- bfd_vma gp = 0;
+ 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;
+ *again = false;
- /* Don't even try to relax for non-ELF outputs. */
- if (!is_elf_hash_table (link_info->hash))
- return FALSE;
-
- /* Nothing to do if there are no relocations or there is no need for
- the relax finalize pass. */
+ /* Nothing to do if there are no relocations. */
if ((sec->flags & SEC_RELOC) == 0
- || sec->reloc_count == 0
- || (!link_info->need_relax_finalize
- && sec->need_finalize_relax == 0))
- return TRUE;
+ || sec->reloc_count == 0)
+ return true;
/* If this is the first time we have been called for this section,
initialize the cooked size. */
@@ -757,15 +633,30 @@ elfNN_ia64_relax_section (abfd, sec, link_info, again)
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
/* Load the relocations for this section. */
- internal_relocs = (_bfd_elf_link_read_relocs
+ internal_relocs = (_bfd_elfNN_link_read_relocs
(abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
link_info->keep_memory));
if (internal_relocs == NULL)
- return FALSE;
+ 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;
@@ -774,101 +665,63 @@ elfNN_ia64_relax_section (abfd, sec, link_info, again)
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;
}
- for (irel = internal_relocs; irel < irelend; irel++)
+ /* 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++)
{
- unsigned long r_type = ELFNN_R_TYPE (irel->r_info);
bfd_vma symaddr, reladdr, trampoff, toff, roff;
+ Elf_Internal_Sym isym;
asection *tsec;
struct one_fixup *f;
- bfd_size_type amt;
- bfd_boolean is_branch;
- struct elfNN_ia64_dyn_sym_info *dyn_i;
-
- switch (r_type)
- {
- case R_IA64_PCREL21B:
- case R_IA64_PCREL21BI:
- case R_IA64_PCREL21M:
- case R_IA64_PCREL21F:
- /* In the finalize pass, all br relaxations are done. We can
- skip it. */
- if (!link_info->need_relax_finalize)
- continue;
- is_branch = TRUE;
- break;
-
- case R_IA64_PCREL60B:
- /* We can't optimize brl to br before the finalize pass since
- br relaxations will increase the code size. Defer it to
- the finalize pass. */
- if (link_info->need_relax_finalize)
- {
- sec->need_finalize_relax = 1;
- continue;
- }
- is_branch = TRUE;
- break;
- case R_IA64_LTOFF22X:
- case R_IA64_LDXMOV:
- /* We can't relax ldx/mov before the finalize pass since
- br relaxations will increase the code size. Defer it to
- the finalize pass. */
- if (link_info->need_relax_finalize)
- {
- sec->need_finalize_relax = 1;
- continue;
- }
- is_branch = FALSE;
- break;
-
- default:
- continue;
- }
+ 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. */
- Elf_Internal_Sym *isym;
-
- /* Read this BFD's local symbols. */
- if (isymbuf == NULL)
- {
- isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
- if (isymbuf == NULL)
- isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- symtab_hdr->sh_info, 0,
- NULL, NULL, NULL);
- if (isymbuf == 0)
- goto error_return;
- }
-
- isym = isymbuf + ELFNN_R_SYM (irel->r_info);
- if (isym->st_shndx == SHN_UNDEF)
- continue; /* We can't do anything with undefined symbols. */
- else if (isym->st_shndx == SHN_ABS)
+ 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 == SHN_IA_64_ANSI_COMMON)
+ 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
- tsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
+ continue; /* who knows. */
- toff = isym->st_value;
- dyn_i = get_dyn_sym_info (ia64_info, NULL, abfd, irel, FALSE);
+ 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];
@@ -878,29 +731,18 @@ elfNN_ia64_relax_section (abfd, sec, link_info, again)
|| 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);
+ 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 (is_branch && dyn_i && dyn_i->want_plt2)
+ if (dyn_i && dyn_i->want_plt2)
{
- /* Internal branches shouldn't be sent to the PLT.
- Leave this for now and we'll give an error later. */
- if (r_type != R_IA64_PCREL21B)
- continue;
-
tsec = ia64_info->plt_sec;
toff = dyn_i->plt2_offset;
- BFD_ASSERT (irel->r_addend == 0);
}
-
- /* Can't do anything else with dynamic symbols. */
- else if (elfNN_ia64_dynamic_symbol_p (h, link_info, r_type))
- continue;
-
else
{
- /* We can't do anything with undefined symbols. */
+ /* We can't do anthing with undefined symbols. */
if (h->root.type == bfd_link_hash_undefined
|| h->root.type == bfd_link_hash_undefweak)
continue;
@@ -910,193 +752,108 @@ elfNN_ia64_relax_section (abfd, sec, link_info, again)
}
}
- if (tsec->sec_info_type == ELF_INFO_TYPE_MERGE)
- toff = _bfd_merged_section_offset (abfd, &tsec,
- elf_section_data (tsec)->sec_info,
- toff + irel->r_addend,
- (bfd_vma) 0);
- else
- toff += irel->r_addend;
-
- symaddr = tsec->output_section->vma + tsec->output_offset + toff;
+ 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 (is_branch)
- {
- bfd_signed_vma offset;
+ /* 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;
- reladdr = (sec->output_section->vma
- + sec->output_offset
- + roff) & (bfd_vma) -4;
+ /* 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;
- /* If the branch is in range, no need to do anything. */
- if ((bfd_signed_vma) (symaddr - reladdr) >= -0x1000000
- && (bfd_signed_vma) (symaddr - reladdr) <= 0x0FFFFF0)
- {
- /* If the 60-bit branch is in 21-bit range, optimize it. */
- if (r_type == R_IA64_PCREL60B)
- {
- elfNN_ia64_relax_brl (abfd, contents, roff);
+ /* Look for an existing fixup to this address. */
+ for (f = fixups; f ; f = f->next)
+ if (f->tsec == tsec && f->toff == toff)
+ break;
- irel->r_info
- = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
- R_IA64_PCREL21B);
+ 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. */
- /* If the original relocation offset points to slot
- 1, change it to slot 2. */
- if ((irel->r_offset & 3) == 1)
- irel->r_offset += 1;
- }
+ int size;
- continue;
+ 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
}
- else if (r_type == R_IA64_PCREL60B)
- 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;
+ /* 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 (f == NULL)
+ if (tsec == ia64_info->plt_sec)
{
- /* 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. */
-
- size_t size;
-
- if (tsec == ia64_info->plt_sec)
- size = sizeof (plt_full_entry);
- else
- size = oor_branch_size;
-
- /* Resize the current section to make room for the new branch. */
- trampoff = (sec->_cooked_size + 15) & (bfd_vma) -16;
-
- /* If trampoline is out of range, there is nothing we
- can do. */
- offset = trampoff - (roff & (bfd_vma) -4);
- if (offset < -0x1000000 || offset > 0x0FFFFF0)
- continue;
-
- amt = trampoff + size;
- contents = (bfd_byte *) bfd_realloc (contents, amt);
- if (contents == NULL)
- goto error_return;
- sec->_cooked_size = amt;
-
- 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
- {
- if (size == sizeof (oor_ip))
- {
- 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;
- }
- else
- {
- 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;
- }
-
- }
+ memcpy (contents + trampoff, plt_full_entry, size);
- /* Record the fixup so we don't do it again this section. */
- f = (struct one_fixup *)
- bfd_malloc ((bfd_size_type) sizeof (*f));
- f->next = fixups;
- f->tsec = tsec;
- f->toff = toff;
- f->trampoff = trampoff;
- fixups = f;
+ /* 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
{
- /* If trampoline is out of range, there is nothing we
- can do. */
- offset = f->trampoff - (roff & (bfd_vma) -4);
- if (offset < -0x1000000 || offset > 0x0FFFFF0)
- continue;
-
- /* Nop out the reloc, since we're finalizing things here. */
- irel->r_info = ELFNN_R_INFO (0, R_IA64_NONE);
+#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
}
- /* Fix up the existing branch to hit the trampoline. */
- if (elfNN_ia64_install_value (abfd, contents + roff, offset,
- r_type) != bfd_reloc_ok)
- goto error_return;
-
- changed_contents = TRUE;
- changed_relocs = TRUE;
+ /* 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
{
- /* Fetch the gp. */
- if (gp == 0)
- {
- bfd *obfd = sec->output_section->owner;
- gp = _bfd_get_gp_value (obfd);
- if (gp == 0)
- {
- if (!elfNN_ia64_choose_gp (obfd, link_info))
- goto error_return;
- gp = _bfd_get_gp_value (obfd);
- }
- }
+ /* Nop out the reloc, since we're finalizing things here. */
+ irel->r_info = ELFNN_R_INFO (0, R_IA64_NONE);
+ }
- /* If the data is out of range, do nothing. */
- if ((bfd_signed_vma) (symaddr - gp) >= 0x200000
- ||(bfd_signed_vma) (symaddr - gp) < -0x200000)
- continue;
+ /* 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;
- if (r_type == R_IA64_LTOFF22X)
- {
- irel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (irel->r_info),
- R_IA64_GPREL22);
- changed_relocs = TRUE;
- if (dyn_i->want_gotx)
- {
- dyn_i->want_gotx = 0;
- changed_got |= !dyn_i->want_got;
- }
- }
- else
- {
- elfNN_ia64_relax_ldxmov (abfd, contents, roff);
- irel->r_info = ELFNN_R_INFO (0, R_IA64_NONE);
- changed_contents = TRUE;
- changed_relocs = TRUE;
- }
- }
+ changed_contents = true;
+ changed_relocs = true;
}
- /* ??? If we created fixups, this may push the code segment large
- enough that the data segment moves, which will change the GP.
- Reset the GP so that we re-calculate next round. We need to
- do this at the _beginning_ of the next round; now will not do. */
-
/* Clean up and go home. */
while (fixups)
{
@@ -1105,23 +862,17 @@ elfNN_ia64_relax_section (abfd, sec, link_info, again)
free (f);
}
- if (isymbuf != NULL
- && symtab_hdr->contents != (unsigned char *) isymbuf)
- {
- if (! link_info->keep_memory)
- free (isymbuf);
- else
- {
- /* Cache the symbols for elf_link_input_bfd. */
- symtab_hdr->contents = (unsigned char *) isymbuf;
- }
- }
+ if (changed_relocs)
+ elf_section_data (sec)->relocs = internal_relocs;
+ else if (free_relocs != NULL)
+ free (free_relocs);
- if (contents != NULL
- && elf_section_data (sec)->this_hdr.contents != contents)
+ if (changed_contents)
+ elf_section_data (sec)->this_hdr.contents = contents;
+ else if (free_contents != NULL)
{
- if (!changed_contents && !link_info->keep_memory)
- free (contents);
+ if (! link_info->keep_memory)
+ free (free_contents);
else
{
/* Cache the section contents for elf_link_input_bfd. */
@@ -1129,94 +880,38 @@ elfNN_ia64_relax_section (abfd, sec, link_info, again)
}
}
- if (elf_section_data (sec)->relocs != internal_relocs)
+ if (free_extsyms != NULL)
{
- if (!changed_relocs)
- free (internal_relocs);
+ if (! link_info->keep_memory)
+ free (free_extsyms);
else
- elf_section_data (sec)->relocs = internal_relocs;
- }
-
- if (changed_got)
- {
- struct elfNN_ia64_allocate_data data;
- data.info = link_info;
- data.ofs = 0;
- ia64_info->self_dtpmod_offset = (bfd_vma) -1;
-
- 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;
- ia64_info->got_sec->_cooked_size = data.ofs;
-
- /* ??? Resize .rela.got too. */
+ {
+ /* Cache the symbols for elf_link_input_bfd. */
+ symtab_hdr->contents = extsyms;
+ }
}
- if (!link_info->need_relax_finalize)
- sec->need_finalize_relax = 0;
-
*again = changed_contents || changed_relocs;
- return TRUE;
+ return true;
error_return:
- if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents)
- free (isymbuf);
- if (contents != NULL
- && elf_section_data (sec)->this_hdr.contents != contents)
- free (contents);
- if (internal_relocs != NULL
- && elf_section_data (sec)->relocs != internal_relocs)
- free (internal_relocs);
- return FALSE;
-}
-
-static void
-elfNN_ia64_relax_ldxmov (abfd, contents, off)
- bfd *abfd;
- bfd_byte *contents;
- bfd_vma off;
-{
- int shift, r1, r3;
- bfd_vma dword, insn;
-
- switch ((int)off & 0x3)
- {
- case 0: shift = 5; break;
- case 1: shift = 14; off += 3; break;
- case 2: shift = 23; off += 6; break;
- default:
- abort ();
- }
-
- dword = bfd_get_64 (abfd, contents + off);
- insn = (dword >> shift) & 0x1ffffffffffLL;
-
- r1 = (insn >> 6) & 127;
- r3 = (insn >> 20) & 127;
- if (r1 == r3)
- insn = 0x8000000; /* nop */
- else
- insn = (insn & 0x7f01fff) | 0x10800000000LL; /* (qp) mov r1 = r3 */
-
- dword &= ~(0x1ffffffffffLL << shift);
- dword |= (insn << shift);
- bfd_put_64 (abfd, dword, contents + off);
+ 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. */
+/* Return true if NAME is an unwind table section name. */
-static inline bfd_boolean
-is_unwind_section_name (abfd, name)
- bfd *abfd;
+static inline boolean
+is_unwind_section_name (name)
const char *name;
{
size_t len1, len2, len3;
- if (elfNN_ia64_hpux_vec (abfd->xvec)
- && !strcmp (name, ELF_STRING_ia64_unwind_hdr))
- return FALSE;
-
len1 = sizeof (ELF_STRING_ia64_unwind) - 1;
len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
len3 = sizeof (ELF_STRING_ia64_unwind_once) - 1;
@@ -1228,11 +923,11 @@ is_unwind_section_name (abfd, name)
/* 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 bfd_boolean
+static boolean
elfNN_ia64_section_from_shdr (abfd, hdr, name)
bfd *abfd;
- Elf_Internal_Shdr *hdr;
- const char *name;
+ ElfNN_Internal_Shdr *hdr;
+ char *name;
{
asection *newsect;
@@ -1244,23 +939,22 @@ elfNN_ia64_section_from_shdr (abfd, hdr, name)
switch (hdr->sh_type)
{
case SHT_IA_64_UNWIND:
- case SHT_IA_64_HP_OPT_ANOT:
break;
case SHT_IA_64_EXT:
if (strcmp (name, ELF_STRING_ia64_archext) != 0)
- return FALSE;
+ return false;
break;
default:
- return FALSE;
+ return false;
}
if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
- return FALSE;
+ return false;
newsect = hdr->bfd_section;
- return TRUE;
+ return true;
}
/* Convert IA-64 specific section flags to bfd internal section flags. */
@@ -1268,31 +962,31 @@ elfNN_ia64_section_from_shdr (abfd, hdr, name)
/* ??? There is no bfd internal flag equivalent to the SHF_IA_64_NORECOV
flag. */
-static bfd_boolean
+static boolean
elfNN_ia64_section_flags (flags, hdr)
flagword *flags;
- Elf_Internal_Shdr *hdr;
+ ElfNN_Internal_Shdr *hdr;
{
if (hdr->sh_flags & SHF_IA_64_SHORT)
*flags |= SEC_SMALL_DATA;
- return TRUE;
+ 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 bfd_boolean
+static boolean
elfNN_ia64_fake_sections (abfd, hdr, sec)
bfd *abfd ATTRIBUTE_UNUSED;
- Elf_Internal_Shdr *hdr;
+ ElfNN_Internal_Shdr *hdr;
asection *sec;
{
register const char *name;
name = bfd_get_section_name (abfd, sec);
- if (is_unwind_section_name (abfd, name))
+ 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. */
@@ -1301,31 +995,31 @@ elfNN_ia64_fake_sections (abfd, hdr, sec)
}
else if (strcmp (name, ELF_STRING_ia64_archext) == 0)
hdr->sh_type = SHT_IA_64_EXT;
- else if (strcmp (name, ".HP.opt_annot") == 0)
- hdr->sh_type = SHT_IA_64_HP_OPT_ANOT;
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. */
+ /*
+ * 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;
+ return true;
}
/* The final processing done just before writing out an IA-64 ELF
@@ -1334,7 +1028,7 @@ elfNN_ia64_fake_sections (abfd, hdr, sec)
static void
elfNN_ia64_final_write_processing (abfd, linker)
bfd *abfd;
- bfd_boolean linker ATTRIBUTE_UNUSED;
+ boolean linker ATTRIBUTE_UNUSED;
{
Elf_Internal_Shdr *hdr;
const char *sname;
@@ -1368,29 +1062,11 @@ elfNN_ia64_final_write_processing (abfd, linker)
{
/* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.t.FOO */
size_t len2 = sizeof (".gnu.linkonce.t.") - 1;
- char *once_name = bfd_malloc (len2 + strlen (sname + len) + 1);
+ char *once_name = alloca (len2 + strlen (sname) - len + 1);
- if (once_name != NULL)
- {
- memcpy (once_name, ".gnu.linkonce.t.", len2);
- strcpy (once_name + len2, sname + len);
- text_sect = bfd_get_section_by_name (abfd, once_name);
- free (once_name);
- }
- else
- /* Should only happen if we run out of memory, in
- which case we're probably toast anyway. Try to
- cope by finding the section the slow way. */
- for (text_sect = abfd->sections;
- text_sect != NULL;
- text_sect = text_sect->next)
- {
- if (strncmp (bfd_section_name (abfd, text_sect),
- ".gnu.linkonce.t.", len2) == 0
- && strcmp (bfd_section_name (abfd, text_sect) + len2,
- sname + len) == 0)
- break;
- }
+ 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 */
@@ -1408,37 +1084,24 @@ elfNN_ia64_final_write_processing (abfd, linker)
break;
}
}
-
- if (! elf_flags_init (abfd))
- {
- unsigned long flags = 0;
-
- if (abfd->xvec->byteorder == BFD_ENDIAN_BIG)
- flags |= EF_IA_64_BE;
- if (bfd_get_mach (abfd) == bfd_mach_ia64_elf64)
- flags |= EF_IA_64_ABI64;
-
- elf_elfheader(abfd)->e_flags = flags;
- elf_flags_init (abfd) = TRUE;
- }
}
/* 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 bfd_boolean
+static boolean
elfNN_ia64_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
bfd *abfd;
struct bfd_link_info *info;
- Elf_Internal_Sym *sym;
+ 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->relocatable
- && sym->st_size <= elf_gp_size (abfd))
+ && !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. */
@@ -1452,14 +1115,14 @@ elfNN_ia64_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
|| !bfd_set_section_flags (abfd, scomm, (SEC_ALLOC
| SEC_IS_COMMON
| SEC_LINKER_CREATED)))
- return FALSE;
+ return false;
}
*secp = scomm;
*valp = sym->st_size;
}
- return TRUE;
+ return true;
}
/* Return the number of additional phdrs we will need. */
@@ -1478,16 +1141,15 @@ elfNN_ia64_additional_program_headers (abfd)
/* Count how many PT_IA_64_UNWIND segments we need. */
for (s = abfd->sections; s; s = s->next)
- if (is_unwind_section_name (abfd, s->name) && (s->flags & SEC_LOAD))
+ if (is_unwind_section_name(s->name) && (s->flags & SEC_LOAD))
++ret;
return ret;
}
-static bfd_boolean
-elfNN_ia64_modify_segment_map (abfd, info)
+static boolean
+elfNN_ia64_modify_segment_map (abfd)
bfd *abfd;
- struct bfd_link_info *info ATTRIBUTE_UNUSED;
{
struct elf_segment_map *m, **pm;
Elf_Internal_Shdr *hdr;
@@ -1503,10 +1165,9 @@ elfNN_ia64_modify_segment_map (abfd, info)
break;
if (m == NULL)
{
- m = ((struct elf_segment_map *)
- bfd_zalloc (abfd, (bfd_size_type) sizeof *m));
+ m = (struct elf_segment_map *) bfd_zalloc (abfd, sizeof *m);
if (m == NULL)
- return FALSE;
+ return false;
m->p_type = PT_IA_64_ARCHEXT;
m->count = 1;
@@ -1534,27 +1195,14 @@ elfNN_ia64_modify_segment_map (abfd, info)
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)
- {
- int i;
-
- /* Look through all sections in the unwind segment
- for a match since there may be multiple sections
- to a segment. */
- for (i = m->count - 1; i >= 0; --i)
- if (m->sections[i] == s)
- break;
-
- if (i >= 0)
- break;
- }
+ if (m->p_type == PT_IA_64_UNWIND && m->sections[0] == s)
+ break;
if (m == NULL)
{
- m = ((struct elf_segment_map *)
- bfd_zalloc (abfd, (bfd_size_type) sizeof *m));
+ m = (struct elf_segment_map *) bfd_zalloc (abfd, sizeof *m);
if (m == NULL)
- return FALSE;
+ return false;
m->p_type = PT_IA_64_UNWIND;
m->count = 1;
@@ -1598,13 +1246,13 @@ elfNN_ia64_modify_segment_map (abfd, info)
found:;
}
- return TRUE;
+ return true;
}
/* According to the Tahoe assembler spec, all labels starting with a
'.' are local. */
-static bfd_boolean
+static boolean
elfNN_ia64_is_local_label_name (abfd, name)
bfd *abfd ATTRIBUTE_UNUSED;
const char *name;
@@ -1614,19 +1262,78 @@ elfNN_ia64_is_local_label_name (abfd, name)
/* Should we do dynamic things to this symbol? */
-static bfd_boolean
-elfNN_ia64_dynamic_symbol_p (h, info, r_type)
+static boolean
+elfNN_ia64_dynamic_symbol_p (h, info)
struct elf_link_hash_entry *h;
struct bfd_link_info *info;
- int r_type;
{
- bfd_boolean ignore_protected
- = ((r_type & 0xf8) == 0x40 /* FPTR relocs */
- || (r_type & 0xf8) == 0x50); /* LTOFF_FPTR relocs */
+ 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 _bfd_elf_dynamic_symbol_p (h, info, ignore_protected);
+ 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;
@@ -1657,14 +1364,13 @@ elfNN_ia64_new_elf_hash_entry (entry, table, string)
}
static void
-elfNN_ia64_hash_copy_indirect (bed, xdir, xind)
- const struct elf_backend_data *bed ATTRIBUTE_UNUSED;
+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;
+ 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. */
@@ -1673,11 +1379,7 @@ elfNN_ia64_hash_copy_indirect (bed, xdir, xind)
(ind->root.elf_link_hash_flags
& (ELF_LINK_HASH_REF_DYNAMIC
| ELF_LINK_HASH_REF_REGULAR
- | ELF_LINK_HASH_REF_REGULAR_NONWEAK
- | ELF_LINK_HASH_NEEDS_PLT));
-
- if (ind->root.root.type != bfd_link_hash_indirect)
- return;
+ | ELF_LINK_HASH_REF_REGULAR_NONWEAK));
/* Copy over the got and plt data. This would have been done
by check_relocs. */
@@ -1708,50 +1410,21 @@ elfNN_ia64_hash_copy_indirect (bed, xdir, xind)
}
static void
-elfNN_ia64_hash_hide_symbol (info, xh, force_local)
- struct bfd_link_info *info;
+elfNN_ia64_hash_hide_symbol (info, xh)
+ struct bfd_link_info *info ATTRIBUTE_UNUSED;
struct elf_link_hash_entry *xh;
- bfd_boolean force_local;
{
struct elfNN_ia64_link_hash_entry *h;
struct elfNN_ia64_dyn_sym_info *dyn_i;
h = (struct elfNN_ia64_link_hash_entry *)xh;
- _bfd_elf_link_hash_hide_symbol (info, &h->root, force_local);
+ 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;
- dyn_i->want_plt = 0;
- }
-}
-
-/* Compute a hash of a local hash entry. */
-
-static hashval_t
-elfNN_ia64_local_htab_hash (ptr)
- const void *ptr;
-{
- struct elfNN_ia64_local_hash_entry *entry
- = (struct elfNN_ia64_local_hash_entry *) ptr;
-
- return (((entry->id & 0xff) << 24) | ((entry->id & 0xff00) << 8))
- ^ entry->r_sym ^ (entry->id >> 16);
-}
-
-/* Compare local hash entries. */
-
-static int
-elfNN_ia64_local_htab_eq (ptr1, ptr2)
- const void *ptr1, *ptr2;
-{
- struct elfNN_ia64_local_hash_entry *entry1
- = (struct elfNN_ia64_local_hash_entry *) ptr1;
- struct elfNN_ia64_local_hash_entry *entry2
- = (struct elfNN_ia64_local_hash_entry *) ptr2;
-
- return entry1->id == entry2->id && entry1->r_sym == entry2->r_sym;
+ dyn_i->want_plt2 = 0;
}
/* Create the derived linker hash table. The IA-64 ELF port uses this
@@ -1764,53 +1437,43 @@ elfNN_ia64_hash_table_create (abfd)
{
struct elfNN_ia64_link_hash_table *ret;
- ret = bfd_zmalloc ((bfd_size_type) sizeof (*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))
{
- free (ret);
- return 0;
- }
-
- ret->loc_hash_table = htab_try_create (1024, elfNN_ia64_local_htab_hash,
- elfNN_ia64_local_htab_eq, NULL);
- ret->loc_hash_memory = objalloc_create ();
- if (!ret->loc_hash_table || !ret->loc_hash_memory)
- {
- free (ret);
+ 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;
}
-/* Destroy IA-64 linker hash table. */
+/* Look up an entry in a Alpha ELF linker hash table. */
-static void
-elfNN_ia64_hash_table_free (hash)
- struct bfd_link_hash_table *hash;
+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;
{
- struct elfNN_ia64_link_hash_table *ia64_info
- = (struct elfNN_ia64_link_hash_table *) hash;
- if (ia64_info->loc_hash_table)
- htab_delete (ia64_info->loc_hash_table);
- if (ia64_info->loc_hash_memory)
- objalloc_free ((struct objalloc *) ia64_info->loc_hash_memory);
- _bfd_generic_link_hash_table_free (hash);
+ 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
{
- bfd_boolean (*func) PARAMS ((struct elfNN_ia64_dyn_sym_info *, PTR));
+ boolean (*func) PARAMS ((struct elfNN_ia64_dyn_sym_info *, PTR));
PTR data;
};
-static bfd_boolean
+static boolean
elfNN_ia64_global_dyn_sym_thunk (xentry, xdata)
struct bfd_hash_entry *xentry;
PTR xdata;
@@ -1821,36 +1484,33 @@ elfNN_ia64_global_dyn_sym_thunk (xentry, xdata)
= (struct elfNN_ia64_dyn_sym_traverse_data *) xdata;
struct elfNN_ia64_dyn_sym_info *dyn_i;
- if (entry->root.root.type == bfd_link_hash_warning)
- entry = (struct elfNN_ia64_link_hash_entry *) entry->root.root.u.i.link;
-
for (dyn_i = entry->info; dyn_i; dyn_i = dyn_i->next)
if (! (*data->func) (dyn_i, data->data))
- return FALSE;
- return TRUE;
+ return false;
+ return true;
}
-static bfd_boolean
-elfNN_ia64_local_dyn_sym_thunk (slot, xdata)
- void **slot;
+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 *) *slot;
+ = (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 0;
- return 1;
+ return false;
+ return true;
}
static void
elfNN_ia64_dyn_sym_traverse (ia64_info, func, data)
struct elfNN_ia64_link_hash_table *ia64_info;
- bfd_boolean (*func) PARAMS ((struct elfNN_ia64_dyn_sym_info *, PTR));
+ boolean (*func) PARAMS ((struct elfNN_ia64_dyn_sym_info *, PTR));
PTR data;
{
struct elfNN_ia64_dyn_sym_traverse_data xdata;
@@ -1860,11 +1520,11 @@ elfNN_ia64_dyn_sym_traverse (ia64_info, func, data)
elf_link_hash_traverse (&ia64_info->root,
elfNN_ia64_global_dyn_sym_thunk, &xdata);
- htab_traverse (ia64_info->loc_hash_table,
- elfNN_ia64_local_dyn_sym_thunk, &xdata);
+ bfd_hash_traverse (&ia64_info->loc_hash_table.root,
+ elfNN_ia64_local_dyn_sym_thunk, &xdata);
}
-static bfd_boolean
+static boolean
elfNN_ia64_create_dynamic_sections (abfd, info)
bfd *abfd;
struct bfd_link_info *info;
@@ -1873,7 +1533,7 @@ elfNN_ia64_create_dynamic_sections (abfd, info)
asection *s;
if (! _bfd_elf_create_dynamic_sections (abfd, info))
- return FALSE;
+ return false;
ia64_info = elfNN_ia64_hash_table (info);
@@ -1883,12 +1543,10 @@ elfNN_ia64_create_dynamic_sections (abfd, info)
{
flagword flags = bfd_get_section_flags (abfd, ia64_info->got_sec);
bfd_set_section_flags (abfd, ia64_info->got_sec, SEC_SMALL_DATA | flags);
- /* The .got section is always aligned at 8 bytes. */
- bfd_set_section_alignment (abfd, ia64_info->got_sec, 3);
}
if (!get_pltoff (abfd, info, ia64_info))
- return FALSE;
+ return false;
s = bfd_make_section(abfd, ".rela.IA_64.pltoff");
if (s == NULL
@@ -1898,7 +1556,7 @@ elfNN_ia64_create_dynamic_sections (abfd, info)
| SEC_LINKER_CREATED
| SEC_READONLY))
|| !bfd_set_section_alignment (abfd, s, 3))
- return FALSE;
+ return false;
ia64_info->rel_pltoff_sec = s;
s = bfd_make_section(abfd, ".rela.got");
@@ -1909,48 +1567,10 @@ elfNN_ia64_create_dynamic_sections (abfd, info)
| SEC_LINKER_CREATED
| SEC_READONLY))
|| !bfd_set_section_alignment (abfd, s, 3))
- return FALSE;
+ return false;
ia64_info->rel_got_sec = s;
- return TRUE;
-}
-
-/* Find and/or create a hash entry for local symbol. */
-static struct elfNN_ia64_local_hash_entry *
-get_local_sym_hash (ia64_info, abfd, rel, create)
- struct elfNN_ia64_link_hash_table *ia64_info;
- bfd *abfd;
- const Elf_Internal_Rela *rel;
- bfd_boolean create;
-{
- struct elfNN_ia64_local_hash_entry e, *ret;
- asection *sec = abfd->sections;
- hashval_t h = (((sec->id & 0xff) << 24) | ((sec->id & 0xff00) << 8))
- ^ ELFNN_R_SYM (rel->r_info) ^ (sec->id >> 16);
- void **slot;
-
- e.id = sec->id;
- e.r_sym = ELFNN_R_SYM (rel->r_info);
- slot = htab_find_slot_with_hash (ia64_info->loc_hash_table, &e, h,
- create ? INSERT : NO_INSERT);
-
- if (!slot)
- return NULL;
-
- if (*slot)
- return (struct elfNN_ia64_local_hash_entry *) *slot;
-
- ret = (struct elfNN_ia64_local_hash_entry *)
- objalloc_alloc ((struct objalloc *) ia64_info->loc_hash_memory,
- sizeof (struct elfNN_ia64_local_hash_entry));
- if (ret)
- {
- memset (ret, 0, sizeof (*ret));
- ret->id = sec->id;
- ret->r_sym = ELFNN_R_SYM (rel->r_info);
- *slot = ret;
- }
- return ret;
+ return true;
}
/* Find and/or create a descriptor for dynamic symbol info. This will
@@ -1962,7 +1582,7 @@ get_dyn_sym_info (ia64_info, h, abfd, rel, create)
struct elf_link_hash_entry *h;
bfd *abfd;
const Elf_Internal_Rela *rel;
- bfd_boolean create;
+ boolean create;
{
struct elfNN_ia64_dyn_sym_info **pp;
struct elfNN_ia64_dyn_sym_info *dyn_i;
@@ -1973,13 +1593,22 @@ get_dyn_sym_info (ia64_info, h, abfd, rel, create)
else
{
struct elfNN_ia64_local_hash_entry *loc_h;
+ char *addr_name;
+ size_t len;
- loc_h = get_local_sym_hash (ia64_info, abfd, rel, create);
- if (!loc_h)
- {
- BFD_ASSERT (!create);
- return NULL;
- }
+ /* 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;
}
@@ -1989,8 +1618,8 @@ get_dyn_sym_info (ia64_info, h, abfd, rel, create)
if (dyn_i == NULL && create)
{
- dyn_i = ((struct elfNN_ia64_dyn_sym_info *)
- bfd_zalloc (abfd, (bfd_size_type) sizeof *dyn_i));
+ dyn_i = (struct elfNN_ia64_dyn_sym_info *)
+ bfd_zalloc (abfd, sizeof *dyn_i);
*pp = dyn_i;
dyn_i->addend = addend;
}
@@ -2022,10 +1651,6 @@ get_got (abfd, info, ia64_info)
BFD_ASSERT (got);
ia64_info->got_sec = got;
- /* The .got section is always aligned at 8 bytes. */
- if (!bfd_set_section_alignment (abfd, got, 3))
- return 0;
-
flags = bfd_get_section_flags (abfd, got);
bfd_set_section_flags (abfd, got, SEC_SMALL_DATA | flags);
}
@@ -2034,14 +1659,14 @@ get_got (abfd, info, ia64_info)
}
/* Create function descriptor section (.opd). This section is called .opd
- because it contains "official procedure descriptors". The "official"
+ 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;
+ struct bfd_link_info *info ATTRIBUTE_UNUSED;
struct elfNN_ia64_link_hash_table *ia64_info;
{
asection *fptr;
@@ -2061,7 +1686,7 @@ get_fptr (abfd, info, ia64_info)
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
- | (info->pie ? 0 : SEC_READONLY)
+ | SEC_READONLY
| SEC_LINKER_CREATED))
|| !bfd_set_section_alignment (abfd, fptr, 4))
{
@@ -2070,26 +1695,6 @@ get_fptr (abfd, info, ia64_info)
}
ia64_info->fptr_sec = fptr;
-
- if (info->pie)
- {
- asection *fptr_rel;
- fptr_rel = bfd_make_section(dynobj, ".rela.opd");
- if (fptr_rel == NULL
- || !bfd_set_section_flags (dynobj, fptr_rel,
- (SEC_ALLOC | SEC_LOAD
- | SEC_HAS_CONTENTS
- | SEC_IN_MEMORY
- | SEC_LINKER_CREATED
- | SEC_READONLY))
- || !bfd_set_section_alignment (abfd, fptr_rel, 3))
- {
- BFD_ASSERT (0);
- return NULL;
- }
-
- ia64_info->rel_fptr_sec = fptr_rel;
- }
}
return fptr;
@@ -2137,7 +1742,7 @@ get_reloc_section (abfd, ia64_info, sec, create)
bfd *abfd;
struct elfNN_ia64_link_hash_table *ia64_info;
asection *sec;
- bfd_boolean create;
+ boolean create;
{
const char *srel_name;
asection *srel;
@@ -2179,9 +1784,12 @@ get_reloc_section (abfd, ia64_info, sec, create)
return srel;
}
-static bfd_boolean
-count_dyn_reloc (bfd *abfd, struct elfNN_ia64_dyn_sym_info *dyn_i,
- asection *srel, int type, bfd_boolean reltext)
+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;
@@ -2191,10 +1799,10 @@ count_dyn_reloc (bfd *abfd, struct elfNN_ia64_dyn_sym_info *dyn_i,
if (!rent)
{
- rent = ((struct elfNN_ia64_dyn_reloc_entry *)
- bfd_alloc (abfd, (bfd_size_type) sizeof (*rent)));
+ rent = (struct elfNN_ia64_dyn_reloc_entry *)
+ bfd_alloc (abfd, sizeof (*rent));
if (!rent)
- return FALSE;
+ return false;
rent->next = dyn_i->reloc_entries;
rent->srel = srel;
@@ -2202,13 +1810,12 @@ count_dyn_reloc (bfd *abfd, struct elfNN_ia64_dyn_sym_info *dyn_i,
rent->count = 0;
dyn_i->reloc_entries = rent;
}
- rent->reltext = reltext;
rent->count++;
- return TRUE;
+ return true;
}
-static bfd_boolean
+static boolean
elfNN_ia64_check_relocs (abfd, info, sec, relocs)
bfd *abfd;
struct bfd_link_info *info;
@@ -2221,8 +1828,8 @@ elfNN_ia64_check_relocs (abfd, info, sec, relocs)
const Elf_Internal_Rela *rel;
asection *got, *fptr, *srel;
- if (info->relocatable)
- return TRUE;
+ if (info->relocateable)
+ return true;
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
ia64_info = elfNN_ia64_hash_table (info);
@@ -2234,23 +1841,19 @@ elfNN_ia64_check_relocs (abfd, info, sec, relocs)
{
enum {
NEED_GOT = 1,
- NEED_GOTX = 2,
- NEED_FPTR = 4,
- NEED_PLTOFF = 8,
- NEED_MIN_PLT = 16,
- NEED_FULL_PLT = 32,
- NEED_DYNREL = 64,
- NEED_LTOFF_FPTR = 128,
- NEED_TPREL = 256,
- NEED_DTPMOD = 512,
- NEED_DTPREL = 1024
+ 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;
- bfd_boolean maybe_dynamic;
+ boolean maybe_dynamic;
int dynrel_type = R_IA64_NONE;
if (r_symndx >= symtab_hdr->sh_info)
@@ -2270,57 +1873,23 @@ elfNN_ia64_check_relocs (abfd, info, sec, relocs)
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->executable
- && (!info->symbolic || info->unresolved_syms_in_shared_libs == RM_IGNORE))
+ 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;
+ 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:
- if (info->shared || maybe_dynamic)
- need_entry = NEED_DYNREL;
- dynrel_type = R_IA64_TPREL64LSB;
- if (info->shared)
- info->flags |= DF_STATIC_TLS;
- break;
-
- case R_IA64_LTOFF_TPREL22:
- need_entry = NEED_TPREL;
- if (info->shared)
- info->flags |= DF_STATIC_TLS;
- break;
-
- case R_IA64_DTPREL64MSB:
- case R_IA64_DTPREL64LSB:
- if (info->shared || maybe_dynamic)
- need_entry = NEED_DYNREL;
- dynrel_type = R_IA64_DTPREL64LSB;
- break;
-
- case R_IA64_LTOFF_DTPREL22:
- need_entry = NEED_DTPREL;
- break;
-
- case R_IA64_DTPMOD64MSB:
- case R_IA64_DTPMOD64LSB:
- if (info->shared || maybe_dynamic)
- need_entry = NEED_DYNREL;
- dynrel_type = R_IA64_DTPMOD64LSB;
- break;
-
- case R_IA64_LTOFF_DTPMOD22:
- need_entry = NEED_DTPMOD;
- break;
+ case R_IA64_LTOFF_TP22:
+ return false;
case R_IA64_LTOFF_FPTR22:
case R_IA64_LTOFF_FPTR64I:
- case R_IA64_LTOFF_FPTR32MSB:
- case R_IA64_LTOFF_FPTR32LSB:
case R_IA64_LTOFF_FPTR64MSB:
case R_IA64_LTOFF_FPTR64LSB:
need_entry = NEED_FPTR | NEED_GOT | NEED_LTOFF_FPTR;
@@ -2339,14 +1908,11 @@ elfNN_ia64_check_relocs (abfd, info, sec, relocs)
break;
case R_IA64_LTOFF22:
+ case R_IA64_LTOFF22X:
case R_IA64_LTOFF64I:
need_entry = NEED_GOT;
break;
- case R_IA64_LTOFF22X:
- need_entry = NEED_GOTX;
- break;
-
case R_IA64_PLTOFF22:
case R_IA64_PLTOFF64I:
case R_IA64_PLTOFF64MSB:
@@ -2361,7 +1927,7 @@ elfNN_ia64_check_relocs (abfd, info, sec, relocs)
{
(*info->callbacks->warning)
(info, _("@pltoff reloc against local symbol"), 0,
- abfd, 0, (bfd_vma) 0);
+ abfd, 0, 0);
}
break;
@@ -2416,34 +1982,24 @@ elfNN_ia64_check_relocs (abfd, info, sec, relocs)
{
(*info->callbacks->warning)
(info, _("non-zero addend in @fptr reloc"), 0,
- abfd, 0, (bfd_vma) 0);
+ abfd, 0, 0);
}
- dyn_i = get_dyn_sym_info (ia64_info, h, abfd, rel, TRUE);
+ 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 | NEED_GOTX | NEED_TPREL
- | NEED_DTPMOD | NEED_DTPREL))
+ if (need_entry & NEED_GOT)
{
if (!got)
{
got = get_got (abfd, info, ia64_info);
if (!got)
- return FALSE;
+ return false;
}
- if (need_entry & NEED_GOT)
- dyn_i->want_got = 1;
- if (need_entry & NEED_GOTX)
- dyn_i->want_gotx = 1;
- if (need_entry & NEED_TPREL)
- dyn_i->want_tprel = 1;
- if (need_entry & NEED_DTPMOD)
- dyn_i->want_dtpmod = 1;
- if (need_entry & NEED_DTPREL)
- dyn_i->want_dtprel = 1;
+ dyn_i->want_got = 1;
}
if (need_entry & NEED_FPTR)
{
@@ -2451,7 +2007,7 @@ elfNN_ia64_check_relocs (abfd, info, sec, relocs)
{
fptr = get_fptr (abfd, info, ia64_info);
if (!fptr)
- return FALSE;
+ return false;
}
/* FPTRs for shared libraries are allocated by the dynamic
@@ -2459,9 +2015,9 @@ elfNN_ia64_check_relocs (abfd, info, sec, relocs)
dynamic symbol table. */
if (!h && info->shared)
{
- if (! (bfd_elf_link_record_local_dynamic_symbol
- (info, abfd, (long) r_symndx)))
- return FALSE;
+ if (! (_bfd_elfNN_link_record_local_dynamic_symbol
+ (info, abfd, r_symndx)))
+ return false;
}
dyn_i->want_fptr = 1;
@@ -2483,72 +2039,47 @@ elfNN_ia64_check_relocs (abfd, info, sec, relocs)
{
if (!srel)
{
- srel = get_reloc_section (abfd, ia64_info, sec, TRUE);
+ srel = get_reloc_section (abfd, ia64_info, sec, true);
if (!srel)
- return FALSE;
+ return false;
}
- if (!count_dyn_reloc (abfd, dyn_i, srel, dynrel_type,
- (sec->flags & SEC_READONLY) != 0))
- return FALSE;
+ if (!count_dyn_reloc (abfd, dyn_i, srel, dynrel_type))
+ return false;
}
}
- return TRUE;
+ 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 bfd_boolean
+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_gotx)
+ if (dyn_i->want_got
&& ! dyn_i->want_fptr
- && elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info, 0))
+ && elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info))
{
dyn_i->got_offset = x->ofs;
x->ofs += 8;
}
- if (dyn_i->want_tprel)
- {
- dyn_i->tprel_offset = x->ofs;
- x->ofs += 8;
- }
- if (dyn_i->want_dtpmod)
- {
- if (elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info, 0))
- {
- dyn_i->dtpmod_offset = x->ofs;
- x->ofs += 8;
- }
- else
- {
- struct elfNN_ia64_link_hash_table *ia64_info;
-
- ia64_info = elfNN_ia64_hash_table (x->info);
- if (ia64_info->self_dtpmod_offset == (bfd_vma) -1)
- {
- ia64_info->self_dtpmod_offset = x->ofs;
- x->ofs += 8;
- }
- dyn_i->dtpmod_offset = ia64_info->self_dtpmod_offset;
- }
- }
- if (dyn_i->want_dtprel)
- {
- dyn_i->dtprel_offset = x->ofs;
- x->ofs += 8;
- }
- return TRUE;
+ return true;
}
/* Next, allocate all the GOT entries used by LTOFF_FPTR relocs. */
-static bfd_boolean
+static boolean
allocate_global_fptr_got (dyn_i, data)
struct elfNN_ia64_dyn_sym_info *dyn_i;
PTR data;
@@ -2557,35 +2088,35 @@ allocate_global_fptr_got (dyn_i, data)
if (dyn_i->want_got
&& dyn_i->want_fptr
- && elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info, R_IA64_FPTR64LSB))
+ && elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info))
{
dyn_i->got_offset = x->ofs;
x->ofs += 8;
}
- return TRUE;
+ return true;
}
/* Lastly, allocate all the GOT entries for local data. */
-static bfd_boolean
+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 || dyn_i->want_gotx)
- && !elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info, 0))
+ 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;
+ return true;
}
/* Search for the index of a global symbol in it's defining object file. */
-static long
+static unsigned long
global_sym_index (h)
struct elf_link_hash_entry *h;
{
@@ -2605,7 +2136,7 @@ global_sym_index (h)
/* Allocate function descriptors. We can do these for every function
in a main executable that is not exported. */
-static bfd_boolean
+static boolean
allocate_fptr (dyn_i, data)
struct elfNN_ia64_dyn_sym_info *dyn_i;
PTR data;
@@ -2621,20 +2152,17 @@ allocate_fptr (dyn_i, data)
|| h->root.type == bfd_link_hash_warning)
h = (struct elf_link_hash_entry *) h->root.u.i.link;
- if (!x->info->executable
- && (!h
- || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
- || h->root.type != bfd_link_hash_undefweak))
+ 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_elf_link_record_local_dynamic_symbol
+ if (!_bfd_elfNN_link_record_local_dynamic_symbol
(x->info, h->root.u.def.section->owner,
global_sym_index (h)))
- return FALSE;
+ return false;
}
dyn_i->want_fptr = 0;
@@ -2647,12 +2175,12 @@ allocate_fptr (dyn_i, data)
else
dyn_i->want_fptr = 0;
}
- return TRUE;
+ return true;
}
/* Allocate all the minimal PLT entries. */
-static bfd_boolean
+static boolean
allocate_plt_entries (dyn_i, data)
struct elfNN_ia64_dyn_sym_info *dyn_i;
PTR data;
@@ -2669,7 +2197,7 @@ allocate_plt_entries (dyn_i, data)
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, 0))
+ if (elfNN_ia64_dynamic_symbol_p (h, x->info))
{
bfd_size_type offset = x->ofs;
if (offset == 0)
@@ -2685,12 +2213,12 @@ allocate_plt_entries (dyn_i, data)
dyn_i->want_plt2 = 0;
}
}
- return TRUE;
+ return true;
}
/* Allocate all the full PLT entries. */
-static bfd_boolean
+static boolean
allocate_plt2_entries (dyn_i, data)
struct elfNN_ia64_dyn_sym_info *dyn_i;
PTR data;
@@ -2710,7 +2238,7 @@ allocate_plt2_entries (dyn_i, data)
h = (struct elf_link_hash_entry *) h->root.u.i.link;
dyn_i->h->plt.offset = ofs;
}
- return TRUE;
+ return true;
}
/* Allocate all the PLTOFF entries requested by relocations and
@@ -2718,7 +2246,7 @@ allocate_plt2_entries (dyn_i, data)
because the latter are not necessarily addressable by the GP.
??? Relaxation might be able to determine that they are. */
-static bfd_boolean
+static boolean
allocate_pltoff_entries (dyn_i, data)
struct elfNN_ia64_dyn_sym_info *dyn_i;
PTR data;
@@ -2730,13 +2258,13 @@ allocate_pltoff_entries (dyn_i, data)
dyn_i->pltoff_offset = x->ofs;
x->ofs += 16;
}
- return TRUE;
+ return true;
}
/* Allocate dynamic relocations for those symbols that turned out
to be dynamic. */
-static bfd_boolean
+static boolean
allocate_dynrel_entries (dyn_i, data)
struct elfNN_ia64_dyn_sym_info *dyn_i;
PTR data;
@@ -2744,17 +2272,11 @@ allocate_dynrel_entries (dyn_i, 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;
- bfd_boolean dynamic_symbol, shared, resolved_zero;
+ boolean dynamic_symbol, shared;
ia64_info = elfNN_ia64_hash_table (x->info);
-
- /* Note that this can't be used in relation to FPTR relocs below. */
- dynamic_symbol = elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info, 0);
-
+ dynamic_symbol = elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info);
shared = x->info->shared;
- resolved_zero = (dyn_i->h
- && ELF_ST_VISIBILITY (dyn_i->h->other)
- && dyn_i->h->root.type == bfd_link_hash_undefweak);
/* Take care of the normal data relocations. */
@@ -2765,11 +2287,10 @@ allocate_dynrel_entries (dyn_i, data)
switch (rent->type)
{
case R_IA64_FPTR64LSB:
- /* Allocate one iff !want_fptr and not PIE, which by this point
- will be true only if we're actually allocating one statically
- in the main executable. Position independent executables
- need a relative reloc. */
- if (dyn_i->want_fptr && !x->info->pie)
+ /* 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:
@@ -2788,46 +2309,19 @@ allocate_dynrel_entries (dyn_i, data)
if (!dynamic_symbol)
count *= 2;
break;
- case R_IA64_TPREL64LSB:
- case R_IA64_DTPREL64LSB:
- case R_IA64_DTPMOD64LSB:
- break;
default:
abort ();
}
- if (rent->reltext)
- ia64_info->reltext = 1;
rent->srel->_raw_size += sizeof (ElfNN_External_Rela) * count;
}
/* Take care of the GOT and PLT relocations. */
- if ((!resolved_zero
- && (dynamic_symbol || shared)
- && (dyn_i->want_got || dyn_i->want_gotx))
- || (dyn_i->want_ltoff_fptr
- && dyn_i->h
- && dyn_i->h->dynindx != -1))
- {
- if (!dyn_i->want_ltoff_fptr
- || !x->info->pie
- || dyn_i->h == NULL
- || dyn_i->h->root.type != bfd_link_hash_undefweak)
- ia64_info->rel_got_sec->_raw_size += sizeof (ElfNN_External_Rela);
- }
- if ((dynamic_symbol || shared) && dyn_i->want_tprel)
+ 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 (dynamic_symbol && dyn_i->want_dtpmod)
- ia64_info->rel_got_sec->_raw_size += sizeof (ElfNN_External_Rela);
- if (dynamic_symbol && dyn_i->want_dtprel)
- ia64_info->rel_got_sec->_raw_size += sizeof (ElfNN_External_Rela);
- if (ia64_info->rel_fptr_sec && dyn_i->want_fptr)
- {
- if (dyn_i->h == NULL || dyn_i->h->root.type != bfd_link_hash_undefweak)
- ia64_info->rel_fptr_sec->_raw_size += sizeof (ElfNN_External_Rela);
- }
- if (!resolved_zero && dyn_i->want_pltoff)
+ if (dyn_i->want_pltoff)
{
bfd_size_type t = 0;
@@ -2842,10 +2336,10 @@ allocate_dynrel_entries (dyn_i, data)
ia64_info->rel_pltoff_sec->_raw_size += t;
}
- return TRUE;
+ return true;
}
-static bfd_boolean
+static boolean
elfNN_ia64_adjust_dynamic_symbol (info, h)
struct bfd_link_info *info ATTRIBUTE_UNUSED;
struct elf_link_hash_entry *h;
@@ -2862,7 +2356,7 @@ elfNN_ia64_adjust_dynamic_symbol (info, h)
|| 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;
+ return true;
}
/* If this is a reference to a symbol defined by a dynamic object which
@@ -2872,29 +2366,29 @@ elfNN_ia64_adjust_dynamic_symbol (info, h)
But IA-64 code is canonically PIC, so as a rule we can avoid this sort
of hackery. */
- return TRUE;
+ return true;
}
-static bfd_boolean
+static boolean
elfNN_ia64_size_dynamic_sections (output_bfd, info)
- bfd *output_bfd ATTRIBUTE_UNUSED;
+ 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;
- bfd_boolean relplt = FALSE;
+ boolean reltext = false;
+ boolean relplt = false;
dynobj = elf_hash_table(info)->dynobj;
ia64_info = elfNN_ia64_hash_table (info);
- ia64_info->self_dtpmod_offset = (bfd_vma) -1;
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->executable)
+ && !info->shared)
{
sec = bfd_get_section_by_name (dynobj, ".interp");
BFD_ASSERT (sec != NULL);
@@ -2924,7 +2418,7 @@ elfNN_ia64_size_dynamic_sections (output_bfd, info)
/* 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
+ 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;
@@ -2938,15 +2432,11 @@ elfNN_ia64_size_dynamic_sections (output_bfd, info)
}
/* Align the pointer for the plt2 entries. */
- data.ofs = (data.ofs + 31) & (bfd_vma) -32;
+ data.ofs = (data.ofs + 31) & -32;
elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_plt2_entries, &data);
- if (data.ofs != 0 || ia64_info->root.dynamic_sections_created)
+ if (data.ofs != 0)
{
- /* FIXME: we always reserve the memory for dynamic linker even if
- there are no PLT entries since dynamic linker may assume the
- reserved memory always exists. */
-
BFD_ASSERT (ia64_info->root.dynamic_sections_created);
ia64_info->plt_sec->_raw_size = data.ofs;
@@ -2971,8 +2461,6 @@ elfNN_ia64_size_dynamic_sections (output_bfd, info)
/* Allocate space for the dynamic relocations that turned out to be
required. */
- if (info->shared && ia64_info->self_dtpmod_offset != (bfd_vma) -1)
- ia64_info->rel_got_sec->_raw_size += sizeof (ElfNN_External_Rela);
elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_dynrel_entries, &data);
}
@@ -2980,7 +2468,7 @@ elfNN_ia64_size_dynamic_sections (output_bfd, info)
Allocate memory for them. */
for (sec = dynobj->sections; sec != NULL; sec = sec->next)
{
- bfd_boolean strip;
+ boolean strip;
if (!(sec->flags & SEC_LINKER_CREATED))
continue;
@@ -2996,7 +2484,7 @@ elfNN_ia64_size_dynamic_sections (output_bfd, info)
strip = (sec->_raw_size == 0);
if (sec == ia64_info->got_sec)
- strip = FALSE;
+ strip = false;
else if (sec == ia64_info->rel_got_sec)
{
if (strip)
@@ -3011,15 +2499,6 @@ elfNN_ia64_size_dynamic_sections (output_bfd, info)
if (strip)
ia64_info->fptr_sec = NULL;
}
- else if (sec == ia64_info->rel_fptr_sec)
- {
- if (strip)
- ia64_info->rel_fptr_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->plt_sec)
{
if (strip)
@@ -3036,7 +2515,7 @@ elfNN_ia64_size_dynamic_sections (output_bfd, info)
ia64_info->rel_pltoff_sec = NULL;
else
{
- relplt = TRUE;
+ 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;
@@ -3051,11 +2530,29 @@ elfNN_ia64_size_dynamic_sections (output_bfd, info)
name = bfd_get_section_name (dynobj, sec);
if (strcmp (name, ".got.plt") == 0)
- strip = FALSE;
+ 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;
@@ -3070,9 +2567,9 @@ elfNN_ia64_size_dynamic_sections (output_bfd, info)
else
{
/* Allocate memory for the section contents. */
- sec->contents = (bfd_byte *) bfd_zalloc (dynobj, sec->_raw_size);
+ sec->contents = (bfd_byte *) bfd_zalloc(dynobj, sec->_raw_size);
if (sec->contents == NULL && sec->_raw_size != 0)
- return FALSE;
+ return false;
}
}
@@ -3082,53 +2579,51 @@ elfNN_ia64_size_dynamic_sections (output_bfd, info)
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->executable)
+ if (!info->shared)
{
/* The DT_DEBUG entry is filled in by the dynamic linker and used
by the debugger. */
-#define add_dynamic_entry(TAG, VAL) \
- _bfd_elf_add_dynamic_entry (info, TAG, VAL)
-
- if (!add_dynamic_entry (DT_DEBUG, 0))
- return FALSE;
+ if (!bfd_elfNN_add_dynamic_entry (info, DT_DEBUG, 0))
+ return false;
}
- if (!add_dynamic_entry (DT_IA_64_PLT_RESERVE, 0))
- return FALSE;
- if (!add_dynamic_entry (DT_PLTGOT, 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 (!add_dynamic_entry (DT_PLTRELSZ, 0)
- || !add_dynamic_entry (DT_PLTREL, DT_RELA)
- || !add_dynamic_entry (DT_JMPREL, 0))
- return FALSE;
+ 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 (!add_dynamic_entry (DT_RELA, 0)
- || !add_dynamic_entry (DT_RELASZ, 0)
- || !add_dynamic_entry (DT_RELAENT, sizeof (ElfNN_External_Rela)))
- 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 (ia64_info->reltext)
+ if (reltext)
{
- if (!add_dynamic_entry (DT_TEXTREL, 0))
- return FALSE;
+ if (! bfd_elfNN_add_dynamic_entry (info, DT_TEXTREL, 0))
+ return false;
info->flags |= DF_TEXTREL;
}
}
/* ??? Perhaps force __gp local. */
- return TRUE;
+ return true;
}
static bfd_reloc_status_type
-elfNN_ia64_install_value (abfd, hit_addr, v, r_type)
+elfNN_ia64_install_value (abfd, hit_addr, val, r_type)
bfd *abfd;
bfd_byte *hit_addr;
- bfd_vma v;
+ bfd_vma val;
unsigned int r_type;
{
const struct ia64_operand *op;
@@ -3137,11 +2632,6 @@ elfNN_ia64_install_value (abfd, hit_addr, v, r_type)
enum ia64_opnd opnd;
const char *err;
size_t size = 8;
-#ifdef BFD_HOST_U_64_BIT
- BFD_HOST_U_64_BIT val = (BFD_HOST_U_64_BIT) v;
-#else
- bfd_vma val = v;
-#endif
opnd = IA64_OPND_NIL;
switch (r_type)
@@ -3152,11 +2642,7 @@ elfNN_ia64_install_value (abfd, hit_addr, v, r_type)
/* Instruction relocations. */
- case R_IA64_IMM14:
- case R_IA64_TPREL14:
- case R_IA64_DTPREL14:
- opnd = IA64_OPND_IMM14;
- break;
+ 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;
@@ -3173,11 +2659,6 @@ elfNN_ia64_install_value (abfd, hit_addr, v, r_type)
case R_IA64_PLTOFF22:
case R_IA64_PCREL22:
case R_IA64_LTOFF_FPTR22:
- case R_IA64_TPREL22:
- case R_IA64_DTPREL22:
- case R_IA64_LTOFF_TPREL22:
- case R_IA64_LTOFF_DTPMOD22:
- case R_IA64_LTOFF_DTPREL22:
opnd = IA64_OPND_IMM22;
break;
@@ -3188,8 +2669,6 @@ elfNN_ia64_install_value (abfd, hit_addr, v, r_type)
case R_IA64_PCREL64I:
case R_IA64_FPTR64I:
case R_IA64_LTOFF_FPTR64I:
- case R_IA64_TPREL64I:
- case R_IA64_DTPREL64I:
opnd = IA64_OPND_IMMU64;
break;
@@ -3199,11 +2678,9 @@ elfNN_ia64_install_value (abfd, hit_addr, v, r_type)
case R_IA64_GPREL32MSB:
case R_IA64_FPTR32MSB:
case R_IA64_PCREL32MSB:
- case R_IA64_LTOFF_FPTR32MSB:
case R_IA64_SEGREL32MSB:
case R_IA64_SECREL32MSB:
case R_IA64_LTV32MSB:
- case R_IA64_DTPREL32MSB:
size = 4; bigendian = 1;
break;
@@ -3211,11 +2688,9 @@ elfNN_ia64_install_value (abfd, hit_addr, v, r_type)
case R_IA64_GPREL32LSB:
case R_IA64_FPTR32LSB:
case R_IA64_PCREL32LSB:
- case R_IA64_LTOFF_FPTR32LSB:
case R_IA64_SEGREL32LSB:
case R_IA64_SECREL32LSB:
case R_IA64_LTV32LSB:
- case R_IA64_DTPREL32LSB:
size = 4; bigendian = 0;
break;
@@ -3228,9 +2703,6 @@ elfNN_ia64_install_value (abfd, hit_addr, v, r_type)
case R_IA64_SEGREL64MSB:
case R_IA64_SECREL64MSB:
case R_IA64_LTV64MSB:
- case R_IA64_TPREL64MSB:
- case R_IA64_DTPMOD64MSB:
- case R_IA64_DTPREL64MSB:
size = 8; bigendian = 1;
break;
@@ -3243,9 +2715,6 @@ elfNN_ia64_install_value (abfd, hit_addr, v, r_type)
case R_IA64_SEGREL64LSB:
case R_IA64_SECREL64LSB:
case R_IA64_LTV64LSB:
- case R_IA64_TPREL64LSB:
- case R_IA64_DTPMOD64LSB:
- case R_IA64_DTPREL64LSB:
size = 8; bigendian = 0;
break;
@@ -3322,7 +2791,7 @@ elfNN_ia64_install_value (abfd, hit_addr, v, r_type)
insn = (dword >> shift) & 0x1ffffffffffLL;
op = elf64_ia64_operands + opnd;
- err = (*op->insert) (op, val, (ia64_insn *)& insn);
+ err = (*op->insert) (op, val, &insn);
if (err)
return bfd_reloc_overflow;
@@ -3362,26 +2831,39 @@ elfNN_ia64_install_dyn_reloc (abfd, info, sec, srel, offset, type,
bfd_vma addend;
{
Elf_Internal_Rela outrel;
- bfd_byte *loc;
+
+ 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;
- outrel.r_offset = _bfd_elf_section_offset (abfd, info, sec, offset);
- if (outrel.r_offset >= (bfd_vma) -2)
+
+ if (elf_section_data (sec)->stab_info != NULL)
{
- /* 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;
- outrel.r_offset = 0;
+ /* 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;
}
- else
- outrel.r_offset += sec->output_section->vma + sec->output_offset;
- loc = srel->contents;
- loc += srel->reloc_count++ * sizeof (ElfNN_External_Rela);
- bfd_elfNN_swap_reloca_out (abfd, &outrel, loc);
+ 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);
}
@@ -3401,69 +2883,25 @@ set_got_entry (abfd, info, dyn_i, dynindx, addend, value, dyn_r_type)
{
struct elfNN_ia64_link_hash_table *ia64_info;
asection *got_sec;
- bfd_boolean done;
- bfd_vma got_offset;
ia64_info = elfNN_ia64_hash_table (info);
got_sec = ia64_info->got_sec;
- switch (dyn_r_type)
- {
- case R_IA64_TPREL64LSB:
- done = dyn_i->tprel_done;
- dyn_i->tprel_done = TRUE;
- got_offset = dyn_i->tprel_offset;
- break;
- case R_IA64_DTPMOD64LSB:
- if (dyn_i->dtpmod_offset != ia64_info->self_dtpmod_offset)
- {
- done = dyn_i->dtpmod_done;
- dyn_i->dtpmod_done = TRUE;
- }
- else
- {
- done = ia64_info->self_dtpmod_done;
- ia64_info->self_dtpmod_done = TRUE;
- dynindx = 0;
- }
- got_offset = dyn_i->dtpmod_offset;
- break;
- case R_IA64_DTPREL64LSB:
- done = dyn_i->dtprel_done;
- dyn_i->dtprel_done = TRUE;
- got_offset = dyn_i->dtprel_offset;
- break;
- default:
- done = dyn_i->got_done;
- dyn_i->got_done = TRUE;
- got_offset = dyn_i->got_offset;
- break;
- }
-
- BFD_ASSERT ((got_offset & 7) == 0);
+ BFD_ASSERT ((dyn_i->got_offset & 7) == 0);
- if (! done)
+ 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 + got_offset);
+ bfd_put_64 (abfd, value, got_sec->contents + dyn_i->got_offset);
/* Install a dynamic relocation if needed. */
- if (((info->shared
- && (!dyn_i->h
- || ELF_ST_VISIBILITY (dyn_i->h->other) == STV_DEFAULT
- || dyn_i->h->root.type != bfd_link_hash_undefweak)
- && dyn_r_type != R_IA64_DTPREL64LSB)
- || elfNN_ia64_dynamic_symbol_p (dyn_i->h, info, dyn_r_type)
- || (dynindx != -1 && dyn_r_type == R_IA64_FPTR64LSB))
- && (!dyn_i->want_ltoff_fptr
- || !info->pie
- || !dyn_i->h
- || dyn_i->h->root.type != bfd_link_hash_undefweak))
+ 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_TPREL64LSB
- && dyn_r_type != R_IA64_DTPMOD64LSB
- && dyn_r_type != R_IA64_DTPREL64LSB)
+ if (dynindx == -1)
{
dyn_r_type = R_IA64_REL64LSB;
dynindx = 0;
@@ -3483,24 +2921,15 @@ set_got_entry (abfd, info, dyn_i, dynindx, addend, value, dyn_r_type)
case R_IA64_FPTR64LSB:
dyn_r_type = R_IA64_FPTR64MSB;
break;
- case R_IA64_TPREL64LSB:
- dyn_r_type = R_IA64_TPREL64MSB;
- break;
- case R_IA64_DTPMOD64LSB:
- dyn_r_type = R_IA64_DTPMOD64MSB;
- break;
- case R_IA64_DTPREL64LSB:
- dyn_r_type = R_IA64_DTPREL64MSB;
- break;
default:
- BFD_ASSERT (FALSE);
+ BFD_ASSERT (false);
break;
}
}
elfNN_ia64_install_dyn_reloc (abfd, NULL, got_sec,
ia64_info->rel_got_sec,
- got_offset, dyn_r_type,
+ dyn_i->got_offset, dyn_r_type,
dynindx, addend);
}
}
@@ -3508,7 +2937,7 @@ set_got_entry (abfd, info, dyn_i, dynindx, addend, value, dyn_r_type)
/* Return the address of the linkage table entry. */
value = (got_sec->output_section->vma
+ got_sec->output_offset
- + got_offset);
+ + dyn_i->got_offset);
return value;
}
@@ -3537,24 +2966,6 @@ set_fptr_entry (abfd, info, dyn_i, value)
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);
- if (ia64_info->rel_fptr_sec)
- {
- Elf_Internal_Rela outrel;
- bfd_byte *loc;
-
- if (bfd_little_endian (abfd))
- outrel.r_info = ELFNN_R_INFO (0, R_IA64_IPLTLSB);
- else
- outrel.r_info = ELFNN_R_INFO (0, R_IA64_IPLTMSB);
- outrel.r_addend = value;
- outrel.r_offset = (fptr_sec->output_section->vma
- + fptr_sec->output_offset
- + dyn_i->fptr_offset);
- loc = ia64_info->rel_fptr_sec->contents;
- loc += ia64_info->rel_fptr_sec->reloc_count++
- * sizeof (ElfNN_External_Rela);
- bfd_elfNN_swap_reloca_out (abfd, &outrel, loc);
- }
}
/* Return the descriptor's address. */
@@ -3574,7 +2985,7 @@ set_pltoff_entry (abfd, info, dyn_i, value, is_plt)
struct bfd_link_info *info;
struct elfNN_ia64_dyn_sym_info *dyn_i;
bfd_vma value;
- bfd_boolean is_plt;
+ boolean is_plt;
{
struct elfNN_ia64_link_hash_table *ia64_info;
asection *pltoff_sec;
@@ -3594,11 +3005,7 @@ set_pltoff_entry (abfd, info, dyn_i, value, is_plt)
bfd_put_64 (abfd, gp, pltoff_sec->contents + dyn_i->pltoff_offset + 8);
/* Install dynamic relocations if needed. */
- if (!is_plt
- && info->shared
- && (!dyn_i->h
- || ELF_ST_VISIBILITY (dyn_i->h->other) == STV_DEFAULT
- || dyn_i->h->root.type != bfd_link_hash_undefweak))
+ if (!is_plt && info->shared)
{
unsigned int dyn_r_type;
@@ -3628,33 +3035,6 @@ set_pltoff_entry (abfd, info, dyn_i, value, is_plt)
return value;
}
-/* Return the base VMA address which should be subtracted from real addresses
- when resolving @tprel() relocation.
- Main program TLS (whose template starts at PT_TLS p_vaddr)
- is assigned offset round(16, PT_TLS p_align). */
-
-static bfd_vma
-elfNN_ia64_tprel_base (info)
- struct bfd_link_info *info;
-{
- asection *tls_sec = elf_hash_table (info)->tls_sec;
-
- BFD_ASSERT (tls_sec != NULL);
- return tls_sec->vma - align_power ((bfd_vma) 16, tls_sec->alignment_power);
-}
-
-/* Return the base VMA address which should be subtracted from real addresses
- when resolving @dtprel() relocation.
- This is PT_TLS segment p_vaddr. */
-
-static bfd_vma
-elfNN_ia64_dtprel_base (info)
- struct bfd_link_info *info;
-{
- BFD_ASSERT (elf_hash_table (info)->tls_sec != NULL);
- return elf_hash_table (info)->tls_sec->vma;
-}
-
/* 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. */
@@ -3663,8 +3043,8 @@ static bfd *elfNN_ia64_unwind_entry_compare_bfd;
static int
elfNN_ia64_unwind_entry_compare (a, b)
- const PTR a;
- const PTR b;
+ PTR a;
+ PTR b;
{
bfd_vma av, bv;
@@ -3674,148 +3054,125 @@ elfNN_ia64_unwind_entry_compare (a, b)
return (av < bv ? -1 : av > bv ? 1 : 0);
}
-/* Make sure we've got ourselves a nice fat __gp value. */
-static bfd_boolean
-elfNN_ia64_choose_gp (abfd, info)
+static boolean
+elfNN_ia64_final_link (abfd, info)
bfd *abfd;
struct bfd_link_info *info;
{
- 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;
struct elfNN_ia64_link_hash_table *ia64_info;
+ asection *unwind_output_sec;
ia64_info = elfNN_ia64_hash_table (info);
- /* 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)
+ /* Make sure we've got ourselves a nice fat __gp value. */
+ if (!info->relocateable)
{
- 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;
+ 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;
- if (min_vma > lo)
- min_vma = lo;
- if (max_vma < hi)
- max_vma = hi;
- if (os->flags & SEC_SMALL_DATA)
+ /* 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)
{
- 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. */
+ bfd_vma lo, hi;
- asection *got_sec = ia64_info->got_sec;
+ if ((os->flags & SEC_ALLOC) == 0)
+ continue;
- /* 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;
+ lo = os->vma;
+ hi = os->vma + os->_raw_size;
+ if (hi < lo)
+ hi = (bfd_vma) -1;
- /* If we're addressing stuff past the end, adjust back. */
- if (gp_val > max_vma)
- gp_val = max_vma - 0x200000 + 8;
+ 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;
+ }
}
- }
- /* Validate whether all SHF_IA_64_SHORT sections are within
- range of the chosen GP. */
+ /* See if the user wants to force a value. */
+ gp = elf_link_hash_lookup (elf_hash_table (info), "__gp", false,
+ false, false);
- if (max_short_vma != 0)
- {
- if (max_short_vma - min_short_vma >= 0x400000)
+ if (gp
+ && (gp->root.type == bfd_link_hash_defined
+ || gp->root.type == bfd_link_hash_defweak))
{
- (*_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;
+ 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 if ((gp_val > min_short_vma
- && gp_val - min_short_vma > 0x200000)
- || (gp_val < max_short_vma
- && max_short_vma - gp_val >= 0x200000))
+ else
{
- (*_bfd_error_handler)
- (_("%s: __gp does not cover short data segment"),
- bfd_get_filename (abfd));
- return FALSE;
- }
- }
+ /* Pick a sensible value. */
- _bfd_set_gp_value (abfd, gp_val);
+ asection *got_sec = ia64_info->got_sec;
- return TRUE;
-}
-
-static bfd_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;
+ /* 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;
- ia64_info = elfNN_ia64_hash_table (info);
+ /* If we're addressing stuff past the end, adjust back. */
+ if (gp_val > max_vma)
+ gp_val = max_vma - 0x200000 + 8;
+ }
+ }
- /* Make sure we've got ourselves a nice fat __gp value. */
- if (!info->relocatable)
- {
- bfd_vma gp_val = _bfd_get_gp_value (abfd);
- struct elf_link_hash_entry *gp;
+ /* Validate whether all SHF_IA_64_SHORT sections are within
+ range of the chosen GP. */
- if (gp_val == 0)
+ if (max_short_vma != 0)
{
- if (! elfNN_ia64_choose_gp (abfd, info))
- return FALSE;
- gp_val = _bfd_get_gp_value (abfd);
+ 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;
+ }
}
- gp = elf_link_hash_lookup (elf_hash_table (info), "__gp", FALSE,
- FALSE, FALSE);
+ _bfd_set_gp_value (abfd, gp_val);
+
if (gp)
{
gp->root.type = bfd_link_hash_defined;
@@ -3828,7 +3185,7 @@ elfNN_ia64_final_link (abfd, info)
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->relocatable)
+ if (!info->relocateable)
{
asection *s = bfd_get_section_by_name (abfd, ELF_STRING_ia64_unwind);
if (s)
@@ -3837,32 +3194,30 @@ elfNN_ia64_final_link (abfd, info)
unwind_output_sec->contents
= bfd_malloc (unwind_output_sec->_raw_size);
if (unwind_output_sec->contents == NULL)
- return FALSE;
+ return false;
}
}
/* Invoke the regular ELF backend linker to do all the work. */
- if (!bfd_elf_final_link (abfd, info))
- return FALSE;
+ 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,
- (size_t) (unwind_output_sec->_raw_size / 24),
- 24,
- elfNN_ia64_unwind_entry_compare);
+ 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, (bfd_vma) 0,
+ unwind_output_sec->contents, 0,
unwind_output_sec->_raw_size))
- return FALSE;
+ return false;
}
- return TRUE;
+ return true;
}
-static bfd_boolean
+static boolean
elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
contents, relocs, local_syms, local_sections)
bfd *output_bfd;
@@ -3879,14 +3234,14 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
Elf_Internal_Rela *rel;
Elf_Internal_Rela *relend;
asection *srel;
- bfd_boolean ret_val = TRUE; /* for non-fatal errors */
+ 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->relocatable)
+ if (info->relocateable)
{
bfd_vma flags;
@@ -3895,11 +3250,10 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
elf_section_data(input_section->output_section)
->this_hdr.sh_flags |= flags;
- return TRUE;
}
gp_val = _bfd_get_gp_value (output_bfd);
- srel = get_reloc_section (input_bfd, ia64_info, input_section, FALSE);
+ srel = get_reloc_section (input_bfd, ia64_info, input_section, false);
rel = relocs;
relend = relocs + input_section->reloc_count;
@@ -3915,86 +3269,110 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
bfd_vma value;
asection *sym_sec;
bfd_byte *hit_addr;
- bfd_boolean dynamic_symbol_p;
- bfd_boolean undef_weak_ref;
+ 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_archive_filename (input_bfd), (int)r_type);
+ bfd_get_filename (input_bfd), (int)r_type);
bfd_set_error (bfd_error_bad_value);
- ret_val = FALSE;
+ 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;
+ undef_weak_ref = false;
if (r_symndx < symtab_hdr->sh_info)
{
/* Reloc against local symbol. */
- asection *msec;
sym = local_syms + r_symndx;
sym_sec = local_sections[r_symndx];
- msec = sym_sec;
- value = _bfd_elf_rela_local_sym (output_bfd, sym, &msec, rel);
- if ((sym_sec->flags & SEC_MERGE)
- && ELF_ST_TYPE (sym->st_info) == STT_SECTION
- && sym_sec->sec_info_type == ELF_INFO_TYPE_MERGE)
- {
- struct elfNN_ia64_local_hash_entry *loc_h;
-
- loc_h = get_local_sym_hash (ia64_info, input_bfd, rel, FALSE);
- if (loc_h && ! loc_h->sec_merge_done)
- {
- struct elfNN_ia64_dyn_sym_info *dynent;
-
- for (dynent = loc_h->info; dynent; dynent = dynent->next)
- {
- msec = sym_sec;
- dynent->addend =
- _bfd_merged_section_offset (output_bfd, &msec,
- elf_section_data (msec)->
- sec_info,
- sym->st_value
- + dynent->addend,
- (bfd_vma) 0);
- dynent->addend -= sym->st_value;
- dynent->addend += msec->output_section->vma
- + msec->output_offset
- - sym_sec->output_section->vma
- - sym_sec->output_offset;
- }
- loc_h->sec_merge_done = 1;
- }
- }
+ value = (sym_sec->output_section->vma
+ + sym_sec->output_offset
+ + sym->st_value);
}
else
{
- bfd_boolean unresolved_reloc;
- bfd_boolean warned;
- struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
-
- RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
- r_symndx, symtab_hdr, sym_hashes,
- h, sym_sec, value,
- unresolved_reloc, warned);
-
- if (h->root.type == bfd_link_hash_undefweak)
- undef_weak_ref = TRUE;
- else if (warned)
- continue;
+ 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, r_type);
+ dynamic_symbol_p = elfNN_ia64_dynamic_symbol_p (h, info);
switch (r_type)
{
@@ -4011,7 +3389,6 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
case R_IA64_DIR64LSB:
/* Install a dynamic relocation for this reloc. */
if ((dynamic_symbol_p || info->shared)
- && r_symndx != 0
&& (input_section->flags & SEC_ALLOC) != 0)
{
unsigned int dyn_r_type;
@@ -4020,24 +3397,6 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
BFD_ASSERT (srel != NULL);
- switch (r_type)
- {
- case R_IA64_IMM14:
- case R_IA64_IMM22:
- case R_IA64_IMM64:
- /* ??? People shouldn't be doing non-pic code in
- shared libraries nor dynamic executables. */
- (*_bfd_error_handler)
- (_("%s: non-pic code with imm relocation against dynamic symbol `%s'"),
- bfd_archive_filename (input_bfd),
- h->root.root.string);
- ret_val = FALSE;
- continue;
-
- default:
- break;
- }
-
/* If we don't need dynamic symbol lookup, find a
matching RELATIVE relocation. */
dyn_r_type = r_type;
@@ -4065,7 +3424,17 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
break;
default:
- break;
+ /* 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;
@@ -4075,7 +3444,7 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
srel, rel->r_offset, dyn_r_type,
dynindx, addend);
}
- /* Fall through. */
+ /* FALLTHRU */
case R_IA64_LTV32MSB:
case R_IA64_LTV32LSB:
@@ -4094,8 +3463,8 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
{
(*_bfd_error_handler)
(_("%s: @gprel relocation against dynamic symbol %s"),
- bfd_archive_filename (input_bfd), h->root.root.string);
- ret_val = FALSE;
+ bfd_get_filename (input_bfd), h->root.root.string);
+ ret_val = false;
continue;
}
value -= gp_val;
@@ -4105,7 +3474,7 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
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);
+ 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;
@@ -4116,8 +3485,8 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
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);
+ 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;
@@ -4127,42 +3496,20 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
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);
+ 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);
}
- if (!dyn_i->want_fptr || info->pie)
+ else
{
long dynindx;
- unsigned int dyn_r_type = r_type;
- bfd_vma addend = rel->r_addend;
/* Otherwise, we expect the dynamic linker to create
the entry. */
- if (dyn_i->want_fptr)
- {
- if (r_type == R_IA64_FPTR64I)
- {
- /* 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 position independent executable"),
- bfd_archive_filename (input_bfd));
- ret_val = FALSE;
- continue;
- }
- dynindx = 0;
- addend = value;
- dyn_r_type = r_type + R_IA64_REL64LSB - R_IA64_FPTR64LSB;
- }
- else if (h)
+ if (h)
{
if (h->dynindx != -1)
dynindx = h->dynindx;
@@ -4170,18 +3517,17 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
dynindx = (_bfd_elf_link_lookup_local_dynindx
(info, h->root.u.def.section->owner,
global_sym_index (h)));
- value = 0;
}
else
{
dynindx = (_bfd_elf_link_lookup_local_dynindx
- (info, input_bfd, (long) r_symndx));
- value = 0;
+ (info, input_bfd, r_symndx));
}
elfNN_ia64_install_dyn_reloc (output_bfd, info, input_section,
- srel, rel->r_offset, dyn_r_type,
- dynindx, addend);
+ srel, rel->r_offset, r_type,
+ dynindx, rel->r_addend);
+ value = 0;
}
r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type);
@@ -4189,14 +3535,12 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
case R_IA64_LTOFF_FPTR22:
case R_IA64_LTOFF_FPTR64I:
- case R_IA64_LTOFF_FPTR32MSB:
- case R_IA64_LTOFF_FPTR32LSB:
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);
+ 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)
@@ -4219,7 +3563,7 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
}
else
dynindx = (_bfd_elf_link_lookup_local_dynindx
- (info, input_bfd, (long) r_symndx));
+ (info, input_bfd, r_symndx));
value = 0;
}
@@ -4235,7 +3579,7 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
case R_IA64_PCREL64MSB:
case R_IA64_PCREL64LSB:
/* Install a dynamic relocation for this reloc. */
- if (dynamic_symbol_p && r_symndx != 0)
+ if (dynamic_symbol_p)
{
BFD_ASSERT (srel != NULL);
@@ -4245,12 +3589,35 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
}
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);
+ dyn_i = get_dyn_sym_info (ia64_info, h, NULL, NULL, false);
if (dyn_i && dyn_i->want_plt2)
{
@@ -4276,32 +3643,8 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
}
goto finish_pcrel;
- case R_IA64_PCREL21BI:
- case R_IA64_PCREL21F:
- case R_IA64_PCREL21M:
case R_IA64_PCREL22:
case R_IA64_PCREL64I:
- /* The PCREL21BI reloc is specifically not intended for use with
- dynamic relocs. PCREL21F and PCREL21M are used for speculation
- fixup code, and thus probably ought not be dynamic. The
- PCREL22 and PCREL64I relocs aren't emitted as dynamic relocs. */
- if (dynamic_symbol_p)
- {
- const char *msg;
-
- if (r_type == R_IA64_PCREL21BI)
- msg = _("%s: @internal branch to dynamic symbol %s");
- else if (r_type == R_IA64_PCREL21F || r_type == R_IA64_PCREL21M)
- msg = _("%s: speculation fixup to dynamic symbol %s");
- else
- msg = _("%s: @pcrel relocation against dynamic symbol %s");
- (*_bfd_error_handler) (msg, bfd_archive_filename (input_bfd),
- h->root.root.string);
- ret_val = FALSE;
- continue;
- }
- goto finish_pcrel;
-
finish_pcrel:
/* Make pc-relative. */
value -= (input_section->output_section->vma
@@ -4314,48 +3657,47 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
case R_IA64_SEGREL32LSB:
case R_IA64_SEGREL64MSB:
case R_IA64_SEGREL64LSB:
- if (r_symndx == 0)
- {
- /* If the input section was discarded from the output, then
- do nothing. */
- r = bfd_reloc_ok;
- }
- else
- {
- 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] == input_section->output_section)
- break;
- if (i >= 0)
+ {
+ 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 (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;
- }
+ }
+ 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:
@@ -4379,7 +3721,7 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
/* If we don't need dynamic symbol lookup, install two
RELATIVE relocations. */
- if (!dynamic_symbol_p)
+ if (! dynamic_symbol_p)
{
unsigned int dyn_r_type;
@@ -4412,66 +3754,6 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
r_type);
break;
- case R_IA64_TPREL14:
- case R_IA64_TPREL22:
- case R_IA64_TPREL64I:
- value -= elfNN_ia64_tprel_base (info);
- r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type);
- break;
-
- case R_IA64_DTPREL14:
- case R_IA64_DTPREL22:
- case R_IA64_DTPREL64I:
- case R_IA64_DTPREL64LSB:
- case R_IA64_DTPREL64MSB:
- value -= elfNN_ia64_dtprel_base (info);
- r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type);
- break;
-
- case R_IA64_LTOFF_TPREL22:
- case R_IA64_LTOFF_DTPMOD22:
- case R_IA64_LTOFF_DTPREL22:
- {
- int got_r_type;
- long dynindx = h ? h->dynindx : -1;
- bfd_vma r_addend = rel->r_addend;
-
- switch (r_type)
- {
- default:
- case R_IA64_LTOFF_TPREL22:
- if (!dynamic_symbol_p)
- {
- if (!info->shared)
- value -= elfNN_ia64_tprel_base (info);
- else
- {
- r_addend += value - elfNN_ia64_dtprel_base (info);
- dynindx = 0;
- }
- }
- got_r_type = R_IA64_TPREL64LSB;
- break;
- case R_IA64_LTOFF_DTPMOD22:
- if (!dynamic_symbol_p && !info->shared)
- value = 1;
- got_r_type = R_IA64_DTPMOD64LSB;
- break;
- case R_IA64_LTOFF_DTPREL22:
- if (!dynamic_symbol_p)
- value -= elfNN_ia64_dtprel_base (info);
- got_r_type = R_IA64_DTPREL64LSB;
- break;
- }
- dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, FALSE);
- value = set_got_entry (input_bfd, info, dyn_i, dynindx, r_addend,
- value, got_r_type);
- value -= gp_val;
- r = elfNN_ia64_install_value (output_bfd, hit_addr, value,
- r_type);
- }
- break;
-
default:
r = bfd_reloc_notsupported;
break;
@@ -4488,7 +3770,7 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
don't try to continue. */
(*info->callbacks->undefined_symbol)
(info, "__gp", input_bfd, input_section, rel->r_offset, 1);
- return FALSE;
+ return false;
case bfd_reloc_notsupported:
{
@@ -4502,15 +3784,15 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
symtab_hdr->sh_link,
sym->st_name);
if (name == NULL)
- return FALSE;
+ 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;
+ return false;
+ ret_val = false;
}
break;
@@ -4529,18 +3811,17 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
symtab_hdr->sh_link,
sym->st_name);
if (name == NULL)
- return FALSE;
+ return false;
if (*name == '\0')
name = bfd_section_name (input_bfd, input_section);
}
if (!(*info->callbacks->reloc_overflow) (info, name,
- howto->name,
- (bfd_vma) 0,
+ howto->name, 0,
input_bfd,
input_section,
rel->r_offset))
- return FALSE;
- ret_val = FALSE;
+ return false;
+ ret_val = false;
}
break;
}
@@ -4549,7 +3830,7 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
return ret_val;
}
-static bfd_boolean
+static boolean
elfNN_ia64_finish_dynamic_symbol (output_bfd, info, h, sym)
bfd *output_bfd;
struct bfd_link_info *info;
@@ -4560,7 +3841,7 @@ elfNN_ia64_finish_dynamic_symbol (output_bfd, info, h, sym)
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);
+ 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)
@@ -4569,6 +3850,7 @@ elfNN_ia64_finish_dynamic_symbol (output_bfd, info, h, sym)
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);
@@ -4586,7 +3868,7 @@ elfNN_ia64_finish_dynamic_symbol (output_bfd, info, h, sym)
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);
+ 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)
@@ -4600,7 +3882,7 @@ elfNN_ia64_finish_dynamic_symbol (output_bfd, info, h, sym)
/* 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.c did some for us. */
+ 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;
}
@@ -4625,10 +3907,10 @@ elfNN_ia64_finish_dynamic_symbol (output_bfd, info, h, sym)
existing sec->reloc_count to be the base of the array of
PLT relocations. */
- loc = ia64_info->rel_pltoff_sec->contents;
- loc += ((ia64_info->rel_pltoff_sec->reloc_count + index)
- * sizeof (ElfNN_External_Rela));
- bfd_elfNN_swap_reloca_out (output_bfd, &outrel, loc);
+ 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. */
@@ -4637,10 +3919,10 @@ elfNN_ia64_finish_dynamic_symbol (output_bfd, info, h, sym)
|| strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
sym->st_shndx = SHN_ABS;
- return TRUE;
+ return true;
}
-static bfd_boolean
+static boolean
elfNN_ia64_finish_dynamic_sections (abfd, info)
bfd *abfd;
struct bfd_link_info *info;
@@ -4706,7 +3988,7 @@ elfNN_ia64_finish_dynamic_sections (abfd, info)
bfd_elfNN_swap_dyn_out (abfd, &dyn, dyncon);
}
- /* Initialize the PLT0 entry. */
+ /* Initialize the PLT0 entry */
if (ia64_info->plt_sec)
{
bfd_byte *loc = ia64_info->plt_sec->contents;
@@ -4722,13 +4004,13 @@ elfNN_ia64_finish_dynamic_sections (abfd, info)
}
}
- return TRUE;
+ return true;
}
-/* ELF file flag handling: */
+/* ELF file flag handling: */
/* Function to keep IA-64 specific file flags. */
-static bfd_boolean
+static boolean
elfNN_ia64_set_private_flags (abfd, flags)
bfd *abfd;
flagword flags;
@@ -4737,31 +4019,49 @@ elfNN_ia64_set_private_flags (abfd, flags)
|| elf_elfheader (abfd)->e_flags == flags);
elf_elfheader (abfd)->e_flags = flags;
- elf_flags_init (abfd) = TRUE;
- return TRUE;
+ 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 bfd_boolean
+static boolean
elfNN_ia64_merge_private_bfd_data (ibfd, obfd)
bfd *ibfd, *obfd;
{
flagword out_flags;
flagword in_flags;
- bfd_boolean ok = TRUE;
+ 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;
+ 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_flags_init (obfd) = true;
elf_elfheader (obfd)->e_flags = in_flags;
if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
@@ -4771,12 +4071,12 @@ elfNN_ia64_merge_private_bfd_data (ibfd, obfd)
bfd_get_mach (ibfd));
}
- return TRUE;
+ return true;
}
/* Check flag compatibility. */
if (in_flags == out_flags)
- return TRUE;
+ 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))
@@ -4786,53 +4086,53 @@ elfNN_ia64_merge_private_bfd_data (ibfd, obfd)
{
(*_bfd_error_handler)
(_("%s: linking trap-on-NULL-dereference with non-trapping files"),
- bfd_archive_filename (ibfd));
+ bfd_get_filename (ibfd));
bfd_set_error (bfd_error_bad_value);
- ok = FALSE;
+ 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_archive_filename (ibfd));
+ bfd_get_filename (ibfd));
bfd_set_error (bfd_error_bad_value);
- ok = FALSE;
+ 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_archive_filename (ibfd));
+ bfd_get_filename (ibfd));
bfd_set_error (bfd_error_bad_value);
- ok = FALSE;
+ 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_archive_filename (ibfd));
+ bfd_get_filename (ibfd));
bfd_set_error (bfd_error_bad_value);
- ok = FALSE;
+ 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_archive_filename (ibfd));
+ bfd_get_filename (ibfd));
bfd_set_error (bfd_error_bad_value);
- ok = FALSE;
+ ok = false;
}
return ok;
}
-static bfd_boolean
+static boolean
elfNN_ia64_print_private_bfd_data (abfd, ptr)
bfd *abfd;
PTR ptr;
@@ -4853,85 +4153,8 @@ elfNN_ia64_print_private_bfd_data (abfd, ptr)
(flags & EF_IA_64_ABI64) ? "ABI64" : "ABI32");
_bfd_elf_print_private_bfd_data (abfd, ptr);
- return TRUE;
-}
-
-static enum elf_reloc_type_class
-elfNN_ia64_reloc_type_class (rela)
- const Elf_Internal_Rela *rela;
-{
- switch ((int) ELFNN_R_TYPE (rela->r_info))
- {
- case R_IA64_REL32MSB:
- case R_IA64_REL32LSB:
- case R_IA64_REL64MSB:
- case R_IA64_REL64LSB:
- return reloc_class_relative;
- case R_IA64_IPLTMSB:
- case R_IA64_IPLTLSB:
- return reloc_class_plt;
- case R_IA64_COPY:
- return reloc_class_copy;
- default:
- return reloc_class_normal;
- }
-}
-
-static struct bfd_elf_special_section const elfNN_ia64_special_sections[]=
-{
- { ".sbss", 5, -1, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT },
- { ".sdata", 6, -1, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT },
- { NULL, 0, 0, 0, 0 }
-};
-
-static bfd_boolean
-elfNN_ia64_hpux_vec (const bfd_target *vec)
-{
- extern const bfd_target bfd_elfNN_ia64_hpux_big_vec;
- return (vec == & bfd_elfNN_ia64_hpux_big_vec);
-}
-
-static void
-elfNN_hpux_post_process_headers (abfd, info)
- bfd *abfd;
- struct bfd_link_info *info ATTRIBUTE_UNUSED;
-{
- Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd);
-
- i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_HPUX;
- i_ehdrp->e_ident[EI_ABIVERSION] = 1;
-}
-
-bfd_boolean
-elfNN_hpux_backend_section_from_bfd_section (abfd, sec, retval)
- bfd *abfd ATTRIBUTE_UNUSED;
- asection *sec;
- int *retval;
-{
- if (bfd_is_com_section (sec))
- {
- *retval = SHN_IA_64_ANSI_COMMON;
- return TRUE;
- }
- return FALSE;
+ return true;
}
-
-static void
-elfNN_hpux_backend_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
- asymbol *asym)
-{
- elf_symbol_type *elfsym = (elf_symbol_type *) asym;;
-
- switch (elfsym->internal_elf_sym.st_shndx)
- {
- case SHN_IA_64_ANSI_COMMON:
- asym->section = bfd_com_section_ptr;
- asym->value = elfsym->internal_elf_sym.st_size;
- asym->flags &= ~BSF_GLOBAL;
- break;
- }
-}
-
#define TARGET_LITTLE_SYM bfd_elfNN_ia64_little_vec
#define TARGET_LITTLE_NAME "elfNN-ia64-little"
@@ -4970,8 +4193,6 @@ elfNN_hpux_backend_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
/* Stuff for the BFD linker: */
#define bfd_elfNN_bfd_link_hash_table_create \
elfNN_ia64_hash_table_create
-#define bfd_elfNN_bfd_link_hash_table_free \
- elfNN_ia64_hash_table_free
#define elf_backend_create_dynamic_sections \
elfNN_ia64_create_dynamic_sections
#define elf_backend_check_relocs \
@@ -4989,6 +4210,8 @@ elfNN_hpux_backend_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
#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 \
@@ -5000,6 +4223,7 @@ elfNN_hpux_backend_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
#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
@@ -5007,41 +4231,5 @@ elfNN_hpux_backend_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
#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
-#define elf_backend_reloc_type_class elfNN_ia64_reloc_type_class
-#define elf_backend_rela_normal 1
-#define elf_backend_special_sections elfNN_ia64_special_sections
#include "elfNN-target.h"
-
-/* HPUX-specific vectors. */
-
-#undef TARGET_LITTLE_SYM
-#undef TARGET_LITTLE_NAME
-#undef TARGET_BIG_SYM
-#define TARGET_BIG_SYM bfd_elfNN_ia64_hpux_big_vec
-#undef TARGET_BIG_NAME
-#define TARGET_BIG_NAME "elfNN-ia64-hpux-big"
-
-/* These are HP-UX specific functions. */
-
-#undef elf_backend_post_process_headers
-#define elf_backend_post_process_headers elfNN_hpux_post_process_headers
-
-#undef elf_backend_section_from_bfd_section
-#define elf_backend_section_from_bfd_section elfNN_hpux_backend_section_from_bfd_section
-
-#undef elf_backend_symbol_processing
-#define elf_backend_symbol_processing elfNN_hpux_backend_symbol_processing
-
-#undef elf_backend_want_p_paddr_set_to_zero
-#define elf_backend_want_p_paddr_set_to_zero 1
-
-#undef ELF_MAXPAGESIZE
-#define ELF_MAXPAGESIZE 0x1000 /* 1K */
-
-#undef elfNN_bed
-#define elfNN_bed elfNN_ia64_hpux_bed
-
-#include "elfNN-target.h"
-
-#undef elf_backend_want_p_paddr_set_to_zero