All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/9] Improve ld.lld-21+ compatibility when building i386-pc target
@ 2026-02-14  1:05 Nicholas Vinson
  2026-02-14  1:05 ` [PATCH v3 1/9] i386/pc/int.h: conditionally apply regparm attr Nicholas Vinson
                   ` (9 more replies)
  0 siblings, 10 replies; 18+ messages in thread
From: Nicholas Vinson @ 2026-02-14  1:05 UTC (permalink / raw)
  To: grub-devel, dkiper, floppym; +Cc: Nicholas Vinson

Starting with ld.llvm-21, any attempt create a non-relocatable binary and set
one more secton addresses below 0x400000 results in a linker error. Furthermore,
the differences between ld.bfd and ld.lld made finding a proper set of
command-line flags tht worked with both linkers and bypass the image base
address restriction difficult. Therefore, the approach of using a custom linker
script was adopted to solve the issue.

This approach was tested using:

../configure CC=clang CXX=clang++ LDFLAGS="-fuse-ld=lld" TARGET_LDFLAGS="-fuse-ld=lld" --with-platform=pc
../configure CC=clang CXX=clang++ --with-platform=pc (both with ld.lld as the default and ld.bfd as the default)
../configure CC=gcc CXX=g++ --with-platform=pc

and a VM was used for testing. To build the disk images the VM was booted with,
the following scripts were used:

EFI disk:
--- /dev/null	2026-01-18 13:24:44.262332704 -0500
+++ efi_disk_image.sh	2026-01-25 11:17:33.554420324 -0500
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+set -xe
+
+dd if=/dev/zero of=grub.img bs=1M count=100 status=progress
+
+sfdisk --force --no-reread --no-tell-kernel grub.img <<EOF
+label: gpt
+label-id: ABEB6772-65C7-4391-BF21-B616916286B9
+size=1M, type=21686148-6449-6E6F-744E-656564454649, uuid=9892A604-439E-4401-A372-AAD5E99EADBB
+type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=FCE5EBB3-C887-4FDE-93C5-7670CC3914BF
+EOF
+
+LOOP_DEV=$(losetup --show -fP grub.img)
+sleep 1
+
+mkfs.ext4 -F "${LOOP_DEV}p2"
+
+mount "${LOOP_DEV}p2" /mnt/gentoo
+./grub-install -v --directory ./grub-core --locale-directory /usr/share/locale --boot-directory=/mnt/gentoo "${LOOP_DEV}"
+
+umount "${LOOP_DEV}p2"
+losetup -d "${LOOP_DEV}"
-- 

MBR image:
--- /dev/null	2026-01-18 13:24:44.262332704 -0500
+++ mbr_disk_image.sh	2026-01-25 11:17:24.129208591 -0500
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+set -xe
+
+dd if=/dev/zero of=grub.img bs=1M count=100 status=progress
+
+sfdisk --force --no-reread --no-tell-kernel grub.img <<EOF
+label: dos
+label-id: 0x12345678
+type=83, bootable
+EOF
+
+LOOP_DEV=$(losetup --show -fP grub.img)
+sleep 1
+
+mkfs.ext4 -F -O ^has_journal "${LOOP_DEV}p1"
+
+mount "${LOOP_DEV}p1" /mnt/gentoo
+./grub-install -v --directory ./grub-core --locale-directory /usr/share/locale --boot-directory=/mnt/gentoo "${LOOP_DEV}"
+
+umount "${LOOP_DEV}p1"
+losetup -d "${LOOP_DEV}"
-- 

In all cases, the VM successfully booted to the standard GRUB prompt.

Nicholas Vinson (9):
  i386/pc/int.h: conditionally apply regparm attr.
  grub-core: Update kernel image generation
  i386-cygwin-img-ld.sc -> i386-cygwin-img.lds
  Revert "configure: Print a more helpful error if autoconf-archive is
    not installed"
  Revert "configure: Check linker for --image-base support"
  Revert "INSTALL: Add note that the GNU Autoconf Archive may be needed"
  configure: drop -Ttext checks for i386-pc
  configure.ac: Add --image-base check for non-i386
  conf/i386-cygwin-img.lds: Update to use _grub_text_base symbol

 .gitignore                                    |  3 +-
 INSTALL                                       |  1 -
 acinclude.m4                                  | 18 ++++--
 conf/Makefile.extra-dist                      |  3 +-
 ...6-cygwin-img-ld.sc => i386-cygwin-img.lds} |  1 +
 conf/i386-pc-kernel.lds                       | 51 ++++++++++++++++
 configure.ac                                  | 61 ++++++++++++-------
 grub-core/Makefile.core.def                   | 31 +++++-----
 include/grub/i386/pc/int.h                    |  5 +-
 m4/ax_check_link_flag.m4                      | 53 ++++++++++++++++
 10 files changed, 181 insertions(+), 46 deletions(-)
 rename conf/{i386-cygwin-img-ld.sc => i386-cygwin-img.lds} (97%)
 create mode 100644 conf/i386-pc-kernel.lds
 create mode 100644 m4/ax_check_link_flag.m4

-- 
2.53.0


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v3 1/9] i386/pc/int.h: conditionally apply regparm attr.
  2026-02-14  1:05 [PATCH v3 0/9] Improve ld.lld-21+ compatibility when building i386-pc target Nicholas Vinson
@ 2026-02-14  1:05 ` Nicholas Vinson
  2026-02-14  7:20   ` Vladimir 'phcoder' Serbinenko
  2026-02-14  1:05 ` [PATCH v3 2/9] grub-core: Update kernel image generation Nicholas Vinson
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 18+ messages in thread
From: Nicholas Vinson @ 2026-02-14  1:05 UTC (permalink / raw)
  To: grub-devel, dkiper, floppym; +Cc: Nicholas Vinson

Modern compilers are becoming more strict and are starting to warn when
certain attributs are ignored. The regparam attribute is such an
attribute.

Update the code so the regparam attribute is only appled when building
against i386 targets as that is the only scenario when it is not
ignored.

Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
---
 include/grub/i386/pc/int.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/grub/i386/pc/int.h b/include/grub/i386/pc/int.h
index a60104001..4b569ca25 100644
--- a/include/grub/i386/pc/int.h
+++ b/include/grub/i386/pc/int.h
@@ -24,7 +24,10 @@
 
 void EXPORT_FUNC (grub_bios_interrupt) (grub_uint8_t intno,
 					struct grub_bios_int_registers *regs)
-     __attribute__ ((regparm(3)));
+#if defined(__i386__) && !defined(__x86_64__)
+     __attribute__ ((regparm(3)))
+#endif
+;
 
 #ifdef GRUB_MACHINE_PCBIOS
 extern struct grub_i386_idt *EXPORT_VAR(grub_realidt);
-- 
2.53.0


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 2/9] grub-core: Update kernel image generation
  2026-02-14  1:05 [PATCH v3 0/9] Improve ld.lld-21+ compatibility when building i386-pc target Nicholas Vinson
  2026-02-14  1:05 ` [PATCH v3 1/9] i386/pc/int.h: conditionally apply regparm attr Nicholas Vinson
