_rel.r_addend = ADDEND; \
_rel.r_offset = (_htab->s##SECTION)->output_section->vma \
+ (_htab->s##SECTION)->output_offset + OFFSET; \
+ BFD_ASSERT ((long) SYM_IDX != -1); \
_rel.r_info = ELF32_R_INFO (SYM_IDX, TYPE); \
bfd_elf32_swap_reloca_out (BFD, &_rel, _loc); \
}
};
#undef ARC_RELOC_HOWTO
+typedef ATTRIBUTE_UNUSED bfd_vma (*replace_func) (unsigned, int ATTRIBUTE_UNUSED);
+
+#define ARC_RELOC_HOWTO(TYPE, VALUE, SIZE, BITSIZE, RELOC_FUNCTION, OVERFLOW, FORMULA) \
+ case TYPE: \
+ func = (void *) RELOC_FUNCTION; \
+ break;
+static replace_func
+get_replace_function (bfd *abfd, unsigned int r_type)
+{
+ void *func = NULL;
+
+ switch (r_type)
+ {
+ #include "elf/arc-reloc.def"
+ }
+
+ if (func == replace_bits24 && bfd_big_endian (abfd))
+ return (replace_func) replace_bits24_be;
+
+ return (replace_func) func;
+}
+#undef ARC_RELOC_HOWTO
+
static reloc_howto_type *
arc_elf32_bfd_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
bfd_reloc_code_real_type code)
switch (flags & EF_ARC_MACH_MSK)
{
- case EF_ARC_CPU_GENERIC : fprintf (file, " -mcpu=generic"); break;
case EF_ARC_CPU_ARCV2HS : fprintf (file, " -mcpu=ARCv2HS"); break;
case EF_ARC_CPU_ARCV2EM : fprintf (file, " -mcpu=ARCv2EM"); break;
case E_ARC_MACH_ARC600 : fprintf (file, " -mcpu=ARC600"); break;
case E_ARC_MACH_ARC700:
mach = bfd_mach_arc_arc700;
break;
+ case E_ARC_MACH_NPS400:
+ mach = bfd_mach_arc_nps400;
+ break;
case EF_ARC_CPU_ARCV2HS:
case EF_ARC_CPU_ARCV2EM:
mach = bfd_mach_arc_arcv2;
arc_elf_final_write_processing (bfd * abfd,
bfd_boolean linker ATTRIBUTE_UNUSED)
{
- unsigned long val;
unsigned long emf;
switch (bfd_get_mach (abfd))
{
case bfd_mach_arc_arc600:
- val = E_ARC_MACH_ARC600;
emf = EM_ARC_COMPACT;
break;
case bfd_mach_arc_arc601:
- val = E_ARC_MACH_ARC601;
emf = EM_ARC_COMPACT;
break;
case bfd_mach_arc_arc700:
- val = E_ARC_MACH_ARC700;
+ emf = EM_ARC_COMPACT;
+ break;
+ case bfd_mach_arc_nps400:
emf = EM_ARC_COMPACT;
break;
case bfd_mach_arc_arcv2:
- val = EF_ARC_CPU_GENERIC;
emf = EM_ARC_COMPACT2;
- /* TODO: Check validity of this. It can also be ARCV2EM here.
- Previous version sets the e_machine here. */
break;
default:
abort ();
}
- if ((elf_elfheader (abfd)->e_flags & EF_ARC_MACH) == EF_ARC_CPU_GENERIC)
- elf_elfheader (abfd)->e_flags |= val;
elf_elfheader (abfd)->e_machine = emf;
struct arc_relocation_data
{
- bfd_vma reloc_offset;
- bfd_vma reloc_addend;
- bfd_vma got_offset_value;
+ bfd_signed_vma reloc_offset;
+ bfd_signed_vma reloc_addend;
+ bfd_signed_vma got_offset_value;
- bfd_vma sym_value;
+ bfd_signed_vma sym_value;
asection * sym_section;
reloc_howto_type *howto;
asection * input_section;
- bfd_vma sdata_begin_symbol_vma;
+ bfd_signed_vma sdata_begin_symbol_vma;
bfd_boolean sdata_begin_symbol_vma_set;
- bfd_vma got_symbol_vma;
+ bfd_signed_vma got_symbol_vma;
bfd_boolean should_relocate;
};
#define IS_ME(FORMULA,BFD) ((strstr (FORMULA, "ME") != NULL) \
&& (!bfd_big_endian (BFD)))
-#define S (reloc_data.sym_value \
+#define S ((bfd_signed_vma) (reloc_data.sym_value \
+ (reloc_data.sym_section->output_section != NULL ? \
(reloc_data.sym_section->output_offset \
- + reloc_data.sym_section->output_section->vma) : 0) \
- )
-#define L (reloc_data.sym_value \
+ + reloc_data.sym_section->output_section->vma) : 0)))
+#define L ((bfd_signed_vma) (reloc_data.sym_value \
+ (reloc_data.sym_section->output_section != NULL ? \
(reloc_data.sym_section->output_offset \
- + reloc_data.sym_section->output_section->vma) : 0) \
- )
+ + reloc_data.sym_section->output_section->vma) : 0)))
#define A (reloc_data.reloc_addend)
#define B (0)
#define G (reloc_data.got_offset_value)
#define MES (0)
/* P: relative offset to PCL The offset should be to the
current location aligned to 32 bits. */
-#define P ( \
+#define P ((bfd_signed_vma) ( \
( \
(reloc_data.input_section->output_section != NULL ? \
reloc_data.input_section->output_section->vma : 0) \
+ reloc_data.input_section->output_offset \
- + (reloc_data.reloc_offset - (bitsize >= 32 ? 4 : 0)) \
- ) & ~0x3)
-#define PDATA ( \
+ + (reloc_data.reloc_offset - (bitsize >= 32 ? 4 : 0))) \
+ & ~0x3))
+#define PDATA ((bfd_signed_vma) ( \
(reloc_data.input_section->output_section->vma \
+ reloc_data.input_section->output_offset \
- + (reloc_data.reloc_offset) \
- ))
-#define SECTSTAR (reloc_data.input_section->output_offset)
-#define SECTSTART (reloc_data.input_section->output_offset)
-#define _SDA_BASE_ (reloc_data.sdata_begin_symbol_vma)
-#define TLS_REL ((elf_hash_table (info))->tls_sec->output_section->vma)
-#define _SDA_BASE_ (reloc_data.sdata_begin_symbol_vma)
+ + (reloc_data.reloc_offset))))
+#define SECTSTART (bfd_signed_vma) (reloc_data.input_section->output_offset)
+#define _SDA_BASE_ (bfd_signed_vma) (reloc_data.sdata_begin_symbol_vma)
+#define TLS_REL (bfd_signed_vma) \
+ ((elf_hash_table (info))->tls_sec->output_section->vma)
#define TLS_TBSS (8)
#define TCB_SIZE (8)
#define none (0)
-#define PRINT_DEBUG_RELOC_INFO_BEFORE(FORMULA) \
+#define PRINT_DEBUG_RELOC_INFO_BEFORE(FORMULA, TYPE) \
{\
asection *sym_section = reloc_data.sym_section; \
asection *input_section = reloc_data.input_section; \
- ARC_DEBUG ("FORMULA = " #FORMULA "\n"); \
+ ARC_DEBUG ("RELOC_TYPE = " TYPE "\n"); \
+ ARC_DEBUG ("FORMULA = " FORMULA "\n"); \
ARC_DEBUG ("S = 0x%x\n", S); \
ARC_DEBUG ("A = 0x%x\n", A); \
ARC_DEBUG ("L = 0x%x\n", L); \
#define ARC_RELOC_HOWTO(TYPE, VALUE, SIZE, BITSIZE, RELOC_FUNCTION, OVERFLOW, FORMULA) \
case R_##TYPE: \
{ \
- bfd_vma bitsize ATTRIBUTE_UNUSED = BITSIZE; \
+ bfd_signed_vma bitsize ATTRIBUTE_UNUSED = BITSIZE; \
relocation = FORMULA ; \
- PRINT_DEBUG_RELOC_INFO_BEFORE(FORMULA) \
+ PRINT_DEBUG_RELOC_INFO_BEFORE (#FORMULA, #TYPE); \
insn = middle_endian_convert (insn, IS_ME (#FORMULA, abfd)); \
- insn = RELOC_FUNCTION (insn, relocation); \
+ insn = (* get_replace_function (abfd, TYPE)) (insn, relocation); \
insn = middle_endian_convert (insn, IS_ME (#FORMULA, abfd)); \
PRINT_DEBUG_RELOC_INFO_AFTER \
} \
struct arc_relocation_data reloc_data,
struct bfd_link_info *info)
{
- bfd_vma relocation = 0;
+ bfd_signed_vma relocation = 0;
bfd_vma insn;
bfd_vma orig_insn ATTRIBUTE_UNUSED;
bfd * abfd = reloc_data.input_section->owner;
else if (r_type == R_ARC_PC32
|| r_type == R_ARC_32_PCREL)
{
- BFD_ASSERT (h != NULL && h->dynindx != -1);
+ BFD_ASSERT (h != NULL);
if ((input_section->flags & SEC_ALLOC) != 0)
relocate = FALSE;
else
relocate = TRUE;
+
+ BFD_ASSERT (h->dynindx != -1);
outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
}
else
relocate = FALSE;
else
relocate = TRUE;
+
+ BFD_ASSERT (h->dynindx != -1);
outrel.r_info = ELF32_R_INFO (h->dynindx, R_ARC_32);
}
}
non-readonly sections. */
if (bfd_link_dll (info) && !bfd_link_pie (info)
&& (sec->flags & SEC_ALLOC) != 0
- && (sec->flags & SEC_READONLY) != 0)
+ && (sec->flags & SEC_READONLY) == 0
+ && (sec->flags & SEC_CODE) != 0)
{
const char *name;
if (h)
/* TODO: being ME is not a property of the relocation but of the
section of which is applying the relocation. */
- if (IS_MIDDLE_ENDIAN (reloc->symbol) || bfd_big_endian (abfd))
+ if (IS_MIDDLE_ENDIAN (reloc->symbol) && !bfd_big_endian (abfd))
{
relocation =
((relocation & 0xffff0000) >> 16) |
+ got_offset,
h->root.root.string);
- memcpy (htab->splt->contents + h->plt.offset,
- plt_data->elem,
- plt_data->elem_size);
+
+ {
+ bfd_vma i = 0;
+ uint16_t *ptr = (uint16_t *) plt_data->elem;
+ for (i = 0; i < plt_data->elem_size/2; i++)
+ {
+ uint16_t data = ptr[i];
+ bfd_put_16 (output_bfd,
+ (bfd_vma) data,
+ htab->splt->contents + h->plt.offset + (i*2));
+ }
+ }
+
plt_do_relocs_for_symbol (output_bfd, htab,
plt_data->elem_relocs,
h->plt.offset,
+ htab->sgotplt->output_offset
+ got_offset);
rel.r_addend = 0;
+
+ BFD_ASSERT (h->dynindx != -1);
rel.r_info = ELF32_R_INFO (h->dynindx, R_ARC_JMP_SLOT);
loc = htab->srelplt->contents;
struct plt_version_t *plt_data = arc_get_plt_version (info);
struct elf_link_hash_table *htab = elf_hash_table (info);
- memcpy (htab->splt->contents, plt_data->entry,
- plt_data->entry_size);
+ {
+ bfd_vma i = 0;
+ uint16_t *ptr = (uint16_t *) plt_data->entry;
+ for (i = 0; i < plt_data->entry_size/2; i++)
+ {
+ uint16_t data = ptr[i];
+ bfd_put_16 (abfd,
+ (bfd_vma) data,
+ htab->splt->contents + (i*2));
+ }
+ }
PLT_DO_RELOCS_FOR_ENTRY (abfd, htab, plt_data->entry_relocs);
}
{
ADD_RELA (output_bfd, got, got_offset, 0, R_ARC_RELATIVE, 0);
}
- else
+ /* Do not fully understand the side effects of this condition.
+ The relocation space might still being reserved. Perhaps
+ I should clear its value. */
+ else if (h->dynindx != -1)
{
ADD_RELA (output_bfd, got, got_offset, h->dynindx,
R_ARC_GLOB_DAT, 0);
Elf_Internal_Rela rel;
rel.r_addend = 0;
rel.r_offset = rel_offset;
+
+ BFD_ASSERT (h->dynindx != -1);
rel.r_info = ELF32_R_INFO (h->dynindx, R_ARC_COPY);
bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);