On Thu, May 25, 2023 at 09:05:20PM +0800, Xiaotian Wu wrote: > The toolchain for the loongarch architecture will contain a series of patches > [1] > in the next release to add relaxation support for the LoongArch. > > In order for the new toolchain to compile grub 2.12, support for relocation > types > such as R_LARCH_B16, R_LARCH_B21 and R_LARCH_RELAX to be added.
s/to be added/have to be added/? > [1]: https://sourceware.org/pipermail/binutils/2023-May/127539.html > > Signed-off-by: Xiaotian Wu <wuxiaot...@loongson.cn> > --- > grub-core/kern/loongarch64/dl.c | 17 ++++++++++++++ > grub-core/kern/loongarch64/dl_helper.c | 32 +++++++++++++++++++++++++- > include/grub/elf.h | 3 +++ > include/grub/loongarch64/reloc.h | 2 ++ > util/grub-mkimagexx.c | 24 ++++++++++++++++++- > util/grub-module-verifier.c | 3 +++ > 6 files changed, 79 insertions(+), 2 deletions(-) > > diff --git a/grub-core/kern/loongarch64/dl.c b/grub-core/kern/loongarch64/dl.c > index 43080e72e..4341bf5e4 100644 > --- a/grub-core/kern/loongarch64/dl.c > +++ b/grub-core/kern/loongarch64/dl.c > @@ -87,11 +87,28 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, > } > break; > case R_LARCH_MARK_LA: > + case R_LARCH_RELAX: > break; > case R_LARCH_SOP_PUSH_PCREL: > case R_LARCH_SOP_PUSH_PLT_PCREL: > grub_loongarch64_sop_push (&stack, sym_addr - (grub_uint64_t)place); > break; > + case R_LARCH_B16: > + { > + grub_uint32_t *abs_place = place; > + grub_ssize_t off = sym_addr - (grub_addr_t) place; > + > + grub_loongarch64_b16 (abs_place, off); > + } > + break; > + case R_LARCH_B21: > + { > + grub_uint32_t *abs_place = place; > + grub_ssize_t off = sym_addr - (grub_addr_t) place; > + > + grub_loongarch64_b21 (abs_place, off); > + } > + break; > case R_LARCH_B26: > { > grub_uint32_t *abs_place = place; > diff --git a/grub-core/kern/loongarch64/dl_helper.c > b/grub-core/kern/loongarch64/dl_helper.c > index e8ec1219f..4d8d83a7e 100644 > --- a/grub-core/kern/loongarch64/dl_helper.c > +++ b/grub-core/kern/loongarch64/dl_helper.c > @@ -200,12 +200,42 @@ grub_loongarch64_sop_32_s_0_10_10_16_s2 > (grub_loongarch64_stack_t stack, > *place =(*place) | ((a >> 18) & 0x3ff); > } > > +void grub_loongarch64_b16 (grub_uint32_t *place, grub_int64_t offset) > +{ > + grub_uint32_t val; > + const grub_uint32_t insmask = grub_cpu_to_le32_compile_time (0xfc0003ff); > + > + grub_dprintf ("dl", " reloc_b16 %p %c= 0x%llx\n", > + place, offset > 0 ? '+' : '-', > + offset < 0 ? (long long) -(unsigned long long) offset : offset); Why do not use proper PRIxGRUB_INT64_T, etc. format specifiers? Then probably you can drop these strange casts. Or at least cast to grub_* types. If both do not work please add a comment why these casts are needed. > + val = ((offset >> 2) & 0xffff) << 10; > + > + *place &= insmask; > + *place |= grub_cpu_to_le32 (val) & ~insmask; > +} > + > +void grub_loongarch64_b21 (grub_uint32_t *place, grub_int64_t offset) > +{ > + grub_uint32_t val; > + const grub_uint32_t insmask = grub_cpu_to_le32_compile_time (0xfc0003e0); > + > + grub_dprintf ("dl", " reloc_b21 %p %c= 0x%llx\n", > + place, offset > 0 ? '+' : '-', > + offset < 0 ? (long long) -(unsigned long long) offset : offset); Ditto and below please... > + val = ((offset >> 18) & 0x1f) | (((offset >> 2) & 0xffff) << 10); Please define constants where possible. If not please add a comment what is happening here and what these values mean. These kind of problems should be fixed everywhere in this patch. > + *place &= insmask; > + *place |= grub_cpu_to_le32 (val) & ~insmask; > +} > + > void grub_loongarch64_b26 (grub_uint32_t *place, grub_int64_t offset) > { > grub_uint32_t val; > const grub_uint32_t insmask = grub_cpu_to_le32_compile_time (0xfc000000); > > - grub_dprintf ("dl", " reloc_xxxx64 %p %c= 0x%llx\n", > + grub_dprintf ("dl", " reloc_b26 %p %c= 0x%llx\n", > place, offset > 0 ? '+' : '-', > offset < 0 ? (long long) -(unsigned long long) offset : offset); Daniel _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel