modpost.c (f057b57270c2a17d3f45c177e9434fa5745caa48) modpost.c (fdf94e4403ece60b29ef9e2da95e2fcefe50817f)
1/* Postprocess module symbol versions
2 *
3 * Copyright 2003 Kai Germaschewski
4 * Copyright 2002-2004 Rusty Russell, IBM Corporation
5 * Copyright 2006-2008 Sam Ravnborg
6 * Based in part on module-init-tools/depmod.c,file2alias
7 *
8 * This software may be used and distributed according to the terms

--- 9 unchanged lines hidden (view full) ---

18#include <ctype.h>
19#include <string.h>
20#include <limits.h>
21#include <stdbool.h>
22#include <errno.h>
23
24#include <hashtable.h>
25#include <list.h>
1/* Postprocess module symbol versions
2 *
3 * Copyright 2003 Kai Germaschewski
4 * Copyright 2002-2004 Rusty Russell, IBM Corporation
5 * Copyright 2006-2008 Sam Ravnborg
6 * Based in part on module-init-tools/depmod.c,file2alias
7 *
8 * This software may be used and distributed according to the terms

--- 9 unchanged lines hidden (view full) ---

18#include <ctype.h>
19#include <string.h>
20#include <limits.h>
21#include <stdbool.h>
22#include <errno.h>
23
24#include <hashtable.h>
25#include <list.h>
26#include <xalloc.h>
26#include "modpost.h"
27#include "../../include/linux/license.h"
28
29static bool module_enabled;
30/* Are we using CONFIG_MODVERSIONS? */
31static bool modversions;
32/* Is CONFIG_MODULE_SRCVERSION_ALL set? */
33static bool all_versions;

--- 11 unchanged lines hidden (view full) ---

45static bool ignore_missing_files;
46/* If set to 1, only warn (instead of error) about missing ns imports */
47static bool allow_missing_ns_imports;
48
49static bool error_occurred;
50
51static bool extra_warn;
52
27#include "modpost.h"
28#include "../../include/linux/license.h"
29
30static bool module_enabled;
31/* Are we using CONFIG_MODVERSIONS? */
32static bool modversions;
33/* Is CONFIG_MODULE_SRCVERSION_ALL set? */
34static bool all_versions;

--- 11 unchanged lines hidden (view full) ---

