Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp905612rdh; Thu, 26 Oct 2023 21:31:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHW9Lu3tAjvkhu3dhj0XScfMX+1QI/0DE6w/14rpMl/SEP+uP8blRAEsV27dcJ+0+RN9FVD X-Received: by 2002:a67:f547:0:b0:457:bf94:f2cb with SMTP id z7-20020a67f547000000b00457bf94f2cbmr1682226vsn.28.1698381073546; Thu, 26 Oct 2023 21:31:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698381073; cv=none; d=google.com; s=arc-20160816; b=liLvdDIWMqtouFf5Thdq9cVGJ+2rNc9klb9VYGor66ailq1GS1p0cYWCAZSFf3Ph2c q1wnihnGj3SX1f/kM2rYyCIyrE846L8rmB1aedYPrwPHIUKm+RYKyT7+x+Ofb6tZM18r y2QG98sP1Q14u2PPjN+m9IsCHDxGNDCf5lXaaeaefkrDJwOj9CJH6UQD7fW5WbJRRJBF 2WJfgQjlQwEoPpnKqtTgI+BosiisHSKuTsix9OINAZGTx75Y2oE5d1KvPfWzuaFZj+Dd ep7X8beGmIV5qQNaYstQXMV1D3k9qRIB2gz1509HqpXyOGUPAhAag9QL+C24cM5pvhxv stWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :content-language:references:cc:to:subject:from:user-agent :mime-version:date:message-id; bh=yec+X2GpCKjgs87Fl3APjVGPoGleYt82yxZghtjd5xU=; fh=D3S9Mx4yzJenhXTpQv/UuXQ+Eh2z4Gi2gxD9QVjREpM=; b=F+wTi23/hx/umpXdf+lMOOWBUXlErhhT6/PRJGJJNLv1yvCly+NROAf7U16G/rWkn/ WAwlb9Y9W+VmU3QEQ5A6SziClQG6Et9iZ4u53nxdXm4DYJdizrZ4BYDeiryWTkpzYnWZ AnMq8W1tV/LhVr06KCpq3B5lLK9RUjw47wX84Cxs/lUbr+aTTnSlx5vedjAJp8yUc+AB xbkurgtqgkxFQYllWKS48H3d3tUkBzJk9whV9r9hyIeLtGXne3jcvnFqNn698gqjmwhP 3zdDAvKITbbKVvJPvwFoLg47yFX5OFbQ6VfcqHaqAxmgXBJDCgedpaPQvuyN47gFQ9qf 80VA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id h126-20020a255384000000b00da0fca23093si1343875ybb.204.2023.10.26.21.31.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 21:31:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 7CE8D8266402; Thu, 26 Oct 2023 21:30:10 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229784AbjJ0E3c (ORCPT + 99 others); Fri, 27 Oct 2023 00:29:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229600AbjJ0E3b (ORCPT ); Fri, 27 Oct 2023 00:29:31 -0400 Received: from icp-osb-irony-out4.external.iinet.net.au (icp-osb-irony-out4.external.iinet.net.au [203.59.1.220]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 059D61AD for ; Thu, 26 Oct 2023 21:29:19 -0700 (PDT) Received: from gateway.pc5.atmailcloud.com (HELO mqr.i-08c0d97331176e550) ([13.54.26.16]) by icp-osb-irony-out4.iinet.net.au with ESMTP; 27 Oct 2023 12:29:10 +0800 Received: from CMR-KAKADU04.i-0d656febc51e9ef2a by MQR.i-08c0d97331176e550 with esmtps (envelope-from ) id 1qwET7-0004bJ-2a; Fri, 27 Oct 2023 04:29:09 +0000 Received: from [203.87.15.156] (helo=[192.168.0.22]) by CMR-KAKADU04.i-0d656febc51e9ef2a with esmtpsa (envelope-from ) id 1qwET7-0001rV-1E; Fri, 27 Oct 2023 04:29:09 +0000 Message-ID: <1fac9d12-2ec2-4ccb-bb81-34f3fc34789e@westnet.com.au> Date: Fri, 27 Oct 2023 14:29:02 +1000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Greg Ungerer Subject: Re: [PATCH v5 16/21] kbuild: generate KSYMTAB entries by modpost To: Masahiro Yamada , linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Pitre , Nicolas Schier References: <20230514152739.962109-1-masahiroy@kernel.org> <20230514152739.962109-17-masahiroy@kernel.org> Content-Language: en-US In-Reply-To: <20230514152739.962109-17-masahiroy@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Atmail-Id: gregungerer@westnet.com.au X-atmailcloud-spam-action: no action X-atmailcloud-spam-report: Action: no action X-Cm-Envelope: MS4xfFXufhrbusa9MhPZespdi097ILTbhCSpqqe5PrGfjKRxDAoBGx2Ac1yKFXQMCFCkblxeKpMTZ49iLQgCCFrszvx3D/1h4thdV5c1noeqf7VpBXH+xn3W zPFbk8xXtfPvSgki37eaXj6jTKR33P6VY3sYikH9WrjfjsVqlwbgpXWr9n2J2HawyBgN7or7AJgcVw== X-Cm-Analysis: v=2.4 cv=Zs0raf3G c=1 sm=1 tr=0 ts=653b3c95 a=Qq7imNNZi2wOFNr6RxuhDA==:117 a=Qq7imNNZi2wOFNr6RxuhDA==:17 a=IkcTkHD0fZMA:10 a=bhdUkHdE2iEA:10 a=80-xaVIC0AIA:10 a=x7bEGLp0ZPQA:10 a=VwQbUJbxAAAA:8 a=RiFP0eX-WucStWrHcg4A:9 a=QEXdDO2ut3YA:10 a=t4F5_PRhjUa2PXbBaQQF:22 a=AjGcO6oz07-iQ99wixmX:22 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 26 Oct 2023 21:30:12 -0700 (PDT) Hi Masahiro, On 15/5/23 01:27, Masahiro Yamada wrote: > Commit 7b4537199a4a ("kbuild: link symbol CRCs at final link, removing > CONFIG_MODULE_REL_CRCS") made modpost output CRCs in the same way > whether the EXPORT_SYMBOL() is placed in *.c or *.S. > > This commit applies a similar approach to the entire data structure of > EXPORT_SYMBOL() for further cleanups. The EXPORT_SYMBOL() compilation > is split into two stages. > > When a source file is compiled, EXPORT_SYMBOL() is converted into a > dummy symbol in the .export_symbol section. > > For example, > > EXPORT_SYMBOL(foo); > EXPORT_SYMBOL_NS_GPL(bar, BAR_NAMESPACE); > > will be encoded into the following assembly code: > > .section ".export_symbol","a" > __export_symbol__foo: > .asciz "" > .balign 8 > .quad foo > .previous > > .section ".export_symbol","a" > __export_symbol_gpl_bar: > .asciz "BAR_NAMESPACE" > .balign 8 > .quad bar > .previous > > They are just markers to tell modpost the name, license, and namespace > of the symbols. They will be dropped from the final vmlinux and modules > because the *(.export_symbol) will go into /DISCARD/ in the linker script. > > Then, modpost extracts all the information about EXPORT_SYMBOL() from the > .export_symbol section, and generates C code: > > KSYMTAB_FUNC(foo, "", ""); > KSYMTAB_FUNC(bar, "_gpl", "BAR_NAMESPACE"); > > KSYMTAB_FUNC() (or KSYMTAB_DATA() if it is data) is expanded to struct > kernel_symbol that will be linked to the vmlinux or a module. > > With this change, EXPORT_SYMBOL() works in the same way for *.c and *.S > files, providing the following benefits. > > [1] Deprecate EXPORT_DATA_SYMBOL() > > In the old days, EXPORT_SYMBOL() was only available in C files. To export > a symbol in *.S, EXPORT_SYMBOL() was placed in a separate *.c file. > arch/arm/kernel/armksyms.c is one example written in the classic manner. > > Commit 22823ab419d8 ("EXPORT_SYMBOL() for asm") removed this limitation. > Since then, EXPORT_SYMBOL() can be placed close to the symbol definition > in *.S files. It was a nice improvement. > > However, as that commit mentioned, you need to use EXPORT_DATA_SYMBOL() > for data objects on some architectures. > > In the new approach, modpost checks symbol's type (STT_FUNC or not), > and outputs KSYMTAB_FUNC() or KSYMTAB_DATA() accordingly. > > There are only two users of EXPORT_DATA_SYMBOL: > > EXPORT_DATA_SYMBOL_GPL(empty_zero_page) (arch/ia64/kernel/head.S) > EXPORT_DATA_SYMBOL(ia64_ivt) (arch/ia64/kernel/ivt.S) > > They are transformed as follows and output into .vmlinux.export.c > > KSYMTAB_DATA(empty_zero_page, "_gpl", ""); > KSYMTAB_DATA(ia64_ivt, "", ""); > > The other EXPORT_SYMBOL users in ia64 assembly are output as > KSYMTAB_FUNC(). > > EXPORT_DATA_SYMBOL() is now deprecated. > > [2] merge and > > There are two similar header implementations: > > include/linux/export.h for .c files > include/asm-generic/export.h for .S files > > Ideally, the functionality should be consistent between them, but they > tend to diverge. > > Commit 8651ec01daed ("module: add support for symbol namespaces.") did > not support the namespace for *.S files. > > This commit shifts the essential implementation part to C, which supports > EXPORT_SYMBOL_NS() for *.S files. > > and will remain as a wrapper of > for a while. > > They will be removed after #include directives are all > replaced with #include . > > [3] Implement CONFIG_TRIM_UNUSED_KSYMS in one-pass algorithm (by a later commit) > > 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. > > We can do this better now; modpost can selectively emit KSYMTAB entries > that are really used by modules. > > Signed-off-by: Masahiro Yamada This breaks building kernels with an m68k-uclinux-gcc toolchain that have modules configured. Before this change they built and ran fine. They build and run fine if CONFIG_MODULES is not set. A few hundred errors like this spew out: scripts/mod/modpost -o Module.symvers -T modules.order vmlinux.o ERROR: modpost: vmlinux: .export_symbol section references '', but it does not seem to be an export symbol ERROR: modpost: vmlinux: .export_symbol section references '', but it does not seem to be an export symbol ERROR: modpost: vmlinux: .export_symbol section references '', but it does not seem to be an export symbol ... This is still broken all the way through to the current 6.6-rc7, though the error messages are slightly better: ERROR: modpost: vmlinux: local symbol 'system_state' was exported ERROR: modpost: vmlinux: local symbol 'static_key_initialized' was exported ERROR: modpost: vmlinux: local symbol 'reset_devices' was exported ... I tried a bunch of different binutils and gcc versions (binutils-2.251 through 2.40 and gcc versions 8.3.0 through 12.3.0). If I compile with an m68k-linux targeted toolchain then it works - no modpost processing problems. nm reports the same information for symbols in both cases, eg: $ m68k-uclinux-nm vmlinux.o | grep system_state 00000000 r __export_symbol_system_state 00000008 B system_state 0000000c d __UNIQUE_ID___addressable_system_state320 $ m68k-linux-nm vmlinux.o | grep system_state 00000000 r __export_symbol_system_state 00000008 B system_state 0000000c d __UNIQUE_ID___addressable_system_state320 Tracing in scripts/mod/modpost.c I see that for this symbol example ("system_state") that ELF_ST_BIND(sym->st_info) is 0x0 for the m68k-uclinux toolchain case, so STB_LOCAL, whereas for the m68k-linux case it is 0x1, so STB_GLOBAL. Any idea what is going on here? Regards Greg