Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp325766iog; Wed, 15 Jun 2022 03:04:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyr7nlLm9THY4fEcnIWRI/6Xb/pEbtqEeT5s+YmQ+t5Gem1hLt2NHUUoFISn1tQG4LjjpGP X-Received: by 2002:a63:2214:0:b0:408:7f25:dc35 with SMTP id i20-20020a632214000000b004087f25dc35mr8435128pgi.430.1655287497239; Wed, 15 Jun 2022 03:04:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655287497; cv=none; d=google.com; s=arc-20160816; b=veRrcmyjVCi9Dt4HK5PkNzRWTDYR/J4SjyDZQHYb1u4PJKALURf+ahLr5WWI8Po2Bk HAI/pQGrEBR3975lArR0Hu+FERscTMbWCceUgdzemsu3jhJvtKQuMOVFhSAwXSEoztnE CGtu6Yk5eZM2XtPSt6rkAnmHjqrZ4JVblf58vhRj/nKXDP7X/bzUfvE4JTqdZ7dHSfsJ VjfA/HXAVw64Rma9hnyjcTjxOwsmcuzPClkWdacTHwEXgDZIkYqct0kQe8LKkY9pxyFE ahwR+cNuLZMAnG1f06fTDagx5C0CGoaDyEeS+dsWDXdpXoUq0a6Ha4fiq08ew4JrGRqQ kenA== 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:dkim-filter; bh=z11ovVAKqI6ZA7KGXOW96R1KX78wxZ9sWHcYkCBNvWg=; b=g4CtvUj3JhU1frADdvdKEQyUbYwZ2In55SWbWeDclk8lBicOiSUH/CSuPOyDl37iDU UYkqJWEPI+Y+mOBpN202HF0Ge15CplkNEl0JqpZVXez5f0RDuXFlEQaN6+249wZOXuB3 +D8+ZydxR9qAJlnYPsDGkgLOI9PmpELDJvgSj60P1AZFhCE6iWCwVKDyD3EzdiCyoPuH 2Vb7W01YE1jm9AaBzh7CUqIQ01WmaqfQzZvKtzMThgY5huI3eV2Tdtavp0L8rT1xgfeF ywaZzbJELY+UqXaSoSG5dLZSMR00eS2B2tHomBUACoW0MeuoEJg3+bYRZOG6WUG04Ir3 knTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=ApQ8fSYt; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h14-20020a63c00e000000b003c6dde2ad19si16506995pgg.26.2022.06.15.03.04.45; Wed, 15 Jun 2022 03:04:57 -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=@nifty.com header.s=dec2015msa header.b=ApQ8fSYt; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239220AbiFOJYj (ORCPT + 99 others); Wed, 15 Jun 2022 05:24:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232109AbiFOJY0 (ORCPT ); Wed, 15 Jun 2022 05:24:26 -0400 Received: from conssluserg-05.nifty.com (conssluserg-05.nifty.com [210.131.2.90]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 153F315726 for ; Wed, 15 Jun 2022 02:24:24 -0700 (PDT) Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (authenticated) by conssluserg-05.nifty.com with ESMTP id 25F9O0B1025279 for ; Wed, 15 Jun 2022 18:24:01 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-05.nifty.com 25F9O0B1025279 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1655285041; bh=z11ovVAKqI6ZA7KGXOW96R1KX78wxZ9sWHcYkCBNvWg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ApQ8fSYtWZBsD7TbE6Ktx2ZrVkQyDEepc6TLORaln5uOlE9z6x8Pys64Uuqt/4Hx0 eSXlBMR7sJoLVjsw5oAUTjE0OJjJJJVx7TGeRyxRGG1ZJ7tw7He73J8M90jDcWtEU0 +ZwPmJ0QxCClZ3WdbGAShZREpuD0c0Pi6VOq31tg1KzcHONPaQfHbVL4MptqEL6yP/ GUyz8E4q9Fs2NeKEUQnXZtOOMK0M4teDpbbIhtKQvCYxyX08APMxj6IL1TXym6IUHd qh3Hd9c2BIobtwgt19gYjztzCXqJzN/rDEcfiIrCULo43gf5jQilvENycbiaMVefA7 97kGQg4RYUK4w== X-Nifty-SrcIP: [209.85.221.54] Received: by mail-wr1-f54.google.com with SMTP id o8so14520603wro.3 for ; Wed, 15 Jun 2022 02:24:01 -0700 (PDT) X-Gm-Message-State: AJIora/bucf5LQlD2DAt/X/BifGhfzPxaDy9MH3oiIYCCDQTY/qyvIcE eOeHyi1XQmzXUc9Y4U8NlXJkuISR9+5I2HtXYvI= X-Received: by 2002:a05:6000:156d:b0:210:3135:ce1c with SMTP id 13-20020a056000156d00b002103135ce1cmr9167065wrz.409.1655285039469; Wed, 15 Jun 2022 02:23:59 -0700 (PDT) MIME-Version: 1.0 References: <20220615063315.279489-1-jhubbard@nvidia.com> In-Reply-To: <20220615063315.279489-1-jhubbard@nvidia.com> From: Masahiro Yamada Date: Wed, 15 Jun 2022 18:23:22 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] gen_compile_commands: fix overlooked module files To: John Hubbard Cc: Nick Desaulniers , Nathan Chancellor , Tom Rix , Jason Gunthorpe , LKML , clang-built-linux Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_SOFTFAIL, T_SCC_BODY_TEXT_LINE autolearn=no 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 Wed, Jun 15, 2022 at 3:33 PM John Hubbard wrote: > > scripts/clang-tools/gen_compile_commands.py incorrectly assumes that > each .mod file only contains one line. Thanks for catching this. That assumption was correct until recently. The first line contained member objects. The second line, if CONFIG_TRIM_UNUSED_KSYMS=y, contained unresolved symbols Commit 9413e7640564 ("kbuild: split the second line of *.mod into *.usyms") changed the format of *.mod so member objects are listed per-line. > In fact, such files contain one > entry per line, and for some subsystems, there can be many, many lines. > For example, Nouveau has 762 entries, but only the first entry was being > processed. This problem causes clangd to fail to provide references and > definitions for valid files that are part of the current kernel > configuration. > > This problem only occurs when using Kbuild to generate, like this: > > make CC=clang compile_commands.json > > It does not occur if you just run gen_compile_commands.py "bare", like > this (below): > > scripts/clang-tools/gen_compile_commands.py/gen_compile_commands.py . > > Fix this by fully processing each .mod file. This fix causes the number > of build commands that clangd finds in my kernel build (these numbers > are heavily dependent upon .config), from 2848 to 5292, which is an 85% > increase. > > Fixes: ecca4fea1ede4 ("gen_compile_commands: support *.o, *.a, modules.order in positional argument") This should be Fixes: 9413e7640564 ("kbuild: split the second line of *.mod into *.usyms") Can you update the commit log? > Cc: Masahiro Yamada > Cc: Nick Desaulniers > Signed-off-by: John Hubbard > --- > scripts/clang-tools/gen_compile_commands.py | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/scripts/clang-tools/gen_compile_commands.py b/scripts/clang-tools/gen_compile_commands.py > index 1d1bde1fd45e..53590e886889 100755 > --- a/scripts/clang-tools/gen_compile_commands.py > +++ b/scripts/clang-tools/gen_compile_commands.py > @@ -157,10 +157,11 @@ def cmdfiles_for_modorder(modorder): > if ext != '.ko': > sys.exit('{}: module path must end with .ko'.format(ko)) > mod = base + '.mod' > - # The first line of *.mod lists the objects that compose the module. > + # Read from *.mod, to get a list of objects that compose the module. > with open(mod) as m: > - for obj in m.readline().split(): > - yield to_cmdfile(obj) > + for line in m.readlines(): for line in m: is simpler, (and maybe will work more efficiently). One more note, the 'line' iterator is shadowing (overwriting) the outer 'line' iterator, which has been used a few lines above. with open(modorder) as f: for line in f: Maybe, it is safer to use a different name for the inner iterator because shadowing does not work in Python. > + for obj in line.split(): This loop is unneeded because each line contains only one word. .rstpip() will do. To sum up, this part can be simpler, for example like this: # Read from *.mod, to get a list of objects that compose the module. with open(mod) as m: for line2 in m: yield to_cmdfile(line2.rstrip()) > + yield to_cmdfile(obj) > > > def process_line(root_directory, command_prefix, file_path): > -- > 2.36.1 > -- Best Regards Masahiro Yamada