linux-postmarketos-mainline: Temporarily patch for LLVM-only build on ppc64le

The PowerPC boot wrapper script in Linux currently requires a GNU
cross toolchain in PATH. This went unnoticed because we currently always
install GCC for native builds, but since recently only install a cross
GCC toolchain if clang is not used to build.

Indeed, we want to only build the kernel with clang and LLVM binutils.
There has been some discussion around fixing this in the past, and
Nathan Chancellor has written some patches that do fix it, but has
apparently not submitted them because the VDSO may require further
changes. I've followed up on the mailing list and asked about the
possibility to submit the patches without reworking the VDSO, since it
fixes this particular usecase nonetheless.

I've also considered installing the cross GCC package in the APKBUILD,
but that's not possible because pmbootstrap cannot evaluate conditional
dependencies. As it stands, we *need* to patch the kernel to get it
building, or revert the pmbootstrap patch, which I really want to avoid.
I'll do my best to get these patches integrated upstream.

[ci:skip-vercheck]: let's not rebuild all the architectures when we're
only touching ppc64le that isn't building in BPO

Part-of: <https://gitlab.postmarketos.org/postmarketOS/pmaports/-/merge_requests/8072>
This commit is contained in:
Aelin 2026-02-25 00:37:28 +01:00 committed by The Friendly Meow (merge) Bot
parent cbad33f921
commit ab005ffc19
No known key found for this signature in database
4 changed files with 320 additions and 1 deletions

View file

