Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2642655rwd; Mon, 15 May 2023 14:51:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4xRQFnGEFq5S34jRV5hshO/d3CMfrYzNaeD3bC2FT4e3OJF3ssUKLGZ+NXKDVRttQ/Pe2E X-Received: by 2002:aa7:88d5:0:b0:64a:6cad:d840 with SMTP id k21-20020aa788d5000000b0064a6cadd840mr17840940pff.25.1684187496492; Mon, 15 May 2023 14:51:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684187496; cv=none; d=google.com; s=arc-20160816; b=NOOvuM2xKFOny+g2d0bbk/fSLUD3iorD95jKGuBAhtWO9pi+i8UTjo3fWTYo1sJqyi b26gC4KW8oK1/8EW1CkxXcG0l07wUg3ZuryJGXObkpIFm9nAe+T2TtgP+NDSqy9gHJZm bY5zj6xCfH4FnFeq8rpXnS5ZuXhoDTkGLEn5HpFBNqLe4XR2Gn8bZAhPWn4Jjg3dglQx kikgain7jI+M2OLaxNvycVqck8+IbvkCqv+M7T6NYesaBwuFvN99X0DppKXGhDlfxL+3 PP9kHzqLgQqeDoA1gSUFgi4nPWjpwJ5ub16Yq/g03y+lwme1dLRS9bT+/BT+fR5NU6V7 GoHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature:dkim-signature; bh=X5x5w1P1qiLSxTzaWbGkBnHhtwpCZiBN2KoNqnbaV74=; b=TH6l9zBGsOkoDYslQSocdavtlZzdkfiSMHO1YEMbUJryWBscYoJXvWdZLKXzyuaKEe ATfEysddJawVBgJdnwSjnBjSZXth1WzK2HPqewfYYoZn83oRpE7V3RgG32OXZuxp/z3U lgwNQO651aH9CQ+9XisvegiZTXUquGar5LUOQ2sGxL1EujZvcq7K9oyS1CMFB/vNc+ZW ZYS2frbydGpYNXRhugIjyUzuKunIwNxRKqrjNjzvT6UVOGs9411b/+A2rzu8S7SaQZnS k9qny7owBRgMVmS/kFq69PCwm+9q6eyr5hjRN8fmOmsWfgttv8XlMH2rhgCigpVmBREm dzsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pobox.com header.s=sasl header.b=xB0dKRIu; dkim=pass header.i=@fluxnic.net header.s=2016-12.pbsmtp header.b=HNhBoFKw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h66-20020a625345000000b0063d28eb37a8si10265067pfb.402.2023.05.15.14.51.21; Mon, 15 May 2023 14:51:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@pobox.com header.s=sasl header.b=xB0dKRIu; dkim=pass header.i=@fluxnic.net header.s=2016-12.pbsmtp header.b=HNhBoFKw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245610AbjEOVjG (ORCPT + 99 others); Mon, 15 May 2023 17:39:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245626AbjEOVi6 (ORCPT ); Mon, 15 May 2023 17:38:58 -0400 X-Greylist: delayed 299 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 15 May 2023 14:38:53 PDT Received: from pb-smtp20.pobox.com (pb-smtp20.pobox.com [173.228.157.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75FDA8A60; Mon, 15 May 2023 14:38:52 -0700 (PDT) Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id A63C41F76A7; Mon, 15 May 2023 17:31:39 -0400 (EDT) (envelope-from nico@fluxnic.net) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=date:from :to:cc:subject:in-reply-to:message-id:references:mime-version :content-type; s=sasl; bh=rNaiPjcXWQ3qBoY52ldgGlp1N5IWMpnSfHA6os B0ZUU=; b=xB0dKRIuVQW58WQ/UKRSp9/y6obmt02YgdsOrB7D3Or8PXHeOeFI1h aL+1pFwGexxJdxk0TWfb9+JSjBYR8xv2OTtoUt1SdbvBqMy4VC04I64y7lmt0/JQ wGkEfJa4okAbwtEgKtj9ci3+f4jJgjCnNL2knvUvDwpqeQ0FMFKSk= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 9E8611F76A5; Mon, 15 May 2023 17:31:39 -0400 (EDT) (envelope-from nico@fluxnic.net) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=fluxnic.net; h=date:from:to:cc:subject:in-reply-to:message-id:references:mime-version:content-type; s=2016-12.pbsmtp; bh=rNaiPjcXWQ3qBoY52ldgGlp1N5IWMpnSfHA6osB0ZUU=; b=HNhBoFKwDAK5NaE1NdE4e3QPRXSdcWrZN/jRWQKdm2YbsHCpvfbMD32G/0sQbmgbOTUAZ7XxEaBgSUP+Sg2ps3KR/jP+tMfSq7DNskyC6ohlxCZBVFOaeQBpwQ82m20jVIBu1g5j0rfJF1F15P1dhnpgEEBbhLf0surgyO+rxws= Received: from yoda.home (unknown [184.162.17.228]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id 4AB671F76A3; Mon, 15 May 2023 17:31:36 -0400 (EDT) (envelope-from nico@fluxnic.net) Received: from xanadu.home (xanadu [10.0.0.101]) by yoda.home (Postfix) with ESMTPSA id 3465976E96C; Mon, 15 May 2023 17:31:34 -0400 (EDT) Date: Mon, 15 May 2023 17:31:33 -0400 (EDT) From: Nicolas Pitre To: Masahiro Yamada cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier Subject: Re: [PATCH v5 21/21] kbuild: implement CONFIG_TRIM_UNUSED_KSYMS without recursion In-Reply-To: <20230514152739.962109-22-masahiroy@kernel.org> Message-ID: <93s3n008-7oon-30rq-5219-5r244919r38q@syhkavp.arg> References: <20230514152739.962109-1-masahiroy@kernel.org> <20230514152739.962109-22-masahiroy@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Pobox-Relay-ID: DEC884C0-F367-11ED-A8C9-C2DA088D43B2-78420484!pb-smtp20.pobox.com X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 15 May 2023, Masahiro Yamada wrote: > When CONFIG_TRIM_UNUSED_KSYMS is enabled, Kbuild recursively traverses > the directory tree to determine which EXPORT_SYMBOL to trim. If an > EXPORT_SYMBOL turns out to be unused by anyone, Kbuild begins the > second traverse, where some source files are recompiled with their > EXPORT_SYMBOL() tuned into a no-op. > > Linus stated negative opinions about this slowness in commits: > > - 5cf0fd591f2e ("Kbuild: disable TRIM_UNUSED_KSYMS option") > - a555bdd0c58c ("Kbuild: enable TRIM_UNUSED_KSYMS again, with some guarding") > > We can do this better now. The final data structures of EXPORT_SYMBOL > are generated by the modpost stage, so modpost can selectively emit > KSYMTAB entries that are really used by modules. > > Commit 2cce989f8461 ("kbuild: unify two modpost invocations") is another > ground-work to do this in a one-pass algorithm. With the list of modules, > modpost sets sym->used if it is used by a module. modpost emits KSYMTAB > only for symbols with sym->used==true. > > BTW, Nicolas explained why the trimming was implemented with recursion: > > https://lore.kernel.org/all/2o2rpn97-79nq-p7s2-nq5-8p83391473r@syhkavp.arg/ > > Actually, we never achieved that level of optimization where the chain > reaction of trimming comes into play because: > > - CONFIG_LTO_CLANG cannot remove any unused symbols > - CONFIG_LD_DEAD_CODE_DATA_ELIMINATION is enabled only for vmlinux, > but not modules I did achieve it using LTO with gcc back then. See the section called "The tree that hides the forest" of https://lwn.net/Articles/746780/ for example results. > If deeper trimming is required, we need to revisit this, but I guess > that is unlikely to happen. Would have been nicer to keep this possibility as an option. The code is already there and working as intended. The build cost is intrinsic to the approach of course. The actual bug is to impose that cost onto people who didn't explicitly ask for it. But I'm no longer fighting this battle. Nicolas