Skip to content

Commit 7b727f1

Browse files
Jessica Yugregkh
authored andcommitted
modpost: move the namespace field in Module.symvers last
commit 5190044 upstream. In order to preserve backwards compatability with kmod tools, we have to move the namespace field in Module.symvers last, as the depmod -e -E option looks at the first three fields in Module.symvers to check symbol versions (and it's expected they stay in the original order of crc, symbol, module). In addition, update an ancient comment above read_dump() in modpost that suggested that the export type field in Module.symvers was optional. I suspect that there were historical reasons behind that comment that are no longer accurate. We have been unconditionally printing the export type since 2.6.18 (commit bd5cbce), which is over a decade ago now. Fix up read_dump() to treat each field as non-optional. I suspect the original read_dump() code treated the export field as optional in order to support pre <= 2.6.18 Module.symvers (which did not have the export type field). Note that although symbol namespaces are optional, the field will not be omitted from Module.symvers if a symbol does not have a namespace. In this case, the field will simply be empty and the next delimiter or end of line will follow. Cc: stable@vger.kernel.org Fixes: cb9b55d ("modpost: add support for symbol namespaces") Tested-by: Matthias Maennich <maennich@google.com> Reviewed-by: Matthias Maennich <maennich@google.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Jessica Yu <jeyu@kernel.org> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0efc757 commit 7b727f1

3 files changed

Lines changed: 15 additions & 15 deletions

File tree

‎Documentation/kbuild/modules.rst‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,9 @@ build.
470470

471471
The syntax of the Module.symvers file is::
472472

473-
<CRC> <Symbol> <Namespace> <Module> <Export Type>
473+
<CRC> <Symbol> <Module> <Export Type> <Namespace>
474474

475-
0xe1cc2a05 usb_stor_suspend USB_STORAGE drivers/usb/storage/usb-storage EXPORT_SYMBOL_GPL
475+
0xe1cc2a05 usb_stor_suspend drivers/usb/storage/usb-storage EXPORT_SYMBOL_GPL USB_STORAGE
476476

477477
The fields are separated by tabs and values may be empty (e.g.
478478
if no namespace is defined for an exported symbol).

‎scripts/export_report.pl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ sub collectcfiles {
9494
#
9595
while ( <$module_symvers> ) {
9696
chomp;
97-
my (undef, $symbol, $namespace, $module, $gpl) = split('\t');
97+
my (undef, $symbol, $module, $gpl, $namespace) = split('\t');
9898
$SYMBOL { $symbol } = [ $module , "0" , $symbol, $gpl];
9999
}
100100
close($module_symvers);

‎scripts/mod/modpost.c‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,7 +2433,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
24332433
}
24342434

24352435
/* parse Module.symvers file. line format:
2436-
* 0x12345678<tab>symbol<tab>module[[<tab>export]<tab>something]
2436+
* 0x12345678<tab>symbol<tab>module<tab>export<tab>namespace
24372437
**/
24382438
static void read_dump(const char *fname, unsigned int kernel)
24392439
{
@@ -2446,24 +2446,24 @@ static void read_dump(const char *fname, unsigned int kernel)
24462446
return;
24472447

24482448
while ((line = get_next_line(&pos, file, size))) {
2449-
char *symname, *namespace, *modname, *d, *export, *end;
2449+
char *symname, *namespace, *modname, *d, *export;
24502450
unsigned int crc;
24512451
struct module *mod;
24522452
struct symbol *s;
24532453

24542454
if (!(symname = strchr(line, '\t')))
24552455
goto fail;
24562456
*symname++ = '\0';
2457-
if (!(namespace = strchr(symname, '\t')))
2458-
goto fail;
2459-
*namespace++ = '\0';
2460-
if (!(modname = strchr(namespace, '\t')))
2457+
if (!(modname = strchr(symname, '\t')))
24612458
goto fail;
24622459
*modname++ = '\0';
2463-
if ((export = strchr(modname, '\t')) != NULL)
2464-
*export++ = '\0';
2465-
if (export && ((end = strchr(export, '\t')) != NULL))
2466-
*end = '\0';
2460+
if (!(export = strchr(modname, '\t')))
2461+
goto fail;
2462+
*export++ = '\0';
2463+
if (!(namespace = strchr(export, '\t')))
2464+
goto fail;
2465+
*namespace++ = '\0';
2466+
24672467
crc = strtoul(line, &d, 16);
24682468
if (*symname == '\0' || *modname == '\0' || *d != '\0')
24692469
goto fail;
@@ -2514,9 +2514,9 @@ static void write_dump(const char *fname)
25142514
namespace = symbol->namespace;
25152515
buf_printf(&buf, "0x%08x\t%s\t%s\t%s\t%s\n",
25162516
symbol->crc, symbol->name,
2517-
namespace ? namespace : "",
25182517
symbol->module->name,
2519-
export_str(symbol->export));
2518+
export_str(symbol->export),
2519+
namespace ? namespace : "");
25202520
}
25212521
symbol = symbol->next;
25222522
}

0 commit comments

Comments
 (0)