Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2EE2CC64EC4 for ; Fri, 17 Feb 2023 15:27:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230084AbjBQP1x (ORCPT ); Fri, 17 Feb 2023 10:27:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229608AbjBQP1u (ORCPT ); Fri, 17 Feb 2023 10:27:50 -0500 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81EE410B for ; Fri, 17 Feb 2023 07:27:48 -0800 (PST) Received: by mail-pj1-x102b.google.com with SMTP id ml23-20020a17090b361700b00234463de251so1705009pjb.3 for ; Fri, 17 Feb 2023 07:27:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=FjhxRmxnq7g/s7HTg3+kkGL/XHuH+Vbf1L6uY1gtdZo=; b=FI/KCZOninl4pna7XqfUzhnxFpGIrbQeTbMujiTucgT+kYUmTkqKvpqrY0BBWfyGHl kGVHGRvlZzrxQgBr1yfxol8SKtKTNnefzdaSMXohxCDU/zWuaKWZDs+j15osVIse5Jbs pPrmNP9mEpEy35h4of6Aq3SVWil9eh91QVjrY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=FjhxRmxnq7g/s7HTg3+kkGL/XHuH+Vbf1L6uY1gtdZo=; b=mqlAy9/ALBKWI8Aas3m7kk/TDtkT0GGNTd5Dgmcm71dLTlUO0UvmBfHXOnQCUBo6Ty coZCo569+KEnCvOpd89MkslDajTGuWujr6B0ewyKabQ7/vTPFpsAWAcnKTuHA/ZICCGh 4kKki3QvdLwpJne1roNDGUIOAmlEIOkoRjogmc9asNkSRPM/CYmP4nTY7XHKUcOrr3lt AdHBzzVzJCO1tXKT/EtlttnD+xvCVxdH4d5PRXe2WwgAOnTkDozdhffdnFdtP6vcebWx uI3zQh5Mt0bXOhLtFwLIFjnrOI+8LqGBgCoJCB9h3/jwl+dxJzffF3Vv8euHPAoLmFlY F1YQ== X-Gm-Message-State: AO0yUKVFrMG2TOB11Trrcm0je1O3uIBytx7HhaV0USd3BgDtAsdX0WJP Q0oIGQAOnlR06f20oeEGd5gUIz2COmG7lYavPUUzLw== X-Google-Smtp-Source: AK7set+MhY2O08saH1T5RViqTcHgqAmXt9TEW6+Qid0bDYcQBDwu1dbJU5pEbkggOuOqzWdO29LJIwiJ55IFIJYYaW8= X-Received: by 2002:a17:90b:3a8f:b0:234:117c:970f with SMTP id om15-20020a17090b3a8f00b00234117c970fmr1596590pjb.28.1676647667935; Fri, 17 Feb 2023 07:27:47 -0800 (PST) MIME-Version: 1.0 References: <20230217151832.27784-1-revest@chromium.org> In-Reply-To: <20230217151832.27784-1-revest@chromium.org> From: Florent Revest Date: Fri, 17 Feb 2023 16:27:36 +0100 Message-ID: Subject: Re: [PATCH bpf-next] selftests/bpf: Fix cross compilation with CLANG_CROSS_FLAGS To: bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-kbuild@vger.kernel.org Cc: andrii@kernel.org, mykolal@fb.com, ast@kernel.org, daniel@iogearbox.net, kpsingh@kernel.org, masahiroy@kernel.org, nathan@kernel.org, ndesaulniers@google.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 17, 2023 at 4:18 PM Florent Revest wrote: > > I cross-compile my BPF selftests with the following command: > > CLANG_CROSS_FLAGS="--target=aarch64-linux-gnu --sysroot=/sysroot/" \ > make LLVM=1 CC=clang CROSS_COMPILE=aarch64-linux-gnu- SRCARCH=arm64 > > (Note the use of CLANG_CROSS_FLAGS to specify a custom sysroot instead > of letting clang use gcc's default sysroot) > > However, CLANG_CROSS_FLAGS gets propagated to host tools builds (libbpf > and bpftool) and because they reference it directly in their Makefiles, > they end up cross-compiling host objects which results in linking > errors. > > This patch ensures that CLANG_CROSS_FLAGS is reset if CROSS_COMPILE > isn't set (for example when reaching a BPF host tool build). Note: I'm not entirely sure which tree should take that patch. I tagged this patch as "bpf-next" because 1- that's the tree I know best 2- as far as I can tell, only BPF tools Makefiles reference CLANG_CROSS_FLAGS directly and are currently broken in this way 3- I figured this would be a simple enough patch that it's not too hard for another tree to take it. Anyway, I tried to CC other relevant folks, I figured there could be different opinions on how this should get solved, for example the bpf Makefiles using CLANG_CROSS_FLAGS could check whether CROSS_COMPILE is set first. I'd be happy to adapt a v2 to any suggestion.