This patch may or may not be needed for Grub, as installed
in the LFS book, however it is a patch to the sources that
was required when I rebuilt Grub for a UEFI system, as per
the UEFI hint, on a machine that has an "AMD A8-6600K APU
with Radeon(tm) HD Graphics" as the CPU.

Having built an unpatched Grub as follows

         cd grub-2.02/

         ./configure --prefix=/usr  \
            --sbindir=/sbin        \
            --sysconfdir=/etc      \
            --disable-efiemu       \
            --enable-grub-mkfont   \
            --with-platform=efi    \
            --target=x86_64        \
            --program-prefix=""    \
            --with-bootdir="/boot" \
            --with-grubdir="grub" \
            --disable-werror

         make 2>&1 | tee ../make_uefi.out

         make install 2>&1 | tee ../make_uefi_install.out

coming to do the grub-install, vis:

grub-install \
  --target=x86_64-efi --efi-directory=/boot/efi \
  --bootloader-id=lfs --recheck --debug 2>&1  | \
  tee 20181006-grub-install01.txt

failed, telling me,

...
grub-install: info: locating grub_memalign at 0x4096 (0x400).
grub-install: info: dealing with the relocation section .rela.text for .text.
grub-install: info: relocating an R_X86_64_PC32 entry to 0xe3b1 at the
offset 0x3.
grub-install: info: relocating an R_X86_64_PC32 entry to 0xe3a2 at the
offset 0xa.
grub-install: error: relocation 0x4 is not implemented yet.


Having followed my nose across the interweb thing, through these sites

https://forum.manjaro.org/t/solved-cant-install-grub-after-trying-to-get-grub-silent/58046

https://aur.archlinux.org/packages/grub-luks-keyfile/

https://www.mail-archive.com/[email protected]/msg112375.html

I arrived at


http://git.savannah.gnu.org/cgit/grub.git/commit/util?id=842c390469e2c2e10b5aa36700324cd3bde25875,


which says the following and provides a patch

x86-64: Treat R_X86_64_PLT32 as R_X86_64_PC32

Starting from binutils commit bd7ab16b4537788ad53521c45469a1bdae84ad4a:

https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=bd7ab16b4537788ad53521c45469a1bdae84ad4a

x86-64 assembler generates R_X86_64_PLT32, instead of R_X86_64_PC32,
for 32-bit PC-relative branches.

Grub2 should treat R_X86_64_PLT32 as R_X86_64_PC32.


diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c
index a2bb054..39d7efb 100644
--- a/util/grub-mkimagexx.c
+++ b/util/grub-mkimagexx.c
@@ -841,6 +841,7 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr
*sections,
           break;

         case R_X86_64_PC32:
+        case R_X86_64_PLT32:
           {
             grub_uint32_t *t32 = (grub_uint32_t *) target;
             *t32 = grub_host_to_target64 (grub_target_to_host32 (*t32)
diff --git a/util/grub-module-verifier.c b/util/grub-module-verifier.c
index 9179285..a79271f 100644
--- a/util/grub-module-verifier.c
+++ b/util/grub-module-verifier.c
@@ -19,6 +19,7 @@ struct grub_module_verifier_arch archs[] = {
       -1
     }, (int[]){
       R_X86_64_PC32,
+      R_X86_64_PLT32,
       -1
     }
   },


Applying that patch

patch -Np1 -i ../treat-R_X86_64_PLT32-as-R_X86_64_PC32.patch

before the configure allowed me to build my UEFI-aware Grub
and perform the grub-install without issue.

grub-install: info: locating grub_memalign at 0x4096 (0x400).
grub-install: info: dealing with the relocation section .rela.text for .text.
grub-install: info: relocating an R_X86_64_PC32 entry to 0xe3b1 at the
offset 0x3.
grub-install: info: relocating an R_X86_64_PC32 entry to 0xe3a2 at the
offset 0xa.
grub-install: info: relocating an R_X86_64_PC32 entry to 0x7222 at the
offset 0x13.
grub-install: info: relocating an R_X86_64_64 entry to 0xe7b0 at the
offset 0x33.
....
.. and it trundles on, doing a lot more reloacating, until ...
...
grub-install: info: adding a relocation entry for 0xc9d8.
grub-install: info: adding 221 padding fixup entries.
grub-install: info: writing 872 bytes of a fixup block starting at 0xc000.
grub-install: info: reading /usr/lib/grub/x86_64-efi/fshelp.mod.
grub-install: info: reading /usr/lib/grub/x86_64-efi/ext2.mod.
grub-install: info: reading /usr/lib/grub/x86_64-efi/part_gpt.mod.
grub-install: info: kernel_img=0xd0aa60, kernel_size=0x18600.
grub-install: info: the core size is 0x1c4f0.
grub-install: info: writing 0x1d800 bytes.
grub-install: info: copying `/boot/grub/x86_64-efi/core.efi' -> `/boot/efi/EFI/l
fs/grubx64.efi'.
grub-install: info: Registering with EFI: distributor = `lfs', path = `\EFI\lfs\
grubx64.efi', ESP at hostdisk//dev/sda,gpt1.
grub-install: info: executing efibootmgr --version </dev/null >/dev/null.
grub-install: info: executing modprobe -q efivars.
grub-install: info: executing efibootmgr -b 0002 -B.
BootCurrent: 0001
Timeout: 15 seconds
BootOrder: 0000,0005,0004,0001,0006
Boot0000* ubuntu
Boot0001* CentOS
Boot0004* CD/DVD Drive
Boot0005* grub
Boot0006* Hard Drive
grub-install: info: executing efibootmgr -c -d /dev/sda -p 1 -w -L lfs
-l \EFI\lfs\grubx64.efi.
BootCurrent: 0001
Timeout: 15 seconds
BootOrder: 0002,0000,0005,0004,0001,0006
Boot0000* ubuntu
Boot0001* CentOS
Boot0004* CD/DVD Drive
Boot0005* grub
Boot0006* Hard Drive
Boot0002* lfs
Installation finished. No error reported.


however, as the patch appears not be UEFI-specific but appears
to be tied to the way Grub 2.02 may see some systems/CPUs, I
believe it might be worth adding into the LFS instructions.


Hoping that's useful to someone: it was certainly useful to me.
-- 
http://lists.linuxfromscratch.org/listinfo/lfs-dev
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page

Reply via email to