Skip to content

Commit eba75a3

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 69a9b97 commit eba75a3

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
@@ -2434,7 +2434,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
24342434
}
24352435

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

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

24552455
if (!(symname = strchr(line, '\t')))
24562456
goto fail;
24572457
*symname++ = '\0';
2458-
if (!(namespace = strchr(symname, '\t')))
2459-
goto fail;
2460-
*namespace++ = '\0';
2461-
if (!(modname = strchr(namespace, '\t')))
2458+
if (!(modname = strchr(symname, '\t')))
24622459
goto fail;
24632460
*modname++ = '\0';
2464-
if ((export = strchr(modname, '\t')) != NULL)
2465-
*export++ = '\0';
2466-
if (export && ((end = strchr(export, '\t')) != NULL))
2467-
*end = '\0';
2461+
if (!(export = strchr(modname, '\t')))
2462+
goto fail;
2463+
*export++ = '\0';
2464+
if (!(namespace = strchr(export, '\t')))
2465+
goto fail;
2466+
*namespace++ = '\0';
2467+
24682468
crc = strtoul(line, &d, 16);
24692469
if (*symname == '\0' || *modname == '\0' || *d != '\0')
24702470
goto fail;
@@ -2516,9 +2516,9 @@ static void write_dump(const char *fname)
25162516
namespace = symbol->namespace;
25172517
buf_printf(&buf, "0x%08x\t%s\t%s\t%s\t%s\n",
25182518
symbol->crc, symbol->name,
2519-
namespace ? namespace : "",
25202519
symbol->module->name,
2521-
export_str(symbol->export));
2520+
export_str(symbol->export),
2521+
namespace ? namespace : "");
25222522
}
25232523
symbol = symbol->next;
25242524
}

0 commit comments

Comments
 (0)