Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3148109pxv; Mon, 12 Jul 2021 10:24:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/RhpkVu111GRAvYFrFZ9f/rFfV6pvWIkC5v6pjZBBPMnbltFFmH9vGLiRuF1xMPBInO7a X-Received: by 2002:a17:906:3c14:: with SMTP id h20mr204710ejg.176.1626110649613; Mon, 12 Jul 2021 10:24:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626110649; cv=none; d=google.com; s=arc-20160816; b=fO34leLQFAYgZQ494q4Ctyb+exdOvbxzHxa/bvYEfsz++TUbGWyorjS1eoahtYG7gK n/akO+K5lMJWpZf+mgGDt5J6UgSH+MyXO3ITSW/oY5MF9W/NOkpaxZ8T8VOwdYYnCg8F P+2xPccSUGaYPbDtY3UcE850mp4HKyTJvjv0yZ7gyBqoa19cHjllkvwJTDJJsJwxeoyg bBuLyUzOt5sNWuVX/fAiGyN2AFuo2lGXQMYlIW3k87yH0IjBkRVrmIM38LDY9I7HWCVw sHP7OqIMxvQSuewlRM2HnHqDF+loMBQnWA8wj5Yz0MXpPxHs0tsTzc0Xw5MICqNrQyiy Js2Q== 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=vJSus6xqz4Py/YBsR2PyDSFXECwi8SLf51Zt42z9NT4=; b=E2wLLEULqnBRpI7uw44GVgoT2pzFLz6bS1TZOLjyWMj5qF0U46kn5N6YJvNv3qXrh4 rfl6wVTDUC+2UmFmFGWYZccwPCyTmiYpDrNUUCLZai/ADap0HjdeKw4ECCdAgV95LTGW 3nooMB5/GwHb7tYqs9zOXJAYVGrW4it1MRrfwfrqf1Tj4wny+YSm1pgS6AO36bvmTuFB oRSsLVpa0lkk52o6bCeZBHwjdDSsMzHfGMSN4L7a4ibEMhhAA/japBHOhY9SOs508Yf3 4Ul25gnn2ee9pY7L5BDRZ2tjaO+uUsbjJN4q+sk9koGg1AyRtZSfUvKeTjXzgqd8J0FF X1ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Mmcvc7l5; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h93si20495008edd.584.2021.07.12.10.23.46; Mon, 12 Jul 2021 10:24:09 -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=@chromium.org header.s=google header.b=Mmcvc7l5; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234728AbhGLRZi (ORCPT + 99 others); Mon, 12 Jul 2021 13:25:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230374AbhGLRZh (ORCPT ); Mon, 12 Jul 2021 13:25:37 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F029C0613DD for ; Mon, 12 Jul 2021 10:22:49 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id a127so17027288pfa.10 for ; Mon, 12 Jul 2021 10:22:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=vJSus6xqz4Py/YBsR2PyDSFXECwi8SLf51Zt42z9NT4=; b=Mmcvc7l5nHdDlEh0IVqZJc5w8y60uSbHCff6KeC5Jkl14UYWGJpRd6DGrn/7aSy0jH /ppNubSXnDqrbctFIwoOwew8asmkJjWJJw8zZSLfC5cnx1Ol8I0j/BP+hoo39m4jPp/x xrJ7JhwedpqtUTVCf02vJjcsV83MQAKp6+cmY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=vJSus6xqz4Py/YBsR2PyDSFXECwi8SLf51Zt42z9NT4=; b=gJkeo0jQt5g7rm2hSOsMkebYt+JsFCaV5K8cssbL967mig3VT0F16XG7oXrmNKzI8l KaGd7ld6VCdmB06YhL9fumYfrrz8Cv2OWNoGxfb8/GWQJaM7macurCLZt4O2u7gmU4CU jm6G0AvJYEs5wMRL8jCG9B4Do7tcqG7Jug6gWE+KBnnI7VHSZe+Fh8ED5MMHfw6Bgm4t SdWUc1O5oTK++PW033yUYZ8D9yFFLmSqyNT9mSFT0CLbLtt6Z1WLB0li6fkHx2tlMXOv /e2Yj7spUX719jV0SE9gRQpPGltJ8AoW15kA0Riz5yAQoFIcUbF4L8BsaTtk7MqeSjAE 4YtA== X-Gm-Message-State: AOAM531oXCOF6WfJE9yyzSI8B4v4owMYCYElYHk3Gk1/GSY3eSVzYw8Q rNNVawLwBVDV5EMN9aC2T0BaIw== X-Received: by 2002:a63:1a12:: with SMTP id a18mr165366pga.269.1626110568824; Mon, 12 Jul 2021 10:22:48 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id i8sm46529pjh.36.2021.07.12.10.22.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jul 2021 10:22:48 -0700 (PDT) Date: Mon, 12 Jul 2021 10:22:47 -0700 From: Kees Cook To: Tor Vic Cc: "linux-kernel@vger.kernel.org" , masahiroy@kernel.org, Nathan Chancellor , "ndesaulniers@google.com" , linux-kbuild@vger.kernel.org, "clang-built-linux@googlegroups.com" Subject: Re: [PATCH 1/1] Kbuild, clang: add option for choosing a ThinLTO cache directory Message-ID: <202107121021.38F447EBE4@keescook> References: 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 On Mon, Jul 12, 2021 at 11:10:04AM +0000, Tor Vic wrote: > 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. Ah-ha, good idea. Thanks! Question below... > > 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. Why are these changes needed in Makefile.lib and Makefile.modfinal? Isn't KBUILD_LDFLAGS already populated from the top-level Makefile? -- Kees Cook