/* IA-64 support for 64-bit ELF
- Copyright (C) 1998-2018 Free Software Foundation, Inc.
+ Copyright (C) 1998-2020 Free Software Foundation, Inc.
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
This file is part of BFD, the Binary File Descriptor library.
#include "elf/ia64.h"
#include "objalloc.h"
#include "hashtab.h"
-#include "bfd_stdint.h"
#include "elfxx-ia64.h"
#define ARCH_SIZE NN
#define LOG_SECTION_ALIGN 2
#endif
+#define is_ia64_elf(bfd) \
+ (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
+ && elf_object_id (bfd) == IA64_ELF_DATA)
+
typedef struct bfd_hash_entry *(*new_hash_entry_func)
(struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
/* Given a ELF reloc, return the matching HOWTO structure. */
-static void
+static bfd_boolean
elfNN_ia64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
arelent *bfd_reloc,
Elf_Internal_Rela *elf_reloc)
{
- bfd_reloc->howto
- = ia64_elf_lookup_howto ((unsigned int) ELFNN_R_TYPE (elf_reloc->r_info));
+ unsigned int r_type = ELF32_R_TYPE (elf_reloc->r_info);
+
+ bfd_reloc->howto = ia64_elf_lookup_howto (r_type);
+ if (bfd_reloc->howto == NULL)
+ {
+ /* xgettext:c-format */
+ _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
+ abfd, r_type);
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+ }
+
+ return TRUE;
}
\f
#define PLT_HEADER_SIZE (3 * 16)
1, change it to slot 2. */
if ((irel->r_offset & 3) == 1)
irel->r_offset += 1;
+
+ changed_contents = TRUE;
+ changed_relocs = TRUE;
}
continue;
/* Make the relocation offset point to slot 1. */
irel->r_offset = (irel->r_offset & ~((bfd_vma) 0x3)) + 1;
+
+ changed_contents = TRUE;
+ changed_relocs = TRUE;
continue;
}
{
_bfd_error_handler
/* xgettext:c-format */
- (_("%pB: Can't relax br at %#" PRIx64 " in section `%pA'."
- " Please use brl or indirect branch."),
+ (_("%pB: can't relax br at %#" PRIx64 " in section `%pA';"
+ " please use brl or indirect branch"),
sec->owner, (uint64_t) roff, sec);
bfd_set_error (bfd_error_bad_value);
goto error_return;
return TRUE;
error_return:
- if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents)
+ if ((unsigned char *) isymbuf != symtab_hdr->contents)
free (isymbuf);
- if (contents != NULL
- && elf_section_data (sec)->this_hdr.contents != contents)
+ if (elf_section_data (sec)->this_hdr.contents != contents)
free (contents);
- if (internal_relocs != NULL
- && elf_section_data (sec)->relocs != internal_relocs)
+ if (elf_section_data (sec)->relocs != internal_relocs)
free (internal_relocs);
return FALSE;
}
flag. */
static bfd_boolean
-elfNN_ia64_section_flags (flagword *flags,
- const Elf_Internal_Shdr *hdr)
+elfNN_ia64_section_flags (const Elf_Internal_Shdr *hdr)
{
if (hdr->sh_flags & SHF_IA_64_SHORT)
- *flags |= SEC_SMALL_DATA;
+ hdr->bfd_section->flags |= SEC_SMALL_DATA;
return TRUE;
}
{
const char *name;
- name = bfd_get_section_name (abfd, sec);
+ name = bfd_section_name (sec);
if (is_unwind_section_name (abfd, name))
{
/* The final processing done just before writing out an IA-64 ELF
object file. */
-static void
-elfNN_ia64_final_write_processing (bfd *abfd,
- bfd_boolean linker ATTRIBUTE_UNUSED)
+static bfd_boolean
+elfNN_ia64_final_write_processing (bfd *abfd)
{
Elf_Internal_Shdr *hdr;
asection *s;
elf_elfheader(abfd)->e_flags = flags;
elf_flags_init (abfd) = TRUE;
}
+ return _bfd_elf_final_write_processing (abfd);
}
/* Hook called by the linker routine which adds symbols from an object
for SHF_IA_64_NORECOV on each. */
static bfd_boolean
-elfNN_ia64_modify_program_headers (bfd *abfd,
- struct bfd_link_info *info ATTRIBUTE_UNUSED)
+elfNN_ia64_modify_headers (bfd *abfd, struct bfd_link_info *info)
{
struct elf_obj_tdata *tdata = elf_tdata (abfd);
struct elf_segment_map *m;
found:;
}
- return TRUE;
+ return _bfd_elf_modify_headers (abfd, info);
}
/* According to the Tahoe assembler spec, all labels starting with a
struct elfNN_ia64_dyn_sym_info *dyn_i;
unsigned int count;
- if (dir->info)
- free (dir->info);
+ free (dir->info);
dir->info = ind->info;
dir->count = ind->count;
struct elfNN_ia64_link_hash_entry *entry
= (struct elfNN_ia64_link_hash_entry *) xentry;
- if (entry->info)
- {
- free (entry->info);
- entry->info = NULL;
- entry->count = 0;
- entry->sorted_count = 0;
- entry->size = 0;
- }
+ free (entry->info);
+ entry->info = NULL;
+ entry->count = 0;
+ entry->sorted_count = 0;
+ entry->size = 0;
return TRUE;
}
struct elfNN_ia64_local_hash_entry *entry
= (struct elfNN_ia64_local_hash_entry *) *slot;
- if (entry->info)
- {
- free (entry->info);
- entry->info = NULL;
- entry->count = 0;
- entry->sorted_count = 0;
- entry->size = 0;
- }
+ free (entry->info);
+ entry->info = NULL;
+ entry->count = 0;
+ entry->sorted_count = 0;
+ entry->size = 0;
return TRUE;
}
return FALSE;
{
- flagword flags = bfd_get_section_flags (abfd, ia64_info->root.sgot);
- bfd_set_section_flags (abfd, ia64_info->root.sgot,
- SEC_SMALL_DATA | flags);
+ flagword flags = bfd_section_flags (ia64_info->root.sgot);
+ bfd_set_section_flags (ia64_info->root.sgot, SEC_SMALL_DATA | flags);
/* The .got section is always aligned at 8 bytes. */
- if (! bfd_set_section_alignment (abfd, ia64_info->root.sgot, 3))
+ if (!bfd_set_section_alignment (ia64_info->root.sgot, 3))
return FALSE;
}
| SEC_LINKER_CREATED
| SEC_READONLY));
if (s == NULL
- || !bfd_set_section_alignment (abfd, s, LOG_SECTION_ALIGN))
+ || !bfd_set_section_alignment (s, LOG_SECTION_ALIGN))
return FALSE;
ia64_info->rel_pltoff_sec = s;
*size_p = size;
*info_p = info;
-has_space:
+ has_space:
/* Append the new one to the array. */
dyn_i = info + count;
memset (dyn_i, 0, sizeof (*dyn_i));
got = ia64_info->root.sgot;
/* The .got section is always aligned at 8 bytes. */
- if (!bfd_set_section_alignment (abfd, got, 3))
+ if (!bfd_set_section_alignment (got, 3))
return NULL;
- flags = bfd_get_section_flags (abfd, got);
- if (! bfd_set_section_flags (abfd, got, SEC_SMALL_DATA | flags))
+ flags = bfd_section_flags (got);
+ if (!bfd_set_section_flags (got, SEC_SMALL_DATA | flags))
return NULL;
}
? 0 : SEC_READONLY)
| SEC_LINKER_CREATED));
if (!fptr
- || !bfd_set_section_alignment (abfd, fptr, 4))
+ || !bfd_set_section_alignment (fptr, 4))
{
BFD_ASSERT (0);
return NULL;
| SEC_LINKER_CREATED
| SEC_READONLY));
if (fptr_rel == NULL
- || !bfd_set_section_alignment (abfd, fptr_rel,
- LOG_SECTION_ALIGN))
+ || !bfd_set_section_alignment (fptr_rel, LOG_SECTION_ALIGN))
{
BFD_ASSERT (0);
return NULL;
| SEC_SMALL_DATA
| SEC_LINKER_CREATED));
if (!pltoff
- || !bfd_set_section_alignment (abfd, pltoff, 4))
+ || !bfd_set_section_alignment (pltoff, 4))
{
BFD_ASSERT (0);
return NULL;
| SEC_LINKER_CREATED
| SEC_READONLY));
if (srel == NULL
- || !bfd_set_section_alignment (dynobj, srel,
- LOG_SECTION_ALIGN))
+ || !bfd_set_section_alignment (srel, LOG_SECTION_ALIGN))
return NULL;
}
/* It's OK to base decisions on the section name, because none
of the dynobj section names depend upon the input files. */
- name = bfd_get_section_name (dynobj, sec);
+ name = bfd_section_name (sec);
if (strcmp (name, ".got.plt") == 0)
strip = FALSE;
{
if (max_short_vma - min_short_vma >= 0x400000)
{
-overflow:
+ overflow:
_bfd_error_handler
/* xgettext:c-format */
(_("%pB: short data segment overflowed (%#" PRIx64 " >= 0x400000)"),
r_type = ELFNN_R_TYPE (rel->r_info);
if (r_type > R_IA64_MAX_RELOC_CODE)
{
- _bfd_error_handler
- /* xgettext:c-format */
- (_("%pB: unknown relocation type %d"), input_bfd, (int) r_type);
+ /* xgettext:c-format */
+ _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
+ input_bfd, (int) r_type);
bfd_set_error (bfd_error_bad_value);
ret_val = FALSE;
continue;
}
howto = ia64_elf_lookup_howto (r_type);
+ if (howto == NULL)
+ {
+ ret_val = FALSE;
+ continue;
+ }
+
r_symndx = ELFNN_R_SYM (rel->r_info);
h = NULL;
sym = NULL;
case bfd_reloc_outofrange:
case bfd_reloc_overflow:
default:
-missing_tls_sec:
+ missing_tls_sec:
{
const char *name;
/* Merge backend specific data from an object file to the output
object file when linking. */
+
static bfd_boolean
elfNN_ia64_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
{
flagword in_flags;
bfd_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;
+ /* FIXME: What should be checked when linking shared libraries? */
+ if ((ibfd->flags & DYNAMIC) != 0)
+ return TRUE;
+
+ if (!is_ia64_elf (ibfd) || !is_ia64_elf (obfd))
+ return TRUE;
in_flags = elf_elfheader (ibfd)->e_flags;
out_flags = elf_elfheader (obfd)->e_flags;
flagword flags;
const char *name;
char *unwi_name, *unw_name;
- bfd_size_type amt;
+ size_t amt;
if (abfd->flags & DYNAMIC)
return TRUE;
return (vec == &ia64_elfNN_hpux_be_vec);
}
-static void
-elfNN_hpux_post_process_headers (bfd *abfd,
- struct bfd_link_info *info ATTRIBUTE_UNUSED)
+static bfd_boolean
+elfNN_hpux_init_file_header (bfd *abfd, struct bfd_link_info *info)
{
- Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd);
+ Elf_Internal_Ehdr *i_ehdrp;
+
+ if (!_bfd_elf_init_file_header (abfd, info))
+ return FALSE;
+ i_ehdrp = elf_elfheader (abfd);
i_ehdrp->e_ident[EI_OSABI] = get_elf_backend_data (abfd)->elf_osabi;
i_ehdrp->e_ident[EI_ABIVERSION] = 1;
+ return TRUE;
}
static bfd_boolean
break;
}
}
+
+static void
+ignore_errors (const char *fmt ATTRIBUTE_UNUSED, ...)
+{
+}
\f
#define TARGET_LITTLE_SYM ia64_elfNN_le_vec
#define TARGET_LITTLE_NAME "elfNN-ia64-little"
elfNN_ia64_additional_program_headers
#define elf_backend_modify_segment_map \
elfNN_ia64_modify_segment_map
-#define elf_backend_modify_program_headers \
- elfNN_ia64_modify_program_headers
+#define elf_backend_modify_headers \
+ elfNN_ia64_modify_headers
#define elf_info_to_howto \
elfNN_ia64_info_to_howto
elfNN_ia64_print_private_bfd_data
#define elf_backend_plt_readonly 1
+#define elf_backend_can_gc_sections 1
#define elf_backend_want_plt_sym 0
#define elf_backend_plt_alignment 5
#define elf_backend_got_header_size 0
We don't want to flood users with so many error messages. We turn
off the warning for now. It will be turned on later when the Intel
compiler is fixed. */
-#define elf_backend_link_order_error_handler NULL
+#define elf_backend_link_order_error_handler ignore_errors
#include "elfNN-target.h"
/* 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_init_file_header
+#define elf_backend_init_file_header elfNN_hpux_init_file_header
#undef elf_backend_section_from_bfd_section
#define elf_backend_section_from_bfd_section elfNN_hpux_backend_section_from_bfd_section