diff mbox series

boot/grub2: grub-core-build-fixes-for-i386 (grub-2.04 + binutils-2.35.2 + pseudo-op .code64)

Message ID CANTg=Qj3vMern005jEMmUs2dWvi0oJ9Y3aoS4ocsrD91KoXW5Q@mail.gmail.com
State New
Headers show
Series boot/grub2: grub-core-build-fixes-for-i386 (grub-2.04 + binutils-2.35.2 + pseudo-op .code64) | expand

Commit Message

Mikhail B. WproxyM April 20, 2021, 9:35 a.m. UTC
We are using binutils-2.35.2+ (later then 2.29.1), grub-2.04,
cross-compiling on recent buildroot under i386/i686 and getting error:

> lib/i386/relocator64.S:66: Error: unknown pseudo-op: `.code64'

So, the working patch is attached. Please add it to buildroot.

Sources:
1) https://debbugs.gnu.org/cgi/bugreport.cgi?bug=41982 (Jul 2020)
2)
http://archive.linuxfromscratch.org/mail-archives/lfs-support/2018-January/051723.html

--
Best regards

Comments

Thomas Petazzoni April 26, 2021, 8:56 p.m. UTC | #1
Hello Mikhail,

On Tue, 20 Apr 2021 12:35:16 +0300
"Mikhail B. WproxyM" <w.proxy.m@gmail.com> wrote:

> We are using binutils-2.35.2+ (later then 2.29.1), grub-2.04,
> cross-compiling on recent buildroot under i386/i686 and getting error:
> 
> > lib/i386/relocator64.S:66: Error: unknown pseudo-op: `.code64'  
> 
> So, the working patch is attached. Please add it to buildroot.

Do you have some details on the conditions to reproduce this issue?
Indeed, I just tried to build grub2, with the following configuration:

BR2_x86_core2=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_INIT_NONE=y
BR2_SYSTEM_BIN_SH_NONE=y
# BR2_PACKAGE_BUSYBOX is not set
# BR2_TARGET_ROOTFS_TAR is not set
BR2_TARGET_GRUB2=y
BR2_TARGET_GRUB2_I386_EFI=y

