diff options
Diffstat (limited to 'scripts/mod/modpost.c')
-rw-r--r-- | scripts/mod/modpost.c | 94 |
1 files changed, 68 insertions, 26 deletions
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 0dd16177642d..dfde0e87a765 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c | |||
@@ -24,7 +24,10 @@ static int all_versions = 0; | |||
24 | /* If we are modposting external module set to 1 */ | 24 | /* If we are modposting external module set to 1 */ |
25 | static int external_module = 0; | 25 | static int external_module = 0; |
26 | /* How a symbol is exported */ | 26 | /* How a symbol is exported */ |
27 | enum export {export_plain, export_gpl, export_gpl_future, export_unknown}; | 27 | enum export { |
28 | export_plain, export_unused, export_gpl, | ||
29 | export_unused_gpl, export_gpl_future, export_unknown | ||
30 | }; | ||
28 | 31 | ||
29 | void fatal(const char *fmt, ...) | 32 | void fatal(const char *fmt, ...) |
30 | { | 33 | { |
@@ -191,7 +194,9 @@ static struct { | |||
191 | enum export export; | 194 | enum export export; |
192 | } export_list[] = { | 195 | } export_list[] = { |
193 | { .str = "EXPORT_SYMBOL", .export = export_plain }, | 196 | { .str = "EXPORT_SYMBOL", .export = export_plain }, |
197 | { .str = "EXPORT_UNUSED_SYMBOL", .export = export_unused }, | ||
194 | { .str = "EXPORT_SYMBOL_GPL", .export = export_gpl }, | 198 | { .str = "EXPORT_SYMBOL_GPL", .export = export_gpl }, |
199 | { .str = "EXPORT_UNUSED_SYMBOL_GPL", .export = export_unused_gpl }, | ||
195 | { .str = "EXPORT_SYMBOL_GPL_FUTURE", .export = export_gpl_future }, | 200 | { .str = "EXPORT_SYMBOL_GPL_FUTURE", .export = export_gpl_future }, |
196 | { .str = "(unknown)", .export = export_unknown }, | 201 | { .str = "(unknown)", .export = export_unknown }, |
197 | }; | 202 | }; |
@@ -205,6 +210,8 @@ static const char *export_str(enum export ex) | |||
205 | static enum export export_no(const char * s) | 210 | static enum export export_no(const char * s) |
206 | { | 211 | { |
207 | int i; | 212 | int i; |
213 | if (!s) | ||
214 | return export_unknown; | ||
208 | for (i = 0; export_list[i].export != export_unknown; i++) { | 215 | for (i = 0; export_list[i].export != export_unknown; i++) { |
209 | if (strcmp(export_list[i].str, s) == 0) | 216 | if (strcmp(export_list[i].str, s) == 0) |
210 | return export_list[i].export; | 217 | return export_list[i].export; |
@@ -216,8 +223,12 @@ static enum export export_from_sec(struct elf_info *elf, Elf_Section sec) | |||
216 | { | 223 | { |
217 | if (sec == elf->export_sec) | 224 | if (sec == elf->export_sec) |
218 | return export_plain; | 225 | return export_plain; |
226 | else if (sec == elf->export_unused_sec) | ||
227 | return export_unused; | ||
219 | else if (sec == elf->export_gpl_sec) | 228 | else if (sec == elf->export_gpl_sec) |
220 | return export_gpl; | 229 | return export_gpl; |
230 | else if (sec == elf->export_unused_gpl_sec) | ||
231 | return export_unused_gpl; | ||
221 | else if (sec == elf->export_gpl_future_sec) | 232 | else if (sec == elf->export_gpl_future_sec) |
222 | return export_gpl_future; | 233 | return export_gpl_future; |
223 | else | 234 | else |
@@ -366,8 +377,12 @@ static void parse_elf(struct elf_info *info, const char *filename) | |||
366 | info->modinfo_len = sechdrs[i].sh_size; | 377 | info->modinfo_len = sechdrs[i].sh_size; |
367 | } else if (strcmp(secname, "__ksymtab") == 0) | 378 | } else if (strcmp(secname, "__ksymtab") == 0) |
368 | info->export_sec = i; | 379 | info->export_sec = i; |
380 | else if (strcmp(secname, "__ksymtab_unused") == 0) | ||
381 | info->export_unused_sec = i; | ||
369 | else if (strcmp(secname, "__ksymtab_gpl") == 0) | 382 | else if (strcmp(secname, "__ksymtab_gpl") == 0) |
370 | info->export_gpl_sec = i; | 383 | info->export_gpl_sec = i; |
384 | else if (strcmp(secname, "__ksymtab_unused_gpl") == 0) | ||
385 | info->export_unused_gpl_sec = i; | ||
371 | else if (strcmp(secname, "__ksymtab_gpl_future") == 0) | 386 | else if (strcmp(secname, "__ksymtab_gpl_future") == 0) |
372 | info->export_gpl_future_sec = i; | 387 | info->export_gpl_future_sec = i; |
373 | 388 | ||
@@ -1085,38 +1100,64 @@ void buf_write(struct buffer *buf, const char *s, int len) | |||
1085 | buf->pos += len; | 1100 | buf->pos += len; |
1086 | } | 1101 | } |
1087 | 1102 | ||
1088 | void check_license(struct module *mod) | 1103 | static void check_for_gpl_usage(enum export exp, const char *m, const char *s) |
1104 | { | ||
1105 | const char *e = is_vmlinux(m) ?"":".ko"; | ||
1106 | |||
1107 | switch (exp) { | ||
1108 | case export_gpl: | ||
1109 | fatal("modpost: GPL-incompatible module %s%s " | ||
1110 | "uses GPL-only symbol '%s'\n", m, e, s); | ||
1111 | break; | ||
1112 | case export_unused_gpl: | ||
1113 | fatal("modpost: GPL-incompatible module %s%s " | ||
1114 | "uses GPL-only symbol marked UNUSED '%s'\n", m, e, s); | ||
1115 | break; | ||
1116 | case export_gpl_future: | ||
1117 | warn("modpost: GPL-incompatible module %s%s " | ||
1118 | "uses future GPL-only symbol '%s'\n", m, e, s); | ||
1119 | break; | ||
1120 | case export_plain: | ||
1121 | case export_unused: | ||
1122 | case export_unknown: | ||
1123 | /* ignore */ | ||
1124 | break; | ||
1125 | } | ||
1126 | } | ||
1127 | |||
1128 | static void check_for_unused(enum export exp, const char* m, const char* s) | ||
1129 | { | ||
1130 | const char *e = is_vmlinux(m) ?"":".ko"; | ||
1131 | |||
1132 | switch (exp) { | ||
1133 | case export_unused: | ||
1134 | case export_unused_gpl: | ||
1135 | warn("modpost: module %s%s " | ||
1136 | "uses symbol '%s' marked UNUSED\n", m, e, s); | ||
1137 | break; | ||
1138 | default: | ||
1139 | /* ignore */ | ||
1140 | break; | ||
1141 | } | ||
1142 | } | ||
1143 | |||
1144 | static void check_exports(struct module *mod) | ||
1089 | { | 1145 | { |
1090 | struct symbol *s, *exp; | 1146 | struct symbol *s, *exp; |
1091 | 1147 | ||
1092 | for (s = mod->unres; s; s = s->next) { | 1148 | for (s = mod->unres; s; s = s->next) { |
1093 | const char *basename; | 1149 | const char *basename; |
1094 | if (mod->gpl_compatible == 1) { | ||
1095 | /* GPL-compatible modules may use all symbols */ | ||
1096 | continue; | ||
1097 | } | ||
1098 | exp = find_symbol(s->name); | 1150 | exp = find_symbol(s->name); |
1099 | if (!exp || exp->module == mod) | 1151 | if (!exp || exp->module == mod) |
1100 | continue; | 1152 | continue; |
1101 | basename = strrchr(mod->name, '/'); | 1153 | basename = strrchr(mod->name, '/'); |
1102 | if (basename) | 1154 | if (basename) |
1103 | basename++; | 1155 | basename++; |
1104 | switch (exp->export) { | 1156 | else |
1105 | case export_gpl: | 1157 | basename = mod->name; |
1106 | fatal("modpost: GPL-incompatible module %s " | 1158 | if (!mod->gpl_compatible) |
1107 | "uses GPL-only symbol '%s'\n", | 1159 | check_for_gpl_usage(exp->export, basename, exp->name); |
1108 | basename ? basename : mod->name, | 1160 | check_for_unused(exp->export, basename, exp->name); |
1109 | exp->name); | ||
1110 | break; | ||
1111 | case export_gpl_future: | ||
1112 | warn("modpost: GPL-incompatible module %s " | ||
1113 | "uses future GPL-only symbol '%s'\n", | ||
1114 | basename ? basename : mod->name, | ||
1115 | exp->name); | ||
1116 | break; | ||
1117 | case export_plain: /* ignore */ break; | ||
1118 | case export_unknown: /* ignore */ break; | ||
1119 | } | ||
1120 | } | 1161 | } |
1121 | } | 1162 | } |
1122 | 1163 | ||
@@ -1271,7 +1312,7 @@ static void write_if_changed(struct buffer *b, const char *fname) | |||
1271 | } | 1312 | } |
1272 | 1313 | ||
1273 | /* parse Module.symvers file. line format: | 1314 | /* parse Module.symvers file. line format: |
1274 | * 0x12345678<tab>symbol<tab>module[<tab>export] | 1315 | * 0x12345678<tab>symbol<tab>module[[<tab>export]<tab>something] |
1275 | **/ | 1316 | **/ |
1276 | static void read_dump(const char *fname, unsigned int kernel) | 1317 | static void read_dump(const char *fname, unsigned int kernel) |
1277 | { | 1318 | { |
@@ -1284,7 +1325,7 @@ static void read_dump(const char *fname, unsigned int kernel) | |||
1284 | return; | 1325 | return; |
1285 | 1326 | ||
1286 | while ((line = get_next_line(&pos, file, size))) { | 1327 | while ((line = get_next_line(&pos, file, size))) { |
1287 | char *symname, *modname, *d, *export; | 1328 | char *symname, *modname, *d, *export, *end; |
1288 | unsigned int crc; | 1329 | unsigned int crc; |
1289 | struct module *mod; | 1330 | struct module *mod; |
1290 | struct symbol *s; | 1331 | struct symbol *s; |
@@ -1297,7 +1338,8 @@ static void read_dump(const char *fname, unsigned int kernel) | |||
1297 | *modname++ = '\0'; | 1338 | *modname++ = '\0'; |
1298 | if ((export = strchr(modname, '\t')) != NULL) | 1339 | if ((export = strchr(modname, '\t')) != NULL) |
1299 | *export++ = '\0'; | 1340 | *export++ = '\0'; |
1300 | 1341 | if (export && ((end = strchr(export, '\t')) != NULL)) | |
1342 | *end = '\0'; | ||
1301 | crc = strtoul(line, &d, 16); | 1343 | crc = strtoul(line, &d, 16); |
1302 | if (*symname == '\0' || *modname == '\0' || *d != '\0') | 1344 | if (*symname == '\0' || *modname == '\0' || *d != '\0') |
1303 | goto fail; | 1345 | goto fail; |
@@ -1396,7 +1438,7 @@ int main(int argc, char **argv) | |||
1396 | for (mod = modules; mod; mod = mod->next) { | 1438 | for (mod = modules; mod; mod = mod->next) { |
1397 | if (mod->skip) | 1439 | if (mod->skip) |
1398 | continue; | 1440 | continue; |
1399 | check_license(mod); | 1441 | check_exports(mod); |
1400 | } | 1442 | } |
1401 | 1443 | ||
1402 | for (mod = modules; mod; mod = mod->next) { | 1444 | for (mod = modules; mod; mod = mod->next) { |