46static bool ignore_missing_files;
47/* If set to 1, only warn (instead of error) about missing ns imports */
48static bool allow_missing_ns_imports;
49
50static bool error_occurred;
51
52static bool extra_warn;
53
54bool target_is_big_endian;
55bool host_is_big_endian;
56
53/*
54 * Cut off the warnings when there are too many. This typically occurs when
55 * vmlinux is missing. ('make modules' without building vmlinux.)
56 */
57#define MAX_UNRESOLVED_REPORTS 10
58static unsigned int nr_unresolved;
59
60/* In kernel, this size is defined in linux/module.h;
61 * here we use Elf_Addr instead of long for covering cross-compile
62 */
63
64#define MODULE_NAME_LEN (64 - sizeof(Elf_Addr))
65
57/*
58 * Cut off the warnings when there are too many. This typically occurs when
59 * vmlinux is missing. ('make modules' without building vmlinux.)
60 */
61#define MAX_UNRESOLVED_REPORTS 10
62static unsigned int nr_unresolved;
63
64/* In kernel, this size is defined in linux/module.h;
65 * here we use Elf_Addr instead of long for covering cross-compile
66 */
67
68#define MODULE_NAME_LEN (64 - sizeof(Elf_Addr))
69
66void modpost_log(enum loglevel loglevel, const char *fmt, ...)
70void modpost_log(bool is_error, const char *fmt, ...)
67{
68 va_list arglist;
69
71{
72 va_list arglist;
73
70 switch (loglevel) {
71 case LOG_WARN:
72 fprintf(stderr, "WARNING: ");
73 break;
74 case LOG_ERROR:
74 if (is_error) {
75 fprintf(stderr, "ERROR: ");
76 error_occurred = true;
75 fprintf(stderr, "ERROR: ");
76 error_occurred = true;
77 break;
78 default: /* invalid loglevel, ignore */
79 break;
77 } else {
78 fprintf(stderr, "WARNING: ");
80 }
81
82 fprintf(stderr, "modpost: ");
83
84 va_start(arglist, fmt);
85 vfprintf(stderr, fmt, arglist);
86 va_end(arglist);
87}
88
89static inline bool strends(const char *str, const char *postfix)
90{
91 if (strlen(str) < strlen(postfix))
92 return false;
93
94 return strcmp(str + strlen(str) - strlen(postfix), postfix) == 0;
95}
96
79 }
80
81 fprintf(stderr, "modpost: ");
82
83 va_start(arglist, fmt);
84 vfprintf(stderr, fmt, arglist);
85 va_end(arglist);
86}
87
88static inline bool strends(const char *str, const char *postfix)
89{
90 if (strlen(str) < strlen(postfix))
91 return false;
92
93 return strcmp(str + strlen(str) - strlen(postfix), postfix) == 0;
94}
95
97void *do_nofail(void *ptr, const char *expr)
98{
99 if (!ptr)
100 fatal("Memory allocation failure: %s.\n", expr);
101
102 return ptr;
103}
104
105char *read_text_file(const char *filename)
106{
107 struct stat st;
108 size_t nbytes;
109 int fd;
110 char *buf;
111
112 fd = open(filename, O_RDONLY);
113 if (fd < 0) {
114 perror(filename);
115 exit(1);
116 }
117
118 if (fstat(fd, &st) < 0) {
119 perror(filename);
120 exit(1);
121 }
122
96char *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
123 buf = NOFAIL(malloc(st.st_size + 1));
114 buf = xmalloc(st.st_size + 1);
124
125 nbytes = st.st_size;
126
127 while (nbytes) {
128 ssize_t bytes_read;
129
130 bytes_read = read(fd, buf, nbytes);
131 if (bytes_read < 0) {

--- 41 unchanged lines hidden (view full) ---

173 }
174 return NULL;
175}
176
177static struct module *new_module(const char *name, size_t namelen)
178{
179 struct module *mod;
180
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) {

--- 41 unchanged lines hidden (view full) ---

164 }
165 return NULL;
166}
167
168static struct module *new_module(const char *name, size_t namelen)
169{
170 struct module *mod;
171
181 mod = NOFAIL(malloc(sizeof(*mod) + namelen + 1));
172 mod = xmalloc(sizeof(*mod) + namelen + 1);
182 memset(mod, 0, sizeof(*mod));
183
184 INIT_LIST_HEAD(&mod->exported_symbols);
185 INIT_LIST_HEAD(&mod->unresolved_symbols);
186 INIT_LIST_HEAD(&mod->missing_namespaces);
187 INIT_LIST_HEAD(&mod->imported_namespaces);
188
189 memcpy(mod->name, name, namelen);

--- 42 unchanged lines hidden (view full) ---

232}
233
234/**
235 * Allocate a new symbols for use in the hash of exported symbols or
236 * the list of unresolved symbols per module
237 **/
238static struct symbol *alloc_symbol(const char *name)
239{
173 memset(mod, 0, sizeof(*mod));
174
175 INIT_LIST_HEAD(&mod->exported_symbols);
176 INIT_LIST_HEAD(&mod->unresolved_symbols);
177 INIT_LIST_HEAD(&mod->missing_namespaces);
178 INIT_LIST_HEAD(&mod->imported_namespaces);
179
180 memcpy(mod->name, name, namelen);

--- 42 unchanged lines hidden (view full) ---

223}
224
225/**
226 * Allocate a new symbols for use in the hash of exported symbols or
227 * the list of unresolved symbols per module
228 **/
229static struct symbol *alloc_symbol(const char *name)
230{
240 struct symbol *s = NOFAIL(malloc(sizeof(*s) + strlen(name) + 1));
231 struct symbol *s = xmalloc(sizeof(*s) + strlen(name) + 1);
241
242 memset(s, 0, sizeof(*s));
243 strcpy(s->name, name);
244
245 return s;
246}
247
248/* For the hash of exported symbols */

--- 56 unchanged lines hidden (view full) ---

