From patchwork Sun Mar 3 12:44:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Obst X-Patchwork-Id: 209305 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp909302dyc; Sun, 3 Mar 2024 05:11:47 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV9qPTW2tTtrlzZjL//Vduga0kWsi9iCgiDvzZdOtjVXrFQsgxfWP0zYC++Lqt6iJydTctJ0LTeNwfcZQQTl0MDz8eHGg== X-Google-Smtp-Source: AGHT+IEsMJGDaXycNh44hV3py2gs3WlYDbgCkanR4ErYsIBq2ho2RU1AF+jycEBgdqYVZpCvBRnG X-Received: by 2002:a17:903:41c4:b0:1d9:a2b1:8693 with SMTP id u4-20020a17090341c400b001d9a2b18693mr6977671ple.23.1709471506915; Sun, 03 Mar 2024 05:11:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709471506; cv=pass; d=google.com; s=arc-20160816; b=z2npq1ioy1qxGlsiWTd8XKRozwPTOSJ9v958n0jMqD4l5dRSmfxSWH4sFF6GZCtAUR giqdNP+E08xDSTUB+H57hq/Ab/KxO40+3di7WSC/gD9EEbXgfT6XXSgEfipGpTQ48cDR vpW3jjJ2uctFZ7lSVLbx3PZ74P06DlfC95FmG4MHaY9M1VsWwzBHuDT4K0iPEfjw5we+ fPxm4ctFxFf0RAJ9Ubs+QY/yC/wMb3EN2r+4SuzaA38lyVnD7mtrmrenpzZZauxwZGda zq3ISWQzo3CBLuCGjlmEtDRAKhFhZ2Ar5DauqPD9vNP/ie9tTiHaLtJc46dQ279gsjBp 5nCQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=ui-outboundreport:cc:to:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=+YEHT4BRPOmbiFOzonS26Dst3cMpNohKq+NCDf4gF3Y=; fh=4GQDg+3YV+FCrPCAbg/gubYRiGNRnUx0sJiJbabllMk=; b=dGXwI8aHQ+YKVwr02Ou0t1bH+oTvNUYBNNynfNwQNOS7k56v6uoqFwCTv1RITzCu0e qHSzYI7S1SMoxmAp3zeuN6YDTJnoC7JTZsm1fxCwp+x7IUK3Ob8MFeB3Z5uYqBkJbEgv y3sVmI34867X4NHt8veZUDfd/8BYp35JdVYGJ7y6K7CW774qWi35zccKsWwmnHW8kpUm 20N1VA63DLBeAHdYHeb02OkPU1n4R2mYPI/yskfe83vcU52k3WczwLfDkDXWMY+rTjkg M8uSkXE1M6gPIlyG30MNyRuhWxh5NnfOgl5BW5nmJM196Ue8qUPj0e65wB8hFA/5DC4y La4A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@valentinobst.de header.s=s1-ionos header.b=sv+TsEdx; arc=pass (i=1 spf=pass spfdomain=valentinobst.de dkim=pass dkdomain=valentinobst.de); spf=pass (google.com: domain of linux-kernel+bounces-89745-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89745-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id t14-20020a170902e84e00b001dba722cf4csi7081553plg.40.2024.03.03.05.11.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 05:11:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-89745-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@valentinobst.de header.s=s1-ionos header.b=sv+TsEdx; arc=pass (i=1 spf=pass spfdomain=valentinobst.de dkim=pass dkdomain=valentinobst.de); spf=pass (google.com: domain of linux-kernel+bounces-89745-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89745-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id D617EB21DCD for ; Sun, 3 Mar 2024 13:11:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B4CB0DDBB; Sun, 3 Mar 2024 13:11:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=valentinobst.de header.i=kernel@valentinobst.de header.b="sv+TsEdx" Received: from mout.kundenserver.de (mout.kundenserver.de [217.72.192.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2C11CA73; Sun, 3 Mar 2024 13:11:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.72.192.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709471476; cv=none; b=T3C7xibDzFBuUuUxxuKHJVnGl0FGS103eUw3uQB8aOYeBlUbEelswcteNdbbe1ITruo6kCE8N3Cv5CF885jst3oZc+CIvK2RuFQutzp0vA9j1RDEUi7ohBHXCCA9pXXQzT8dl39WQh1ZCrVcBdr2N8r5V+O2iZ4iGvk2XHckDsE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709471476; c=relaxed/simple; bh=PYafNNhjJMBNjwpI8k3yoMSKo6rMOK3JKkJ6SSwHO/c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=cDfuEZAjRYsaCsgUk7n02O7ePGL0/OlfVvK4h9K4WQswt8cseZlyGNPF2fz8eANGMYCH/hiFD2xkvuQaUwxKAXVumXZMWoKpgfN6NGDPy80HcOJwa++y3t7OXsidMhwuMQ9Rstt7yPZVlSjPOjzDJysM1aJ/mjhVOBxDPqpZtbY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=valentinobst.de; spf=pass smtp.mailfrom=valentinobst.de; dkim=pass (2048-bit key) header.d=valentinobst.de header.i=kernel@valentinobst.de header.b=sv+TsEdx; arc=none smtp.client-ip=217.72.192.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=valentinobst.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=valentinobst.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=valentinobst.de; s=s1-ionos; t=1709471466; x=1710076266; i=kernel@valentinobst.de; bh=PYafNNhjJMBNjwpI8k3yoMSKo6rMOK3JKkJ6SSwHO/c=; h=X-UI-Sender-Class:From:Date:Subject:To:Cc; b=sv+TsEdxulpP6xxBh3w2qqlA/lfQr9iE+QyomVvKB9E9gm4XPQpo5dJ/Nmx0XTaO qMIHS2fm/+wT4ramoa1MW6Zii10EdHYDCDyiysaqZNdZ4NIxEhIdOPdN2e51Q0bh9 Rrbo9kIqPwEpeFlBAMmkWPpr95zUBzVawsWaJQ4Ys71MzL0dbwvAOneA+lHlkSsgW e2k+FNTLV/t0DZeEU0/FLXxpg9+C1b/Zf8m/4H++5RmlIdgVab4dBhpwFat46B09u N5ynokZbx6ZFroKpEqTeV5LT6ESqQU1jTIYUHFWzRXdYgVA/H4M+hbnW5hDwKLzvb Wzkbp7Oz7l8/AdBV6w== X-UI-Sender-Class: 55c96926-9e95-11ee-ae09-1f7a4046a0f6 Received: from [192.168.2.229] ([80.133.137.1]) by mrelayeu.kundenserver.de (mreue109 [213.165.67.113]) with ESMTPSA (Nemesis) id 1MWAay-1rNOzJ37xi-00XgKM; Sun, 03 Mar 2024 13:44:59 +0100 From: Valentin Obst Date: Sun, 03 Mar 2024 13:44:36 +0100 Subject: [PATCH RFC] selftests: default to host arch for LLVM builds Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240303-selftests-libmk-llvm-rfc-v1-1-9ab53e365e31@valentinobst.de> X-B4-Tracking: v=1; b=H4sIALNw5GUC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDIxMDYwNj3eLUnLSS1OKSYt2czKTcbN2cnLJc3aK0ZF3TtFTj5LREyzQDSxM loPaCotS0zAqw0dFKQW7OSrG1tQA8nkx2bwAAAA== To: Shuah Khan Cc: Anders Roxell , Benjamin Poirier , Guillaume Tucker , John Hubbard , Marcos Paulo de Souza , Mark Brown , Nathan Chancellor , Sasha Levin , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Valentin Obst X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1709469899; l=4000; i=kernel@valentinobst.de; s=20240131; h=from:subject:message-id; bh=yZzV08YOvoeLyJJ85Mn+deJxF5jyLGkheHCV3AY3Ufs=; b=TSN9jyLjY6bKdK+NLS7g1B8qOvrNCSBg8JOwMdTGuEH/NmHm11YJWG+eHr+U7CQMkaHgHO8id 5nbK2BFfjh8ABJuP+6uaorPV+sBQssX/76EHtCTvre8y/PTwgfmYMvs X-Developer-Key: i=kernel@valentinobst.de; a=ed25519; pk=3s7U8y0mqkaiurgHSQQTYWOo2tw5HgzCg5vnJVfw37Y= X-Provags-ID: V03:K1:Sz5F4HnDlLJMIKupiDJCbYrM2nc8zUpYRbGOYYRMiddrKjStcw/ 7V1Vf7oZPMHDJla9MJDzF50E2SsmkBk8MyFa51I8SIkUHNjyfTUIbiyOjYKlXSmfZs6+4i+ J9bGyVj07bHh7iqUEIXrXQvsJhufztJxHDS5uA8tOykeY7LZ9RkI+wEOBOmh7YUsT/7tyxz Z19I4Xx70anfa2xxF7+BA== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:/CEI+nyxZus=;PvNMHw0P8TdM9bclnRLsNCwmtWm qzi2i0QYj3wTVzmHuEm3Jws0S1FtDwbYkByzou1DMeLFGHYdXFXyTQ1P+OTBNcj6nDYIwiIVV oqVFJjzCU6ZwVjVvTsUP7FRASskasGhy0K4z8jrmf9bKE/XzhQcz2GYPD00l1AfMD0TsB9BSR Vviu0/MFFQ0AvTuoxEGneDrf5ffFF7GEXkYewC59V4ALVqY/cC29FtC3ILu7dK71P6rnWTLpG JHDCQHz+zBeEqKphOJaYBIXRNC0rykQ0vbu3x+4B2o2GWWd+Le3fBzYn+0Mc0dD6nLVCXWriQ K9PKOFqNT2jUlgDZGqiPRytgMH4Syvrw60bdMl/cqlnRToPH8ZHvEOLF3dScr6foGxGVwbRAM n5hlv7Or+wrrYefzxXVtoqMCleJ4ZOW1AFUOFhM6fD7+k0/iebjx+Jv4XPJQ2Phh+nyYApBHP u3rsrfgHLMa8Hx1XFEaT6Pi83jHazAC39TaPSglzekwassWue8S8dgb+kxW7Ss33VZFeF1O02 fnF6UGnWbRjvuNeOGiKR0DuG/MHtULGix0X/uH/fTH8a9kwUM32SV1kryzCUJDu4oiLbPDlvX mkulJZOQvzYBTbSChQIIQGZbUuZQyppPjBFiAdU7fBMyPGcnK2bfJcbG8xEz2C1hYBZ1dY8gu B+6hC2lU30bYXm071ALFt7AwdatS81m4z7UYiYzr2dRan5IY+y5YJmZeglFSZe99Lu4vev9Vc t/DpYFPrhVkZWKs5CNZ55UBjw8b3bKtG+Q2axAb1Eno0VWVCfdeJCo= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792510794638217452 X-GMAIL-MSGID: 1792510794638217452 When using gcc without cross compiling, i.e., `CROSS_COMPILE` unset or empty, the selftests build defaults to the host architecture, i.e., it uses plain gcc. However, when compiling with clang an unset `ARCH` variable in combination with an unset `CROSS_COMPILE` variable, i.e., compiling for the host architecture, leads to compilation failures since `lib.mk` can not determine the clang target triple. In this case, the following error message is displayed for each subsystem that does not set `ARCH` in its own Makefile before including `lib.mk` (lines wrapped at 75 chrs): make[1]: Entering directory '/mnt/build/linux/tools/testing/selftests/ sysctl' ../lib.mk:33: *** Specify CROSS_COMPILE or add '--target=' option to lib.mk. Stop. make[1]: Leaving directory '/mnt/build/linux/tools/testing/selftests/ sysctl' Align the behavior for gcc and clang builds by interpreting unset `ARCH` and `CROSS_COMPILE` variables in `LLVM` builds as a sign that the user wants to build for the host architecture. This preserves the property that setting the `ARCH` variable to an unknown value will trigger an error that complains about insufficient information. RFC since I am not entirely sure if this behavior is in fact known and intended, and whether the way to obtain the host target triple is sufficiently general. (The flag was introduced in llvm-8 with [1], it will be an error for older clang versions, however, currently 13.0.1 is the minimal version required to build the kernel. For some clang binaries it prints the 'unknown' instead of the 'linux' version of the target, e.g., mips [2]). An alternative could be to simply do: ARCH ?= $(shell uname -m) before using it to select the target. Possibly with some post processing, but at that point we would likely be replicating `scripts/subarch.include`. Also unsure if it needs a 'Fixes: 795285ef2425 ("selftests: Fix clang cross compilation")'. Furthermore, this change might make it possible to remove the explicit setting of `ARCH` from the few subsystem Makefiles that do it. Would be happy to get some feedback on those points. If it looks OK I can also send it as a patch. Link: https://reviews.llvm.org/D50755 [1] Link: https://godbolt.org/z/r7Gn9bvv1 [2] Signed-off-by: Valentin Obst --- tools/testing/selftests/lib.mk | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) --- base-commit: d206a76d7d2726f3b096037f2079ce0bd3ba329b change-id: 20240303-selftests-libmk-llvm-rfc-5fe3cfa9f094 Best regards, -- Valentin Obst diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk index aa646e0661f3..a8f0442a36bc 100644 --- a/tools/testing/selftests/lib.mk +++ b/tools/testing/selftests/lib.mk @@ -7,6 +7,8 @@ else ifneq ($(filter -%,$(LLVM)),) LLVM_SUFFIX := $(LLVM) endif +CLANG := $(LLVM_PREFIX)clang$(LLVM_SUFFIX) + CLANG_TARGET_FLAGS_arm := arm-linux-gnueabi CLANG_TARGET_FLAGS_arm64 := aarch64-linux-gnu CLANG_TARGET_FLAGS_hexagon := hexagon-linux-musl @@ -18,7 +20,13 @@ CLANG_TARGET_FLAGS_riscv := riscv64-linux-gnu CLANG_TARGET_FLAGS_s390 := s390x-linux-gnu CLANG_TARGET_FLAGS_x86 := x86_64-linux-gnu CLANG_TARGET_FLAGS_x86_64 := x86_64-linux-gnu -CLANG_TARGET_FLAGS := $(CLANG_TARGET_FLAGS_$(ARCH)) + +# Default to host architecture if ARCH is not explicitly given. +ifeq ($(ARCH),) +CLANG_TARGET_FLAGS := $(shell $(CLANG) -print-target-triple) +else +CLANG_TARGET_FLAGS := $(CLANG_TARGET_FLAGS_$(ARCH)) +endif ifeq ($(CROSS_COMPILE),) ifeq ($(CLANG_TARGET_FLAGS),) @@ -30,7 +38,7 @@ else CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%)) endif # CROSS_COMPILE -CC := $(LLVM_PREFIX)clang$(LLVM_SUFFIX) $(CLANG_FLAGS) -fintegrated-as +CC := $(CLANG) $(CLANG_FLAGS) -fintegrated-as else CC := $(CROSS_COMPILE)gcc endif # LLVM