#
4079fe8e |
| 16-Aug-2024 |
Masahiro Yamada <masahiroy@kernel.org> |
modpost: simplify modpost_log()
With commit cda5f94e88b4 ("modpost: avoid using the alias attribute"), only two log levels remain: LOG_WARN and LOG_ERROR. Simplify this by making it a boolean variab
modpost: simplify modpost_log()
With commit cda5f94e88b4 ("modpost: avoid using the alias attribute"), only two log levels remain: LOG_WARN and LOG_ERROR. Simplify this by making it a boolean variable.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nathan Chancellor <nathan@kernel.org>
show more ...
|
#
4c2598e3 |
| 12-Aug-2024 |
Masahiro Yamada <masahiroy@kernel.org> |
modpost: replace the use of NOFAIL() with xmalloc() etc.
I think x*alloc() functions are cleaner.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
|
#
a660deb0 |
| 27-Jul-2024 |
Masahiro Yamada <masahiroy@kernel.org> |
modpost: detect endianness on run-time
Endianness is currently detected on compile-time, but we can defer this until run-time. This change avoids re-executing scripts/mod/mk_elfconfig even if modpos
modpost: detect endianness on run-time
Endianness is currently detected on compile-time, but we can defer this until run-time. This change avoids re-executing scripts/mod/mk_elfconfig even if modpost in the linux-headers package needs to be rebuilt for a foreign architecture.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
show more ...
|
#
fbaf242c |
| 20-Jul-2024 |
Masahiro Yamada <masahiroy@kernel.org> |
kbuild: move some helper headers from scripts/kconfig/ to scripts/include/
Move array_size.h, hashtable.h, list.h, list_types.h from scripts/kconfig/ to scripts/include/.
These headers will be usef
kbuild: move some helper headers from scripts/kconfig/ to scripts/include/
Move array_size.h, hashtable.h, list.h, list_types.h from scripts/kconfig/ to scripts/include/.
These headers will be useful for other host programs.
Remove scripts/mod/list.h.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
show more ...
|
#
cda5f94e |
| 27-Jan-2024 |
Masahiro Yamada <masahiroy@kernel.org> |
modpost: avoid using the alias attribute
Aiden Leong reported modpost fails to build on macOS since commit 16a473f60edc ("modpost: inform compilers that fatal() never returns"):
scripts/mod/modpo
modpost: avoid using the alias attribute
Aiden Leong reported modpost fails to build on macOS since commit 16a473f60edc ("modpost: inform compilers that fatal() never returns"):
scripts/mod/modpost.c:93:21: error: aliases are not supported on darwin
Nathan's research indicates that Darwin seems to support weak aliases at least [1]. Although the situation might be improved in future Clang versions, we can achieve a similar outcome without relying on it.
This commit makes fatal() a macro of error() + exit(1) in modpost.h, as compilers recognize that exit() never returns.
[1]: https://github.com/llvm/llvm-project/issues/71001
Fixes: 16a473f60edc ("modpost: inform compilers that fatal() never returns") Reported-by: Aiden Leong <aiden.leong@aibsd.com> Closes: https://lore.kernel.org/all/d9ac2960-6644-4a87-b5e4-4bfb6e0364a8@aibsd.com/ Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
show more ...
|
#
16a473f6 |
| 03-Dec-2023 |
Masahiro Yamada <masahiroy@kernel.org> |
modpost: inform compilers that fatal() never returns
The function fatal() never returns because modpost_log() calls exit(1) when LOG_FATAL is passed.
Inform compilers of this fact so that unreachab
modpost: inform compilers that fatal() never returns
The function fatal() never returns because modpost_log() calls exit(1) when LOG_FATAL is passed.
Inform compilers of this fact so that unreachable code flow can be identified at compile time.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nathan Chancellor <nathan@kernel.org>
show more ...
|
#
cc87b7c0 |
| 03-Dec-2023 |
Masahiro Yamada <masahiroy@kernel.org> |
modpost: move __attribute__((format(printf, 2, 3))) to modpost.h
This attribute must be added to the function declaration in a header for comprehensive checking of all the callsites.
Fixes: 6d9a89e
modpost: move __attribute__((format(printf, 2, 3))) to modpost.h
This attribute must be added to the function declaration in a header for comprehensive checking of all the callsites.
Fixes: 6d9a89ea4b06 ("kbuild: declare the modpost error functions as printf like") Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nathan Chancellor <nathan@kernel.org>
show more ...
|
#
bd78c9d7 |
| 07-Oct-2023 |
Masahiro Yamada <masahiroy@kernel.org> |
modpost: define TO_NATIVE() using bswap_* functions
The current TO_NATIVE() has some limitations:
1) You cannot cast the argument.
2) You cannot pass a variable marked as 'const'.
3) Passing a
modpost: define TO_NATIVE() using bswap_* functions
The current TO_NATIVE() has some limitations:
1) You cannot cast the argument.
2) You cannot pass a variable marked as 'const'.
3) Passing an array is a bug, but it is not detected.
Impelement TO_NATIVE() using bswap_*() functions. These are GNU extensions. If we face portability issues, we can port the code from include/uapi/linux/swab.h.
With this change, get_rel_type_and_sym() can be simplified by casting the arguments directly.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
show more ...
|
#
40745327 |
| 26-Sep-2023 |
Jack Brennen <jbrennen@google.com> |
modpost: Optimize symbol search from linear to binary search
Modify modpost to use binary search for converting addresses back into symbol references. Previously it used linear search.
This change
modpost: Optimize symbol search from linear to binary search
Modify modpost to use binary search for converting addresses back into symbol references. Previously it used linear search.
This change saves a few seconds of wall time for defconfig builds, but can save several minutes on allyesconfigs.
Before: $ make LLVM=1 -j128 allyesconfig vmlinux -s KCFLAGS="-Wno-error" $ time scripts/mod/modpost -M -m -a -N -o vmlinux.symvers vmlinux.o 198.38user 1.27system 3:19.71elapsed
After: $ make LLVM=1 -j128 allyesconfig vmlinux -s KCFLAGS="-Wno-error" $ time scripts/mod/modpost -M -m -a -N -o vmlinux.symvers vmlinux.o 11.91user 0.85system 0:12.78elapsed
Signed-off-by: Jack Brennen <jbrennen@google.com> Tested-by: Nick Desaulniers <ndesaulniers@google.com> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
show more ...
|
#
4732acb7 |
| 23-Jul-2023 |
Masahiro Yamada <masahiroy@kernel.org> |
modpost: clean up MIPS64 little endian relocation code
MIPS64 little endian target has an odd encoding of r_info.
This commit makes the special handling less ugly. It is still ugly, but #if conditi
modpost: clean up MIPS64 little endian relocation code
MIPS64 little endian target has an odd encoding of r_info.
This commit makes the special handling less ugly. It is still ugly, but #if conditionals will go away, at least.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
show more ...
|
#
ddb5cdba |
| 11-Jun-2023 |
Masahiro Yamada <masahiroy@kernel.org> |
kbuild: generate KSYMTAB entries by modpost
Commit 7b4537199a4a ("kbuild: link symbol CRCs at final link, removing CONFIG_MODULE_REL_CRCS") made modpost output CRCs in the same way whether the EXPOR
kbuild: generate KSYMTAB entries by modpost
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.
For further cleanups, this commit applies a similar approach to the entire data structure of EXPORT_SYMBOL().
The EXPORT_SYMBOL() compilation is split into two stages.
When a source file is compiled, EXPORT_SYMBOL() will be 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 "" /* license */ .asciz "" /* name space */ .balign 8 .quad foo /* symbol reference */ .previous
.section ".export_symbol","a" __export_symbol_bar: .asciz "GPL" /* license */ .asciz "BAR_NAMESPACE" /* name space */ .balign 8 .quad bar /* symbol reference */ .previous
They are mere 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 the final 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> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
show more ...
|
#
a9bb3e5d |
| 21-May-2023 |
Masahiro Yamada <masahiroy@kernel.org> |
modpost: remove is_shndx_special() check from section_rel(a)
This check is unneeded. Without it, sec_name() will returns the null string "", then section_mismatch() will return immediately.
Anyway,
modpost: remove is_shndx_special() check from section_rel(a)
This check is unneeded. Without it, sec_name() will returns the null string "", then section_mismatch() will return immediately.
Anyway, special section indices rarely appear in these loops.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
show more ...
|
#
36b0f0de |
| 03-Aug-2022 |
Masahiro Yamada <masahiroy@kernel.org> |
modpost: refactor get_secindex()
SPECIAL() is only used in get_secindex(). Squash it.
Make the code more readable with more comments.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
|
#
7193cda9 |
| 26-Jul-2022 |
Masahiro Yamada <masahiroy@kernel.org> |
modpost: remove unused Elf_Sword macro
Commit 9ad21c3f3ecf ("kbuild: try harder to find symbol names in modpost") added Elf_Sword (in a wrong way), but did not use it at all.
BTW, the current code
modpost: remove unused Elf_Sword macro
Commit 9ad21c3f3ecf ("kbuild: try harder to find symbol names in modpost") added Elf_Sword (in a wrong way), but did not use it at all.
BTW, the current code looks weird.
The fix for the 32-bit part would be:
Elf64_Sword --> Elf32_Sword
(inconsistet prefix, Elf32_ vs Elf64_)
The fix for the 64-bit part would be:
Elf64_Sxword --> Elf64_Sword
(the size is different between Sword and Sxword)
Note:
Elf32_Sword == Elf64_Sword == int32_t Elf32_Sxword == Elf64_Sxword == int64_t
Anyway, let's drop unused code instead of fixing it.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
show more ...
|
#
abe864b8 |
| 19-Jul-2022 |
Masahiro Yamada <masahiroy@kernel.org> |
modpost: use sym_get_data() to get module device_table data
Use sym_get_data() to replace the long code.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nick Desaulniers <ndesaul
modpost: use sym_get_data() to get module device_table data
Use sym_get_data() to replace the long code.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
show more ...
|
#
c5c468dc |
| 23-May-2022 |
Masahiro Yamada <masahiroy@kernel.org> |
modpost: reuse ARRAY_SIZE() macro for section_mismatch()
Move ARRAY_SIZE() from file2alias.c to modpost.h to reuse it in section_mismatch().
Also, move the variable 'check' inside the for-loop.
Si
modpost: reuse ARRAY_SIZE() macro for section_mismatch()
Move ARRAY_SIZE() from file2alias.c to modpost.h to reuse it in section_mismatch().
Also, move the variable 'check' inside the for-loop.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
show more ...
|
#
ce79c406 |
| 08-May-2022 |
Masahiro Yamada <masahiroy@kernel.org> |
modpost: remove left-over cross_compile declaration
This is a remnant of commit 6543becf26ff ("mod/file2alias: make modalias generation safe for cross compiling").
Signed-off-by: Masahiro Yamada <m
modpost: remove left-over cross_compile declaration
This is a remnant of commit 6543becf26ff ("mod/file2alias: make modalias generation safe for cross compiling").
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
show more ...
|
#
f841536e |
| 01-May-2022 |
Masahiro Yamada <masahiroy@kernel.org> |
modpost: dump Module.symvers in the same order of modules.order
modpost dumps the exported symbols into Module.symvers, but currently in random order because it iterates in the hash table.
Add a li
modpost: dump Module.symvers in the same order of modules.order
modpost dumps the exported symbols into Module.symvers, but currently in random order because it iterates in the hash table.
Add a linked list of exported symbols in struct module, so we can iterate on symbols per module.
This commit makes Module.symvers much more readable; the outer loop in write_dump() iterates over the modules in the order of modules.order, and the inner loop dumps symbols in each module.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
show more ...
|
#
ab489d60 |
| 01-May-2022 |
Masahiro Yamada <masahiroy@kernel.org> |
modpost: traverse the namespace_list in order
Use the doubly linked list to traverse the list in the added order. This makes the code more consistent.
Signed-off-by: Masahiro Yamada <masahiroy@kern
modpost: traverse the namespace_list in order
Use the doubly linked list to traverse the list in the added order. This makes the code more consistent.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
show more ...
|
#
8a69152b |
| 01-May-2022 |
Masahiro Yamada <masahiroy@kernel.org> |
modpost: traverse unresolved symbols in order
Currently, modpost manages unresolved in a singly linked list; it adds a new node to the head, and traverses the list from new to old.
Use a doubly lin
modpost: traverse unresolved symbols in order
Currently, modpost manages unresolved in a singly linked list; it adds a new node to the head, and traverses the list from new to old.
Use a doubly linked list to keep the order in the symbol table in the ELF file.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
show more ...
|
#
325eba05 |
| 01-May-2022 |
Masahiro Yamada <masahiroy@kernel.org> |
modpost: traverse modules in order
Currently, modpost manages modules in a singly linked list; it adds a new node to the head, and traverses the list from new to old.
It works, but the error messag
modpost: traverse modules in order
Currently, modpost manages modules in a singly linked list; it adds a new node to the head, and traverses the list from new to old.
It works, but the error messages are shown in the reverse order.
If you have a Makefile like this:
obj-m += foo.o bar.o
then, modpost shows error messages in bar.o, foo.o, in this order.
Use a doubly linked list to keep the order in modules.order; use list_add_tail() for the node addition and list_for_each_entry() for the list traverse.
Now that the kernel's list macros have been imported to modpost, I will use them actively going forward.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
show more ...
|
#
5066743e |
| 01-May-2022 |
Masahiro Yamada <masahiroy@kernel.org> |
modpost: change mod->gpl_compatible to bool type
Currently, mod->gpl_compatible is tristate; it is set to -1 by default, then to 1 or 0 when MODULE_LICENSE() is found.
Maybe, -1 was chosen to repre
modpost: change mod->gpl_compatible to bool type
Currently, mod->gpl_compatible is tristate; it is set to -1 by default, then to 1 or 0 when MODULE_LICENSE() is found.
Maybe, -1 was chosen to represent the 'unknown' license, but it is not useful.
The current code:
if (!mod->gpl_compatible) check_for_gpl_usage(exp->export, basename, exp->name);
... only cares whether gpl_compatible is zero or not.
Change it to a bool type with the initial value 'true', which has no functional change.
The default value should be 'true' instead of 'false'.
Since commit 1d6cd3929360 ("modpost: turn missing MODULE_LICENSE() into error"), unknown module license is an error.
The error message, "missing MODULE_LICENSE()" is enough to explain the issue. It is not sensible to show another message, "GPL-incompatible module ... uses GPL-only symbol".
Add comments to explain this.
While I was here, I renamed gpl_compatible to is_gpl_compatible for clarification, and also slightly refactored the code.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
show more ...
|
#
58e01fca |
| 01-May-2022 |
Masahiro Yamada <masahiroy@kernel.org> |
modpost: use bool type where appropriate
Use 'bool' to clarify that the valid value is true or false.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nick Desaulniers <ndesaulnie
modpost: use bool type where appropriate
Use 'bool' to clarify that the valid value is true or false.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
show more ...
|
#
70ddb48d |
| 24-Apr-2022 |
Masahiro Yamada <masahiroy@kernel.org> |
modpost: move struct namespace_list to modpost.c
There is no good reason to define struct namespace_list in modpost.h
struct module has pointers to struct namespace_list, but that does not require
modpost: move struct namespace_list to modpost.c
There is no good reason to define struct namespace_list in modpost.h
struct module has pointers to struct namespace_list, but that does not require the definition of struct namespace_list.
Move it to modpost.c.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
show more ...
|
#
7ce3e410 |
| 05-Apr-2022 |
Masahiro Yamada <masahiroy@kernel.org> |
modpost: remove useless export_from_sec()
With commit 1743694eb235 ("modpost: stop symbol preloading for modversion CRC") applied, now export_from_sec() is useless.
handle_symbol() is called for ev
modpost: remove useless export_from_sec()
With commit 1743694eb235 ("modpost: stop symbol preloading for modversion CRC") applied, now export_from_sec() is useless.
handle_symbol() is called for every symbol in the ELF.
When 'symname' does not start with "__ksymtab", export_from_sec() is called, and the returned value is stored in 'export'.
It is used in the last part of handle_symbol():
if (strstarts(symname, "__ksymtab_")) { name = symname + strlen("__ksymtab_"); sym_add_exported(name, mod, export); }
'export' is used only when 'symname' starts with "__ksymtab_".
So, the value returned by export_from_sec() is never used.
Remove useless export_from_sec(). This makes further cleanups possible.
I put the temporary code:
export = export_unknown;
Otherwise, I would get the compiler warning:
warning: 'export' may be used uninitialized in this function [-Wmaybe-uninitialized]
This is apparently false positive because
if (strstarts(symname, "__ksymtab_")
... is a stronger condition than:
if (strstarts(symname, "__ksymtab")
Anyway, this part will be cleaned up by the next commit.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
show more ...
|