/* NDS32-specific support for 32-bit ELF.
- Copyright (C) 2012-2016 Free Software Foundation, Inc.
+ Copyright (C) 2012-2017 Free Software Foundation, Inc.
Contributed by Andes Technology Corporation.
This file is part of BFD, the Binary File Descriptor library.
r_type = ELF32_R_TYPE (dst->r_info);
if (r_type > R_NDS32_GNU_VTENTRY)
{
+ /* xgettext:c-format */
_bfd_error_handler (_("%B: invalid NDS32 reloc number: %d"), abfd, r_type);
r_type = 0;
}
}
}
- if (add_symbol == TRUE)
+ if (add_symbol)
{
if (h)
{
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_ld_script = NULL;
- ret->ex9_export_file = NULL;
- ret->ex9_import_file = NULL;
-
return &ret->root.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 elf_nds32_link_hash_table *htab;
-
- if (!_bfd_elf_create_got_section (dynobj, info))
- return FALSE;
-
- htab = nds32_elf_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 ();
-
- /* _bfd_elf_create_got_section will create it for us. */
- htab->srelgot = bfd_get_section_by_name (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, 2))
- return FALSE;
-
- return TRUE;
-}
-
/* Create dynamic sections when linking against a dynamic object. */
static bfd_boolean
pltflags |= SEC_READONLY;
s = bfd_make_section (abfd, ".plt");
- htab->splt = s;
+ htab->root.splt = s;
if (s == NULL
|| !bfd_set_section_flags (abfd, s, pltflags)
|| !bfd_set_section_alignment (abfd, s, bed->plt_alignment))
s = bfd_make_section (abfd,
bed->default_use_rela_p ? ".rela.plt" : ".rel.plt");
- htab->srelplt = s;
+ htab->root.srelplt = s;
if (s == NULL
|| !bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
|| !bfd_set_section_alignment (abfd, s, ptralign))
return FALSE;
- if (htab->sgot == NULL && !create_got_section (abfd, info))
+ if (htab->root.sgot == NULL && !_bfd_elf_create_got_section (abfd, info))
return FALSE;
{
if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h))
{
- asection *s = htab->splt;
+ asection *s = htab->root.splt;
/* If this is the first .plt entry, make room for the special
first entry. */
/* 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->size += 4;
+ htab->root.sgotplt->size += 4;
/* We also need to make an entry in the .rel.plt section. */
- htab->srelplt->size += sizeof (Elf32_External_Rela);
+ htab->root.srelplt->size += sizeof (Elf32_External_Rela);
}
else
{
return FALSE;
}
- s = htab->sgot;
+ s = htab->root.sgot;
h->got.offset = s->size;
if (tls_type == GOT_UNKNOWN)
dyn = htab->root.dynamic_sections_created;
if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h))
- htab->srelgot->size += sizeof (Elf32_External_Rela);
+ htab->root.srelgot->size += sizeof (Elf32_External_Rela);
}
else
h->got.offset = (bfd_vma) - 1;
symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
locsymcount = symtab_hdr->sh_info;
end_local_got = local_got + locsymcount;
- s = htab->sgot;
- srel = htab->srelgot;
+ s = htab->root.sgot;
+ srel = htab->root.srelgot;
for (; local_got < end_local_got; ++local_got)
{
if (*local_got > 0)
if ((s->flags & SEC_LINKER_CREATED) == 0)
continue;
- if (s == htab->splt)
+ if (s == htab->root.splt)
{
/* Strip this section if we don't need it; see the
comment below. */
}
- else if (s == htab->sgot)
+ else if (s == htab->root.sgot)
{
got_size += s->size;
}
- else if (s == htab->sgotplt)
+ else if (s == htab->root.sgotplt)
{
got_size += s->size;
}
else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
{
- if (s->size != 0 && s != htab->srelplt)
+ if (s->size != 0 && s != htab->root.srelplt)
relocs = TRUE;
/* We use the reloc_count field as a counter if we need
return FALSE;
}
- if (htab->splt->size != 0)
+ if (htab->root.splt->size != 0)
{
if (!add_dynamic_entry (DT_PLTGOT, 0)
|| !add_dynamic_entry (DT_PLTRELSZ, 0)
dynobj = htab->root.dynobj;
local_got_offsets = elf_local_got_offsets (input_bfd);
- sgot = htab->sgot;
- splt = htab->splt;
+ sgot = htab->root.sgot;
+ splt = htab->root.splt;
sreloc = NULL;
rel = relocs;
r_type = ELF32_R_TYPE (rel->r_info);
if (r_type >= R_NDS32_max)
{
+ /* xgettext:c-format */
_bfd_error_handler (_("%B: error: unknown relocation type %d."),
input_bfd, r_type);
bfd_set_error (bfd_error_bad_value);
/* We need to generate a R_NDS32_RELATIVE reloc
for the dynamic linker. */
- srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
+ srelgot = htab->root.srelgot;
BFD_ASSERT (srelgot != NULL);
outrel.r_offset = (elf_gp (output_bfd)
if (bfd_link_pic (info))
{
_bfd_error_handler
- (_("%s: warning: cannot deal R_NDS32_25_ABS_RELA in shared "
- "mode."), bfd_get_filename (input_bfd));
+ (_("%B: warning: cannot deal R_NDS32_25_ABS_RELA in shared "
+ "mode."), input_bfd);
return FALSE;
}
break;
/* We need to generate a R_NDS32_RELATIVE reloc
for the dynamic linker. */
- srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
+ srelgot = htab->root.srelgot;
BFD_ASSERT (srelgot != NULL);
outrel.r_offset = (elf_gp (output_bfd)
{
/* Incorrect alignment. */
_bfd_error_handler
+ /* xgettext:c-format */
(_("%B(%A): warning: unaligned small data access of type %d."),
input_bfd, input_section, r_type);
ret = FALSE;
else
{
bfd_boolean need_relocs = FALSE;
- srelgot = htab->srelgot;
+ srelgot = htab->root.srelgot;
if ((bfd_link_pic (info) || indx != 0)
&& (h == NULL
|| ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
BFD_ASSERT (h->dynindx != -1);
- splt = htab->splt;
- sgot = htab->sgotplt;
- srela = htab->srelplt;
+ splt = htab->root.splt;
+ sgot = htab->root.sgotplt;
+ srela = htab->root.srelplt;
BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
/* Get the index in the procedure linkage table which
/* This symbol has an entry in the global offset table.
Set it up. */
- sgot = htab->sgot;
- srela = htab->srelgot;
+ sgot = htab->root.sgot;
+ srela = htab->root.srelgot;
BFD_ASSERT (sgot != NULL && srela != NULL);
rela.r_offset = (sgot->output_section->vma
htab = nds32_elf_hash_table (info);
dynobj = htab->root.dynobj;
- sgot = htab->sgotplt;
+ sgot = htab->root.sgotplt;
sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
if (htab->root.dynamic_sections_created)
break;
case DT_PLTGOT:
- s = htab->sgotplt;
+ s = htab->root.sgotplt;
goto get_vma;
case DT_JMPREL:
- s = htab->srelplt;
+ s = htab->root.srelplt;
get_vma:
dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
break;
case DT_PLTRELSZ:
- s = htab->srelplt;
+ s = htab->root.srelplt;
dyn.d_un.d_val = s->size;
bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
break;
-
- case DT_RELASZ:
- /* My reading of the SVR4 ABI indicates that the
- procedure linkage table relocs (DT_JMPREL) should be
- included in the overall relocs (DT_RELA). This is
- what Solaris does. However, UnixWare can not handle
- that case. 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)
- {
- s = htab->srelplt;
- dyn.d_un.d_val -= s->size;
- }
- bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
- break;
}
}
/* Fill in the first entry in the procedure linkage table. */
- splt = htab->splt;
+ splt = htab->root.splt;
if (splt && splt->size > 0)
{
if (bfd_link_pic (info))
else if (nds32_vec_size != (flag_t & 0x3))
{
_bfd_error_handler
+ /* xgettext:c-format */
(_("%B: ISR vector size mismatch"
" with previous modules, previous %u-byte, current %u-byte"),
ibfd,
{
if (in_version != out_version)
_bfd_error_handler
+ /* xgettext:c-format */
(_("%B: warning: Incompatible elf-versions %s and %s."),
ibfd, nds32_elfver_strtab[out_version],
nds32_elfver_strtab[in_version]);
/* Some relocs require a global offset table. We create
got section here, since these relocation need got section
and it is not created yet. */
- if (htab->sgot == NULL)
+ if (htab->root.sgot == NULL)
{
switch (r_type)
{
case R_NDS32_TLS_IE_LO12S2:
if (dynobj == NULL)
htab->root.dynobj = dynobj = abfd;
- if (!create_got_section (dynobj, info))
+ if (!_bfd_elf_create_got_section (dynobj, info))
return FALSE;
break;
h = elf_sym_hashes (abfd)[indx];
BFD_ASSERT (h != NULL);
htab = nds32_elf_hash_table (link_info);
- splt = htab->splt;
+ splt = htab->root.splt;
while (h->root.type == bfd_link_hash_indirect
|| h->root.type == bfd_link_hash_warning)
if (symndx >= 0)
{
BFD_ASSERT (h != NULL);
- return htab->sgot->output_section->vma + htab->sgot->output_offset
- + h->got.offset;
+ return (htab->root.sgot->output_section->vma
+ + htab->root.sgot->output_offset
+ + h->got.offset);
}
else
{
local_got_offsets = elf_local_got_offsets (abfd);
BFD_ASSERT (local_got_offsets != NULL);
- return htab->sgot->output_section->vma + htab->sgot->output_offset
- + local_got_offsets[ELF32_R_SYM (irel->r_info)];
+ return (htab->root.sgot->output_section->vma
+ + htab->root.sgot->output_offset
+ + local_got_offsets[ELF32_R_SYM (irel->r_info)]);
}
/* The _GLOBAL_OFFSET_TABLE_ may be undefweak(or should be?). */
unsigned long before, between;
bfd_byte *endp, *p;
- val = read_unsigned_leb128 (abfd, contents + irel->r_offset,
- &len);
+ val = _bfd_read_unsigned_leb128 (abfd, contents + irel->r_offset,
+ &len);
before = get_nds32_elf_blank_total (&blank_t, irel->r_addend, 0);
between = get_nds32_elf_blank_total (&blank_t,
&& (blank_t2->offset > raddr
|| blank_t2->next->offset <= raddr))
_bfd_error_handler
- (_("%B: %s\n"), abfd,
- "Error: search_nds32_elf_blank reports wrong node");
+ (_("%B: Error: search_nds32_elf_blank reports wrong node\n"), abfd);
/* Mark reloc in deleted portion as NONE.
For some relocs like R_NDS32_LABEL that doesn't modify the
#define IS_OPTIMIZE(addend) ((addend) & 0x40000000)
#define IS_16BIT_ON(addend) ((addend) & 0x20000000)
+static const char * unrecognized_reloc_msg =
+ /* xgettext:c-format */
+ N_("%B: warning: %s points to unrecognized reloc at 0x%lx.");
+
/* Relax LONGCALL1 relocation for nds32_elf_relax_section. */
static bfd_boolean
if (hi_irelfn == irelend || lo_irelfn == irelend)
{
- _bfd_error_handler
- ("%B: warning: R_NDS32_LONGCALL1 points to unrecognized"
- "reloc at 0x%lx.", abfd, (long) irel->r_offset);
+ _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGCALL1",
+ (long) irel->r_offset);
return FALSE;
}
if (i1_irelfn == irelend)
{
- _bfd_error_handler
- ("%B: warning: R_NDS32_LONGCALL2 points to unrecognized"
- "reloc at 0x%lx.", abfd, (long) irel->r_offset);
+ _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGCALL2",
+ (long) irel->r_offset);
return FALSE;
}
if (hi_irelfn == irelend || lo_irelfn == irelend)
{
- _bfd_error_handler
- ("%B: warning: R_NDS32_LONGCALL3 points to unrecognized"
- "reloc at 0x%lx.", abfd, (long) irel->r_offset);
+ _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGCALL3",
+ (long) irel->r_offset);
return FALSE;
}
R_NDS32_LO12S0_ORI_RELA, laddr + 4);
if (hi_irelfn == irelend || lo_irelfn == irelend)
{
- _bfd_error_handler
- ("%B: warning: R_NDS32_LONGJUMP1 points to unrecognized"
- "reloc at 0x%lx.", abfd, (long) irel->r_offset);
+ _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGJUMP1",
+ (long) irel->r_offset);
return FALSE;
}
if (i2_irelfn == irelend || cond_irelfn == irelend)
{
- _bfd_error_handler
- ("%B: warning: R_NDS32_LONGJUMP2 points to unrecognized"
- "reloc at 0x%lx.", abfd, (long) irel->r_offset);
+ _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGJUMP2",
+ (long) irel->r_offset);
return FALSE;
}
if (hi_irelfn == irelend || lo_irelfn == irelend || cond_irelfn == irelend)
{
- _bfd_error_handler
- ("%B: warning: R_NDS32_LONGJUMP3 points to unrecognized"
- "reloc at 0x%lx.", abfd, (long) irel->r_offset);
+ _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGJUMP3",
+ (long) irel->r_offset);
return FALSE;
}
if (hi_irel == irelend)
{
- _bfd_error_handler
- ("%B: warning: R_NDS32_LONGCALL4 points to unrecognized"
- "reloc at 0x%lx.", abfd, (long) irel->r_offset);
+ _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGCALL4",
+ (long) irel->r_offset);
return FALSE;
}
if (ptr_irel == irelend || em_irel == irelend)
{
- _bfd_error_handler
- ("%B: warning: R_NDS32_LONGCALL4 points to unrecognized"
- "reloc at 0x%lx.", abfd, (long) irel->r_offset);
+ _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGCALL4",
+ (long) irel->r_offset);
return FALSE;
}
/* Check these is enough space to insert jal in R_NDS32_EMPTY. */
R_NDS32_25_PCREL_RELA, irel->r_addend);
if (cond_irel == irelend)
{
- _bfd_error_handler
- ("%B: warning: R_NDS32_LONGCALL5 points to unrecognized"
- "reloc at 0x%lx.", abfd, (long) irel->r_offset);
+ _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGCALL5",
+ (long) irel->r_offset);
return FALSE;
}
if (em_irel == irelend)
{
- _bfd_error_handler
- ("%B: warning: R_NDS32_LONGCALL6 points to unrecognized"
- "reloc at 0x%lx.", abfd, (long) irel->r_offset);
+ _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGCALL6",
+ (long) irel->r_offset);
return FALSE;
}
R_NDS32_PTR_RESOLVED, irel->r_addend);
if (cond_irel == irelend)
{
- _bfd_error_handler
- ("%B: warning: R_NDS32_LONGCALL6 points to unrecognized"
- "reloc at 0x%lx.", abfd, (long) irel->r_offset);
+ _bfd_error_handler (unrecognized_reloc_msg, abfd,
+ "R_NDS32_LONGCALL6", (long) irel->r_offset);
return FALSE;
}
cond_irel->r_addend = 1;
R_NDS32_PTR_RESOLVED, irel->r_addend);
if (cond_irel == irelend)
{
- _bfd_error_handler
- ("%B: warning: R_NDS32_LONGCALL6 points to unrecognized"
- "reloc at 0x%lx.", abfd, (long) irel->r_offset);
+ _bfd_error_handler (unrecognized_reloc_msg, abfd,
+ "R_NDS32_LONGCALL6", (long) irel->r_offset);
return FALSE;
}
cond_irel->r_addend = 1;
if (hi_irel == irelend)
{
- _bfd_error_handler
- ("%B: warning: R_NDS32_LONGJUMP4 points to unrecognized"
- "reloc at 0x%lx.", abfd, (long) irel->r_offset);
+ _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGJUMP4",
+ (long) irel->r_offset);
return FALSE;
}
if (ptr_irel == irelend || em_irel == irelend)
{
- _bfd_error_handler
- ("%B: warning: R_NDS32_LONGJUMP4 points to unrecognized"
- "reloc at 0x%lx.", abfd, (long) irel->r_offset);
+ _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGJUMP4",
+ (long) irel->r_offset);
return FALSE;
}
R_NDS32_25_PCREL_RELA, irel->r_addend);
if (cond_irel == irelend)
{
- _bfd_error_handler
- ("%B: warning: R_NDS32_LONGJUMP5 points to unrecognized"
- "reloc at 0x%lx.", abfd, (long) irel->r_offset);
+ _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGJUMP5",
+ (long) irel->r_offset);
return FALSE;
}
if (em_irel == irelend)
{
- _bfd_error_handler
- ("%B: warning: R_NDS32_LONGJUMP6 points to unrecognized"
- "reloc at 0x%lx.", abfd, (long) irel->r_offset);
+ _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGJUMP6",
+ (long) irel->r_offset);
return FALSE;
}
R_NDS32_15_PCREL_RELA, irel->r_addend);
if (cond_irel == irelend)
{
- _bfd_error_handler
- ("%B: warning: R_NDS32_LONGJUMP7 points to unrecognized"
- "reloc at 0x%lx.", abfd, (long) irel->r_offset);
+ _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGJUMP7",
+ (long) irel->r_offset);
return FALSE;
}
if (hi_irelfn == irelend)
{
- _bfd_error_handler
- ("%B: warning: R_NDS32_LOADSTORE points to unrecognized"
- "reloc at 0x%lx.", abfd, (long) irel->r_offset);
+ _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LOADSTORE",
+ (long) irel->r_offset);
return FALSE;
}
if (re_irel == irelend)
{
- _bfd_error_handler
- ("%B: warning: R_NDS32_PTR points to unrecognized reloc at 0x%lx.",
- abfd, (long) irel->r_offset);
+ _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_PTR",
+ (long) irel->r_offset);
return FALSE;
}
irelend, isymbuf))
goto error_return;
- if (*again == FALSE)
+ if (!*again)
{
if (!nds32_fag_remove_unused_fpbase (abfd, sec, internal_relocs,
irelend))
nds32_elf_pick_relax (FALSE, sec, again, table, link_info);
- if (*again == FALSE)
+ if (!*again)
{
if (!nds32_relax_adjust_label (abfd, sec, internal_relocs, contents,
&relax_blank_list, optimize, opt_size))
relax_blank_list = NULL;
}
- if (*again == FALSE)
+ if (!*again)
{
/* Closing the section, so we don't relax it anymore. */
bfd_vma sec_size_align;
{
/* Begin of the region. */
if (begin_rel)
+ /* xgettext:c-format */
_bfd_error_handler (_("%B: Nested OMIT_FP in %A."), abfd, sec);
begin_rel = irel;
if (begin_rel == NULL)
{
+ /* xgettext:c-format */
_bfd_error_handler (_("%B: Unmatched OMIT_FP in %A."), abfd, sec);
continue;
}
complete binaries. Do not abort, but issue an error
message instead. */
link_info->callbacks->einfo
+ /* xgettext:c-format */
(_("%X%P: %B(%A): relocation \"%R\" goes out of range\n"),
abfd, input_section, * parent);
goto error_return;
{
int num = 0;
bfd_byte *contents;
- unsigned long insn;
FILE *ex9_import_file;
int update_ex9_table;
struct elf_nds32_link_hash_table *table;
/* Read instructions from the input file and build the list. */
while (!feof (ex9_import_file))
{
+ unsigned long insn;
char *code;
struct elf_nds32_insn_times_entry *ptr;
size_t nread;
break;
insn = bfd_getb32 (contents);
code = bfd_malloc (sizeof (char) * 9);
- snprintf (code, 9, "%08lx", insn);
+ snprintf (code, 9, "%08lx", (insn & 0xffffffff));
ptr = bfd_malloc (sizeof (struct elf_nds32_insn_times_entry));
ptr->string = code;
ptr->order = num;
{
/* Incorrect alignment. */
_bfd_error_handler
- (_("%s: warning: unaligned small data access. "
+ /* xgettext:c-format */
+ (_("%B: warning: unaligned small data access. "
"For entry: {%d, %d, %d}, addr = 0x%x, align = 0x%x."),
- bfd_get_filename (abfd), irel->r_offset,
+ abfd, irel->r_offset,
irel->r_info, irel->r_addend, relocation, align);
off += 4;
continue;
#define elf_backend_may_use_rel_p 1
#define elf_backend_default_use_rela_p 1
#define elf_backend_may_use_rela_p 1
+#define elf_backend_dtrel_excludes_plt 1
#include "elf32-target.h"