305 return false;
306}
307
308static void add_namespace(struct list_head *head, const char *namespace)
309{
310 struct namespace_list *ns_entry;
311
312 if (!contains_namespace(head, namespace)) {
232
233 memset(s, 0, sizeof(*s));
234 strcpy(s->name, name);
235
236 return s;
237}
238
239/* For the hash of exported symbols */

--- 56 unchanged lines hidden (view full) ---

296 return false;
297}
298
299static void add_namespace(struct list_head *head, const char *namespace)
300{
301 struct namespace_list *ns_entry;
302
303 if (!contains_namespace(head, namespace)) {
313 ns_entry = NOFAIL(malloc(sizeof(*ns_entry) +
314 strlen(namespace) + 1));
304 ns_entry = xmalloc(sizeof(*ns_entry) + strlen(namespace) + 1);
315 strcpy(ns_entry->namespace, namespace);
316 list_add_tail(&ns_entry->list, head);
317 }
318}
319
320static void *sym_get_data_by_offset(const struct elf_info *info,
321 unsigned int secindex, unsigned long offset)
322{

--- 38 unchanged lines hidden (view full) ---

361 error("%s: '%s' exported twice. Previous export was in %s%s\n",
362 mod->name, name, s->module->name,
363 s->module->is_vmlinux ? "" : ".ko");
364 }
365
366 s = alloc_symbol(name);
367 s->module = mod;
368 s->is_gpl_only = gpl_only;
305 strcpy(ns_entry->namespace, namespace);
306 list_add_tail(&ns_entry->list, head);
307 }
308}
309
310static void *sym_get_data_by_offset(const struct elf_info *info,
311 unsigned int secindex, unsigned long offset)
312{

--- 38 unchanged lines hidden (view full) ---

351 error("%s: '%s' exported twice. Previous export was in %s%s\n",
352 mod->name, name, s->module->name,
353 s->module->is_vmlinux ? "" : ".ko");
354 }
355
356 s = alloc_symbol(name);
357 s->module = mod;
358 s->is_gpl_only = gpl_only;
369 s->namespace = NOFAIL(strdup(namespace));
359 s->namespace = xstrdup(namespace);
370 list_add_tail(&s->list, &mod->exported_symbols);
371 hash_add_symbol(s);
372
373 return s;
374}
375
376static void sym_set_crc(struct symbol *sym, unsigned int crc)
377{

--- 55 unchanged lines hidden (view full) ---

433 /* Is this a valid ELF file? */
434 if ((hdr->e_ident[EI_MAG0] != ELFMAG0) ||
435 (hdr->e_ident[EI_MAG1] != ELFMAG1) ||
436 (hdr->e_ident[EI_MAG2] != ELFMAG2) ||
437 (hdr->e_ident[EI_MAG3] != ELFMAG3)) {
438 /* Not an ELF file - silently ignore it */
439 return 0;
440 }
360 list_add_tail(&s->list, &mod->exported_symbols);
361 hash_add_symbol(s);
362
363 return s;
364}
365
366static void sym_set_crc(struct symbol *sym, unsigned int crc)
367{

--- 55 unchanged lines hidden (view full) ---

423 /* Is this a valid ELF file? */
424 if ((hdr->e_ident[EI_MAG0] != ELFMAG0) ||
425 (hdr->e_ident[EI_MAG1] != ELFMAG1) ||
426 (hdr->e_ident[EI_MAG2] != ELFMAG2) ||
427 (hdr->e_ident[EI_MAG3] != ELFMAG3)) {
428 /* Not an ELF file - silently ignore it */
429 return 0;
430 }
431
432 switch (hdr->e_ident[EI_DATA]) {
433 case ELFDATA2LSB:
434 target_is_big_endian = false;
435 break;
436 case ELFDATA2MSB:
437 target_is_big_endian = true;
438 break;
439 default:
440 fatal("target endian is unknown\n");
441 }
442
441 /* Fix endianness in ELF header */
442 hdr->e_type = TO_NATIVE(hdr->e_type);
443 hdr->e_machine = TO_NATIVE(hdr->e_machine);
444 hdr->e_version = TO_NATIVE(hdr->e_version);
445 hdr->e_entry = TO_NATIVE(hdr->e_entry);
446 hdr->e_phoff = TO_NATIVE(hdr->e_phoff);
447 hdr->e_shoff = TO_NATIVE(hdr->e_shoff);
448 hdr->e_flags = TO_NATIVE(hdr->e_flags);

--- 168 unchanged lines hidden (view full) ---

617 if (ignore_undef_symbol(info, symname))
618 break;
619 if (info->hdr->e_machine == EM_SPARC ||
620 info->hdr->e_machine == EM_SPARCV9) {
621 /* Ignore register directives. */
622 if (ELF_ST_TYPE(sym->st_info) == STT_SPARC_REGISTER)
623 break;
624 if (symname[0] == '.') {
443 /* Fix endianness in ELF header */
444 hdr->e_type = TO_NATIVE(hdr->e_type);
445 hdr->e_machine = TO_NATIVE(hdr->e_machine);
446 hdr->e_version = TO_NATIVE(hdr->e_version);
447 hdr->e_entry = TO_NATIVE(hdr->e_entry);
448 hdr->e_phoff = TO_NATIVE(hdr->e_phoff);
449 hdr->e_shoff = TO_NATIVE(hdr->e_shoff);
450 hdr->e_flags = TO_NATIVE(hdr->e_flags);

--- 168 unchanged lines hidden (view full) ---

619 if (ignore_undef_symbol(info, symname))
620 break;
621 if (info->hdr->e_machine == EM_SPARC ||
622 info->hdr->e_machine == EM_SPARCV9) {
623 /* Ignore register directives. */
624 if (ELF_ST_TYPE(sym->st_info) == STT_SPARC_REGISTER)
625 break;
626 if (symname[0] == '.') {
625 char *munged = NOFAIL(strdup(symname));
627 char *munged = xstrdup(symname);
626 munged[0] = '_';
627 munged[1] = toupper(munged[1]);
628 symname = munged;
629 }
630 }
631
632 sym_add_unresolved(symname, mod,
633 ELF_ST_BIND(sym->st_info) == STB_WEAK);

--- 51 unchanged lines hidden (view full) ---

685static char *get_modinfo(struct elf_info *info, const char *tag)
686
687{
688 return get_next_modinfo(info, tag, NULL);
689}
690
691static const char *sym_name(struct elf_info *elf, Elf_Sym *sym)
692{
628 munged[0] = '_';
629 munged[1] = toupper(munged[1]);
630 symname = munged;
631 }
632 }
633
634 sym_add_unresolved(symname, mod,
635 ELF_ST_BIND(sym->st_info) == STB_WEAK);

--- 51 unchanged lines hidden (view full) ---

687static char *get_modinfo(struct elf_info *info, const char *tag)
688
689{
690 return get_next_modinfo(info, tag, NULL);
691}
692
693static const char *sym_name(struct elf_info *elf, Elf_Sym *sym)
694{
693 if (sym)
694 return elf->strtab + sym->st_name;
695 else
696 return "(unknown)";
695 return sym ? elf->strtab + sym->st_name : "";
697}
698
699/*
700 * Check whether the 'string' argument matches one of the 'patterns',
701 * an array of shell wildcard patterns (glob).
702 *
703 * Return true is there is a match.
704 */

--- 296 unchanged lines hidden (view full) ---

1001 const struct sectioncheck* const mismatch,
1002 Elf_Sym *tsym,
1003 unsigned int fsecndx, const char *fromsec, Elf_Addr faddr,
1004 const char *tosec, Elf_Addr taddr)
1005{
1006 Elf_Sym *from;
1007 const char *tosym;
1008 const char *fromsym;
696}
697
698/*
699 * Check whether the 'string' argument matches one of the 'patterns',
700 * an array of shell wildcard patterns (glob).
701 *
702 * Return true is there is a match.
703 */

--- 296 unchanged lines hidden (view full) ---

1000 const struct sectioncheck* const mismatch,
1001 Elf_Sym *tsym,
1002 unsigned int fsecndx, const char *fromsec, Elf_Addr faddr,
1003 const char *tosec, Elf_Addr taddr)
1004{
1005 Elf_Sym *from;
1006 const char *tosym;
1007 const char *fromsym;
1008 char taddr_str[16];
1009
1010 from = find_fromsym(elf, faddr, fsecndx);
1011 fromsym = sym_name(elf, from);
1012
1013 tsym = find_tosym(elf, taddr, tsym);
1014 tosym = sym_name(elf, tsym);
1015
1016 /* check whitelist - we may ignore it */
1017 if (!secref_whitelist(fromsec, fromsym, tosec, tosym))
1018 return;
1019
1020 sec_mismatch_count++;
1021
1009
1010 from = find_fromsym(elf, faddr, fsecndx);
1011 fromsym = sym_name(elf, from);
1012
1013 tsym = find_tosym(elf, taddr, tsym);
1014 tosym = sym_name(elf, tsym);
1015
1016 /* check whitelist - we may ignore it */
1017 if (!secref_whitelist(fromsec, fromsym, tosec, tosym))
1018 return;
1019
1020 sec_mismatch_count++;
1021
1022 warn("%s: section mismatch in reference: %s+0x%x (section: %s) -> %s (section: %s)\n",
1023 modname, fromsym,
1024 (unsigned int)(faddr - (from ? from->st_value : 0)),
1025 fromsec, tosym, tosec);
1022 if (!tosym[0])
1023 snprintf(taddr_str, sizeof(taddr_str), "0x%x", (unsigned int)taddr);
1026
1024
1025 /*
1026 * The format for the reference source: <symbol_name>+<offset> or <address>
1027 * The format for the reference destination: <symbol_name> or <address>
1028 */
1029 warn("%s: section mismatch in reference: %s%s0x%x (section: %s) -> %s (section: %s)\n",
1030 modname, fromsym, fromsym[0] ? "+" : "",
1031 (unsigned int)(faddr - (fromsym[0] ? from->st_value : 0)),
1032 fromsec, tosym[0] ? tosym : taddr_str, tosec);
1033
1027 if (mismatch->mismatch == EXTABLE_TO_NON_TEXT) {
1028 if (match(tosec, mismatch->bad_tosec))
1029 fatal("The relocation at %s+0x%lx references\n"
1030 "section \"%s\" which is black-listed.\n"
1031 "Something is seriously wrong and should be fixed.\n"
1032 "You might get more information about where this is\n"
1033 "coming from by using scripts/check_extable.sh %s\n",
1034 fromsec, (long)faddr, tosec, modname);

--- 622 unchanged lines hidden (view full) ---

1657 buf_write(buf, tmp, len);
1658 va_end(ap);
1659}
1660
1661void buf_write(struct buffer *buf, const char *s, int len)
1662{
1663 if (buf->size - buf->pos < len) {
1664 buf->size += len + SZ;
1034 if (mismatch->mismatch == EXTABLE_TO_NON_TEXT) {
1035 if (match(tosec, mismatch->bad_tosec))
1036 fatal("The relocation at %s+0x%lx references\n"
1037 "section \"%s\" which is black-listed.\n"
1038 "Something is seriously wrong and should be fixed.\n"
1039 "You might get more information about where this is\n"
1040 "coming from by using scripts/check_extable.sh %s\n",
1041 fromsec, (long)faddr, tosec, modname);

--- 622 unchanged lines hidden (view full) ---

1664 buf_write(buf, tmp, len);
1665 va_end(ap);
1666}
1667
1668void buf_write(struct buffer *buf, const char *s, int len)
1669{
1670 if (buf->size - buf->pos < len) {
1671 buf->size += len + SZ;
1665 buf->p = NOFAIL(realloc(buf->p, buf->size));
1672 buf->p = xrealloc(buf->p, buf->size);
1666 }
1667 strncpy(buf->p + buf->pos, s, len);
1668 buf->pos += len;
1669}
1670
1671static void check_exports(struct module *mod)
1672{
1673 struct symbol *s, *exp;
1674
1675 list_for_each_entry(s, &mod->unresolved_symbols, list) {
1676 const char *basename;
1677 exp = find_symbol(s->name);
1678 if (!exp) {
1679 if (!s->weak && nr_unresolved++ < MAX_UNRESOLVED_REPORTS)
1673 }
1674 strncpy(buf->p + buf->pos, s, len);
1675 buf->pos += len;
1676}
1677
1678static void check_exports(struct module *mod)
1679{
1680 struct symbol *s, *exp;
1681
1682 list_for_each_entry(s, &mod->unresolved_symbols, list) {
1683 const char *basename;
1684 exp = find_symbol(s->name);
1685 if (!exp) {
1686 if (!s->weak && nr_unresolved++ < MAX_UNRESOLVED_REPORTS)
1680 modpost_log(warn_unresolved ? LOG_WARN : LOG_ERROR,
1687 modpost_log(!warn_unresolved,
1681 "\"%s\" [%s.ko] undefined!\n",
1682 s->name, mod->name);
1683 continue;
1684 }
1685 if (exp->module == mod) {
1686 error("\"%s\" [%s.ko] was exported without definition\n",
1687 s->name, mod->name);
1688 continue;

--- 6 unchanged lines hidden (view full) ---

1695
1696 basename = strrchr(mod->name, '/');
1697 if (basename)
1698 basename++;
1699 else
1700 basename = mod->name;
1701
1702 if (!contains_namespace(&mod->imported_namespaces, exp->namespace)) {
1688 "\"%s\" [%s.ko] undefined!\n",
1689 s->name, mod->name);
1690 continue;
1691 }
1692 if (exp->module == mod) {
1693 error("\"%s\" [%s.ko] was exported without definition\n",
1694 s->name, mod->name);
1695 continue;

--- 6 unchanged lines hidden (view full) ---

1702
1703 basename = strrchr(mod->name, '/');
1704 if (basename)
1705 basename++;
1706 else
1707 basename = mod->name;
1708
1709 if (!contains_namespace(&mod->imported_namespaces, exp->namespace)) {
1703 modpost_log(allow_missing_ns_imports ? LOG_WARN : LOG_ERROR,
1710 modpost_log(!allow_missing_ns_imports,
1704 "module %s uses symbol %s from namespace %s, but does not import it.\n",
1705 basename, exp->name, exp->namespace);
1706 add_namespace(&mod->missing_namespaces, exp->namespace);
1707 }
1708
1709 if (!mod->is_gpl_compatible && exp->is_gpl_only)
1710 error("GPL-incompatible module %s.ko uses GPL-only symbol '%s'\n",
1711 basename, exp->name);

--- 31 unchanged lines hidden (view full) ---

1743}
1744
1745/**
1746 * Header for the generated file
1747 **/
1748static void add_header(struct buffer *b, struct module *mod)
1749{
1750 buf_printf(b, "#include <linux/module.h>\n");
1711 "module %s uses symbol %s from namespace %s, but does not import it.\n",
1712 basename, exp->name, exp->namespace);
1713 add_namespace(&mod->missing_namespaces, exp->namespace);
1714 }
1715
1716 if (!mod->is_gpl_compatible && exp->is_gpl_only)
1717 error("GPL-incompatible module %s.ko uses GPL-only symbol '%s'\n",
1718 basename, exp->name);

--- 31 unchanged lines hidden (view full) ---

1750}
1751
1752/**
1753 * Header for the generated file
1754 **/
1755static void add_header(struct buffer *b, struct module *mod)
1756{
1757 buf_printf(b, "#include <linux/module.h>\n");
1751 /*
1752 * Include build-salt.h after module.h in order to
1753 * inherit the definitions.
1754 */
1755 buf_printf(b, "#define INCLUDE_VERMAGIC\n");
1756 buf_printf(b, "#include <linux/build-salt.h>\n");
1757 buf_printf(b, "#include <linux/elfnote-lto.h>\n");
1758 buf_printf(b, "#include <linux/export-internal.h>\n");
1758 buf_printf(b, "#include <linux/export-internal.h>\n");
1759 buf_printf(b, "#include <linux/vermagic.h>\n");
1760 buf_printf(b, "#include <linux/compiler.h>\n");
1761 buf_printf(b, "\n");
1759 buf_printf(b, "#include <linux/compiler.h>\n");
1760 buf_printf(b, "\n");
1762 buf_printf(b, "#ifdef CONFIG_UNWINDER_ORC\n");
1763 buf_printf(b, "#include <asm/orc_header.h>\n");
1764 buf_printf(b, "ORC_HEADER;\n");
1765 buf_printf(b, "#endif\n");
1766 buf_printf(b, "\n");
1767 buf_printf(b, "BUILD_SALT;\n");
1768 buf_printf(b, "BUILD_LTO_INFO;\n");
1769 buf_printf(b, "\n");
1770 buf_printf(b, "MODULE_INFO(vermagic, VERMAGIC_STRING);\n");
1771 buf_printf(b, "MODULE_INFO(name, KBUILD_MODNAME);\n");
1772 buf_printf(b, "\n");
1773 buf_printf(b, "__visible struct module __this_module\n");
1774 buf_printf(b, "__section(\".gnu.linkonce.this_module\") = {\n");
1775 buf_printf(b, "\t.name = KBUILD_MODNAME,\n");
1776 if (mod->has_init)
1777 buf_printf(b, "\t.init = init_module,\n");
1778 if (mod->has_cleanup)
1779 buf_printf(b, "#ifdef CONFIG_MODULE_UNLOAD\n"
1780 "\t.exit = cleanup_module,\n"
1781 "#endif\n");
1782 buf_printf(b, "\t.arch = MODULE_ARCH_INIT,\n");
1783 buf_printf(b, "};\n");
1784
1785 if (!external_module)
1786 buf_printf(b, "\nMODULE_INFO(intree, \"Y\");\n");
1787
1761 buf_printf(b, "MODULE_INFO(name, KBUILD_MODNAME);\n");
1762 buf_printf(b, "\n");
1763 buf_printf(b, "__visible struct module __this_module\n");
1764 buf_printf(b, "__section(\".gnu.linkonce.this_module\") = {\n");
1765 buf_printf(b, "\t.name = KBUILD_MODNAME,\n");
1766 if (mod->has_init)
1767 buf_printf(b, "\t.init = init_module,\n");
1768 if (mod->has_cleanup)
1769 buf_printf(b, "#ifdef CONFIG_MODULE_UNLOAD\n"
1770 "\t.exit = cleanup_module,\n"
1771 "#endif\n");
1772 buf_printf(b, "\t.arch = MODULE_ARCH_INIT,\n");
1773 buf_printf(b, "};\n");
1774
1775 if (!external_module)
1776 buf_printf(b, "\nMODULE_INFO(intree, \"Y\");\n");
1777
1788 buf_printf(b,
1789 "\n"
1790 "#ifdef CONFIG_MITIGATION_RETPOLINE\n"
1791 "MODULE_INFO(retpoline, \"Y\");\n"
1792 "#endif\n");
1793
1794 if (strstarts(mod->name, "drivers/staging"))
1795 buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n");
1796
1797 if (strstarts(mod->name, "tools/testing"))
1798 buf_printf(b, "\nMODULE_INFO(test, \"Y\");\n");
1799}
1800
1801static void add_exported_symbols(struct buffer *buf, struct module *mod)

--- 140 unchanged lines hidden (view full) ---

1942 goto write;
1943
1944 if (fstat(fileno(file), &st) < 0)
1945 goto close_write;
1946
1947 if (st.st_size != b->pos)
1948 goto close_write;
1949
1778 if (strstarts(mod->name, "drivers/staging"))
1779 buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n");
1780
1781 if (strstarts(mod->name, "tools/testing"))
1782 buf_printf(b, "\nMODULE_INFO(test, \"Y\");\n");
1783}
1784
1785static void add_exported_symbols(struct buffer *buf, struct module *mod)

--- 140 unchanged lines hidden (view full) ---

1926 goto write;
1927
1928 if (fstat(fileno(file), &st) < 0)
1929 goto close_write;
1930
1931 if (st.st_size != b->pos)
1932 goto close_write;
1933
1950 tmp = NOFAIL(malloc(b->pos));
1934 tmp = xmalloc(b->pos);
1951 if (fread(tmp, 1, b->pos, file) != b->pos)
1952 goto free_write;
1953
1954 if (memcmp(tmp, b->p, b->pos) != 0)
1955 goto free_write;
1956
1957 free(tmp);
1958 fclose(file);

--- 153 unchanged lines hidden (view full) ---

2112 free(ns_deps_buf.p);
2113}
2114
2115struct dump_list {
2116 struct list_head list;
2117 const char *file;
2118};
2119
1935 if (fread(tmp, 1, b->pos, file) != b->pos)
1936 goto free_write;
1937
1938 if (memcmp(tmp, b->p, b->pos) != 0)
1939 goto free_write;
1940
1941 free(tmp);
1942 fclose(file);

--- 153 unchanged lines hidden (view full) ---

2096 free(ns_deps_buf.p);
2097}
2098
2099struct dump_list {
2100 struct list_head list;
2101 const char *file;
2102};
2103
2104static void check_host_endian(void)
2105{
2106 static const union {
2107 short s;
2108 char c[2];
2109 } endian_test = { .c = {0x01, 0x02} };
2110
2111 switch (endian_test.s) {
2112 case 0x0102:
2113 host_is_big_endian = true;
2114 break;
2115 case 0x0201:
2116 host_is_big_endian = false;
2117 break;
2118 default:
2119 fatal("Unknown host endian\n");
2120 }
2121}
2122
2120int main(int argc, char **argv)
2121{
2122 struct module *mod;
2123 char *missing_namespace_deps = NULL;
2124 char *unused_exports_white_list = NULL;
2125 char *dump_write = NULL, *files_source = NULL;
2126 int opt;
2127 LIST_HEAD(dump_lists);
2128 struct dump_list *dl, *dl2;
2129
2130 while ((opt = getopt(argc, argv, "ei:MmnT:to:au:WwENd:")) != -1) {
2131 switch (opt) {
2132 case 'e':
2133 external_module = true;
2134 break;
2135 case 'i':
2123int main(int argc, char **argv)
2124{
2125 struct module *mod;
2126 char *missing_namespace_deps = NULL;
2127 char *unused_exports_white_list = NULL;
2128 char *dump_write = NULL, *files_source = NULL;
2129 int opt;
2130 LIST_HEAD(dump_lists);
2131 struct dump_list *dl, *dl2;
2132
2133 while ((opt = getopt(argc, argv, "ei:MmnT:to:au:WwENd:")) != -1) {
2134 switch (opt) {
2135 case 'e':
2136 external_module = true;
2137 break;
2138 case 'i':
2136 dl = NOFAIL(malloc(sizeof(*dl)));
2139 dl = xmalloc(sizeof(*dl));
2137 dl->file = optarg;
2138 list_add_tail(&dl->list, &dump_lists);
2139 break;
2140 case 'M':
2141 module_enabled = true;
2142 break;
2143 case 'm':
2144 modversions = true;

--- 31 unchanged lines hidden (view full) ---

2176 case 'd':
2177 missing_namespace_deps = optarg;
2178 break;
2179 default:
2180 exit(1);
2181 }
2182 }
2183
2140 dl->file = optarg;
2141 list_add_tail(&dl->list, &dump_lists);
2142 break;
2143 case 'M':
2144 module_enabled = true;
2145 break;
2146 case 'm':
2147 modversions = true;

--- 31 unchanged lines hidden (view full) ---

2179 case 'd':
2180 missing_namespace_deps = optarg;
2181 break;
2182 default:
2183 exit(1);
2184 }
2185 }
2186
2187 check_host_endian();
2188
2184 list_for_each_entry_safe(dl, dl2, &dump_lists, list) {
2185 read_dump(dl->file);
2186 list_del(&dl->list);
2187 free(dl);
2188 }
2189
2190 while (optind < argc)
2191 read_symbols(argv[optind++]);

--- 40 unchanged lines hidden ---
2189 list_for_each_entry_safe(dl, dl2, &dump_lists, list) {
2190 read_dump(dl->file);
2191 list_del(&dl->list);
2192 free(dl);
2193 }
2194
2195 while (optind < argc)
2196 read_symbols(argv[optind++]);

--- 40 unchanged lines hidden ---