UBUNTU: SAUCE: modpost: support arbitrary symbol length in modversion
BugLink: https://bugs.launchpad.net/bugs/2007654
Currently modversion uses a fixed size array of size (64 - sizeof(long))
to store symbol names, thus placing a hard limit on length of symbols.
Rust symbols (which encodes crate and module names) can be quite a bit
longer. The length limit in kallsyms is increased to 512 for this reason.
It's a waste of space to simply expand the fixed array size to 512 in
modversion info entries. I therefore make it variably sized, with offset
to the next entry indicated by the initial "next" field.
In addition to supporting longer-than-56/60 byte symbols, this patch also
reduce the size for short symbols by getting rid of excessive 0 paddings.
There are still some zero paddings to ensure "next" and "crc" fields are
properly aligned.
This patch does have a tiny drawback that it makes ".mod.c" files generated
a bit less easy to read, as code like
"\x08\x00\x00\x00\x78\x56\x34\x12"
"symbol\0\0"
is generated as opposed to
{ 0x12345678, "symbol" },
because the structure is now variable-length. But hopefully nobody reads
the generated file :)
Link: b8a94bfb33 ("kallsyms: increase maximum kernel symbol length to 512")
Link: https://github.com/Rust-for-Linux/linux/pull/379
Signed-off-by: Gary Guo <gary@garyguo.net>
(backported from https://lore.kernel.org/lkml/20230111161155.1349375-1-gary@garyguo.net/)
[ fix build error on s390x: always use a variable with TO_NATIVE() ]
[ add dummy NULL entry at the end of the modversion array ]
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
This commit is contained in:
+25
-10
@@ -1900,13 +1900,17 @@ static void add_exported_symbols(struct buffer *buf, struct module *mod)
|
||||
static void add_versions(struct buffer *b, struct module *mod)
|
||||
{
|
||||
struct symbol *s;
|
||||
unsigned int name_len;
|
||||
unsigned int name_len_padded;
|
||||
unsigned int tmp;
|
||||
unsigned char *tmp_view = (unsigned char *)&tmp;
|
||||
|
||||
if (!modversions)
|
||||
return;
|
||||
|
||||
buf_printf(b, "\n");
|
||||
buf_printf(b, "static const struct modversion_info ____versions[]\n");
|
||||
buf_printf(b, "__used __section(\"__versions\") = {\n");
|
||||
buf_printf(b, "static const char ____versions[]\n");
|
||||
buf_printf(b, "__used __section(\"__versions\") =\n");
|
||||
|
||||
list_for_each_entry(s, &mod->unresolved_symbols, list) {
|
||||
if (!s->module)
|
||||
@@ -1916,16 +1920,27 @@ static void add_versions(struct buffer *b, struct module *mod)
|
||||
s->name, mod->name);
|
||||
continue;
|
||||
}
|
||||
if (strlen(s->name) >= MODULE_NAME_LEN) {
|
||||
error("too long symbol \"%s\" [%s.ko]\n",
|
||||
s->name, mod->name);
|
||||
break;
|
||||
}
|
||||
buf_printf(b, "\t{ %#8x, \"%s\" },\n",
|
||||
s->crc, s->name);
|
||||
name_len = strlen(s->name);
|
||||
name_len_padded = (name_len + 1 + 3) & ~3;
|
||||
|
||||
/* Offset to next entry */
|
||||
tmp = 8 + name_len_padded;
|
||||
tmp = TO_NATIVE(tmp);
|
||||
buf_printf(b, "\t\"\\x%02x\\x%02x\\x%02x\\x%02x",
|
||||
tmp_view[0], tmp_view[1], tmp_view[2], tmp_view[3]);
|
||||
|
||||
tmp = TO_NATIVE(s->crc);
|
||||
buf_printf(b, "\\x%02x\\x%02x\\x%02x\\x%02x\"\n",
|
||||
tmp_view[0], tmp_view[1], tmp_view[2], tmp_view[3]);
|
||||
|
||||
buf_printf(b, "\t\"%s", s->name);
|
||||
for (; name_len < name_len_padded; name_len++)
|
||||
buf_printf(b, "\\0");
|
||||
buf_printf(b, "\"\n");
|
||||
}
|
||||
|
||||
buf_printf(b, "};\n");
|
||||
/* Always end with a NULL entry */
|
||||
buf_printf(b, "\t\"\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\";\n");
|
||||
}
|
||||
|
||||
static void add_depends(struct buffer *b, struct module *mod)
|
||||
|
||||
Reference in New Issue
Block a user