Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp616656pxu; Tue, 1 Dec 2020 21:50:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJy5nicga3Y+Qt7ZxfwQ/qXOfHzMDvJ19OU51dxI11jqHCgy5RDsBLirWevhmS5S/GccP5YV X-Received: by 2002:a50:9ee6:: with SMTP id a93mr1075527edf.174.1606888222448; Tue, 01 Dec 2020 21:50:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606888222; cv=none; d=google.com; s=arc-20160816; b=VBhL+cfb25UBxvi6GvP0yd8pH9PD0712eBdKdM2bltSkNyEoTlSXk721B4CYLQ9U6N z1NDZrmHjG8z4q+8og7lldp5AtzEVnnr4F7a5DxpO41Qx/v4/WnYA4ecbRhJd0JKG9ch nIbh1TO1GkN2HeEa7/4P9Z+KD1pMWpdPv61lF3CvDnLImBJ3Z4pck8YjRzGV6rZj6f1T C4PEGCRLunXResMuRv7pwBDu/bnbMTqI+csQ/WTeXooE3ck+M5wY+HOM+FLt2jhNIac/ /x9ukLlPX2NHDQhDm8JHxEplAPipcFhcRUXcJJksnm1anWqkb4IWFeFCH8U0kGHmkZUC D4Uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=zIYg3wn3IiOAwIUjN3HHnL/xxZ7BzmV6ArGGQCieAHY=; b=mkB6/joJzUgvHkp2LBZGuqxU1uQNGLAM4Xa004jquYJtuc5XqRg7/x1fB5PRTl7u+d YPE18nm0fzKT67EIoCRqbl6AOn8ffClQ8mtNc01q74h01DJZQVuOeLws7F5/gggE42O6 8vi8/+E+AyYGIXjQyTB+GD+Oob6zvueN44nZUHqtRvqwT1LQUS+hKgXGwUVRVUSlzGQ2 iFJbC1/K6b31Fz6R8DR/IZPRwncXHrdC4plzVO0pjQIQ/DFQ5kuFdHQbIGQK19F0FEsh 2JXjXVJ/AEbuCc87iUWEnvcdPGSmg32bFuzQkZspl0id3XvWr+kI8uSZjB+UIOOvx2f8 WENg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=bON2yGnf; 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=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bm4si255708ejb.283.2020.12.01.21.49.57; Tue, 01 Dec 2020 21:50:22 -0800 (PST) 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=@google.com header.s=20161025 header.b=bON2yGnf; 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=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728436AbgLBFr1 (ORCPT + 99 others); Wed, 2 Dec 2020 00:47:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726125AbgLBFr1 (ORCPT ); Wed, 2 Dec 2020 00:47:27 -0500 Received: from mail-vk1-xa42.google.com (mail-vk1-xa42.google.com [IPv6:2607:f8b0:4864:20::a42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23417C0613D4 for ; Tue, 1 Dec 2020 21:46:47 -0800 (PST) Received: by mail-vk1-xa42.google.com with SMTP id m6so147844vkl.2 for ; Tue, 01 Dec 2020 21:46:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zIYg3wn3IiOAwIUjN3HHnL/xxZ7BzmV6ArGGQCieAHY=; b=bON2yGnfCiyS2deASK7lq7vUUxyZx+TcNqxyx0Y2lzXGXaJk2/GGL6wVTlpf746M17 ewSfrj7S9dsZKHz9EXsFml/ZRzW3ibKt2hylTzUrhiQailV3BSYLijuRVIlNThE7Ss7H KnWN0tGzIrPrfvFAOAvf+8FI8ABAECA3BAv1o2Nf8hdcpJnE2U+4ENVHLDfsMJ2syTzS iaGmOfE/X9XwWP/ylcYRN5sQKiXL7/ZHlVEs4e0tCksSkzjQe+RVz9j9FQbs4OUZPc8T CR1MgHpyNAn/FzhGrLr7gcE7qYAYqX3l4Q2HISPXD2rjqVZX7wjj378ggI/rHdDvjDb8 F84w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zIYg3wn3IiOAwIUjN3HHnL/xxZ7BzmV6ArGGQCieAHY=; b=EIcAIbW/pDTsFRr329eyuicoczT+QVRK9a8lJocyEznzdK1EDY6/gBhhwPFcGG5QP5 QBaJukTE5lJcW1UilRpDWf9Sb/N9a4YtMOz8DXLw0K/GzO2MFGyISwOJux9Wqj+0Zkj7 Pwf3doshusbZcaGs5XJ9tNt2X4fQKCnCYqESQjJWzVZ9is0UVUna38ufQdLp8xZ+rs5l 8Xv5Jy3UUzTQSxXasS0PEOxAYJt8TbG/zWS/qJwRg/k4UVhjESrpQYk7cMX9Pm3M/f9G G3GcaCqCA794BZnKBbFnwDxd/gDj0IEXDl8llZeHoXcvTbPk0K2YN2VhKZSiyL+RboJK mdBQ== X-Gm-Message-State: AOAM531FSmaLhTAEfUg9GjmhI6MxH8s7gvsmUI91QMloLsqpyIXRSBSE 9IzN6xkGPFZXrEz5BylPp4ihJATpVtshnnlhYLXqww== X-Received: by 2002:a1f:36d4:: with SMTP id d203mr580407vka.22.1606888005927; Tue, 01 Dec 2020 21:46:45 -0800 (PST) MIME-Version: 1.0 References: <20201118220731.925424-1-samitolvanen@google.com> <20201130120130.GF24563@willie-the-truck> <202012010929.3788AF5@keescook> In-Reply-To: From: Sami Tolvanen Date: Tue, 1 Dec 2020 21:46:33 -0800 Message-ID: Subject: Re: [PATCH v7 00/17] Add support for Clang LTO To: Masahiro Yamada Cc: Kees Cook , Will Deacon , Steven Rostedt , Josh Poimboeuf , Peter Zijlstra , Greg Kroah-Hartman , "Paul E. McKenney" , Nick Desaulniers , clang-built-linux , Kernel Hardening , linux-arch , linux-arm-kernel , Linux Kbuild mailing list , Linux Kernel Mailing List , PCI Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 1, 2020 at 6:43 PM Masahiro Yamada wrote: > > On Wed, Dec 2, 2020 at 2:31 AM Kees Cook wrote: > > > > On Mon, Nov 30, 2020 at 12:01:31PM +0000, Will Deacon wrote: > > > Hi Sami, > > > > > > On Wed, Nov 18, 2020 at 02:07:14PM -0800, Sami Tolvanen wrote: > > > > This patch series adds support for building the kernel with Clang's > > > > Link Time Optimization (LTO). In addition to performance, the primary > > > > motivation for LTO is to allow Clang's Control-Flow Integrity (CFI) to > > > > be used in the kernel. Google has shipped millions of Pixel devices > > > > running three major kernel versions with LTO+CFI since 2018. > > > > > > > > Most of the patches are build system changes for handling LLVM bitcode, > > > > which Clang produces with LTO instead of ELF object files, postponing > > > > ELF processing until a later stage, and ensuring initcall ordering. > > > > > > > > Note that v7 brings back arm64 support as Will has now staged the > > > > prerequisite memory ordering patches [1], and drops x86_64 while we work > > > > on fixing the remaining objtool warnings [2]. > > > > > > Sounds like you're going to post a v8, but that's the plan for merging > > > that? The arm64 parts look pretty good to me now. > > > > I haven't seen Masahiro comment on this in a while, so given the review > > history and its use (for years now) in Android, I will carry v8 (assuming > > all is fine with it) it in -next unless there are objections. > > > What I dislike about this implementation is > it cannot drop any unreachable function/data. > (and it is completely different from GCC LTO) > > This is not real LTO. I'm not sure I understand your concern. LTO cannot drop functions or data from vmlinux.o that may be referenced externally. However, with CONFIG_LD_DEAD_CODE_DATA_ELIMINATION, the linker certainly can drop unused functions and data when linking vmlinux, and there's no reason this option can't be used together with LTO. In fact, Pixel 3 does enable this option, but in our experience, there isn't much unused code or data to remove, so later devices no longer use it. There's technically no reason why we couldn't postpone LTO until we link vmlinux instead, and thus allow the linker to possibly remove more unused code without the help of --gc-sections, but at least with the current build process, that would involve performing the slow LTO link step multiple times, which isn't worth it when we can get the performance benefits (and CFI) already when linking vmlinux.o with LTO. Sami