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

See previous commit for details

[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-03-12 17:37:30 +00:00
parent c99c4271d7
commit 6520fb5c9f
4 changed files with 320 additions and 1 deletions
@@ -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
@@ -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
@@ -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
+12 -1
View File
@@ -48,10 +48,18 @@ makedepends="
"
replaces="linux-lts"
# 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="
linux-$_kver.tar.xz::https://cdn.kernel.org/pub/linux/kernel/v${pkgver%%.*}.x/linux-$_kver.tar.xz
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-lts.aarch64
config-lts.armv7
config-lts.loongarch64
@@ -114,6 +122,9 @@ package() {
sha512sums="
bf7844571f282c161f1c064bfe9f258d64ef3c026a36cc4406b18323ad919640343de6d3fd35f1a5a67250289112c01bc192c84434e46a62902326dc3b2af175 patch-6.18.16.patch.xz
88599ffdec96d150c1feb9b261ba93bb0301a9d0e1ad6bef7aeab1f5372cbfc57d8b43c7e902bd8f76921d1dbd8189663c142ea869e51d0e2b483b150ee00fe0 linux-6.18.tar.xz
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
b7b0df7ce6a20c25f45072b9aa38eb1c47911fe0c2e06bf1dad03b96049dbef52ef253e893b37002682a32f7d58075222baed85625a621f1fc4d0d7d4cf91a5c config-lts.aarch64
2389669f774de3b107e59d273118150eab37db15d5643e994479609f63bcbc2680d11c34d3e69686365aef7f0cd4b6a5b2ca34caf4c6694bf8681ad284816c56 config-lts.armv7
0cfe41cd172320fc2f708eb2ae3fd14417b38d178fc8a5d00adc038b32bd46c95866ede7a0ebc2144de7b1d8ecca9154d7864f97db7cac17e7b7b65d288fdb3b config-lts.loongarch64