@ 2026-02-14  1:05 ` Nicholas Vinson
  2026-02-16 15:33   ` Daniel Kiper
  2026-02-14  1:05 ` [PATCH v3 3/9] i386-cygwin-img-ld.sc -> i386-cygwin-img.lds Nicholas Vinson
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 18+ messages in thread
From: Nicholas Vinson @ 2026-02-14  1:05 UTC (permalink / raw)
  To: grub-devel, dkiper, floppym; +Cc: Nicholas Vinson

The i386-pc kernel image fails to build because of changes made to
address ld.lld-21 and newer linking issues. Specifically, with
ld.lld-21, if you try to set the text section address below image base
address when linking a non-relocatable binary, ld.lld wil fail to link.

Switching to using a customized linker script solves the issue and is a
more robost solution to supporting multiple linkers than attempting to
find a set of command-line flags that satisified all supported linkers
and links the kernel properly. In the worst case, continued use of
command-line flags could result in having to create code branches to
support various linkers.

For example, when dealing with just ld.bfd and ld.lld, the behavioral
differences between the two made finding a proper subset of flags that
worked impossible. The previous attempt dropped -Ttext for --image-base,
which has been proven not to work. The simplest correction,
-Wl,--image-base=0 -Wl,-Ttext, did not work because that option resulted
in a GRUB kernel that entered into a tight infinite refresh loop.

Moreover, ld.lld does not order the sections the same way ld.bfd does,
and that results in object files with gaps or holes when sections are
stripped. I suspect, but did not investigate, that this plays a role in
the infinite refresh loop I mentioned earlier.

The easiest way to resolve all this is to use customized linker scripts.
These scripts, by default, override any default configuration the linker
would otherwise impose, allow for complete control in aligning sections,
and allows GRUB to specify where in the load segment each section goes.

This change does require linkers to support the --defsym flag, which
requires its argument to be of the form 'sym=address' as 'sym address'
is not supported.

Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
---
 conf/Makefile.extra-dist    |  1 +
 conf/i386-pc-kernel.lds     | 51 +++++++++++++++++++++++++++++++++++++
 grub-core/Makefile.core.def | 31 +++++++++++-----------
 3 files changed, 68 insertions(+), 15 deletions(-)
 create mode 100644 conf/i386-pc-kernel.lds

diff --git a/conf/Makefile.extra-dist b/conf/Makefile.extra-dist
index d22b6c862..892df8208 100644
--- a/conf/Makefile.extra-dist
+++ b/conf/Makefile.extra-dist
@@ -17,6 +17,7 @@ EXTRA_DIST += docs/grub.cfg
 EXTRA_DIST += docs/osdetect.cfg
 
 EXTRA_DIST += conf/i386-cygwin-img-ld.sc
+EXTRA_DIST += conf/i386-pc-kernel.lds
 
 EXTRA_DIST += grub-core/Makefile.core.def
 EXTRA_DIST += grub-core/Makefile.gcry.def
diff --git a/conf/i386-pc-kernel.lds b/conf/i386-pc-kernel.lds
new file mode 100644
index 000000000..d40c7736c
--- /dev/null
+++ b/conf/i386-pc-kernel.lds
@@ -0,0 +1,51 @@
+ENTRY(_start)
+
+/*
+ * Align sections to a 16-byte boundary. This guarantees ABI compatibility with
+ * C generated code
+ */
+SECTION_ALIGN = 0x10;
+
+PHDRS {
+    text PT_LOAD FLAGS(7) /* PF_R | PF_W | PF_X */;
+}
+
+SECTIONS
+{
+    /*
+     * Set section alignment to 1. This allows sections to be aligned without
+     * creating holes in the VMA space or gaps in the file.
+     */
+    . = _grub_text_base;
+    .text ALIGN(0x1) : {
+        _start = .;
+        *(.text .text.*)
+        . = ALIGN(SECTION_ALIGN);
+    } :text
+    .rodata ALIGN(0x1) : {
+        *(.rodata .rodata.*)
+        . = ALIGN(SECTION_ALIGN);
+    } :text
+    .module_license ALIGN(0x1) : {
+        *(.module_license)
+        . = ALIGN(SECTION_ALIGN);
+    } :text
+    .data ALIGN(0x1) : {
+        *(.data .data.*)
+        . = ALIGN(SECTION_ALIGN);
+        _edata = .;
+    } :text
+    .bss ALIGN(0x1) : {
+        __bss_start = .;
+        *(.bss .bss.*)
+        *(COMMON)
+        . = ALIGN(SECTION_ALIGN);
+        _end = .;
+    } :text
+    /DISCARD/ : {
+        *(.interp)
+        *(.note*)
+        *(.comment)
+        *(.build-id)
+    }
+}
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 0cf155128..1a91e53d6 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -10,6 +10,7 @@ transform_data = {
   installdir = noinst;
   name = genmod.sh;
   common = genmod.sh.in;
+  i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)';
 };
 
 transform_data = {
@@ -82,21 +83,21 @@ kernel = {
   riscv64_efi_stripflags   = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version -R .eh_frame';
 
   i386_pc_ldflags          = '$(TARGET_IMG_LDFLAGS)';
-  i386_pc_ldflags          = '$(TARGET_IMG_BASE_LDOPT),0x9000';
+  i386_pc_ldflags          = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0x9000';
   i386_qemu_ldflags        = '$(TARGET_IMG_LDFLAGS)';
-  i386_qemu_ldflags        = '$(TARGET_IMG_BASE_LDOPT),0x9000';
+  i386_qemu_ldflags        = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0x9000';
   i386_coreboot_ldflags    = '$(TARGET_IMG_LDFLAGS)';
-  i386_coreboot_ldflags    = '$(TARGET_IMG_BASE_LDOPT),0x9000';
+  i386_coreboot_ldflags    = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0x9000';
   i386_multiboot_ldflags   = '$(TARGET_IMG_LDFLAGS)';
-  i386_multiboot_ldflags   = '$(TARGET_IMG_BASE_LDOPT),0x9000';
+  i386_multiboot_ldflags   = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0x9000';
   i386_ieee1275_ldflags    = '$(TARGET_IMG_LDFLAGS)';
-  i386_ieee1275_ldflags    = '$(TARGET_IMG_BASE_LDOPT),0x10000';
+  i386_ieee1275_ldflags    = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0x10000';
   i386_xen_ldflags         = '$(TARGET_IMG_LDFLAGS)';
-  i386_xen_ldflags         = '$(TARGET_IMG_BASE_LDOPT),0';
+  i386_xen_ldflags         = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0';
   x86_64_xen_ldflags       = '$(TARGET_IMG_LDFLAGS)';
   x86_64_xen_ldflags       = '$(TARGET_IMG_BASE_LDOPT),0';
   i386_xen_pvh_ldflags     = '$(TARGET_IMG_LDFLAGS)';
-  i386_xen_pvh_ldflags     = '$(TARGET_IMG_BASE_LDOPT),0x100000';
+  i386_xen_pvh_ldflags     = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0x100000';
 
   mips_loongson_ldflags    = '-Wl,-Ttext,0x80200000';
   powerpc_ieee1275_ldflags = '-Wl,-Ttext,0x200000';
@@ -450,10 +451,10 @@ image = {
   sparc64_ieee1275 = boot/sparc64/ieee1275/boot.S;
 
   i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)';
-  i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x7C00';
+  i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0x7C00';
 
   i386_qemu_ldflags = '$(TARGET_IMG_LDFLAGS)';
-  i386_qemu_ldflags = '$(TARGET_IMG_BASE_LDOPT),$(GRUB_BOOT_MACHINE_LINK_ADDR)';
+  i386_qemu_ldflags = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)$(GRUB_BOOT_MACHINE_LINK_ADDR)';
   i386_qemu_ccasflags = '-DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR)';
 
   /* The entry point for a.out binaries on sparc64 starts
@@ -478,7 +479,7 @@ image = {
   cppflags = '-DHYBRID_BOOT=1';
   
   i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)';
-  i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x7C00';
+  i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0x7C00';
 
   objcopyflags = '-O binary';
   enable = i386_pc;
@@ -489,7 +490,7 @@ image = {
 
   i386_pc = boot/i386/pc/cdboot.S;
   i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)';
-  i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x7C00';
+  i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0x7C00';
 
   sparc64_ieee1275 = boot/sparc64/ieee1275/boot.S;
 
@@ -509,7 +510,7 @@ image = {
   i386_pc = boot/i386/pc/pxeboot.S;
 
   i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)';
-  i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x7C00';
+  i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0x7C00';
 
   objcopyflags = '-O binary';
   enable = i386_pc;
@@ -520,7 +521,7 @@ image = {
   i386_pc = boot/i386/pc/diskboot.S;
 
   i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)';
-  i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x8000';
+  i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0x8000';
 
   sparc64_ieee1275 = boot/sparc64/ieee1275/diskboot.S;
   sparc64_ieee1275_ldflags = '-Wl,-Ttext=0x4200';
@@ -536,7 +537,7 @@ image = {
   i386_pc = boot/i386/pc/lnxboot.S;
 
   i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)';
-  i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x6000';
+  i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0x6000';
 
   objcopyflags = '-O binary';
   enable = i386_pc;
@@ -578,7 +579,7 @@ image = {
   i386_pc_nodist = rs_decoder.h;
 
   objcopyflags = '-O binary';
-  ldflags = '$(TARGET_IMG_LDFLAGS) $(TARGET_IMG_BASE_LDOPT),0x8200';
+  ldflags = '$(TARGET_IMG_LDFLAGS) $(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0x8200';
   enable = i386_pc;
 };
 
-- 
2.53.0


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 3/9] i386-cygwin-img-ld.sc -> i386-cygwin-img.lds
  2026-02-14  1:05 [PATCH v3 0/9] Improve ld.lld-21+ compatibility when building i386-pc target Nicholas Vinson
  2026-02-14  1:05 ` [PATCH v3 1/9] i386/pc/int.h: conditionally apply regparm attr Nicholas Vinson
  2026-02-14  1:05 ` [PATCH v3 2/9] grub-core: Update kernel image generation Nicholas Vinson
@ 2026-02-14  1:05 ` Nicholas Vinson
  2026-02-14  1:05 ` [PATCH v3 4/9] Revert "configure: Print a more helpful error if autoconf-archive is not installed" Nicholas Vinson
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 18+ messages in thread
From: Nicholas Vinson @ 2026-02-14  1:05 UTC (permalink / raw)
  To: grub-devel, dkiper, floppym; +Cc: Nicholas Vinson

Rename i386-cygwin-img-ld.sc to i386-cygwin-img.lds as 'lds' is the
preferred extension for linker scripts.

Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
---
 conf/Makefile.extra-dist                            | 2 +-
 conf/{i386-cygwin-img-ld.sc => i386-cygwin-img.lds} | 0
 configure.ac                                        | 4 ++--
 3 files changed, 3 insertions(+), 3 deletions(-)
 rename conf/{i386-cygwin-img-ld.sc => i386-cygwin-img.lds} (100%)

diff --git a/conf/Makefile.extra-dist b/conf/Makefile.extra-dist
index 892df8208..393693ffc 100644
--- a/conf/Makefile.extra-dist
+++ b/conf/Makefile.extra-dist
@@ -16,7 +16,7 @@ EXTRA_DIST += docs/autoiso.cfg
 EXTRA_DIST += docs/grub.cfg
 EXTRA_DIST += docs/osdetect.cfg
 
-EXTRA_DIST += conf/i386-cygwin-img-ld.sc
+EXTRA_DIST += conf/i386-cygwin-img.lds
 EXTRA_DIST += conf/i386-pc-kernel.lds
 
 EXTRA_DIST += grub-core/Makefile.core.def
diff --git a/conf/i386-cygwin-img-ld.sc b/conf/i386-cygwin-img.lds
similarity index 100%
rename from conf/i386-cygwin-img-ld.sc
rename to conf/i386-cygwin-img.lds
diff --git a/configure.ac b/configure.ac
index d8ca1b7c1..2827ae2c1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1458,9 +1458,9 @@ if test x$grub_cv_target_cc_link_format = x-arch,i386 || test x$grub_cv_target_c
 elif test x$grub_cv_target_cc_link_format = x-mi386pe || test x$grub_cv_target_cc_link_format = x-mi386pep ; then
   TARGET_APPLE_LINKER=0
   TARGET_LDFLAGS_OLDMAGIC="-Wl,-N"
-  TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/i386-cygwin-img-ld.sc"
+  TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/i386-cygwin-img.lds"
   TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT}"
-  TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/i386-cygwin-img-ld.sc"
+  TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/i386-cygwin-img.lds"
   TARGET_IMG_CFLAGS=
 else
   TARGET_APPLE_LINKER=0
-- 
2.53.0


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 4/9] Revert "configure: Print a more helpful error if autoconf-archive is not installed"
  2026-02-14  1:05 [PATCH v3 0/9] Improve ld.lld-21+ compatibility when building i386-pc target Nicholas Vinson
                   ` (2 preceding siblings ...)
  2026-02-14  1:05 ` [PATCH v3 3/9] i386-cygwin-img-ld.sc -> i386-cygwin-img.lds Nicholas Vinson
@ 2026-02-14  1:05 ` Nicholas Vinson
  2026-02-14  7:21   ` Vladimir 'phcoder' Serbinenko
  2026-02-14  1:05 ` [PATCH v3 5/9] Revert "configure: Check linker for --image-base support" Nicholas Vinson
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 18+ messages in thread
From: Nicholas Vinson @ 2026-02-14  1:05 UTC (permalink / raw)
  To: grub-devel, dkiper, floppym; +Cc: Nicholas Vinson

