hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
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
....@@ -1280,6 +1309,10 @@
12801309 if (relsym->st_name != 0)
12811310 return relsym;
12821311
1312
+ /*
1313
+ * Strive to find a better symbol name, but the resulting name may not
1314
+ * match the symbol referenced in the original code.
1315
+ */
12831316 relsym_secindex = get_secindex(elf, relsym);
12841317 for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) {
12851318 if (get_secindex(elf, sym) != relsym_secindex)
....@@ -1427,8 +1460,6 @@
14271460 char *prl_to;
14281461
14291462 sec_mismatch_count++;
1430
- if (!sec_mismatch_verbose)
1431
- return;
14321463
14331464 get_pretty_name(from_is_func, &from, &from_p);
14341465 get_pretty_name(to_is_func, &to, &to_p);
....@@ -1586,7 +1617,7 @@
15861617
15871618 static int is_executable_section(struct elf_info* elf, unsigned int section_index)
15881619 {
1589
- if (section_index > elf->num_sections)
1620
+ if (section_index >= elf->num_sections)
15901621 fatal("section_index is outside elf->num_sections!\n");
15911622
15921623 return ((elf->sechdrs[section_index].sh_flags & SHF_EXECINSTR) == SHF_EXECINSTR);
....@@ -1676,9 +1707,7 @@
16761707
16771708 sec_mismatch_count++;
16781709
1679
- if (sec_mismatch_verbose)
1680
- report_extable_warnings(modname, elf, mismatch, r, sym,
1681
- fromsec, tosec);
1710
+ report_extable_warnings(modname, elf, mismatch, r, sym, fromsec, tosec);
16821711
16831712 if (match(tosec, mismatch->bad_tosec))
16841713 fatal("The relocation at %s+0x%lx references\n"
....@@ -1724,11 +1753,7 @@
17241753 static unsigned int *reloc_location(struct elf_info *elf,
17251754 Elf_Shdr *sechdr, Elf_Rela *r)
17261755 {
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;
1756
+ return sym_get_data_by_offset(elf, sechdr->sh_info, r->r_offset);
17321757 }
17331758
17341759 static int addend_386_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
....@@ -1767,19 +1792,33 @@
17671792 #define R_ARM_THM_JUMP19 51
17681793 #endif
17691794
1795
+static int32_t sign_extend32(int32_t value, int index)
1796
+{
1797
+ uint8_t shift = 31 - index;
1798
+
1799
+ return (int32_t)(value << shift) >> shift;
1800
+}
1801
+
17701802 static int addend_arm_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
17711803 {
17721804 unsigned int r_typ = ELF_R_TYPE(r->r_info);
1805
+ Elf_Sym *sym = elf->symtab_start + ELF_R_SYM(r->r_info);
1806
+ void *loc = reloc_location(elf, sechdr, r);
1807
+ uint32_t inst;
1808
+ int32_t offset;
17731809
17741810 switch (r_typ) {
17751811 case R_ARM_ABS32:
1776
- /* From ARM ABI: (S + A) | T */
1777
- r->r_addend = (int)(long)
1778
- (elf->symtab_start + ELF_R_SYM(r->r_info));
1812
+ inst = TO_NATIVE(*(uint32_t *)loc);
1813
+ r->r_addend = inst + sym->st_value;
17791814 break;
17801815 case R_ARM_PC24:
17811816 case R_ARM_CALL:
17821817 case R_ARM_JUMP24:
1818
+ inst = TO_NATIVE(*(uint32_t *)loc);
1819
+ offset = sign_extend32((inst & 0x00ffffff) << 2, 25);
1820
+ r->r_addend = offset + sym->st_value + 8;
1821
+ break;
17831822 case R_ARM_THM_CALL:
17841823 case R_ARM_THM_JUMP24:
17851824 case R_ARM_THM_JUMP19:
....@@ -1958,7 +1997,7 @@
19581997
19591998 if (n && s[n]) {
19601999 size_t m = strspn(s + n + 1, "0123456789");
1961
- if (m && (s[n + m] == '.' || s[n + m] == 0))
2000
+ if (m && (s[n + m + 1] == '.' || s[n + m + 1] == 0))
19622001 s[n] = 0;
19632002
19642003 /* strip trailing .lto */
....@@ -1973,6 +2012,7 @@
19732012 const char *symname;
19742013 char *version;
19752014 char *license;
2015
+ char *namespace;
19762016 struct module *mod;
19772017 struct elf_info info = { };
19782018 Elf_Sym *sym;
....@@ -1980,46 +2020,84 @@
19802020 if (!parse_elf(&info, modname))
19812021 return;
19822022
1983
- mod = new_module(modname);
2023
+ {
2024
+ char *tmp;
19842025
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;
2026
+ /* strip trailing .o */
2027
+ tmp = NOFAIL(strdup(modname));
2028
+ tmp[strlen(tmp) - 2] = '\0';
2029
+ /* strip trailing .lto */
2030
+ if (strends(tmp, ".lto"))
2031
+ tmp[strlen(tmp) - 4] = '\0';
2032
+ mod = new_module(tmp);
2033
+ free(tmp);
19902034 }
19912035
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;
2036
+ if (!mod->is_vmlinux) {
2037
+ license = get_modinfo(&info, "license");
2038
+ if (!license)
2039
+ error("missing MODULE_LICENSE() in %s\n", modname);
2040
+ while (license) {
2041
+ if (license_is_gpl_compatible(license))
2042
+ mod->gpl_compatible = 1;
2043
+ else {
2044
+ mod->gpl_compatible = 0;
2045
+ break;
2046
+ }
2047
+ license = get_next_modinfo(&info, "license", license);
20032048 }
2004
- license = get_next_modinfo(&info, "license", license);
2049
+
2050
+ namespace = get_modinfo(&info, "import_ns");
2051
+ while (namespace) {
2052
+ add_namespace(&mod->imported_namespaces, namespace);
2053
+ namespace = get_next_modinfo(&info, "import_ns",
2054
+ namespace);
2055
+ }
20052056 }
20062057
20072058 for (sym = info.symtab_start; sym < info.symtab_stop; sym++) {
20082059 symname = remove_dot(info.strtab + sym->st_name);
20092060
2010
- handle_modversions(mod, &info, sym, symname);
2061
+ handle_symbol(mod, &info, sym, symname);
20112062 handle_moddevtable(mod, &info, sym, symname);
20122063 }
2013
- if (!is_vmlinux(modname) || vmlinux_section_warnings)
2014
- check_sec_ref(mod, modname, &info);
20152064
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);
2065
+ for (sym = info.symtab_start; sym < info.symtab_stop; sym++) {
2066
+ symname = remove_dot(info.strtab + sym->st_name);
2067
+
2068
+ /* Apply symbol namespaces from __kstrtabns_<symbol> entries. */
2069
+ if (strstarts(symname, "__kstrtabns_"))
2070
+ sym_update_namespace(symname + strlen("__kstrtabns_"),
2071
+ namespace_from_kstrtabns(&info,
2072
+ sym));
2073
+
2074
+ if (strstarts(symname, "__crc_"))
2075
+ handle_modversion(mod, &info, sym,
2076
+ symname + strlen("__crc_"));
2077
+ }
2078
+
2079
+ // check for static EXPORT_SYMBOL_* functions && global vars
2080
+ for (sym = info.symtab_start; sym < info.symtab_stop; sym++) {
2081
+ unsigned char bind = ELF_ST_BIND(sym->st_info);
2082
+
2083
+ if (bind == STB_GLOBAL || bind == STB_WEAK) {
2084
+ struct symbol *s =
2085
+ find_symbol(remove_dot(info.strtab +
2086
+ sym->st_name));
2087
+
2088
+ if (s)
2089
+ s->is_static = 0;
2090
+ }
2091
+ }
2092
+
2093
+ check_sec_ref(mod, modname, &info);
2094
+
2095
+ if (!mod->is_vmlinux) {
2096
+ version = get_modinfo(&info, "version");
2097
+ if (version || all_versions)
2098
+ get_src_version(modname, mod->srcversion,
2099
+ sizeof(mod->srcversion) - 1);
2100
+ }
20232101
20242102 parse_elf_finish(&info);
20252103
....@@ -2083,20 +2161,18 @@
20832161
20842162 static void check_for_gpl_usage(enum export exp, const char *m, const char *s)
20852163 {
2086
- const char *e = is_vmlinux(m) ?"":".ko";
2087
-
20882164 switch (exp) {
20892165 case export_gpl:
2090
- fatal("modpost: GPL-incompatible module %s%s "
2091
- "uses GPL-only symbol '%s'\n", m, e, s);
2166
+ error("GPL-incompatible module %s.ko uses GPL-only symbol '%s'\n",
2167
+ m, s);
20922168 break;
20932169 case export_unused_gpl:
2094
- fatal("modpost: GPL-incompatible module %s%s "
2095
- "uses GPL-only symbol marked UNUSED '%s'\n", m, e, s);
2170
+ error("GPL-incompatible module %s.ko uses GPL-only symbol marked UNUSED '%s'\n",
2171
+ m, s);
20962172 break;
20972173 case export_gpl_future:
2098
- warn("modpost: GPL-incompatible module %s%s "
2099
- "uses future GPL-only symbol '%s'\n", m, e, s);
2174
+ warn("GPL-incompatible module %s.ko uses future GPL-only symbol '%s'\n",
2175
+ m, s);
21002176 break;
21012177 case export_plain:
21022178 case export_unused:
....@@ -2108,13 +2184,11 @@
21082184
21092185 static void check_for_unused(enum export exp, const char *m, const char *s)
21102186 {
2111
- const char *e = is_vmlinux(m) ?"":".ko";
2112
-
21132187 switch (exp) {
21142188 case export_unused:
21152189 case export_unused_gpl:
2116
- warn("modpost: module %s%s "
2117
- "uses symbol '%s' marked UNUSED\n", m, e, s);
2190
+ warn("module %s.ko uses symbol '%s' marked UNUSED\n",
2191
+ m, s);
21182192 break;
21192193 default:
21202194 /* ignore */
....@@ -2129,20 +2203,34 @@
21292203 for (s = mod->unres; s; s = s->next) {
21302204 const char *basename;
21312205 exp = find_symbol(s->name);
2132
- if (!exp || exp->module == mod)
2206
+ if (!exp || exp->module == mod) {
2207
+ if (have_vmlinux && !s->weak)
2208
+ modpost_log(warn_unresolved ? LOG_WARN : LOG_ERROR,
2209
+ "\"%s\" [%s.ko] undefined!\n",
2210
+ s->name, mod->name);
21332211 continue;
2212
+ }
21342213 basename = strrchr(mod->name, '/');
21352214 if (basename)
21362215 basename++;
21372216 else
21382217 basename = mod->name;
2218
+
2219
+ if (exp->namespace &&
2220
+ !module_imports_namespace(mod, exp->namespace)) {
2221
+ modpost_log(allow_missing_ns_imports ? LOG_WARN : LOG_ERROR,
2222
+ "module %s uses symbol %s from namespace %s, but does not import it.\n",
2223
+ basename, exp->name, exp->namespace);
2224
+ add_namespace(&mod->missing_namespaces, exp->namespace);
2225
+ }
2226
+
21392227 if (!mod->gpl_compatible)
21402228 check_for_gpl_usage(exp->export, basename, exp->name);
21412229 check_for_unused(exp->export, basename, exp->name);
21422230 }
21432231 }
21442232
2145
-static int check_modname_len(struct module *mod)
2233
+static void check_modname_len(struct module *mod)
21462234 {
21472235 const char *mod_name;
21482236
....@@ -2151,12 +2239,8 @@
21512239 mod_name = mod->name;
21522240 else
21532241 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;
2242
+ if (strlen(mod_name) >= MODULE_NAME_LEN)
2243
+ error("module name is too long [%s.ko]\n", mod->name);
21602244 }
21612245
21622246 /**
....@@ -2169,6 +2253,7 @@
21692253 * Include build-salt.h after module.h in order to
21702254 * inherit the definitions.
21712255 */
2256
+ buf_printf(b, "#define INCLUDE_VERMAGIC\n");
21722257 buf_printf(b, "#include <linux/build-salt.h>\n");
21732258 buf_printf(b, "#include <linux/vermagic.h>\n");
21742259 buf_printf(b, "#include <linux/compiler.h>\n");
....@@ -2179,7 +2264,7 @@
21792264 buf_printf(b, "MODULE_INFO(name, KBUILD_MODNAME);\n");
21802265 buf_printf(b, "\n");
21812266 buf_printf(b, "__visible struct module __this_module\n");
2182
- buf_printf(b, "__attribute__((section(\".gnu.linkonce.this_module\"))) = {\n");
2267
+ buf_printf(b, "__section(\".gnu.linkonce.this_module\") = {\n");
21832268 buf_printf(b, "\t.name = KBUILD_MODNAME,\n");
21842269 if (mod->has_init)
21852270 buf_printf(b, "\t.init = init_module,\n");
....@@ -2195,6 +2280,20 @@
21952280 {
21962281 if (is_intree)
21972282 buf_printf(b, "\nMODULE_INFO(intree, \"Y\");\n");
2283
+}
2284
+
2285
+/**
2286
+ * add_scmversion() - Adds the MODULE_INFO macro for the scmversion.
2287
+ * @b: Buffer to append to.
2288
+ *
2289
+ * This function fills in the module attribute `scmversion` for the kernel
2290
+ * module. This is useful for determining a given module's SCM version on
2291
+ * device via /sys/modules/<module>/scmversion and/or using the modinfo tool.
2292
+ */
2293
+static void add_scmversion(struct buffer *b)
2294
+{
2295
+ if (module_scmversion[0] != '\0')
2296
+ buf_printf(b, "\nMODULE_INFO(scmversion, \"%s\");\n", module_scmversion);
21982297 }
21992298
22002299 /* Cannot check for assembler */
....@@ -2214,38 +2313,25 @@
22142313 /**
22152314 * Record CRCs for unresolved symbols
22162315 **/
2217
-static int add_versions(struct buffer *b, struct module *mod)
2316
+static void add_versions(struct buffer *b, struct module *mod)
22182317 {
22192318 struct symbol *s, *exp;
2220
- int err = 0;
22212319
22222320 for (s = mod->unres; s; s = s->next) {
22232321 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
- }
2322
+ if (!exp || exp->module == mod)
22352323 continue;
2236
- }
22372324 s->module = exp->module;
22382325 s->crc_valid = exp->crc_valid;
22392326 s->crc = exp->crc;
22402327 }
22412328
22422329 if (!modversions)
2243
- return err;
2330
+ return;
22442331
22452332 buf_printf(b, "\n");
22462333 buf_printf(b, "static const struct modversion_info ____versions[]\n");
2247
- buf_printf(b, "__used\n");
2248
- buf_printf(b, "__attribute__((section(\"__versions\"))) = {\n");
2334
+ buf_printf(b, "__used __section(\"__versions\") = {\n");
22492335
22502336 for (s = mod->unres; s; s = s->next) {
22512337 if (!s->module)
....@@ -2256,9 +2342,8 @@
22562342 continue;
22572343 }
22582344 if (strlen(s->name) >= MODULE_NAME_LEN) {
2259
- merror("too long symbol \"%s\" [%s.ko]\n",
2260
- s->name, mod->name);
2261
- err = 1;
2345
+ error("too long symbol \"%s\" [%s.ko]\n",
2346
+ s->name, mod->name);
22622347 break;
22632348 }
22642349 buf_printf(b, "\t{ %#8x, \"%s\" },\n",
....@@ -2266,25 +2351,20 @@
22662351 }
22672352
22682353 buf_printf(b, "};\n");
2269
-
2270
- return err;
22712354 }
22722355
2273
-static void add_depends(struct buffer *b, struct module *mod,
2274
- struct module *modules)
2356
+static void add_depends(struct buffer *b, struct module *mod)
22752357 {
22762358 struct symbol *s;
2277
- struct module *m;
22782359 int first = 1;
22792360
2280
- for (m = modules; m; m = m->next)
2281
- m->seen = is_vmlinux(m->name);
2361
+ /* Clear ->seen flag of modules that own symbols needed by this. */
2362
+ for (s = mod->unres; s; s = s->next)
2363
+ if (s->module)
2364
+ s->module->seen = s->module->is_vmlinux;
22822365
22832366 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=");
2367
+ buf_printf(b, "MODULE_INFO(depends, \"");
22882368 for (s = mod->unres; s; s = s->next) {
22892369 const char *p;
22902370 if (!s->module)
....@@ -2302,7 +2382,7 @@
23022382 buf_printf(b, "%s%s", first ? "" : ",", p);
23032383 first = 0;
23042384 }
2305
- buf_printf(b, "\";\n");
2385
+ buf_printf(b, "\");\n");
23062386 }
23072387
23082388 static void add_srcversion(struct buffer *b, struct module *mod)
....@@ -2311,6 +2391,25 @@
23112391 buf_printf(b, "\n");
23122392 buf_printf(b, "MODULE_INFO(srcversion, \"%s\");\n",
23132393 mod->srcversion);
2394
+ }
2395
+}
2396
+
2397
+static void write_buf(struct buffer *b, const char *fname)
2398
+{
2399
+ FILE *file;
2400
+
2401
+ file = fopen(fname, "w");
2402
+ if (!file) {
2403
+ perror(fname);
2404
+ exit(1);
2405
+ }
2406
+ if (fwrite(b->p, 1, b->pos, file) != b->pos) {
2407
+ perror(fname);
2408
+ exit(1);
2409
+ }
2410
+ if (fclose(file) != 0) {
2411
+ perror(fname);
2412
+ exit(1);
23142413 }
23152414 }
23162415
....@@ -2346,33 +2445,25 @@
23462445 close_write:
23472446 fclose(file);
23482447 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);
2448
+ write_buf(b, fname);
23592449 }
23602450
23612451 /* parse Module.symvers file. line format:
2362
- * 0x12345678<tab>symbol<tab>module[[<tab>export]<tab>something]
2452
+ * 0x12345678<tab>symbol<tab>module<tab>export<tab>namespace
23632453 **/
2364
-static void read_dump(const char *fname, unsigned int kernel)
2454
+static void read_dump(const char *fname)
23652455 {
2366
- unsigned long size, pos = 0;
2367
- void *file = grab_file(fname, &size);
2368
- char *line;
2456
+ char *buf, *pos, *line;
23692457
2370
- if (!file)
2458
+ buf = read_text_file(fname);
2459
+ if (!buf)
23712460 /* No symbol versions, silently ignore */
23722461 return;
23732462
2374
- while ((line = get_next_line(&pos, file, size))) {
2375
- char *symname, *modname, *d, *export, *end;
2463
+ pos = buf;
2464
+
2465
+ while ((line = get_line(&pos))) {
2466
+ char *symname, *namespace, *modname, *d, *export;
23762467 unsigned int crc;
23772468 struct module *mod;
23782469 struct symbol *s;
....@@ -2383,68 +2474,83 @@
23832474 if (!(modname = strchr(symname, '\t')))
23842475 goto fail;
23852476 *modname++ = '\0';
2386
- if ((export = strchr(modname, '\t')) != NULL)
2387
- *export++ = '\0';
2388
- if (export && ((end = strchr(export, '\t')) != NULL))
2389
- *end = '\0';
2477
+ if (!(export = strchr(modname, '\t')))
2478
+ goto fail;
2479
+ *export++ = '\0';
2480
+ if (!(namespace = strchr(export, '\t')))
2481
+ goto fail;
2482
+ *namespace++ = '\0';
2483
+
23902484 crc = strtoul(line, &d, 16);
23912485 if (*symname == '\0' || *modname == '\0' || *d != '\0')
23922486 goto fail;
23932487 mod = find_module(modname);
23942488 if (!mod) {
2395
- if (is_vmlinux(modname))
2396
- have_vmlinux = 1;
23972489 mod = new_module(modname);
2398
- mod->skip = 1;
2490
+ mod->from_dump = 1;
23992491 }
24002492 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));
2493
+ s->is_static = 0;
2494
+ sym_set_crc(symname, crc);
2495
+ sym_update_namespace(symname, namespace);
24042496 }
2405
- release_file(file, size);
2497
+ free(buf);
24062498 return;
24072499 fail:
2408
- release_file(file, size);
2500
+ free(buf);
24092501 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;
24232502 }
24242503
24252504 static void write_dump(const char *fname)
24262505 {
24272506 struct buffer buf = { };
24282507 struct symbol *symbol;
2508
+ const char *namespace;
24292509 int n;
24302510
24312511 for (n = 0; n < SYMBOL_HASH_SIZE ; n++) {
24322512 symbol = symbolhash[n];
24332513 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));
2514
+ if (!symbol->module->from_dump) {
2515
+ namespace = symbol->namespace;
2516
+ buf_printf(&buf, "0x%08x\t%s\t%s\t%s\t%s\n",
2517
+ symbol->crc, symbol->name,
2518
+ symbol->module->name,
2519
+ export_str(symbol->export),
2520
+ namespace ? namespace : "");
2521
+ }
24392522 symbol = symbol->next;
24402523 }
24412524 }
2442
- write_if_changed(&buf, fname);
2525
+ write_buf(&buf, fname);
24432526 free(buf.p);
24442527 }
24452528
2446
-struct ext_sym_list {
2447
- struct ext_sym_list *next;
2529
+static void write_namespace_deps_files(const char *fname)
2530
+{
2531
+ struct module *mod;
2532
+ struct namespace_list *ns;
2533
+ struct buffer ns_deps_buf = {};
2534
+
2535
+ for (mod = modules; mod; mod = mod->next) {
2536
+
2537
+ if (mod->from_dump || !mod->missing_namespaces)
2538
+ continue;
2539
+
2540
+ buf_printf(&ns_deps_buf, "%s.ko:", mod->name);
2541
+
2542
+ for (ns = mod->missing_namespaces; ns; ns = ns->next)
2543
+ buf_printf(&ns_deps_buf, " %s", ns->namespace);
2544
+
2545
+ buf_printf(&ns_deps_buf, "\n");
2546
+ }
2547
+
2548
+ write_if_changed(&ns_deps_buf, fname);
2549
+ free(ns_deps_buf.p);
2550
+}
2551
+
2552
+struct dump_list {
2553
+ struct dump_list *next;
24482554 const char *file;
24492555 };
24502556
....@@ -2452,29 +2558,23 @@
24522558 {
24532559 struct module *mod;
24542560 struct buffer buf = { };
2455
- char *kernel_read = NULL, *module_read = NULL;
2561
+ char *missing_namespace_deps = NULL;
24562562 char *dump_write = NULL, *files_source = NULL;
24572563 int opt;
2458
- int err;
2459
- struct ext_sym_list *extsym_iter;
2460
- struct ext_sym_list *extsym_start = NULL;
2564
+ int n;
2565
+ struct dump_list *dump_read_start = NULL;
2566
+ struct dump_list **dump_read_iter = &dump_read_start;
24612567
2462
- while ((opt = getopt(argc, argv, "i:I:e:mnsST:o:awM:K:E")) != -1) {
2568
+ while ((opt = getopt(argc, argv, "ei:mnT:o:awENd:v:")) != -1) {
24632569 switch (opt) {
2464
- case 'i':
2465
- kernel_read = optarg;
2466
- break;
2467
- case 'I':
2468
- module_read = optarg;
2469
- external_module = 1;
2470
- break;
24712570 case 'e':
24722571 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;
2572
+ break;
2573
+ case 'i':
2574
+ *dump_read_iter =
2575
+ NOFAIL(calloc(1, sizeof(**dump_read_iter)));
2576
+ (*dump_read_iter)->file = optarg;
2577
+ dump_read_iter = &(*dump_read_iter)->next;
24782578 break;
24792579 case 'm':
24802580 modversions = 1;
....@@ -2488,12 +2588,6 @@
24882588 case 'a':
24892589 all_versions = 1;
24902590 break;
2491
- case 's':
2492
- vmlinux_section_warnings = 0;
2493
- break;
2494
- case 'S':
2495
- sec_mismatch_verbose = 0;
2496
- break;
24972591 case 'T':
24982592 files_source = optarg;
24992593 break;
....@@ -2501,22 +2595,29 @@
25012595 warn_unresolved = 1;
25022596 break;
25032597 case 'E':
2504
- sec_mismatch_fatal = 1;
2598
+ sec_mismatch_warn_only = false;
2599
+ break;
2600
+ case 'N':
2601
+ allow_missing_ns_imports = 1;
2602
+ break;
2603
+ case 'd':
2604
+ missing_namespace_deps = optarg;
2605
+ break;
2606
+ case 'v':
2607
+ strncpy(module_scmversion, optarg, sizeof(module_scmversion) - 1);
25052608 break;
25062609 default:
25072610 exit(1);
25082611 }
25092612 }
25102613
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;
2614
+ while (dump_read_start) {
2615
+ struct dump_list *tmp;
2616
+
2617
+ read_dump(dump_read_start->file);
2618
+ tmp = dump_read_start->next;
2619
+ free(dump_read_start);
2620
+ dump_read_start = tmp;
25202621 }
25212622
25222623 while (optind < argc)
....@@ -2525,50 +2626,58 @@
25252626 if (files_source)
25262627 read_symbols_from_files(files_source);
25272628
2528
- for (mod = modules; mod; mod = mod->next) {
2529
- if (mod->skip)
2530
- continue;
2531
- check_exports(mod);
2532
- }
2533
-
2534
- err = 0;
2629
+ /*
2630
+ * When there's no vmlinux, don't print warnings about
2631
+ * unresolved symbols (since there'll be too many ;)
2632
+ */
2633
+ if (!have_vmlinux)
2634
+ warn("Symbol info of vmlinux is missing. Unresolved symbol check will be entirely skipped.\n");
25352635
25362636 for (mod = modules; mod; mod = mod->next) {
25372637 char fname[PATH_MAX];
25382638
2539
- if (mod->skip)
2639
+ if (mod->is_vmlinux || mod->from_dump)
25402640 continue;
25412641
25422642 buf.pos = 0;
25432643
2544
- err |= check_modname_len(mod);
2644
+ check_modname_len(mod);
2645
+ check_exports(mod);
2646
+
25452647 add_header(&buf, mod);
25462648 add_intree_flag(&buf, !external_module);
25472649 add_retpoline(&buf);
25482650 add_staging_flag(&buf, mod->name);
2549
- err |= add_versions(&buf, mod);
2550
- add_depends(&buf, mod, modules);
2651
+ add_versions(&buf, mod);
2652
+ add_depends(&buf, mod);
25512653 add_moddevtable(&buf, mod);
25522654 add_srcversion(&buf, mod);
2655
+ add_scmversion(&buf);
25532656
25542657 sprintf(fname, "%s.mod.c", mod->name);
25552658 write_if_changed(&buf, fname);
25562659 }
2660
+
2661
+ if (missing_namespace_deps)
2662
+ write_namespace_deps_files(missing_namespace_deps);
2663
+
25572664 if (dump_write)
25582665 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");
2666
+ if (sec_mismatch_count && !sec_mismatch_warn_only)
2667
+ error("Section mismatches detected.\n"
2668
+ "Set CONFIG_SECTION_MISMATCH_WARN_ONLY=y to allow them.\n");
2669
+ for (n = 0; n < SYMBOL_HASH_SIZE; n++) {
2670
+ struct symbol *s;
2671
+
2672
+ for (s = symbolhash[n]; s; s = s->next) {
2673
+ if (s->is_static)
2674
+ error("\"%s\" [%s] is a static %s\n",
2675
+ s->name, s->module->name,
2676
+ export_str(s->export));
25692677 }
25702678 }
2679
+
25712680 free(buf.p);
25722681
2573
- return err;
2682
+ return error_occurred ? 1 : 0;
25742683 }