Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1182067pxb; Sat, 30 Oct 2021 07:38:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpiEUAMY3s7hMeOvZ6762MetgvPOr2oqdTbISA0gcKU1pRAsFdrHmnW+e6Sj0pZO3u27L7 X-Received: by 2002:a17:907:868f:: with SMTP id qa15mr12388576ejc.386.1635604726777; Sat, 30 Oct 2021 07:38:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635604726; cv=none; d=google.com; s=arc-20160816; b=trW4jFA8yxXlsXsWpZyvkBe50tyNrf2Lj0kyJysO9nroPfTD+Ed3wwaCHvlzAV3RWd E5A1vuAEMLzqxZeDWE740Bj0SNRw1pvQv7n3OePG/1Kn4eYu5kvZw+/NWLEh/MXpEcfw 0fBKSGMECTSrMZoc5G3KN5H9n+GDxzWn0tiEtVFTkGMKqT7L3Had933vbvoZP58ygA4w 5+ImOSlaS6TtLn6f1sWvSaNgn8YBa2SHcfnloZbdk43eCOTt+RAeJs1H6RGm5pIP45aU /Bj9w0Kuzx9LQUfpzKF4voX9l6Jv6jQsec2OvaT+j8SkqAYEpGIdyNOiOSWJIDd2cifC PFtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ba2xFt3kXSmSTLD8SqkglhCszGSJjIidpOhGBZZRwqs=; b=x3AlLIhKYz5abN+tXTincSqM0uVCuv2dEK3GQmZNUY9evgonEQ5/BgM3y3YxSuV+xt W8UN9S1XsoNvKVZR6lp8LzdR03Si7xnQjybu0joXN6ffDbXfl94s6cK+ByzI3KQHYj4h Ox5A3KtUchzOlzMYL+N88hUm9q+5dT4XzSS4+Kby0J/jdXokHXnNe97j0PNN58uGeJ/S rAqA68aTSqpw7T6+eR1/dutethlSOuNnIzrV8/TgkAVWQG+uJ24oSe+hxwzkYc9utlt8 eaCJoFJGsWBT2evDe5znZ/eGYC43xcnviMUtENHK4AR6sliPv8ki4kp4yZKst/4SO4Wu FBkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=KxNTFF6M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c24si16083867edx.616.2021.10.30.07.38.21; Sat, 30 Oct 2021 07:38:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=KxNTFF6M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230086AbhJ3OhK (ORCPT + 99 others); Sat, 30 Oct 2021 10:37:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229585AbhJ3OhJ (ORCPT ); Sat, 30 Oct 2021 10:37:09 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97BC2C061570; Sat, 30 Oct 2021 07:34:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=ba2xFt3kXSmSTLD8SqkglhCszGSJjIidpOhGBZZRwqs=; b=KxNTFF6MESt7Owjy7Rsimcsszl 9FviqkuUnjHAEdEUcpb27yNW2R3RQl4BZ2BpEpgKnVGmCQgS43k8yyDkiEwOmJIXh9ny17Oqy49fk PDzxT4IF3ecJyJ+aS8I9Pl95V3b/lHt+cppYj8q6WWrmZVghxldeDp6c0yugf64yb86maeZhY0XW6 M4ELbvaS5q42icbzRDk3cL6+bH2lFgfKSth6aBFEFmuvDPZNSdnDF8V0ZJ41dihgWJ3r1h5l6jHoC 2yuB27lUIfCxkj/34CUOzYY9V4KFnELO6o+846IGnZxokUITPIP03oyMWbD8H19o9GstbZWmtYv4X f5ChCmVg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=worktop.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mgpQ1-002TG3-24; Sat, 30 Oct 2021 14:33:22 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id C89129816BA; Sat, 30 Oct 2021 16:33:11 +0200 (CEST) Date: Sat, 30 Oct 2021 16:33:11 +0200 From: Peter Zijlstra To: Nick Desaulniers Cc: Nathan Chancellor , Masahiro Yamada , Michal Marek , X86 ML , Linux Kernel Mailing List , Linux Kbuild mailing list , llvm@lists.linux.dev Subject: Re: [PATCH] kbuild: Support clang-$ver builds Message-ID: <20211030143311.GH174730@worktop.programming.kicks-ass.net> References: <20211028204855.GP174703@worktop.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Latestest greatness... :-) --- Subject: kbuild: Fix clang/llvm build infra Debian (and derived) distros ship their compilers as -$ver suffixed binaries. For gcc it is sufficent to use: $ make CC=gcc-12 However, clang builds (esp. clang-lto) need a whole array of tools to be exactly right, leading to unweildy stuff like: $ make CC=clang-13 LD=ld.lld=14 AR=llvm-ar-13 NM=llvm-nm-13 OBJCOPY=llvm-objcopy-13 OBJDUMP=llvm-objdump-13 READELF=llvm-readelf-13 STRIP=llvm-strip-13 LLVM=1 which is, quite franktly, totally insane and unusable. Instead make the CC variable DTRT, enabling one such as myself to use: $ make CC=clang-13 This also lets one quickly test different clang versions. Additionally, also support path based LLVM suites like: $ make CC=/opt/llvm/bin/clang Signed-off-by: Peter Zijlstra (Intel) --- Makefile | 45 +++++++++++++++++++++++++++--------- tools/scripts/Makefile.include | 50 ++++++++++++++++++++++++++++------------- 2 files changed, 68 insertions(+), 27 deletions(-) --- a/Makefile +++ b/Makefile @@ -423,9 +423,29 @@ HOST_LFS_CFLAGS := $(shell getconf LFS_C HOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS 2>/dev/null) HOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null) -ifneq ($(LLVM),) -HOSTCC = clang -HOSTCXX = clang++ +# powerpc and s390 don't yet work with LLVM as a whole +ifeq ($(ARCH),powerpc) +LLVM = 0 +endif +ifeq ($(ARCH),s390) +LLVM = 0 +endif + +# otherwise, if CC=clang, default to using LLVM to enable LTO +CC_BASE := $(shell echo $(CC) | sed 's/.*\///') +CC_NAME := $(shell echo $(CC_BASE) | cut -b "1-5") +ifeq ($(shell test "$(CC_NAME)" = "clang"; echo $$?),0) +LLVM ?= 1 +LLVM_PFX := $(shell echo $(CC) | sed 's/\(.*\/\)\?.*/\1/') +LLVM_SFX := $(shell echo $(CC_BASE) | cut -b "6-") +endif + +# if not set by now, do not use LLVM +LLVM ?= 0 + +ifneq ($(LLVM),0) +HOSTCC = $(LLVM_PFX)clang$(LLVM_SFX) +HOSTCXX = $(LLVM_PFX)clang++$(LLVM_SFX) else HOSTCC = gcc HOSTCXX = g++ @@ -442,15 +462,15 @@ KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) # Make variables (CC, etc...) CPP = $(CC) -E -ifneq ($(LLVM),) -CC = clang -LD = ld.lld -AR = llvm-ar -NM = llvm-nm -OBJCOPY = llvm-objcopy -OBJDUMP = llvm-objdump -READELF = llvm-readelf -STRIP = llvm-strip +ifneq ($(LLVM),0) +CC = $(LLVM_PFX)clang$(LLVM_SFX) +LD = $(LLVM_PFX)ld.lld$(LLVM_SFX) +AR = $(LLVM_PFX)llvm-ar$(LLVM_SFX) +NM = $(LLVM_PFX)llvm-nm$(LLVM_SFX) +OBJCOPY = $(LLVM_PFX)llvm-objcopy$(LLVM_SFX) +OBJDUMP = $(LLVM_PFX)llvm-objdump$(LLVM_SFX) +READELF = $(LLVM_PFX)llvm-readelf$(LLVM_SFX) +STRIP = $(LLVM_PFX)llvm-strip$(LLVM_SFX) else CC = $(CROSS_COMPILE)gcc LD = $(CROSS_COMPILE)ld @@ -461,6 +481,7 @@ OBJDUMP = $(CROSS_COMPILE)objdump READELF = $(CROSS_COMPILE)readelf STRIP = $(CROSS_COMPILE)strip endif + PAHOLE = pahole RESOLVE_BTFIDS = $(objtree)/tools/bpf/resolve_btfids/resolve_btfids LEX = flex --- a/tools/scripts/Makefile.include +++ b/tools/scripts/Makefile.include @@ -51,12 +51,32 @@ define allow-override $(eval $(1) = $(2))) endef -ifneq ($(LLVM),) -$(call allow-override,CC,clang) -$(call allow-override,AR,llvm-ar) -$(call allow-override,LD,ld.lld) -$(call allow-override,CXX,clang++) -$(call allow-override,STRIP,llvm-strip) +# powerpc and s390 don't yet work with LLVM as a whole +ifeq ($(ARCH),powerpc) +LLVM = 0 +endif +ifeq ($(ARCH),s390) +LLVM = 0 +endif + +# otherwise, if CC=clang, default to using LLVM to enable LTO +CC_BASE := $(shell echo $(CC) | sed 's/.*\///') +CC_NAME := $(shell echo $(CC_BASE) | cut -b "1-5") +ifeq ($(shell test "$(CC_NAME)" = "clang"; echo $$?),0) +LLVM ?= 1 +LLVM_PFX := $(shell echo $(CC) | sed 's/\(.*\/\)\?.*/\1/') +LLVM_SFX := $(shell echo $(CC_BASE) | cut -b "6-") +endif + +# if not set by now, do not use LLVM +LLVM ?= 0 + +ifneq ($(LLVM),0) +$(call allow-override,CC,$(LLVM_PFX)clang$(LLVM_SFX)) +$(call allow-override,AR,$(LLVM_PFX)llvm-ar$(LLVM_SFX)) +$(call allow-override,LD,$(LLVM_PFX)ld.lld$(LLVM_SFX)) +$(call allow-override,CXX,$(LLVM_PFX)clang++$(LLVM_SFX)) +$(call allow-override,STRIP,$(LLVM_PFX)llvm-strip$(LLVM_SFX)) else # Allow setting various cross-compile vars or setting CROSS_COMPILE as a prefix. $(call allow-override,CC,$(CROSS_COMPILE)gcc) @@ -68,10 +88,10 @@ endif CC_NO_CLANG := $(shell $(CC) -dM -E -x c /dev/null | grep -Fq "__clang__"; echo $$?) -ifneq ($(LLVM),) -HOSTAR ?= llvm-ar -HOSTCC ?= clang -HOSTLD ?= ld.lld +ifneq ($(LLVM),0) +HOSTAR ?= $(LLVM_PFX)llvm-ar$(LLVM_SFX) +HOSTCC ?= $(LLVM_PFX)clang$(LLVM_SFX) +HOSTLD ?= $(LLVM_PFX)ld.lld$(LLVM_SFX) else HOSTAR ?= ar HOSTCC ?= gcc @@ -79,11 +99,11 @@ HOSTLD ?= ld endif # Some tools require Clang, LLC and/or LLVM utils -CLANG ?= clang -LLC ?= llc -LLVM_CONFIG ?= llvm-config -LLVM_OBJCOPY ?= llvm-objcopy -LLVM_STRIP ?= llvm-strip +CLANG ?= $(LLVM_PFX)clang$(LLVM_SFX) +LLC ?= $(LLVM_PFX)llc$(LLVM_SFX) +LLVM_CONFIG ?= $(LLVM_PFX)llvm-config$(LLVM_SFX) +LLVM_OBJCOPY ?= $(LLVM_PFX)llvm-objcopy$(LLVM_SFX) +LLVM_STRIP ?= $(LLVM_PFX)llvm-strip$(LLVM_SFX) ifeq ($(CC_NO_CLANG), 1) EXTRA_WARNINGS += -Wstrict-aliasing=3