This reverts commit ac042f3f58d33ce9cd5ff61750f06da1a1d7b0eb.

Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
---
 configure.ac | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/configure.ac b/configure.ac
index 2827ae2c1..dfef2e278 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1792,11 +1792,6 @@ LIBS=""
 # Defined in acinclude.m4.
 grub_ASM_USCORE
 grub_PROG_TARGET_CC
-
-# The error message produced by autoconf if autoconf-archive is not installed is
-# quite misleading and not very helpful. So, try point people in the right direction.
-m4_ifndef([AX_CHECK_LINK_FLAG], [m4_fatal([autoconf-archive is missing. You must install it to generate the configure script.])])
-
 if test "x$TARGET_APPLE_LINKER" != x1 ; then
 AX_CHECK_LINK_FLAG([-Wl,--image-base,0x400000],
     [TARGET_IMG_BASE_LDOPT="-Wl,--image-base"],
-- 
2.53.0


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 5/9] Revert "configure: Check linker for --image-base support"
  2026-02-14  1:05 [PATCH v3 0/9] Improve ld.lld-21+ compatibility when building i386-pc target Nicholas Vinson
                   ` (3 preceding siblings ...)
  2026-02-14  1:05 ` [PATCH v3 4/9] Revert "configure: Print a more helpful error if autoconf-archive is not installed" Nicholas Vinson
@ 2026-02-14  1:05 ` Nicholas Vinson
  2026-02-14  1:05 ` [PATCH v3 6/9] Revert "INSTALL: Add note that the GNU Autoconf Archive may be needed" Nicholas Vinson
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 18+ messages in thread
From: Nicholas Vinson @ 2026-02-14  1:05 UTC (permalink / raw)
  To: grub-devel, dkiper, floppym; +Cc: Nicholas Vinson

