Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2882622pxv; Mon, 12 Jul 2021 04:19:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeOixNdp2yt//QcPZK4zqZz790hRiIihjMzjRwIm0jQ4CJ5VfxlcM746zUGG6u2XgMrpX3 X-Received: by 2002:a05:6402:358b:: with SMTP id y11mr38595205edc.43.1626088792748; Mon, 12 Jul 2021 04:19:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626088792; cv=none; d=google.com; s=arc-20160816; b=gq9mpaXLox6hRq82lBPnjQRsaOfyHdm+BzBNLXZcJCnc29Bp779zIorXVKjV0b2tdv DDNj1hrd3ecnolVimVt7MNDZbuaItKA1M/ZtsQehpOBJmG2bCqLIugaDAUq1/P6nlm7H vN8Y72RtOIGMBMG7cY7OY1n1tZGU+osEuEr0DG60HtqXoQfeMb9yWCUWyUzR2Ur60LQo bmcKhAFYno2GACf/oSTQyUO40ORODvTP/blP2vsDGYpRL9+v1W1TpJxCmTjex3t+47xx DmRpzleTXNa+alRzIQRqw0EseC9rHtZc0suL5ZXlsiMemBBh9JDglZxni/oSoAQD+caD 2Hfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:date:message-id:cc:to:subject:from:dkim-signature :dkim-signature; bh=wOi1UYYQ8I3f24rxux4lFTLL6nRIrOruMYvcRjf03t4=; b=KXRL6p6hzFu9AqCA7kMy7oWm72w0B0tiNOG1bJzdO/pxWZ7+Qm2OIqTuafrx6ypqUX TtNNBYtzhAbiIjASQUQRQ6s07WNVU9QgZFm+C2Xu3+2TpOS4/ibavWcle4YSu5NIwQQg 02Rub+Smxv4/LDKrRDBtjoTEKKbyLHFzkWg9Ie7oBalrrtVpcuaea5uUtZ95gDatCpGf TR40wQNYeZpwEyBa8WCEqPhb5SE81WmHm9f5pCyLAQsb3KyCtu0CfjMRXHHlGYanW8Nh zpS4ldxqVhG1yxB7nLWv6yQOCsRjo8sH1f5TAjNOtQPYh6XJ3VHMAIQX6gIaJP6cdpN7 zYdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mailbox.org header.s=mail20150812 header.b=n1hP2uZj; dkim=pass header.i=@mailbox.org header.s=mail20150812 header.b=j30PfgR9; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=mailbox.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w17si19565815ejb.632.2021.07.12.04.19.30; Mon, 12 Jul 2021 04:19:52 -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=@mailbox.org header.s=mail20150812 header.b=n1hP2uZj; dkim=pass header.i=@mailbox.org header.s=mail20150812 header.b=j30PfgR9; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=mailbox.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234001AbhGLLNH (ORCPT + 99 others); Mon, 12 Jul 2021 07:13:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231955AbhGLLNE (ORCPT ); Mon, 12 Jul 2021 07:13:04 -0400 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [IPv6:2001:67c:2050::465:202]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49B8AC0613DD; Mon, 12 Jul 2021 04:10:16 -0700 (PDT) Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4GNgz86l8BzQk9Q; Mon, 12 Jul 2021 13:10:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mailbox.org; h= content-transfer-encoding:content-language:content-type :content-type:mime-version:date:date:message-id:subject:subject :from:from:received; s=mail20150812; t=1626088209; bh=xOpulS9RVQ 75hhiqo9JTOyo5JltLbEXsGU4c2Ixs/xI=; b=n1hP2uZjMni+RSeupiOSuAEAMa Ewd6T3z18AfQ6gLLcU09tIolFVg08Irpys2Xt6MnF4uwNpmdCzdpj/crk/5O1h3m pzugvBpz7mC40pG/xcKS+D0G9EwshiP6OzA6oq6BcOc9l70xMc4mcSPf+dCojd56 sA5ObvCKZl943N9blJRA8WTZvHcMOTdD1U4Bm4lsGgTYCgRxEwucxl5CpFBpsn8z 0ASuC8rYWeer+ykI41Sz7h4BNEOIYgKB7o/VpzugyPSEWcnlK6d4WDPcxo+JoF8W vKhtXy09zS5AuANcelEVpfeHt2vXjJWMCzS1SqlxyjqFFISqGJbqYcBaq/DA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1626088210; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=wOi1UYYQ8I3f24rxux4lFTLL6nRIrOruMYvcRjf03t4=; b=j30PfgR9w6FwvvDn7LyvfJoGL61zQ5pQKt+1ZQcIjpdgGybHP6252WhlTyOqbuMvkZ+nq0 /59NEuVTHodqZS6AbDBa2UW19DY3DSASdpiZOAEpoDSTu0PU+H62YLCaTXdqJSIvYBmZuT Gvy7YawETJxNzSIeigxUZVRzEhdNmVhBctAyziPobz74/QWPmgSrXDZzAmO6j8Slo4x7Qk WL8mTWSLm9VTG9RFu6rHJdYC9hMGGE9ucx33jzcBD1Nq6oarUkVUXMulMYjtErAzDrY4/y up2tSzK5i1ls4NGc0zmn3w8OCYBnvKlzgyZh7iiONvNSTukCP5ob9uhBRC5l3g== X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter06.heinlein-hosting.de (spamfilter06.heinlein-hosting.de [80.241.56.125]) (amavisd-new, port 10030) with ESMTP id tO8fHc4YlX90; Mon, 12 Jul 2021 13:10:09 +0200 (CEST) From: Tor Vic Subject: [PATCH 1/1] Kbuild, clang: add option for choosing a ThinLTO cache directory To: "linux-kernel@vger.kernel.org" , masahiroy@kernel.org, Nathan Chancellor , "ndesaulniers@google.com" , keescook@chromium.org Cc: linux-kbuild@vger.kernel.org, "clang-built-linux@googlegroups.com" Message-ID: Date: Mon, 12 Jul 2021 11:10:04 +0000 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-MBO-SPAM-Probability: X-Rspamd-Score: -6.54 / 15.00 / 15.00 X-Rspamd-Queue-Id: 88D25182B X-Rspamd-UID: d25e57 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On some distros and configurations, it might be useful to allow for specifying a directory where Clang stores its ThinLTO cache. More specifically, when building the VirtualBox extramodules on Arch with its proper 'makepkg' build system and DKMS, against an already installed ThinLTO kernel, the build fails because it tries to create the ThinLTO cache in a directory that is not user-writable. A similar problem has been reported with openSUSE's OBS build system. Add a Kconfig option that allows users to choose a directory in which Clang's ThinLTO can store its cache. Link: https://github.com/ClangBuiltLinux/linux/issues/1104 Signed-off-by: Tor Vic --- Makefile | 5 +++-- arch/Kconfig | 10 ++++++++++ scripts/Makefile.lib | 4 ++++ scripts/Makefile.modfinal | 4 ++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index c3f9bd191b89..472bc8bfff03 100644 --- a/Makefile +++ b/Makefile @@ -932,7 +932,8 @@ endif ifdef CONFIG_LTO_CLANG ifdef CONFIG_LTO_CLANG_THIN CC_FLAGS_LTO := -flto=thin -fsplit-lto-unit -KBUILD_LDFLAGS += --thinlto-cache-dir=$(extmod_prefix).thinlto-cache +export thinlto-dir = $(if $(CONFIG_LTO_CLANG_THIN_CACHEDIR),$(CONFIG_LTO_CLANG_THIN_CACHEDIR)/) +KBUILD_LDFLAGS += --thinlto-cache-dir=$(thinlto-dir)$(extmod_prefix).thinlto-cache else CC_FLAGS_LTO := -flto endif @@ -1728,7 +1729,7 @@ PHONY += compile_commands.json clean-dirs := $(KBUILD_EXTMOD) clean: rm-files := $(KBUILD_EXTMOD)/Module.symvers $(KBUILD_EXTMOD)/modules.nsdeps \ - $(KBUILD_EXTMOD)/compile_commands.json $(KBUILD_EXTMOD)/.thinlto-cache + $(KBUILD_EXTMOD)/compile_commands.json $(thinlto-dir)$(KBUILD_EXTMOD)/.thinlto-cache PHONY += help help: diff --git a/arch/Kconfig b/arch/Kconfig index 129df498a8e1..19e4d140e12a 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -696,6 +696,16 @@ config LTO_CLANG_THIN https://clang.llvm.org/docs/ThinLTO.html If unsure, say Y. + +config LTO_CLANG_THIN_CACHEDIR + string "Clang ThinLTO cache directory" + depends on LTO_CLANG_THIN + default "" + help + This option allows users to choose a directory that stores + Clang's ThinLTO cache. + Leave empty for default. + endchoice config ARCH_SUPPORTS_CFI_CLANG diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 10950559b223..bca87a6aa35b 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -197,6 +197,10 @@ endif part-of-module = $(if $(filter $(basename $@).o, $(real-obj-m)),y) quiet_modtag = $(if $(part-of-module),[M], ) +ifdef CONFIG_LTO_CLANG_THIN +KBUILD_LDFLAGS += --thinlto-cache-dir=$(thinlto-dir)$(extmod-prefix).thinlto-cache +endif + modkern_cflags = \ $(if $(part-of-module), \ $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \ diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal index 5e9b8057fb24..ab0d72e21318 100644 --- a/scripts/Makefile.modfinal +++ b/scripts/Makefile.modfinal @@ -35,6 +35,10 @@ ifdef CONFIG_LTO_CLANG # avoid a second slow LTO link prelink-ext := .lto +ifdef CONFIG_LTO_CLANG_THIN +KBUILD_LDFLAGS += --thinlto-cache-dir=$(thinlto-dir)$(extmod-prefix).thinlto-cache +endif # CONFIG_LTO_CLANG_THIN + # ELF processing was skipped earlier because we didn't have native code, # so let's now process the prelinked binary before we link the module. -- 2.32.0