On Mon, Mar 16, 2026 at 12:15:28PM -0700, Josh Poimboeuf wrote:
> On Wed, Mar 11, 2026 at 04:18:40PM -0700, Song Liu wrote:
> > On Wed, Mar 4, 2026 at 7:32 PM Josh Poimboeuf <[email protected]> wrote:
> > >
> > > Add support for cross-compilation. The user must export ARCH, and
> > > either CROSS_COMPILE or LLVM.
> > >
> > > Signed-off-by: Josh Poimboeuf <[email protected]>
> > > ---
> > > scripts/livepatch/klp-build | 11 ++++++++++-
> > > 1 file changed, 10 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build
> > > index 809e198a561d..b6c057e2120f 100755
> > > --- a/scripts/livepatch/klp-build
> > > +++ b/scripts/livepatch/klp-build
> > > @@ -404,6 +404,14 @@ validate_patches() {
> > > revert_patches
> > > }
> > >
> > > +cross_compile_init() {
> > > + if [[ -v LLVM ]]; then
> > > + OBJCOPY=llvm-objcopy
> > > + else
> > > + OBJCOPY="${CROSS_COMPILE:-}objcopy"
> > > + fi
> > > +}
> >
> > Shall we show a specific warning if
> > - ARCH is set; and
> > - ARCH is not the same as (uname -m); and
> > - neither LLVM nor CROSS_COMPILE is set.
>
> Yeah, I think that would be a good idea. Will do that for v2.
So, in general ARCH is complicated. For example:
- ARCH=arm64 would never match "uname -m" (aarch64)
- ARCH=i386 would use the same gcc binary (no cross-compiler needed)
- I'm sure there are many other edge cases...
Instead of a manual error, it may be simpler to just let the build fail
naturally if the user doesn't set the right ARCH.
Though, I think the check can be improved slightly, as ARCH is a
reasonably good indicator that cross-compiling is happening. So I can
at least add an ARCH check at the beginning like so?
cross_compile_init() {
if [[ ! -v ARCH ]]; then
OBJCOPY=objcopy
return 0
fi
if [[ -v LLVM ]]; then
OBJCOPY=llvm-objcopy
else
OBJCOPY="${CROSS_COMPILE:-}objcopy"
fi
}
--
Josh