Skip to content

Commit 7b45371

Browse files
committed
kbuild: link symbol CRCs at final link, removing CONFIG_MODULE_REL_CRCS
include/{linux,asm-generic}/export.h defines a weak symbol, __crc_* as a placeholder. Genksyms writes the version CRCs into the linker script, which will be used for filling the __crc_* symbols. The linker script format depends on CONFIG_MODULE_REL_CRCS. If it is enabled, __crc_* holds the offset to the reference of CRC. It is time to get rid of this complexity. Now that modpost parses text files (.*.cmd) to collect all the CRCs, it can generate C code that will be linked to the vmlinux or modules. Generate a new C file, .vmlinux.export.c, which contains the CRCs of symbols exported by vmlinux. It is compiled and linked to vmlinux in scripts/link-vmlinux.sh. Put the CRCs of symbols exported by modules into the existing *.mod.c files. No additional build step is needed for modules. As before, *.mod.c are compiled and linked to *.ko in scripts/Makefile.modfinal. No linker magic is used here. The new C implementation works in the same way, whether CONFIG_RELOCATABLE is enabled or not. CONFIG_MODULE_REL_CRCS is no longer needed. Previously, Kbuild invoked additional $(LD) to update the CRCs in objects, but this step is unneeded too. Signed-off-by: Masahiro Yamada <[email protected]> Tested-by: Nathan Chancellor <[email protected]> Tested-by: Nicolas Schier <[email protected]> Reviewed-by: Nicolas Schier <[email protected]> Tested-by: Sedat Dilek <[email protected]> # LLVM-14 (x86-64)
1 parent f292d87 commit 7b45371

File tree

15 files changed

+108
-96
lines changed

15 files changed

+108
-96
lines changed

arch/m68k/include/asm/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0
22
generated-y += syscall_table.h
3+
generic-y += export.h
34
generic-y += extable.h
45
generic-y += kvm_para.h
56
generic-y += mcs_spinlock.h

arch/m68k/include/asm/export.h

Lines changed: 0 additions & 2 deletions
This file was deleted.

arch/powerpc/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,6 @@ config RELOCATABLE
566566
bool "Build a relocatable kernel"
567567
depends on PPC64 || (FLATMEM && (44x || FSL_BOOKE))
568568
select NONSTATIC_KERNEL
569-
select MODULE_REL_CRCS if MODVERSIONS
570569
help
571570
This builds a kernel image that is capable of running at the
572571
location the kernel is loaded at. For ppc32, there is no any

arch/s390/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,6 @@ endchoice
567567

568568
config RELOCATABLE
569569
bool "Build a relocatable kernel"
570-
select MODULE_REL_CRCS if MODVERSIONS
571570
default y
572571
help
573572
This builds a kernel image that retains relocation information

arch/um/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ config LD_SCRIPT_DYN
106106
bool
107107
default y
108108
depends on !LD_SCRIPT_STATIC
109-
select MODULE_REL_CRCS if MODVERSIONS
110109

111110
config LD_SCRIPT_DYN_RPATH
112111
bool "set rpath in the binary" if EXPERT

include/asm-generic/export.h

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
#ifndef __ASM_GENERIC_EXPORT_H
33
#define __ASM_GENERIC_EXPORT_H
44

5+
/*
6+
* This comment block is used by fixdep. Please do not remove.
7+
*
8+
* When CONFIG_MODVERSIONS is changed from n to y, all source files having
9+
* EXPORT_SYMBOL variants must be re-compiled because genksyms is run as a
10+
* side effect of the *.o build rule.
11+
*/
12+
513
#ifndef KSYM_FUNC
614
#define KSYM_FUNC(x) x
715
#endif
@@ -12,9 +20,6 @@
1220
#else
1321
#define KSYM_ALIGN 4
1422
#endif
15-
#ifndef KCRC_ALIGN
16-
#define KCRC_ALIGN 4
17-
#endif
1823

1924
.macro __put, val, name
2025
#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
@@ -43,17 +48,6 @@ __ksymtab_\name:
4348
__kstrtab_\name:
4449
.asciz "\name"
4550
.previous
46-
#ifdef CONFIG_MODVERSIONS
47-
.section ___kcrctab\sec+\name,"a"
48-
.balign KCRC_ALIGN
49-
#if defined(CONFIG_MODULE_REL_CRCS)
50-
.long __crc_\name - .
51-
#else
52-
.long __crc_\name
53-
#endif
54-
.weak __crc_\name
55-
.previous
56-
#endif
5751
#endif
5852
.endm
5953

include/linux/export-internal.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* Please do not include this explicitly.
4+
* This is used by C files generated by modpost.
5+
*/
6+
7+
#ifndef __LINUX_EXPORT_INTERNAL_H__
8+
#define __LINUX_EXPORT_INTERNAL_H__
9+
10+
#include <linux/compiler.h>
11+
#include <linux/types.h>
12+
13+
/* __used is needed to keep __crc_* for LTO */
14+
#define SYMBOL_CRC(sym, crc, sec) \
15+
u32 __section("___kcrctab" sec "+" #sym) __used __crc_##sym = crc
16+
17+
#endif /* __LINUX_EXPORT_INTERNAL_H__ */

include/linux/export.h

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
* hackers place grumpy comments in header files.
1212
*/
1313

14+
/*
15+
* This comment block is used by fixdep. Please do not remove.
16+
*
17+
* When CONFIG_MODVERSIONS is changed from n to y, all source files having
18+
* EXPORT_SYMBOL variants must be re-compiled because genksyms is run as a
19+
* side effect of the *.o build rule.
20+
*/
21+
1422
#ifndef __ASSEMBLY__
1523
#ifdef MODULE
1624
extern struct module __this_module;
@@ -19,26 +27,6 @@ extern struct module __this_module;
1927
#define THIS_MODULE ((struct module *)0)
2028
#endif
2129

22-
#ifdef CONFIG_MODVERSIONS
23-
/* Mark the CRC weak since genksyms apparently decides not to
24-
* generate a checksums for some symbols */
25-
#if defined(CONFIG_MODULE_REL_CRCS)
26-
#define __CRC_SYMBOL(sym, sec) \
27-
asm(" .section \"___kcrctab" sec "+" #sym "\", \"a\" \n" \
28-
" .weak __crc_" #sym " \n" \
29-
" .long __crc_" #sym " - . \n" \
30-
" .previous \n")
31-
#else
32-
#define __CRC_SYMBOL(sym, sec) \
33-
asm(" .section \"___kcrctab" sec "+" #sym "\", \"a\" \n" \
34-
" .weak __crc_" #sym " \n" \
35-
" .long __crc_" #sym " \n" \
36-
" .previous \n")
37-
#endif
38-
#else
39-
#define __CRC_SYMBOL(sym, sec)
40-
#endif
41-
4230
#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
4331
#include <linux/compiler.h>
4432
/*
@@ -85,7 +73,6 @@ struct kernel_symbol {
8573
/*
8674
* For every exported symbol, do the following:
8775
*
88-
* - If applicable, place a CRC entry in the __kcrctab section.
8976
* - Put the name of the symbol and namespace (empty string "" for none) in
9077
* __ksymtab_strings.
9178
* - Place a struct kernel_symbol entry in the __ksymtab section.
@@ -98,7 +85,6 @@ struct kernel_symbol {
9885
extern typeof(sym) sym; \
9986
extern const char __kstrtab_##sym[]; \
10087
extern const char __kstrtabns_##sym[]; \
101-
__CRC_SYMBOL(sym, sec); \
10288
asm(" .section \"__ksymtab_strings\",\"aMS\",%progbits,1 \n" \
10389
"__kstrtab_" #sym ": \n" \
10490
" .asciz \"" #sym "\" \n" \

init/Kconfig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,10 +2136,6 @@ config ASM_MODVERSIONS
21362136
assembly. This can be enabled only when the target architecture
21372137
supports it.
21382138

2139-
config MODULE_REL_CRCS
2140-
bool
2141-
depends on MODVERSIONS
2142-
21432139
config MODULE_SRCVERSION_ALL
21442140
bool "Source checksum for all modules"
21452141
help

kernel/module.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,11 +1231,6 @@ static int try_to_force_load(struct module *mod, const char *reason)
12311231

12321232
#ifdef CONFIG_MODVERSIONS
12331233

1234-
static u32 resolve_rel_crc(const s32 *crc)
1235-
{
1236-
return *(u32 *)((void *)crc + *crc);
1237-
}
1238-
12391234
static int check_version(const struct load_info *info,
12401235
const char *symname,
12411236
struct module *mod,
@@ -1264,10 +1259,7 @@ static int check_version(const struct load_info *info,
12641259
if (strcmp(versions[i].name, symname) != 0)
12651260
continue;
12661261

1267-
if (IS_ENABLED(CONFIG_MODULE_REL_CRCS))
1268-
crcval = resolve_rel_crc(crc);
1269-
else
1270-
crcval = *crc;
1262+
crcval = *crc;
12711263
if (versions[i].crc == crcval)
12721264
return 1;
12731265
pr_debug("Found checksum %X vs module %lX\n",

0 commit comments

Comments
 (0)