mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Masahiro Yamada <masahiroy@kernel.org>
To: linux-kbuild@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	llvm@lists.linux.dev, Fangrui Song <maskray@google.com>,
	Masahiro Yamada <masahiroy@kernel.org>,
	"Dmitry V. Levin" <ldv@altlinux.org>,
	Elliot Berman <quic_eberman@quicinc.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [PATCH] kbuild: add --target to correctly cross-compile UAPI headers with Clang
Date: Sat,  5 Mar 2022 18:28:16 +0900	[thread overview]
Message-ID: <20220305092816.92114-1-masahiroy@kernel.org> (raw)

When you compile-test UAPI headers (CONFIG_UAPI_HEADER_TEST=y) with
Clang, they are currently compiled for the host target (likely x86_64)
regardless of the given ARCH=.

As a matter of fact, some exported headers include libc headers.
For example, include/uapi/sound/asound.h includes <stdlib.h> and <time.h>
after being exported. It is better to try to match the header search
paths to the target we are compiling them for.

Pick up the --target triple from KBUILD_CFLAGS in the same ways as
commit 7f58b487e9ff ("kbuild: make Clang build userprogs for target
architecture").

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

As far as I tested on Debian, Clang falls back to /usr/include/
when libc dev package for the specified target is not installed.

For example, --target=aarch64-linux-gnu tries to include

   /usr/aarch64-linux-gnu/include/stdlib.h

, which is available when libc6-dev-arm64-cross is installed.

Otherwise, includes

   /usr/include/stdlib.h





 usr/include/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/usr/include/Makefile b/usr/include/Makefile
index 703ee034033e..19ac4b63866d 100644
--- a/usr/include/Makefile
+++ b/usr/include/Makefile
@@ -12,7 +12,7 @@ UAPI_CFLAGS += $(CLANG_FLAGS)
 
 # In theory, we do not care -m32 or -m64 for header compile tests.
 # It is here just because CONFIG_CC_CAN_LINK is tested with -m32 or -m64.
-UAPI_CFLAGS += $(filter -m32 -m64, $(KBUILD_CFLAGS))
+UAPI_CFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS))
 
 # USERCFLAGS might contain sysroot location for CC.
 UAPI_CFLAGS += $(USERCFLAGS)
-- 
2.32.0


                 reply	other threads:[~2022-03-05  9:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220305092816.92114-1-masahiroy@kernel.org \
    --to=masahiroy@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=ldv@altlinux.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=maskray@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=quic_eberman@quicinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®