From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.0 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F16ACC433DF for ; Thu, 25 Jun 2020 16:15:47 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BC1052082F for ; Thu, 25 Jun 2020 16:15:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="rBFKbpfQ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="FNy/7DFb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BC1052082F Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=bh+uF/pGwtwamTCBzLBa8HoVVKrS23czDoBlaeT2ij8=; b=rBFKbpfQDdNcVgLV2Rlc3H3zF D3hTBcAmziwfzs8S96sO4wZkp+G86EQ3D6CgMPI8ZNY5n3vtH98Z/0dxZnoLCg8v86Uwb8x/Z0lVK w2YhoCauipDK5DbnIckPhk+bQF0pORO7ySlq8/fjnhp4I1aJjByndhWutq/Y/nQor+jMHBjOpFm9c s++iXZyHAubqi5mHtsYEwO1FcRvqe9G1zE1bZz4f9Zzfz85sotepSlUAD5gP/ZT9dqWNHUHjxGnSQ kxuu83quweBCQxypsu+I6iQd2xDYYauzhX9CjILMCL7ODAdaKU1kG1oLEJkbwVCyQ+4lvvoOFvvUN LL1OmIxVA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1joUVe-0000jo-Ca; Thu, 25 Jun 2020 16:13:54 +0000 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1joUVa-0000j9-Bx for linux-arm-kernel@lists.infradead.org; Thu, 25 Jun 2020 16:13:52 +0000 Received: by mail-pl1-x641.google.com with SMTP id 35so3004747ple.0 for ; Thu, 25 Jun 2020 09:13:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=tN3RRFkW8H40rA8SGu1JDOigZLSzT5qVO0+D16XtuLc=; b=FNy/7DFbxnBgI72+dWF1OpzoyRqVVhI3k7b313hoPAknwI2gtcpnrbI/QxduZaLChO XsS20NJXJUX+BgZZni3WHhBJhCOxGeey5qw4s+h96KkQc1DbqtdERktvlQbbWfMI5Qtj CMFRos0WWK71LdR3xO8mzueiOZZD/HrvnbZcL7TWPhuTj08pp29CzK2iwQtWYxS/KzPS DbZRhxXQXIM+BXTF2MYRYYBA9EL7Z4t+n9j3emOXcA8xRPQhjqftNQZaWno22ZXuxY9B OJCpp0YifwADaKWWU1uXVBh+ae7gxCNBEpNdOASG/NzMPjRUdcy8BrCxoR+02HHMW5zQ TEBA== 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=tN3RRFkW8H40rA8SGu1JDOigZLSzT5qVO0+D16XtuLc=; b=l7emzqQzisN5EiTm3kblZhZSWSdaBcin0RmLKYCW9MgeDfVKHaFeyHiZvZj4V3DMlf NXsLtHV7RGvXFmZGdHmn/NMzzv4mrYOeGqrcjrY+MNRpEfvXFigjId6oF1hebrZ+8EAL SPdafyB/vWCerJ/xveO7qEmJhY5j6E062VdlihZRnH2XNyOhkFygovbWrV/WY74MKL8o PJyCXH2ZprnvIn/HB08bg/9Rq9Gxni6LyEGGLrp3dU64Dujsv4PnuRzhKaD7qDCfsClK viZ9FUF4vy2EIWn6SazzxrVHz59hxjuJmJB3GbaL1AS5e6HS/7srkNTo5Z3+/8u7/YFv VmcA== X-Gm-Message-State: AOAM533+cFIJSDE+qv+rYOLB62NHPL3WvNtA8LDep2D5KIlR3G6YnvDs jCbkyS7sN/AnjWFc4TTkq5+lFQ== X-Google-Smtp-Source: ABdhPJxZZxKF0/AUF+MScBXa8zZXuQ+lX7KkH7oqN3X8Y0ebQY5u9x4x5ou8dadW03hvgkUjiMZCBw== X-Received: by 2002:a17:90a:7c4e:: with SMTP id e14mr4310401pjl.52.1593101626297; Thu, 25 Jun 2020 09:13:46 -0700 (PDT) Received: from google.com ([2620:15c:201:2:ce90:ab18:83b0:619]) by smtp.gmail.com with ESMTPSA id v7sm22710119pfn.147.2020.06.25.09.13.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jun 2020 09:13:45 -0700 (PDT) Date: Thu, 25 Jun 2020 09:13:39 -0700 From: Sami Tolvanen To: Nathan Chancellor Subject: Re: [PATCH 02/22] kbuild: add support for Clang LTO Message-ID: <20200625161339.GA173089@google.com> References: <20200624203200.78870-1-samitolvanen@google.com> <20200624203200.78870-3-samitolvanen@google.com> <20200625022647.GB2871607@ubuntu-n2-xlarge-x86> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200625022647.GB2871607@ubuntu-n2-xlarge-x86> X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, x86@kernel.org, Kees Cook , "Paul E. McKenney" , kernel-hardening@lists.openwall.com, Greg Kroah-Hartman , Masahiro Yamada , linux-kbuild@vger.kernel.org, Nick Desaulniers , linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com, linux-pci@vger.kernel.org, Will Deacon , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Jun 24, 2020 at 07:26:47PM -0700, Nathan Chancellor wrote: > Hi Sami, > > On Wed, Jun 24, 2020 at 01:31:40PM -0700, 'Sami Tolvanen' via Clang Built Linux wrote: > > This change adds build system support for Clang's Link Time > > Optimization (LTO). With -flto, instead of ELF object files, Clang > > produces LLVM bitcode, which is compiled into native code at link > > time, allowing the final binary to be optimized globally. For more > > details, see: > > > > https://llvm.org/docs/LinkTimeOptimization.html > > > > The Kconfig option CONFIG_LTO_CLANG is implemented as a choice, > > which defaults to LTO being disabled. To use LTO, the architecture > > must select ARCH_SUPPORTS_LTO_CLANG and support: > > > > - compiling with Clang, > > - compiling inline assembly with Clang's integrated assembler, > > - and linking with LLD. > > > > While using full LTO results in the best runtime performance, the > > compilation is not scalable in time or memory. CONFIG_THINLTO > > enables ThinLTO, which allows parallel optimization and faster > > incremental builds. ThinLTO is used by default if the architecture > > also selects ARCH_SUPPORTS_THINLTO: > > > > https://clang.llvm.org/docs/ThinLTO.html > > > > To enable LTO, LLVM tools must be used to handle bitcode files. The > > easiest way is to pass the LLVM=1 option to make: > > > > $ make LLVM=1 defconfig > > $ scripts/config -e LTO_CLANG > > $ make LLVM=1 > > > > Alternatively, at least the following LLVM tools must be used: > > > > CC=clang LD=ld.lld AR=llvm-ar NM=llvm-nm > > > > To prepare for LTO support with other compilers, common parts are > > gated behind the CONFIG_LTO option, and LTO can be disabled for > > specific files by filtering out CC_FLAGS_LTO. > > > > Note that support for DYNAMIC_FTRACE and MODVERSIONS are added in > > follow-up patches. > > > > Signed-off-by: Sami Tolvanen > > --- > > Makefile | 16 ++++++++ > > arch/Kconfig | 66 +++++++++++++++++++++++++++++++ > > include/asm-generic/vmlinux.lds.h | 11 ++++-- > > scripts/Makefile.build | 9 ++++- > > scripts/Makefile.modfinal | 9 ++++- > > scripts/Makefile.modpost | 24 ++++++++++- > > scripts/link-vmlinux.sh | 32 +++++++++++---- > > 7 files changed, 151 insertions(+), 16 deletions(-) > > > > diff --git a/Makefile b/Makefile > > index ac2c61c37a73..0c7fe6fb2143 100644 > > --- a/Makefile > > +++ b/Makefile > > @@ -886,6 +886,22 @@ KBUILD_CFLAGS += $(CC_FLAGS_SCS) > > export CC_FLAGS_SCS > > endif > > > > +ifdef CONFIG_LTO_CLANG > > +ifdef CONFIG_THINLTO > > +CC_FLAGS_LTO_CLANG := -flto=thin $(call cc-option, -fsplit-lto-unit) > > +KBUILD_LDFLAGS += --thinlto-cache-dir=.thinlto-cache > > +else > > +CC_FLAGS_LTO_CLANG := -flto > > +endif > > +CC_FLAGS_LTO_CLANG += -fvisibility=default > > +endif > > + > > +ifdef CONFIG_LTO > > +CC_FLAGS_LTO := $(CC_FLAGS_LTO_CLANG) > > +KBUILD_CFLAGS += $(CC_FLAGS_LTO) > > +export CC_FLAGS_LTO > > +endif > > + > > # arch Makefile may override CC so keep this after arch Makefile is included > > NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include) > > > > diff --git a/arch/Kconfig b/arch/Kconfig > > index 8cc35dc556c7..e00b122293f8 100644 > > --- a/arch/Kconfig > > +++ b/arch/Kconfig > > @@ -552,6 +552,72 @@ config SHADOW_CALL_STACK > > reading and writing arbitrary memory may be able to locate them > > and hijack control flow by modifying the stacks. > > > > +config LTO > > + bool > > + > > +config ARCH_SUPPORTS_LTO_CLANG > > + bool > > + help > > + An architecture should select this option if it supports: > > + - compiling with Clang, > > + - compiling inline assembly with Clang's integrated assembler, > > + - and linking with LLD. > > + > > +config ARCH_SUPPORTS_THINLTO > > + bool > > + help > > + An architecture should select this option if it supports Clang's > > + ThinLTO. > > + > > +config THINLTO > > + bool "Clang ThinLTO" > > + depends on LTO_CLANG && ARCH_SUPPORTS_THINLTO > > + default y > > + help > > + This option enables Clang's ThinLTO, which allows for parallel > > + optimization and faster incremental compiles. More information > > + can be found from Clang's documentation: > > + > > + https://clang.llvm.org/docs/ThinLTO.html > > + > > +choice > > + prompt "Link Time Optimization (LTO)" > > + default LTO_NONE > > + help > > + This option enables Link Time Optimization (LTO), which allows the > > + compiler to optimize binaries globally. > > + > > + If unsure, select LTO_NONE. > > + > > +config LTO_NONE > > + bool "None" > > + > > +config LTO_CLANG > > + bool "Clang's Link Time Optimization (EXPERIMENTAL)" > > + depends on CC_IS_CLANG && CLANG_VERSION >= 110000 && LD_IS_LLD > > I am curious, what is the reason for gating this at clang 11.0.0? > > Presumably this? https://github.com/ClangBuiltLinux/linux/issues/510 > > It might be nice to notate this so that we do not have to wonder :) Yes, that's the reason. I'll add a note about it. Thanks! Sami _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel