|
|
f725e3 |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
f725e3 |
From: Vladimir Serbinenko <phcoder@gmail.com>
|
|
|
f725e3 |
Date: Fri, 22 Jan 2016 19:09:37 +0100
|
|
|
f725e3 |
Subject: [PATCH] arm64: Add support for relocations needed for linaro gcc
|
|
|
f725e3 |
|
|
|
f725e3 |
---
|
|
|
f725e3 |
grub-core/kern/arm64/dl.c | 18 ++++++++++++++++++
|
|
|
f725e3 |
grub-core/kern/arm64/dl_helper.c | 40 ++++++++++++++++++++++++++++++++++++++++
|
|
|
f725e3 |
util/grub-mkimagexx.c | 31 +++++++++++++++++++++++++++++++
|
|
|
f725e3 |
util/grub-module-verifier.c | 8 +++++++-
|
|
|
f725e3 |
include/grub/arm64/reloc.h | 8 ++++++++
|
|
|
f725e3 |
include/grub/elf.h | 3 +++
|
|
|
f725e3 |
6 files changed, 107 insertions(+), 1 deletion(-)
|
|
|
f725e3 |
|
|
|
f725e3 |
diff --git a/grub-core/kern/arm64/dl.c b/grub-core/kern/arm64/dl.c
|
|
|
f725e3 |
index e19ba6a0d58..cf50d7250d9 100644
|
|
|
f725e3 |
--- a/grub-core/kern/arm64/dl.c
|
|
|
f725e3 |
+++ b/grub-core/kern/arm64/dl.c
|
|
|
f725e3 |
@@ -132,6 +132,12 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
|
|
|
f725e3 |
*abs_place = (grub_uint64_t) sym_addr;
|
|
|
f725e3 |
}
|
|
|
f725e3 |
break;
|
|
|
f725e3 |
+ case R_AARCH64_ADD_ABS_LO12_NC:
|
|
|
f725e3 |
+ grub_arm64_set_abs_lo12 (place, sym_addr);
|
|
|
f725e3 |
+ break;
|
|
|
f725e3 |
+ case R_AARCH64_LDST64_ABS_LO12_NC:
|
|
|
f725e3 |
+ grub_arm64_set_abs_lo12_ldst64 (place, sym_addr);
|
|
|
f725e3 |
+ break;
|
|
|
f725e3 |
case R_AARCH64_CALL26:
|
|
|
f725e3 |
case R_AARCH64_JUMP26:
|
|
|
f725e3 |
{
|
|
|
f725e3 |
@@ -154,6 +160,18 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
|
|
|
f725e3 |
grub_arm64_set_xxxx26_offset (place, offset);
|
|
|
f725e3 |
}
|
|
|
f725e3 |
break;
|
|
|
f725e3 |
+ case R_AARCH64_ADR_PREL_PG_HI21:
|
|
|
f725e3 |
+ {
|
|
|
f725e3 |
+ grub_int64_t offset = (sym_addr & ~0xfffULL) - (((grub_uint64_t) place) & ~0xfffULL);
|
|
|
f725e3 |
+
|
|
|
f725e3 |
+ if (!grub_arm64_check_hi21_signed (offset))
|
|
|
f725e3 |
+ return grub_error (GRUB_ERR_BAD_MODULE,
|
|
|
f725e3 |
+ "HI21 out of range");
|
|
|
f725e3 |
+
|
|
|
f725e3 |
+ grub_arm64_set_hi21 (place, offset);
|
|
|
f725e3 |
+ }
|
|
|
f725e3 |
+ break;
|
|
|
f725e3 |
+
|
|
|
f725e3 |
default:
|
|
|
f725e3 |
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
|
|
f725e3 |
N_("relocation 0x%x is not implemented yet"),
|
|
|
f725e3 |
diff --git a/grub-core/kern/arm64/dl_helper.c b/grub-core/kern/arm64/dl_helper.c
|
|
|
f725e3 |
index d213ab93e88..f031b1ae921 100644
|
|
|
f725e3 |
--- a/grub-core/kern/arm64/dl_helper.c
|
|
|
f725e3 |
+++ b/grub-core/kern/arm64/dl_helper.c
|
|
|
f725e3 |
@@ -53,3 +53,43 @@ grub_arm64_set_xxxx26_offset (grub_uint32_t *place, grub_int64_t offset)
|
|
|
f725e3 |
*place &= insmask;
|
|
|
f725e3 |
*place |= grub_cpu_to_le32 (offset >> 2) & ~insmask;
|
|
|
f725e3 |
}
|
|
|
f725e3 |
+
|
|
|
f725e3 |
+int
|
|
|
f725e3 |
+grub_arm64_check_hi21_signed (grub_int64_t offset)
|
|
|
f725e3 |
+{
|
|
|
f725e3 |
+ if (offset != (grub_int64_t)(grub_int32_t)offset)
|
|
|
f725e3 |
+ return 0;
|
|
|
f725e3 |
+ return 1;
|
|
|
f725e3 |
+}
|
|
|
f725e3 |
+
|
|
|
f725e3 |
+void
|
|
|
f725e3 |
+grub_arm64_set_hi21 (grub_uint32_t *place, grub_int64_t offset)
|
|
|
f725e3 |
+{
|
|
|
f725e3 |
+ const grub_uint32_t insmask = grub_cpu_to_le32_compile_time (0x9f00001f);
|
|
|
f725e3 |
+ grub_uint32_t val;
|
|
|
f725e3 |
+
|
|
|
f725e3 |
+ offset >>= 12;
|
|
|
f725e3 |
+
|
|
|
f725e3 |
+ val = ((offset & 3) << 29) | (((offset >> 2) & 0x7ffff) << 5);
|
|
|
f725e3 |
+
|
|
|
f725e3 |
+ *place &= insmask;
|
|
|
f725e3 |
+ *place |= grub_cpu_to_le32 (val) & ~insmask;
|
|
|
f725e3 |
+}
|
|
|
f725e3 |
+
|
|
|
f725e3 |
+void
|
|
|
f725e3 |
+grub_arm64_set_abs_lo12 (grub_uint32_t *place, grub_int64_t target)
|
|
|
f725e3 |
+{
|
|
|
f725e3 |
+ const grub_uint32_t insmask = grub_cpu_to_le32_compile_time (0xffc003ff);
|
|
|
f725e3 |
+
|
|
|
f725e3 |
+ *place &= insmask;
|
|
|
f725e3 |
+ *place |= grub_cpu_to_le32 (target << 10) & ~insmask;
|
|
|
f725e3 |
+}
|
|
|
f725e3 |
+
|
|
|
f725e3 |
+void
|
|
|
f725e3 |
+grub_arm64_set_abs_lo12_ldst64 (grub_uint32_t *place, grub_int64_t target)
|
|
|
f725e3 |
+{
|
|
|
f725e3 |
+ const grub_uint32_t insmask = grub_cpu_to_le32_compile_time (0xfff803ff);
|
|
|
f725e3 |
+
|
|
|
f725e3 |
+ *place &= insmask;
|
|
|
f725e3 |
+ *place |= grub_cpu_to_le32 (target << 7) & ~insmask;
|
|
|
f725e3 |
+}
|
|
|
f725e3 |
diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c
|
|
|
f725e3 |
index 66e8576411e..d1bc95e350d 100644
|
|
|
f725e3 |
--- a/util/grub-mkimagexx.c
|
|
|
f725e3 |
+++ b/util/grub-mkimagexx.c
|
|
|
f725e3 |
@@ -836,6 +836,14 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections,
|
|
|
f725e3 |
*target = grub_host_to_target64 (grub_target_to_host64 (*target) + sym_addr);
|
|
|
f725e3 |
}
|
|
|
f725e3 |
break;
|
|
|
f725e3 |
+ case R_AARCH64_ADD_ABS_LO12_NC:
|
|
|
f725e3 |
+ grub_arm64_set_abs_lo12 ((grub_uint32_t *) target,
|
|
|
f725e3 |
+ sym_addr);
|
|
|
f725e3 |
+ break;
|
|
|
f725e3 |
+ case R_AARCH64_LDST64_ABS_LO12_NC:
|
|
|
f725e3 |
+ grub_arm64_set_abs_lo12_ldst64 ((grub_uint32_t *) target,
|
|
|
f725e3 |
+ sym_addr);
|
|
|
f725e3 |
+ break;
|
|
|
f725e3 |
case R_AARCH64_JUMP26:
|
|
|
f725e3 |
case R_AARCH64_CALL26:
|
|
|
f725e3 |
{
|
|
|
f725e3 |
@@ -848,6 +856,17 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections,
|
|
|
f725e3 |
sym_addr);
|
|
|
f725e3 |
}
|
|
|
f725e3 |
break;
|
|
|
f725e3 |
+ case R_AARCH64_ADR_PREL_PG_HI21:
|
|
|
f725e3 |
+ {
|
|
|
f725e3 |
+ sym_addr &= ~0xfffULL;
|
|
|
f725e3 |
+ sym_addr -= (offset + SUFFIX (entry_point)) & ~0xfffULL;
|
|
|
f725e3 |
+ if (!grub_arm64_check_hi21_signed (sym_addr))
|
|
|
f725e3 |
+ grub_util_error ("%s", "CALL26 Relocation out of range");
|
|
|
f725e3 |
+
|
|
|
f725e3 |
+ grub_arm64_set_hi21((grub_uint32_t *)target,
|
|
|
f725e3 |
+ sym_addr);
|
|
|
f725e3 |
+ }
|
|
|
f725e3 |
+ break;
|
|
|
f725e3 |
default:
|
|
|
f725e3 |
grub_util_error (_("relocation 0x%x is not implemented yet"),
|
|
|
f725e3 |
(unsigned int) ELF_R_TYPE (info));
|
|
|
f725e3 |
@@ -1200,6 +1219,15 @@ SUFFIX (make_reloc_section) (Elf_Ehdr *e, void **out,
|
|
|
f725e3 |
case R_AARCH64_CALL26:
|
|
|
f725e3 |
case R_AARCH64_JUMP26:
|
|
|
f725e3 |
break;
|
|
|
f725e3 |
+ /* Page-relative relocations do not require fixup entries. */
|
|
|
f725e3 |
+ case R_AARCH64_ADR_PREL_PG_HI21:
|
|
|
f725e3 |
+ /* We page-align the whole kernel, so no need
|
|
|
f725e3 |
+ for fixup entries.
|
|
|
f725e3 |
+ */
|
|
|
f725e3 |
+ case R_AARCH64_ADD_ABS_LO12_NC:
|
|
|
f725e3 |
+ case R_AARCH64_LDST64_ABS_LO12_NC:
|
|
|
f725e3 |
+ break;
|
|
|
f725e3 |
+
|
|
|
f725e3 |
default:
|
|
|
f725e3 |
grub_util_error (_("relocation 0x%x is not implemented yet"),
|
|
|
f725e3 |
(unsigned int) ELF_R_TYPE (info));
|
|
|
f725e3 |
@@ -1343,6 +1371,9 @@ SUFFIX (locate_sections) (const char *kernel_path,
|
|
|
f725e3 |
Elf_Shdr *s;
|
|
|
f725e3 |
|
|
|
f725e3 |
*all_align = 1;
|
|
|
f725e3 |
+ /* Page-aligning simplifies relocation handling. */
|
|
|
f725e3 |
+ if (image_target->elf_target == EM_AARCH64)
|
|
|
f725e3 |
+ *all_align = 4096;
|
|
|
f725e3 |
|
|
|
f725e3 |
section_addresses = xmalloc (sizeof (*section_addresses) * num_sections);
|
|
|
f725e3 |
memset (section_addresses, 0, sizeof (*section_addresses) * num_sections);
|
|
|
f725e3 |
diff --git a/util/grub-module-verifier.c b/util/grub-module-verifier.c
|
|
|
f725e3 |
index e217dcddc07..405c9117051 100644
|
|
|
f725e3 |
--- a/util/grub-module-verifier.c
|
|
|
f725e3 |
+++ b/util/grub-module-verifier.c
|
|
|
f725e3 |
@@ -107,7 +107,13 @@ struct grub_module_verifier_arch archs[] = {
|
|
|
f725e3 |
R_AARCH64_CALL26,
|
|
|
f725e3 |
R_AARCH64_JUMP26,
|
|
|
f725e3 |
-1
|
|
|
f725e3 |
- } },
|
|
|
f725e3 |
+ }, (int[]){
|
|
|
f725e3 |
+ R_AARCH64_ADR_PREL_PG_HI21,
|
|
|
f725e3 |
+ R_AARCH64_ADD_ABS_LO12_NC,
|
|
|
f725e3 |
+ R_AARCH64_LDST64_ABS_LO12_NC,
|
|
|
f725e3 |
+ -1
|
|
|
f725e3 |
+ }
|
|
|
f725e3 |
+ },
|
|
|
f725e3 |
};
|
|
|
f725e3 |
|
|
|
f725e3 |
|
|
|
f725e3 |
diff --git a/include/grub/arm64/reloc.h b/include/grub/arm64/reloc.h
|
|
|
f725e3 |
index 4aed3d715e0..452c148226d 100644
|
|
|
f725e3 |
--- a/include/grub/arm64/reloc.h
|
|
|
f725e3 |
+++ b/include/grub/arm64/reloc.h
|
|
|
f725e3 |
@@ -22,5 +22,13 @@
|
|
|
f725e3 |
int grub_arm_64_check_xxxx26_offset (grub_int64_t offset);
|
|
|
f725e3 |
void
|
|
|
f725e3 |
grub_arm64_set_xxxx26_offset (grub_uint32_t *place, grub_int64_t offset);
|
|
|
f725e3 |
+int
|
|
|
f725e3 |
+grub_arm64_check_hi21_signed (grub_int64_t offset);
|
|
|
f725e3 |
+void
|
|
|
f725e3 |
+grub_arm64_set_hi21 (grub_uint32_t *place, grub_int64_t offset);
|
|
|
f725e3 |
+void
|
|
|
f725e3 |
+grub_arm64_set_abs_lo12 (grub_uint32_t *place, grub_int64_t target);
|
|
|
f725e3 |
+void
|
|
|
f725e3 |
+grub_arm64_set_abs_lo12_ldst64 (grub_uint32_t *place, grub_int64_t target);
|
|
|
f725e3 |
|
|
|
f725e3 |
#endif
|
|
|
f725e3 |
diff --git a/include/grub/elf.h b/include/grub/elf.h
|
|
|
f725e3 |
index caa79639082..db15acecf9f 100644
|
|
|
f725e3 |
--- a/include/grub/elf.h
|
|
|
f725e3 |
+++ b/include/grub/elf.h
|
|
|
f725e3 |
@@ -2068,6 +2068,9 @@ typedef Elf32_Addr Elf32_Conflict;
|
|
|
f725e3 |
#define R_AARCH64_NONE 0 /* No relocation. */
|
|
|
f725e3 |
#define R_AARCH64_ABS64 257 /* Direct 64 bit. */
|
|
|
f725e3 |
#define R_AARCH64_ABS32 258 /* Direct 32 bit. */
|
|
|
f725e3 |
+#define R_AARCH64_ADR_PREL_PG_HI21 275
|
|
|
f725e3 |
+#define R_AARCH64_ADD_ABS_LO12_NC 277
|
|
|
f725e3 |
+#define R_AARCH64_LDST64_ABS_LO12_NC 286
|
|
|
f725e3 |
#define R_AARCH64_JUMP26 282 /* 26-bit relative. */
|
|
|
f725e3 |
#define R_AARCH64_CALL26 283 /* 26-bit relative. */
|
|
|
f725e3 |
#define R_AARCH64_COPY 1024 /* Copy symbol at runtime. */
|