hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/scripts/mod/modpost.c
....@@ -12,11 +12,11 @@
1212 */
1313
1414 #define _GNU_SOURCE
15
+#include <elf.h>
1516 #include <stdio.h>
1617 #include <ctype.h>
1718 #include <string.h>
1819 #include <limits.h>
19
-#include <stdbool.h>
2020 #include <errno.h>
2121 #include "modpost.h"
2222 #include "../../include/linux/license.h"
....@@ -29,16 +29,19 @@
2929 static int all_versions = 0;
3030 /* If we are modposting external module set to 1 */
3131 static int external_module = 0;
32
-/* Warn about section mismatch in vmlinux if set to 1 */
33
-static int vmlinux_section_warnings = 1;
32
+#define MODULE_SCMVERSION_SIZE 64
33
+static char module_scmversion[MODULE_SCMVERSION_SIZE];
3434 /* Only warn about unresolved symbols */
3535 static int warn_unresolved = 0;
3636 /* How a symbol is exported */
3737 static int sec_mismatch_count = 0;
38
-static int sec_mismatch_verbose = 1;
39
-static int sec_mismatch_fatal = 0;
38
+static int sec_mismatch_warn_only = true;
4039 /* ignore missing files */
4140 static int ignore_missing_files;
41
+/* If set to 1, only warn (instead of error) about missing ns imports */
42
+static int allow_missing_ns_imports;
43
+
44
+static bool error_occurred;
4245
4346 enum export {
4447 export_plain, export_unused, export_gpl,
....@@ -51,71 +54,101 @@
5154
5255 #define MODULE_NAME_LEN (64 - sizeof(Elf_Addr))
5356
54
-#define PRINTF __attribute__ ((format (printf, 1, 2)))
55
-
56
-PRINTF void fatal(const char *fmt, ...)
57
+void __attribute__((format(printf, 2, 3)))
58
+modpost_log(enum loglevel loglevel, const char *fmt, ...)
5759 {
5860 va_list arglist;
5961
60
- fprintf(stderr, "FATAL: ");
62
+ switch (loglevel) {
63
+ case LOG_WARN:
64
+ fprintf(stderr, "WARNING: ");
65
+ break;
66
+ case LOG_ERROR:
67
+ fprintf(stderr, "ERROR: ");
68
+ break;
69
+ case LOG_FATAL:
70
+ fprintf(stderr, "FATAL: ");
71
+ break;
72
+ default: /* invalid loglevel, ignore */
73
+ break;
74
+ }
75
+
76
+ fprintf(stderr, "modpost: ");
6177
6278 va_start(arglist, fmt);
6379 vfprintf(stderr, fmt, arglist);
6480 va_end(arglist);
6581
66
- exit(1);
67
-}
68
-
69
-PRINTF void warn(const char *fmt, ...)
70
-{
71
- va_list arglist;
72
-
73
- fprintf(stderr, "WARNING: ");
74
-
75
- va_start(arglist, fmt);
76
- vfprintf(stderr, fmt, arglist);
77
- va_end(arglist);
78
-}
79
-
80
-PRINTF void merror(const char *fmt, ...)
81
-{
82
- va_list arglist;
83
-
84
- fprintf(stderr, "ERROR: ");
85
-
86
- va_start(arglist, fmt);
87
- vfprintf(stderr, fmt, arglist);
88
- va_end(arglist);
89
-}
90
-
91
-static inline bool strends(const char *str, const char *postfix)
92
-{
93
- if (strlen(str) < strlen(postfix))
94
- return false;
95
-
96
- return strcmp(str + strlen(str) - strlen(postfix), postfix) == 0;
97
-}
98
-
99
-static int is_vmlinux(const char *modname)
100
-{
101
- const char *myname;
102
-
103
- myname = strrchr(modname, '/');
104
- if (myname)
105
- myname++;
106
- else
107
- myname = modname;
108
-
109
- return (strcmp(myname, "vmlinux") == 0) ||
110
- (strcmp(myname, "vmlinux.o") == 0);
82
+ if (loglevel == LOG_FATAL)
83
+ exit(1);
84
+ if (loglevel == LOG_ERROR)
85
+ error_occurred = true;
11186 }
11287
11388 void *do_nofail(void *ptr, const char *expr)
11489 {
11590 if (!ptr)
116
- fatal("modpost: Memory allocation failure: %s.\n", expr);
91
+ fatal("Memory allocation failure: %s.\n", expr);
11792
11893 return ptr;
94
+}
95
+
96
+char *read_text_file(const char *filename)
97
+{
98
+ struct stat st;
99
+ size_t nbytes;
100
+ int fd;
101
+ char *buf;
102
+
103
+ fd = open(filename, O_RDONLY);
104
+ if (fd < 0) {
105
+ perror(filename);
106
+ exit(1);
107
+ }
108
+
109
+ if (fstat(fd, &st) < 0) {
110
+ perror(filename);
111
+ exit(1);
112
+ }
113
+
114
+ buf = NOFAIL(malloc(st.st_size + 1));
115
+
116
+ nbytes = st.st_size;
117
+
118
+ while (nbytes) {
119
+ ssize_t bytes_read;
120
+
121
+ bytes_read = read(fd, buf, nbytes);
122
+ if (bytes_read < 0) {
123
+ perror(filename);
124
+ exit(1);
125
+ }
126
+
127
+ nbytes -= bytes_read;
128
+ }
129
+ buf[st.st_size] = '\0';
130
+
131
+ close(fd);
132
+
133
+ return buf;
134
+}
135
+
136
+char *get_line(char **stringp)
137
+{
138
+ char *orig = *stringp, *next;
139
+
140
+ /* do not return the unwanted extra line at EOF */
141
+ if (!orig || *orig == '\0')
142
+ return NULL;
143
+
144
+ /* don't use strsep here, it is not available everywhere */
145
+ next = strchr(orig, '\n');
146
+ if (next)
147
+ *next++ = '\0';
148
+
149
+ *stringp = next;
150
+
151
+ return orig;
119152 }
120153
121154 /* A list of all modules we processed */
....@@ -134,26 +167,19 @@
134167 static struct module *new_module(const char *modname)
135168 {
136169 struct module *mod;
137
- char *p;
138170
139
- mod = NOFAIL(malloc(sizeof(*mod)));
171
+ mod = NOFAIL(malloc(sizeof(*mod) + strlen(modname) + 1));
140172 memset(mod, 0, sizeof(*mod));
141
- p = NOFAIL(strdup(modname));
142
-
143
- /* strip trailing .o */
144
- if (strends(p, ".o")) {
145
- p[strlen(p) - 2] = '\0';
146
- mod->is_dot_o = 1;
147
- }
148
- /* strip trailing .lto */
149
- if (strends(p, ".lto"))
150
- p[strlen(p) - 4] = '\0';
151173
152174 /* add to list */
153
- mod->name = p;
175
+ strcpy(mod->name, modname);
176
+ mod->is_vmlinux = (strcmp(modname, "vmlinux") == 0);
154177 mod->gpl_compatible = -1;
155178 mod->next = modules;
156179 modules = mod;
180
+
181
+ if (mod->is_vmlinux)
182
+ have_vmlinux = 1;
157183
158184 return mod;
159185 }
....@@ -168,13 +194,11 @@
168194 struct module *module;
169195 unsigned int crc;
170196 int crc_valid;
197
+ char *namespace;
171198 unsigned int weak:1;
172
- unsigned int vmlinux:1; /* 1 if symbol is defined in vmlinux */
173
- unsigned int kernel:1; /* 1 if symbol is from kernel
174
- * (only for external modules) **/
175
- unsigned int preloaded:1; /* 1 if symbol from Module.symvers, or crc */
199
+ unsigned int is_static:1; /* 1 if symbol is not global */
176200 enum export export; /* Type of export */
177
- char name[0];
201
+ char name[];
178202 };
179203
180204 static struct symbol *symbolhash[SYMBOL_HASH_SIZE];
....@@ -205,6 +229,7 @@
205229 strcpy(s->name, name);
206230 s->weak = weak;
207231 s->next = next;
232
+ s->is_static = 1;
208233 return s;
209234 }
210235
....@@ -213,13 +238,11 @@
213238 enum export export)
214239 {
215240 unsigned int hash;
216
- struct symbol *new;
217241
218242 hash = tdb_hash(name) % SYMBOL_HASH_SIZE;
219
- new = symbolhash[hash] = alloc_symbol(name, 0, symbolhash[hash]);
220
- new->module = module;
221
- new->export = export;
222
- return new;
243
+ symbolhash[hash] = alloc_symbol(name, 0, symbolhash[hash]);
244
+
245
+ return symbolhash[hash];
223246 }
224247
225248 static struct symbol *find_symbol(const char *name)
....@@ -235,6 +258,35 @@
235258 return s;
236259 }
237260 return NULL;
261
+}
262
+
263
+static bool contains_namespace(struct namespace_list *list,
264
+ const char *namespace)
265
+{
266
+ for (; list; list = list->next)
267
+ if (!strcmp(list->namespace, namespace))
268
+ return true;
269
+
270
+ return false;
271
+}
272
+
273
+static void add_namespace(struct namespace_list **list, const char *namespace)
274
+{
275
+ struct namespace_list *ns_entry;
276
+
277
+ if (!contains_namespace(*list, namespace)) {
278
+ ns_entry = NOFAIL(malloc(sizeof(struct namespace_list) +
279
+ strlen(namespace) + 1));
280
+ strcpy(ns_entry->namespace, namespace);
281
+ ns_entry->next = *list;
282
+ *list = ns_entry;
283
+ }
284
+}
285
+
286
+static bool module_imports_namespace(struct module *module,
287
+ const char *namespace)
288
+{
289
+ return contains_namespace(module->imported_namespaces, namespace);
238290 }
239291
240292 static const struct {
....@@ -268,16 +320,32 @@
268320 return export_unknown;
269321 }
270322
271
-static const char *sech_name(struct elf_info *elf, Elf_Shdr *sechdr)
323
+static void *sym_get_data_by_offset(const struct elf_info *info,
324
+ unsigned int secindex, unsigned long offset)
272325 {
273
- return (void *)elf->hdr +
274
- elf->sechdrs[elf->secindex_strings].sh_offset +
275
- sechdr->sh_name;
326
+ Elf_Shdr *sechdr = &info->sechdrs[secindex];
327
+
328
+ if (info->hdr->e_type != ET_REL)
329
+ offset -= sechdr->sh_addr;
330
+
331
+ return (void *)info->hdr + sechdr->sh_offset + offset;
276332 }
277333
278
-static const char *sec_name(struct elf_info *elf, int secindex)
334
+static void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym)
279335 {
280
- return sech_name(elf, &elf->sechdrs[secindex]);
336
+ return sym_get_data_by_offset(info, get_secindex(info, sym),
337
+ sym->st_value);
338
+}
339
+
340
+static const char *sech_name(const struct elf_info *info, Elf_Shdr *sechdr)
341
+{
342
+ return sym_get_data_by_offset(info, info->secindex_strings,
343
+ sechdr->sh_name);
344
+}
345
+
346
+static const char *sec_name(const struct elf_info *info, int secindex)
347
+{
348
+ return sech_name(info, &info->sechdrs[secindex]);
281349 }
282350
283351 #define strstarts(str, prefix) (strncmp(str, prefix, strlen(prefix)) == 0)
....@@ -316,6 +384,32 @@
316384 return export_unknown;
317385 }
318386
387
+static const char *namespace_from_kstrtabns(const struct elf_info *info,
388
+ const Elf_Sym *sym)
389
+{
390
+ const char *value = sym_get_data(info, sym);
391
+ return value[0] ? value : NULL;
392
+}
393
+
394
+static void sym_update_namespace(const char *symname, const char *namespace)
395
+{
396
+ struct symbol *s = find_symbol(symname);
397
+
398
+ /*
399
+ * That symbol should have been created earlier and thus this is
400
+ * actually an assertion.
401
+ */
402
+ if (!s) {
403
+ error("Could not update namespace(%s) for symbol %s\n",
404
+ namespace, symname);
405
+ return;
406
+ }
407
+
408
+ free(s->namespace);
409
+ s->namespace =
410
+ namespace && namespace[0] ? NOFAIL(strdup(namespace)) : NULL;
411
+}
412
+
319413 /**
320414 * Add an exported symbol - it may have already been added without a
321415 * CRC, in this case just update the CRC
....@@ -327,39 +421,34 @@
327421
328422 if (!s) {
329423 s = new_symbol(name, mod, export);
330
- } else {
331
- if (!s->preloaded) {
332
- warn("%s: '%s' exported twice. Previous export "
333
- "was in %s%s\n", mod->name, name,
334
- s->module->name,
335
- is_vmlinux(s->module->name) ?"":".ko");
336
- } else {
337
- /* In case Module.symvers was out of date */
338
- s->module = mod;
339
- }
424
+ } else if (!external_module || s->module->is_vmlinux ||
425
+ s->module == mod) {
426
+ fatal("%s: '%s' exported twice. Previous export was in %s%s\n",
427
+ mod->name, name, s->module->name,
428
+ s->module->is_vmlinux ? "" : ".ko");
340429 }
341
- s->preloaded = 0;
342
- s->vmlinux = is_vmlinux(mod->name);
343
- s->kernel = 0;
430
+
431
+ s->module = mod;
344432 s->export = export;
345433 return s;
346434 }
347435
348
-static void sym_update_crc(const char *name, struct module *mod,
349
- unsigned int crc, enum export export)
436
+static void sym_set_crc(const char *name, unsigned int crc)
350437 {
351438 struct symbol *s = find_symbol(name);
352439
353
- if (!s) {
354
- s = new_symbol(name, mod, export);
355
- /* Don't complain when we find it later. */
356
- s->preloaded = 1;
357
- }
440
+ /*
441
+ * Ignore stand-alone __crc_*, which might be auto-generated symbols
442
+ * such as __*_veneer in ARM ELF.
443
+ */
444
+ if (!s)
445
+ return;
446
+
358447 s->crc = crc;
359448 s->crc_valid = 1;
360449 }
361450
362
-void *grab_file(const char *filename, unsigned long *size)
451
+static void *grab_file(const char *filename, size_t *size)
363452 {
364453 struct stat st;
365454 void *map = MAP_FAILED;
....@@ -381,41 +470,7 @@
381470 return map;
382471 }
383472
384
-/**
385
- * Return a copy of the next line in a mmap'ed file.
386
- * spaces in the beginning of the line is trimmed away.
387
- * Return a pointer to a static buffer.
388
- **/
389
-char *get_next_line(unsigned long *pos, void *file, unsigned long size)
390
-{
391
- static char line[4096];
392
- int skip = 1;
393
- size_t len = 0;
394
- signed char *p = (signed char *)file + *pos;
395
- char *s = line;
396
-
397
- for (; *pos < size ; (*pos)++) {
398
- if (skip && isspace(*p)) {
399
- p++;
400
- continue;
401
- }
402
- skip = 0;
403
- if (*p != '\n' && (*pos < size)) {
404
- len++;
405
- *s++ = *p++;
406
- if (len > 4095)
407
- break; /* Too long, stop */
408
- } else {
409
- /* End of string */
410
- *s = '\0';
411
- return line;
412
- }
413
- }
414
- /* End of buffer */
415
- return NULL;
416
-}
417
-
418
-void release_file(void *file, unsigned long size)
473
+static void release_file(void *file, size_t size)
419474 {
420475 munmap(file, size);
421476 }
....@@ -471,9 +526,8 @@
471526
472527 /* Check if file offset is correct */
473528 if (hdr->e_shoff > info->size) {
474
- fatal("section header offset=%lu in file '%s' is bigger than "
475
- "filesize=%lu\n", (unsigned long)hdr->e_shoff,
476
- filename, info->size);
529
+ fatal("section header offset=%lu in file '%s' is bigger than filesize=%zu\n",
530
+ (unsigned long)hdr->e_shoff, filename, info->size);
477531 return 0;
478532 }
479533
....@@ -618,36 +672,40 @@
618672 return 0;
619673 }
620674
621
-static void handle_modversions(struct module *mod, struct elf_info *info,
622
- Elf_Sym *sym, const char *symname)
675
+static void handle_modversion(const struct module *mod,
676
+ const struct elf_info *info,
677
+ const Elf_Sym *sym, const char *symname)
623678 {
624679 unsigned int crc;
625
- enum export export;
626
- bool is_crc = false;
627680
628
- if ((!is_vmlinux(mod->name) || mod->is_dot_o) &&
629
- strstarts(symname, "__ksymtab"))
681
+ if (sym->st_shndx == SHN_UNDEF) {
682
+ warn("EXPORT symbol \"%s\" [%s%s] version generation failed, symbol will not be versioned.\n",
683
+ symname, mod->name, mod->is_vmlinux ? "" : ".ko");
684
+ return;
685
+ }
686
+
687
+ if (sym->st_shndx == SHN_ABS) {
688
+ crc = sym->st_value;
689
+ } else {
690
+ unsigned int *crcp;
691
+
692
+ /* symbol points to the CRC in the ELF object */
693
+ crcp = sym_get_data(info, sym);
694
+ crc = TO_NATIVE(*crcp);
695
+ }
696
+ sym_set_crc(symname, crc);
697
+}
698
+
699
+static void handle_symbol(struct module *mod, struct elf_info *info,
700
+ const Elf_Sym *sym, const char *symname)
701
+{
702
+ enum export export;
703
+ const char *name;
704
+
705
+ if (strstarts(symname, "__ksymtab"))
630706 export = export_from_secname(info, get_secindex(info, sym));
631707 else
632708 export = export_from_sec(info, get_secindex(info, sym));
633
-
634
- /* CRC'd symbol */
635
- if (strstarts(symname, "__crc_")) {
636
- is_crc = true;
637
- crc = (unsigned int) sym->st_value;
638
- if (sym->st_shndx != SHN_UNDEF && sym->st_shndx != SHN_ABS) {
639
- unsigned int *crcp;
640
-
641
- /* symbol points to the CRC in the ELF object */
642
- crcp = (void *)info->hdr + sym->st_value +
643
- info->sechdrs[sym->st_shndx].sh_offset -
644
- (info->hdr->e_type != ET_REL ?
645
- info->sechdrs[sym->st_shndx].sh_addr : 0);
646
- crc = TO_NATIVE(*crcp);
647
- }
648
- sym_update_crc(symname + strlen("__crc_"), mod, crc,
649
- export);
650
- }
651709
652710 switch (sym->st_shndx) {
653711 case SHN_COMMON:
....@@ -663,12 +721,6 @@
663721 break;
664722 if (ignore_undef_symbol(info, symname))
665723 break;
666
-/* cope with newer glibc (2.3.4 or higher) STT_ definition in elf.h */
667
-#if defined(STT_REGISTER) || defined(STT_SPARC_REGISTER)
668
-/* add compatibility with older glibc */
669
-#ifndef STT_SPARC_REGISTER
670
-#define STT_SPARC_REGISTER STT_REGISTER
671
-#endif
672724 if (info->hdr->e_machine == EM_SPARC ||
673725 info->hdr->e_machine == EM_SPARCV9) {
674726 /* Ignore register directives. */
....@@ -681,13 +733,7 @@
681733 symname = munged;
682734 }
683735 }
684
-#endif
685736
686
- if (is_crc) {
687
- const char *e = is_vmlinux(mod->name) ?"":".ko";
688
- warn("EXPORT symbol \"%s\" [%s%s] version generation failed, symbol will not be versioned.\n",
689
- symname + strlen("__crc_"), mod->name, e);
690
- }
691737 mod->unres = alloc_symbol(symname,
692738 ELF_ST_BIND(sym->st_info) == STB_WEAK,
693739 mod->unres);
....@@ -695,8 +741,8 @@
695741 default:
696742 /* All exported symbols */
697743 if (strstarts(symname, "__ksymtab_")) {
698
- sym_add_exported(symname + strlen("__ksymtab_"), mod,
699
- export);
744
+ name = symname + strlen("__ksymtab_");
745
+ sym_add_exported(name, mod, export);
700746 }
701747 if (strcmp(symname, "init_module") == 0)
702748 mod->has_init = 1;
....@@ -799,9 +845,9 @@
799845
800846 /* "*foo*" */
801847 if (*p == '*' && *endp == '*') {
802
- char *here, *bare = strndup(p + 1, strlen(p) - 2);
848
+ char *bare = NOFAIL(strndup(p + 1, strlen(p) - 2));
849
+ char *here = strstr(sym, bare);
803850
804
- here = strstr(sym, bare);
805851 free(bare);
806852 if (here != NULL)
807853 return 1;
....@@ -945,7 +991,6 @@
945991 static const char *const linker_symbols[] =
946992 { "__init_begin", "_sinittext", "_einittext", NULL };
947993 static const char *const optim_symbols[] = { "*.constprop.*", NULL };
948
-static const char *const cfi_symbols[] = { "*.cfi", NULL };
949994
950995 enum mismatch {
951996 TEXT_TO_ANY_INIT,
....@@ -1070,7 +1115,7 @@
10701115 },
10711116 /* Do not export init/exit functions or data */
10721117 {
1073
- .fromsec = { "__ksymtab*", NULL },
1118
+ .fromsec = { "___ksymtab*", NULL },
10741119 .bad_tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
10751120 .mismatch = EXPORT_TO_INIT_EXIT,
10761121 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
....@@ -1175,17 +1220,6 @@
11751220 * whitelisting, which relies on pattern-matching against symbol
11761221 * names to work. (One situation where gcc can autogenerate ELF
11771222 * local symbols is when "-fsection-anchors" is used.)
1178
- *
1179
- * Pattern 7:
1180
- * With CONFIG_CFI_CLANG, clang appends .cfi to all indirectly called
1181
- * functions and creates a function stub with the original name. This
1182
- * stub is always placed in .text, even if the actual function with the
1183
- * .cfi postfix is in .init.text or .exit.text.
1184
- * This pattern is identified by
1185
- * tosec = init or exit section
1186
- * fromsec = text section
1187
- * tosym = *.cfi
1188
- *
11891223 **/
11901224 static int secref_whitelist(const struct sectioncheck *mismatch,
11911225 const char *fromsec, const char *fromsym,
....@@ -1228,18 +1262,13 @@
12281262 if (strstarts(fromsym, ".L"))
12291263 return 0;
12301264
1231
- /* Check for pattern 7 */
1232
- if (match(fromsec, text_sections) &&
1233
- match(tosec, init_exit_sections) &&
1234
- match(tosym, cfi_symbols))
1235
- return 0;
1236
-
12371265 return 1;
12381266 }
12391267
12401268 static inline int is_arm_mapping_symbol(const char *str)
12411269 {
1242
- return str[0] == '$' && strchr("axtd", str[1])
1270
+ return str[0] == '$' &&
1271
+ (str[1] == 'a' || str[1] == 'd' || str[1] == 't' || str[1] == 'x')
12431272 && (str[2] == '\0' || str[2] == '.');
12441273 }
12451274
....@@ -1427,8 +1456,6 @@
14271456 char *prl_to;
14281457
14291458 sec_mismatch_count++;
1430
- if (!sec_mismatch_verbose)
1431
- return;
14321459
14331460 get_pretty_name(from_is_func, &from, &from_p);
14341461 get_pretty_name(to_is_func, &to, &to_p);
....@@ -1676,9 +1703,7 @@
16761703
16771704 sec_mismatch_count++;
16781705
1679
- if (sec_mismatch_verbose)
1680
- report_extable_warnings(modname, elf, mismatch, r, sym,
1681
- fromsec, tosec);
1706
+ report_extable_warnings(modname, elf, mismatch, r, sym, fromsec, tosec);
16821707
16831708 if (match(tosec, mismatch->bad_tosec))
16841709 fatal("The relocation at %s+0x%lx references\n"
....@@ -1724,11 +1749,7 @@
17241749 static unsigned int *reloc_location(struct elf_info *elf,
17251750 Elf_Shdr *sechdr, Elf_Rela *r)
17261751 {
1727
- Elf_Shdr *sechdrs = elf->sechdrs;
1728
- int section = sechdr->sh_info;
1729
-
1730
- return (void *)elf->hdr + sechdrs[section].sh_offset +
1731
- r->r_offset;
1752
+ return sym_get_data_by_offset(elf, sechdr->sh_info, r->r_offset);
17321753 }
17331754
17341755 static int addend_386_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
....@@ -1958,7 +1979,7 @@
19581979
19591980 if (n && s[n]) {
19601981 size_t m = strspn(s + n + 1, "0123456789");
1961
- if (m && (s[n + m] == '.' || s[n + m] == 0))
1982
+ if (m && (s[n + m + 1] == '.' || s[n + m + 1] == 0))
19621983 s[n] = 0;
19631984
19641985 /* strip trailing .lto */
....@@ -1973,6 +1994,7 @@
19731994 const char *symname;
19741995 char *version;
19751996 char *license;
1997
+ char *namespace;
19761998 struct module *mod;
19771999 struct elf_info info = { };
19782000 Elf_Sym *sym;
....@@ -1980,46 +2002,84 @@
19802002 if (!parse_elf(&info, modname))
19812003 return;
19822004
1983
- mod = new_module(modname);
2005
+ {
2006
+ char *tmp;
19842007
1985
- /* When there's no vmlinux, don't print warnings about
1986
- * unresolved symbols (since there'll be too many ;) */
1987
- if (is_vmlinux(modname)) {
1988
- have_vmlinux = 1;
1989
- mod->skip = 1;
2008
+ /* strip trailing .o */
2009
+ tmp = NOFAIL(strdup(modname));
2010
+ tmp[strlen(tmp) - 2] = '\0';
2011
+ /* strip trailing .lto */
2012
+ if (strends(tmp, ".lto"))
2013
+ tmp[strlen(tmp) - 4] = '\0';
2014
+ mod = new_module(tmp);
2015
+ free(tmp);
19902016 }
19912017
1992
- license = get_modinfo(&info, "license");
1993
- if (!license && !is_vmlinux(modname))
1994
- warn("modpost: missing MODULE_LICENSE() in %s\n"
1995
- "see include/linux/module.h for "
1996
- "more information\n", modname);
1997
- while (license) {
1998
- if (license_is_gpl_compatible(license))
1999
- mod->gpl_compatible = 1;
2000
- else {
2001
- mod->gpl_compatible = 0;
2002
- break;
2018
+ if (!mod->is_vmlinux) {
2019
+ license = get_modinfo(&info, "license");
2020
+ if (!license)
2021
+ error("missing MODULE_LICENSE() in %s\n", modname);
2022
+ while (license) {
2023
+ if (license_is_gpl_compatible(license))
2024
+ mod->gpl_compatible = 1;
2025
+ else {
2026
+ mod->gpl_compatible = 0;
2027
+ break;
2028
+ }
2029
+ license = get_next_modinfo(&info, "license", license);
20032030 }
2004
- license = get_next_modinfo(&info, "license", license);
2031
+
2032
+ namespace = get_modinfo(&info, "import_ns");
2033
+ while (namespace) {
2034
+ add_namespace(&mod->imported_namespaces, namespace);
2035
+ namespace = get_next_modinfo(&info, "import_ns",
2036
+ namespace);
2037
+ }
20052038 }
20062039
20072040 for (sym = info.symtab_start; sym < info.symtab_stop; sym++) {
20082041 symname = remove_dot(info.strtab + sym->st_name);
20092042
2010
- handle_modversions(mod, &info, sym, symname);
2043
+ handle_symbol(mod, &info, sym, symname);
20112044 handle_moddevtable(mod, &info, sym, symname);
20122045 }
2013
- if (!is_vmlinux(modname) || vmlinux_section_warnings)
2014
- check_sec_ref(mod, modname, &info);
20152046
2016
- version = get_modinfo(&info, "version");
2017
- if (version)
2018
- maybe_frob_rcs_version(modname, version, info.modinfo,
2019
- version - (char *)info.hdr);
2020
- if (version || (all_versions && !is_vmlinux(modname)))
2021
- get_src_version(modname, mod->srcversion,
2022
- sizeof(mod->srcversion)-1);
2047
+ for (sym = info.symtab_start; sym < info.symtab_stop; sym++) {
2048
+ symname = remove_dot(info.strtab + sym->st_name);
2049
+
2050
+ /* Apply symbol namespaces from __kstrtabns_<symbol> entries. */
2051
+ if (strstarts(symname, "__kstrtabns_"))
2052
+ sym_update_namespace(symname + strlen("__kstrtabns_"),
2053
+ namespace_from_kstrtabns(&info,
2054
+ sym));
2055
+
2056
+ if (strstarts(symname, "__crc_"))
2057
+ handle_modversion(mod, &info, sym,
2058
+ symname + strlen("__crc_"));
2059
+ }
2060
+
2061
+ // check for static EXPORT_SYMBOL_* functions && global vars
2062
+ for (sym = info.symtab_start; sym < info.symtab_stop; sym++) {
2063
+ unsigned char bind = ELF_ST_BIND(sym->st_info);
2064
+
2065
+ if (bind == STB_GLOBAL || bind == STB_WEAK) {
2066
+ struct symbol *s =
2067
+ find_symbol(remove_dot(info.strtab +
2068
+ sym->st_name));
2069
+
2070
+ if (s)
2071
+ s->is_static = 0;
2072
+ }
2073
+ }
2074
+
2075
+ check_sec_ref(mod, modname, &info);
2076
+
2077
+ if (!mod->is_vmlinux) {
2078
+ version = get_modinfo(&info, "version");
2079
+ if (version || all_versions)
2080
+ get_src_version(modname, mod->srcversion,
2081
+ sizeof(mod->srcversion) - 1);
2082
+ }
20232083
20242084 parse_elf_finish(&info);
20252085
....@@ -2083,20 +2143,18 @@
20832143
20842144 static void check_for_gpl_usage(enum export exp, const char *m, const char *s)
20852145 {
2086
- const char *e = is_vmlinux(m) ?"":".ko";
2087
-
20882146 switch (exp) {
20892147 case export_gpl:
2090
- fatal("modpost: GPL-incompatible module %s%s "
2091
- "uses GPL-only symbol '%s'\n", m, e, s);
2148
+ error("GPL-incompatible module %s.ko uses GPL-only symbol '%s'\n",
2149
+ m, s);
20922150 break;
20932151 case export_unused_gpl:
2094
- fatal("modpost: GPL-incompatible module %s%s "
2095
- "uses GPL-only symbol marked UNUSED '%s'\n", m, e, s);
2152
+ error("GPL-incompatible module %s.ko uses GPL-only symbol marked UNUSED '%s'\n",
2153
+ m, s);
20962154 break;
20972155 case export_gpl_future:
2098
- warn("modpost: GPL-incompatible module %s%s "
2099
- "uses future GPL-only symbol '%s'\n", m, e, s);
2156
+ warn("GPL-incompatible module %s.ko uses future GPL-only symbol '%s'\n",
2157
+ m, s);
21002158 break;
21012159 case export_plain:
21022160 case export_unused:
....@@ -2108,13 +2166,11 @@
21082166
21092167 static void check_for_unused(enum export exp, const char *m, const char *s)
21102168 {
2111
- const char *e = is_vmlinux(m) ?"":".ko";
2112
-
21132169 switch (exp) {
21142170 case export_unused:
21152171 case export_unused_gpl:
2116
- warn("modpost: module %s%s "
2117
- "uses symbol '%s' marked UNUSED\n", m, e, s);
2172
+ warn("module %s.ko uses symbol '%s' marked UNUSED\n",
2173
+ m, s);
21182174 break;
21192175 default:
21202176 /* ignore */
....@@ -2129,20 +2185,34 @@
21292185 for (s = mod->unres; s; s = s->next) {
21302186 const char *basename;
21312187 exp = find_symbol(s->name);
2132
- if (!exp || exp->module == mod)
2188
+ if (!exp || exp->module == mod) {
2189
+ if (have_vmlinux && !s->weak)
2190
+ modpost_log(warn_unresolved ? LOG_WARN : LOG_ERROR,
2191
+ "\"%s\" [%s.ko] undefined!\n",
2192
+ s->name, mod->name);
21332193 continue;
2194
+ }
21342195 basename = strrchr(mod->name, '/');
21352196 if (basename)
21362197 basename++;
21372198 else
21382199 basename = mod->name;
2200
+
2201
+ if (exp->namespace &&
2202
+ !module_imports_namespace(mod, exp->namespace)) {
2203
+ modpost_log(allow_missing_ns_imports ? LOG_WARN : LOG_ERROR,
2204
+ "module %s uses symbol %s from namespace %s, but does not import it.\n",
2205
+ basename, exp->name, exp->namespace);
2206
+ add_namespace(&mod->missing_namespaces, exp->namespace);
2207
+ }
2208
+
21392209 if (!mod->gpl_compatible)
21402210 check_for_gpl_usage(exp->export, basename, exp->name);
21412211 check_for_unused(exp->export, basename, exp->name);
21422212 }
21432213 }
21442214
2145
-static int check_modname_len(struct module *mod)
2215
+static void check_modname_len(struct module *mod)
21462216 {
21472217 const char *mod_name;
21482218
....@@ -2151,12 +2221,8 @@
21512221 mod_name = mod->name;
21522222 else
21532223 mod_name++;
2154
- if (strlen(mod_name) >= MODULE_NAME_LEN) {
2155
- merror("module name is too long [%s.ko]\n", mod->name);
2156
- return 1;
2157
- }
2158
-
2159
- return 0;
2224
+ if (strlen(mod_name) >= MODULE_NAME_LEN)
2225
+ error("module name is too long [%s.ko]\n", mod->name);
21602226 }
21612227
21622228 /**
....@@ -2169,6 +2235,7 @@
21692235 * Include build-salt.h after module.h in order to
21702236 * inherit the definitions.
21712237 */
2238
+ buf_printf(b, "#define INCLUDE_VERMAGIC\n");
21722239 buf_printf(b, "#include <linux/build-salt.h>\n");
21732240 buf_printf(b, "#include <linux/vermagic.h>\n");
21742241 buf_printf(b, "#include <linux/compiler.h>\n");
....@@ -2179,7 +2246,7 @@
21792246 buf_printf(b, "MODULE_INFO(name, KBUILD_MODNAME);\n");
21802247 buf_printf(b, "\n");
21812248 buf_printf(b, "__visible struct module __this_module\n");
2182
- buf_printf(b, "__attribute__((section(\".gnu.linkonce.this_module\"))) = {\n");
2249
+ buf_printf(b, "__section(\".gnu.linkonce.this_module\") = {\n");
21832250 buf_printf(b, "\t.name = KBUILD_MODNAME,\n");
21842251 if (mod->has_init)
21852252 buf_printf(b, "\t.init = init_module,\n");
....@@ -2195,6 +2262,20 @@
21952262 {
21962263 if (is_intree)
21972264 buf_printf(b, "\nMODULE_INFO(intree, \"Y\");\n");
2265
+}
2266
+
2267
+/**
2268
+ * add_scmversion() - Adds the MODULE_INFO macro for the scmversion.
2269
+ * @b: Buffer to append to.
2270
+ *
2271
+ * This function fills in the module attribute `scmversion` for the kernel
2272
+ * module. This is useful for determining a given module's SCM version on
2273
+ * device via /sys/modules/<module>/scmversion and/or using the modinfo tool.
2274
+ */
2275
+static void add_scmversion(struct buffer *b)
2276
+{
2277
+ if (module_scmversion[0] != '\0')
2278
+ buf_printf(b, "\nMODULE_INFO(scmversion, \"%s\");\n", module_scmversion);
21982279 }
21992280
22002281 /* Cannot check for assembler */
....@@ -2214,38 +2295,25 @@
22142295 /**
22152296 * Record CRCs for unresolved symbols
22162297 **/
2217
-static int add_versions(struct buffer *b, struct module *mod)
2298
+static void add_versions(struct buffer *b, struct module *mod)
22182299 {
22192300 struct symbol *s, *exp;
2220
- int err = 0;
22212301
22222302 for (s = mod->unres; s; s = s->next) {
22232303 exp = find_symbol(s->name);
2224
- if (!exp || exp->module == mod) {
2225
- if (have_vmlinux && !s->weak) {
2226
- if (warn_unresolved) {
2227
- warn("\"%s\" [%s.ko] undefined!\n",
2228
- s->name, mod->name);
2229
- } else {
2230
- merror("\"%s\" [%s.ko] undefined!\n",
2231
- s->name, mod->name);
2232
- err = 1;
2233
- }
2234
- }
2304
+ if (!exp || exp->module == mod)
22352305 continue;
2236
- }
22372306 s->module = exp->module;
22382307 s->crc_valid = exp->crc_valid;
22392308 s->crc = exp->crc;
22402309 }
22412310
22422311 if (!modversions)
2243
- return err;
2312
+ return;
22442313
22452314 buf_printf(b, "\n");
22462315 buf_printf(b, "static const struct modversion_info ____versions[]\n");
2247
- buf_printf(b, "__used\n");
2248
- buf_printf(b, "__attribute__((section(\"__versions\"))) = {\n");
2316
+ buf_printf(b, "__used __section(\"__versions\") = {\n");
22492317
22502318 for (s = mod->unres; s; s = s->next) {
22512319 if (!s->module)
....@@ -2256,9 +2324,8 @@
22562324 continue;
22572325 }
22582326 if (strlen(s->name) >= MODULE_NAME_LEN) {
2259
- merror("too long symbol \"%s\" [%s.ko]\n",
2260
- s->name, mod->name);
2261
- err = 1;
2327
+ error("too long symbol \"%s\" [%s.ko]\n",
2328
+ s->name, mod->name);
22622329 break;
22632330 }
22642331 buf_printf(b, "\t{ %#8x, \"%s\" },\n",
....@@ -2266,25 +2333,20 @@
22662333 }
22672334
22682335 buf_printf(b, "};\n");
2269
-
2270
- return err;
22712336 }
22722337
2273
-static void add_depends(struct buffer *b, struct module *mod,
2274
- struct module *modules)
2338
+static void add_depends(struct buffer *b, struct module *mod)
22752339 {
22762340 struct symbol *s;
2277
- struct module *m;
22782341 int first = 1;
22792342
2280
- for (m = modules; m; m = m->next)
2281
- m->seen = is_vmlinux(m->name);
2343
+ /* Clear ->seen flag of modules that own symbols needed by this. */
2344
+ for (s = mod->unres; s; s = s->next)
2345
+ if (s->module)
2346
+ s->module->seen = s->module->is_vmlinux;
22822347
22832348 buf_printf(b, "\n");
2284
- buf_printf(b, "static const char __module_depends[]\n");
2285
- buf_printf(b, "__used\n");
2286
- buf_printf(b, "__attribute__((section(\".modinfo\"))) =\n");
2287
- buf_printf(b, "\"depends=");
2349
+ buf_printf(b, "MODULE_INFO(depends, \"");
22882350 for (s = mod->unres; s; s = s->next) {
22892351 const char *p;
22902352 if (!s->module)
....@@ -2302,7 +2364,7 @@
23022364 buf_printf(b, "%s%s", first ? "" : ",", p);
23032365 first = 0;
23042366 }
2305
- buf_printf(b, "\";\n");
2367
+ buf_printf(b, "\");\n");
23062368 }
23072369
23082370 static void add_srcversion(struct buffer *b, struct module *mod)
....@@ -2311,6 +2373,25 @@
23112373 buf_printf(b, "\n");
23122374 buf_printf(b, "MODULE_INFO(srcversion, \"%s\");\n",
23132375 mod->srcversion);
2376
+ }
2377
+}
2378
+
2379
+static void write_buf(struct buffer *b, const char *fname)
2380
+{
2381
+ FILE *file;
2382
+
2383
+ file = fopen(fname, "w");
2384
+ if (!file) {
2385
+ perror(fname);
2386
+ exit(1);
2387
+ }
2388
+ if (fwrite(b->p, 1, b->pos, file) != b->pos) {
2389
+ perror(fname);
2390
+ exit(1);
2391
+ }
2392
+ if (fclose(file) != 0) {
2393
+ perror(fname);
2394
+ exit(1);
23142395 }
23152396 }
23162397
....@@ -2346,33 +2427,25 @@
23462427 close_write:
23472428 fclose(file);
23482429 write:
2349
- file = fopen(fname, "w");
2350
- if (!file) {
2351
- perror(fname);
2352
- exit(1);
2353
- }
2354
- if (fwrite(b->p, 1, b->pos, file) != b->pos) {
2355
- perror(fname);
2356
- exit(1);
2357
- }
2358
- fclose(file);
2430
+ write_buf(b, fname);
23592431 }
23602432
23612433 /* parse Module.symvers file. line format:
2362
- * 0x12345678<tab>symbol<tab>module[[<tab>export]<tab>something]
2434
+ * 0x12345678<tab>symbol<tab>module<tab>export<tab>namespace
23632435 **/
2364
-static void read_dump(const char *fname, unsigned int kernel)
2436
+static void read_dump(const char *fname)
23652437 {
2366
- unsigned long size, pos = 0;
2367
- void *file = grab_file(fname, &size);
2368
- char *line;
2438
+ char *buf, *pos, *line;
23692439
2370
- if (!file)
2440
+ buf = read_text_file(fname);
2441
+ if (!buf)
23712442 /* No symbol versions, silently ignore */
23722443 return;
23732444
2374
- while ((line = get_next_line(&pos, file, size))) {
2375
- char *symname, *modname, *d, *export, *end;
2445
+ pos = buf;
2446
+
2447
+ while ((line = get_line(&pos))) {
2448
+ char *symname, *namespace, *modname, *d, *export;
23762449 unsigned int crc;
23772450 struct module *mod;
23782451 struct symbol *s;
....@@ -2383,68 +2456,83 @@
23832456 if (!(modname = strchr(symname, '\t')))
23842457 goto fail;
23852458 *modname++ = '\0';
2386
- if ((export = strchr(modname, '\t')) != NULL)
2387
- *export++ = '\0';
2388
- if (export && ((end = strchr(export, '\t')) != NULL))
2389
- *end = '\0';
2459
+ if (!(export = strchr(modname, '\t')))
2460
+ goto fail;
2461
+ *export++ = '\0';
2462
+ if (!(namespace = strchr(export, '\t')))
2463
+ goto fail;
2464
+ *namespace++ = '\0';
2465
+
23902466 crc = strtoul(line, &d, 16);
23912467 if (*symname == '\0' || *modname == '\0' || *d != '\0')
23922468 goto fail;
23932469 mod = find_module(modname);
23942470 if (!mod) {
2395
- if (is_vmlinux(modname))
2396
- have_vmlinux = 1;
23972471 mod = new_module(modname);
2398
- mod->skip = 1;
2472
+ mod->from_dump = 1;
23992473 }
24002474 s = sym_add_exported(symname, mod, export_no(export));
2401
- s->kernel = kernel;
2402
- s->preloaded = 1;
2403
- sym_update_crc(symname, mod, crc, export_no(export));
2475
+ s->is_static = 0;
2476
+ sym_set_crc(symname, crc);
2477
+ sym_update_namespace(symname, namespace);
24042478 }
2405
- release_file(file, size);
2479
+ free(buf);
24062480 return;
24072481 fail:
2408
- release_file(file, size);
2482
+ free(buf);
24092483 fatal("parse error in symbol dump file\n");
2410
-}
2411
-
2412
-/* For normal builds always dump all symbols.
2413
- * For external modules only dump symbols
2414
- * that are not read from kernel Module.symvers.
2415
- **/
2416
-static int dump_sym(struct symbol *sym)
2417
-{
2418
- if (!external_module)
2419
- return 1;
2420
- if (sym->vmlinux || sym->kernel)
2421
- return 0;
2422
- return 1;
24232484 }
24242485
24252486 static void write_dump(const char *fname)
24262487 {
24272488 struct buffer buf = { };
24282489 struct symbol *symbol;
2490
+ const char *namespace;
24292491 int n;
24302492
24312493 for (n = 0; n < SYMBOL_HASH_SIZE ; n++) {
24322494 symbol = symbolhash[n];
24332495 while (symbol) {
2434
- if (dump_sym(symbol))
2435
- buf_printf(&buf, "0x%08x\t%s\t%s\t%s\n",
2436
- symbol->crc, symbol->name,
2437
- symbol->module->name,
2438
- export_str(symbol->export));
2496
+ if (!symbol->module->from_dump) {
2497
+ namespace = symbol->namespace;
2498
+ buf_printf(&buf, "0x%08x\t%s\t%s\t%s\t%s\n",
2499
+ symbol->crc, symbol->name,
2500
+ symbol->module->name,
2501
+ export_str(symbol->export),
2502
+ namespace ? namespace : "");
2503
+ }
24392504 symbol = symbol->next;
24402505 }
24412506 }
2442
- write_if_changed(&buf, fname);
2507
+ write_buf(&buf, fname);
24432508 free(buf.p);
24442509 }
24452510
2446
-struct ext_sym_list {
2447
- struct ext_sym_list *next;
2511
+static void write_namespace_deps_files(const char *fname)
2512
+{
2513
+ struct module *mod;
2514
+ struct namespace_list *ns;
2515
+ struct buffer ns_deps_buf = {};
2516
+
2517
+ for (mod = modules; mod; mod = mod->next) {
2518
+
2519
+ if (mod->from_dump || !mod->missing_namespaces)
2520
+ continue;
2521
+
2522
+ buf_printf(&ns_deps_buf, "%s.ko:", mod->name);
2523
+
2524
+ for (ns = mod->missing_namespaces; ns; ns = ns->next)
2525
+ buf_printf(&ns_deps_buf, " %s", ns->namespace);
2526
+
2527
+ buf_printf(&ns_deps_buf, "\n");
2528
+ }
2529
+
2530
+ write_if_changed(&ns_deps_buf, fname);
2531
+ free(ns_deps_buf.p);
2532
+}
2533
+
2534
+struct dump_list {
2535
+ struct dump_list *next;
24482536 const char *file;
24492537 };
24502538
....@@ -2452,29 +2540,23 @@
24522540 {
24532541 struct module *mod;
24542542 struct buffer buf = { };
2455
- char *kernel_read = NULL, *module_read = NULL;
2543
+ char *missing_namespace_deps = NULL;
24562544 char *dump_write = NULL, *files_source = NULL;
24572545 int opt;
2458
- int err;
2459
- struct ext_sym_list *extsym_iter;
2460
- struct ext_sym_list *extsym_start = NULL;
2546
+ int n;
2547
+ struct dump_list *dump_read_start = NULL;
2548
+ struct dump_list **dump_read_iter = &dump_read_start;
24612549
2462
- while ((opt = getopt(argc, argv, "i:I:e:mnsST:o:awM:K:E")) != -1) {
2550
+ while ((opt = getopt(argc, argv, "ei:mnT:o:awENd:v:")) != -1) {
24632551 switch (opt) {
2464
- case 'i':
2465
- kernel_read = optarg;
2466
- break;
2467
- case 'I':
2468
- module_read = optarg;
2469
- external_module = 1;
2470
- break;
24712552 case 'e':
24722553 external_module = 1;
2473
- extsym_iter =
2474
- NOFAIL(malloc(sizeof(*extsym_iter)));
2475
- extsym_iter->next = extsym_start;
2476
- extsym_iter->file = optarg;
2477
- extsym_start = extsym_iter;
2554
+ break;
2555
+ case 'i':
2556
+ *dump_read_iter =
2557
+ NOFAIL(calloc(1, sizeof(**dump_read_iter)));
2558
+ (*dump_read_iter)->file = optarg;
2559
+ dump_read_iter = &(*dump_read_iter)->next;
24782560 break;
24792561 case 'm':
24802562 modversions = 1;
....@@ -2488,12 +2570,6 @@
24882570 case 'a':
24892571 all_versions = 1;
24902572 break;
2491
- case 's':
2492
- vmlinux_section_warnings = 0;
2493
- break;
2494
- case 'S':
2495
- sec_mismatch_verbose = 0;
2496
- break;
24972573 case 'T':
24982574 files_source = optarg;
24992575 break;
....@@ -2501,22 +2577,29 @@
25012577 warn_unresolved = 1;
25022578 break;
25032579 case 'E':
2504
- sec_mismatch_fatal = 1;
2580
+ sec_mismatch_warn_only = false;
2581
+ break;
2582
+ case 'N':
2583
+ allow_missing_ns_imports = 1;
2584
+ break;
2585
+ case 'd':
2586
+ missing_namespace_deps = optarg;
2587
+ break;
2588
+ case 'v':
2589
+ strncpy(module_scmversion, optarg, sizeof(module_scmversion) - 1);
25052590 break;
25062591 default:
25072592 exit(1);
25082593 }
25092594 }
25102595
2511
- if (kernel_read)
2512
- read_dump(kernel_read, 1);
2513
- if (module_read)
2514
- read_dump(module_read, 0);
2515
- while (extsym_start) {
2516
- read_dump(extsym_start->file, 0);
2517
- extsym_iter = extsym_start->next;
2518
- free(extsym_start);
2519
- extsym_start = extsym_iter;
2596
+ while (dump_read_start) {
2597
+ struct dump_list *tmp;
2598
+
2599
+ read_dump(dump_read_start->file);
2600
+ tmp = dump_read_start->next;
2601
+ free(dump_read_start);
2602
+ dump_read_start = tmp;
25202603 }
25212604
25222605 while (optind < argc)
....@@ -2525,50 +2608,58 @@
25252608 if (files_source)
25262609 read_symbols_from_files(files_source);
25272610
2528
- for (mod = modules; mod; mod = mod->next) {
2529
- if (mod->skip)
2530
- continue;
2531
- check_exports(mod);
2532
- }
2533
-
2534
- err = 0;
2611
+ /*
2612
+ * When there's no vmlinux, don't print warnings about
2613
+ * unresolved symbols (since there'll be too many ;)
2614
+ */
2615
+ if (!have_vmlinux)
2616
+ warn("Symbol info of vmlinux is missing. Unresolved symbol check will be entirely skipped.\n");
25352617
25362618 for (mod = modules; mod; mod = mod->next) {
25372619 char fname[PATH_MAX];
25382620
2539
- if (mod->skip)
2621
+ if (mod->is_vmlinux || mod->from_dump)
25402622 continue;
25412623
25422624 buf.pos = 0;
25432625
2544
- err |= check_modname_len(mod);
2626
+ check_modname_len(mod);
2627
+ check_exports(mod);
2628
+
25452629 add_header(&buf, mod);
25462630 add_intree_flag(&buf, !external_module);
25472631 add_retpoline(&buf);
25482632 add_staging_flag(&buf, mod->name);
2549
- err |= add_versions(&buf, mod);
2550
- add_depends(&buf, mod, modules);
2633
+ add_versions(&buf, mod);
2634
+ add_depends(&buf, mod);
25512635 add_moddevtable(&buf, mod);
25522636 add_srcversion(&buf, mod);
2637
+ add_scmversion(&buf);
25532638
25542639 sprintf(fname, "%s.mod.c", mod->name);
25552640 write_if_changed(&buf, fname);
25562641 }
2642
+
2643
+ if (missing_namespace_deps)
2644
+ write_namespace_deps_files(missing_namespace_deps);
2645
+
25572646 if (dump_write)
25582647 write_dump(dump_write);
2559
- if (sec_mismatch_count) {
2560
- if (!sec_mismatch_verbose) {
2561
- warn("modpost: Found %d section mismatch(es).\n"
2562
- "To see full details build your kernel with:\n"
2563
- "'make CONFIG_DEBUG_SECTION_MISMATCH=y'\n",
2564
- sec_mismatch_count);
2565
- }
2566
- if (sec_mismatch_fatal) {
2567
- fatal("modpost: Section mismatches detected.\n"
2568
- "Set CONFIG_SECTION_MISMATCH_WARN_ONLY=y to allow them.\n");
2648
+ if (sec_mismatch_count && !sec_mismatch_warn_only)
2649
+ error("Section mismatches detected.\n"
2650
+ "Set CONFIG_SECTION_MISMATCH_WARN_ONLY=y to allow them.\n");
2651
+ for (n = 0; n < SYMBOL_HASH_SIZE; n++) {
2652
+ struct symbol *s;
2653
+
2654
+ for (s = symbolhash[n]; s; s = s->next) {
2655
+ if (s->is_static)
2656
+ error("\"%s\" [%s] is a static %s\n",
2657
+ s->name, s->module->name,
2658
+ export_str(s->export));
25692659 }
25702660 }
2661
+
25712662 free(buf.p);
25722663
2573
- return err;
2664
+ return error_occurred ? 1 : 0;
25742665 }