linux-google-crosshatch-mainline: build with LLVM and sync kconfig

The previous patch was broken because the kernel was still configured to use
GCC. Builds passed in pmaports CI because the runner is native aarch64, which
hits the issue of Alpine's clang packaging depending on gcc to get access to
libgcc-dev. This pulls in the whole GCC compiler, causing the kernel to default
to it and ignore clang. When this patch got to BPO, it failed because BPO
cross-compiles packages, leading to aarch64 GCC not being installed when
building (only clang is used as the cross-compiler) and causing the build to
fail there.

Signed-off-by: Aster Boese <asterboese@mailbox.org>
Part-of: <https://gitlab.postmarketos.org/postmarketOS/pmaports/-/merge_requests/8265>
This commit is contained in:
Aster Boese
2026-04-07 13:34:38 +00:00
parent 83e7197431
commit b33ba8203c
3 changed files with 148 additions and 12 deletions
@@ -0,0 +1,123 @@
From 5934637641c863cc2c1765a0d01c5b6f53ecc4fc Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers@google.com>
Date: Wed, 26 Aug 2020 15:21:29 +1000
Subject: lib/string.c: implement stpcpy
LLVM implemented a recent "libcall optimization" that lowers calls to
`sprintf(dest, "%s", str)` where the return value is used to `stpcpy(dest,
str) - dest`. This generally avoids the machinery involved in parsing
format strings. `stpcpy` is just like `strcpy` except it returns the
pointer to the new tail of `dest`. This optimization was introduced into
clang-12.
Implement this so that we don't observe linkage failures due to missing
symbol definitions for `stpcpy`.
Similar to last year's fire drill with: commit 5f074f3e192f
("lib/string.c: implement a basic bcmp")
The kernel is somewhere between a "freestanding" environment (no full
libc) and "hosted" environment (many symbols from libc exist with the same
type, function signature, and semantics).
As H. Peter Anvin notes, there's not really a great way to inform the
compiler that you're targeting a freestanding environment but would like
to opt-in to some libcall optimizations (see pr/47280 below), rather than
opt-out.
Arvind notes, -fno-builtin-* behaves slightly differently between GCC and
Clang, and Clang is missing many __builtin_* definitions, which I consider
a bug in Clang and am working on fixing.
Masahiro summarizes the subtle distinction between compilers justly:
To prevent transformation from foo() into bar(), there are two ways in
Clang to do that; -fno-builtin-foo, and -fno-builtin-bar. There is
only one in GCC; -fno-buitin-foo.
(Any difference in that behavior in Clang is likely a bug from a missing
__builtin_* definition.)
Masahiro also notes:
We want to disable optimization from foo() to bar(),
but we may still benefit from the optimization from
foo() into something else. If GCC implements the same transform, we
would run into a problem because it is not -fno-builtin-bar, but
-fno-builtin-foo that disables that optimization.
In this regard, -fno-builtin-foo would be more future-proof than
-fno-built-bar, but -fno-builtin-foo is still potentially overkill. We
may want to prevent calls from foo() being optimized into calls to
bar(), but we still may want other optimization on calls to foo().
It seems that compilers today don't quite provide the fine grain control
over which libcall optimizations pseudo-freestanding environments would
prefer.
Finally, Kees notes that this interface is unsafe, so we should not
encourage its use. As such, I've removed the declaration from any header,
but it still needs to be exported to avoid linkage errors in modules.
Link: https://lkml.kernel.org/r/20200825140001.2941001-1-ndesaulniers@google.com
Link: https://bugs.llvm.org/show_bug.cgi?id=47162
Link: https://bugs.llvm.org/show_bug.cgi?id=47280
Link: https://github.com/ClangBuiltLinux/linux/issues/1126
Link: https://man7.org/linux/man-pages/man3/stpcpy.3.html
Link: https://pubs.opengroup.org/onlinepubs/9699919799/functions/stpcpy.html
Link: https://reviews.llvm.org/D85963
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Reported-by: Sami Tolvanen <samitolvanen@google.com>
Tested-by: Nathan Chancellor <natechancellor@gmail.com>
Suggested-by: Andy Lavr <andy.lavr@gmail.com>
Suggested-by: Arvind Sankar <nivedita@alum.mit.edu>
Suggested-by: Joe Perches <joe@perches.com>
Suggested-by: Masahiro Yamada <masahiroy@kernel.org>
Suggested-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: <stable@vger.kernel.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Alexandru Ardelean <alexandru.ardelean@analog.com>
Cc: Yury Norov <yury.norov@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
---
lib/string.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/lib/string.c b/lib/string.c
index 6012c385fb314d..6bd0cf0fb009a2 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -272,6 +272,30 @@ ssize_t strscpy_pad(char *dest, const char *src, size_t count)
}
EXPORT_SYMBOL(strscpy_pad);
+/**
+ * stpcpy - copy a string from src to dest returning a pointer to the new end
+ * of dest, including src's %NUL-terminator. May overrun dest.
+ * @dest: pointer to end of string being copied into. Must be large enough
+ * to receive copy.
+ * @src: pointer to the beginning of string being copied from. Must not overlap
+ * dest.
+ *
+ * stpcpy differs from strcpy in a key way: the return value is the new
+ * %NUL-terminated character. (for strcpy, the return value is a pointer to
+ * src. This interface is considered unsafe as it doesn't perform bounds
+ * checking of the inputs. As such it's not recommended for usage. Instead,
+ * its definition is provided in case the compiler lowers other libcalls to
+ * stpcpy.
+ */
+char *stpcpy(char *__restrict__ dest, const char *__restrict__ src);
+char *stpcpy(char *__restrict__ dest, const char *__restrict__ src)
+{
+ while ((*dest++ = *src++) != '\0')
+ /* nothing */;
+ return --dest;
+}
+EXPORT_SYMBOL(stpcpy);
+
#ifndef __HAVE_ARCH_STRCAT
/**
* strcat - Append one %NUL-terminated string to another
--
cgit 1.2.3-korg
@@ -8,13 +8,24 @@ _config="config-$_flavor.$CARCH"
maintainer=""
pkgname=linux-$_flavor
pkgver=5.3_rc5
pkgrel=8
pkgrel=9
arch="aarch64"
_carch="arm64"
pkgdesc="Google Pixel 3 XL kernel fork, close to mainline"
url="https://kernel.org/"
license="GPL2-2.0-only"
makedepends="perl sed installkernel bash gmp-dev bc linux-headers elfutils-dev openssl-dev file bison flex"
license="GPL-2.0-only"
makedepends="
bison
clang
findutils
flex
lld
llvm
openssl-dev
perl
postmarketos-installkernel
zstd
"
options="!strip !check !tracedeps
pmb:cross-native
"
@@ -26,6 +37,7 @@ source="
$pkgname-$_commit.tar.gz::https://github.com/Pixel3Dev/$_repository/archive/$_commit.tar.gz
config-$_flavor.aarch64
0001-linux4.17-gcc10-extern_YYLOC_global_declaration.patch
10_add_stpcpy.patch
"
builddir="$srcdir/linux-$_commit"
@@ -38,7 +50,7 @@ prepare() {
build() {
unset LDFLAGS
# V=1: workaround for pma#1990
make ARCH="$_carch" CC="${CC:-gcc}" \
make ARCH="$_carch" LLVM=1 LLVM_IAS=1 \
KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-$_flavor" \
CFLAGS_MODULE=-fno-pic V=1
}
@@ -50,6 +62,8 @@ package() {
make modules_install dtbs_install \
ARCH="$_carch" \
LLVM=1 \
LLVM_IAS=1 \
INSTALL_PATH="$pkgdir"/boot \
INSTALL_MOD_PATH="$pkgdir" \
INSTALL_DTBS_PATH="$pkgdir/boot/dtbs"
@@ -62,6 +76,7 @@ package() {
sha512sums="
1ce235689d7ce0b40be203cb16c1bdfe9bc7b2c5e793a942afc5ea4f3268a0a15b684d9c4017a87916d989d8592a96a4223976c95bf7fcca603e71d2f20fee86 linux-google-crosshatch-mainline-9c9b87cec239101274451cc9c086da60108f9fda.tar.gz
62eb29876da044ee5b112a80e750b7511280a2a1624d7264ee41ec09d09072c03ba8052f27df644b116dded1becc86c807de9fe3ba31fca54dcdc12b58345f12 config-google-crosshatch-mainline.aarch64
858f75f29fc18b600f2a8359c69d53628665f926fa3b06010a9cb6b377555e4786b2967c98a9a752277dae1071bfb1980f6422e1d72f4661da4b652a342004f6 config-google-crosshatch-mainline.aarch64
27827877040007fc1c4c719f7e2e19e5c272d44972415cfc53feba0313d87e4074f8204bdb13cbc5fe21ea61bf595314b68f10c081e7b7bac3c888b60f008acf 0001-linux4.17-gcc10-extern_YYLOC_global_declaration.patch
706c2d3a178231d9f79f5f594cebaafdc6a39add602cca4c8a381ca181d27a82afb49aef494dc7b11905089d337c344cb9ce05b6d94199af37a4a46cc9cf22f1 10_add_stpcpy.patch
"
@@ -4,14 +4,13 @@
#
#
# Compiler: gcc (Alpine 15.2.0) 15.2.0
# Compiler: Alpine clang version 22.1.2
#
CONFIG_CC_IS_GCC=y
CONFIG_GCC_VERSION=150200
CONFIG_CLANG_VERSION=0
CONFIG_GCC_VERSION=0
CONFIG_CC_IS_CLANG=y
CONFIG_CLANG_VERSION=220102
CONFIG_CC_CAN_LINK=y
CONFIG_CC_HAS_ASM_GOTO=y
CONFIG_CC_HAS_WARN_MAYBE_UNINITIALIZED=y
CONFIG_IRQ_WORK=y
CONFIG_BUILDTIME_EXTABLE_SORT=y
CONFIG_THREAD_INFO_IN_TASK=y
@@ -743,7 +742,6 @@ CONFIG_ARCH_USE_MEMREMAP_PROT=y
CONFIG_ARCH_HAS_GCOV_PROFILE_ALL=y
# end of GCOV-based kernel profiling
CONFIG_PLUGIN_HOSTCC=""
CONFIG_HAVE_GCC_PLUGINS=y
# end of General architecture-dependent options
@@ -7510,7 +7508,7 @@ CONFIG_HAVE_ARCH_KASAN_SW_TAGS=y
CONFIG_CC_HAS_KASAN_GENERIC=y
CONFIG_CC_HAS_KASAN_SW_TAGS=y
# CONFIG_KASAN is not set
CONFIG_KASAN_STACK=1
CONFIG_KASAN_STACK=0
# end of Memory Debugging
CONFIG_ARCH_HAS_KCOV=y