diff -Nru grub2-2.02~beta2/debian/changelog grub2-2.02~beta2/debian/changelog --- grub2-2.02~beta2/debian/changelog 2021-02-24 19:59:33.000000000 +0000 +++ grub2-2.02~beta2/debian/changelog 2021-04-30 12:33:21.000000000 +0000 @@ -1,3 +1,13 @@ +grub2 (2.02~beta2-36ubuntu3.32) xenial; urgency=medium + + * Cherrypick upstream commit to add support for + R_AARCH64_ADR_PREL_PG_HI21, R_AARCH64_ADD_ABS_LO12_NC, + R_AARCH64_LDST64_ABS_LO12_NC relocations in grub-install / mkimage to + allow generating and installing grub.efi from one-grub modules. LP: + #1926748 + + -- Dimitri John Ledkov Fri, 30 Apr 2021 13:33:21 +0100 + grub2 (2.02~beta2-36ubuntu3.31) xenial; urgency=medium [ Dimitri John Ledkov & Steve Langasek ] diff -Nru grub2-2.02~beta2/debian/patches/arm64-Add-support-for-relocations-needed-for-linaro-gcc.patch grub2-2.02~beta2/debian/patches/arm64-Add-support-for-relocations-needed-for-linaro-gcc.patch --- grub2-2.02~beta2/debian/patches/arm64-Add-support-for-relocations-needed-for-linaro-gcc.patch 1970-01-01 00:00:00.000000000 +0000 +++ grub2-2.02~beta2/debian/patches/arm64-Add-support-for-relocations-needed-for-linaro-gcc.patch 2021-04-30 12:33:17.000000000 +0000 @@ -0,0 +1,193 @@ +From 605eecc985b677d196b558d4d8cec6592a68e462 Mon Sep 17 00:00:00 2001 +From: Vladimir Serbinenko +Date: Fri, 22 Jan 2016 19:09:37 +0100 +Subject: [PATCH] arm64: Add support for relocations needed for linaro gcc + +--- + grub-core/kern/arm64/dl.c | 18 ++++++++++++++ + grub-core/kern/arm64/dl_helper.c | 40 ++++++++++++++++++++++++++++++++ + include/grub/arm64/reloc.h | 8 +++++++ + include/grub/elf.h | 3 +++ + util/grub-mkimagexx.c | 31 +++++++++++++++++++++++++ + util/grub-module-verifier.c | 8 ++++++- + 6 files changed, 107 insertions(+), 1 deletion(-) + +Index: grub2-2.02~beta2/grub-core/kern/arm64/dl.c +=================================================================== +--- grub2-2.02~beta2.orig/grub-core/kern/arm64/dl.c ++++ grub2-2.02~beta2/grub-core/kern/arm64/dl.c +@@ -132,6 +132,12 @@ grub_arch_dl_relocate_symbols (grub_dl_t + *abs_place = (grub_uint64_t) sym_addr; + } + break; ++ case R_AARCH64_ADD_ABS_LO12_NC: ++ grub_arm64_set_abs_lo12 (place, sym_addr); ++ break; ++ case R_AARCH64_LDST64_ABS_LO12_NC: ++ grub_arm64_set_abs_lo12_ldst64 (place, sym_addr); ++ break; + case R_AARCH64_CALL26: + case R_AARCH64_JUMP26: + { +@@ -154,6 +160,18 @@ grub_arch_dl_relocate_symbols (grub_dl_t + grub_arm64_set_xxxx26_offset (place, offset); + } + break; ++ case R_AARCH64_ADR_PREL_PG_HI21: ++ { ++ grub_int64_t offset = (sym_addr & ~0xfffULL) - (((grub_uint64_t) place) & ~0xfffULL); ++ ++ if (!grub_arm64_check_hi21_signed (offset)) ++ return grub_error (GRUB_ERR_BAD_MODULE, ++ "HI21 out of range"); ++ ++ grub_arm64_set_hi21 (place, offset); ++ } ++ break; ++ + default: + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, + N_("relocation 0x%x is not implemented yet"), +Index: grub2-2.02~beta2/grub-core/kern/arm64/dl_helper.c +=================================================================== +--- grub2-2.02~beta2.orig/grub-core/kern/arm64/dl_helper.c ++++ grub2-2.02~beta2/grub-core/kern/arm64/dl_helper.c +@@ -53,3 +53,43 @@ grub_arm64_set_xxxx26_offset (grub_uint3 + *place &= insmask; + *place |= grub_cpu_to_le32 (offset >> 2) & ~insmask; + } ++ ++int ++grub_arm64_check_hi21_signed (grub_int64_t offset) ++{ ++ if (offset != (grub_int64_t)(grub_int32_t)offset) ++ return 0; ++ return 1; ++} ++ ++void ++grub_arm64_set_hi21 (grub_uint32_t *place, grub_int64_t offset) ++{ ++ const grub_uint32_t insmask = grub_cpu_to_le32_compile_time (0x9f00001f); ++ grub_uint32_t val; ++ ++ offset >>= 12; ++ ++ val = ((offset & 3) << 29) | (((offset >> 2) & 0x7ffff) << 5); ++ ++ *place &= insmask; ++ *place |= grub_cpu_to_le32 (val) & ~insmask; ++} ++ ++void ++grub_arm64_set_abs_lo12 (grub_uint32_t *place, grub_int64_t target) ++{ ++ const grub_uint32_t insmask = grub_cpu_to_le32_compile_time (0xffc003ff); ++ ++ *place &= insmask; ++ *place |= grub_cpu_to_le32 (target << 10) & ~insmask; ++} ++ ++void ++grub_arm64_set_abs_lo12_ldst64 (grub_uint32_t *place, grub_int64_t target) ++{ ++ const grub_uint32_t insmask = grub_cpu_to_le32_compile_time (0xfff803ff); ++ ++ *place &= insmask; ++ *place |= grub_cpu_to_le32 (target << 7) & ~insmask; ++} +Index: grub2-2.02~beta2/include/grub/arm64/reloc.h +=================================================================== +--- grub2-2.02~beta2.orig/include/grub/arm64/reloc.h ++++ grub2-2.02~beta2/include/grub/arm64/reloc.h +@@ -22,5 +22,13 @@ + int grub_arm_64_check_xxxx26_offset (grub_int64_t offset); + void + grub_arm64_set_xxxx26_offset (grub_uint32_t *place, grub_int64_t offset); ++int ++grub_arm64_check_hi21_signed (grub_int64_t offset); ++void ++grub_arm64_set_hi21 (grub_uint32_t *place, grub_int64_t offset); ++void ++grub_arm64_set_abs_lo12 (grub_uint32_t *place, grub_int64_t target); ++void ++grub_arm64_set_abs_lo12_ldst64 (grub_uint32_t *place, grub_int64_t target); + + #endif +Index: grub2-2.02~beta2/include/grub/elf.h +=================================================================== +--- grub2-2.02~beta2.orig/include/grub/elf.h ++++ grub2-2.02~beta2/include/grub/elf.h +@@ -2075,6 +2075,9 @@ typedef Elf32_Addr Elf32_Conflict; + #define R_AARCH64_NONE 0 /* No relocation. */ + #define R_AARCH64_ABS64 257 /* Direct 64 bit. */ + #define R_AARCH64_ABS32 258 /* Direct 32 bit. */ ++#define R_AARCH64_ADR_PREL_PG_HI21 275 ++#define R_AARCH64_ADD_ABS_LO12_NC 277 ++#define R_AARCH64_LDST64_ABS_LO12_NC 286 + #define R_AARCH64_JUMP26 282 /* 26-bit relative. */ + #define R_AARCH64_CALL26 283 /* 26-bit relative. */ + #define R_AARCH64_COPY 1024 /* Copy symbol at runtime. */ +Index: grub2-2.02~beta2/util/grub-mkimagexx.c +=================================================================== +--- grub2-2.02~beta2.orig/util/grub-mkimagexx.c ++++ grub2-2.02~beta2/util/grub-mkimagexx.c +@@ -837,6 +837,14 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e + *target = grub_host_to_target64 (grub_target_to_host64 (*target) + sym_addr); + } + break; ++ case R_AARCH64_ADD_ABS_LO12_NC: ++ grub_arm64_set_abs_lo12 ((grub_uint32_t *) target, ++ sym_addr); ++ break; ++ case R_AARCH64_LDST64_ABS_LO12_NC: ++ grub_arm64_set_abs_lo12_ldst64 ((grub_uint32_t *) target, ++ sym_addr); ++ break; + case R_AARCH64_JUMP26: + case R_AARCH64_CALL26: + { +@@ -849,6 +857,17 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e + sym_addr); + } + break; ++ case R_AARCH64_ADR_PREL_PG_HI21: ++ { ++ sym_addr &= ~0xfffULL; ++ sym_addr -= (offset + SUFFIX (entry_point)) & ~0xfffULL; ++ if (!grub_arm64_check_hi21_signed (sym_addr)) ++ grub_util_error ("%s", "CALL26 Relocation out of range"); ++ ++ grub_arm64_set_hi21((grub_uint32_t *)target, ++ sym_addr); ++ } ++ break; + default: + grub_util_error (_("relocation 0x%x is not implemented yet"), + (unsigned int) ELF_R_TYPE (info)); +@@ -1201,6 +1220,15 @@ SUFFIX (make_reloc_section) (Elf_Ehdr *e + case R_AARCH64_CALL26: + case R_AARCH64_JUMP26: + break; ++ /* Page-relative relocations do not require fixup entries. */ ++ case R_AARCH64_ADR_PREL_PG_HI21: ++ /* We page-align the whole kernel, so no need ++ for fixup entries. ++ */ ++ case R_AARCH64_ADD_ABS_LO12_NC: ++ case R_AARCH64_LDST64_ABS_LO12_NC: ++ break; ++ + default: + grub_util_error (_("relocation 0x%x is not implemented yet"), + (unsigned int) ELF_R_TYPE (info)); +@@ -1344,6 +1372,9 @@ SUFFIX (locate_sections) (const char *ke + Elf_Shdr *s; + + *all_align = 1; ++ /* Page-aligning simplifies relocation handling. */ ++ if (image_target->elf_target == EM_AARCH64) ++ *all_align = 4096; + + section_addresses = xcalloc (num_sections, sizeof (*section_addresses)); + memset (section_addresses, 0, sizeof (*section_addresses) * num_sections); diff -Nru grub2-2.02~beta2/debian/patches/series grub2-2.02~beta2/debian/patches/series --- grub2-2.02~beta2/debian/patches/series 2021-02-24 19:59:33.000000000 +0000 +++ grub2-2.02~beta2/debian/patches/series 2021-04-30 12:33:17.000000000 +0000 @@ -168,3 +168,4 @@ ubuntu-linuxefi-arm64-set-base-addr.patch tftp-rollover-block-counter.patch R_X86_64_PLT32.patch +arm64-Add-support-for-relocations-needed-for-linaro-gcc.patch