So it's using a i686 target system, with a toolchain that uses binutils
2.34 (i.e later than the 2.29 you're pointing). And it builds fine,
including relocator64.S, which gets built as part of the build process.

Note: I am building *from* an x86-64 system. But how can that matter,
as relocator64.S is built using the cross-compiler?

Also, why isn't this patch in upstream Grub ?

Thanks a lot for the additional details you could provide.

Best regards,

Thomas
Mikhail B. WproxyM April 28, 2021, 8:07 a.m. UTC | #2
Hello, Thomas.

I have the build error, when building *from i686* to i686.

You do not have the build error, when building *from x86-64* to i686.
Looks like it is the reason.

Grub2 developers do not run build tests under i386/i686. Even you do
not run build tests under i686.

P.S.: Common build platform for most developers is x86-64, so I am not
surprised. It is too simple to lose compatibility by using too many
levels of assumptions, facades and abstractions.

--
Best regards

--
Best regards, Mikhail B.


пн, 26 апр. 2021 г. в 23:56, Thomas Petazzoni <thomas.petazzoni@bootlin.com>:
>
> Hello Mikhail,
>
> On Tue, 20 Apr 2021 12:35:16 +0300
> "Mikhail B. WproxyM" <w.proxy.m@gmail.com> wrote:
>
> > We are using binutils-2.35.2+ (later then 2.29.1), grub-2.04,
> > cross-compiling on recent buildroot under i386/i686 and getting error:
> >
> > > lib/i386/relocator64.S:66: Error: unknown pseudo-op: `.code64'
> >
> > So, the working patch is attached. Please add it to buildroot.
>
> Do you have some details on the conditions to reproduce this issue?
> Indeed, I just tried to build grub2, with the following configuration:
>
> BR2_x86_core2=y
> BR2_TOOLCHAIN_EXTERNAL=y
> BR2_INIT_NONE=y
> BR2_SYSTEM_BIN_SH_NONE=y
> # BR2_PACKAGE_BUSYBOX is not set
> # BR2_TARGET_ROOTFS_TAR is not set
> BR2_TARGET_GRUB2=y
> BR2_TARGET_GRUB2_I386_EFI=y
>
> So it's using a i686 target system, with a toolchain that uses binutils
> 2.34 (i.e later than the 2.29 you're pointing). And it builds fine,
> including relocator64.S, which gets built as part of the build process.
>
> Note: I am building *from* an x86-64 system. But how can that matter,
> as relocator64.S is built using the cross-compiler?
>
> Also, why isn't this patch in upstream Grub ?
>
> Thanks a lot for the additional details you could provide.
>
> Best regards,
>
> Thomas
> --
> Thomas Petazzoni, co-owner and CEO, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
Thomas Petazzoni April 28, 2021, 11:44 a.m. UTC | #3
Hello Mikhail,

On Wed, 28 Apr 2021 11:07:13 +0300
"Mikhail B. WproxyM" <w.proxy.m@gmail.com> wrote:

> I have the build error, when building *from i686* to i686.
> 
> You do not have the build error, when building *from x86-64* to i686.
> Looks like it is the reason.
> 
> Grub2 developers do not run build tests under i386/i686. Even you do
> not run build tests under i686.

I was worried the issue would be related from the difference of the
build machine architecture. In theory it shouldn't matter, as the file
being built is built with the cross-compiler, but it seems like there
is an actual difference.

What about having this patch submitted to upstream Grub ?

Best regards,

Thomas
Mikhail B. WproxyM April 28, 2021, 1:23 p.m. UTC | #4
>What about having this patch submitted to upstream Grub ?

Idea is nice, but I am not sure that it will work.
The patch was already ignored some time before by grub2 developers,
because it is not included in upstream. I will try.

--
Best regards, Mikhail B.

ср, 28 апр. 2021 г. в 14:44, Thomas Petazzoni <thomas.petazzoni@bootlin.com>:
>
> Hello Mikhail,
>
> On Wed, 28 Apr 2021 11:07:13 +0300
> "Mikhail B. WproxyM" <w.proxy.m@gmail.com> wrote:
>
> > I have the build error, when building *from i686* to i686.
> >
> > You do not have the build error, when building *from x86-64* to i686.
> > Looks like it is the reason.
> >
> > Grub2 developers do not run build tests under i386/i686. Even you do
> > not run build tests under i686.
>
> I was worried the issue would be related from the difference of the
> build machine architecture. In theory it shouldn't matter, as the file
> being built is built with the cross-compiler, but it seems like there
> is an actual difference.
>
> What about having this patch submitted to upstream Grub ?
>
> Best regards,
>
> Thomas
> --
> Thomas Petazzoni, co-owner and CEO, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
diff mbox series

Patch

From 270667540146f8ef9ea7a44258a71b3837a7af4a Mon Sep 17 00:00:00 2001
From: "Jan (janneke) Nieuwenhuizen" <janneke@gnu.org>
Date: Sun, 21 Jun 2020 15:10:40 +0200
Subject: [PATCH] grub-core: Build fixes for i386

* grub-core/lib/i386/relocator64.S: Avoid x86_64 instructions on i386.
---
 grub-core/lib/i386/relocator64.S | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/grub-core/lib/i386/relocator64.S b/grub-core/lib/i386/relocator64.S
index 148f38adb..45fed9444 100644
--- a/grub-core/lib/i386/relocator64.S
+++ b/grub-core/lib/i386/relocator64.S
@@ -63,7 +63,9 @@  VARIABLE(grub_relocator64_cr3)
 	movq	%rax, %cr3
 #endif
 
+#ifdef __x86_64__
 	.code64
+#endif
 
 	/* mov imm64, %rax */
 	.byte 	0x48
@@ -71,7 +73,14 @@  VARIABLE(grub_relocator64_cr3)
 VARIABLE(grub_relocator64_rsp)
 	.quad	0
 
+#ifndef __x86_64__
+	/* movq	%rax, %rsp */
+	.byte 	0x48
+	.byte	0x89
+	.byte	0xc4
+#else
 	movq	%rax, %rsp
+#endif
 
 #ifdef GRUB_MACHINE_EFI
 	jmp	LOCAL(skip_efi_stack_align)
@@ -95,8 +104,15 @@  LOCAL(skip_efi_stack_align):
 VARIABLE(grub_relocator64_rsi)
 	.quad	0
 
+#ifndef	__x86_64__
+	/* movq	%rax, %rsi */
+	.byte 	0x48
+	.byte	0x89
+	.byte 	0xc6
+#else
 	movq	%rax, %rsi
-	
+#endif
+
 	/* mov imm64, %rax */
 	.byte 	0x48
 	.byte	0xb8
@@ -128,6 +144,14 @@  VARIABLE(grub_relocator64_rdx)
 #ifdef __APPLE__
 	.byte 0xff, 0x25
 	.quad 0
+#elif !defined (__x86_64__)
+	/* jmp *LOCAL(jump_addr) (%rip) */
+	.byte 0xff
+        .byte 0x25
+	.byte 0
+	.byte 0
+	.byte 0
+	.byte 0
 #else
 	jmp *LOCAL(jump_addr) (%rip)
 #endif
-- 
Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.com