/* Common code for PA ELF implementations.
- Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+ Copyright 1999, 2000, 2001, 2002, 2003, 2004
+ Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
#define elf_hppa_reloc_final_type elf64_hppa_reloc_final_type
#define _bfd_elf_hppa_gen_reloc_type _bfd_elf64_hppa_gen_reloc_type
#define elf_hppa_relocate_section elf64_hppa_relocate_section
-#define bfd_elf_bfd_final_link bfd_elf64_bfd_final_link
#define elf_hppa_final_link elf64_hppa_final_link
#endif
#if ARCH_SIZE == 32
#define elf_hppa_reloc_final_type elf32_hppa_reloc_final_type
#define _bfd_elf_hppa_gen_reloc_type _bfd_elf32_hppa_gen_reloc_type
#define elf_hppa_relocate_section elf32_hppa_relocate_section
-#define bfd_elf_bfd_final_link bfd_elf32_bfd_final_link
#define elf_hppa_final_link elf32_hppa_final_link
#endif
-static void elf_hppa_info_to_howto
- PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
-
-static void elf_hppa_info_to_howto_rel
- PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
-
-static reloc_howto_type * elf_hppa_reloc_type_lookup
- PARAMS ((bfd *, bfd_reloc_code_real_type));
-
-static bfd_boolean elf_hppa_is_local_label_name
- PARAMS ((bfd *, const char *));
-
-static bfd_boolean elf_hppa_fake_sections
- PARAMS ((bfd *abfd, Elf_Internal_Shdr *, asection *));
-
-static void elf_hppa_final_write_processing
- PARAMS ((bfd *, bfd_boolean));
-
-static int hppa_unwind_entry_compare
- PARAMS ((const PTR, const PTR));
-
-static bfd_boolean elf_hppa_sort_unwind
- PARAMS ((bfd *));
-
#if ARCH_SIZE == 64
-static bfd_boolean elf_hppa_add_symbol_hook
- PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
- const char **, flagword *, asection **, bfd_vma *));
-
-static bfd_boolean elf_hppa_unmark_useless_dynamic_symbols
- PARAMS ((struct elf_link_hash_entry *, PTR));
-
-static bfd_boolean elf_hppa_remark_useless_dynamic_symbols
- PARAMS ((struct elf_link_hash_entry *, PTR));
-
-static bfd_boolean elf_hppa_is_dynamic_loader_symbol
- PARAMS ((const char *));
-
-static void elf_hppa_record_segment_addrs
- PARAMS ((bfd *, asection *, PTR));
-
-static bfd_boolean elf_hppa_final_link
- PARAMS ((bfd *, struct bfd_link_info *));
-
-static bfd_boolean elf_hppa_relocate_section
- PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *,
- bfd_byte *, Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
-
static bfd_reloc_status_type elf_hppa_final_link_relocate
- PARAMS ((Elf_Internal_Rela *, bfd *, bfd *, asection *,
- bfd_byte *, bfd_vma, struct bfd_link_info *,
- asection *, struct elf_link_hash_entry *,
- struct elf64_hppa_dyn_hash_entry *));
+ (Elf_Internal_Rela *, bfd *, bfd *, asection *, bfd_byte *, bfd_vma,
+ struct bfd_link_info *, asection *, struct elf_link_hash_entry *,
+ struct elf64_hppa_dyn_hash_entry *);
static int elf_hppa_relocate_insn
- PARAMS ((int, int, unsigned int));
+ (int, int, unsigned int);
#endif
/* ELF/PA relocation howto entries. */
format, and field selector. */
elf_hppa_reloc_type
-elf_hppa_reloc_final_type (abfd, base_type, format, field)
- bfd *abfd;
- elf_hppa_reloc_type base_type;
- int format;
- unsigned int field;
+elf_hppa_reloc_final_type (bfd *abfd,
+ elf_hppa_reloc_type base_type,
+ int format,
+ unsigned int field)
{
elf_hppa_reloc_type final_type = base_type;
}
break;
+ case 32:
+ switch (field)
+ {
+ case e_fsel:
+ final_type = R_PARISC_PCREL32;
+ break;
+ default:
+ return R_PARISC_NONE;
+ }
+ break;
+
+ case 64:
+ switch (field)
+ {
+ case e_fsel:
+ final_type = R_PARISC_PCREL64;
+ break;
+ default:
+ return R_PARISC_NONE;
+ }
+ break;
+
default:
return R_PARISC_NONE;
}
relocation with modifications based on format and field. */
elf_hppa_reloc_type **
-_bfd_elf_hppa_gen_reloc_type (abfd, base_type, format, field, ignore, sym)
- bfd *abfd;
- elf_hppa_reloc_type base_type;
- int format;
- unsigned int field;
- int ignore ATTRIBUTE_UNUSED;
- asymbol *sym ATTRIBUTE_UNUSED;
+_bfd_elf_hppa_gen_reloc_type (bfd *abfd,
+ elf_hppa_reloc_type base_type,
+ int format,
+ unsigned int field,
+ int ignore ATTRIBUTE_UNUSED,
+ asymbol *sym ATTRIBUTE_UNUSED)
{
elf_hppa_reloc_type *finaltype;
elf_hppa_reloc_type **final_types;
bfd_size_type amt = sizeof (elf_hppa_reloc_type *) * 2;
/* Allocate slots for the BFD relocation. */
- final_types = (elf_hppa_reloc_type **) bfd_alloc (abfd, amt);
+ final_types = bfd_alloc (abfd, amt);
if (final_types == NULL)
return NULL;
/* Allocate space for the relocation itself. */
amt = sizeof (elf_hppa_reloc_type);
- finaltype = (elf_hppa_reloc_type *) bfd_alloc (abfd, amt);
+ finaltype = bfd_alloc (abfd, amt);
if (finaltype == NULL)
return NULL;
/* Translate from an elf into field into a howto relocation pointer. */
static void
-elf_hppa_info_to_howto (abfd, bfd_reloc, elf_reloc)
- bfd *abfd ATTRIBUTE_UNUSED;
- arelent *bfd_reloc;
- Elf_Internal_Rela *elf_reloc;
+elf_hppa_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
+ arelent *bfd_reloc,
+ Elf_Internal_Rela *elf_reloc)
{
- BFD_ASSERT (ELF_R_TYPE(elf_reloc->r_info)
+ BFD_ASSERT (ELF_R_TYPE (elf_reloc->r_info)
< (unsigned int) R_PARISC_UNIMPLEMENTED);
bfd_reloc->howto = &elf_hppa_howto_table[ELF_R_TYPE (elf_reloc->r_info)];
}
/* Translate from an elf into field into a howto relocation pointer. */
static void
-elf_hppa_info_to_howto_rel (abfd, bfd_reloc, elf_reloc)
- bfd *abfd ATTRIBUTE_UNUSED;
- arelent *bfd_reloc;
- Elf_Internal_Rela *elf_reloc;
+elf_hppa_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
+ arelent *bfd_reloc,
+ Elf_Internal_Rela *elf_reloc)
{
BFD_ASSERT (ELF_R_TYPE(elf_reloc->r_info)
< (unsigned int) R_PARISC_UNIMPLEMENTED);
relocation for an ARCH machine. */
static reloc_howto_type *
-elf_hppa_reloc_type_lookup (abfd, code)
- bfd *abfd ATTRIBUTE_UNUSED;
- bfd_reloc_code_real_type code;
+elf_hppa_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
+ bfd_reloc_code_real_type code)
{
if ((int) code < (int) R_PARISC_UNIMPLEMENTED)
{
/* Return TRUE if SYM represents a local label symbol. */
static bfd_boolean
-elf_hppa_is_local_label_name (abfd, name)
- bfd *abfd ATTRIBUTE_UNUSED;
- const char *name;
+elf_hppa_is_local_label_name (bfd *abfd ATTRIBUTE_UNUSED, const char *name)
{
if (name[0] == 'L' && name[1] == '$')
return 1;
section name, which is a hack, but ought to work. */
static bfd_boolean
-elf_hppa_fake_sections (abfd, hdr, sec)
- bfd *abfd;
- Elf_Internal_Shdr *hdr;
- asection *sec;
+elf_hppa_fake_sections (bfd *abfd, Elf_Internal_Shdr *hdr, asection *sec)
{
- register const char *name;
+ const char *name;
name = bfd_get_section_name (abfd, sec);
}
static void
-elf_hppa_final_write_processing (abfd, linker)
- bfd *abfd;
- bfd_boolean linker ATTRIBUTE_UNUSED;
+elf_hppa_final_write_processing (bfd *abfd,
+ bfd_boolean linker ATTRIBUTE_UNUSED)
{
int mach = bfd_get_mach (abfd);
final link. */
static int
-hppa_unwind_entry_compare (a, b)
- const PTR a;
- const PTR b;
+hppa_unwind_entry_compare (const void *a, const void *b)
{
const bfd_byte *ap, *bp;
unsigned long av, bv;
- ap = (const bfd_byte *) a;
+ ap = a;
av = (unsigned long) ap[0] << 24;
av |= (unsigned long) ap[1] << 16;
av |= (unsigned long) ap[2] << 8;
av |= (unsigned long) ap[3];
- bp = (const bfd_byte *) b;
+ bp = b;
bv = (unsigned long) bp[0] << 24;
bv |= (unsigned long) bp[1] << 16;
bv |= (unsigned long) bp[2] << 8;
return av < bv ? -1 : av > bv ? 1 : 0;
}
-static bfd_boolean elf_hppa_sort_unwind (abfd)
- bfd *abfd;
+static bfd_boolean elf_hppa_sort_unwind (bfd *abfd)
{
asection *s;
if (s != NULL)
{
bfd_size_type size;
- char *contents;
-
- size = s->_raw_size;
- contents = bfd_malloc (size);
- if (contents == NULL)
- return FALSE;
+ bfd_byte *contents;
- if (! bfd_get_section_contents (abfd, s, contents, (file_ptr) 0, size))
+ if (!bfd_malloc_and_get_section (abfd, s, &contents))
return FALSE;
+ size = s->size;
qsort (contents, (size_t) (size / 16), 16, hppa_unwind_entry_compare);
if (! bfd_set_section_contents (abfd, s, contents, (file_ptr) 0, size))
indices, which we have to handle. */
static bfd_boolean
-elf_hppa_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
- bfd *abfd;
- struct bfd_link_info *info ATTRIBUTE_UNUSED;
- const Elf_Internal_Sym *sym;
- const char **namep ATTRIBUTE_UNUSED;
- flagword *flagsp ATTRIBUTE_UNUSED;
- asection **secp;
- bfd_vma *valp;
+elf_hppa_add_symbol_hook (bfd *abfd,
+ struct bfd_link_info *info ATTRIBUTE_UNUSED,
+ Elf_Internal_Sym *sym,
+ const char **namep ATTRIBUTE_UNUSED,
+ flagword *flagsp ATTRIBUTE_UNUSED,
+ asection **secp,
+ bfd_vma *valp)
{
int index = sym->st_shndx;
}
static bfd_boolean
-elf_hppa_unmark_useless_dynamic_symbols (h, data)
- struct elf_link_hash_entry *h;
- PTR data;
+elf_hppa_unmark_useless_dynamic_symbols (struct elf_link_hash_entry *h,
+ void *data)
{
- struct bfd_link_info *info = (struct bfd_link_info *)data;
+ struct bfd_link_info *info = data;
if (h->root.type == bfd_link_hash_warning)
h = (struct elf_link_hash_entry *) h->root.u.i.link;
Ultimately we should have better controls over the generic ELF BFD
linker code. */
- if (! info->relocateable
- && ! (info->shared
- && !info->no_undefined)
+ if (! info->relocatable
+ && info->unresolved_syms_in_shared_libs != RM_IGNORE
&& h->root.type == bfd_link_hash_undefined
- && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0
- && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0)
+ && h->ref_dynamic
+ && !h->ref_regular)
{
- h->elf_link_hash_flags &= ~ELF_LINK_HASH_REF_DYNAMIC;
- h->elf_link_hash_flags |= 0x8000;
+ h->ref_dynamic = 0;
+ h->pointer_equality_needed = 1;
}
return TRUE;
}
static bfd_boolean
-elf_hppa_remark_useless_dynamic_symbols (h, data)
- struct elf_link_hash_entry *h;
- PTR data;
+elf_hppa_remark_useless_dynamic_symbols (struct elf_link_hash_entry *h,
+ void *data)
{
- struct bfd_link_info *info = (struct bfd_link_info *)data;
+ struct bfd_link_info *info = data;
if (h->root.type == bfd_link_hash_warning)
h = (struct elf_link_hash_entry *) h->root.u.i.link;
the generic code will warn that it is undefined.
This behavior is undesirable on HPs since the standard shared
- libraries contain reerences to undefined symbols.
+ libraries contain references to undefined symbols.
So we twiddle the flags associated with such symbols so that they
will not trigger the warning. ?!? FIXME. This is horribly fragile.
Ultimately we should have better controls over the generic ELF BFD
linker code. */
- if (! info->relocateable
- && ! (info->shared
- && !info->no_undefined)
+ if (! info->relocatable
+ && info->unresolved_syms_in_shared_libs != RM_IGNORE
&& h->root.type == bfd_link_hash_undefined
- && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0
- && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0
- && (h->elf_link_hash_flags & 0x8000) != 0)
+ && !h->ref_dynamic
+ && !h->ref_regular
+ && h->pointer_equality_needed)
{
- h->elf_link_hash_flags |= ELF_LINK_HASH_REF_DYNAMIC;
- h->elf_link_hash_flags &= ~0x8000;
+ h->ref_dynamic = 1;
+ h->pointer_equality_needed = 0;
}
return TRUE;
}
static bfd_boolean
-elf_hppa_is_dynamic_loader_symbol (name)
- const char * name;
+elf_hppa_is_dynamic_loader_symbol (const char *name)
{
return (! strcmp (name, "__CPU_REVISION")
|| ! strcmp (name, "__CPU_KEYBITS_1")
/* Record the lowest address for the data and text segments. */
static void
-elf_hppa_record_segment_addrs (abfd, section, data)
- bfd *abfd ATTRIBUTE_UNUSED;
- asection *section;
- PTR data;
+elf_hppa_record_segment_addrs (bfd *abfd ATTRIBUTE_UNUSED,
+ asection *section,
+ void *data)
{
struct elf64_hppa_link_hash_table *hppa_info;
bfd_vma value;
- hppa_info = (struct elf64_hppa_link_hash_table *)data;
+ hppa_info = data;
value = section->vma - section->filepos;
fall back to the generic ELF final link routine. */
static bfd_boolean
-elf_hppa_final_link (abfd, info)
- bfd *abfd;
- struct bfd_link_info *info;
+elf_hppa_final_link (bfd *abfd, struct bfd_link_info *info)
{
bfd_boolean retval;
struct elf64_hppa_link_hash_table *hppa_info = elf64_hppa_hash_table (info);
- if (! info->relocateable)
+ if (! info->relocatable)
{
struct elf_link_hash_entry *gp;
bfd_vma gp_val;
hppa_info->data_segment_base = (bfd_vma)-1;
/* HP's shared libraries have references to symbols that are not
- defined anywhere. The generic ELF BFD linker code will complaim
+ defined anywhere. The generic ELF BFD linker code will complain
about such symbols.
So we detect the losing case and arrange for the flags on the symbol
info);
/* Invoke the regular ELF backend linker to do all the work. */
- retval = bfd_elf_bfd_final_link (abfd, info);
+ retval = bfd_elf_final_link (abfd, info);
elf_link_hash_traverse (elf_hash_table (info),
elf_hppa_remark_useless_dynamic_symbols,
/* Relocate an HPPA ELF section. */
static bfd_boolean
-elf_hppa_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;
+elf_hppa_relocate_section (bfd *output_bfd,
+ struct bfd_link_info *info,
+ bfd *input_bfd,
+ asection *input_section,
+ bfd_byte *contents,
+ Elf_Internal_Rela *relocs,
+ Elf_Internal_Sym *local_syms,
+ asection **local_sections)
{
Elf_Internal_Shdr *symtab_hdr;
Elf_Internal_Rela *rel;
Elf_Internal_Rela *relend;
struct elf64_hppa_link_hash_table *hppa_info;
- if (info->relocateable)
+ if (info->relocatable)
return TRUE;
hppa_info = elf64_hppa_hash_table (info);
asection *sym_sec;
bfd_vma relocation;
bfd_reloc_status_type r;
- const char *sym_name;
const char *dyn_name;
char *dynh_buf = NULL;
size_t dynh_buflen = 0;
/* This is a local symbol. */
sym = local_syms + r_symndx;
sym_sec = local_sections[r_symndx];
- relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sym_sec, rel);
+ relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sym_sec, rel);
/* If this symbol has an entry in the PA64 dynamic hash
table, then get it. */
- dyn_name = get_dyn_name (input_section, h, rel,
+ dyn_name = get_dyn_name (input_bfd, h, rel,
&dynh_buf, &dynh_buflen);
dyn_h = elf64_hppa_dyn_hash_lookup (&hppa_info->dyn_hash_table,
dyn_name, FALSE, FALSE);
/* If this symbol has an entry in the PA64 dynamic hash
table, then get it. */
- dyn_name = get_dyn_name (input_section, h, rel,
+ dyn_name = get_dyn_name (input_bfd, h, rel,
&dynh_buf, &dynh_buflen);
dyn_h = elf64_hppa_dyn_hash_lookup (&hppa_info->dyn_hash_table,
dyn_name, FALSE, FALSE);
if (sym_sec->output_section == NULL && dyn_h == NULL)
{
(*_bfd_error_handler)
- (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"),
- bfd_archive_filename (input_bfd), h->root.root.string,
- bfd_get_section_name (input_bfd, input_section));
+ (_("%B(%A): warning: unresolvable relocation against symbol `%s'"),
+ input_bfd, input_section, h->root.root.string);
relocation = 0;
}
else if (sym_sec->output_section)
else
relocation = 0;
}
- /* Allow undefined symbols in shared libraries. */
- else if (info->shared && !info->no_undefined
+ else if (info->unresolved_syms_in_objects == RM_IGNORE
&& ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
{
- if (info->symbolic)
- (*info->callbacks->undefined_symbol)
- (info, h->root.root.string, input_bfd,
- input_section, rel->r_offset, FALSE);
-
/* If this symbol has an entry in the PA64 dynamic hash
table, then get it. */
- dyn_name = get_dyn_name (input_section, h, rel,
+ dyn_name = get_dyn_name (input_bfd, h, rel,
&dynh_buf, &dynh_buflen);
dyn_h = elf64_hppa_dyn_hash_lookup (&hppa_info->dyn_hash_table,
dyn_name, FALSE, FALSE);
if (dyn_h == NULL)
{
(*_bfd_error_handler)
- (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"),
- bfd_archive_filename (input_bfd), h->root.root.string,
- bfd_get_section_name (input_bfd, input_section));
- relocation = 0;
+ (_("%B(%A): warning: unresolvable relocation against symbol `%s'"),
+ input_bfd, input_section, h->root.root.string);
}
relocation = 0;
}
else if (h->root.type == bfd_link_hash_undefweak)
- relocation = 0;
+ {
+ dyn_name = get_dyn_name (input_bfd, h, rel,
+ &dynh_buf, &dynh_buflen);
+ dyn_h = elf64_hppa_dyn_hash_lookup (&hppa_info->dyn_hash_table,
+ dyn_name, FALSE, FALSE);
+
+ if (dyn_h == NULL)
+ {
+ (*_bfd_error_handler)
+ (_("%B(%A): warning: unresolvable relocation against symbol `%s'"),
+ input_bfd, input_section, h->root.root.string);
+ }
+ relocation = 0;
+ }
else
{
/* Ignore dynamic loader defined symbols. */
{
if (!((*info->callbacks->undefined_symbol)
(info, h->root.root.string, input_bfd,
- input_section, rel->r_offset, TRUE)))
+ input_section, rel->r_offset,
+ (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
+ || ELF_ST_VISIBILITY (h->other)))))
return FALSE;
break;
}
}
}
- if (h != NULL)
- sym_name = h->root.root.string;
- else
- {
- sym_name = bfd_elf_string_from_elf_section (input_bfd,
- symtab_hdr->sh_link,
- sym->st_name);
- if (sym_name == NULL)
- return FALSE;
- if (*sym_name == '\0')
- sym_name = bfd_section_name (input_bfd, sym_sec);
- }
-
r = elf_hppa_final_link_relocate (rel, input_bfd, output_bfd,
input_section, contents,
relocation, info, sym_sec,
abort ();
case bfd_reloc_overflow:
{
+ const char *sym_name;
+
+ if (h != NULL)
+ sym_name = NULL;
+ else
+ {
+ sym_name = bfd_elf_string_from_elf_section (input_bfd,
+ symtab_hdr->sh_link,
+ sym->st_name);
+ if (sym_name == NULL)
+ return FALSE;
+ if (*sym_name == '\0')
+ sym_name = bfd_section_name (input_bfd, sym_sec);
+ }
+
if (!((*info->callbacks->reloc_overflow)
- (info, sym_name, howto->name, (bfd_vma) 0,
- input_bfd, input_section, rel->r_offset)))
+ (info, (h ? &h->root : NULL), sym_name,
+ howto->name, (bfd_vma) 0, input_bfd,
+ input_section, rel->r_offset)))
return FALSE;
}
break;
function. */
static bfd_reloc_status_type
-elf_hppa_final_link_relocate (rel, input_bfd, output_bfd,
- input_section, contents, value,
- info, sym_sec, h, dyn_h)
- Elf_Internal_Rela *rel;
- bfd *input_bfd;
- bfd *output_bfd;
- asection *input_section;
- bfd_byte *contents;
- bfd_vma value;
- struct bfd_link_info *info;
- asection *sym_sec;
- struct elf_link_hash_entry *h ATTRIBUTE_UNUSED;
- struct elf64_hppa_dyn_hash_entry *dyn_h;
+elf_hppa_final_link_relocate (Elf_Internal_Rela *rel,
+ bfd *input_bfd,
+ bfd *output_bfd,
+ asection *input_section,
+ bfd_byte *contents,
+ bfd_vma value,
+ struct bfd_link_info *info,
+ asection *sym_sec,
+ struct elf_link_hash_entry *h ATTRIBUTE_UNUSED,
+ struct elf64_hppa_dyn_hash_entry *dyn_h)
{
int insn;
bfd_vma offset = rel->r_offset;
to insert the relocation into the given instruction. */
static int
-elf_hppa_relocate_insn (insn, sym_value, r_type)
- int insn;
- int sym_value;
- unsigned int r_type;
+elf_hppa_relocate_insn (int insn, int sym_value, unsigned int r_type)
{
switch (r_type)
{