Skip to content

Improve ld.lld-21+ compatibility when building i386-pc target

Nicholas Vinson grub-devel 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest9 patches 2 repliesIn review
  2. v39 patches 7 repliesSuperseded
  3. v28 patches 6 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v15 patches8 repliesSuperseded

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/9i386/pc/int.h: move GRUB_MACHINE_PCBIOS ifdefinclude/grub/i386/pc/int.h+1 -10 replies
2/9grub-core: Update kernel image generationconf/i386-pc-kernel.lds+51 -00 replies
3/9Revert "configure: Print a more helpful error if autoconf-archive is not installed"configure.ac+0 -50 replies
4/9Revert "configure: Check linker for --image-base support"acinclude.m4 configure.ac+2 -170 replies
5/9Revert "INSTALL: Add note that the GNU Autoconf Archive may be needed"INSTALL+0 -10 replies
6/9configure: drop -Ttext checks for i386-pcacinclude.m4 conf/Makefile.extra-dist configure.ac +1 more+55 -190 replies
7/9configure.ac: Add --image-base check for non-i386.gitignore configure.ac m4/ax_check_link_flag.m4+67 -20 replies
8/9i386-cygwin-img-ld.sc -> i386-cygwin-img.ldsconf/Makefile.extra-dist conf/i386-cygwin-img.lds configure.ac+3 -30 replies
9/9conf/i386-cygwin-img.lds: Update to use _grub_text_base symbolconf/i386-cygwin-img.lds configure.ac+2 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.

Read the v4 thread

Cover letter [PATCH v4 0/9] Improve ld.lld-21+ compatibility when building i386-pc target

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:

efi_disk_image.sh new file +23 -0
@@ -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:

mbr_disk_image.sh new file +22 -0
@@ -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: move GRUB_MACHINE_PCBIOS ifdef
grub-core: Update kernel image generation
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 i386-cygwin-img-ld.sc -> i386-cygwin-img.lds 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                                  | 59 ++++++++++++-------
 grub-core/Makefile.core.def                   | 31 +++++-----
 include/grub/i386/pc/int.h                    |  2 +-
 m4/ax_check_link_flag.m4                      | 53 +++++++++++++++++
 10 files changed, 177 insertions(+), 45 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
Signature · 7 lines
2.53.0


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel