[Bug 272740] CURRENT with ZFS not bootable when built with LLVM from ports

From: <bugzilla-noreply_at_freebsd.org>
Date: Wed, 26 Jul 2023 18:58:01 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=272740

            Bug ID: 272740
           Summary: CURRENT with ZFS not bootable when built with LLVM
                    from ports
           Product: Base System
           Version: CURRENT
          Hardware: amd64
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: kern
          Assignee: bugs@FreeBSD.org
          Reporter: bsd@orsolic.org

Building -CURRENT (2023-07-17 be4c7f273508) without system compiler (with
LLVM16 from ports) results in unbootable system:
Preloaded elf kernel "/boot/kernel/kernel" at 0xffffffff82328000.
Preloaded elf obj module "/boot/kernel/zfs.ko" at 0xffffffff82329090.
Preloaded boot_entropy_cache "/boot/entropy" at 0xffffffff823298f8.
Preloaded elf obj module "/boot/kernel/cryptodev.ko" at 0xffffffff82329950.
Preloaded hostuuid "/etc/hostid" at 0xffffffff8232a140.
kldload: unexpected relocation type 42, symbol index 8662
link_elf_obj: symbol __stack_chk_guard undefined
KLD file zfs.ko - could not finalize loading
...
Trying to mount root from zfs:builder/ROOT/b4 []...
Mounting from zfs:builder/ROOT/b4 failed with error 2: unknown file system.

Loader variables:
  vfs.root.mountfrom=zfs:builder/ROOT/b4

Manual root filesystem specification:
  <fstype>:<device> [options]
      Mount <device> using filesystem <fstype>
      and with the specified (optional) option list.

    eg. ufs:/dev/da0s1a
        zfs:zroot/ROOT/default
        cd9660:/dev/cd0 ro
          (which is equivalent to: mount -t cd9660 -o ro /dev/cd0 /)

  ?               List valid disk boot devices
  .               Yield 1 second (for background tasks)
  <empty line>    Abort manual input

Patching and rebuilding LLVM16 with this patch results in bootable system:
--- llvm/lib/CodeGen/TargetLoweringBase.cpp.orig        2023-06-11
00:58:16.000000000 +0200
+++ llvm/lib/CodeGen/TargetLoweringBase.cpp     2023-07-15 14:43:52.151958000
+0200
@@ -1979,8 +1979,7 @@

     // FreeBSD has "__stack_chk_guard" defined externally on libc.so
     if (TM.getRelocationModel() == Reloc::Static &&
-        !TM.getTargetTriple().isWindowsGNUEnvironment() &&
-        !TM.getTargetTriple().isOSFreeBSD())
+        !TM.getTargetTriple().isWindowsGNUEnvironment())
       GV->setDSOLocal(true);
   }
 }

Patch was taken from:
https://cgit.freebsd.org/src/commit/?h=stable/13&id=e8e5d75e6a9676e76c3bfd6d1d52561ffbb40846

Few months ago it was possible to use LLVM from ports to build kernel and
world, but I don't remember the details.
This patch was tested in bhyve VM and on real hardware.

On real hardware it was possible to boot system without patched compiler when
zfs.ko (options ZFS and GEOM_ELI with devices crypto and cryptodev) is built
into the kernel.
But then other modules (acpi_ibm, iic, drm, i915kms, acpi_video, ... pf,
various ng_* and so on) will fail to load with same reason.
Didn't try including zfs.ko into the kernel in the VM.

-- 
You are receiving this mail because:
You are the assignee for the bug.