Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp876833ybt; Wed, 24 Jun 2020 13:33:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3t97ZPbP7lz/H5vnrxVFtCapADtwFOMpf3I90fraRp+v4w6UDCeMScJV4a7avCQ2V2CVk X-Received: by 2002:a17:906:fcc1:: with SMTP id qx1mr8811667ejb.379.1593030805852; Wed, 24 Jun 2020 13:33:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593030805; cv=none; d=google.com; s=arc-20160816; b=xc3HKRFYVShur8li+8JPv4U0rl4DSK4jQ38K9i+ys6qfvpBtA1x9SNTdVToxXF/2lq UF8/3LdP/izktlZxxwoAZNLgVPxRm7g8PaIilOysXkVy0YDawuhlTE6OyGMke0ZB9kiy sl0la5duthykFCHfClmMOlD5MXPe8Xh7J7OEe1k/iWulWaTXbUB/hSu9zNus9zR4z+bd zQ9OIlA551nFkRp395UHwvCBHOGOHS5Eo5zQiWofs4TxdOMAqHmbXTY0INOwlCsl2J6j cDXoh/r0pqkqTPDKC5zYrK1dvy0Wt6X74S1HoJp/eWllQoR3hr8ifTNI/58P0BC66NcF LwcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=geZqQu8Pc2IZyEmyfjSbirVoyCHoNCVPX8WSrD5/a0I=; b=htuo35ervlZmewTvth4cVxI8R487kmLcYo3oHn6zuCMLV7FksyWwtZOA3zZY1scK+s Ry0dtb3+AEASSANch4kChP6Ly7uC6goOWyPugll8F9y1gbLNLWm0euNsAjugfH97EPpP BS89X5NKKPE6rEpGg/4/Y+wSMR6Cw9j/s9QV7lTTxRjoHog8F0dL53HgeYI/UEDytJII 4mJPSw7kkjz08CHdbDXBZWUFMuIsdCE01VvPl8pyKTnEV9HjleO9XBral47QPBVvZf4M 0+bqBRI+com79O9OMqySal/jYg0+8afnkgDf87bKU7Ifnohm9cHaLZgWCtO7kTQr4Bs7 zc/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Uawx1Hym; 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 a1si3364789edb.90.2020.06.24.13.33.01; Wed, 24 Jun 2020 13:33:25 -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=@google.com header.s=20161025 header.b=Uawx1Hym; 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 S2389041AbgFXUct (ORCPT + 99 others); Wed, 24 Jun 2020 16:32:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388133AbgFXUcs (ORCPT ); Wed, 24 Jun 2020 16:32:48 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05762C0613ED for ; Wed, 24 Jun 2020 13:32:47 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 186so3453635yby.19 for ; Wed, 24 Jun 2020 13:32:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=geZqQu8Pc2IZyEmyfjSbirVoyCHoNCVPX8WSrD5/a0I=; b=Uawx1HymTuOmFuIsE6m0edc2JOJkrIL4ohCvAqVmbJ8lL51+F8GFU8Edzr7cqZcv2w HodyjPnW3CEUXq8PkZVULO6ZyoUtxp9+p+vdtGUCMz8qqae3fj+ztQ8oZGg5KLQxzxtv WsCNEibFNfuA+bNlcIR8b4sSEDOv2SkH85c5Dy7chvY+wP/aaRR1NsYEhp1bKM54GsoI 2QcLu0Jhfop40Tu+FeyQ89Qe5QVYishLUcPnbhRan/pilxFWfHclHWVyGJPxpvvrwTh0 JNHLSYYTI2a6tpFbw45+Zc3Ez5EH+jMImL6HifoQ7sZW+Y10m8LKlencaSHV2sNpKm9n vXag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=geZqQu8Pc2IZyEmyfjSbirVoyCHoNCVPX8WSrD5/a0I=; b=Q47Zmb4LkoaLFBjNBMnaC276nnHrKGHhG9+AhKT2DfTwxEXm/7w59EdhDWSwwQoACH 29hFd1nSoq5v3JjQqEujZdh1K/9n/vR6L43bS0321ZaKv/mdjzkbMAlVB8Z9d0HV7Lrs 5G7YVoyDi9V4K5onzWI4KViY6y02ggfH/wIyrEb66SvPsVeNAMrLwOTmdbFAH2xkIKHH Vl9QV/qNHO7C6FQ47npLIV5cqsmmKrmKh0Fmz095Jd3zeirXw6KY2/u4Y2N2o0bkUQFo 94OfyytxKzanJp/uCFZ3XSsdb6bda98JX68imDfJzJ+8G71D6CTqTo5oBnKX3gHe9BOT wYIg== X-Gm-Message-State: AOAM532nqB9CywAIiGrmDZscU/n4YVxkmiHZ4iCMsDe5EGhJqLYCOPTZ EHtJeXDam+uwpqwfEixl7WgfREsUxbZCghOOr3U= X-Received: by 2002:a25:3342:: with SMTP id z63mr44129932ybz.200.1593030767109; Wed, 24 Jun 2020 13:32:47 -0700 (PDT) Date: Wed, 24 Jun 2020 13:31:38 -0700 Message-Id: <20200624203200.78870-1-samitolvanen@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.27.0.212.ge8ba1cc988-goog Subject: [PATCH 00/22] add support for Clang LTO From: Sami Tolvanen To: Masahiro Yamada , Will Deacon Cc: Greg Kroah-Hartman , "Paul E. McKenney" , Kees Cook , Nick Desaulniers , clang-built-linux@googlegroups.com, kernel-hardening@lists.openwall.com, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, x86@kernel.org, Sami Tolvanen Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch series adds support for building x86_64 and arm64 kernels 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's Pixel devices have shipped with LTO+CFI kernels 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 first objtool patch in the series is already in linux-next, but as it's needed with LTO, I'm including it also here to make testing easier. Sami Tolvanen (22): objtool: use sh_info to find the base for .rela sections kbuild: add support for Clang LTO kbuild: lto: fix module versioning kbuild: lto: fix recordmcount kbuild: lto: postpone objtool kbuild: lto: limit inlining kbuild: lto: merge module sections kbuild: lto: remove duplicate dependencies from .mod files init: lto: ensure initcall ordering init: lto: fix PREL32 relocations pci: lto: fix PREL32 relocations modpost: lto: strip .lto from module names scripts/mod: disable LTO for empty.c efi/libstub: disable LTO drivers/misc/lkdtm: disable LTO for rodata.o arm64: export CC_USING_PATCHABLE_FUNCTION_ENTRY arm64: vdso: disable LTO arm64: allow LTO_CLANG and THINLTO to be selected x86, vdso: disable LTO only for vDSO x86, ftrace: disable recordmcount for ftrace_make_nop x86, relocs: Ignore L4_PAGE_OFFSET relocations x86, build: allow LTO_CLANG and THINLTO to be selected .gitignore | 1 + Makefile | 27 ++- arch/Kconfig | 65 +++++++ arch/arm64/Kconfig | 2 + arch/arm64/Makefile | 1 + arch/arm64/kernel/vdso/Makefile | 4 +- arch/x86/Kconfig | 2 + arch/x86/Makefile | 5 + arch/x86/entry/vdso/Makefile | 5 +- arch/x86/kernel/ftrace.c | 1 + arch/x86/tools/relocs.c | 1 + drivers/firmware/efi/libstub/Makefile | 2 + drivers/misc/lkdtm/Makefile | 1 + include/asm-generic/vmlinux.lds.h | 12 +- include/linux/compiler-clang.h | 4 + include/linux/compiler.h | 2 +- include/linux/compiler_types.h | 4 + include/linux/init.h | 78 +++++++- include/linux/pci.h | 15 +- kernel/trace/ftrace.c | 1 + lib/Kconfig.debug | 2 +- scripts/Makefile.build | 55 +++++- scripts/Makefile.lib | 6 +- scripts/Makefile.modfinal | 40 +++- scripts/Makefile.modpost | 26 ++- scripts/generate_initcall_order.pl | 270 ++++++++++++++++++++++++++ scripts/link-vmlinux.sh | 100 +++++++++- scripts/mod/Makefile | 1 + scripts/mod/modpost.c | 16 +- scripts/mod/modpost.h | 9 + scripts/mod/sumversion.c | 6 +- scripts/module-lto.lds | 26 +++ scripts/recordmcount.c | 3 +- tools/objtool/elf.c | 2 +- 34 files changed, 737 insertions(+), 58 deletions(-) create mode 100755 scripts/generate_initcall_order.pl create mode 100644 scripts/module-lto.lds base-commit: 26e122e97a3d0390ebec389347f64f3730fdf48f -- 2.27.0.212.ge8ba1cc988-goog