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.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,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 938C1C433E0 for ; Sat, 9 Jan 2021 14:55:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E8FC23A3C for ; Sat, 9 Jan 2021 14:55:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725999AbhAIOzO (ORCPT ); Sat, 9 Jan 2021 09:55:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725780AbhAIOzN (ORCPT ); Sat, 9 Jan 2021 09:55:13 -0500 Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF7BEC061786; Sat, 9 Jan 2021 06:54:32 -0800 (PST) Received: by mail-il1-x12e.google.com with SMTP id 75so13400337ilv.13; Sat, 09 Jan 2021 06:54:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:reply-to:from:date:message-id :subject:to:cc; bh=D12F/5eqLacVjkZjRiSdLFKTLkLrM01QiwzEKmGG7kg=; b=Bri5dW58vELYIPUb9vXYPdr9tYMsJFTKOWbYmN8Q8fgxaoSY9H7X/XH7Z4sJKN9kMR k7ac3vFv8ulpO5PFYnISJNesBpgn28ZhfYRVxfUh3Hi9g7lG1Gn01swLHg0d0xVgcAea VfCWkNSyxD6G2PZ/scf46Mpal2+O1EwqCSbv2avxKXFzt6N/XZ+DMLwbbnNoFBiAuNiu QGtqrVsh13mg6BfHkYFl2rcvzkNNv9Ur2vOyimzCkgJ31QBj5Jzh2gK2N6h6tWWjTvJ2 uPaDSoR9XmtsYewaILrMpcd4ifEL0nsEnomPIzmY0lJbEyvK3QiCu95bLzoqdtBig4pl 3zPA== 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:reply-to :from:date:message-id:subject:to:cc; bh=D12F/5eqLacVjkZjRiSdLFKTLkLrM01QiwzEKmGG7kg=; b=NmC0dwgBUz6TmKBqrE22+dIU+vrXNWaL/js9IfJgX3ESIZuLJYYt8nYMTrjuxXAj8Z mDBM1IzvVZ0pr1C+n/bXS/e7txkvvJX2xHyXYbm//cCxh6HE+EfMZjTc8OKYfsvz6T/a ji16tOIH9W2wfgfuo4WukHXiie4wwrhQ9XpTwQF8O0GjKvh/BQ34sjSl8hklUtEHQuD4 trvl4G6YH8sbKGDnly/V2KzudXpN3x6bgHsySkf1fcaIqGElMDZwoHzHsiXcPt6qmmgk cEmYPqVOCsTtk1+dE4q4xBrHjxSjoLnDA3C8epehaBolhh6vbUpS46iogQbpK/5CrIIx NqlQ== X-Gm-Message-State: AOAM530fT34h/3gZa5qqMDDvj77Cis4cWrLsf3Ks0M5JDzCpLFxyH4/M nZD0lyoqO2kCBRJJeQ2eGXFE0PKwa0bRv2zvQsY= X-Google-Smtp-Source: ABdhPJwVv4PFOqPosBHukOFnJ4wi1WhA23C1yUe3nwW75P2WzZXNyJ9esu/ru+OPCXZnxNgLZ7Vuc1GfwVAqUirf4I0= X-Received: by 2002:a05:6e02:1a43:: with SMTP id u3mr8682427ilv.209.1610204071843; Sat, 09 Jan 2021 06:54:31 -0800 (PST) MIME-Version: 1.0 References: <20201211184633.3213045-1-samitolvanen@google.com> In-Reply-To: <20201211184633.3213045-1-samitolvanen@google.com> Reply-To: sedat.dilek@gmail.com From: Sedat Dilek Date: Sat, 9 Jan 2021 15:54:20 +0100 Message-ID: Subject: Re: [PATCH v9 00/16] Add support for Clang LTO To: Sami Tolvanen Cc: Masahiro Yamada , Steven Rostedt , Will Deacon , Josh Poimboeuf , Peter Zijlstra , Greg Kroah-Hartman , "Paul E. McKenney" , Kees Cook , Nick Desaulniers , Clang-Built-Linux ML , 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 11, 2020 at 7:46 PM 'Sami Tolvanen' via Clang Built Linux 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 arm64 support depends on Will's memory ordering patches > [1]. I will post x86_64 patches separately after we have fixed the > remaining objtool warnings [2][3]. > > [1] https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git/log/?h=for-next/lto > [2] https://lore.kernel.org/lkml/20201120040424.a3wctajzft4ufoiw@treble/ > [3] https://git.kernel.org/pub/scm/linux/kernel/git/jpoimboe/linux.git/log/?h=objtool-vmlinux > Hi Sami, Thanks for the update. I am interested in having Clang LTO (Clang-CFI) for x86-64 working and help with testing. I tried the Git tree mentioned in [3] (together with changes from ). I only see in my build-log... drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: eb_relocate_parse_slow()+0x3d0: stack state mismatch: cfa1=7+120 cfa2=-1+0 drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: eb_copy_relocations()+0x229: stack state mismatch: cfa1=7+120 cfa2=-1+0 ...which was reported and worked on in [1]. This is with Clang-IAS version 11.0.1. Unfortunately, the recent changes in do not cleanly apply with Josh stuff. My intention/wish was to report this combination of patchsets "heals" a lot of objtool-warnings for vmlinux.o I observed with Clang-CFI. Is it possible to have a Git branch where Josh's objtool-vmlinux is working together with Clang-LTO? For testing purposes. Thanks. Regards, - Sedat - [1] https://github.com/ClangBuiltLinux/linux/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc > You can also pull this series from > > https://github.com/samitolvanen/linux.git lto-v9 > > --- > Changes in v9: > > - Added HAS_LTO_CLANG dependencies to LLVM=1 and LLVM_IAS=1 to avoid > issues with mismatched toolchains. > > - Dropped the .mod patch as Masahiro landed a better solution to > the split line issue in commit 7d32358be8ac ("kbuild: avoid split > lines in .mod files"). > > - Updated CC_FLAGS_LTO to use -fvisibility=hidden to avoid weak symbol > visibility issues with ThinLTO on x86. > > - Changed LTO_CLANG_FULL to depend on !COMPILE_TEST to prevent > timeouts in automated testing. > > - Added a dependency to CPU_LITTLE_ENDIAN to ARCH_SUPPORTS_LTO_CLANG > in arch/arm64/Kconfig. > > - Added a default symbol list to fix an issue with TRIM_UNUSED_KSYMS. > > Changes in v8: > > - Cleaned up the LTO Kconfig options based on suggestions from > Nick and Kees. > > - Dropped the patch to disable LTO for the arm64 nVHE KVM code as > David pointed out it's not needed anymore. > > Changes in v7: > > - Rebased to master again. > > - Added back arm64 patches as the prerequisites are now staged, > and dropped x86_64 support until the remaining objtool issues > are resolved. > > - Dropped ifdefs from module.lds.S. > > Changes in v6: > > - Added the missing --mcount flag to patch 5. > > - Dropped the arm64 patches from this series and will repost them > later. > > Changes in v5: > > - Rebased on top of tip/master. > > - Changed the command line for objtool to use --vmlinux --duplicate > to disable warnings about retpoline thunks and to fix .orc_unwind > generation for vmlinux.o. > > - Added --noinstr flag to objtool, so we can use --vmlinux without > also enabling noinstr validation. > > - Disabled objtool's unreachable instruction warnings with LTO to > disable false positives for the int3 padding in vmlinux.o. > > - Added ANNOTATE_RETPOLINE_SAFE annotations to the indirect jumps > in x86 assembly code to fix objtool warnings with retpoline. > > - Fixed modpost warnings about missing version information with > CONFIG_MODVERSIONS. > > - Included Makefile.lib into Makefile.modpost for ld_flags. Thanks > to Sedat for pointing this out. > > - Updated the help text for ThinLTO to better explain the trade-offs. > > - Updated commit messages with better explanations. > > Changes in v4: > > - Fixed a typo in Makefile.lib to correctly pass --no-fp to objtool. > > - Moved ftrace configs related to generating __mcount_loc to Kconfig, > so they are available also in Makefile.modfinal. > > - Dropped two prerequisite patches that were merged to Linus' tree. > > Changes in v3: > > - Added a separate patch to remove the unused DISABLE_LTO treewide, > as filtering out CC_FLAGS_LTO instead is preferred. > > - Updated the Kconfig help to explain why LTO is behind a choice > and disabled by default. > > - Dropped CC_FLAGS_LTO_CLANG, compiler-specific LTO flags are now > appended directly to CC_FLAGS_LTO. > > - Updated $(AR) flags as KBUILD_ARFLAGS was removed earlier. > > - Fixed ThinLTO cache handling for external module builds. > > - Rebased on top of Masahiro's patch for preprocessing modules.lds, > and moved the contents of module-lto.lds to modules.lds.S. > > - Moved objtool_args to Makefile.lib to avoid duplication of the > command line parameters in Makefile.modfinal. > > - Clarified in the commit message for the initcall ordering patch > that the initcall order remains the same as without LTO. > > - Changed link-vmlinux.sh to use jobserver-exec to control the > number of jobs started by generate_initcall_ordering.pl. > > - Dropped the x86/relocs patch to whitelist L4_PAGE_OFFSET as it's > no longer needed with ToT kernel. > > - Disabled LTO for arch/x86/power/cpu.c to work around a Clang bug > with stack protector attributes. > > Changes in v2: > > - Fixed -Wmissing-prototypes warnings with W=1. > > - Dropped cc-option from -fsplit-lto-unit and added .thinlto-cache > scrubbing to make distclean. > > - Added a comment about Clang >=11 being required. > > - Added a patch to disable LTO for the arm64 KVM nVHE code. > > - Disabled objtool's noinstr validation with LTO unless enabled. > > - Included Peter's proposed objtool mcount patch in the series > and replaced recordmcount with the objtool pass to avoid > whitelisting relocations that are not calls. > > - Updated several commit messages with better explanations. > > > Sami Tolvanen (16): > tracing: move function tracer options to Kconfig > kbuild: add support for Clang LTO > kbuild: lto: fix module versioning > kbuild: lto: limit inlining > kbuild: lto: merge module sections > kbuild: lto: add a default list of used symbols > init: lto: ensure initcall ordering > init: lto: fix PREL32 relocations > PCI: Fix PREL32 relocations for LTO > 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: vdso: disable LTO > arm64: disable recordmcount with DYNAMIC_FTRACE_WITH_REGS > arm64: allow LTO to be selected > > .gitignore | 1 + > Makefile | 45 +++-- > arch/Kconfig | 90 +++++++++ > arch/arm64/Kconfig | 4 + > arch/arm64/kernel/vdso/Makefile | 3 +- > drivers/firmware/efi/libstub/Makefile | 2 + > drivers/misc/lkdtm/Makefile | 1 + > include/asm-generic/vmlinux.lds.h | 11 +- > include/linux/init.h | 79 +++++++- > include/linux/pci.h | 19 +- > init/Kconfig | 1 + > kernel/trace/Kconfig | 16 ++ > scripts/Makefile.build | 48 ++++- > scripts/Makefile.lib | 6 +- > scripts/Makefile.modfinal | 9 +- > scripts/Makefile.modpost | 25 ++- > scripts/generate_initcall_order.pl | 270 ++++++++++++++++++++++++++ > scripts/link-vmlinux.sh | 70 ++++++- > scripts/lto-used-symbollist | 5 + > scripts/mod/Makefile | 1 + > scripts/mod/modpost.c | 16 +- > scripts/mod/modpost.h | 9 + > scripts/mod/sumversion.c | 6 +- > scripts/module.lds.S | 24 +++ > 24 files changed, 696 insertions(+), 65 deletions(-) > create mode 100755 scripts/generate_initcall_order.pl > create mode 100644 scripts/lto-used-symbollist > > > base-commit: 33dc9614dc208291d0c4bcdeb5d30d481dcd2c4c > -- > 2.29.2.576.ga3fc446d84-goog > > -- > You received this message because you are subscribed to the Google Groups "Clang Built Linux" group. > To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-linux+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20201211184633.3213045-1-samitolvanen%40google.com. 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=-10.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,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 9F427C433DB for ; Sat, 9 Jan 2021 15:15:32 +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 4F25923A04 for ; Sat, 9 Jan 2021 15:15:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4F25923A04 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.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:Reply-To:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=qD4qsnbn7ieWkL04tVvAPy8pRgc2Inhjr9RbGR1g89o=; b=2t+sGvV3CRASTWCE6bH4eyaUx iDnEQ6kY4Jgvd4CeDY9lCxGkdPoTRVlkX+iko5eE/xeuKWicWK4fJlfrEnZEytNdU781U5D2BgNzd gggbGEobSGW7O13vtlyXvGEbF/q7+41fLdx3CcWTrj2EGSko6UafZW7BN9XOJO9PI0k263zvrpuWk ghot4wr8BmcnDtvdEFpvbuQ/aqbFhM/ydIAI8ge73dWvxWlMRUIHqFEbAiD76QLS52Gag+wnctWkx iVpqzr/9C5ykFC9h5ZCJf5oHLSBfMHkqUnJ+/Pb3n2uvwS7oSY1HkIuymgkrSypmQnfEQofhpqoOB OiBFm/xJw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kyFv8-0007Cm-Sv; Sat, 09 Jan 2021 15:12:50 +0000 Received: from mail-il1-x12e.google.com ([2607:f8b0:4864:20::12e]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kyFdW-0007Mq-1g for linux-arm-kernel@lists.infradead.org; Sat, 09 Jan 2021 14:54:39 +0000 Received: by mail-il1-x12e.google.com with SMTP id 14so12156475ilq.2 for ; Sat, 09 Jan 2021 06:54:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:reply-to:from:date:message-id :subject:to:cc; bh=D12F/5eqLacVjkZjRiSdLFKTLkLrM01QiwzEKmGG7kg=; b=Bri5dW58vELYIPUb9vXYPdr9tYMsJFTKOWbYmN8Q8fgxaoSY9H7X/XH7Z4sJKN9kMR k7ac3vFv8ulpO5PFYnISJNesBpgn28ZhfYRVxfUh3Hi9g7lG1Gn01swLHg0d0xVgcAea VfCWkNSyxD6G2PZ/scf46Mpal2+O1EwqCSbv2avxKXFzt6N/XZ+DMLwbbnNoFBiAuNiu QGtqrVsh13mg6BfHkYFl2rcvzkNNv9Ur2vOyimzCkgJ31QBj5Jzh2gK2N6h6tWWjTvJ2 uPaDSoR9XmtsYewaILrMpcd4ifEL0nsEnomPIzmY0lJbEyvK3QiCu95bLzoqdtBig4pl 3zPA== 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:reply-to :from:date:message-id:subject:to:cc; bh=D12F/5eqLacVjkZjRiSdLFKTLkLrM01QiwzEKmGG7kg=; b=puFxUYdBo0rZB7z6S90w9GpJquSxcqwPRMXOqQm97JH1MGLhwFtk8YEkBmx04zVLb3 v3dgiIHvY2RDYH54GAUd2+dCxss9NwqTRh458tSEbvmmifDmOfzXff0utDiPWD9YqDHo NMxowJ+N07jBLzqkWaOFZpoV7BE+nGE0/EdqiSAJBySiyXj3vAJtIyM0tOkxOz8x20Yi Re7Ky5sfM/tg7wZQpR79IBCLCJVPsxUYWP75AP3gtSIN9kfrCKigIR8xstvD++mrDabj 4salE63fl8Y/nDAXKQphS8n8cZr+tCVEnlqNOpJENMIjxaygdr6LJzLJmbb43BLLjupA u9pg== X-Gm-Message-State: AOAM5314oSjXH4dxjUZIkZBi3BGElLZq4Roiryg4EsF8N5EdJ9TeB7sW f7U/krl3Da+SIHtb3o8Fbd7laOXy8AJApwBzqXM= X-Google-Smtp-Source: ABdhPJwVv4PFOqPosBHukOFnJ4wi1WhA23C1yUe3nwW75P2WzZXNyJ9esu/ru+OPCXZnxNgLZ7Vuc1GfwVAqUirf4I0= X-Received: by 2002:a05:6e02:1a43:: with SMTP id u3mr8682427ilv.209.1610204071843; Sat, 09 Jan 2021 06:54:31 -0800 (PST) MIME-Version: 1.0 References: <20201211184633.3213045-1-samitolvanen@google.com> In-Reply-To: <20201211184633.3213045-1-samitolvanen@google.com> From: Sedat Dilek Date: Sat, 9 Jan 2021 15:54:20 +0100 Message-ID: Subject: Re: [PATCH v9 00/16] Add support for Clang LTO To: Sami Tolvanen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210109_095438_140654_A0AF3751 X-CRM114-Status: GOOD ( 49.86 ) 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: , Reply-To: sedat.dilek@gmail.com Cc: linux-arch@vger.kernel.org, Kees Cook , "Paul E. McKenney" , kernel-hardening@lists.openwall.com, Peter Zijlstra , Greg Kroah-Hartman , Masahiro Yamada , linux-kbuild@vger.kernel.org, Nick Desaulniers , linux-kernel@vger.kernel.org, Steven Rostedt , Clang-Built-Linux ML , linux-pci@vger.kernel.org, Josh Poimboeuf , 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 Fri, Dec 11, 2020 at 7:46 PM 'Sami Tolvanen' via Clang Built Linux 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 arm64 support depends on Will's memory ordering patches > [1]. I will post x86_64 patches separately after we have fixed the > remaining objtool warnings [2][3]. > > [1] https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git/log/?h=for-next/lto > [2] https://lore.kernel.org/lkml/20201120040424.a3wctajzft4ufoiw@treble/ > [3] https://git.kernel.org/pub/scm/linux/kernel/git/jpoimboe/linux.git/log/?h=objtool-vmlinux > Hi Sami, Thanks for the update. I am interested in having Clang LTO (Clang-CFI) for x86-64 working and help with testing. I tried the Git tree mentioned in [3] (together with changes from ). I only see in my build-log... drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: eb_relocate_parse_slow()+0x3d0: stack state mismatch: cfa1=7+120 cfa2=-1+0 drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: eb_copy_relocations()+0x229: stack state mismatch: cfa1=7+120 cfa2=-1+0 ...which was reported and worked on in [1]. This is with Clang-IAS version 11.0.1. Unfortunately, the recent changes in do not cleanly apply with Josh stuff. My intention/wish was to report this combination of patchsets "heals" a lot of objtool-warnings for vmlinux.o I observed with Clang-CFI. Is it possible to have a Git branch where Josh's objtool-vmlinux is working together with Clang-LTO? For testing purposes. Thanks. Regards, - Sedat - [1] https://github.com/ClangBuiltLinux/linux/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc > You can also pull this series from > > https://github.com/samitolvanen/linux.git lto-v9 > > --- > Changes in v9: > > - Added HAS_LTO_CLANG dependencies to LLVM=1 and LLVM_IAS=1 to avoid > issues with mismatched toolchains. > > - Dropped the .mod patch as Masahiro landed a better solution to > the split line issue in commit 7d32358be8ac ("kbuild: avoid split > lines in .mod files"). > > - Updated CC_FLAGS_LTO to use -fvisibility=hidden to avoid weak symbol > visibility issues with ThinLTO on x86. > > - Changed LTO_CLANG_FULL to depend on !COMPILE_TEST to prevent > timeouts in automated testing. > > - Added a dependency to CPU_LITTLE_ENDIAN to ARCH_SUPPORTS_LTO_CLANG > in arch/arm64/Kconfig. > > - Added a default symbol list to fix an issue with TRIM_UNUSED_KSYMS. > > Changes in v8: > > - Cleaned up the LTO Kconfig options based on suggestions from > Nick and Kees. > > - Dropped the patch to disable LTO for the arm64 nVHE KVM code as > David pointed out it's not needed anymore. > > Changes in v7: > > - Rebased to master again. > > - Added back arm64 patches as the prerequisites are now staged, > and dropped x86_64 support until the remaining objtool issues > are resolved. > > - Dropped ifdefs from module.lds.S. > > Changes in v6: > > - Added the missing --mcount flag to patch 5. > > - Dropped the arm64 patches from this series and will repost them > later. > > Changes in v5: > > - Rebased on top of tip/master. > > - Changed the command line for objtool to use --vmlinux --duplicate > to disable warnings about retpoline thunks and to fix .orc_unwind > generation for vmlinux.o. > > - Added --noinstr flag to objtool, so we can use --vmlinux without > also enabling noinstr validation. > > - Disabled objtool's unreachable instruction warnings with LTO to > disable false positives for the int3 padding in vmlinux.o. > > - Added ANNOTATE_RETPOLINE_SAFE annotations to the indirect jumps > in x86 assembly code to fix objtool warnings with retpoline. > > - Fixed modpost warnings about missing version information with > CONFIG_MODVERSIONS. > > - Included Makefile.lib into Makefile.modpost for ld_flags. Thanks > to Sedat for pointing this out. > > - Updated the help text for ThinLTO to better explain the trade-offs. > > - Updated commit messages with better explanations. > > Changes in v4: > > - Fixed a typo in Makefile.lib to correctly pass --no-fp to objtool. > > - Moved ftrace configs related to generating __mcount_loc to Kconfig, > so they are available also in Makefile.modfinal. > > - Dropped two prerequisite patches that were merged to Linus' tree. > > Changes in v3: > > - Added a separate patch to remove the unused DISABLE_LTO treewide, > as filtering out CC_FLAGS_LTO instead is preferred. > > - Updated the Kconfig help to explain why LTO is behind a choice > and disabled by default. > > - Dropped CC_FLAGS_LTO_CLANG, compiler-specific LTO flags are now > appended directly to CC_FLAGS_LTO. > > - Updated $(AR) flags as KBUILD_ARFLAGS was removed earlier. > > - Fixed ThinLTO cache handling for external module builds. > > - Rebased on top of Masahiro's patch for preprocessing modules.lds, > and moved the contents of module-lto.lds to modules.lds.S. > > - Moved objtool_args to Makefile.lib to avoid duplication of the > command line parameters in Makefile.modfinal. > > - Clarified in the commit message for the initcall ordering patch > that the initcall order remains the same as without LTO. > > - Changed link-vmlinux.sh to use jobserver-exec to control the > number of jobs started by generate_initcall_ordering.pl. > > - Dropped the x86/relocs patch to whitelist L4_PAGE_OFFSET as it's > no longer needed with ToT kernel. > > - Disabled LTO for arch/x86/power/cpu.c to work around a Clang bug > with stack protector attributes. > > Changes in v2: > > - Fixed -Wmissing-prototypes warnings with W=1. > > - Dropped cc-option from -fsplit-lto-unit and added .thinlto-cache > scrubbing to make distclean. > > - Added a comment about Clang >=11 being required. > > - Added a patch to disable LTO for the arm64 KVM nVHE code. > > - Disabled objtool's noinstr validation with LTO unless enabled. > > - Included Peter's proposed objtool mcount patch in the series > and replaced recordmcount with the objtool pass to avoid > whitelisting relocations that are not calls. > > - Updated several commit messages with better explanations. > > > Sami Tolvanen (16): > tracing: move function tracer options to Kconfig > kbuild: add support for Clang LTO > kbuild: lto: fix module versioning > kbuild: lto: limit inlining > kbuild: lto: merge module sections > kbuild: lto: add a default list of used symbols > init: lto: ensure initcall ordering > init: lto: fix PREL32 relocations > PCI: Fix PREL32 relocations for LTO > 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: vdso: disable LTO > arm64: disable recordmcount with DYNAMIC_FTRACE_WITH_REGS > arm64: allow LTO to be selected > > .gitignore | 1 + > Makefile | 45 +++-- > arch/Kconfig | 90 +++++++++ > arch/arm64/Kconfig | 4 + > arch/arm64/kernel/vdso/Makefile | 3 +- > drivers/firmware/efi/libstub/Makefile | 2 + > drivers/misc/lkdtm/Makefile | 1 + > include/asm-generic/vmlinux.lds.h | 11 +- > include/linux/init.h | 79 +++++++- > include/linux/pci.h | 19 +- > init/Kconfig | 1 + > kernel/trace/Kconfig | 16 ++ > scripts/Makefile.build | 48 ++++- > scripts/Makefile.lib | 6 +- > scripts/Makefile.modfinal | 9 +- > scripts/Makefile.modpost | 25 ++- > scripts/generate_initcall_order.pl | 270 ++++++++++++++++++++++++++ > scripts/link-vmlinux.sh | 70 ++++++- > scripts/lto-used-symbollist | 5 + > scripts/mod/Makefile | 1 + > scripts/mod/modpost.c | 16 +- > scripts/mod/modpost.h | 9 + > scripts/mod/sumversion.c | 6 +- > scripts/module.lds.S | 24 +++ > 24 files changed, 696 insertions(+), 65 deletions(-) > create mode 100755 scripts/generate_initcall_order.pl > create mode 100644 scripts/lto-used-symbollist > > > base-commit: 33dc9614dc208291d0c4bcdeb5d30d481dcd2c4c > -- > 2.29.2.576.ga3fc446d84-goog > > -- > You received this message because you are subscribed to the Google Groups "Clang Built Linux" group. > To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-linux+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20201211184633.3213045-1-samitolvanen%40google.com. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel 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=-10.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 2F969C433E0 for ; Sat, 9 Jan 2021 14:54:55 +0000 (UTC) Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.kernel.org (Postfix) with SMTP id E638E23998 for ; Sat, 9 Jan 2021 14:54:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E638E23998 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernel-hardening-return-20614-kernel-hardening=archiver.kernel.org@lists.openwall.com Received: (qmail 25973 invoked by uid 550); 9 Jan 2021 14:54:44 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Received: (qmail 25950 invoked from network); 9 Jan 2021 14:54:43 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:reply-to:from:date:message-id :subject:to:cc; bh=D12F/5eqLacVjkZjRiSdLFKTLkLrM01QiwzEKmGG7kg=; b=Bri5dW58vELYIPUb9vXYPdr9tYMsJFTKOWbYmN8Q8fgxaoSY9H7X/XH7Z4sJKN9kMR k7ac3vFv8ulpO5PFYnISJNesBpgn28ZhfYRVxfUh3Hi9g7lG1Gn01swLHg0d0xVgcAea VfCWkNSyxD6G2PZ/scf46Mpal2+O1EwqCSbv2avxKXFzt6N/XZ+DMLwbbnNoFBiAuNiu QGtqrVsh13mg6BfHkYFl2rcvzkNNv9Ur2vOyimzCkgJ31QBj5Jzh2gK2N6h6tWWjTvJ2 uPaDSoR9XmtsYewaILrMpcd4ifEL0nsEnomPIzmY0lJbEyvK3QiCu95bLzoqdtBig4pl 3zPA== 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:reply-to :from:date:message-id:subject:to:cc; bh=D12F/5eqLacVjkZjRiSdLFKTLkLrM01QiwzEKmGG7kg=; b=U1jZMEGLojycwJEsVlkLL6McuK4/SQoa7ZBu41m97UjWASJD+3nSGZ84WceeVmisin qy+tSuTrxIbLtoSPU0Bam6qCqSjOfFq6P/x44Nv/CCyIBiwUFZEYHjhfpjblqmzSSloK sZiTgna3u0jSqRDxSUBsjL93yEQZBqzv58u+QYyk9w5xTTRqtoU8seYjhb24nIR9a5Km SMOxTvvidOT5Vt9CK7wluhYtAtFc9O/uysPWWWBX+mAGVKC0TiWv4TY+VHpx2pcgjtoG AfpCbBX5cBNJYJpEuOb2107G3f00sWwBfsgv7xwefyWLoMxSUHR1mPCDFBf65yW95buU mmGw== X-Gm-Message-State: AOAM5315X8P1aMpwIZhsUw7SH9mCL7rv9rT+iO4O2zrcHm98OlHt43pQ S7QqrffOGuUGPF58lSPj9O4qRyZpATuMOefAIKk= X-Google-Smtp-Source: ABdhPJwVv4PFOqPosBHukOFnJ4wi1WhA23C1yUe3nwW75P2WzZXNyJ9esu/ru+OPCXZnxNgLZ7Vuc1GfwVAqUirf4I0= X-Received: by 2002:a05:6e02:1a43:: with SMTP id u3mr8682427ilv.209.1610204071843; Sat, 09 Jan 2021 06:54:31 -0800 (PST) MIME-Version: 1.0 References: <20201211184633.3213045-1-samitolvanen@google.com> In-Reply-To: <20201211184633.3213045-1-samitolvanen@google.com> From: Sedat Dilek Date: Sat, 9 Jan 2021 15:54:20 +0100 Message-ID: Subject: Re: [PATCH v9 00/16] Add support for Clang LTO To: Sami Tolvanen Cc: Masahiro Yamada , Steven Rostedt , Will Deacon , Josh Poimboeuf , Peter Zijlstra , Greg Kroah-Hartman , "Paul E. McKenney" , Kees Cook , Nick Desaulniers , Clang-Built-Linux ML , 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 Content-Type: text/plain; charset="UTF-8" On Fri, Dec 11, 2020 at 7:46 PM 'Sami Tolvanen' via Clang Built Linux 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 arm64 support depends on Will's memory ordering patches > [1]. I will post x86_64 patches separately after we have fixed the > remaining objtool warnings [2][3]. > > [1] https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git/log/?h=for-next/lto > [2] https://lore.kernel.org/lkml/20201120040424.a3wctajzft4ufoiw@treble/ > [3] https://git.kernel.org/pub/scm/linux/kernel/git/jpoimboe/linux.git/log/?h=objtool-vmlinux > Hi Sami, Thanks for the update. I am interested in having Clang LTO (Clang-CFI) for x86-64 working and help with testing. I tried the Git tree mentioned in [3] (together with changes from ). I only see in my build-log... drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: eb_relocate_parse_slow()+0x3d0: stack state mismatch: cfa1=7+120 cfa2=-1+0 drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: eb_copy_relocations()+0x229: stack state mismatch: cfa1=7+120 cfa2=-1+0 ...which was reported and worked on in [1]. This is with Clang-IAS version 11.0.1. Unfortunately, the recent changes in do not cleanly apply with Josh stuff. My intention/wish was to report this combination of patchsets "heals" a lot of objtool-warnings for vmlinux.o I observed with Clang-CFI. Is it possible to have a Git branch where Josh's objtool-vmlinux is working together with Clang-LTO? For testing purposes. Thanks. Regards, - Sedat - [1] https://github.com/ClangBuiltLinux/linux/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc > You can also pull this series from > > https://github.com/samitolvanen/linux.git lto-v9 > > --- > Changes in v9: > > - Added HAS_LTO_CLANG dependencies to LLVM=1 and LLVM_IAS=1 to avoid > issues with mismatched toolchains. > > - Dropped the .mod patch as Masahiro landed a better solution to > the split line issue in commit 7d32358be8ac ("kbuild: avoid split > lines in .mod files"). > > - Updated CC_FLAGS_LTO to use -fvisibility=hidden to avoid weak symbol > visibility issues with ThinLTO on x86. > > - Changed LTO_CLANG_FULL to depend on !COMPILE_TEST to prevent > timeouts in automated testing. > > - Added a dependency to CPU_LITTLE_ENDIAN to ARCH_SUPPORTS_LTO_CLANG > in arch/arm64/Kconfig. > > - Added a default symbol list to fix an issue with TRIM_UNUSED_KSYMS. > > Changes in v8: > > - Cleaned up the LTO Kconfig options based on suggestions from > Nick and Kees. > > - Dropped the patch to disable LTO for the arm64 nVHE KVM code as > David pointed out it's not needed anymore. > > Changes in v7: > > - Rebased to master again. > > - Added back arm64 patches as the prerequisites are now staged, > and dropped x86_64 support until the remaining objtool issues > are resolved. > > - Dropped ifdefs from module.lds.S. > > Changes in v6: > > - Added the missing --mcount flag to patch 5. > > - Dropped the arm64 patches from this series and will repost them > later. > > Changes in v5: > > - Rebased on top of tip/master. > > - Changed the command line for objtool to use --vmlinux --duplicate > to disable warnings about retpoline thunks and to fix .orc_unwind > generation for vmlinux.o. > > - Added --noinstr flag to objtool, so we can use --vmlinux without > also enabling noinstr validation. > > - Disabled objtool's unreachable instruction warnings with LTO to > disable false positives for the int3 padding in vmlinux.o. > > - Added ANNOTATE_RETPOLINE_SAFE annotations to the indirect jumps > in x86 assembly code to fix objtool warnings with retpoline. > > - Fixed modpost warnings about missing version information with > CONFIG_MODVERSIONS. > > - Included Makefile.lib into Makefile.modpost for ld_flags. Thanks > to Sedat for pointing this out. > > - Updated the help text for ThinLTO to better explain the trade-offs. > > - Updated commit messages with better explanations. > > Changes in v4: > > - Fixed a typo in Makefile.lib to correctly pass --no-fp to objtool. > > - Moved ftrace configs related to generating __mcount_loc to Kconfig, > so they are available also in Makefile.modfinal. > > - Dropped two prerequisite patches that were merged to Linus' tree. > > Changes in v3: > > - Added a separate patch to remove the unused DISABLE_LTO treewide, > as filtering out CC_FLAGS_LTO instead is preferred. > > - Updated the Kconfig help to explain why LTO is behind a choice > and disabled by default. > > - Dropped CC_FLAGS_LTO_CLANG, compiler-specific LTO flags are now > appended directly to CC_FLAGS_LTO. > > - Updated $(AR) flags as KBUILD_ARFLAGS was removed earlier. > > - Fixed ThinLTO cache handling for external module builds. > > - Rebased on top of Masahiro's patch for preprocessing modules.lds, > and moved the contents of module-lto.lds to modules.lds.S. > > - Moved objtool_args to Makefile.lib to avoid duplication of the > command line parameters in Makefile.modfinal. > > - Clarified in the commit message for the initcall ordering patch > that the initcall order remains the same as without LTO. > > - Changed link-vmlinux.sh to use jobserver-exec to control the > number of jobs started by generate_initcall_ordering.pl. > > - Dropped the x86/relocs patch to whitelist L4_PAGE_OFFSET as it's > no longer needed with ToT kernel. > > - Disabled LTO for arch/x86/power/cpu.c to work around a Clang bug > with stack protector attributes. > > Changes in v2: > > - Fixed -Wmissing-prototypes warnings with W=1. > > - Dropped cc-option from -fsplit-lto-unit and added .thinlto-cache > scrubbing to make distclean. > > - Added a comment about Clang >=11 being required. > > - Added a patch to disable LTO for the arm64 KVM nVHE code. > > - Disabled objtool's noinstr validation with LTO unless enabled. > > - Included Peter's proposed objtool mcount patch in the series > and replaced recordmcount with the objtool pass to avoid > whitelisting relocations that are not calls. > > - Updated several commit messages with better explanations. > > > Sami Tolvanen (16): > tracing: move function tracer options to Kconfig > kbuild: add support for Clang LTO > kbuild: lto: fix module versioning > kbuild: lto: limit inlining > kbuild: lto: merge module sections > kbuild: lto: add a default list of used symbols > init: lto: ensure initcall ordering > init: lto: fix PREL32 relocations > PCI: Fix PREL32 relocations for LTO > 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: vdso: disable LTO > arm64: disable recordmcount with DYNAMIC_FTRACE_WITH_REGS > arm64: allow LTO to be selected > > .gitignore | 1 + > Makefile | 45 +++-- > arch/Kconfig | 90 +++++++++ > arch/arm64/Kconfig | 4 + > arch/arm64/kernel/vdso/Makefile | 3 +- > drivers/firmware/efi/libstub/Makefile | 2 + > drivers/misc/lkdtm/Makefile | 1 + > include/asm-generic/vmlinux.lds.h | 11 +- > include/linux/init.h | 79 +++++++- > include/linux/pci.h | 19 +- > init/Kconfig | 1 + > kernel/trace/Kconfig | 16 ++ > scripts/Makefile.build | 48 ++++- > scripts/Makefile.lib | 6 +- > scripts/Makefile.modfinal | 9 +- > scripts/Makefile.modpost | 25 ++- > scripts/generate_initcall_order.pl | 270 ++++++++++++++++++++++++++ > scripts/link-vmlinux.sh | 70 ++++++- > scripts/lto-used-symbollist | 5 + > scripts/mod/Makefile | 1 + > scripts/mod/modpost.c | 16 +- > scripts/mod/modpost.h | 9 + > scripts/mod/sumversion.c | 6 +- > scripts/module.lds.S | 24 +++ > 24 files changed, 696 insertions(+), 65 deletions(-) > create mode 100755 scripts/generate_initcall_order.pl > create mode 100644 scripts/lto-used-symbollist > > > base-commit: 33dc9614dc208291d0c4bcdeb5d30d481dcd2c4c > -- > 2.29.2.576.ga3fc446d84-goog > > -- > You received this message because you are subscribed to the Google Groups "Clang Built Linux" group. > To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-linux+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20201211184633.3213045-1-samitolvanen%40google.com.