Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp587110iob; Fri, 13 May 2022 08:12:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzmfaDLo4HKWz0u5zED+1dqN51DZ0w9pPs4/+TDE1jVea5YBUJm70YGtOP4ZDXIOTdsOac X-Received: by 2002:a5d:64a5:0:b0:20c:599d:6b29 with SMTP id m5-20020a5d64a5000000b0020c599d6b29mr4603779wrp.642.1652454771174; Fri, 13 May 2022 08:12:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652454771; cv=none; d=google.com; s=arc-20160816; b=BReL8sSwqPrHKMh63oOo8ob2lMr48AkWU7QUG/RFqWZoHQmXyHZiRz928pmOpb+19J zi/L3Nnpv+rG0un7TC6c946HRU2hTnLjNSJ6y3FSn90jBNSqYB93ZYdzSqcIAg3UeUBs C0VHxYzxP5YoF11sEcNSkqBVCJclxP+10Naa8GgMs4WtRDYVrRYgG6QbGHYePubgMZZ0 +/nt1LHUXxULCrEK4c0m3Ya91p5H2Y6+6ZC7MhUXCJyFN4Z53lW3fq+opMRzDTgNYgkn T8EvPxX+QnU1gRlnP5z7Fj6iLOaayFLGv5HdALCJl8gD1VU7ZDaGNjkrADjWdF+DC4kg eMqA== 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=mO/DMNrIOb9APlTM3yT+RrP66+SqAVMQ3Ym8daEBsB8=; b=CyudvF394dq3tp9WapoYkKa2eugQ0h/x5qMTmEy96SyOeVnwB3jE4e3OY4/EfVybhI yaZw9iwZiQGrp/kIMycg7U60zFWk2wQiSOee7dG8xSiL3koBOnUCOhwj25Co7miifkat HxY28dU2dr4mWGfMe86atdV70yiMNFhxfP5zXpHE5GZOufV3eUDgMJbGgz4jPc7s05vO 2fcSF0MXPLc/G0Ggwn01Zl9LWHC9nCEA6zEv6F/jJELMoFjAhpptyAUzG0CJS48qtBbs ho9+LGNU4FD65wMxPdrAcTWBtkZKhP63FzzilI8Xf9d71dNplRIXWegfZ4odRmikVPzN AVkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=Au1gJMIj; 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 c7-20020a056000184700b0020ad9b931bfsi3198861wri.1053.2022.05.13.08.12.15; Fri, 13 May 2022 08:12:51 -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=Au1gJMIj; 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 S1356457AbiELQ35 (ORCPT + 99 others); Thu, 12 May 2022 12:29:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343801AbiELQ3z (ORCPT ); Thu, 12 May 2022 12:29:55 -0400 Received: from conssluserg-05.nifty.com (conssluserg-05.nifty.com [210.131.2.90]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBF861B57B4; Thu, 12 May 2022 09:29:53 -0700 (PDT) Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (authenticated) by conssluserg-05.nifty.com with ESMTP id 24CGTdRr000432; Fri, 13 May 2022 01:29:40 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-05.nifty.com 24CGTdRr000432 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1652372980; bh=mO/DMNrIOb9APlTM3yT+RrP66+SqAVMQ3Ym8daEBsB8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Au1gJMIjZjri4c45hmo3gtGE7edeeRZZiAj50KRCy93yqQEX3OiJc27G2vejdK/Rr SUkCPjY/bM5k2he0yiFxrOT/fF6M2XBnQxRW6uC+SQbH9PJl3bz/FIjj912CdGJE0W 9TT1bAnCZzhs0dnpCqrIHoQ67+DHvE9o4MnJ+9esQrGuIetwcYueGNOFpYFk5jjQfQ PIHLlQzb7nNNbOh2CYRdUfX8b84e1HBeXve+49vBPxn4i2QGlHQcGAbrKoTTSJ+kYR 7rV5SYftOIjaIbLqLugI5kDM9OSwKLxE7tIlPzuK6nRSqVRYzN6NBGVMeCw06vcpxt B9Okg8BC7RxcQ== X-Nifty-SrcIP: [209.85.214.181] Received: by mail-pl1-f181.google.com with SMTP id q4so5379133plr.11; Thu, 12 May 2022 09:29:40 -0700 (PDT) X-Gm-Message-State: AOAM531Ckf51Ih4XDxmd/r5rREO4UKnvxWdJHkZ56WUaAVsfwG4KWRFl 85esODfWFn0dwuDbofs2hFNiW0EBkmuXRxjEDvo= X-Received: by 2002:a17:90b:1bca:b0:1dd:1f36:dc2a with SMTP id oa10-20020a17090b1bca00b001dd1f36dc2amr11680027pjb.119.1652372979433; Thu, 12 May 2022 09:29:39 -0700 (PDT) MIME-Version: 1.0 References: <20220511164514.2741934-1-masahiroy@kernel.org> <20220511164514.2741934-4-masahiroy@kernel.org> In-Reply-To: <20220511164514.2741934-4-masahiroy@kernel.org> From: Masahiro Yamada Date: Fri, 13 May 2022 01:28:26 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5 03/12] modpost: extract symbol versions from *.cmd files To: Linux Kbuild mailing list Cc: Linux Kernel Mailing List , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Peter Zijlstra , linux-modules , clang-built-linux , Ard Biesheuvel , Sami Tolvanen 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 Thu, May 12, 2022 at 1:49 AM Masahiro Yamada wrote: > > Currently, CONFIG_MODVERSIONS needs extra link to embed the symbol > versions into ELF objects. Then, modpost extracts the version CRCs > from them. > > The following figures show how it currently works, and how I am trying > to change it. > > Current implementation > ====================== > |----------| > embed CRC -------------------------->| final | > $(CC) $(LD) / |---------| | link for | > -----> *.o -------> *.o -->| modpost | | vmlinux | > / / | |-- *.mod.c -->| or | > / genksyms / |---------| | module | > *.c ------> *.symversions |----------| > > Genksyms outputs the calculated CRCs in the form of linker script > (*.symversions), which is used by $(LD) to update the object. > > If CONFIG_LTO_CLANG=y, the build process is much more complex. Embedding > the CRCs is postponed until the LLVM bitcode is converted into ELF, > creating another intermediate *.prelink.o. > > However, this complexity is unneeded. There is no reason why we must > embed version CRCs in objects so early. > > There is final link stage for vmlinux (scripts/link-vmlinux.sh) and > modules (scripts/Makefile.modfinal). We can link CRCs at the very last > moment. > > New implementation > ================== > |----------| > --------------------------------------->| final | > $(CC) / |---------| | link for | > -----> *.o ---->| | | vmlinux | > / | modpost |--- .vmlinux.export.c -->| or | > / genksyms | |--- *.mod.c ------------>| module | > *.c ------> *.cmd -->|---------| |----------| > > Pass the symbol versions to modpost as separate text data, which are > available in *.cmd files. > > This commit changes modpost to extract CRCs from *.cmd files instead of > from ELF objects. > > Signed-off-by: Masahiro Yamada > Reviewed-by: Nicolas Schier > Tested-by: Nathan Chancellor > Reviewed-by: Sami Tolvanen > --- > > (no changes since v2) > > Changes in v2: > - Simplify the implementation (parse .cmd files after ELF) > > scripts/mod/modpost.c | 177 ++++++++++++++++++++++++++++++------------ > 1 file changed, 129 insertions(+), 48 deletions(-) > +/* > + * The CRCs are recorded in .*.cmd files in the form of: > + * #SYMVER > + */ > +static void extract_crcs_for_object(const char *object, struct module *mod) > +{ > + char cmd_file[PATH_MAX]; > + char *buf, *p; > + const char *base; > + int dirlen, ret; > + > + base = strrchr(object, '/'); > + if (base) { > + base++; > + dirlen = base - object; > + } else { > + dirlen = 0; > + base = object; > + } > + > + ret = snprintf(cmd_file, sizeof(cmd_file), "%.*s.%s.cmd", > + dirlen, object, base); > + if (ret >= sizeof(cmd_file)) { > + error("%s: too long path was truncated\n", cmd_file); > + return; > + } > + > + buf = read_text_file(cmd_file); > + p = buf; > + > + while ((p = strstr(p, "\n#SYMVER "))) { > + char *name; > + size_t namelen; > + unsigned int crc; > + struct symbol *sym; > + > + name = p + strlen("\n#SYMVER "); > + > + p = strchr(name, ' '); > + if (!p) > + break; > + > + namelen = p - name; > + p++; > + > + if (!isdigit(*p)) > + continue; /* skip this line */ > + > + crc = strtol(p, &p, 0); > + if (*p != '\n') > + continue; /* skip this line */ > + > + name[namelen] = '\0'; > + > + sym = sym_find_with_module(name, mod); > + if (!sym) { > + warn("Skip the version for unexported symbol \"%s\" [%s%s]\n", > + name, mod->name, mod->is_vmlinux ? "" : ".ko"); > + continue; > + } A lot of warnings are displayed when CONFIG_TRIM_UNUSED_KSYMS=y. I will fix this in v6. -- Best Regards Masahiro Yamada