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=-28.2 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_IN_DEF_DKIM_WL 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 3D990C432BE for ; Thu, 12 Aug 2021 20:34:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1EC136103E for ; Thu, 12 Aug 2021 20:34:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237341AbhHLUfN (ORCPT ); Thu, 12 Aug 2021 16:35:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230018AbhHLUfM (ORCPT ); Thu, 12 Aug 2021 16:35:12 -0400 Received: from mail-yb1-xb29.google.com (mail-yb1-xb29.google.com [IPv6:2607:f8b0:4864:20::b29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9629DC061756 for ; Thu, 12 Aug 2021 13:34:46 -0700 (PDT) Received: by mail-yb1-xb29.google.com with SMTP id z5so14381292ybj.2 for ; Thu, 12 Aug 2021 13:34:46 -0700 (PDT) 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=4PJufOzjLBDCxdq/byxiVCZ51RzAASfRORWxOimYCxM=; b=FhizRNLCd+RpqCzF7ofLVuYTSDV5HqtAsijvP5uBYKiQfQrC1MpI5rFPfWxlG1PPEd usL3o21HJUcysoaA/e54dPPnFam1mt/bXCXA/hHmj2cu7hruApd7pdF9lSudzFXee8hh clgFmKrihfVyFBa+x70y/9THhNesXqiaj02aNT7qauvtD+xMaNfizcEGUHbaB9hztQTp NeoQxcGTMMR3Va5RYXFZWHAQyBL1O0uL5KVSTvMDYRuoL8sgPYANAnCuI2h7+mRThJQt kksIAa2YDQm0ptup/oWRi2oeLCHR06qpE1BvhIIgf6k9RlxHNApWI82NdRiGgrmMSv6k ANaw== 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=4PJufOzjLBDCxdq/byxiVCZ51RzAASfRORWxOimYCxM=; b=D/uwfj3JHxZbapeswzUBfyIC/+x3XgTOCUEStWsRtAmsbo2Fi8DgdvDtw1DbrkFlpM pGyu7y+HjTOzRx1vYTHNtntb3vv2MMpWMveDaLT11AMPWBF7bFs79K8a0Aw8ASDV4Ylb TQdSxJGz7DFfK2oDhPj0X35GLJU3cCGcnge6C9ulEHp2voEdApyyCPNnHwcNSV+4jo8T KjIt0nP7mT7r90kwwuyCRTPV+yqrHpk0PfM7f1grTDvwkHwYmgMeHhSU0VEO9hHteMBt GNTM63URF5uYYyF4y/fv0xX/70m5quNpFWpgBLWyvX9J1CZjXvamGs3FafkljoZIx/5X u/+A== X-Gm-Message-State: AOAM532t5pXpnlzLGN39Z5wUr4ELLxKC5tXoMoa/Stc1xBR3seSQfFlN H4zCav74Nk89LG1qwzOhs8ulSgiLD0lNLyygFVVjQQ== X-Google-Smtp-Source: ABdhPJygpRbF8yewEdCLcSehxtUV+GfdmlXeak1qcq+DZ2i4bEBInT1AtkYF730K9VPxZwPeLuSAR2ivIpVrh+3QrN8= X-Received: by 2002:a25:24cd:: with SMTP id k196mr6831305ybk.459.1628800485582; Thu, 12 Aug 2021 13:34:45 -0700 (PDT) MIME-Version: 1.0 References: <20210811203035.2463343-1-samitolvanen@google.com> In-Reply-To: From: Sami Tolvanen Date: Thu, 12 Aug 2021 13:34:34 -0700 Message-ID: Subject: Re: [PATCH RESEND v2] kbuild: Fix TRIM_UNUSED_KSYMS with LTO_CLANG To: Masahiro Yamada Cc: Kees Cook , Michal Marek , Alexander Lobakin , Nathan Chancellor , Nick Desaulniers , Linux Kbuild mailing list , clang-built-linux , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 12, 2021 at 1:02 PM Masahiro Yamada wrote: > > On Thu, Aug 12, 2021 at 5:30 AM Sami Tolvanen wrote: > > > > With CONFIG_LTO_CLANG, we currently link modules into native > > code just before modpost, which means with TRIM_UNUSED_KSYMS > > enabled, we still look at the LLVM bitcode in the .o files when > > generating the list of used symbols. As the bitcode doesn't > > yet have calls to compiler intrinsics and llvm-nm doesn't see > > function references that only exist in function-level inline > > assembly, we currently need a whitelist for TRIM_UNUSED_KSYMS to > > work with LTO. > > > > This change moves module LTO linking to happen earlier, and > > thus avoids the issue with LLVM bitcode and TRIM_UNUSED_KSYMS > > entirely, allowing us to also drop the whitelist from > > gen_autoksyms.sh. > > > > Link: https://github.com/ClangBuiltLinux/linux/issues/1369 > > Signed-off-by: Sami Tolvanen > > Reviewed-by: Alexander Lobakin > > Tested-by: Alexander Lobakin > > --- > > Changes in v2: > > - Fixed a couple of typos. > > - Fixed objtool arguments for .lto.o to always include --module. > > > > --- > > scripts/Makefile.build | 24 +++++++++++++++++++++++- > > scripts/Makefile.lib | 7 +++++++ > > scripts/Makefile.modfinal | 21 ++------------------- > > scripts/Makefile.modpost | 22 +++------------------- > > scripts/gen_autoksyms.sh | 12 ------------ > > 5 files changed, 35 insertions(+), 51 deletions(-) > > > > diff --git a/scripts/Makefile.build b/scripts/Makefile.build > > index 02197cb8e3a7..778dabea3a89 100644 > > --- a/scripts/Makefile.build > > +++ b/scripts/Makefile.build > > @@ -271,12 +271,34 @@ $(obj)/%.o: $(src)/%.c $(recordmcount_source) $$(objtool_dep) FORCE > > $(call if_changed_rule,cc_o_c) > > $(call cmd,force_checksrc) > > > > +ifdef CONFIG_LTO_CLANG > > +# Module .o files may contain LLVM bitcode, compile them into native code > > +# before ELF processing > > +quiet_cmd_cc_lto_link_modules = LTO [M] $@ > > +cmd_cc_lto_link_modules = \ > > + $(LD) $(ld_flags) -r -o $@ \ > > + $(shell [ -s $(@:.lto.o=.o.symversions) ] && \ > > + echo -T $(@:.lto.o=.o.symversions)) \ > > + --whole-archive $^ > > + > > +ifdef CONFIG_STACK_VALIDATION > > +# objtool was skipped for LLVM bitcode, run it now that we have compiled > > +# modules into native code > > +cmd_cc_lto_link_modules += ; \ > > + $(objtree)/tools/objtool/objtool $(objtool_args) --module \ > > + $(@:.ko=$(mod-prelink-ext).o) > > +endif > > + > > +$(obj)/%.lto.o: $(obj)/%.o > > + $(call if_changed,cc_lto_link_modules) > > > > > Documentation/kbuild/makefiles.rst says: > > Note: It is a typical mistake to forget the FORCE prerequisite. > > > The current code in scripts/Makefile.modpost is also wrong, though. Thanks for taking a look, Masahiro. I'll fix that in v3. Sami