public inbox for linux-kbuild@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Ungerer <gregungerer@westnet.com.au>
To: Masahiro Yamada <masahiroy@kernel.org>, linux-kbuild@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Nicolas Pitre <npitre@baylibre.com>,
	Nicolas Schier <nicolas@fjasle.eu>
Subject: Re: [PATCH v5 16/21] kbuild: generate KSYMTAB entries by modpost
Date: Fri, 27 Oct 2023 14:29:02 +1000	[thread overview]
Message-ID: <1fac9d12-2ec2-4ccb-bb81-34f3fc34789e@westnet.com.au> (raw)
In-Reply-To: <20230514152739.962109-17-masahiroy@kernel.org>

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 <linux/export.h> and <asm-generic/export.h>
> 
> 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.
> 
> <asm/export.h> and <asm-generic/export.h> will remain as a wrapper of
> <linux/export.h> for a while.
> 
> They will be removed after #include <asm/export.h> directives are all
> replaced with #include <linux/export.h>.
> 
> [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 <masahiroy@kernel.org>

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

  reply	other threads:[~2023-10-27  4:32 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-14 15:27 [PATCH v5 00/21] Unify <linux/export.h> and <asm/export.h>, remove EXPORT_DATA_SYMBOL(), faster TRIM_UNUSED_KSYMS Masahiro Yamada
2023-05-14 15:27 ` [PATCH v5 01/21] modpost: remove broken calculation of exception_table_entry size Masahiro Yamada
2023-05-14 15:27 ` [PATCH v5 02/21] modpost: remove fromsym info in __ex_table section mismatch warning Masahiro Yamada
2023-05-17 18:53   ` Nick Desaulniers
2023-05-20 13:11     ` Masahiro Yamada
2023-05-14 15:27 ` [PATCH v5 03/21] modpost: remove get_prettyname() Masahiro Yamada
2023-05-17 21:44   ` Nick Desaulniers
2023-05-20 13:32     ` Masahiro Yamada
2023-05-14 15:27 ` [PATCH v5 04/21] modpost: squash report_extable_warnings() into extable_mismatch_handler() Masahiro Yamada
2023-05-17 21:27   ` Nick Desaulniers
2023-05-14 15:27 ` [PATCH v5 05/21] modpost: squash report_sec_mismatch() into default_mismatch_handler() Masahiro Yamada
2023-05-17 21:53   ` Nick Desaulniers
2023-05-14 15:27 ` [PATCH v5 06/21] modpost: clean up is_executable_section() Masahiro Yamada
2023-05-17 21:10   ` Nick Desaulniers
2023-05-20 13:19     ` Masahiro Yamada
2023-05-14 15:27 ` [PATCH v5 07/21] modpost: squash extable_mismatch_handler() into default_mismatch_handler() Masahiro Yamada
2023-05-17 20:55   ` Nick Desaulniers
2023-05-14 15:27 ` [PATCH v5 08/21] modpost: pass 'tosec' down to default_mismatch_handler() Masahiro Yamada
2023-05-17 20:58   ` Nick Desaulniers
2023-05-14 15:27 ` [PATCH v5 09/21] modpost: pass section index to find_elf_symbol2() Masahiro Yamada
2023-05-17 21:05   ` Nick Desaulniers
2023-05-14 15:27 ` [PATCH v5 10/21] modpost: rename find_elf_symbol() and find_elf_symbol2() Masahiro Yamada
2023-05-17 21:14   ` Nick Desaulniers
2023-05-20 13:27     ` Masahiro Yamada
2023-05-22 16:59       ` Nick Desaulniers
2023-05-23 12:04         ` Masahiro Yamada
2023-05-14 15:27 ` [PATCH v5 11/21] modpost: modpost: refactor find_fromsym() and find_tosym() Masahiro Yamada
2023-05-14 15:27 ` [PATCH v5 12/21] modpost: unify 'sym' and 'to' in default_mismatch_handler() Masahiro Yamada
2023-05-14 15:27 ` [PATCH v5 13/21] modpost: replace r->r_offset, r->r_addend with faddr, taddr Masahiro Yamada
2023-05-14 15:27 ` [PATCH v5 14/21] modpost: remove is_shndx_special() check from section_rel(a) Masahiro Yamada
2023-05-17 21:23   ` Nick Desaulniers
2023-05-17 21:24     ` Nick Desaulniers
2023-05-20 13:45     ` Masahiro Yamada
2023-05-14 15:27 ` [PATCH v5 15/21] modpost: pass struct module pointer to check_section_mismatch() Masahiro Yamada
2023-05-14 15:27 ` [PATCH v5 16/21] kbuild: generate KSYMTAB entries by modpost Masahiro Yamada
2023-10-27  4:29   ` Greg Ungerer [this message]
2023-10-27  9:56     ` Masahiro Yamada
2023-05-14 15:27 ` [PATCH v5 17/21] ia64,export.h: replace EXPORT_DATA_SYMBOL* with EXPORT_SYMBOL* Masahiro Yamada
2023-05-14 15:27 ` [PATCH v5 18/21] modpost: check static EXPORT_SYMBOL* by modpost again Masahiro Yamada
2023-05-14 15:27 ` [PATCH v5 19/21] modpost: squash sym_update_namespace() into sym_add_exported() Masahiro Yamada
2023-05-14 15:27 ` [PATCH v5 20/21] modpost: use null string instead of NULL pointer for default namespace Masahiro Yamada
2023-05-14 15:27 ` [PATCH v5 21/21] kbuild: implement CONFIG_TRIM_UNUSED_KSYMS without recursion Masahiro Yamada
2023-05-15 21:31   ` Nicolas Pitre
2023-05-15 22:54     ` Sami Tolvanen
2023-05-16  2:16       ` Masahiro Yamada
2023-05-16 14:51         ` Sami Tolvanen
2023-05-16  1:41   ` Masahiro Yamada
2023-05-21 13:15 ` [PATCH v5 00/21] Unify <linux/export.h> and <asm/export.h>, remove EXPORT_DATA_SYMBOL(), faster TRIM_UNUSED_KSYMS Masahiro Yamada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1fac9d12-2ec2-4ccb-bb81-34f3fc34789e@westnet.com.au \
    --to=gregungerer@westnet.com.au \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=nicolas@fjasle.eu \
    --cc=npitre@baylibre.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox