Skip to contentSkip to conversation

Extended MODVERSIONS Support

PATCH Superseded Matthew Maurer 4 participants 12 messages Oct 23, 2024 – Oct 30, 2024

Subsystems (4)

v7 of 13 Superseded Latest is v13 →

lore
Share & tools
lore
#0 lore raw

v7 cover Extended MODVERSIONS Support

This patch series is intended for use alongside the Implement DWARF modversions series [1] to enable RUST and MODVERSIONS at the same time.

Elsewhere, we've seen a desire for long symbol name support for LTO symbol names [2], and the previous series came up [3] as a possible solution rather than hashing, which some have objected [4] to.

This series adds a MODVERSIONS format which uses a section per column. This avoids userspace tools breaking if we need to make a similar change to the format in the future - we would do so by adding a new section, rather than editing the struct definition. In the new format, the name section is formatted as a concatenated sequence of NUL-terminated strings, which allows for arbitrary length names.

Emitting the extended format is guarded by CONFIG_EXTENDED_MODVERSIONS, but the kernel always knows how to validate both the original and extended formats.

Selecting RUST and MODVERSIONS is now possible if GENDWARFKSYMS is selected, and will implicitly select EXTENDED_MODVERSIONS.

This series depends upon the module verification refactor patches [5] that were split off of v5, and DWARF-based versions [1].

linuxppc-dev is requested to look at the ppc-specific munging, as Luis would like some eyes on there [6].

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/lkml/[email protected]/
[4] https://lore.kernel.org/lkml/[email protected]/
[5] https://lore.kernel.org/linux-modules/[email protected]/T/#t
[6] https://lore.kernel.org/lkml/[email protected]/

Changes in v7:
- Fix modpost to detect EXTENDED_MODVERSIONS based on a flag
- Drop patches to fix export_report.pl
- Switch from conditional compilation in .mod.c to conditional emission in modpost
- Factored extended modversion emission into its own function
- Allow RUST + MODVERSIONS if GENDWARFKSYMS is enabled by selecting EXTENDED_MODVERSIONS

v6: https://lore.kernel.org/lkml/[email protected]/
- Splits verification refactor Luis requested out to a separate change
- Clarifies commits around export_report.pl repairs
- Add CONFIG_EXTENDED_MODVERSIONS to control whether extended information is included in the module, per Luis's request.

v5: https://lore.kernel.org/all/[email protected]/
- Addresses Sami's comments from v3 that I missed in v4 (missing early return, extra parens)

v4: https://lore.kernel.org/asahi/[email protected]/
- Fix incorrect dot munging in PPC

v3: https://lore.kernel.org/lkml/[email protected]/T/
- Split up the module verification refactor into smaller patches, per Greg K-H's suggestion.

v2: https://lore.kernel.org/all/[email protected]/
- Add loading/verification refactor before modifying, per Luis's request

v1: https://lore.kernel.org/rust-for-linux/[email protected]/

Matthew Maurer (5):
export_report: Rehabilitate script
modules: Support extended MODVERSIONS info
export_report: Tolerate additional .mod.c content
modpost: Produce extended MODVERSIONS information
export_report: Use new version info format

 arch/powerpc/kernel/module_64.c | 23 ++++++++-
 kernel/module/Kconfig           |  8 +++
 kernel/module/internal.h        | 11 ++++
 kernel/module/main.c            | 92 ++++++++++++++++++++++++++++++---
 kernel/module/version.c         | 45 ++++++++++++++++
 scripts/export_report.pl        | 17 +++---
 scripts/mod/modpost.c           | 41 +++++++++++++++
 7 files changed, 220 insertions(+), 17 deletions(-)

--
2.47.0.rc1.288.g06298d1525-goog

---
Matthew Maurer (2):
modules: Support extended MODVERSIONS info
modpost: Produce extended MODVERSIONS information

Sami Tolvanen (1):
rust: Use gendwarfksyms + extended modversions for CONFIG_MODVERSIONS

 arch/powerpc/kernel/module_64.c | 24 ++++++++++-
 init/Kconfig                    |  3 +-
 kernel/module/Kconfig           | 10 +++++
 kernel/module/internal.h        | 11 +++++
 kernel/module/main.c            | 92 +++++++++++++++++++++++++++++++++++++----
 kernel/module/version.c         | 45 ++++++++++++++++++++
 rust/Makefile                   | 32 +++++++++++++-
 scripts/Makefile.modpost        |  1 +
 scripts/mod/modpost.c           | 65 +++++++++++++++++++++++++++--
 9 files changed, 266 insertions(+), 17 deletions(-)

---
base-commit: 2295cf87ed5a6da4564034e4f8ebcce0a0a021ed
change-id: 20241022-extended-modversions-a7b44dfbfff1
prerequisite-message-id: <[email protected]>
prerequisite-patch-id: 08b46e0d1e37c262c08da6db4a87728d7b3047cc
prerequisite-patch-id: 97f307e05ec4b7a653f1ec68f825e8d5bd622b05
prerequisite-patch-id: a4519fb5eef33d692b918529ae094845f822b718
prerequisite-patch-id: e192e2a692c40d96cba919e3baae68c441ab25e4
prerequisite-patch-id: 58359b851618c2b6582e02e11ac54d7cd0375853
prerequisite-patch-id: 4d6a826429c519b581d01215e1d9c7373fdfd8c6
prerequisite-patch-id: 0dcd84187b222adf52696dbcab303d683d087dd2
prerequisite-patch-id: 0abe8634eb844a85e8dc51c1cd3970cf96cc494a
prerequisite-patch-id: c9b1a36f177f5bd25cc5a9236f4839e972c12333
prerequisite-patch-id: b7b61991d74f0a0a0b8f50f7eeb3c306261ee512
prerequisite-patch-id: f6c97ecaaa62cee387d7bb83e3dd6d5fda44cafd
prerequisite-patch-id: 6182973041c913f727b289228e7e3e19de09c999
prerequisite-patch-id: d688fb99eb5d6152fece6068c1b3a434c5750109
prerequisite-patch-id: f09e5d7c8bbba276b0e3a244a89b6bb18f692fa1
prerequisite-patch-id: 66ffe1d8df889b254a0f29992d9c0356676ed489
prerequisite-patch-id: a372f88626c3dda51eab6c6af132a76141ff20cc
prerequisite-patch-id: 57d2fe708769154a6494fb1fece56911dea00687
prerequisite-patch-id: 18ddc778b1a3b263db34e906eb74e9d15602ce68
prerequisite-patch-id: 8297655807a95e5a5522edaa0c082888c8a0286f

Best regards,

Signature · 1 line
Matthew Maurer <[email protected]>
#1 lore raw

PATCH v7 1/3 modules: Support extended MODVERSIONS info

Adds a new format for MODVERSIONS which stores each field in a separate ELF section. This initially adds support for variable length names, but could later be used to add additional fields to MODVERSIONS in a backwards compatible way if needed. Any new fields will be ignored by old user tooling, unlike the current format where user tooling cannot tolerate adjustments to the format (for example making the name field longer).

Since PPC munges its version records to strip leading dots, we reproduce the munging for the new format. Other architectures do not appear to have architecture-specific usage of this information.

---
 arch/powerpc/kernel/module_64.c | 24 ++++++++++-
 kernel/module/internal.h        | 11 +++++
 kernel/module/main.c            | 92 +++++++++++++++++++++++++++++++++++++----
 kernel/module/version.c         | 45 ++++++++++++++++++++
 4 files changed, 162 insertions(+), 10 deletions(-)
arch/powerpc/kernel/module_64.c +22 -2
index e9bab599d0c2745e4d2b5cae04f2c56395c24654..02ada0b057cef6b2f29fa7519a5d52acac740ee5 100644
@@ -355,6 +355,24 @@ static void dedotify_versions(struct modversion_info *vers,
 		}
 }
 
+/* Same as normal versions, remove a leading dot if present. */
+static void dedotify_ext_version_names(char *str_seq, unsigned long size)
+{
+	unsigned long out = 0;
+	unsigned long in;
+	char last = '\0';
+
+	for (in = 0; in < size; in++) {
+		/* Skip one leading dot */
+		if (last == '\0' && str_seq[in] == '.')
+			in++;
+		last = str_seq[in];
+		str_seq[out++] = last;
+	}
+	/* Zero the trailing portion of the names table for robustness */
+	memset(&str_seq[out], 0, size - out);
+}
+
 /*
  * Undefined symbols which refer to .funcname, hack to funcname. Make .TOC.
  * seem to be defined (value set later).
@@ -424,10 +442,12 @@ int module_frob_arch_sections(Elf64_Ehdr *hdr,
 			me->arch.toc_section = i;
 			if (sechdrs[i].sh_addralign < 8)
 				sechdrs[i].sh_addralign = 8;
-		}
-		else if (strcmp(secstrings+sechdrs[i].sh_name,"__versions")==0)
+		} else if (strcmp(secstrings + sechdrs[i].sh_name, "__versions") == 0)
 			dedotify_versions((void *)hdr + sechdrs[i].sh_offset,
 					  sechdrs[i].sh_size);
+		else if (strcmp(secstrings + sechdrs[i].sh_name, "__version_ext_names") == 0)
+			dedotify_ext_version_names((void *)hdr + sechdrs[i].sh_offset,
+						   sechdrs[i].sh_size);
 
 		if (sechdrs[i].sh_type == SHT_SYMTAB)
 			dedotify((void *)hdr + sechdrs[i].sh_offset,
kernel/module/internal.h +11 -0
index daef2be8390222c22220e2f168baa8d35ad531b9..59959c21b205bf91c0073260885743098c4022cf 100644
@@ -86,6 +86,8 @@ struct load_info {
 		unsigned int vers;
 		unsigned int info;
 		unsigned int pcpu;
+		unsigned int vers_ext_crc;
+		unsigned int vers_ext_name;
 	} index;
 };
 
@@ -389,6 +391,15 @@ void module_layout(struct module *mod, struct modversion_info *ver, struct kerne
 		   struct kernel_symbol *ks, struct tracepoint * const *tp);
 int check_modstruct_version(const struct load_info *info, struct module *mod);
 int same_magic(const char *amagic, const char *bmagic, bool has_crcs);
+struct modversion_info_ext {
+	size_t remaining;
+	const s32 *crc;
+	const char *name;
+};
+void modversion_ext_start(const struct load_info *info, struct modversion_info_ext *ver);
+void modversion_ext_advance(struct modversion_info_ext *ver);
+#define for_each_modversion_info_ext(ver, info) \
+	for (modversion_ext_start(info, &ver); ver.remaining > 0; modversion_ext_advance(&ver))
 #else /* !CONFIG_MODVERSIONS */
 static inline int check_version(const struct load_info *info,
 				const char *symname,
kernel/module/main.c +84 -8

116 lines not on this page · raw message

kernel/module/version.c +45 -0

62 lines not on this page · raw message

Signature · 1 line
2.47.0.105.g07ac214952-goog
maintainer Reviewed-by on v7 1/3
#2 lore raw

Re: [PATCH v7 1/3] modules: Support extended MODVERSIONS info

Quoted 8 lines · Matthew Maurer

Adds a new format for MODVERSIONS which stores each field in a separate ELF section. This initially adds support for variable length names, but could later be used to add additional fields to MODVERSIONS in a backwards compatible way if needed. Any new fields will be ignored by old user tooling, unlike the current format where user tooling cannot tolerate adjustments to the format (for example making the name field longer).

Quoted 5 lines

Since PPC munges its version records to strip leading dots, we reproduce the munging for the new format. Other architectures do not appear to have architecture-specific usage of this information.

Sami

#3 lore raw

Re: [PATCH v7 1/3] modules: Support extended MODVERSIONS info

In reply to Matthew Maurer
Quoted 35 lines · Matthew Maurer

Adds a new format for MODVERSIONS which stores each field in a separate ELF section. This initially adds support for variable length names, but could later be used to add additional fields to MODVERSIONS in a backwards compatible way if needed. Any new fields will be ignored by old user tooling, unlike the current format where user tooling cannot tolerate adjustments to the format (for example making the name field longer).

Since PPC munges its version records to strip leading dots, we reproduce the munging for the new format. Other architectures do not appear to have architecture-specific usage of this information.

---
 arch/powerpc/kernel/module_64.c | 24 ++++++++++-
 kernel/module/internal.h        | 11 +++++
 kernel/module/main.c            | 92 +++++++++++++++++++++++++++++++++++++----
 kernel/module/version.c         | 45 ++++++++++++++++++++
 4 files changed, 162 insertions(+), 10 deletions(-)
arch/powerpc/kernel/module_64.c +7 -0
index e9bab599d0c2745e4d2b5cae04f2c56395c24654..02ada0b057cef6b2f29fa7519a5d52acac740ee5 100644
@@ -355,6 +355,24 @@ static void dedotify_versions(struct modversion_info *vers,
 		}
 }
 
+/* Same as normal versions, remove a leading dot if present. */
+static void dedotify_ext_version_names(char *str_seq, unsigned long size)
+{
+	unsigned long out = 0;
+	unsigned long in;
+	char last = '\0';
+

arch/powerpc/kernel/module_64.c static void dedotify_versions(struct modversion_info *vers, · line 374

Quoted 10 lines
arch/powerpc/kernel/module_64.c +10 -0
+	for (in = 0; in < size; in++) {
+		/* Skip one leading dot */
+		if (last == '\0' && str_seq[in] == '.')
+			in++;
+		last = str_seq[in];
+		str_seq[out++] = last;
+	}
+	/* Zero the trailing portion of the names table for robustness */
+	memset(&str_seq[out], 0, size - out);
+}

Sorry I realise it's version 7, but although the above looks correct it's kind of dense.

I think the below would also work and is (I think) easier to follow, and is more obviously similar to the existing code. I'm sure your version is faster, but I don't think it's that performance critical.

static void dedotify_ext_version_names(char *str_seq, unsigned long size)

{
	char *end = str_seq + size;
	char *p = str_seq;

	while (p < end) {
		if (*p == '.')
			memmove(p, p + 1, end - p - 1);

		p += strlen(p) + 1;
	}
}

The tail of str_seq will be filled with nulls as long as the last string was null terminated.

cheers

#4 lore raw

Re: [PATCH v7 1/3] modules: Support extended MODVERSIONS info

Quoted 20 lines

Sorry I realise it's version 7, but although the above looks correct it's kind of dense.

I think the below would also work and is (I think) easier to follow, and is more obviously similar to the existing code. I'm sure your version is faster, but I don't think it's that performance critical.

static void dedotify_ext_version_names(char *str_seq, unsigned long size)

{
        char *end = str_seq + size;
        char *p = str_seq;

        while (p < end) {
                if (*p == '.')
                        memmove(p, p + 1, end - p - 1);

                p += strlen(p) + 1;
        }
}
Quoted 4 lines

The tail of str_seq will be filled with nulls as long as the last string was null terminated.

cheers

As you alluded to, what you're providing is potentially O(n^2) in the number of symbols a module depends on - the existing code is O(n). If leading dots on names are rare, this is probably fine. If they're common, this will potentially make loading modules with a large number of imported symbols actually take a measurable amount of additional time.

That said, I take your point about complexity, and trust you to know your arch's inputs/requirements, so if I don't hear back again I will incorporate that into the next revision of the patch (to be produced after the gendwarfksyms update comes out).

#5 lore raw

Re: [PATCH v7 1/3] modules: Support extended MODVERSIONS info

Quoted 23 lines · Matthew Maurer
Quoted 20 lines

Sorry I realise it's version 7, but although the above looks correct it's kind of dense.

I think the below would also work and is (I think) easier to follow, and is more obviously similar to the existing code. I'm sure your version is faster, but I don't think it's that performance critical.

static void dedotify_ext_version_names(char *str_seq, unsigned long size)

{
        char *end = str_seq + size;
        char *p = str_seq;

        while (p < end) {
                if (*p == '.')
                        memmove(p, p + 1, end - p - 1);

                p += strlen(p) + 1;
        }
}
Quoted 2 lines

The tail of str_seq will be filled with nulls as long as the last string was null terminated.

Quoted 6 lines

As you alluded to, what you're providing is potentially O(n^2) in the number of symbols a module depends on - the existing code is O(n). If leading dots on names are rare, this is probably fine. If they're common, this will potentially make loading modules with a large number of imported symbols actually take a measurable amount of additional time.

It should only be a single symbol these days, .TOC., for both big and little endian builds.

But maybe someone out there is still building their kernel ELFv1, in which case every function will begin with '.'.

I still don't think it will be measurable, but n^2 is asking for trouble.

So forget it, just use your version, you've already written it anyway. Sorry for the noise.

cheers

#6 lore raw

PATCH v7 2/3 modpost: Produce extended MODVERSIONS information

In reply to Matthew Maurer

Generate both the existing modversions format and the new extended one when running modpost. Presence of this metadata in the final .ko is guarded by CONFIG_EXTENDED_MODVERSIONS.

We no longer generate an error on long symbols in modpost if CONFIG_EXTENDED_MODVERSIONS is set, as they can now be appropriately encoded in the extended section. These symbols will be skipped in the previous encoding. An error will still be generated if CONFIG_EXTENDED_MODVERSIONS is not set.

---
 kernel/module/Kconfig    | 10 ++++++++
 scripts/Makefile.modpost |  1 +
 scripts/mod/modpost.c    | 65 +++++++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 72 insertions(+), 4 deletions(-)
kernel/module/Kconfig +10 -0
index e6b2427e5c190aacf7b9c5c1bb57fca39d311564..a31c617cd67d3d66b24d2fba34cbd5cc9c53ab78 100644
@@ -208,6 +208,16 @@ config ASM_MODVERSIONS
 	  assembly. This can be enabled only when the target architecture
 	  supports it.
 
+config EXTENDED_MODVERSIONS
+	bool "Extended Module Versioning Support"
+	depends on MODVERSIONS
+	help
+	  This enables extended MODVERSIONs support, allowing long symbol
+	  names to be versioned.
+
+	  The most likely reason you would enable this is to enable Rust
+	  support. If unsure, say N.
+
 config MODULE_SRCVERSION_ALL
 	bool "Source checksum for all modules"
 	help
scripts/Makefile.modpost +1 -0
index 44936ebad161e914cbcc40ac74a2d651596d7b07..765da63d592be56fe93c0f4a35f1bfbcb924541a 100644
@@ -43,6 +43,7 @@ MODPOST = scripts/mod/modpost
 modpost-args =										\
 	$(if $(CONFIG_MODULES),-M)							\
 	$(if $(CONFIG_MODVERSIONS),-m)							\
+	$(if $(CONFIG_EXTENDED_MODVERSIONS),-x)						\
 	$(if $(CONFIG_MODULE_SRCVERSION_ALL),-a)					\
 	$(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E)					\
 	$(if $(KBUILD_MODPOST_WARN),-w)							\
scripts/mod/modpost.c +61 -4

101 lines not on this page · raw message

Signature · 1 line
2.47.0.105.g07ac214952-goog
maintainer Reviewed-by on v7 2/3
#7 lore raw

Re: [PATCH v7 2/3] modpost: Produce extended MODVERSIONS information

Quoted 11 lines · Matthew Maurer

Generate both the existing modversions format and the new extended one when running modpost. Presence of this metadata in the final .ko is guarded by CONFIG_EXTENDED_MODVERSIONS.

We no longer generate an error on long symbols in modpost if CONFIG_EXTENDED_MODVERSIONS is set, as they can now be appropriately encoded in the extended section. These symbols will be skipped in the previous encoding. An error will still be generated if CONFIG_EXTENDED_MODVERSIONS is not set.

Thanks for fixing this, LGTM.

Sami

#8 lore raw

PATCH v7 3/3 rust: Use gendwarfksyms + extended modversions for CONFIG_MODVERSIONS

In reply to Matthew Maurer

From: Sami Tolvanen <[email protected]>

Previously, two things stopped Rust from using MODVERSIONS:
1. Rust symbols are occasionally too long to be represented in the original versions table
2. Rust types cannot be properly hashed by the existing genksyms approach because:
* Looking up type definitions in Rust is more complex than C
* Type layout is potentially dependent on the compiler in Rust, not just the source type declaration.

CONFIG_EXTENDED_MODVERSIONS addresses the first point, and CONFIG_GENDWARFKSYMS the second. If Rust wants to use MODVERSIONS, allow it to do so by selecting both features.

---
 init/Kconfig  |  3 ++-
 rust/Makefile | 32 ++++++++++++++++++++++++++++++--
 2 files changed, 32 insertions(+), 3 deletions(-)
init/Kconfig +2 -1
index 530a382ee0feb391b4717abdba3672e584a462d0..f5cce579f29b2ed89e97f8075a3bf70e32e71ad0 100644
@@ -1942,7 +1942,8 @@ config RUST
 	bool "Rust support"
 	depends on HAVE_RUST
 	depends on RUST_IS_AVAILABLE
-	depends on !MODVERSIONS
+	select EXTENDED_MODVERSIONS if MODVERSIONS
+	depends on (GENDWARFKSYMS || !MODVERSIONS)
 	depends on !GCC_PLUGIN_RANDSTRUCT
 	depends on !RANDSTRUCT
 	depends on !DEBUG_INFO_BTF || PAHOLE_HAS_LANG_EXCLUDE
rust/Makefile +30 -2
index b5e0a73b78f3e58fc8fb8c9fab8fb5792406c6d8..b80bc4eb98202f774c493da89c2caee322cffc91 100644
@@ -303,10 +303,11 @@ $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ;
 $(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers/helpers.c FORCE
 	$(call if_changed_dep,bindgen)
 
+rust_exports = $(NM) -p --defined-only $(1) | awk '$$2~/(T|R|D|B)/ && $$3!~/__cfi/ { printf $(2),$(3) }'
+
 quiet_cmd_exports = EXPORTS $@
       cmd_exports = \
-	$(NM) -p --defined-only $< \
-		| awk '$$2~/(T|R|D|B)/ && $$3!~/__cfi/ {printf "EXPORT_SYMBOL_RUST_GPL(%s);\n",$$3}' > $@
+	$(call rust_exports,$<,"EXPORT_SYMBOL_RUST_GPL(%s);\n",$$3) > $@
 
 $(obj)/exports_core_generated.h: $(obj)/core.o FORCE
 	$(call if_changed,exports)
@@ -378,11 +379,35 @@ ifneq ($(or $(CONFIG_ARM64),$(and $(CONFIG_RISCV),$(CONFIG_64BIT))),)
 		__ashlti3 __lshrti3
 endif
 
+ifdef CONFIG_MODVERSIONS
+cmd_gendwarfksyms = $(if $(skip_gendwarfksyms),, \
+	$(call rust_exports,$@,"%s\n",$$3) | \
+	scripts/gendwarfksyms/gendwarfksyms \
+		$(if $(KBUILD_SYMTYPES), --symtypes $(@:.o=.symtypes),) \
+		$@ >> $(dot-target).cmd)
+endif
+
 define rule_rustc_library
 	$(call cmd_and_fixdep,rustc_library)
 	$(call cmd,gen_objtooldep)
+	$(call cmd,gendwarfksyms)
 endef
 
+define rule_rust_cc_library
+	$(call if_changed_rule,cc_o_c)
+	$(call cmd,force_checksrc)
+	$(call cmd,gendwarfksyms)
+endef
+
+# helpers.o uses the same export mechanism as Rust libraries, so ensure symbol
+# versions are calculated for the helpers too.
+$(obj)/helpers/helpers.o: $(src)/helpers/helpers.c $(recordmcount_source) FORCE
+	+$(call if_changed_rule,rust_cc_library)
+
+# Disable symbol versioning for exports.o to avoid conflicts with the actual
+# symbol versions generated from Rust objects.
+$(obj)/exports.o: private skip_gendwarfksyms = 1
+
 $(obj)/core.o: private skip_clippy = 1
 $(obj)/core.o: private skip_flags = -Wunreachable_pub
 $(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym))
@@ -394,6 +419,7 @@ ifneq ($(or $(CONFIG_X86_64),$(CONFIG_X86_32)),)
 $(obj)/core.o: scripts/target.json
 endif
 
+$(obj)/compiler_builtins.o: private skip_gendwarfksyms = 1
 $(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*'
 $(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE
 	+$(call if_changed_rule,rustc_library)
@@ -404,6 +430,7 @@ $(obj)/alloc.o: private rustc_target_flags = $(alloc-cfgs)
 $(obj)/alloc.o: $(RUST_LIB_SRC)/alloc/src/lib.rs $(obj)/compiler_builtins.o FORCE
 	+$(call if_changed_rule,rustc_library)
 
+$(obj)/build_error.o: private skip_gendwarfksyms = 1
 $(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE
 	+$(call if_changed_rule,rustc_library)
 
@@ -413,6 +440,7 @@ $(obj)/bindings.o: $(src)/bindings/lib.rs \
     $(obj)/bindings/bindings_helpers_generated.rs FORCE
 	+$(call if_changed_rule,rustc_library)
 
+$(obj)/uapi.o: private skip_gendwarfksyms = 1
 $(obj)/uapi.o: $(src)/uapi/lib.rs \
     $(obj)/compiler_builtins.o \
     $(obj)/uapi/uapi_generated.rs FORCE
Signature · 1 line
2.47.0.105.g07ac214952-goog
maintainer
#9 lore raw

Re: [PATCH v7 3/3] rust: Use gendwarfksyms + extended modversions for CONFIG_MODVERSIONS

Quoted 28 lines · Matthew Maurer

From: Sami Tolvanen <[email protected]>

Previously, two things stopped Rust from using MODVERSIONS:
1. Rust symbols are occasionally too long to be represented in the original versions table
2. Rust types cannot be properly hashed by the existing genksyms approach because:
* Looking up type definitions in Rust is more complex than C
* Type layout is potentially dependent on the compiler in Rust, not just the source type declaration.

CONFIG_EXTENDED_MODVERSIONS addresses the first point, and CONFIG_GENDWARFKSYMS the second. If Rust wants to use MODVERSIONS, allow it to do so by selecting both features.

---
 init/Kconfig  |  3 ++-
 rust/Makefile | 32 ++++++++++++++++++++++++++++++--
 2 files changed, 32 insertions(+), 3 deletions(-)
init/Kconfig +0 -0
index 530a382ee0feb391b4717abdba3672e584a462d0..f5cce579f29b2ed89e97f8075a3bf70e32e71ad0 100644

init/Kconfig config RUST · line 1946

Quoted 6 lines
init/Kconfig +2 -1
@@ -1942,7 +1942,8 @@ config RUST
 	bool "Rust support"
 	depends on HAVE_RUST
 	depends on RUST_IS_AVAILABLE
-	depends on !MODVERSIONS
+	select EXTENDED_MODVERSIONS if MODVERSIONS
+	depends on (GENDWARFKSYMS || !MODVERSIONS)

Nit: depends on !MODVERSIONS || GENDWARFKSYMS would match the convention used below.

init/Kconfig config RUST

Quoted 5 lines
init/Kconfig +5 -0
+cmd_gendwarfksyms = $(if $(skip_gendwarfksyms),, \
+	$(call rust_exports,$@,"%s\n",$$3) | \
+	scripts/gendwarfksyms/gendwarfksyms \
+		$(if $(KBUILD_SYMTYPES), --symtypes $(@:.o=.symtypes),) \
+		$@ >> $(dot-target).cmd)

Note that Petr suggested adding a KBUILD_ flag for passing the --stable parameter to gendwarfksyms, which I think would be useful, so once I send out v5 of that series, we'll have to update this to also use the parameter when processing Rust objects:

https://lore.kernel.org/linux-modules/[email protected]/

Sami

maintainer
#10 lore raw
In reply to Matthew Maurer
Quoted 35 lines · Matthew Maurer

This patch series is intended for use alongside the Implement DWARF modversions series [1] to enable RUST and MODVERSIONS at the same time.

Elsewhere, we've seen a desire for long symbol name support for LTO symbol names [2], and the previous series came up [3] as a possible solution rather than hashing, which some have objected [4] to.

This series adds a MODVERSIONS format which uses a section per column. This avoids userspace tools breaking if we need to make a similar change to the format in the future - we would do so by adding a new section, rather than editing the struct definition. In the new format, the name section is formatted as a concatenated sequence of NUL-terminated strings, which allows for arbitrary length names.

Emitting the extended format is guarded by CONFIG_EXTENDED_MODVERSIONS, but the kernel always knows how to validate both the original and extended formats.

Selecting RUST and MODVERSIONS is now possible if GENDWARFKSYMS is selected, and will implicitly select EXTENDED_MODVERSIONS.

This series depends upon the module verification refactor patches [5] that were split off of v5, and DWARF-based versions [1].

linuxppc-dev is requested to look at the ppc-specific munging, as Luis would like some eyes on there [6].

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/lkml/[email protected]/
[4] https://lore.kernel.org/lkml/[email protected]/
[5] https://lore.kernel.org/linux-modules/[email protected]/T/#t
[6] https://lore.kernel.org/lkml/[email protected]/

Quoted 3 lines

Changes in v7:
- Fix modpost to detect EXTENDED_MODVERSIONS based on a flag
- Drop patches to fix export_report.pl

Unless Luis prefers to deal with this separately, perhaps you can just include a patch to delete export_report.pl in this series?

Sami

maintainer
#11 lore raw
Quoted 6 lines · Sami Tolvanen
Quoted 3 lines

Changes in v7:
- Fix modpost to detect EXTENDED_MODVERSIONS based on a flag
- Drop patches to fix export_report.pl

Unless Luis prefers to deal with this separately, perhaps you can just include a patch to delete export_report.pl in this series?

Yes, please do the homework to check the history of export_report.pl and just nuke it if we don't need it. Ignoring it just because it may not be used is not the right thing.

If you don't find the history on the current tree we have the history.git tree [0] I often use to go down memory lane pre-git.

[0] https://git.kernel.org/pub/scm/linux/kernel/git/history/history.git/

Luis