@ -0,0 +1,229 @@
From 1036fc931dcd28ea093949a07873545665b0c520 Mon Sep 17 00:00:00 2001
From: Nathan Chancellor <nathan@kernel.org>
Date: Fri, 21 Jan 2022 11:53:52 -0700
Subject: [PATCH 1/3] WIP: arch/powerpc/boot: Support LLVM=1 in wrapper script
When LLVM=1 is set, pass through the make variables, as they will
generally be multi-targeted.
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
arch/powerpc/boot/Makefile | 11 +++++-
arch/powerpc/boot/wrapper | 72 +++++++++++++++++++++++++++++---------
2 files changed, 66 insertions(+), 17 deletions(-)
diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile
index f1a4761ebd44..655750126ce9 100644
--- a/arch/powerpc/boot/Makefile
+++ b/arch/powerpc/boot/Makefile
@@ -264,6 +264,15 @@ CROSSWRAP := -C "$(CROSS_COMPILE)"
endif
endif
+ifneq ($(LLVM),)
+WRAPTOOLS := --ld $(LD)
+WRAPTOOLS += --nm $(NM)
+WRAPTOOLS += --objcopy $(OBJCOPY)
+WRAPTOOLS += --objdump $(OBJDUMP)
+# No $(STRINGS)
+WRAPTOOLS += --strings llvm-strings
+endif
+
compressor-$(CONFIG_KERNEL_GZIP) := gz
compressor-$(CONFIG_KERNEL_XZ) := xz
compressor-$(CONFIG_KERNEL_LZMA) := lzma
@@ -272,7 +281,7 @@ compressor-$(CONFIG_KERNEL_LZO) := lzo
# args (to if_changed): 1 = (this rule), 2 = platform, 3 = dts 4=dtb 5=initrd
quiet_cmd_wrap = WRAP $@
cmd_wrap =$(CONFIG_SHELL) $(wrapper) -Z $(compressor-y) -c -o $@ -p $2 \
- $(CROSSWRAP) $(if $3, -s $3)$(if $4, -d $4)$(if $5, -i $5) \
+ $(CROSSWRAP) $(WRAPTOOLS) $(if $3, -s $3)$(if $4, -d $4)$(if $5, -i $5) \
vmlinux
image-$(CONFIG_PPC_PSERIES) += zImage.pseries
diff --git a/arch/powerpc/boot/wrapper b/arch/powerpc/boot/wrapper
index 1efd1206fcab..8dabcf5406b2 100755
--- a/arch/powerpc/boot/wrapper
+++ b/arch/powerpc/boot/wrapper
@@ -167,6 +167,31 @@ while [ "$#" -gt 0 ]; do
compression=
uboot_comp=none
;;
+ --ld)
+ shift
+ [ "$#" -gt 0 ] || usage
+ ld="$1"
+ ;;
+ --nm)
+ shift
+ [ "$#" -gt 0 ] || usage
+ nm="$1"
+ ;;
+ --objcopy)
+ shift
+ [ "$#" -gt 0 ] || usage
+ objcopy="$1"
+ ;;
+ --objdump)
+ shift
+ [ "$#" -gt 0 ] || usage
+ objdump="$1"
+ ;;
+ --strings)
+ shift
+ [ "$#" -gt 0 ] || usage
+ strings="$1"
+ ;;
-?)
usage
;;
@@ -178,6 +203,21 @@ while [ "$#" -gt 0 ]; do
shift
done
+if [ -z "$ld" ]; then
+ ld=${CROSS}ld
+fi
+if [ -z "$nm" ]; then
+ nm=${CROSS}nm
+fi
+if [ -z "$objcopy" ]; then
+ objcopy=${CROSS}objcopy
+fi
+if [ -z "$objdump" ]; then
+ objdump=${CROSS}objdump
+fi
+if [ -z "$strings" ]; then
+ strings=${CROSS}strings
+fi
if [ -n "$dts" ]; then
if [ ! -r "$dts" -a -r "$object/dts/$dts" ]; then
@@ -193,7 +233,7 @@ if [ -z "$kernel" ]; then
kernel=vmlinux
fi
-LC_ALL=C elfformat="`${CROSS}objdump -p "$kernel" | grep 'file format' | awk '{print $4}'`"
+LC_ALL=C elfformat="`$objdump -p "$kernel" | grep 'file format' | awk '{print $4}'`"
case "$elfformat" in
elf64-powerpcle) format=elf64lppc ;;
elf64-powerpc) format=elf32ppc ;;
@@ -230,7 +270,7 @@ nodl="--no-dynamic-linker"
# suppress some warnings in recent ld versions
nowarn="-z noexecstack"
-if "${CROSS}ld" -v --no-warn-rwx-segments >/dev/null 2>&1; then
+if $ld -v --no-warn-rwx-segments >/dev/null 2>&1; then
nowarn="$nowarn --no-warn-rwx-segments"
fi
@@ -369,7 +409,7 @@ epapr)
link_address='0x20000000'
pie=-pie
notext='-z notext'
- rodynamic=$(if ${CROSS}ld -V 2>&1 | grep -q LLD ; then echo "-z rodynamic"; fi)
+ rodynamic=$(if $ld -V 2>&1 | grep -q LLD ; then echo "-z rodynamic"; fi)
;;
mvme5100)
platformo="$object/fixed-head.o $object/mvme5100.o"
@@ -385,7 +425,7 @@ esac
vmz="$tmpdir/`basename \"$kernel\"`.$ext"
# Calculate the vmlinux.strip size
-${CROSS}objcopy $objflags "$kernel" "$vmz.$$"
+$objcopy $objflags "$kernel" "$vmz.$$"
strip_size=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" "$vmz.$$")
if [ -z "$cacheit" -o ! -f "$vmz$compression" -o "$vmz$compression" -ot "$kernel" ]; then
@@ -438,14 +478,14 @@ fi
# Extract kernel version information, some platforms want to include
# it in the image header
-version=`${CROSS}strings "$kernel" | grep '^Linux version [-0-9.]' | \
+version=`$strings "$kernel" | grep '^Linux version [-0-9.]' | \
head -n1 | cut -d' ' -f3`
if [ -n "$version" ]; then
uboot_version="-n Linux-$version"
fi
# physical offset of kernel image
-membase=`${CROSS}objdump -p "$kernel" | grep -m 1 LOAD | awk '{print $7}'`
+membase=`$objdump -p "$kernel" | grep -m 1 LOAD | awk '{print $7}'`
case "$platform" in
uboot)
@@ -460,7 +500,7 @@ uboot)
esac
addsec() {
- ${CROSS}objcopy $4 $1 \
+ $objcopy $4 $1 \
--add-section=$3="$2" \
--set-section-flags=$3=contents,alloc,load,readonly,data
}
@@ -490,18 +530,18 @@ if [ "$platform" != "miboot" ]; then
text_start="-Ttext $link_address"
fi
#link everything
- ${CROSS}ld -m $format -T $lds $text_start $pie $nodl $nowarn $rodynamic $notext -o "$ofile" $map \
+ $ld -m $format -T $lds $text_start $pie $nodl $nowarn $rodynamic $notext -o "$ofile" $map \
$platformo $tmp $object/wrapper.a
rm $tmp
fi
# Some platforms need the zImage's entry point and base address
-base=0x`${CROSS}nm "$ofile" | grep ' _start$' | cut -d' ' -f1`
-entry=`${CROSS}objdump -f "$ofile" | grep '^start address ' | cut -d' ' -f3`
+base=0x`$nm "$ofile" | grep ' _start$' | cut -d' ' -f1`
+entry=`$objdump -f "$ofile" | grep '^start address ' | cut -d' ' -f3`
if [ -n "$binary" ]; then
mv "$ofile" "$ofile".elf
- ${CROSS}objcopy -O binary "$ofile".elf "$ofile"
+ $objcopy -O binary "$ofile".elf "$ofile"
fi
# post-processing needed for some platforms
@@ -510,7 +550,7 @@ pseries|chrp)
$objbin/addnote "$ofile"
;;
coff)
- ${CROSS}objcopy -O aixcoff-rs6000 --set-start "$entry" "$ofile"
+ $objcopy -O aixcoff-rs6000 --set-start "$entry" "$ofile"
$objbin/hack-coff "$ofile"
;;
cuboot*)
@@ -538,18 +578,18 @@ ps3)
# copied to offset 0x100. At runtime the bootwrapper program copies
# the data at __system_reset_kernel back to addr 0x100.
- system_reset_overlay=0x`${CROSS}nm "$ofile" \
+ system_reset_overlay=0x`$nm "$ofile" \
| grep ' __system_reset_overlay$' \
| cut -d' ' -f1`
system_reset_overlay=`printf "%d" $system_reset_overlay`
- system_reset_kernel=0x`${CROSS}nm "$ofile" \
+ system_reset_kernel=0x`$nm "$ofile" \
| grep ' __system_reset_kernel$' \
| cut -d' ' -f1`
system_reset_kernel=`printf "%d" $system_reset_kernel`
overlay_dest="256"
overlay_size="512"
- ${CROSS}objcopy -O binary "$ofile" "$ofile.bin"
+ $objcopy -O binary "$ofile" "$ofile.bin"
run_cmd dd if="$ofile.bin" of="$ofile.bin" conv=notrunc \
skip=$overlay_dest seek=$system_reset_kernel \
@@ -567,7 +607,7 @@ ps3)
# reached, then enter the system reset vector of the partially decompressed
# image. No warning is issued.
rm -f "$odir"/{otheros,otheros-too-big}.bld
- size=$(${CROSS}nm --no-sort --radix=d "$ofile" | grep -E ' _end$' | cut -d' ' -f1)
+ size=$($nm --no-sort --radix=d "$ofile" | grep -E ' _end$' | cut -d' ' -f1)
bld="otheros.bld"
if [ $size -gt $((0x1000000)) ]; then
bld="otheros-too-big.bld"
--
2.53.0

View file

@ -0,0 +1,41 @@
From b5cf37159427f2589632e30789488e993a725e0c Mon Sep 17 00:00:00 2001
From: Nathan Chancellor <nathan@kernel.org>
Date: Fri, 21 Jan 2022 12:39:58 -0700
Subject: [PATCH 2/3] WIP: arch/powerpc/boot: Use '-z notext' for pseries image
Same reason as commit 4c078c86b4a4 ("powerpc/boot/wrapper: Add "-z
notext" flag to disable diagnostic").
ld.lld: error: relocation R_PPC64_ADDR64 cannot be used against symbol '_start'; recompile with -fPIC
>>> referenced by crt0.o:(.text+0x8) in archive arch/powerpc/boot/wrapper.a
ld.lld: error: relocation R_PPC64_ADDR64 cannot be used against symbol '_etext'; recompile with -fPIC
>>> referenced by crt0.o:(.text+0x10) in archive arch/powerpc/boot/wrapper.a
ld.lld: error: relocation R_PPC64_ADDR64 cannot be used against symbol '__bss_start'; recompile with -fPIC
>>> referenced by crt0.o:(.text+0x18) in archive arch/powerpc/boot/wrapper.a
ld.lld: error: relocation R_PPC64_ADDR64 cannot be used against symbol '_end'; recompile with -fPIC
>>> referenced by crt0.o:(.text+0x20) in archive arch/powerpc/boot/wrapper.a
make[2]: *** [arch/powerpc/boot/Makefile:400: arch/powerpc/boot/zImage.pseries] Error 1
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
arch/powerpc/boot/wrapper | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/powerpc/boot/wrapper b/arch/powerpc/boot/wrapper
index 8dabcf5406b2..2a28695d5bd6 100755
--- a/arch/powerpc/boot/wrapper
+++ b/arch/powerpc/boot/wrapper
@@ -302,6 +302,7 @@ pseries)
if [ "$format" != "elf32ppc" ]; then
link_address=
pie=-pie
+ notext='-z notext'
fi
make_space=n
;;
--
2.53.0

View file

@ -0,0 +1,38 @@
From 445dd03e6d4c8ba8bbc0525d82f77ede2f89355e Mon Sep 17 00:00:00 2001
From: Nathan Chancellor <nathan@kernel.org>
Date: Fri, 21 Jan 2022 14:15:08 -0700
Subject: [PATCH 3/3] WIP: arch/powerpc/boot: Add '-z norelro'
ld.bfd defaults to '-z norelro', whereas ld.lld defaults to '-z relro',
which results in an error when building cuImages:
ld.lld: error: section: .dynamic is not contiguous with other relro sections
Commit a538d184e3f0 ("powerpc/boot: Move the .got section to after the
.dynamic section") previously worked around this in the boot wrapper by
shuffling the sections but other areas of the kernel have just disabled
the relro program header altogether (see commit 3b92fa7485eb ("arm64:
link with -z norelro regardless of CONFIG_RELOCATABLE") and
commit 0cda9bc15dfc ("ARM: 9038/1: Link with '-z norelro'")).
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
arch/powerpc/boot/wrapper | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/powerpc/boot/wrapper b/arch/powerpc/boot/wrapper
index 2a28695d5bd6..1e4f4fbd3948 100755
--- a/arch/powerpc/boot/wrapper
+++ b/arch/powerpc/boot/wrapper
@@ -531,7 +531,7 @@ if [ "$platform" != "miboot" ]; then
text_start="-Ttext $link_address"
fi
#link everything
- $ld -m $format -T $lds $text_start $pie $nodl $nowarn $rodynamic $notext -o "$ofile" $map \
+ $ld -m $format -T $lds $text_start $pie $nodl $nowarn $rodynamic $notext -z norelro -o "$ofile" $map \
$platformo $tmp $object/wrapper.a
rm $tmp
fi
--
2.53.0

View file

@ -49,10 +49,18 @@ makedepends="
zstd
"
# Source
# powerpc boot wrapper patches:
# Necessary for compilation without cross GCC in PATH, cherry-picked from
# Nathan's fork, he does not have time to upstream them right now but would be
# happy if someone else did:
# https://lore.kernel.org/linuxppc-dev/aXs8sgAcci9FKKpx@luna/
source="
$pkgname-$pkgver.tar.gz::https://git.kernel.org/torvalds/t/linux-${pkgver/_/-}.tar.gz
0001-WIP-arch-powerpc-boot-Support-LLVM-1-in-wrapper-scri.patch
0002-WIP-arch-powerpc-boot-Use-z-notext-for-pseries-image.patch
0003-WIP-arch-powerpc-boot-Add-z-norelro.patch
config-mainline.aarch64
config-mainline.armv7
config-mainline.loongarch64
@ -109,6 +117,9 @@ package() {
sha512sums="
8f52207ee68fee8880c085db8033367c18cd2c44854add726eb4cdb90ab7502e5394d6c7ccc6896ce589f93ad081af1edc8cc011374cf7f24d37a1ade4e846e8 linux-postmarketos-mainline-7.0_rc3.tar.gz
1f11df2480e9f691573283597160b4c806e492cdca4825f3acb3afb70bde43abfab487bcde1f5553b431a702a0039479d041b0ce7859970e706b5a51d2ad8fb0 0001-WIP-arch-powerpc-boot-Support-LLVM-1-in-wrapper-scri.patch
26521a9c9ea769534095dc4e306babadc8bcbaf03d7faa523c377e41ba0f742ecd0490fa27791d895f729c3ae8845297dca59b4db2475e7f078e689c447430bc 0002-WIP-arch-powerpc-boot-Use-z-notext-for-pseries-image.patch
302c20c85559fc9b3b2420ed25be1bfbb76c87f2a470e4141c32e9542cf1f5c6b3b5a7847231a3eaa0f6bc0e5942d0c1599e807175dcf5e63469704c3d6adde3 0003-WIP-arch-powerpc-boot-Add-z-norelro.patch
395095e082da9a17f18b9d33a0ec9ae649031924aab436f4a8461295bbc926fda85b64e9eb8fc062843f9e76a3ec6536a37a8fe7bf3ecb7454624b4009f6b755 config-mainline.aarch64
39b64f3e78d87d2d5c8cc66a570c92def6ae9c8cac8eb83b8f0791444cfbb2913fd2b6a2095ee0aeaef9d249fd3a9e4c0b2e854b940141c5264b3cb8283dcf55 config-mainline.armv7
c8bb1565ce324c57baebe4f961bd3db0c98f4423ae289cb7a255f827bf3e9685184bf2e40b0134c2f4be83470f2d17df11bce01a8d44bc3c4d186244ffd4e30a config-mainline.loongarch64