aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bfd/coff-aarch64.c47
-rw-r--r--gas/config/tc-aarch64.c75
-rw-r--r--gas/config/tc-aarch64.h4
-rw-r--r--ld/testsuite/ld-pe/pe.exp2
4 files changed, 108 insertions, 20 deletions
diff --git a/bfd/coff-aarch64.c b/bfd/coff-aarch64.c
index d6c48eb..8e9081a 100644
--- a/bfd/coff-aarch64.c
+++ b/bfd/coff-aarch64.c
@@ -267,6 +267,20 @@ coff_aarch64_addr32nb_reloc (bfd *abfd ATTRIBUTE_UNUSED,
return bfd_reloc_ok;
}
+static bfd_reloc_status_type
+coff_aarch64_secrel_reloc (bfd *abfd ATTRIBUTE_UNUSED,
+ arelent *reloc_entry,
+ asymbol *symbol ATTRIBUTE_UNUSED,
+ void *data,
+ asection *input_section ATTRIBUTE_UNUSED,
+ bfd *output_bfd ATTRIBUTE_UNUSED,
+ char **error_message ATTRIBUTE_UNUSED)
+{
+ bfd_putl32 (reloc_entry->addend, data + reloc_entry->address);
+
+ return bfd_reloc_ok;
+}
+
/* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
#define MINUS_ONE (~ (bfd_vma) 0)
@@ -330,6 +344,11 @@ static const reloc_howto_type arm64_reloc_howto_32nb = HOWTO (IMAGE_REL_ARM64_AD
coff_aarch64_addr32nb_reloc, "IMAGE_REL_ARM64_ADDR32NB",
false, 0xffffffff, 0xffffffff, false);
+static const reloc_howto_type arm64_reloc_howto_secrel = HOWTO (IMAGE_REL_ARM64_SECREL, 0, 4, 32, false, 0,
+ complain_overflow_bitfield,
+ coff_aarch64_secrel_reloc, "IMAGE_REL_ARM64_SECREL",
+ false, 0xffffffff, 0xffffffff, false);
+
static const reloc_howto_type* const arm64_howto_table[] = {
&arm64_reloc_howto_abs,
&arm64_reloc_howto_64,
@@ -342,7 +361,8 @@ static const reloc_howto_type* const arm64_howto_table[] = {
&arm64_reloc_howto_branch19,
&arm64_reloc_howto_branch14,
&arm64_reloc_howto_pgoff12a,
- &arm64_reloc_howto_32nb
+ &arm64_reloc_howto_32nb,
+ &arm64_reloc_howto_secrel
};
#ifndef NUM_ELEM
@@ -387,6 +407,8 @@ coff_aarch64_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED, bfd_reloc_code_real
return &arm64_reloc_howto_branch19;
case BFD_RELOC_RVA:
return &arm64_reloc_howto_32nb;
+ case BFD_RELOC_32_SECREL:
+ return &arm64_reloc_howto_secrel;
default:
BFD_FAIL ();
return NULL;
@@ -441,6 +463,8 @@ coff_aarch64_rtype_lookup (unsigned int code)
return &arm64_reloc_howto_pgoff12a;
case IMAGE_REL_ARM64_ADDR32NB:
return &arm64_reloc_howto_32nb;
+ case IMAGE_REL_ARM64_SECREL:
+ return &arm64_reloc_howto_secrel;
default:
BFD_FAIL ();
return NULL;
@@ -811,6 +835,27 @@ coff_pe_aarch64_relocate_section (bfd *output_bfd,
break;
}
+ case IMAGE_REL_ARM64_SECREL:
+ {
+ uint64_t val;
+ int32_t addend;
+
+ addend = bfd_getl32 (contents + rel->r_vaddr);
+
+ val = sec->output_offset + sym_value + addend;
+
+ if (val > 0xffffffff)
+ (*info->callbacks->reloc_overflow)
+ (info, h ? &h->root : NULL, syms[symndx]._n._n_name,
+ "IMAGE_REL_ARM64_SECREL", addend, input_bfd,
+ input_section, rel->r_vaddr - input_section->vma);
+
+ bfd_putl32 (val, contents + rel->r_vaddr);
+ rel->r_type = IMAGE_REL_ARM64_ABSOLUTE;
+
+ break;
+ }
+
default:
info->callbacks->einfo (_("%F%P: Unhandled relocation type %u\n"),
rel->r_type);
diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c
index 25e7943..ad070cd 100644
--- a/gas/config/tc-aarch64.c
+++ b/gas/config/tc-aarch64.c
@@ -2097,6 +2097,27 @@ s_tlsdescldr (int ignored ATTRIBUTE_UNUSED)
}
#endif /* OBJ_ELF */
+#ifdef TE_PE
+static void
+s_secrel (int dummy ATTRIBUTE_UNUSED)
+{
+ expressionS exp;
+
+ do
+ {
+ expression (&exp);
+ if (exp.X_op == O_symbol)
+ exp.X_op = O_secrel;
+
+ emit_expr (&exp, 4);
+ }
+ while (*input_line_pointer++ == ',');
+
+ input_line_pointer--;
+ demand_empty_rest_of_line ();
+}
+#endif /* TE_PE */
+
static void s_aarch64_arch (int);
static void s_aarch64_cpu (int);
static void s_aarch64_arch_extension (int);
@@ -2132,6 +2153,9 @@ const pseudo_typeS md_pseudo_table[] = {
{"xword", s_aarch64_cons, 8},
{"dword", s_aarch64_cons, 8},
#endif
+#ifdef TE_PE
+ {"secrel32", s_secrel, 0},
+#endif
{"float16", float_cons, 'h'},
{"bfloat16", float_cons, 'b'},
{0, 0, 0}
@@ -9268,6 +9292,7 @@ md_apply_fix (fixS * fixP, valueT * valP, segT seg)
break;
case BFD_RELOC_RVA:
+ case BFD_RELOC_32_SECREL:
break;
default:
@@ -9353,27 +9378,39 @@ cons_fix_new_aarch64 (fragS * frag, int where, int size, expressionS * exp)
bfd_reloc_code_real_type type;
int pcrel = 0;
- /* Pick a reloc.
- FIXME: @@ Should look at CPU word size. */
- switch (size)
+#ifdef TE_PE
+ if (exp->X_op == O_secrel)
{
- case 1:
- type = BFD_RELOC_8;
- break;
- case 2:
- type = BFD_RELOC_16;
- break;
- case 4:
- type = BFD_RELOC_32;
- break;
- case 8:
- type = BFD_RELOC_64;
- break;
- default:
- as_bad (_("cannot do %u-byte relocation"), size);
- type = BFD_RELOC_UNUSED;
- break;
+ exp->X_op = O_symbol;
+ type = BFD_RELOC_32_SECREL;
}
+ else
+ {
+#endif
+ /* Pick a reloc.
+ FIXME: @@ Should look at CPU word size. */
+ switch (size)
+ {
+ case 1:
+ type = BFD_RELOC_8;
+ break;
+ case 2:
+ type = BFD_RELOC_16;
+ break;
+ case 4:
+ type = BFD_RELOC_32;
+ break;
+ case 8:
+ type = BFD_RELOC_64;
+ break;
+ default:
+ as_bad (_("cannot do %u-byte relocation"), size);
+ type = BFD_RELOC_UNUSED;
+ break;
+ }
+#ifdef TE_PE
+ }
+#endif
fix_new_exp (frag, where, (int) size, exp, pcrel, type);
}
diff --git a/gas/config/tc-aarch64.h b/gas/config/tc-aarch64.h
index d7d782c..fa4b3ac 100644
--- a/gas/config/tc-aarch64.h
+++ b/gas/config/tc-aarch64.h
@@ -314,4 +314,8 @@ extern void aarch64_handle_align (struct frag *);
extern int tc_aarch64_regname_to_dw2regnum (char *regname);
extern void tc_aarch64_frame_initial_instructions (void);
+#ifdef TE_PE
+#define O_secrel O_md1
+#endif /* TE_PE */
+
#endif /* TC_AARCH64 */
diff --git a/ld/testsuite/ld-pe/pe.exp b/ld/testsuite/ld-pe/pe.exp
index c22c6d4..dae8c34 100644
--- a/ld/testsuite/ld-pe/pe.exp
+++ b/ld/testsuite/ld-pe/pe.exp
@@ -84,6 +84,8 @@ if {[istarget "aarch64-*-pe*"]} {
set pe_tests {
{"aarch64" "--image-base 0x1000" "" "" {aarch64a.s aarch64b.s}
{{objdump -dr aarch64.d}} "aarch64.x"}
+ {".secrel32" "--disable-reloc-section" "" "" {secrel1.s secrel2.s}
+ {{objdump -s secrel_64.d}} "secrel.x"}
}
run_ld_link_tests $pe_tests