This reverts commit 1a5417f39a0ccefcdd5440f2a67f84d2d2e26960.

Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
---
 acinclude.m4 |  5 -----
 configure.ac | 14 ++------------
 2 files changed, 2 insertions(+), 17 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index 70c1912f8..fa7840f09 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -79,11 +79,6 @@ AC_DEFUN([grub_PROG_OBJCOPY_ABSOLUTE],
 [AC_MSG_CHECKING([whether ${TARGET_OBJCOPY} works for absolute addresses])
 AC_CACHE_VAL(grub_cv_prog_objcopy_absolute,
 [cat > conftest.c <<\EOF
-asm (
-    ".globl start, _start, __start\n"
-    ".ifdef cmain; .set start = _start = __start = cmain\n.endif\n"
-    ".ifdef _cmain; .set start = _start = __start = _cmain\n.endif\n"
-);
 void cmain (void);
 void
 cmain (void)
diff --git a/configure.ac b/configure.ac
index dfef2e278..3106bb11d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1461,6 +1461,7 @@ elif test x$grub_cv_target_cc_link_format = x-mi386pe || test x$grub_cv_target_c
   TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/i386-cygwin-img.lds"
   TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT}"
   TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/i386-cygwin-img.lds"
+  TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"
   TARGET_IMG_CFLAGS=
 else
   TARGET_APPLE_LINKER=0
@@ -1468,6 +1469,7 @@ else
   TARGET_IMG_LDSCRIPT=
   TARGET_IMG_LDFLAGS='-Wl,-N'
   TARGET_IMG_LDFLAGS_AC='-Wl,-N'
+  TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"
   TARGET_IMG_CFLAGS=
 fi
 
@@ -1793,18 +1795,6 @@ LIBS=""
 grub_ASM_USCORE
 grub_PROG_TARGET_CC
 if test "x$TARGET_APPLE_LINKER" != x1 ; then
-AX_CHECK_LINK_FLAG([-Wl,--image-base,0x400000],
-    [TARGET_IMG_BASE_LDOPT="-Wl,--image-base"],
-    [TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"],
-    [],
-    [AC_LANG_SOURCE([
-asm (".globl start; start:");
-asm (".globl _start; _start:");
-asm (".globl __start; __start:");
-void __main (void);
-void __main (void) {}
-int main (void);
-    ])])
 grub_PROG_OBJCOPY_ABSOLUTE
 fi
 grub_PROG_LD_BUILD_ID_NONE
-- 
2.53.0


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 6/9] Revert "INSTALL: Add note that the GNU Autoconf Archive may be needed"
  2026-02-14  1:05 [PATCH v3 0/9] Improve ld.lld-21+ compatibility when building i386-pc target Nicholas Vinson
                   ` (4 preceding siblings ...)
  2026-02-14  1:05 ` [PATCH v3 5/9] Revert "configure: Check linker for --image-base support" Nicholas Vinson
@ 2026-02-14  1:05 ` Nicholas Vinson
  2026-02-14  1:27   ` [PATCH v3 7/9] [corrected] " Nicholas Vinson
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 18+ messages in thread
From: Nicholas Vinson @ 2026-02-14  1:05 UTC (permalink / raw)
  To: grub-devel, dkiper, floppym; +Cc: Nicholas Vinson

This reverts commit a90ccbac677db62fc0c1940cda4388370ac8a04b.

Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
---
 INSTALL | 1 -
 1 file changed, 1 deletion(-)

diff --git a/INSTALL b/INSTALL
index 7ac1c7cc8..7e5397f58 100644
--- a/INSTALL
+++ b/INSTALL
@@ -56,7 +56,6 @@ need the following.
 * Python 3 (NOTE: python 2.6 should still work, but it's not tested)
 * Autoconf 2.64 or later
 * Automake 1.14 or later
-* GNU Autoconf Archive (autoconf-archive on Debian)
 
 Your distro may package cross-compiling toolchains such as the following
 incomplete list on Debian: gcc-aarch64-linux-gnu, gcc-arm-linux-gnueabihf,
-- 
2.53.0


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 7/9] configure: drop -Ttext checks for i386-pc
@ 2026-02-14  1:27   ` Nicholas Vinson
  0 siblings, 0 replies; 18+ messages in thread
From: Nicholas Vinson @ 2026-02-14  1:05 UTC (permalink / raw)
  To: grub-devel, dkiper, floppym; +Cc: Nicholas Vinson

The i386-pc target now uses a linker script, so -Ttext is no longer
required.

Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
---
 acinclude.m4 | 13 ++++++++++++-
 configure.ac | 29 ++++++++++++++++++++++++++---
 2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index fa7840f09..478aab6d3 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -93,7 +93,18 @@ else
 fi
 grub_cv_prog_objcopy_absolute=yes
 for link_addr in 0x2000 0x8000 0x7C00; do
-  if AC_TRY_COMMAND([${CC-cc} ${TARGET_CFLAGS} ${TARGET_LDFLAGS} -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${TARGET_IMG_BASE_LDOPT},$link_addr conftest.o -o conftest.exec]); then :
+
+  target_img_base_ld="${TARGET_IMG_BASE_LDOPT}"
+  case "$target_img_base_ld" in
+    *_grub_text_base)
+      target_img_base_ld="${target_img_base_ld}=$link_addr"
+    ;;
+    *)
+      target_img_base_ld="${target_img_base_ld},$link_addr"
+    ;;
+  esac
+
+  if AC_TRY_COMMAND([${CC-cc} ${TARGET_CFLAGS} ${TARGET_LDFLAGS} -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${target_img_base_ld} conftest.o -o conftest.exec]); then :
   else
     AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr])
   fi
diff --git a/configure.ac b/configure.ac
index 3106bb11d..4febd084d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1454,6 +1454,7 @@ if test x$grub_cv_target_cc_link_format = x-arch,i386 || test x$grub_cv_target_c
    TARGET_IMG_LDFLAGS='-nostdlib -static -Wl,-preload -Wl,-segalign,20'
    TARGET_IMG_LDFLAGS_AC='-nostdlib -static -Wl,-preload -Wl,-segalign,20'
    TARGET_IMG_BASE_LDOPT="-Wl,-image_base"
+   TARGET_IMG_BASE_LDOPT_ARG_SEP=","
    TARGET_LDFLAGS_OLDMAGIC=""
 elif test x$grub_cv_target_cc_link_format = x-mi386pe || test x$grub_cv_target_cc_link_format = x-mi386pep ; then
   TARGET_APPLE_LINKER=0
@@ -1461,7 +1462,8 @@ elif test x$grub_cv_target_cc_link_format = x-mi386pe || test x$grub_cv_target_c
   TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/i386-cygwin-img.lds"
   TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT}"
   TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/i386-cygwin-img.lds"
-  TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"
+  TARGET_IMG_BASE_LDOPT=
+  TARGET_IMG_BASE_LDOPT_ARG_SEP=","
   TARGET_IMG_CFLAGS=
 else
   TARGET_APPLE_LINKER=0
@@ -1469,7 +1471,16 @@ else
   TARGET_IMG_LDSCRIPT=
   TARGET_IMG_LDFLAGS='-Wl,-N'
   TARGET_IMG_LDFLAGS_AC='-Wl,-N'
-  TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"
+  if test "x$target_cpu-$platform" != "xi386-pc"; then
+    TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"
+    TARGET_IMG_BASE_LDOPT_ARG_SEP=","
+  else
+    TARGET_IMG_BASE_LDOPT="-Wl,--defsym,_grub_text_base"
+    TARGET_IMG_BASE_LDOPT_ARG_SEP="="
+    TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/i386-pc-kernel.lds"
+    TARGET_IMG_LDFLAGS="${TARGET_IMG_LDFLAGS} -Wl,-T${TARGET_IMG_LDSCRIPT}"
+    TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/i386-pc-kernel.lds"
+  fi
   TARGET_IMG_CFLAGS=
 fi
 
@@ -1802,7 +1813,18 @@ if test "x$target_cpu" = xi386; then
   if test "$platform" != emu && test "x$TARGET_APPLE_LINKER" != x1 ; then
     if test ! -z "$TARGET_IMG_LDSCRIPT"; then
       # Check symbols provided by linker script.
-      CFLAGS="$TARGET_CFLAGS -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${TARGET_IMG_BASE_LDOPT},0x8000"
+      target_img_base_ld="${TARGET_IMG_BASE_LDOPT}"
+      case "$target_img_base_ld" in
+        *_grub_text_base)
+          target_img_base_ld="${target_img_base_ld}="
+        ;;
+        *)
+          target_img_base_ld="${target_img_base_ld},"
+        ;;
+      esac
+      target_img_base_ld="${target_img_base_ld}0x8000"
+      CFLAGS="$TARGET_CFLAGS -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${target_img_base_ld}"
+      target_img_base_ld=""
     fi
     grub_CHECK_BSS_START_SYMBOL
     grub_CHECK_END_SYMBOL
@@ -2404,6 +2426,7 @@ AC_SUBST(TARGET_CCASFLAGS)
 AC_SUBST(TARGET_IMG_LDFLAGS)
 AC_SUBST(TARGET_IMG_CFLAGS)
 AC_SUBST(TARGET_IMG_BASE_LDOPT)
+AC_SUBST(TARGET_IMG_BASE_LDOPT_ARG_SEP)
 AC_SUBST(TARGET_APPLE_LINKER)
 
 AC_SUBST(HOST_CFLAGS)
-- 
2.53.0


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 8/9] configure.ac: Add --image-base check for non-i386
  2026-02-14  1:05 [PATCH v3 0/9] Improve ld.lld-21+ compatibility when building i386-pc target Nicholas Vinson
                   ` (6 preceding siblings ...)
  2026-02-14  1:27   ` [PATCH v3 7/9] [corrected] " Nicholas Vinson
@ 2026-02-14  1:05 ` Nicholas Vinson
  2026-02-14  1:05 ` [PATCH v3 9/9] conf/i386-cygwin-img.lds: Update to use _grub_text_base symbol Nicholas Vinson
  2026-02-16 15:42 ` [PATCH v3 0/9] Improve ld.lld-21+ compatibility when building i386-pc target Daniel Kiper
  9 siblings, 0 replies; 18+ messages in thread
From: Nicholas Vinson @ 2026-02-14  1:05 UTC (permalink / raw)
  To: grub-devel, dkiper, floppym; +Cc: Nicholas Vinson

The configure check grub_PROG_OBJCOPY_ABSOLUTE is run for all non-Apple
targets.  With ld.lld-21, the check fails for addresses below image base
address (which ld.lld-21 assumes is 0x200000).

Fix by checking if linker supports the --image-base flag, and if it does,
include "--image-base 0" to TARGET_IMG_BASE_LDOPT.

The AX_CHECK_LINK_FLAG macro has been added to avoid a dependency on
autoconf-archive.

Note: I tried this approach with i386-pc, but I ended up with a grub
image that failed to boot correctly.

Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
---
 .gitignore               |  3 ++-
 configure.ac             | 13 +++++++++-
 m4/ax_check_link_flag.m4 | 53 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 67 insertions(+), 2 deletions(-)
 create mode 100644 m4/ax_check_link_flag.m4

diff --git a/.gitignore b/.gitignore
index db16295ad..f61f4805f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -238,7 +238,8 @@ widthspec.bin
 /lzocompress_test
 /luks1_test
 /luks2_test
-/m4/
+/m4/*
+!/m4/ax_check_link_flag.m4
 /minixfs_test
 /missing
 /netboot_test
diff --git a/configure.ac b/configure.ac
index 4febd084d..94218e014 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1472,7 +1472,18 @@ else
   TARGET_IMG_LDFLAGS='-Wl,-N'
   TARGET_IMG_LDFLAGS_AC='-Wl,-N'
   if test "x$target_cpu-$platform" != "xi386-pc"; then
-    TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"
+    AX_CHECK_LINK_FLAG([-Wl,--image-base,0],
+        [TARGET_IMG_BASE_LDOPT="-Wl,--image-base,0 -Wl,-Ttext"],
+        [TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"],
+        [],
+        [AC_LANG_SOURCE([
+    asm (".globl start; start:");
+    asm (".globl _start; _start:");
+    asm (".globl __start; __start:");
+    void __main (void);
+    void __main (void) {}
+    int main (void);
+        ])])
     TARGET_IMG_BASE_LDOPT_ARG_SEP=","
   else
     TARGET_IMG_BASE_LDOPT="-Wl,--defsym,_grub_text_base"
diff --git a/m4/ax_check_link_flag.m4 b/m4/ax_check_link_flag.m4
new file mode 100644
index 000000000..03a30ce4c
--- /dev/null
+++ b/m4/ax_check_link_flag.m4
@@ -0,0 +1,53 @@
+# ===========================================================================
+#    https://www.gnu.org/software/autoconf-archive/ax_check_link_flag.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+#   AX_CHECK_LINK_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
+#
+# DESCRIPTION
+#
+#   Check whether the given FLAG works with the linker or gives an error.
+#   (Warnings, however, are ignored)
+#
+#   ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
+#   success/failure.
+#
+#   If EXTRA-FLAGS is defined, it is added to the linker's default flags
+#   when the check is done.  The check is thus made with the flags: "LDFLAGS
+#   EXTRA-FLAGS FLAG".  This can for example be used to force the linker to
+#   issue an error when a bad flag is given.
+#
+#   INPUT gives an alternative input source to AC_LINK_IFELSE.
+#
+#   NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
+#   macro in sync with AX_CHECK_{PREPROC,COMPILE}_FLAG.
+#
+# LICENSE
+#
+#   Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
+#   Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>
+#
+#   Copying and distribution of this file, with or without modification, are
+#   permitted in any medium without royalty provided the copyright notice
+#   and this notice are preserved.  This file is offered as-is, without any
+#   warranty.
+
+#serial 6
+
+AC_DEFUN([AX_CHECK_LINK_FLAG],
+[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
+AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_ldflags_$4_$1])dnl
+AC_CACHE_CHECK([whether the linker accepts $1], CACHEVAR, [
+  ax_check_save_flags=$LDFLAGS
+  LDFLAGS="$LDFLAGS $4 $1"
+  AC_LINK_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
+    [AS_VAR_SET(CACHEVAR,[yes])],
+    [AS_VAR_SET(CACHEVAR,[no])])
+  LDFLAGS=$ax_check_save_flags])
+AS_VAR_IF(CACHEVAR,yes,
+  [m4_default([$2], :)],
+  [m4_default([$3], :)])
+AS_VAR_POPDEF([CACHEVAR])dnl
+])dnl AX_CHECK_LINK_FLAGS
-- 
2.53.0


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 9/9] conf/i386-cygwin-img.lds: Update to use _grub_text_base symbol
  2026-02-14  1:05 [PATCH v3 0/9] Improve ld.lld-21+ compatibility when building i386-pc target Nicholas Vinson
                   ` (7 preceding siblings ...)
  2026-02-14  1:05 ` [PATCH v3 8/9] configure.ac: Add --image-base check for non-i386 Nicholas Vinson
@ 2026-02-14  1:05 ` Nicholas Vinson
  2026-02-14  1:08   ` Nicholas Vinson
  2026-02-16 15:42 ` [PATCH v3 0/9] Improve ld.lld-21+ compatibility when building i386-pc target Daniel Kiper
  9 siblings, 1 reply; 18+ messages in thread
From: Nicholas Vinson @ 2026-02-14  1:05 UTC (permalink / raw)
  To: grub-devel, dkiper, floppym; +Cc: Nicholas Vinson

This patch updates conf/i386-cygwin-img.lds to use the _grub_text_base
symbol just like conf/i386-pc-kernel.lds. It also updates configure.ac
to account for this change.

Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
---
 conf/i386-cygwin-img.lds | 1 +
 configure.ac             | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/conf/i386-cygwin-img.lds b/conf/i386-cygwin-img.lds
index 578da91b0..26935ce92 100644
--- a/conf/i386-cygwin-img.lds
+++ b/conf/i386-cygwin-img.lds
@@ -2,6 +2,7 @@
 
 SECTIONS
 {
+  . = _grub_image_base;
   .text :
   {
     start = . ;
diff --git a/configure.ac b/configure.ac
index 94218e014..6367afddc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1453,8 +1453,8 @@ if test x$grub_cv_target_cc_link_format = x-arch,i386 || test x$grub_cv_target_c
    TARGET_IMG_CFLAGS="-static"
    TARGET_IMG_LDFLAGS='-nostdlib -static -Wl,-preload -Wl,-segalign,20'
    TARGET_IMG_LDFLAGS_AC='-nostdlib -static -Wl,-preload -Wl,-segalign,20'
-   TARGET_IMG_BASE_LDOPT="-Wl,-image_base"
-   TARGET_IMG_BASE_LDOPT_ARG_SEP=","
+   TARGET_IMG_BASE_LDOPT="-Wl,--defsym,_grub_text_base"
+   TARGET_IMG_BASE_LDOPT_ARG_SEP="="
    TARGET_LDFLAGS_OLDMAGIC=""
 elif test x$grub_cv_target_cc_link_format = x-mi386pe || test x$grub_cv_target_cc_link_format = x-mi386pep ; then
   TARGET_APPLE_LINKER=0
-- 
2.53.0


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 9/9] conf/i386-cygwin-img.lds: Update to use _grub_text_base symbol
  2026-02-14  1:05 ` [PATCH v3 9/9] conf/i386-cygwin-img.lds: Update to use _grub_text_base symbol Nicholas Vinson
@ 2026-02-14  1:08   ` Nicholas Vinson
  0 siblings, 0 replies; 18+ messages in thread
From: Nicholas Vinson @ 2026-02-14  1:08 UTC (permalink / raw)
  To: grub-devel, dkiper, floppym

This patch is optional and if the changes it makes are not desirable, it 
can be dropped from the series without affecting any of the others. I 
included it so i386-cygwin-img.lds and i386-pc-kernel.lds would use the 
same mechanism for setting the image base address.

Regards,
Nicholas Vinson

On 2/13/26 20:05, Nicholas Vinson wrote:
> This patch updates conf/i386-cygwin-img.lds to use the _grub_text_base
> symbol just like conf/i386-pc-kernel.lds. It also updates configure.ac
> to account for this change.
> 
> Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
> ---
>   conf/i386-cygwin-img.lds | 1 +
>   configure.ac             | 4 ++--
>   2 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/conf/i386-cygwin-img.lds b/conf/i386-cygwin-img.lds
> index 578da91b0..26935ce92 100644
> --- a/conf/i386-cygwin-img.lds
> +++ b/conf/i386-cygwin-img.lds
> @@ -2,6 +2,7 @@
>   
>   SECTIONS
>   {
> +  . = _grub_image_base;
>     .text :
>     {
>       start = . ;
> diff --git a/configure.ac b/configure.ac
> index 94218e014..6367afddc 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -1453,8 +1453,8 @@ if test x$grub_cv_target_cc_link_format = x-arch,i386 || test x$grub_cv_target_c
>      TARGET_IMG_CFLAGS="-static"
>      TARGET_IMG_LDFLAGS='-nostdlib -static -Wl,-preload -Wl,-segalign,20'
>      TARGET_IMG_LDFLAGS_AC='-nostdlib -static -Wl,-preload -Wl,-segalign,20'
> -   TARGET_IMG_BASE_LDOPT="-Wl,-image_base"
> -   TARGET_IMG_BASE_LDOPT_ARG_SEP=","
> +   TARGET_IMG_BASE_LDOPT="-Wl,--defsym,_grub_text_base"
> +   TARGET_IMG_BASE_LDOPT_ARG_SEP="="
>      TARGET_LDFLAGS_OLDMAGIC=""
>   elif test x$grub_cv_target_cc_link_format = x-mi386pe || test x$grub_cv_target_cc_link_format = x-mi386pep ; then
>     TARGET_APPLE_LINKER=0


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 7/9] configure: drop -Ttext checks for i386-pc
  2026-02-14  1:27   ` [PATCH v3 7/9] [corrected] " Nicholas Vinson
  (?)
@ 2026-02-14  1:15   ` Nicholas Vinson
  -1 siblings, 0 replies; 18+ messages in thread
From: Nicholas Vinson @ 2026-02-14  1:15 UTC (permalink / raw)
  To: grub-devel, dkiper, floppym

I reworked this patch with the hope that these changes will work with 
the cygwin target. Unfortunately, I don't have a way to test these 
changes using cygwin.

On 2/13/26 20:05, Nicholas Vinson wrote:
> The i386-pc target now uses a linker script, so -Ttext is no longer
> required.
> 
> Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
> ---
>   acinclude.m4 | 13 ++++++++++++-
>   configure.ac | 29 ++++++++++++++++++++++++++---
>   2 files changed, 38 insertions(+), 4 deletions(-)
> 
> diff --git a/acinclude.m4 b/acinclude.m4
> index fa7840f09..478aab6d3 100644
> --- a/acinclude.m4
> +++ b/acinclude.m4
> @@ -93,7 +93,18 @@ else
>   fi
>   grub_cv_prog_objcopy_absolute=yes
>   for link_addr in 0x2000 0x8000 0x7C00; do
> -  if AC_TRY_COMMAND([${CC-cc} ${TARGET_CFLAGS} ${TARGET_LDFLAGS} -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${TARGET_IMG_BASE_LDOPT},$link_addr conftest.o -o conftest.exec]); then :
> +
> +  target_img_base_ld="${TARGET_IMG_BASE_LDOPT}"
> +  case "$target_img_base_ld" in
> +    *_grub_text_base)
> +      target_img_base_ld="${target_img_base_ld}=$link_addr"
> +    ;;
> +    *)
> +      target_img_base_ld="${target_img_base_ld},$link_addr"
> +    ;;
> +  esac
> +
> +  if AC_TRY_COMMAND([${CC-cc} ${TARGET_CFLAGS} ${TARGET_LDFLAGS} -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${target_img_base_ld} conftest.o -o conftest.exec]); then :
>     else
>       AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr])
>     fi
> diff --git a/configure.ac b/configure.ac
> index 3106bb11d..4febd084d 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -1454,6 +1454,7 @@ if test x$grub_cv_target_cc_link_format = x-arch,i386 || test x$grub_cv_target_c
>      TARGET_IMG_LDFLAGS='-nostdlib -static -Wl,-preload -Wl,-segalign,20'
>      TARGET_IMG_LDFLAGS_AC='-nostdlib -static -Wl,-preload -Wl,-segalign,20'
>      TARGET_IMG_BASE_LDOPT="-Wl,-image_base"
> +   TARGET_IMG_BASE_LDOPT_ARG_SEP=","
>      TARGET_LDFLAGS_OLDMAGIC=""
>   elif test x$grub_cv_target_cc_link_format = x-mi386pe || test x$grub_cv_target_cc_link_format = x-mi386pep ; then
>     TARGET_APPLE_LINKER=0
> @@ -1461,7 +1462,8 @@ elif test x$grub_cv_target_cc_link_format = x-mi386pe || test x$grub_cv_target_c
>     TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/i386-cygwin-img.lds"
>     TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT}"
>     TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/i386-cygwin-img.lds"
> -  TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"
> +  TARGET_IMG_BASE_LDOPT=

This change is a mistake. I'll fix and resend this patch.

Regards,
Nicholas Vinson

> +  TARGET_IMG_BASE_LDOPT_ARG_SEP=","
>     TARGET_IMG_CFLAGS=
>   else
>     TARGET_APPLE_LINKER=0
> @@ -1469,7 +1471,16 @@ else
>     TARGET_IMG_LDSCRIPT=
>     TARGET_IMG_LDFLAGS='-Wl,-N'
>     TARGET_IMG_LDFLAGS_AC='-Wl,-N'
> -  TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"
> +  if test "x$target_cpu-$platform" != "xi386-pc"; then
> +    TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"
> +    TARGET_IMG_BASE_LDOPT_ARG_SEP=","
> +  else
> +    TARGET_IMG_BASE_LDOPT="-Wl,--defsym,_grub_text_base"
> +    TARGET_IMG_BASE_LDOPT_ARG_SEP="="
> +    TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/i386-pc-kernel.lds"
> +    TARGET_IMG_LDFLAGS="${TARGET_IMG_LDFLAGS} -Wl,-T${TARGET_IMG_LDSCRIPT}"
> +    TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/i386-pc-kernel.lds"
> +  fi
>     TARGET_IMG_CFLAGS=
>   fi
>   
> @@ -1802,7 +1813,18 @@ if test "x$target_cpu" = xi386; then
>     if test "$platform" != emu && test "x$TARGET_APPLE_LINKER" != x1 ; then
>       if test ! -z "$TARGET_IMG_LDSCRIPT"; then
>         # Check symbols provided by linker script.
> -      CFLAGS="$TARGET_CFLAGS -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${TARGET_IMG_BASE_LDOPT},0x8000"
> +      target_img_base_ld="${TARGET_IMG_BASE_LDOPT}"
> +      case "$target_img_base_ld" in
> +        *_grub_text_base)
> +          target_img_base_ld="${target_img_base_ld}="
> +        ;;
> +        *)
> +          target_img_base_ld="${target_img_base_ld},"
> +        ;;
> +      esac
> +      target_img_base_ld="${target_img_base_ld}0x8000"
> +      CFLAGS="$TARGET_CFLAGS -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${target_img_base_ld}"
> +      target_img_base_ld=""
>       fi
>       grub_CHECK_BSS_START_SYMBOL
>       grub_CHECK_END_SYMBOL
> @@ -2404,6 +2426,7 @@ AC_SUBST(TARGET_CCASFLAGS)
>   AC_SUBST(TARGET_IMG_LDFLAGS)
>   AC_SUBST(TARGET_IMG_CFLAGS)
>   AC_SUBST(TARGET_IMG_BASE_LDOPT)
> +AC_SUBST(TARGET_IMG_BASE_LDOPT_ARG_SEP)
>   AC_SUBST(TARGET_APPLE_LINKER)
>   
>   AC_SUBST(HOST_CFLAGS)


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v3 7/9] [corrected] configure: drop -Ttext checks for i386-pc
@ 2026-02-14  1:27   ` Nicholas Vinson
  0 siblings, 0 replies; 18+ messages in thread
From: Nicholas Vinson @ 2026-02-14  1:27 UTC (permalink / raw)
  To: grub-devel, dkiper, floppym; +Cc: Nicholas Vinson

The i386-pc target now uses a linker script, so -Ttext is no longer
required.

Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
---
 acinclude.m4 | 13 ++++++++++++-
 configure.ac | 29 ++++++++++++++++++++++++++---
 2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index fa7840f09..478aab6d3 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -93,7 +93,18 @@ else
 fi
 grub_cv_prog_objcopy_absolute=yes
 for link_addr in 0x2000 0x8000 0x7C00; do
-  if AC_TRY_COMMAND([${CC-cc} ${TARGET_CFLAGS} ${TARGET_LDFLAGS} -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${TARGET_IMG_BASE_LDOPT},$link_addr conftest.o -o conftest.exec]); then :
+
+  target_img_base_ld="${TARGET_IMG_BASE_LDOPT}"
+  case "$target_img_base_ld" in
+    *_grub_text_base)
+      target_img_base_ld="${target_img_base_ld}=$link_addr"
+    ;;
+    *)
+      target_img_base_ld="${target_img_base_ld},$link_addr"
+    ;;
+  esac
+
+  if AC_TRY_COMMAND([${CC-cc} ${TARGET_CFLAGS} ${TARGET_LDFLAGS} -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${target_img_base_ld} conftest.o -o conftest.exec]); then :
   else
     AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr])
   fi
diff --git a/configure.ac b/configure.ac
index 3106bb11d..4febd084d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1454,6 +1454,7 @@ if test x$grub_cv_target_cc_link_format = x-arch,i386 || test x$grub_cv_target_c
    TARGET_IMG_LDFLAGS='-nostdlib -static -Wl,-preload -Wl,-segalign,20'
    TARGET_IMG_LDFLAGS_AC='-nostdlib -static -Wl,-preload -Wl,-segalign,20'
    TARGET_IMG_BASE_LDOPT="-Wl,-image_base"
+   TARGET_IMG_BASE_LDOPT_ARG_SEP=","
    TARGET_LDFLAGS_OLDMAGIC=""
 elif test x$grub_cv_target_cc_link_format = x-mi386pe || test x$grub_cv_target_cc_link_format = x-mi386pep ; then
   TARGET_APPLE_LINKER=0
@@ -1461,7 +1462,8 @@ elif test x$grub_cv_target_cc_link_format = x-mi386pe || test x$grub_cv_target_c
   TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/i386-cygwin-img.lds"
   TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT}"
   TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/i386-cygwin-img.lds"
   TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"
+  TARGET_IMG_BASE_LDOPT_ARG_SEP=","
   TARGET_IMG_CFLAGS=
 else
   TARGET_APPLE_LINKER=0
@@ -1469,7 +1471,16 @@ else
   TARGET_IMG_LDSCRIPT=
   TARGET_IMG_LDFLAGS='-Wl,-N'
   TARGET_IMG_LDFLAGS_AC='-Wl,-N'
-  TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"
+  if test "x$target_cpu-$platform" != "xi386-pc"; then
+    TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"
+    TARGET_IMG_BASE_LDOPT_ARG_SEP=","
+  else
+    TARGET_IMG_BASE_LDOPT="-Wl,--defsym,_grub_text_base"
+    TARGET_IMG_BASE_LDOPT_ARG_SEP="="
+    TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/i386-pc-kernel.lds"
+    TARGET_IMG_LDFLAGS="${TARGET_IMG_LDFLAGS} -Wl,-T${TARGET_IMG_LDSCRIPT}"
+    TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/i386-pc-kernel.lds"
+  fi
   TARGET_IMG_CFLAGS=
 fi
 
@@ -1802,7 +1813,18 @@ if test "x$target_cpu" = xi386; then
   if test "$platform" != emu && test "x$TARGET_APPLE_LINKER" != x1 ; then
     if test ! -z "$TARGET_IMG_LDSCRIPT"; then
       # Check symbols provided by linker script.
-      CFLAGS="$TARGET_CFLAGS -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${TARGET_IMG_BASE_LDOPT},0x8000"
+      target_img_base_ld="${TARGET_IMG_BASE_LDOPT}"
+      case "$target_img_base_ld" in
+        *_grub_text_base)
+          target_img_base_ld="${target_img_base_ld}="
+        ;;
+        *)
+          target_img_base_ld="${target_img_base_ld},"
+        ;;
+      esac
+      target_img_base_ld="${target_img_base_ld}0x8000"
+      CFLAGS="$TARGET_CFLAGS -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${target_img_base_ld}"
+      target_img_base_ld=""
     fi
     grub_CHECK_BSS_START_SYMBOL
     grub_CHECK_END_SYMBOL
@@ -2404,6 +2426,7 @@ AC_SUBST(TARGET_CCASFLAGS)
 AC_SUBST(TARGET_IMG_LDFLAGS)
 AC_SUBST(TARGET_IMG_CFLAGS)
 AC_SUBST(TARGET_IMG_BASE_LDOPT)
+AC_SUBST(TARGET_IMG_BASE_LDOPT_ARG_SEP)
 AC_SUBST(TARGET_APPLE_LINKER)
 
 AC_SUBST(HOST_CFLAGS)
-- 
2.53.0


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 1/9] i386/pc/int.h: conditionally apply regparm attr.
  2026-02-14  1:05 ` [PATCH v3 1/9] i386/pc/int.h: conditionally apply regparm attr Nicholas Vinson
@ 2026-02-14  7:20   ` Vladimir 'phcoder' Serbinenko
  0 siblings, 0 replies; 18+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2026-02-14  7:20 UTC (permalink / raw)
  To: The development of GNU GRUB


[-- Attachment #1.1: Type: text/plain, Size: 1563 bytes --]

Entire function is undefined on non-i386 and even there should only be
called on i386-pc. Please surround the entire function definition with
right ifdef rather than just the attribute.

Regards
Vladimir 'phcoder' Serbinenko

Le sam. 14 févr. 2026, 04:07, Nicholas Vinson <nvinson234@gmail.com> a
écrit :

> Modern compilers are becoming more strict and are starting to warn when
> certain attributs are ignored. The regparam attribute is such an
> attribute.
>
> Update the code so the regparam attribute is only appled when building
> against i386 targets as that is the only scenario when it is not
> ignored.
>
> Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
> ---
>  include/grub/i386/pc/int.h | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/include/grub/i386/pc/int.h b/include/grub/i386/pc/int.h
> index a60104001..4b569ca25 100644
> --- a/include/grub/i386/pc/int.h
> +++ b/include/grub/i386/pc/int.h
> @@ -24,7 +24,10 @@
>
>  void EXPORT_FUNC (grub_bios_interrupt) (grub_uint8_t intno,
>                                         struct grub_bios_int_registers
> *regs)
> -     __attribute__ ((regparm(3)));
> +#if defined(__i386__) && !defined(__x86_64__)
> +     __attribute__ ((regparm(3)))
> +#endif
> +;
>
>  #ifdef GRUB_MACHINE_PCBIOS
>  extern struct grub_i386_idt *EXPORT_VAR(grub_realidt);
> --
> 2.53.0
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>

[-- Attachment #1.2: Type: text/html, Size: 2298 bytes --]

[-- Attachment #2: Type: text/plain, Size: 141 bytes --]

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 4/9] Revert "configure: Print a more helpful error if autoconf-archive is not installed"
  2026-02-14  1:05 ` [PATCH v3 4/9] Revert "configure: Print a more helpful error if autoconf-archive is not installed" Nicholas Vinson
@ 2026-02-14  7:21   ` Vladimir 'phcoder' Serbinenko
  2026-02-14 12:15     ` Nicholas Vinson
  0 siblings, 1 reply; 18+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2026-02-14  7:21 UTC (permalink / raw)
  To: The development of GNU GRUB


[-- Attachment #1.1: Type: text/plain, Size: 1241 bytes --]

Can you explain why?

Regards
Vladimir 'phcoder' Serbinenko

Le sam. 14 févr. 2026, 04:06, Nicholas Vinson <nvinson234@gmail.com> a
écrit :

> This reverts commit ac042f3f58d33ce9cd5ff61750f06da1a1d7b0eb.
>
> Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
> ---
>  configure.ac | 5 -----
>  1 file changed, 5 deletions(-)
>
> diff --git a/configure.ac b/configure.ac
> index 2827ae2c1..dfef2e278 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -1792,11 +1792,6 @@ LIBS=""
>  # Defined in acinclude.m4.
>  grub_ASM_USCORE
>  grub_PROG_TARGET_CC
> -
> -# The error message produced by autoconf if autoconf-archive is not
> installed is
> -# quite misleading and not very helpful. So, try point people in the
> right direction.
> -m4_ifndef([AX_CHECK_LINK_FLAG], [m4_fatal([autoconf-archive is missing.
> You must install it to generate the configure script.])])
> -
>  if test "x$TARGET_APPLE_LINKER" != x1 ; then
>  AX_CHECK_LINK_FLAG([-Wl,--image-base,0x400000],
>      [TARGET_IMG_BASE_LDOPT="-Wl,--image-base"],
> --
> 2.53.0
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>

[-- Attachment #1.2: Type: text/html, Size: 2348 bytes --]

[-- Attachment #2: Type: text/plain, Size: 141 bytes --]

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 4/9] Revert "configure: Print a more helpful error if autoconf-archive is not installed"
  2026-02-14  7:21   ` Vladimir 'phcoder' Serbinenko
@ 2026-02-14 12:15     ` Nicholas Vinson
  0 siblings, 0 replies; 18+ messages in thread
From: Nicholas Vinson @ 2026-02-14 12:15 UTC (permalink / raw)
  To: grub-devel

On 2/14/26 02:21, Vladimir 'phcoder' Serbinenko wrote:
> Can you explain why?

In my original attempt to fix the problem, I added the 
AX_CHECK_LINK_FLAG macro to configure.ac.

In this patch series, the first thing I do is undo the commits I added 
with my original attempt. I also undo commits that were added as a 
result of that attempt (such as this one).

The root cause is the same; the macro grub_PROG_OBJCOPY_ABSOLUTE is run 
unconditionally, and it tries to place .text at low addresses. ld.lld-21 
does not allow that by default, so it fails to link.

I add a modified version of the original solution back with patch 8 of 
this series to make grub_PROG_OBJCOPY_ABSOLUTE happy. Ideally, I would 
only execute that macro for scenarios that need objcopy. That said, I 
don't know what those scenarios would be other than i386-pc.

Moreover, this commit hides the real error message for one that can end 
up being just as confusing. To avoid re-adding this potentially 
problematic error message, I opted to add the macro directly to GRUB's 
sources instead of reintroducing the autoconf-archive dependency.

Thanks,
Nicholas Vinson

> 
> Regards
> Vladimir 'phcoder' Serbinenko
> 
> Le sam. 14 févr. 2026, 04:06, Nicholas Vinson <nvinson234@gmail.com 
> <mailto:nvinson234@gmail.com>> a écrit :
> 
>     This reverts commit ac042f3f58d33ce9cd5ff61750f06da1a1d7b0eb.
> 
>     Signed-off-by: Nicholas Vinson <nvinson234@gmail.com
>     <mailto:nvinson234@gmail.com>>
>     ---
>     configure.ac <http://configure.ac> | 5 -----
>       1 file changed, 5 deletions(-)
> 
>     diff --git a/configure.ac <http://configure.ac> b/configure.ac
>     <http://configure.ac>
>     index 2827ae2c1..dfef2e278 100644
>     --- a/configure.ac <http://configure.ac>
>     +++ b/configure.ac <http://configure.ac>
>     @@ -1792,11 +1792,6 @@ LIBS=""
>       # Defined in acinclude.m4.
>       grub_ASM_USCORE
>       grub_PROG_TARGET_CC
>     -
>     -# The error message produced by autoconf if autoconf-archive is not
>     installed is
>     -# quite misleading and not very helpful. So, try point people in
>     the right direction.
>     -m4_ifndef([AX_CHECK_LINK_FLAG], [m4_fatal([autoconf-archive is
>     missing. You must install it to generate the configure script.])])
>     -
>       if test "x$TARGET_APPLE_LINKER" != x1 ; then
>       AX_CHECK_LINK_FLAG([-Wl,--image-base,0x400000],
>           [TARGET_IMG_BASE_LDOPT="-Wl,--image-base"],
>     -- 
>     2.53.0
> 
> 
>     _______________________________________________
>     Grub-devel mailing list
>     Grub-devel@gnu.org <mailto:Grub-devel@gnu.org>
>     https://lists.gnu.org/mailman/listinfo/grub-devel <https://
>     lists.gnu.org/mailman/listinfo/grub-devel>
> 
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 2/9] grub-core: Update kernel image generation
  2026-02-14  1:05 ` [PATCH v3 2/9] grub-core: Update kernel image generation Nicholas Vinson
@ 2026-02-16 15:33   ` Daniel Kiper
  0 siblings, 0 replies; 18+ messages in thread
From: Daniel Kiper @ 2026-02-16 15:33 UTC (permalink / raw)
  To: Nicholas Vinson; +Cc: grub-devel, floppym

On Fri, Feb 13, 2026 at 08:05:02PM -0500, Nicholas Vinson wrote:
> The i386-pc kernel image fails to build because of changes made to
> address ld.lld-21 and newer linking issues. Specifically, with
> ld.lld-21, if you try to set the text section address below image base
> address when linking a non-relocatable binary, ld.lld wil fail to link.
>
> Switching to using a customized linker script solves the issue and is a
> more robost solution to supporting multiple linkers than attempting to
> find a set of command-line flags that satisified all supported linkers
> and links the kernel properly. In the worst case, continued use of
> command-line flags could result in having to create code branches to
> support various linkers.
>
> For example, when dealing with just ld.bfd and ld.lld, the behavioral
> differences between the two made finding a proper subset of flags that
> worked impossible. The previous attempt dropped -Ttext for --image-base,
> which has been proven not to work. The simplest correction,
> -Wl,--image-base=0 -Wl,-Ttext, did not work because that option resulted
> in a GRUB kernel that entered into a tight infinite refresh loop.
>
> Moreover, ld.lld does not order the sections the same way ld.bfd does,
> and that results in object files with gaps or holes when sections are
> stripped. I suspect, but did not investigate, that this plays a role in
> the infinite refresh loop I mentioned earlier.
>
> The easiest way to resolve all this is to use customized linker scripts.
> These scripts, by default, override any default configuration the linker
> would otherwise impose, allow for complete control in aligning sections,
> and allows GRUB to specify where in the load segment each section goes.
>
> This change does require linkers to support the --defsym flag, which
> requires its argument to be of the form 'sym=address' as 'sym address'
> is not supported.
>
> Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
> ---
>  conf/Makefile.extra-dist    |  1 +
>  conf/i386-pc-kernel.lds     | 51 +++++++++++++++++++++++++++++++++++++
>  grub-core/Makefile.core.def | 31 +++++++++++-----------
>  3 files changed, 68 insertions(+), 15 deletions(-)
>  create mode 100644 conf/i386-pc-kernel.lds
>
> diff --git a/conf/Makefile.extra-dist b/conf/Makefile.extra-dist
> index d22b6c862..892df8208 100644
> --- a/conf/Makefile.extra-dist
> +++ b/conf/Makefile.extra-dist
> @@ -17,6 +17,7 @@ EXTRA_DIST += docs/grub.cfg
>  EXTRA_DIST += docs/osdetect.cfg
>
>  EXTRA_DIST += conf/i386-cygwin-img-ld.sc
> +EXTRA_DIST += conf/i386-pc-kernel.lds
>
>  EXTRA_DIST += grub-core/Makefile.core.def
>  EXTRA_DIST += grub-core/Makefile.gcry.def
> diff --git a/conf/i386-pc-kernel.lds b/conf/i386-pc-kernel.lds
> new file mode 100644
> index 000000000..d40c7736c
> --- /dev/null
> +++ b/conf/i386-pc-kernel.lds
> @@ -0,0 +1,51 @@
> +ENTRY(_start)
> +
> +/*
> + * Align sections to a 16-byte boundary. This guarantees ABI compatibility with
> + * C generated code
> + */
> +SECTION_ALIGN = 0x10;
> +
> +PHDRS {
> +    text PT_LOAD FLAGS(7) /* PF_R | PF_W | PF_X */;
> +}
> +
> +SECTIONS
> +{
> +    /*
> +     * Set section alignment to 1. This allows sections to be aligned without
> +     * creating holes in the VMA space or gaps in the file.
> +     */
> +    . = _grub_text_base;
> +    .text ALIGN(0x1) : {
> +        _start = .;
> +        *(.text .text.*)
> +        . = ALIGN(SECTION_ALIGN);
> +    } :text
> +    .rodata ALIGN(0x1) : {
> +        *(.rodata .rodata.*)
> +        . = ALIGN(SECTION_ALIGN);
> +    } :text
> +    .module_license ALIGN(0x1) : {
> +        *(.module_license)
> +        . = ALIGN(SECTION_ALIGN);
> +    } :text
> +    .data ALIGN(0x1) : {
> +        *(.data .data.*)
> +        . = ALIGN(SECTION_ALIGN);
> +        _edata = .;
> +    } :text
> +    .bss ALIGN(0x1) : {
> +        __bss_start = .;
> +        *(.bss .bss.*)
> +        *(COMMON)
> +        . = ALIGN(SECTION_ALIGN);
> +        _end = .;
> +    } :text
> +    /DISCARD/ : {
> +        *(.interp)
> +        *(.note*)
> +        *(.comment)
> +        *(.build-id)
> +    }
> +}
> diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
> index 0cf155128..1a91e53d6 100644
> --- a/grub-core/Makefile.core.def
> +++ b/grub-core/Makefile.core.def
> @@ -10,6 +10,7 @@ transform_data = {
>    installdir = noinst;
>    name = genmod.sh;
>    common = genmod.sh.in;
> +  i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)';

I think everything below belongs to patch #7.

>  };
>
>  transform_data = {
> @@ -82,21 +83,21 @@ kernel = {
>    riscv64_efi_stripflags   = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version -R .eh_frame';
>
>    i386_pc_ldflags          = '$(TARGET_IMG_LDFLAGS)';
> -  i386_pc_ldflags          = '$(TARGET_IMG_BASE_LDOPT),0x9000';
> +  i386_pc_ldflags          = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0x9000';
>    i386_qemu_ldflags        = '$(TARGET_IMG_LDFLAGS)';
> -  i386_qemu_ldflags        = '$(TARGET_IMG_BASE_LDOPT),0x9000';
> +  i386_qemu_ldflags        = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0x9000';
>    i386_coreboot_ldflags    = '$(TARGET_IMG_LDFLAGS)';
> -  i386_coreboot_ldflags    = '$(TARGET_IMG_BASE_LDOPT),0x9000';
> +  i386_coreboot_ldflags    = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0x9000';
>    i386_multiboot_ldflags   = '$(TARGET_IMG_LDFLAGS)';
> -  i386_multiboot_ldflags   = '$(TARGET_IMG_BASE_LDOPT),0x9000';
> +  i386_multiboot_ldflags   = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0x9000';
>    i386_ieee1275_ldflags    = '$(TARGET_IMG_LDFLAGS)';
> -  i386_ieee1275_ldflags    = '$(TARGET_IMG_BASE_LDOPT),0x10000';
> +  i386_ieee1275_ldflags    = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0x10000';
>    i386_xen_ldflags         = '$(TARGET_IMG_LDFLAGS)';
> -  i386_xen_ldflags         = '$(TARGET_IMG_BASE_LDOPT),0';
> +  i386_xen_ldflags         = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0';
>    x86_64_xen_ldflags       = '$(TARGET_IMG_LDFLAGS)';
>    x86_64_xen_ldflags       = '$(TARGET_IMG_BASE_LDOPT),0';
>    i386_xen_pvh_ldflags     = '$(TARGET_IMG_LDFLAGS)';
> -  i386_xen_pvh_ldflags     = '$(TARGET_IMG_BASE_LDOPT),0x100000';
> +  i386_xen_pvh_ldflags     = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0x100000';
>
>    mips_loongson_ldflags    = '-Wl,-Ttext,0x80200000';
>    powerpc_ieee1275_ldflags = '-Wl,-Ttext,0x200000';
> @@ -450,10 +451,10 @@ image = {
>    sparc64_ieee1275 = boot/sparc64/ieee1275/boot.S;
>
>    i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)';
> -  i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x7C00';
> +  i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0x7C00';
>
>    i386_qemu_ldflags = '$(TARGET_IMG_LDFLAGS)';
> -  i386_qemu_ldflags = '$(TARGET_IMG_BASE_LDOPT),$(GRUB_BOOT_MACHINE_LINK_ADDR)';
> +  i386_qemu_ldflags = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)$(GRUB_BOOT_MACHINE_LINK_ADDR)';
>    i386_qemu_ccasflags = '-DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR)';
>
>    /* The entry point for a.out binaries on sparc64 starts
> @@ -478,7 +479,7 @@ image = {
>    cppflags = '-DHYBRID_BOOT=1';
>
>    i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)';
> -  i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x7C00';
> +  i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0x7C00';
>
>    objcopyflags = '-O binary';
>    enable = i386_pc;
> @@ -489,7 +490,7 @@ image = {
>
>    i386_pc = boot/i386/pc/cdboot.S;
>    i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)';
> -  i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x7C00';
> +  i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0x7C00';
>
>    sparc64_ieee1275 = boot/sparc64/ieee1275/boot.S;
>
> @@ -509,7 +510,7 @@ image = {
>    i386_pc = boot/i386/pc/pxeboot.S;
>
>    i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)';
> -  i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x7C00';
> +  i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0x7C00';
>
>    objcopyflags = '-O binary';
>    enable = i386_pc;
> @@ -520,7 +521,7 @@ image = {
>    i386_pc = boot/i386/pc/diskboot.S;
>
>    i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)';
> -  i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x8000';
> +  i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0x8000';
>
>    sparc64_ieee1275 = boot/sparc64/ieee1275/diskboot.S;
>    sparc64_ieee1275_ldflags = '-Wl,-Ttext=0x4200';
> @@ -536,7 +537,7 @@ image = {
>    i386_pc = boot/i386/pc/lnxboot.S;
>
>    i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)';
> -  i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x6000';
> +  i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0x6000';
>
>    objcopyflags = '-O binary';
>    enable = i386_pc;
> @@ -578,7 +579,7 @@ image = {
>    i386_pc_nodist = rs_decoder.h;
>
>    objcopyflags = '-O binary';
> -  ldflags = '$(TARGET_IMG_LDFLAGS) $(TARGET_IMG_BASE_LDOPT),0x8200';
> +  ldflags = '$(TARGET_IMG_LDFLAGS) $(TARGET_IMG_BASE_LDOPT)$(TARGET_IMG_BASE_LDOPT_ARG_SEP)0x8200';
>    enable = i386_pc;
>  };

Daniel

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 0/9] Improve ld.lld-21+ compatibility when building i386-pc target
  2026-02-14  1:05 [PATCH v3 0/9] Improve ld.lld-21+ compatibility when building i386-pc target Nicholas Vinson
                   ` (8 preceding siblings ...)
  2026-02-14  1:05 ` [PATCH v3 9/9] conf/i386-cygwin-img.lds: Update to use _grub_text_base symbol Nicholas Vinson
@ 2026-02-16 15:42 ` Daniel Kiper
  9 siblings, 0 replies; 18+ messages in thread
From: Daniel Kiper @ 2026-02-16 15:42 UTC (permalink / raw)
  To: Nicholas Vinson; +Cc: grub-devel, floppym

On Fri, Feb 13, 2026 at 08:05:00PM -0500, Nicholas Vinson wrote:
> Starting with ld.llvm-21, any attempt create a non-relocatable binary and set
> one more secton addresses below 0x400000 results in a linker error. Furthermore,
> the differences between ld.bfd and ld.lld made finding a proper set of
> command-line flags tht worked with both linkers and bypass the image base
> address restriction difficult. Therefore, the approach of using a custom linker
> script was adopted to solve the issue.
>
> This approach was tested using:
>
> ../configure CC=clang CXX=clang++ LDFLAGS="-fuse-ld=lld" TARGET_LDFLAGS="-fuse-ld=lld" --with-platform=pc
> ../configure CC=clang CXX=clang++ --with-platform=pc (both with ld.lld as the default and ld.bfd as the default)
> ../configure CC=gcc CXX=g++ --with-platform=pc
>
> and a VM was used for testing. To build the disk images the VM was booted with,
> the following scripts were used:

[...]

> In all cases, the VM successfully booted to the standard GRUB prompt.
>
> Nicholas Vinson (9):
>   i386/pc/int.h: conditionally apply regparm attr.
>   grub-core: Update kernel image generation
>   i386-cygwin-img-ld.sc -> i386-cygwin-img.lds
>   Revert "configure: Print a more helpful error if autoconf-archive is
>     not installed"
>   Revert "configure: Check linker for --image-base support"
>   Revert "INSTALL: Add note that the GNU Autoconf Archive may be needed"
>   configure: drop -Ttext checks for i386-pc
>   configure.ac: Add --image-base check for non-i386
>   conf/i386-cygwin-img.lds: Update to use _grub_text_base symbol

Still Windows builds are broken... :-(

  ./configure --build=x86_64-linux-gnu --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-platform=efi --enable-stack-protector
  [...]
  checking whether x86_64-w64-mingw32-objcopy works for absolute addresses... configure: error: x86_64-w64-mingw32-gcc cannot link at address 0x2000

The INSTALL file lists compilers packages which are needed to build GRUB
for all architectures and platforms.

Daniel

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2026-02-16 15:43 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-14  1:05 [PATCH v3 0/9] Improve ld.lld-21+ compatibility when building i386-pc target Nicholas Vinson
2026-02-14  1:05 ` [PATCH v3 1/9] i386/pc/int.h: conditionally apply regparm attr Nicholas Vinson
2026-02-14  7:20   ` Vladimir 'phcoder' Serbinenko
2026-02-14  1:05 ` [PATCH v3 2/9] grub-core: Update kernel image generation Nicholas Vinson
2026-02-16 15:33   ` Daniel Kiper
2026-02-14  1:05 ` [PATCH v3 3/9] i386-cygwin-img-ld.sc -> i386-cygwin-img.lds Nicholas Vinson
2026-02-14  1:05 ` [PATCH v3 4/9] Revert "configure: Print a more helpful error if autoconf-archive is not installed" Nicholas Vinson
2026-02-14  7:21   ` Vladimir 'phcoder' Serbinenko
2026-02-14 12:15     ` Nicholas Vinson
2026-02-14  1:05 ` [PATCH v3 5/9] Revert "configure: Check linker for --image-base support" Nicholas Vinson
2026-02-14  1:05 ` [PATCH v3 6/9] Revert "INSTALL: Add note that the GNU Autoconf Archive may be needed" Nicholas Vinson
2026-02-14  1:05 ` [PATCH v3 7/9] configure: drop -Ttext checks for i386-pc Nicholas Vinson
2026-02-14  1:27   ` [PATCH v3 7/9] [corrected] " Nicholas Vinson
2026-02-14  1:15   ` [PATCH v3 7/9] " Nicholas Vinson
2026-02-14  1:05 ` [PATCH v3 8/9] configure.ac: Add --image-base check for non-i386 Nicholas Vinson
2026-02-14  1:05 ` [PATCH v3 9/9] conf/i386-cygwin-img.lds: Update to use _grub_text_base symbol Nicholas Vinson
2026-02-14  1:08   ` Nicholas Vinson
2026-02-16 15:42 ` [PATCH v3 0/9] Improve ld.lld-21+ compatibility when building i386-pc target Daniel Kiper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.