* [PATCH v2 0/8] Improve ld.lld-21+ compatibility when building i386-pc target
@ 2026-02-10 0:43 Nicholas Vinson
2026-02-10 0:43 ` [PATCH v2 1/8] i386/pc/int.h: conditionally apply regparm attr Nicholas Vinson
` (8 more replies)
0 siblings, 9 replies; 16+ messages in thread
From: Nicholas Vinson @ 2026-02-10 0:43 UTC (permalink / raw)
To: grub-devel; +Cc: Nicholas Vinson, floppym, dkiper
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 (8):
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
C23 fixes: fix strchr() and strrchr() handling
INSTALL | 1 -
acinclude.m4 | 18 ++++---
conf/Makefile.extra-dist | 3 +-
...6-cygwin-img-ld.sc => i386-cygwin-img.lds} | 0
conf/i386-pc-kernel.lds | 51 +++++++++++++++++++
configure.ac | 42 +++++++--------
grub-core/Makefile.core.def | 24 ++++++---
grub-core/osdep/linux/ofpath.c | 14 ++---
include/grub/i386/pc/int.h | 5 +-
util/probe.c | 6 +--
util/resolve.c | 10 ++--
11 files changed, 123 insertions(+), 51 deletions(-)
rename conf/{i386-cygwin-img-ld.sc => i386-cygwin-img.lds} (100%)
create mode 100644 conf/i386-pc-kernel.lds
--
2.53.0
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2 1/8] i386/pc/int.h: conditionally apply regparm attr.
2026-02-10 0:43 [PATCH v2 0/8] Improve ld.lld-21+ compatibility when building i386-pc target Nicholas Vinson
@ 2026-02-10 0:43 ` Nicholas Vinson
2026-02-10 0:43 ` [PATCH v2 2/8] grub-core: Update kernel image generation Nicholas Vinson
` (7 subsequent siblings)
8 siblings, 0 replies; 16+ messages in thread
From: Nicholas Vinson @ 2026-02-10 0:43 UTC (permalink / raw)
To: grub-devel; +Cc: Nicholas Vinson, floppym, dkiper
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] 16+ messages in thread
* [PATCH v2 2/8] grub-core: Update kernel image generation
2026-02-10 0:43 [PATCH v2 0/8] Improve ld.lld-21+ compatibility when building i386-pc target Nicholas Vinson
2026-02-10 0:43 ` [PATCH v2 1/8] i386/pc/int.h: conditionally apply regparm attr Nicholas Vinson
@ 2026-02-10 0:43 ` Nicholas Vinson
2026-02-10 0:43 ` [PATCH v2 3/8] i386-cygwin-img-ld.sc -> i386-cygwin-img.lds Nicholas Vinson
` (6 subsequent siblings)
8 siblings, 0 replies; 16+ messages in thread
From: Nicholas Vinson @ 2026-02-10 0:43 UTC (permalink / raw)
To: grub-devel; +Cc: Nicholas Vinson, floppym, dkiper
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>
---
| 1 +
conf/i386-pc-kernel.lds | 51 +++++++++++++++++++++++++++++++++++++
grub-core/Makefile.core.def | 24 +++++++++++------
3 files changed, 68 insertions(+), 8 deletions(-)
create mode 100644 conf/i386-pc-kernel.lds
--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..99ad557f7 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,7 +83,8 @@ 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 = '-Wl,-T$(top_srcdir)/conf/i386-pc-kernel.lds';
+ i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT)=0x9000';
i386_qemu_ldflags = '$(TARGET_IMG_LDFLAGS)';
i386_qemu_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x9000';
i386_coreboot_ldflags = '$(TARGET_IMG_LDFLAGS)';
@@ -450,7 +452,8 @@ 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 = '-Wl,-T$(top_srcdir)/conf/i386-pc-kernel.lds';
+ i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT)=0x7C00';
i386_qemu_ldflags = '$(TARGET_IMG_LDFLAGS)';
i386_qemu_ldflags = '$(TARGET_IMG_BASE_LDOPT),$(GRUB_BOOT_MACHINE_LINK_ADDR)';
@@ -478,7 +481,8 @@ image = {
cppflags = '-DHYBRID_BOOT=1';
i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)';
- i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x7C00';
+ i386_pc_ldflags = '-Wl,-T$(top_srcdir)/conf/i386-pc-kernel.lds';
+ i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT)=0x7C00';
objcopyflags = '-O binary';
enable = i386_pc;
@@ -489,7 +493,8 @@ 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 = '-Wl,-T$(top_srcdir)/conf/i386-pc-kernel.lds';
+ i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT)=0x7C00';
sparc64_ieee1275 = boot/sparc64/ieee1275/boot.S;
@@ -509,7 +514,8 @@ 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 = '-Wl,-T$(top_srcdir)/conf/i386-pc-kernel.lds';
+ i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT)=0x7C00';
objcopyflags = '-O binary';
enable = i386_pc;
@@ -520,7 +526,8 @@ 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 = '-Wl,-T$(top_srcdir)/conf/i386-pc-kernel.lds';
+ i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT)=0x8000';
sparc64_ieee1275 = boot/sparc64/ieee1275/diskboot.S;
sparc64_ieee1275_ldflags = '-Wl,-Ttext=0x4200';
@@ -536,7 +543,8 @@ 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 = '-Wl,-T$(top_srcdir)/conf/i386-pc-kernel.lds';
+ i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT)=0x6000';
objcopyflags = '-O binary';
enable = i386_pc;
@@ -578,7 +586,7 @@ image = {
i386_pc_nodist = rs_decoder.h;
objcopyflags = '-O binary';
- ldflags = '$(TARGET_IMG_LDFLAGS) $(TARGET_IMG_BASE_LDOPT),0x8200';
+ ldflags = '$(TARGET_IMG_LDFLAGS) -Wl,-T$(top_srcdir)/conf/i386-pc-kernel.lds $(TARGET_IMG_BASE_LDOPT)=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] 16+ messages in thread
* [PATCH v2 3/8] i386-cygwin-img-ld.sc -> i386-cygwin-img.lds
2026-02-10 0:43 [PATCH v2 0/8] Improve ld.lld-21+ compatibility when building i386-pc target Nicholas Vinson
2026-02-10 0:43 ` [PATCH v2 1/8] i386/pc/int.h: conditionally apply regparm attr Nicholas Vinson
2026-02-10 0:43 ` [PATCH v2 2/8] grub-core: Update kernel image generation Nicholas Vinson
@ 2026-02-10 0:43 ` Nicholas Vinson
2026-02-10 0:43 ` [PATCH v2 4/8] Revert "configure: Print a more helpful error if autoconf-archive is not installed" Nicholas Vinson
` (5 subsequent siblings)
8 siblings, 0 replies; 16+ messages in thread
From: Nicholas Vinson @ 2026-02-10 0:43 UTC (permalink / raw)
To: grub-devel; +Cc: Nicholas Vinson, floppym, dkiper
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>
---
| 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%)
--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] 16+ messages in thread
* [PATCH v2 4/8] Revert "configure: Print a more helpful error if autoconf-archive is not installed"
2026-02-10 0:43 [PATCH v2 0/8] Improve ld.lld-21+ compatibility when building i386-pc target Nicholas Vinson
` (2 preceding siblings ...)
2026-02-10 0:43 ` [PATCH v2 3/8] i386-cygwin-img-ld.sc -> i386-cygwin-img.lds Nicholas Vinson
@ 2026-02-10 0:43 ` Nicholas Vinson
2026-02-10 0:43 ` [PATCH v2 5/8] Revert "configure: Check linker for --image-base support" Nicholas Vinson
` (4 subsequent siblings)
8 siblings, 0 replies; 16+ messages in thread
From: Nicholas Vinson @ 2026-02-10 0:43 UTC (permalink / raw)
To: grub-devel; +Cc: Nicholas Vinson, floppym, dkiper
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] 16+ messages in thread
* [PATCH v2 5/8] Revert "configure: Check linker for --image-base support"
2026-02-10 0:43 [PATCH v2 0/8] Improve ld.lld-21+ compatibility when building i386-pc target Nicholas Vinson
` (3 preceding siblings ...)
2026-02-10 0:43 ` [PATCH v2 4/8] Revert "configure: Print a more helpful error if autoconf-archive is not installed" Nicholas Vinson
@ 2026-02-10 0:43 ` Nicholas Vinson
2026-02-10 0:43 ` [PATCH v2 6/8] Revert "INSTALL: Add note that the GNU Autoconf Archive may be needed" Nicholas Vinson
` (3 subsequent siblings)
8 siblings, 0 replies; 16+ messages in thread
From: Nicholas Vinson @ 2026-02-10 0:43 UTC (permalink / raw)
To: grub-devel; +Cc: Nicholas Vinson, floppym, dkiper
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] 16+ messages in thread
* [PATCH v2 6/8] Revert "INSTALL: Add note that the GNU Autoconf Archive may be needed"
2026-02-10 0:43 [PATCH v2 0/8] Improve ld.lld-21+ compatibility when building i386-pc target Nicholas Vinson
` (4 preceding siblings ...)
2026-02-10 0:43 ` [PATCH v2 5/8] Revert "configure: Check linker for --image-base support" Nicholas Vinson
@ 2026-02-10 0:43 ` Nicholas Vinson
2026-02-10 0:43 ` [PATCH v2 7/8] configure: drop -Ttext checks for i386-pc Nicholas Vinson
` (2 subsequent siblings)
8 siblings, 0 replies; 16+ messages in thread
From: Nicholas Vinson @ 2026-02-10 0:43 UTC (permalink / raw)
To: grub-devel; +Cc: Nicholas Vinson, floppym, dkiper
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] 16+ messages in thread
* [PATCH v2 7/8] configure: drop -Ttext checks for i386-pc
2026-02-10 0:43 [PATCH v2 0/8] Improve ld.lld-21+ compatibility when building i386-pc target Nicholas Vinson
` (5 preceding siblings ...)
2026-02-10 0:43 ` [PATCH v2 6/8] Revert "INSTALL: Add note that the GNU Autoconf Archive may be needed" Nicholas Vinson
@ 2026-02-10 0:43 ` Nicholas Vinson
2026-02-10 0:43 ` [PATCH v2 8/8] C23 fixes: fix strchr() and strrchr() handling Nicholas Vinson
2026-02-10 15:47 ` [PATCH v2 0/8] Improve ld.lld-21+ compatibility when building i386-pc target Daniel Kiper
8 siblings, 0 replies; 16+ messages in thread
From: Nicholas Vinson @ 2026-02-10 0:43 UTC (permalink / raw)
To: grub-devel; +Cc: Nicholas Vinson, floppym, dkiper
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 | 21 +++++++++++++++++++--
2 files changed, 31 insertions(+), 3 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..3ccb0e6ef 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1469,7 +1469,13 @@ 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"
+ else
+ TARGET_IMG_BASE_LDOPT="-Wl,--defsym,_grub_text_base"
+ TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/i386-pc-kernel.lds"
+ TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/i386-pc-kernel.lds"
+ fi
TARGET_IMG_CFLAGS=
fi
@@ -1802,7 +1808,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
--
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] 16+ messages in thread
* [PATCH v2 8/8] C23 fixes: fix strchr() and strrchr() handling
2026-02-10 0:43 [PATCH v2 0/8] Improve ld.lld-21+ compatibility when building i386-pc target Nicholas Vinson
` (6 preceding siblings ...)
2026-02-10 0:43 ` [PATCH v2 7/8] configure: drop -Ttext checks for i386-pc Nicholas Vinson
@ 2026-02-10 0:43 ` Nicholas Vinson
2026-02-10 15:47 ` [PATCH v2 0/8] Improve ld.lld-21+ compatibility when building i386-pc target Daniel Kiper
8 siblings, 0 replies; 16+ messages in thread
From: Nicholas Vinson @ 2026-02-10 0:43 UTC (permalink / raw)
To: grub-devel; +Cc: Nicholas Vinson, floppym, dkiper
With C23, strchr() and strrchr() can now return return constant char *
*if* the first argument to the function is a const char *.
This change is implemented in glibc-2.43.
Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
---
grub-core/osdep/linux/ofpath.c | 14 ++++++++------
util/probe.c | 6 +++---
util/resolve.c | 10 +++++-----
3 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/grub-core/osdep/linux/ofpath.c b/grub-core/osdep/linux/ofpath.c
index 24a4d5c8d..1ec5098ab 100644
--- a/grub-core/osdep/linux/ofpath.c
+++ b/grub-core/osdep/linux/ofpath.c
@@ -488,8 +488,10 @@ check_hba_identifiers (const char *sysfs_path, int *vendor, int *device_id)
static void
check_sas (const char *sysfs_path, int *tgt, unsigned long int *sas_address)
{
- char *ed = strstr (sysfs_path, "end_device");
- char *p, *q, *path;
+ const char *ed = strstr (sysfs_path, "end_device");
+ int ed_len;
+ const char *q;
+ char *p, *path;
char phy[21];
int fd;
size_t path_size;
@@ -506,12 +508,12 @@ check_sas (const char *sysfs_path, int *tgt, unsigned long int *sas_address)
q = ed;
while (*q && *q != '/')
q++;
- *q = '\0';
+ ed_len = (int)(q - ed);
- path_size = (strlen (p) + strlen (ed)
+ path_size = (strlen (p) + ed_len
+ sizeof ("%s/sas_device/%s/phy_identifier"));
path = xmalloc (path_size);
- snprintf (path, path_size, "%s/sas_device/%s/phy_identifier", p, ed);
+ snprintf (path, path_size, "%s/sas_device/%.*s/phy_identifier", p, ed_len, ed);
fd = open (path, O_RDONLY);
if (fd < 0)
grub_util_error (_("cannot open `%s': %s"), path, strerror (errno));
@@ -524,7 +526,7 @@ check_sas (const char *sysfs_path, int *tgt, unsigned long int *sas_address)
sscanf (phy, "%d", tgt);
- snprintf (path, path_size, "%s/sas_device/%s/sas_address", p, ed);
+ snprintf (path, path_size, "%s/sas_device/%.*s/sas_address", p, ed_len, ed);
fd = open (path, O_RDONLY);
if (fd < 0)
grub_util_error (_("cannot open `%s': %s"), path, strerror (errno));
diff --git a/util/probe.c b/util/probe.c
index 81d91cf59..a9158d640 100644
--- a/util/probe.c
+++ b/util/probe.c
@@ -70,7 +70,7 @@ char *
grub_util_guess_bios_drive (const char *orig_path)
{
char *canon;
- char *ptr;
+ const char *ptr;
canon = grub_canonicalize_file_name (orig_path);
if (!canon)
return NULL;
@@ -99,7 +99,7 @@ char *
grub_util_guess_efi_drive (const char *orig_path)
{
char *canon;
- char *ptr;
+ const char *ptr;
canon = grub_canonicalize_file_name (orig_path);
if (!canon)
return NULL;
@@ -128,7 +128,7 @@ char *
grub_util_guess_baremetal_drive (const char *orig_path)
{
char *canon;
- char *ptr;
+ const char *ptr;
canon = grub_canonicalize_file_name (orig_path);
if (!canon)
return NULL;
diff --git a/util/resolve.c b/util/resolve.c
index b6e26312f..254379195 100644
--- a/util/resolve.c
+++ b/util/resolve.c
@@ -138,12 +138,12 @@ read_dep_list (FILE *fp)
static char *
get_module_name (const char *str)
{
- char *base;
- char *ext;
+ const char *base;
+ const char *ext;
base = strrchr (str, '/');
if (! base)
- base = (char *) str;
+ base = str;
else
base++;
@@ -164,9 +164,9 @@ get_module_name (const char *str)
static char *
get_module_path (const char *prefix, const char *str)
{
- char *dir;
+ const char *dir;
char *base;
- char *ext;
+ const char *ext;
char *ret;
ext = strrchr (str, '.');
--
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] 16+ messages in thread
* Re: [PATCH v2 0/8] Improve ld.lld-21+ compatibility when building i386-pc target
2026-02-10 0:43 [PATCH v2 0/8] Improve ld.lld-21+ compatibility when building i386-pc target Nicholas Vinson
` (7 preceding siblings ...)
2026-02-10 0:43 ` [PATCH v2 8/8] C23 fixes: fix strchr() and strrchr() handling Nicholas Vinson
@ 2026-02-10 15:47 ` Daniel Kiper
2026-02-10 23:27 ` Nicholas Vinson
2026-02-11 18:49 ` Daniel Kiper
8 siblings, 2 replies; 16+ messages in thread
From: Daniel Kiper @ 2026-02-10 15:47 UTC (permalink / raw)
To: Nicholas Vinson; +Cc: grub-devel, floppym
On Mon, Feb 09, 2026 at 07:43:28PM -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 (8):
> 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
For all these patches Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>...
> C23 fixes: fix strchr() and strrchr() handling
It seems to me that this patch does more than commit message says.
I think it has to be split into more parts or commit message has to be
improved.
Daniel
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 0/8] Improve ld.lld-21+ compatibility when building i386-pc target
2026-02-10 15:47 ` [PATCH v2 0/8] Improve ld.lld-21+ compatibility when building i386-pc target Daniel Kiper
@ 2026-02-10 23:27 ` Nicholas Vinson
2026-02-11 17:49 ` Daniel Kiper
` (2 more replies)
2026-02-11 18:49 ` Daniel Kiper
1 sibling, 3 replies; 16+ messages in thread
From: Nicholas Vinson @ 2026-02-10 23:27 UTC (permalink / raw)
To: Daniel Kiper; +Cc: grub-devel, floppym
On 2/10/26 10:47, Daniel Kiper wrote:
> On Mon, Feb 09, 2026 at 07:43:28PM -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 (8):
>> 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
>
> For all these patches Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>...
>
>> C23 fixes: fix strchr() and strrchr() handling
>
> It seems to me that this patch does more than commit message says.
> I think it has to be split into more parts or commit message has to be
> improved.
I admit the message is a bit terse, but I kept the changes to a minimum.
I did, however, forget to mention strstr().
Put simply, with C23, if the first argument to strstr(), strchr(), or
strrchar() is a const char *, the result is a const char *. C23 also
made this change to about 9 or so other functions.
As a result, most of the changes were just changing a variable from
'char *' to 'const char *'.
The changes for ofpath.c are a bit more involved because the original
code would modify the string 'ed' pointed to. With C23, ed needs to be a
'const char *' because sysfs_path is a 'const char *'. This also means
that the line "*q = '\0'" is no longer valid because you cannot safely
modify a const char string.
I saw two options to fix this, the first was to modify the line to be q
= strndup(...);, add the requisite error checking, and then make sure to
free q just before every subsequent return. The second option, is what I
did, find the difference between q and ed, save it off, and then replace
the strlen(ed) calls with that difference.
I believe the second approach is the better of the two. It did have the
ancillary effect of updating a few snprintf() calls and the path_size
calculation; however, these changes are required with this approach.
If you'd prefer, I can re-submit patch 8 with these details in the
commit message. Alternatively, if you would prefer the strndup()
approach, I will respin this patch series without patch 8, and then
submit a re-worked C23 patch as a separate request.
Thanks,
Nicholas Vinson
>
> Daniel
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 0/8] Improve ld.lld-21+ compatibility when building i386-pc target
2026-02-10 23:27 ` Nicholas Vinson
@ 2026-02-11 17:49 ` Daniel Kiper
2026-02-12 7:46 ` [PATCH] Fix build with glibc 2.43 after new ISO C23 changes Radoslav Kolev via Grub-devel
2026-02-12 7:53 ` [PATCH v2 0/8] Improve ld.lld-21+ compatibility when building i386-pc target Radoslav Kolev via Grub-devel
2 siblings, 0 replies; 16+ messages in thread
From: Daniel Kiper @ 2026-02-11 17:49 UTC (permalink / raw)
To: Nicholas Vinson; +Cc: grub-devel, floppym
On Tue, Feb 10, 2026 at 06:27:49PM -0500, Nicholas Vinson wrote:
> On 2/10/26 10:47, Daniel Kiper wrote:
> > On Mon, Feb 09, 2026 at 07:43:28PM -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 (8):
> > > 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
> >
> > For all these patches Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>...
> >
> > > C23 fixes: fix strchr() and strrchr() handling
> >
> > It seems to me that this patch does more than commit message says.
> > I think it has to be split into more parts or commit message has to be
> > improved.
>
> I admit the message is a bit terse, but I kept the changes to a minimum. I
> did, however, forget to mention strstr().
If you mention strstr() I am OK with it...
> Put simply, with C23, if the first argument to strstr(), strchr(), or
> strrchar() is a const char *, the result is a const char *. C23 also made
> this change to about 9 or so other functions.
>
> As a result, most of the changes were just changing a variable from 'char *'
> to 'const char *'.
>
> The changes for ofpath.c are a bit more involved because the original code
> would modify the string 'ed' pointed to. With C23, ed needs to be a 'const
> char *' because sysfs_path is a 'const char *'. This also means that the
> line "*q = '\0'" is no longer valid because you cannot safely modify a const
> char string.
>
> I saw two options to fix this, the first was to modify the line to be q =
> strndup(...);, add the requisite error checking, and then make sure to free
> q just before every subsequent return. The second option, is what I did,
> find the difference between q and ed, save it off, and then replace the
> strlen(ed) calls with that difference.
>
> I believe the second approach is the better of the two. It did have the
> ancillary effect of updating a few snprintf() calls and the path_size
> calculation; however, these changes are required with this approach.
I am OK with second approach but I think this change should go to
separate patch, with an explanation like above, because it is more
complicated than just adding const.
> If you'd prefer, I can re-submit patch 8 with these details in the commit
> message. Alternatively, if you would prefer the strndup() approach, I will
> respin this patch series without patch 8, and then submit a re-worked C23
> patch as a separate request.
Just split patch #8 as I suggested above and repost C23 as separate series.
Daniel
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 0/8] Improve ld.lld-21+ compatibility when building i386-pc target
2026-02-10 15:47 ` [PATCH v2 0/8] Improve ld.lld-21+ compatibility when building i386-pc target Daniel Kiper
2026-02-10 23:27 ` Nicholas Vinson
@ 2026-02-11 18:49 ` Daniel Kiper
1 sibling, 0 replies; 16+ messages in thread
From: Daniel Kiper @ 2026-02-11 18:49 UTC (permalink / raw)
To: Nicholas Vinson; +Cc: grub-devel, floppym
On Tue, Feb 10, 2026 at 04:47:41PM +0100, Daniel Kiper wrote:
> On Mon, Feb 09, 2026 at 07:43:28PM -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 (8):
> > 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
>
> For all these patches Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>...
Sadly your patch set breaks Windows build... :-(
$ ./configure --build=x86_64-linux-gnu --host=i686-w64-mingw32 --target=i686-w64-mingw32 --with-platform=pc
$ make
[...]
i686-w64-mingw32-gcc -std=gnu99 -fno-common -Os -m32 -Wall -W -Wshadow -Wpointer-arith -Wundef -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Wmain -Wmissing-braces -Wmissing-format-attribute -Wmultichar -Wparentheses -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wswitch -Wtrigraphs -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wwrite-strings -Wnested-externs -Wstrict-prototypes -g -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations -Wextra -Wattributes -Wendif-labels -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmissing-field-initializers -Wnonnull -Woverflow -Wvla -Wpointer-to-int-cast -Wstrict-aliasing -Wvariadic-macros -Wvolatile-register-var -Wpointer-sign -Wmissing-include-dirs -Wmissing-prototypes -Wmissing-declarations -Wformat=2 -march=i386 -mrtd -mregparm=3 -falign-functions=1 -falign-loops=1 -falign-jumps=1 -freg-struct-return -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow -msoft-float -fno-omit-frame-pointer -fno-dwarf2-cfi-asm -fno-reorder-functions -mno-stack-arg-probe -fno-asynchronous-unwind-tables -fno-unwind-tables -fno-ident -fno-stack-protector -Wtrampolines -Werror -DGRUB_HAS_PCI -fno-builtin -m32 -Wl,-mi386pe -nostdlib -Wl,-N -Wl,-S -Wl,-T../conf/i386-cygwin-img.lds -Wl,-T../conf/i386-pc-kernel.lds -Wl,-Ttext=0x8200 -o lzma_decompress.image.exe boot/i386/pc/lzma_decompress_image-startup_raw.o
/usr/bin/i686-w64-mingw32-ld:../conf/i386-pc-kernel.lds:19: undefined symbol `_grub_text_base' referenced in expression
/usr/bin/i686-w64-mingw32-ld:../conf/i386-pc-kernel.lds:19: undefined symbol `_grub_text_base' referenced in expression
collect2: error: ld returned 1 exit status
collect2: error: ld returned 1 exit status
/usr/bin/i686-w64-mingw32-ld:../conf/i386-pc-kernel.lds:19: undefined symbol `_grub_text_base' referenced in expression
make[3]: *** [Makefile:33123: boot.image.exe] Error 1
make[3]: *** Waiting for unfinished jobs....
make[3]: *** [Makefile:33145: boot_hybrid.image.exe] Error 1
collect2: error: ld returned 1 exit status
/usr/bin/i686-w64-mingw32-ld:../conf/i386-pc-kernel.lds:19: undefined symbol `_grub_text_base' referenced in expression
collect2: error: ld returned 1 exit status
make[3]: *** [Makefile:33276: cdboot.image.exe] Error 1
make[3]: *** [Makefile:36161: pxeboot.image.exe] Error 1
/usr/bin/i686-w64-mingw32-ld:../conf/i386-pc-kernel.lds:19: undefined symbol `_grub_text_base' referenced in expression
/usr/bin/i686-w64-mingw32-ld:../conf/i386-pc-kernel.lds:19: undefined symbol `_grub_text_base' referenced in expression
collect2: error: ld returned 1 exit status
collect2: error: ld returned 1 exit status
/usr/bin/i686-w64-mingw32-ld:../conf/i386-pc-kernel.lds:19: undefined symbol `_grub_text_base' referenced in expression
collect2: error: ld returned 1 exit status
make[3]: *** [Makefile:35303: lnxboot.image.exe] Error 1
make[3]: *** [Makefile:33499: diskboot.image.exe] Error 1
make[3]: *** [Makefile:35449: lzma_decompress.image.exe] Error 1
/usr/bin/i686-w64-mingw32-ld:../conf/i386-pc-kernel.lds:19: undefined symbol `_grub_text_base' referenced in expression
collect2: error: ld returned 1 exit status
make[3]: *** [Makefile:35180: kernel.exec.exe] Error 1
I suppose that the problem is due to inclusion in the command line two
linker scripts...
Daniel
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH] Fix build with glibc 2.43 after new ISO C23 changes
2026-02-10 23:27 ` Nicholas Vinson
2026-02-11 17:49 ` Daniel Kiper
@ 2026-02-12 7:46 ` Radoslav Kolev via Grub-devel
2026-02-12 7:53 ` [PATCH v2 0/8] Improve ld.lld-21+ compatibility when building i386-pc target Radoslav Kolev via Grub-devel
2 siblings, 0 replies; 16+ messages in thread
From: Radoslav Kolev via Grub-devel @ 2026-02-12 7:46 UTC (permalink / raw)
To: nvinson234; +Cc: Radoslav Kolev, dkiper, grub-devel, floppym
For ISO C23, the functions bsearch, memchr, strchr, strpbrk, strrchr,
strstr, wcschr, wcspbrk, wcsrchr, wcsstr and wmemchr that return
pointers into their input arrays now have definitions as macros that
return a pointer to a const-qualified type when the input argument is
a pointer to a const-qualified type.
Signed-off-by: Radoslav Kolev <radoslav.kolev@suse.com>
---
grub-core/osdep/linux/ofpath.c | 4 ++--
util/probe.c | 6 +++---
util/resolve.c | 8 ++++----
3 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/grub-core/osdep/linux/ofpath.c b/grub-core/osdep/linux/ofpath.c
index 24a4d5c8d..cbcc4332f 100644
--- a/grub-core/osdep/linux/ofpath.c
+++ b/grub-core/osdep/linux/ofpath.c
@@ -488,13 +488,13 @@ check_hba_identifiers (const char *sysfs_path, int *vendor, int *device_id)
static void
check_sas (const char *sysfs_path, int *tgt, unsigned long int *sas_address)
{
- char *ed = strstr (sysfs_path, "end_device");
+ char *ed;
char *p, *q, *path;
char phy[21];
int fd;
size_t path_size;
- if (!ed)
+ if (!strstr(sysfs_path, "end_device"))
return;
/* SAS devices are identified using disk@$PHY_ID */
diff --git a/util/probe.c b/util/probe.c
index 81d91cf59..a9158d640 100644
--- a/util/probe.c
+++ b/util/probe.c
@@ -70,7 +70,7 @@ char *
grub_util_guess_bios_drive (const char *orig_path)
{
char *canon;
- char *ptr;
+ const char *ptr;
canon = grub_canonicalize_file_name (orig_path);
if (!canon)
return NULL;
@@ -99,7 +99,7 @@ char *
grub_util_guess_efi_drive (const char *orig_path)
{
char *canon;
- char *ptr;
+ const char *ptr;
canon = grub_canonicalize_file_name (orig_path);
if (!canon)
return NULL;
@@ -128,7 +128,7 @@ char *
grub_util_guess_baremetal_drive (const char *orig_path)
{
char *canon;
- char *ptr;
+ const char *ptr;
canon = grub_canonicalize_file_name (orig_path);
if (!canon)
return NULL;
diff --git a/util/resolve.c b/util/resolve.c
index b6e26312f..5310a5521 100644
--- a/util/resolve.c
+++ b/util/resolve.c
@@ -138,8 +138,8 @@ read_dep_list (FILE *fp)
static char *
get_module_name (const char *str)
{
- char *base;
- char *ext;
+ const char *base;
+ const char *ext;
base = strrchr (str, '/');
if (! base)
@@ -164,9 +164,9 @@ get_module_name (const char *str)
static char *
get_module_path (const char *prefix, const char *str)
{
- char *dir;
+ const char *dir;
char *base;
- char *ext;
+ const char *ext;
char *ret;
ext = strrchr (str, '.');
--
2.52.0
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH v2 0/8] Improve ld.lld-21+ compatibility when building i386-pc target
2026-02-10 23:27 ` Nicholas Vinson
2026-02-11 17:49 ` Daniel Kiper
2026-02-12 7:46 ` [PATCH] Fix build with glibc 2.43 after new ISO C23 changes Radoslav Kolev via Grub-devel
@ 2026-02-12 7:53 ` Radoslav Kolev via Grub-devel
2026-02-12 13:21 ` Nicholas Vinson
2 siblings, 1 reply; 16+ messages in thread
From: Radoslav Kolev via Grub-devel @ 2026-02-12 7:53 UTC (permalink / raw)
To: nvinson234; +Cc: Radoslav Kolev, Daniel Kiper, grub-devel, floppym
On Wed, Feb 11, 2026 at 1:28 AM Nicholas Vinson <nvinso in a linker
error. Furthermore,
> The changes for ofpath.c are a bit more involved because the original
> code would modify the string 'ed' pointed to. With C23, ed needs to be a
> 'const char *' because sysfs_path is a 'const char *'. This also means
> that the line "*q = '\0'" is no longer valid because you cannot safely
> modify a const char string.
I may be completely missing something important here, but I run into
the same issue trying to build against glibc 2.43 and my fix for
ofpath.c was less invasive. I'm sending my patch in a reply, please
have a look.
Regards,
Rado
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 0/8] Improve ld.lld-21+ compatibility when building i386-pc target
2026-02-12 7:53 ` [PATCH v2 0/8] Improve ld.lld-21+ compatibility when building i386-pc target Radoslav Kolev via Grub-devel
@ 2026-02-12 13:21 ` Nicholas Vinson
0 siblings, 0 replies; 16+ messages in thread
From: Nicholas Vinson @ 2026-02-12 13:21 UTC (permalink / raw)
To: Radoslav Kolev; +Cc: Daniel Kiper, grub-devel, floppym
On 2/12/26 02:53, Radoslav Kolev wrote:
> On Wed, Feb 11, 2026 at 1:28 AM Nicholas Vinson <nvinso in a linker
> error. Furthermore,
>> The changes for ofpath.c are a bit more involved because the original
>> code would modify the string 'ed' pointed to. With C23, ed needs to be a
>> 'const char *' because sysfs_path is a 'const char *'. This also means
>> that the line "*q = '\0'" is no longer valid because you cannot safely
>> modify a const char string.
>
> I may be completely missing something important here, but I run into
> the same issue trying to build against glibc 2.43 and my fix for
> ofpath.c was less invasive. I'm sending my patch in a reply, please
> have a look.
I think the issue is I missed the xstrdup() call on my first pass
through. That said, on re-evaluation, I find the xstrdup() call to be
superfluous and recommend removing it. It's removal would allow the
function to execute without reduced dynamic memory allocation (only
space for path is needed) and reduces the total number of strstr() calls
to 1.
I want to review my commit messages before publishing the revised patch
(which I'll do later).
Thanks,
Nicholas Vinson
>
> Regards,
> Rado
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2026-02-12 13:21 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-10 0:43 [PATCH v2 0/8] Improve ld.lld-21+ compatibility when building i386-pc target Nicholas Vinson
2026-02-10 0:43 ` [PATCH v2 1/8] i386/pc/int.h: conditionally apply regparm attr Nicholas Vinson
2026-02-10 0:43 ` [PATCH v2 2/8] grub-core: Update kernel image generation Nicholas Vinson
2026-02-10 0:43 ` [PATCH v2 3/8] i386-cygwin-img-ld.sc -> i386-cygwin-img.lds Nicholas Vinson
2026-02-10 0:43 ` [PATCH v2 4/8] Revert "configure: Print a more helpful error if autoconf-archive is not installed" Nicholas Vinson
2026-02-10 0:43 ` [PATCH v2 5/8] Revert "configure: Check linker for --image-base support" Nicholas Vinson
2026-02-10 0:43 ` [PATCH v2 6/8] Revert "INSTALL: Add note that the GNU Autoconf Archive may be needed" Nicholas Vinson
2026-02-10 0:43 ` [PATCH v2 7/8] configure: drop -Ttext checks for i386-pc Nicholas Vinson
2026-02-10 0:43 ` [PATCH v2 8/8] C23 fixes: fix strchr() and strrchr() handling Nicholas Vinson
2026-02-10 15:47 ` [PATCH v2 0/8] Improve ld.lld-21+ compatibility when building i386-pc target Daniel Kiper
2026-02-10 23:27 ` Nicholas Vinson
2026-02-11 17:49 ` Daniel Kiper
2026-02-12 7:46 ` [PATCH] Fix build with glibc 2.43 after new ISO C23 changes Radoslav Kolev via Grub-devel
2026-02-12 7:53 ` [PATCH v2 0/8] Improve ld.lld-21+ compatibility when building i386-pc target Radoslav Kolev via Grub-devel
2026-02-12 13:21 ` Nicholas Vinson
2026-02-11 18:49 ` Daniel Kiper
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox