Subject: bug#76988: Architecture-specific kernels (arm64-generic) built for x86_64

From: Vagrant Cascadian <[email-masked]>
Date: Fri, 21 Mar 2025 12:29:16 -0700

On 2025-03-14, Leo Famulari wrote:
> I don't do anything regarding the "generic" arm64 kernels, so I also
> don't know how they work or why they are built in any particular way.

Yeah, in most cases I would prefer to use the regular linux-libre
package, but sometimes it is difficult to follow the module name changes
to hard-code the appropriate list of initrd modules to find the rootfs,
and some of these kernel variants make that easier by using some =y
options that might reasonably be =m options in "linux-libre", and also
might allow patches that are not appropriate to apply to the standard
"linux-libre" packages (e.g. linux-libre-arm64-mnt-reform in
bug#77090). Or just include options that are only particular to a
particular platform, but cannot be made modules for one reason or
another... anyways... :)

I made a lazy attempt at forcing a build failure by ensuring the
appropriate architecture was set in the configuration:

					  #:extra-options
					  (append
+                      `(;; Ensure we are building for arm64
+                        ("CONFIG_ARM64" . #true)

But the build still picks the wrong defconfig:

  *** Default configuration is based on 'x86_64_defconfig'

I presume that the checks to make sure the configuration includes the
options in #:extra-options must run before the config is generated with
the wrongly selected defconfig... ??

Interestingly, linux-libre-arm-generic does usefully fail to build early
on, but by pure luck:

  starting phase `set-environment'
  `ARCH' set to `x86_64'
  phase `set-environment' succeeded after 0.0 seconds
  starting phase `configure'
  HOSTCC  scripts/basic/fixdep
  ...
  HOSTLD  scripts/kconfig/conf
  ***
  *** Can't find default configuration "arch/x86/configs/multi_v7_defconfig"!

Because it is setting ARCH to x86_64, and there is obviously no
corresponding multi_v7_defconfig. For the arm64 linux-libre variants:

  #:defconfig "defconfig"

So it happily picks arch/x86/configs/defconfig...

If a custom linux-libre variant could force the ARCH value (based on
supported-systems?), this just might work as desired... or at least
usefully break earlier in the build, saving considerable build time!

When cross-compiling, ARCH and CROSS_COMPILE are set appropriately:

  $ guix build --check --target=aarch64-linux-gnu linux-libre-arm64-generic
  ...
  starting phase `set-environment'
  `ARCH' set to `arm64'
  `CROSS_COMPILE' set to `aarch64-linux-gnu-'

But the only option for linux-libre-arm64-generic is either native or
cross compilation, since it is an aarch64-linux/arm64 specific
package... we should be able to detect that somehow and at least fail
the build early or ideally not even attempt the build if ARCH
mismatches.

Maybe somewhere in make-linux-libre* it could have a sanity check
comparing "supported-systems" against the %current-target-system and
%current-system?

			  ;; Set ARCH and CROSS_COMPILE.
			  (let ((arch #$(platform-linux-architecture
							 (lookup-platform-by-target-or-system
							  (or (%current-target-system)
								  (%current-system))))))
				(setenv "ARCH" arch)
				(format #t "`ARCH' set to `~a'~%" (getenv "ARCH"))
				(when target
				  (setenv "CROSS_COMPILE" (string-append target "-"))
				  (format #t "`CROSS_COMPILE' set to `~a'~%"
						  (getenv "CROSS_COMPILE"))))

Thanks for considering!

live well,
  vagrant