aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/mod
diff options
context:
space:
mode:
authorPaul Mundt <lethal@linux-sh.org>2011-01-13 01:06:28 -0500
committerPaul Mundt <lethal@linux-sh.org>2011-01-13 01:06:28 -0500
commitf43dc23d5ea91fca257be02138a255f02d98e806 (patch)
treeb29722f6e965316e90ac97abf79923ced250dc21 /scripts/mod
parentf8e53553f452dcbf67cb89c8cba63a1cd6eb4cc0 (diff)
parent4162cf64973df51fc885825bc9ca4d055891c49f (diff)
Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/torvalds/linux-2.6 into common/serial-rework
Conflicts: arch/sh/kernel/cpu/sh2/setup-sh7619.c arch/sh/kernel/cpu/sh2a/setup-mxg.c arch/sh/kernel/cpu/sh2a/setup-sh7201.c arch/sh/kernel/cpu/sh2a/setup-sh7203.c arch/sh/kernel/cpu/sh2a/setup-sh7206.c arch/sh/kernel/cpu/sh3/setup-sh7705.c arch/sh/kernel/cpu/sh3/setup-sh770x.c arch/sh/kernel/cpu/sh3/setup-sh7710.c arch/sh/kernel/cpu/sh3/setup-sh7720.c arch/sh/kernel/cpu/sh4/setup-sh4-202.c arch/sh/kernel/cpu/sh4/setup-sh7750.c arch/sh/kernel/cpu/sh4/setup-sh7760.c arch/sh/kernel/cpu/sh4a/setup-sh7343.c arch/sh/kernel/cpu/sh4a/setup-sh7366.c arch/sh/kernel/cpu/sh4a/setup-sh7722.c arch/sh/kernel/cpu/sh4a/setup-sh7723.c arch/sh/kernel/cpu/sh4a/setup-sh7724.c arch/sh/kernel/cpu/sh4a/setup-sh7763.c arch/sh/kernel/cpu/sh4a/setup-sh7770.c arch/sh/kernel/cpu/sh4a/setup-sh7780.c arch/sh/kernel/cpu/sh4a/setup-sh7785.c arch/sh/kernel/cpu/sh4a/setup-sh7786.c arch/sh/kernel/cpu/sh4a/setup-shx3.c arch/sh/kernel/cpu/sh5/setup-sh5.c drivers/serial/sh-sci.c drivers/serial/sh-sci.h include/linux/serial_sci.h
Diffstat (limited to 'scripts/mod')
-rw-r--r--scripts/mod/Makefile2
-rw-r--r--scripts/mod/file2alias.c173
-rw-r--r--scripts/mod/mk_elfconfig.c9
-rw-r--r--scripts/mod/modpost.c521
-rw-r--r--scripts/mod/modpost.h46
-rw-r--r--scripts/mod/sumversion.c2
6 files changed, 445 insertions, 308 deletions
diff --git a/scripts/mod/Makefile b/scripts/mod/Makefile
index 11d69c35e5b4..ff954f8168c1 100644
--- a/scripts/mod/Makefile
+++ b/scripts/mod/Makefile
@@ -8,7 +8,7 @@ modpost-objs := modpost.o file2alias.o sumversion.o
8$(obj)/modpost.o $(obj)/file2alias.o $(obj)/sumversion.o: $(obj)/elfconfig.h 8$(obj)/modpost.o $(obj)/file2alias.o $(obj)/sumversion.o: $(obj)/elfconfig.h
9 9
10quiet_cmd_elfconfig = MKELF $@ 10quiet_cmd_elfconfig = MKELF $@
11 cmd_elfconfig = $(obj)/mk_elfconfig $(ARCH) < $< > $@ 11 cmd_elfconfig = $(obj)/mk_elfconfig < $< > $@
12 12
13$(obj)/elfconfig.h: $(obj)/empty.o $(obj)/mk_elfconfig FORCE 13$(obj)/elfconfig.h: $(obj)/empty.o $(obj)/mk_elfconfig FORCE
14 $(call if_changed,elfconfig) 14 $(call if_changed,elfconfig)
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index 40e0045876ee..88f3f07205f8 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -104,7 +104,7 @@ static void device_id_check(const char *modname, const char *device_id,
104static void do_usb_entry(struct usb_device_id *id, 104static void do_usb_entry(struct usb_device_id *id,
105 unsigned int bcdDevice_initial, int bcdDevice_initial_digits, 105 unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
106 unsigned char range_lo, unsigned char range_hi, 106 unsigned char range_lo, unsigned char range_hi,
107 struct module *mod) 107 unsigned char max, struct module *mod)
108{ 108{
109 char alias[500]; 109 char alias[500];
110 strcpy(alias, "usb:"); 110 strcpy(alias, "usb:");
@@ -118,9 +118,22 @@ static void do_usb_entry(struct usb_device_id *id,
118 sprintf(alias + strlen(alias), "%0*X", 118 sprintf(alias + strlen(alias), "%0*X",
119 bcdDevice_initial_digits, bcdDevice_initial); 119 bcdDevice_initial_digits, bcdDevice_initial);
120 if (range_lo == range_hi) 120 if (range_lo == range_hi)
121 sprintf(alias + strlen(alias), "%u", range_lo); 121 sprintf(alias + strlen(alias), "%X", range_lo);
122 else if (range_lo > 0 || range_hi < 9) 122 else if (range_lo > 0 || range_hi < max) {
123 sprintf(alias + strlen(alias), "[%u-%u]", range_lo, range_hi); 123 if (range_lo > 0x9 || range_hi < 0xA)
124 sprintf(alias + strlen(alias),
125 "[%X-%X]",
126 range_lo,
127 range_hi);
128 else {
129 sprintf(alias + strlen(alias),
130 range_lo < 0x9 ? "[%X-9" : "[%X",
131 range_lo);
132 sprintf(alias + strlen(alias),
133 range_hi > 0xA ? "a-%X]" : "%X]",
134 range_lo);
135 }
136 }
124 if (bcdDevice_initial_digits < (sizeof(id->bcdDevice_lo) * 2 - 1)) 137 if (bcdDevice_initial_digits < (sizeof(id->bcdDevice_lo) * 2 - 1))
125 strcat(alias, "*"); 138 strcat(alias, "*");
126 139
@@ -147,10 +160,49 @@ static void do_usb_entry(struct usb_device_id *id,
147 "MODULE_ALIAS(\"%s\");\n", alias); 160 "MODULE_ALIAS(\"%s\");\n", alias);
148} 161}
149 162
163/* Handles increment/decrement of BCD formatted integers */
164/* Returns the previous value, so it works like i++ or i-- */
165static unsigned int incbcd(unsigned int *bcd,
166 int inc,
167 unsigned char max,
168 size_t chars)
169{
170 unsigned int init = *bcd, i, j;
171 unsigned long long c, dec = 0;
172
173 /* If bcd is not in BCD format, just increment */
174 if (max > 0x9) {
175 *bcd += inc;
176 return init;
177 }
178
179 /* Convert BCD to Decimal */
180 for (i=0 ; i < chars ; i++) {
181 c = (*bcd >> (i << 2)) & 0xf;
182 c = c > 9 ? 9 : c; /* force to bcd just in case */
183 for (j=0 ; j < i ; j++)
184 c = c * 10;
185 dec += c;
186 }
187
188 /* Do our increment/decrement */
189 dec += inc;
190 *bcd = 0;
191
192 /* Convert back to BCD */
193 for (i=0 ; i < chars ; i++) {
194 for (c=1,j=0 ; j < i ; j++)
195 c = c * 10;
196 c = (dec / c) % 10;
197 *bcd += c << (i << 2);
198 }
199 return init;
200}
201
150static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod) 202static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
151{ 203{
152 unsigned int devlo, devhi; 204 unsigned int devlo, devhi;
153 unsigned char chi, clo; 205 unsigned char chi, clo, max;
154 int ndigits; 206 int ndigits;
155 207
156 id->match_flags = TO_NATIVE(id->match_flags); 208 id->match_flags = TO_NATIVE(id->match_flags);
@@ -162,6 +214,17 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
162 devhi = id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI ? 214 devhi = id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI ?
163 TO_NATIVE(id->bcdDevice_hi) : ~0x0U; 215 TO_NATIVE(id->bcdDevice_hi) : ~0x0U;
164 216
217 /* Figure out if this entry is in bcd or hex format */
218 max = 0x9; /* Default to decimal format */
219 for (ndigits = 0 ; ndigits < sizeof(id->bcdDevice_lo) * 2 ; ndigits++) {
220 clo = (devlo >> (ndigits << 2)) & 0xf;
221 chi = ((devhi > 0x9999 ? 0x9999 : devhi) >> (ndigits << 2)) & 0xf;
222 if (clo > max || chi > max) {
223 max = 0xf;
224 break;
225 }
226 }
227
165 /* 228 /*
166 * Some modules (visor) have empty slots as placeholder for 229 * Some modules (visor) have empty slots as placeholder for
167 * run-time specification that results in catch-all alias 230 * run-time specification that results in catch-all alias
@@ -173,21 +236,27 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
173 for (ndigits = sizeof(id->bcdDevice_lo) * 2 - 1; devlo <= devhi; ndigits--) { 236 for (ndigits = sizeof(id->bcdDevice_lo) * 2 - 1; devlo <= devhi; ndigits--) {
174 clo = devlo & 0xf; 237 clo = devlo & 0xf;
175 chi = devhi & 0xf; 238 chi = devhi & 0xf;
176 if (chi > 9) /* it's bcd not hex */ 239 if (chi > max) /* If we are in bcd mode, truncate if necessary */
177 chi = 9; 240 chi = max;
178 devlo >>= 4; 241 devlo >>= 4;
179 devhi >>= 4; 242 devhi >>= 4;
180 243
181 if (devlo == devhi || !ndigits) { 244 if (devlo == devhi || !ndigits) {
182 do_usb_entry(id, devlo, ndigits, clo, chi, mod); 245 do_usb_entry(id, devlo, ndigits, clo, chi, max, mod);
183 break; 246 break;
184 } 247 }
185 248
186 if (clo > 0) 249 if (clo > 0x0)
187 do_usb_entry(id, devlo++, ndigits, clo, 9, mod); 250 do_usb_entry(id,
188 251 incbcd(&devlo, 1, max,
189 if (chi < 9) 252 sizeof(id->bcdDevice_lo) * 2),
190 do_usb_entry(id, devhi--, ndigits, 0, chi, mod); 253 ndigits, clo, max, max, mod);
254
255 if (chi < max)
256 do_usb_entry(id,
257 incbcd(&devhi, -1, max,
258 sizeof(id->bcdDevice_lo) * 2),
259 ndigits, 0x0, chi, max, mod);
191 } 260 }
192} 261}
193 262
@@ -657,6 +726,15 @@ static int do_i2c_entry(const char *filename, struct i2c_device_id *id,
657 return 1; 726 return 1;
658} 727}
659 728
729/* Looks like: spi:S */
730static int do_spi_entry(const char *filename, struct spi_device_id *id,
731 char *alias)
732{
733 sprintf(alias, SPI_MODULE_PREFIX "%s", id->name);
734
735 return 1;
736}
737
660static const struct dmifield { 738static const struct dmifield {
661 const char *prefix; 739 const char *prefix;
662 int field; 740 int field;
@@ -718,6 +796,51 @@ static int do_platform_entry(const char *filename,
718 return 1; 796 return 1;
719} 797}
720 798
799static int do_mdio_entry(const char *filename,
800 struct mdio_device_id *id, char *alias)
801{
802 int i;
803
804 alias += sprintf(alias, MDIO_MODULE_PREFIX);
805
806 for (i = 0; i < 32; i++) {
807 if (!((id->phy_id_mask >> (31-i)) & 1))
808 *(alias++) = '?';
809 else if ((id->phy_id >> (31-i)) & 1)
810 *(alias++) = '1';
811 else
812 *(alias++) = '0';
813 }
814
815 /* Terminate the string */
816 *alias = 0;
817
818 return 1;
819}
820
821/* Looks like: zorro:iN. */
822static int do_zorro_entry(const char *filename, struct zorro_device_id *id,
823 char *alias)
824{
825 id->id = TO_NATIVE(id->id);
826 strcpy(alias, "zorro:");
827 ADD(alias, "i", id->id != ZORRO_WILDCARD, id->id);
828 return 1;
829}
830
831/* looks like: "pnp:dD" */
832static int do_isapnp_entry(const char *filename,
833 struct isapnp_device_id *id, char *alias)
834{
835 sprintf(alias, "pnp:d%c%c%c%x%x%x%x*",
836 'A' + ((id->vendor >> 2) & 0x3f) - 1,
837 'A' + (((id->vendor & 3) << 3) | ((id->vendor >> 13) & 7)) - 1,
838 'A' + ((id->vendor >> 8) & 0x1f) - 1,
839 (id->function >> 4) & 0x0f, id->function & 0x0f,
840 (id->function >> 12) & 0x0f, (id->function >> 8) & 0x0f);
841 return 1;
842}
843
721/* Ignore any prefix, eg. some architectures prepend _ */ 844/* Ignore any prefix, eg. some architectures prepend _ */
722static inline int sym_is(const char *symbol, const char *name) 845static inline int sym_is(const char *symbol, const char *name)
723{ 846{
@@ -726,7 +849,7 @@ static inline int sym_is(const char *symbol, const char *name)
726 match = strstr(symbol, name); 849 match = strstr(symbol, name);
727 if (!match) 850 if (!match)
728 return 0; 851 return 0;
729 return match[strlen(symbol)] == '\0'; 852 return match[strlen(name)] == '\0';
730} 853}
731 854
732static void do_table(void *symval, unsigned long size, 855static void do_table(void *symval, unsigned long size,
@@ -761,16 +884,16 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
761 char *zeros = NULL; 884 char *zeros = NULL;
762 885
763 /* We're looking for a section relative symbol */ 886 /* We're looking for a section relative symbol */
764 if (!sym->st_shndx || sym->st_shndx >= info->hdr->e_shnum) 887 if (!sym->st_shndx || get_secindex(info, sym) >= info->num_sections)
765 return; 888 return;
766 889
767 /* Handle all-NULL symbols allocated into .bss */ 890 /* Handle all-NULL symbols allocated into .bss */
768 if (info->sechdrs[sym->st_shndx].sh_type & SHT_NOBITS) { 891 if (info->sechdrs[get_secindex(info, sym)].sh_type & SHT_NOBITS) {
769 zeros = calloc(1, sym->st_size); 892 zeros = calloc(1, sym->st_size);
770 symval = zeros; 893 symval = zeros;
771 } else { 894 } else {
772 symval = (void *)info->hdr 895 symval = (void *)info->hdr
773 + info->sechdrs[sym->st_shndx].sh_offset 896 + info->sechdrs[get_secindex(info, sym)].sh_offset
774 + sym->st_value; 897 + sym->st_value;
775 } 898 }
776 899
@@ -853,6 +976,10 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
853 do_table(symval, sym->st_size, 976 do_table(symval, sym->st_size,
854 sizeof(struct i2c_device_id), "i2c", 977 sizeof(struct i2c_device_id), "i2c",
855 do_i2c_entry, mod); 978 do_i2c_entry, mod);
979 else if (sym_is(symname, "__mod_spi_device_table"))
980 do_table(symval, sym->st_size,
981 sizeof(struct spi_device_id), "spi",
982 do_spi_entry, mod);
856 else if (sym_is(symname, "__mod_dmi_device_table")) 983 else if (sym_is(symname, "__mod_dmi_device_table"))
857 do_table(symval, sym->st_size, 984 do_table(symval, sym->st_size,
858 sizeof(struct dmi_system_id), "dmi", 985 sizeof(struct dmi_system_id), "dmi",
@@ -861,6 +988,18 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
861 do_table(symval, sym->st_size, 988 do_table(symval, sym->st_size,
862 sizeof(struct platform_device_id), "platform", 989 sizeof(struct platform_device_id), "platform",
863 do_platform_entry, mod); 990 do_platform_entry, mod);
991 else if (sym_is(symname, "__mod_mdio_device_table"))
992 do_table(symval, sym->st_size,
993 sizeof(struct mdio_device_id), "mdio",
994 do_mdio_entry, mod);
995 else if (sym_is(symname, "__mod_zorro_device_table"))
996 do_table(symval, sym->st_size,
997 sizeof(struct zorro_device_id), "zorro",
998 do_zorro_entry, mod);
999 else if (sym_is(symname, "__mod_isapnp_device_table"))
1000 do_table(symval, sym->st_size,
1001 sizeof(struct isapnp_device_id), "isa",
1002 do_isapnp_entry, mod);
864 free(zeros); 1003 free(zeros);
865} 1004}
866 1005
diff --git a/scripts/mod/mk_elfconfig.c b/scripts/mod/mk_elfconfig.c
index 6a96d47bd1e6..639bca7ba559 100644
--- a/scripts/mod/mk_elfconfig.c
+++ b/scripts/mod/mk_elfconfig.c
@@ -9,9 +9,6 @@ main(int argc, char **argv)
9 unsigned char ei[EI_NIDENT]; 9 unsigned char ei[EI_NIDENT];
10 union { short s; char c[2]; } endian_test; 10 union { short s; char c[2]; } endian_test;
11 11
12 if (argc != 2) {
13 fprintf(stderr, "Error: no arch\n");
14 }
15 if (fread(ei, 1, EI_NIDENT, stdin) != EI_NIDENT) { 12 if (fread(ei, 1, EI_NIDENT, stdin) != EI_NIDENT) {
16 fprintf(stderr, "Error: input truncated\n"); 13 fprintf(stderr, "Error: input truncated\n");
17 return 1; 14 return 1;
@@ -55,12 +52,6 @@ main(int argc, char **argv)
55 else 52 else
56 exit(1); 53 exit(1);
57 54
58 if ((strcmp(argv[1], "h8300") == 0)
59 || (strcmp(argv[1], "blackfin") == 0))
60 printf("#define MODULE_SYMBOL_PREFIX \"_\"\n");
61 else
62 printf("#define MODULE_SYMBOL_PREFIX \"\"\n");
63
64 return 0; 55 return 0;
65} 56}
66 57
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 4522948a012e..97d2259ae999 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -14,9 +14,19 @@
14#define _GNU_SOURCE 14#define _GNU_SOURCE
15#include <stdio.h> 15#include <stdio.h>
16#include <ctype.h> 16#include <ctype.h>
17#include <string.h>
17#include "modpost.h" 18#include "modpost.h"
19#include "../../include/generated/autoconf.h"
18#include "../../include/linux/license.h" 20#include "../../include/linux/license.h"
19 21
22/* Some toolchains use a `_' prefix for all user symbols. */
23#ifdef CONFIG_SYMBOL_PREFIX
24#define MODULE_SYMBOL_PREFIX CONFIG_SYMBOL_PREFIX
25#else
26#define MODULE_SYMBOL_PREFIX ""
27#endif
28
29
20/* Are we using CONFIG_MODVERSIONS? */ 30/* Are we using CONFIG_MODVERSIONS? */
21int modversions = 0; 31int modversions = 0;
22/* Warn about undefined symbols? (do so if we have vmlinux) */ 32/* Warn about undefined symbols? (do so if we have vmlinux) */
@@ -244,7 +254,7 @@ static enum export export_no(const char *s)
244 return export_unknown; 254 return export_unknown;
245} 255}
246 256
247static enum export export_from_sec(struct elf_info *elf, Elf_Section sec) 257static enum export export_from_sec(struct elf_info *elf, unsigned int sec)
248{ 258{
249 if (sec == elf->export_sec) 259 if (sec == elf->export_sec)
250 return export_plain; 260 return export_plain;
@@ -364,6 +374,8 @@ static int parse_elf(struct elf_info *info, const char *filename)
364 Elf_Ehdr *hdr; 374 Elf_Ehdr *hdr;
365 Elf_Shdr *sechdrs; 375 Elf_Shdr *sechdrs;
366 Elf_Sym *sym; 376 Elf_Sym *sym;
377 const char *secstrings;
378 unsigned int symtab_idx = ~0U, symtab_shndx_idx = ~0U;
367 379
368 hdr = grab_file(filename, &info->size); 380 hdr = grab_file(filename, &info->size);
369 if (!hdr) { 381 if (!hdr) {
@@ -408,8 +420,27 @@ static int parse_elf(struct elf_info *info, const char *filename)
408 return 0; 420 return 0;
409 } 421 }
410 422
423 if (hdr->e_shnum == 0) {
424 /*
425 * There are more than 64k sections,
426 * read count from .sh_size.
427 * note: it doesn't need shndx2secindex()
428 */
429 info->num_sections = TO_NATIVE(sechdrs[0].sh_size);
430 }
431 else {
432 info->num_sections = hdr->e_shnum;
433 }
434 if (hdr->e_shstrndx == SHN_XINDEX) {
435 info->secindex_strings =
436 shndx2secindex(TO_NATIVE(sechdrs[0].sh_link));
437 }
438 else {
439 info->secindex_strings = hdr->e_shstrndx;
440 }
441
411 /* Fix endianness in section headers */ 442 /* Fix endianness in section headers */
412 for (i = 0; i < hdr->e_shnum; i++) { 443 for (i = 0; i < info->num_sections; i++) {
413 sechdrs[i].sh_name = TO_NATIVE(sechdrs[i].sh_name); 444 sechdrs[i].sh_name = TO_NATIVE(sechdrs[i].sh_name);
414 sechdrs[i].sh_type = TO_NATIVE(sechdrs[i].sh_type); 445 sechdrs[i].sh_type = TO_NATIVE(sechdrs[i].sh_type);
415 sechdrs[i].sh_flags = TO_NATIVE(sechdrs[i].sh_flags); 446 sechdrs[i].sh_flags = TO_NATIVE(sechdrs[i].sh_flags);
@@ -422,9 +453,8 @@ static int parse_elf(struct elf_info *info, const char *filename)
422 sechdrs[i].sh_entsize = TO_NATIVE(sechdrs[i].sh_entsize); 453 sechdrs[i].sh_entsize = TO_NATIVE(sechdrs[i].sh_entsize);
423 } 454 }
424 /* Find symbol table. */ 455 /* Find symbol table. */
425 for (i = 1; i < hdr->e_shnum; i++) { 456 secstrings = (void *)hdr + sechdrs[info->secindex_strings].sh_offset;
426 const char *secstrings 457 for (i = 1; i < info->num_sections; i++) {
427 = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
428 const char *secname; 458 const char *secname;
429 int nobits = sechdrs[i].sh_type == SHT_NOBITS; 459 int nobits = sechdrs[i].sh_type == SHT_NOBITS;
430 460
@@ -451,17 +481,27 @@ static int parse_elf(struct elf_info *info, const char *filename)
451 info->export_unused_gpl_sec = i; 481 info->export_unused_gpl_sec = i;
452 else if (strcmp(secname, "__ksymtab_gpl_future") == 0) 482 else if (strcmp(secname, "__ksymtab_gpl_future") == 0)
453 info->export_gpl_future_sec = i; 483 info->export_gpl_future_sec = i;
454 else if (strcmp(secname, "__markers_strings") == 0)
455 info->markers_strings_sec = i;
456 484
457 if (sechdrs[i].sh_type != SHT_SYMTAB) 485 if (sechdrs[i].sh_type == SHT_SYMTAB) {
458 continue; 486 unsigned int sh_link_idx;
487 symtab_idx = i;
488 info->symtab_start = (void *)hdr +
489 sechdrs[i].sh_offset;
490 info->symtab_stop = (void *)hdr +
491 sechdrs[i].sh_offset + sechdrs[i].sh_size;
492 sh_link_idx = shndx2secindex(sechdrs[i].sh_link);
493 info->strtab = (void *)hdr +
494 sechdrs[sh_link_idx].sh_offset;
495 }
459 496
460 info->symtab_start = (void *)hdr + sechdrs[i].sh_offset; 497 /* 32bit section no. table? ("more than 64k sections") */
461 info->symtab_stop = (void *)hdr + sechdrs[i].sh_offset 498 if (sechdrs[i].sh_type == SHT_SYMTAB_SHNDX) {
462 + sechdrs[i].sh_size; 499 symtab_shndx_idx = i;
463 info->strtab = (void *)hdr + 500 info->symtab_shndx_start = (void *)hdr +
464 sechdrs[sechdrs[i].sh_link].sh_offset; 501 sechdrs[i].sh_offset;
502 info->symtab_shndx_stop = (void *)hdr +
503 sechdrs[i].sh_offset + sechdrs[i].sh_size;
504 }
465 } 505 }
466 if (!info->symtab_start) 506 if (!info->symtab_start)
467 fatal("%s has no symtab?\n", filename); 507 fatal("%s has no symtab?\n", filename);
@@ -473,6 +513,21 @@ static int parse_elf(struct elf_info *info, const char *filename)
473 sym->st_value = TO_NATIVE(sym->st_value); 513 sym->st_value = TO_NATIVE(sym->st_value);
474 sym->st_size = TO_NATIVE(sym->st_size); 514 sym->st_size = TO_NATIVE(sym->st_size);
475 } 515 }
516
517 if (symtab_shndx_idx != ~0U) {
518 Elf32_Word *p;
519 if (symtab_idx !=
520 shndx2secindex(sechdrs[symtab_shndx_idx].sh_link))
521 fatal("%s: SYMTAB_SHNDX has bad sh_link: %u!=%u\n",
522 filename,
523 shndx2secindex(sechdrs[symtab_shndx_idx].sh_link),
524 symtab_idx);
525 /* Fix endianness */
526 for (p = info->symtab_shndx_start; p < info->symtab_shndx_stop;
527 p++)
528 *p = TO_NATIVE(*p);
529 }
530
476 return 1; 531 return 1;
477} 532}
478 533
@@ -496,6 +551,11 @@ static int ignore_undef_symbol(struct elf_info *info, const char *symname)
496 strncmp(symname, "_rest32gpr_", sizeof("_rest32gpr_") - 1) == 0 || 551 strncmp(symname, "_rest32gpr_", sizeof("_rest32gpr_") - 1) == 0 ||
497 strncmp(symname, "_save32gpr_", sizeof("_save32gpr_") - 1) == 0) 552 strncmp(symname, "_save32gpr_", sizeof("_save32gpr_") - 1) == 0)
498 return 1; 553 return 1;
554 if (info->hdr->e_machine == EM_PPC64)
555 /* Special register function linked on all modules during final link of .ko */
556 if (strncmp(symname, "_restgpr0_", sizeof("_restgpr0_") - 1) == 0 ||
557 strncmp(symname, "_savegpr0_", sizeof("_savegpr0_") - 1) == 0)
558 return 1;
499 /* Do not ignore this symbol */ 559 /* Do not ignore this symbol */
500 return 0; 560 return 0;
501} 561}
@@ -507,7 +567,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info,
507 Elf_Sym *sym, const char *symname) 567 Elf_Sym *sym, const char *symname)
508{ 568{
509 unsigned int crc; 569 unsigned int crc;
510 enum export export = export_from_sec(info, sym->st_shndx); 570 enum export export = export_from_sec(info, get_secindex(info, sym));
511 571
512 switch (sym->st_shndx) { 572 switch (sym->st_shndx) {
513 case SHN_COMMON: 573 case SHN_COMMON:
@@ -515,7 +575,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info,
515 break; 575 break;
516 case SHN_ABS: 576 case SHN_ABS:
517 /* CRC'd symbol */ 577 /* CRC'd symbol */
518 if (memcmp(symname, CRC_PFX, strlen(CRC_PFX)) == 0) { 578 if (strncmp(symname, CRC_PFX, strlen(CRC_PFX)) == 0) {
519 crc = (unsigned int) sym->st_value; 579 crc = (unsigned int) sym->st_value;
520 sym_update_crc(symname + strlen(CRC_PFX), mod, crc, 580 sym_update_crc(symname + strlen(CRC_PFX), mod, crc,
521 export); 581 export);
@@ -559,7 +619,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info,
559 break; 619 break;
560 default: 620 default:
561 /* All exported symbols */ 621 /* All exported symbols */
562 if (memcmp(symname, KSYMTAB_PFX, strlen(KSYMTAB_PFX)) == 0) { 622 if (strncmp(symname, KSYMTAB_PFX, strlen(KSYMTAB_PFX)) == 0) {
563 sym_add_exported(symname + strlen(KSYMTAB_PFX), mod, 623 sym_add_exported(symname + strlen(KSYMTAB_PFX), mod,
564 export); 624 export);
565 } 625 }
@@ -649,19 +709,19 @@ static const char *sym_name(struct elf_info *elf, Elf_Sym *sym)
649 return "(unknown)"; 709 return "(unknown)";
650} 710}
651 711
652static const char *sec_name(struct elf_info *elf, int shndx) 712static const char *sec_name(struct elf_info *elf, int secindex)
653{ 713{
654 Elf_Shdr *sechdrs = elf->sechdrs; 714 Elf_Shdr *sechdrs = elf->sechdrs;
655 return (void *)elf->hdr + 715 return (void *)elf->hdr +
656 elf->sechdrs[elf->hdr->e_shstrndx].sh_offset + 716 elf->sechdrs[elf->secindex_strings].sh_offset +
657 sechdrs[shndx].sh_name; 717 sechdrs[secindex].sh_name;
658} 718}
659 719
660static const char *sech_name(struct elf_info *elf, Elf_Shdr *sechdr) 720static const char *sech_name(struct elf_info *elf, Elf_Shdr *sechdr)
661{ 721{
662 return (void *)elf->hdr + 722 return (void *)elf->hdr +
663 elf->sechdrs[elf->hdr->e_shstrndx].sh_offset + 723 elf->sechdrs[elf->secindex_strings].sh_offset +
664 sechdr->sh_name; 724 sechdr->sh_name;
665} 725}
666 726
667/* if sym is empty or point to a string 727/* if sym is empty or point to a string
@@ -691,7 +751,7 @@ static int number_prefix(const char *sym)
691 * The $ syntax is for sections where ld append a dot number 751 * The $ syntax is for sections where ld append a dot number
692 * to make section name unique. 752 * to make section name unique.
693 */ 753 */
694int match(const char *sym, const char * const pat[]) 754static int match(const char *sym, const char * const pat[])
695{ 755{
696 const char *p; 756 const char *p;
697 while (*pat) { 757 while (*pat) {
@@ -730,6 +790,8 @@ static const char *section_white_list[] =
730{ 790{
731 ".comment*", 791 ".comment*",
732 ".debug*", 792 ".debug*",
793 ".zdebug*", /* Compressed debug sections. */
794 ".GCC-command-line", /* mn10300 */
733 ".mdebug*", /* alpha, score, mips etc. */ 795 ".mdebug*", /* alpha, score, mips etc. */
734 ".pdr", /* alpha, score, mips etc. */ 796 ".pdr", /* alpha, score, mips etc. */
735 ".stab*", 797 ".stab*",
@@ -774,10 +836,13 @@ static void check_section(const char *modname, struct elf_info *elf,
774#define ALL_EXIT_TEXT_SECTIONS \ 836#define ALL_EXIT_TEXT_SECTIONS \
775 ".exit.text$", ".devexit.text$", ".cpuexit.text$", ".memexit.text$" 837 ".exit.text$", ".devexit.text$", ".cpuexit.text$", ".memexit.text$"
776 838
777#define ALL_INIT_SECTIONS INIT_SECTIONS, DEV_INIT_SECTIONS, \ 839#define ALL_XXXINIT_SECTIONS DEV_INIT_SECTIONS, CPU_INIT_SECTIONS, \
778 CPU_INIT_SECTIONS, MEM_INIT_SECTIONS 840 MEM_INIT_SECTIONS
779#define ALL_EXIT_SECTIONS EXIT_SECTIONS, DEV_EXIT_SECTIONS, \ 841#define ALL_XXXEXIT_SECTIONS DEV_EXIT_SECTIONS, CPU_EXIT_SECTIONS, \
780 CPU_EXIT_SECTIONS, MEM_EXIT_SECTIONS 842 MEM_EXIT_SECTIONS
843
844#define ALL_INIT_SECTIONS INIT_SECTIONS, ALL_XXXINIT_SECTIONS
845#define ALL_EXIT_SECTIONS EXIT_SECTIONS, ALL_XXXEXIT_SECTIONS
781 846
782#define DATA_SECTIONS ".data$", ".data.rel$" 847#define DATA_SECTIONS ".data$", ".data.rel$"
783#define TEXT_SECTIONS ".text$" 848#define TEXT_SECTIONS ".text$"
@@ -807,33 +872,29 @@ static const char *data_sections[] = { DATA_SECTIONS, NULL };
807 872
808 873
809/* symbols in .data that may refer to init/exit sections */ 874/* symbols in .data that may refer to init/exit sections */
810static const char *symbol_white_list[] = 875#define DEFAULT_SYMBOL_WHITE_LIST \
811{ 876 "*driver", \
812 "*driver", 877 "*_template", /* scsi uses *_template a lot */ \
813 "*_template", /* scsi uses *_template a lot */ 878 "*_timer", /* arm uses ops structures named _timer a lot */ \
814 "*_timer", /* arm uses ops structures named _timer a lot */ 879 "*_sht", /* scsi also used *_sht to some extent */ \
815 "*_sht", /* scsi also used *_sht to some extent */ 880 "*_ops", \
816 "*_ops", 881 "*_probe", \
817 "*_probe", 882 "*_probe_one", \
818 "*_probe_one", 883 "*_console"
819 "*_console",
820 NULL
821};
822 884
823static const char *head_sections[] = { ".head.text*", NULL }; 885static const char *head_sections[] = { ".head.text*", NULL };
824static const char *linker_symbols[] = 886static const char *linker_symbols[] =
825 { "__init_begin", "_sinittext", "_einittext", NULL }; 887 { "__init_begin", "_sinittext", "_einittext", NULL };
826 888
827enum mismatch { 889enum mismatch {
828 NO_MISMATCH, 890 TEXT_TO_ANY_INIT,
829 TEXT_TO_INIT, 891 DATA_TO_ANY_INIT,
830 DATA_TO_INIT, 892 TEXT_TO_ANY_EXIT,
831 TEXT_TO_EXIT, 893 DATA_TO_ANY_EXIT,
832 DATA_TO_EXIT, 894 XXXINIT_TO_SOME_INIT,
833 XXXINIT_TO_INIT, 895 XXXEXIT_TO_SOME_EXIT,
834 XXXEXIT_TO_EXIT, 896 ANY_INIT_TO_ANY_EXIT,
835 INIT_TO_EXIT, 897 ANY_EXIT_TO_ANY_INIT,
836 EXIT_TO_INIT,
837 EXPORT_TO_INIT_EXIT, 898 EXPORT_TO_INIT_EXIT,
838}; 899};
839 900
@@ -841,6 +902,7 @@ struct sectioncheck {
841 const char *fromsec[20]; 902 const char *fromsec[20];
842 const char *tosec[20]; 903 const char *tosec[20];
843 enum mismatch mismatch; 904 enum mismatch mismatch;
905 const char *symbol_white_list[20];
844}; 906};
845 907
846const struct sectioncheck sectioncheck[] = { 908const struct sectioncheck sectioncheck[] = {
@@ -850,80 +912,103 @@ const struct sectioncheck sectioncheck[] = {
850{ 912{
851 .fromsec = { TEXT_SECTIONS, NULL }, 913 .fromsec = { TEXT_SECTIONS, NULL },
852 .tosec = { ALL_INIT_SECTIONS, NULL }, 914 .tosec = { ALL_INIT_SECTIONS, NULL },
853 .mismatch = TEXT_TO_INIT, 915 .mismatch = TEXT_TO_ANY_INIT,
916 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
854}, 917},
855{ 918{
856 .fromsec = { DATA_SECTIONS, NULL }, 919 .fromsec = { DATA_SECTIONS, NULL },
857 .tosec = { ALL_INIT_SECTIONS, NULL }, 920 .tosec = { ALL_XXXINIT_SECTIONS, NULL },
858 .mismatch = DATA_TO_INIT, 921 .mismatch = DATA_TO_ANY_INIT,
922 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
923},
924{
925 .fromsec = { DATA_SECTIONS, NULL },
926 .tosec = { INIT_SECTIONS, NULL },
927 .mismatch = DATA_TO_ANY_INIT,
928 .symbol_white_list = {
929 "*_template", "*_timer", "*_sht", "*_ops",
930 "*_probe", "*_probe_one", "*_console", NULL
931 },
859}, 932},
860{ 933{
861 .fromsec = { TEXT_SECTIONS, NULL }, 934 .fromsec = { TEXT_SECTIONS, NULL },
862 .tosec = { ALL_EXIT_SECTIONS, NULL }, 935 .tosec = { ALL_EXIT_SECTIONS, NULL },
863 .mismatch = TEXT_TO_EXIT, 936 .mismatch = TEXT_TO_ANY_EXIT,
937 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
864}, 938},
865{ 939{
866 .fromsec = { DATA_SECTIONS, NULL }, 940 .fromsec = { DATA_SECTIONS, NULL },
867 .tosec = { ALL_EXIT_SECTIONS, NULL }, 941 .tosec = { ALL_EXIT_SECTIONS, NULL },
868 .mismatch = DATA_TO_EXIT, 942 .mismatch = DATA_TO_ANY_EXIT,
943 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
869}, 944},
870/* Do not reference init code/data from devinit/cpuinit/meminit code/data */ 945/* Do not reference init code/data from devinit/cpuinit/meminit code/data */
871{ 946{
872 .fromsec = { DEV_INIT_SECTIONS, CPU_INIT_SECTIONS, MEM_INIT_SECTIONS, NULL }, 947 .fromsec = { ALL_XXXINIT_SECTIONS, NULL },
873 .tosec = { INIT_SECTIONS, NULL }, 948 .tosec = { INIT_SECTIONS, NULL },
874 .mismatch = XXXINIT_TO_INIT, 949 .mismatch = XXXINIT_TO_SOME_INIT,
950 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
875}, 951},
876/* Do not reference cpuinit code/data from meminit code/data */ 952/* Do not reference cpuinit code/data from meminit code/data */
877{ 953{
878 .fromsec = { MEM_INIT_SECTIONS, NULL }, 954 .fromsec = { MEM_INIT_SECTIONS, NULL },
879 .tosec = { CPU_INIT_SECTIONS, NULL }, 955 .tosec = { CPU_INIT_SECTIONS, NULL },
880 .mismatch = XXXINIT_TO_INIT, 956 .mismatch = XXXINIT_TO_SOME_INIT,
957 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
881}, 958},
882/* Do not reference meminit code/data from cpuinit code/data */ 959/* Do not reference meminit code/data from cpuinit code/data */
883{ 960{
884 .fromsec = { CPU_INIT_SECTIONS, NULL }, 961 .fromsec = { CPU_INIT_SECTIONS, NULL },
885 .tosec = { MEM_INIT_SECTIONS, NULL }, 962 .tosec = { MEM_INIT_SECTIONS, NULL },
886 .mismatch = XXXINIT_TO_INIT, 963 .mismatch = XXXINIT_TO_SOME_INIT,
964 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
887}, 965},
888/* Do not reference exit code/data from devexit/cpuexit/memexit code/data */ 966/* Do not reference exit code/data from devexit/cpuexit/memexit code/data */
889{ 967{
890 .fromsec = { DEV_EXIT_SECTIONS, CPU_EXIT_SECTIONS, MEM_EXIT_SECTIONS, NULL }, 968 .fromsec = { ALL_XXXEXIT_SECTIONS, NULL },
891 .tosec = { EXIT_SECTIONS, NULL }, 969 .tosec = { EXIT_SECTIONS, NULL },
892 .mismatch = XXXEXIT_TO_EXIT, 970 .mismatch = XXXEXIT_TO_SOME_EXIT,
971 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
893}, 972},
894/* Do not reference cpuexit code/data from memexit code/data */ 973/* Do not reference cpuexit code/data from memexit code/data */
895{ 974{
896 .fromsec = { MEM_EXIT_SECTIONS, NULL }, 975 .fromsec = { MEM_EXIT_SECTIONS, NULL },
897 .tosec = { CPU_EXIT_SECTIONS, NULL }, 976 .tosec = { CPU_EXIT_SECTIONS, NULL },
898 .mismatch = XXXEXIT_TO_EXIT, 977 .mismatch = XXXEXIT_TO_SOME_EXIT,
978 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
899}, 979},
900/* Do not reference memexit code/data from cpuexit code/data */ 980/* Do not reference memexit code/data from cpuexit code/data */
901{ 981{
902 .fromsec = { CPU_EXIT_SECTIONS, NULL }, 982 .fromsec = { CPU_EXIT_SECTIONS, NULL },
903 .tosec = { MEM_EXIT_SECTIONS, NULL }, 983 .tosec = { MEM_EXIT_SECTIONS, NULL },
904 .mismatch = XXXEXIT_TO_EXIT, 984 .mismatch = XXXEXIT_TO_SOME_EXIT,
985 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
905}, 986},
906/* Do not use exit code/data from init code */ 987/* Do not use exit code/data from init code */
907{ 988{
908 .fromsec = { ALL_INIT_SECTIONS, NULL }, 989 .fromsec = { ALL_INIT_SECTIONS, NULL },
909 .tosec = { ALL_EXIT_SECTIONS, NULL }, 990 .tosec = { ALL_EXIT_SECTIONS, NULL },
910 .mismatch = INIT_TO_EXIT, 991 .mismatch = ANY_INIT_TO_ANY_EXIT,
992 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
911}, 993},
912/* Do not use init code/data from exit code */ 994/* Do not use init code/data from exit code */
913{ 995{
914 .fromsec = { ALL_EXIT_SECTIONS, NULL }, 996 .fromsec = { ALL_EXIT_SECTIONS, NULL },
915 .tosec = { ALL_INIT_SECTIONS, NULL }, 997 .tosec = { ALL_INIT_SECTIONS, NULL },
916 .mismatch = EXIT_TO_INIT, 998 .mismatch = ANY_EXIT_TO_ANY_INIT,
999 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
917}, 1000},
918/* Do not export init/exit functions or data */ 1001/* Do not export init/exit functions or data */
919{ 1002{
920 .fromsec = { "__ksymtab*", NULL }, 1003 .fromsec = { "__ksymtab*", NULL },
921 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL }, 1004 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
922 .mismatch = EXPORT_TO_INIT_EXIT 1005 .mismatch = EXPORT_TO_INIT_EXIT,
1006 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
923} 1007}
924}; 1008};
925 1009
926static int section_mismatch(const char *fromsec, const char *tosec) 1010static const struct sectioncheck *section_mismatch(
1011 const char *fromsec, const char *tosec)
927{ 1012{
928 int i; 1013 int i;
929 int elems = sizeof(sectioncheck) / sizeof(struct sectioncheck); 1014 int elems = sizeof(sectioncheck) / sizeof(struct sectioncheck);
@@ -932,10 +1017,10 @@ static int section_mismatch(const char *fromsec, const char *tosec)
932 for (i = 0; i < elems; i++) { 1017 for (i = 0; i < elems; i++) {
933 if (match(fromsec, check->fromsec) && 1018 if (match(fromsec, check->fromsec) &&
934 match(tosec, check->tosec)) 1019 match(tosec, check->tosec))
935 return check->mismatch; 1020 return check;
936 check++; 1021 check++;
937 } 1022 }
938 return NO_MISMATCH; 1023 return NULL;
939} 1024}
940 1025
941/** 1026/**
@@ -951,10 +1036,17 @@ static int section_mismatch(const char *fromsec, const char *tosec)
951 * fromsec = .data* 1036 * fromsec = .data*
952 * atsym =__param* 1037 * atsym =__param*
953 * 1038 *
1039 * Pattern 1a:
1040 * module_param_call() ops can refer to __init set function if permissions=0
1041 * The pattern is identified by:
1042 * tosec = .init.text
1043 * fromsec = .data*
1044 * atsym = __param_ops_*
1045 *
954 * Pattern 2: 1046 * Pattern 2:
955 * Many drivers utilise a *driver container with references to 1047 * Many drivers utilise a *driver container with references to
956 * add, remove, probe functions etc. 1048 * add, remove, probe functions etc.
957 * These functions may often be marked __init and we do not want to 1049 * These functions may often be marked __devinit and we do not want to
958 * warn here. 1050 * warn here.
959 * the pattern is identified by: 1051 * the pattern is identified by:
960 * tosec = init or exit section 1052 * tosec = init or exit section
@@ -975,7 +1067,8 @@ static int section_mismatch(const char *fromsec, const char *tosec)
975 * refsymname = __init_begin, _sinittext, _einittext 1067 * refsymname = __init_begin, _sinittext, _einittext
976 * 1068 *
977 **/ 1069 **/
978static int secref_whitelist(const char *fromsec, const char *fromsym, 1070static int secref_whitelist(const struct sectioncheck *mismatch,
1071 const char *fromsec, const char *fromsym,
979 const char *tosec, const char *tosym) 1072 const char *tosec, const char *tosym)
980{ 1073{
981 /* Check for pattern 1 */ 1074 /* Check for pattern 1 */
@@ -984,10 +1077,16 @@ static int secref_whitelist(const char *fromsec, const char *fromsym,
984 (strncmp(fromsym, "__param", strlen("__param")) == 0)) 1077 (strncmp(fromsym, "__param", strlen("__param")) == 0))
985 return 0; 1078 return 0;
986 1079
1080 /* Check for pattern 1a */
1081 if (strcmp(tosec, ".init.text") == 0 &&
1082 match(fromsec, data_sections) &&
1083 (strncmp(fromsym, "__param_ops_", strlen("__param_ops_")) == 0))
1084 return 0;
1085
987 /* Check for pattern 2 */ 1086 /* Check for pattern 2 */
988 if (match(tosec, init_exit_sections) && 1087 if (match(tosec, init_exit_sections) &&
989 match(fromsec, data_sections) && 1088 match(fromsec, data_sections) &&
990 match(fromsym, symbol_white_list)) 1089 match(fromsym, mismatch->symbol_white_list))
991 return 0; 1090 return 0;
992 1091
993 /* Check for pattern 3 */ 1092 /* Check for pattern 3 */
@@ -1016,11 +1115,14 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
1016 Elf_Sym *near = NULL; 1115 Elf_Sym *near = NULL;
1017 Elf64_Sword distance = 20; 1116 Elf64_Sword distance = 20;
1018 Elf64_Sword d; 1117 Elf64_Sword d;
1118 unsigned int relsym_secindex;
1019 1119
1020 if (relsym->st_name != 0) 1120 if (relsym->st_name != 0)
1021 return relsym; 1121 return relsym;
1122
1123 relsym_secindex = get_secindex(elf, relsym);
1022 for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) { 1124 for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) {
1023 if (sym->st_shndx != relsym->st_shndx) 1125 if (get_secindex(elf, sym) != relsym_secindex)
1024 continue; 1126 continue;
1025 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION) 1127 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
1026 continue; 1128 continue;
@@ -1082,9 +1184,9 @@ static Elf_Sym *find_elf_symbol2(struct elf_info *elf, Elf_Addr addr,
1082 for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) { 1184 for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) {
1083 const char *symsec; 1185 const char *symsec;
1084 1186
1085 if (sym->st_shndx >= SHN_LORESERVE) 1187 if (is_shndx_special(sym->st_shndx))
1086 continue; 1188 continue;
1087 symsec = sec_name(elf, sym->st_shndx); 1189 symsec = sec_name(elf, get_secindex(elf, sym));
1088 if (strcmp(symsec, sec) != 0) 1190 if (strcmp(symsec, sec) != 0)
1089 continue; 1191 continue;
1090 if (!is_valid_name(elf, sym)) 1192 if (!is_valid_name(elf, sym))
@@ -1107,6 +1209,9 @@ static Elf_Sym *find_elf_symbol2(struct elf_info *elf, Elf_Addr addr,
1107 * .cpuinit.data => __cpudata 1209 * .cpuinit.data => __cpudata
1108 * .memexitconst => __memconst 1210 * .memexitconst => __memconst
1109 * etc. 1211 * etc.
1212 *
1213 * The memory of returned value has been allocated on a heap. The user of this
1214 * method should free it after usage.
1110*/ 1215*/
1111static char *sec2annotation(const char *s) 1216static char *sec2annotation(const char *s)
1112{ 1217{
@@ -1129,9 +1234,9 @@ static char *sec2annotation(const char *s)
1129 strcat(p, "data "); 1234 strcat(p, "data ");
1130 else 1235 else
1131 strcat(p, " "); 1236 strcat(p, " ");
1132 return r; /* we leak her but we do not care */ 1237 return r;
1133 } else { 1238 } else {
1134 return ""; 1239 return strdup("");
1135 } 1240 }
1136} 1241}
1137 1242
@@ -1148,7 +1253,8 @@ static int is_function(Elf_Sym *sym)
1148 * Try to find symbols near it so user can find it. 1253 * Try to find symbols near it so user can find it.
1149 * Check whitelist before warning - it may be a false positive. 1254 * Check whitelist before warning - it may be a false positive.
1150 */ 1255 */
1151static void report_sec_mismatch(const char *modname, enum mismatch mismatch, 1256static void report_sec_mismatch(const char *modname,
1257 const struct sectioncheck *mismatch,
1152 const char *fromsec, 1258 const char *fromsec,
1153 unsigned long long fromaddr, 1259 unsigned long long fromaddr,
1154 const char *fromsym, 1260 const char *fromsym,
@@ -1158,6 +1264,8 @@ static void report_sec_mismatch(const char *modname, enum mismatch mismatch,
1158{ 1264{
1159 const char *from, *from_p; 1265 const char *from, *from_p;
1160 const char *to, *to_p; 1266 const char *to, *to_p;
1267 char *prl_from;
1268 char *prl_to;
1161 1269
1162 switch (from_is_func) { 1270 switch (from_is_func) {
1163 case 0: from = "variable"; from_p = ""; break; 1271 case 0: from = "variable"; from_p = ""; break;
@@ -1179,64 +1287,80 @@ static void report_sec_mismatch(const char *modname, enum mismatch mismatch,
1179 modname, fromsec, fromaddr, from, fromsym, from_p, to, tosec, 1287 modname, fromsec, fromaddr, from, fromsym, from_p, to, tosec,
1180 tosym, to_p); 1288 tosym, to_p);
1181 1289
1182 switch (mismatch) { 1290 switch (mismatch->mismatch) {
1183 case TEXT_TO_INIT: 1291 case TEXT_TO_ANY_INIT:
1292 prl_from = sec2annotation(fromsec);
1293 prl_to = sec2annotation(tosec);
1184 fprintf(stderr, 1294 fprintf(stderr,
1185 "The function %s%s() references\n" 1295 "The function %s%s() references\n"
1186 "the %s %s%s%s.\n" 1296 "the %s %s%s%s.\n"
1187 "This is often because %s lacks a %s\n" 1297 "This is often because %s lacks a %s\n"
1188 "annotation or the annotation of %s is wrong.\n", 1298 "annotation or the annotation of %s is wrong.\n",
1189 sec2annotation(fromsec), fromsym, 1299 prl_from, fromsym,
1190 to, sec2annotation(tosec), tosym, to_p, 1300 to, prl_to, tosym, to_p,
1191 fromsym, sec2annotation(tosec), tosym); 1301 fromsym, prl_to, tosym);
1302 free(prl_from);
1303 free(prl_to);
1192 break; 1304 break;
1193 case DATA_TO_INIT: { 1305 case DATA_TO_ANY_INIT: {
1194 const char **s = symbol_white_list; 1306 prl_to = sec2annotation(tosec);
1307 const char *const *s = mismatch->symbol_white_list;
1195 fprintf(stderr, 1308 fprintf(stderr,
1196 "The variable %s references\n" 1309 "The variable %s references\n"
1197 "the %s %s%s%s\n" 1310 "the %s %s%s%s\n"
1198 "If the reference is valid then annotate the\n" 1311 "If the reference is valid then annotate the\n"
1199 "variable with __init* or __refdata (see linux/init.h) " 1312 "variable with __init* or __refdata (see linux/init.h) "
1200 "or name the variable:\n", 1313 "or name the variable:\n",
1201 fromsym, to, sec2annotation(tosec), tosym, to_p); 1314 fromsym, to, prl_to, tosym, to_p);
1202 while (*s) 1315 while (*s)
1203 fprintf(stderr, "%s, ", *s++); 1316 fprintf(stderr, "%s, ", *s++);
1204 fprintf(stderr, "\n"); 1317 fprintf(stderr, "\n");
1318 free(prl_to);
1205 break; 1319 break;
1206 } 1320 }
1207 case TEXT_TO_EXIT: 1321 case TEXT_TO_ANY_EXIT:
1322 prl_to = sec2annotation(tosec);
1208 fprintf(stderr, 1323 fprintf(stderr,
1209 "The function %s() references a %s in an exit section.\n" 1324 "The function %s() references a %s in an exit section.\n"
1210 "Often the %s %s%s has valid usage outside the exit section\n" 1325 "Often the %s %s%s has valid usage outside the exit section\n"
1211 "and the fix is to remove the %sannotation of %s.\n", 1326 "and the fix is to remove the %sannotation of %s.\n",
1212 fromsym, to, to, tosym, to_p, sec2annotation(tosec), tosym); 1327 fromsym, to, to, tosym, to_p, prl_to, tosym);
1328 free(prl_to);
1213 break; 1329 break;
1214 case DATA_TO_EXIT: { 1330 case DATA_TO_ANY_EXIT: {
1215 const char **s = symbol_white_list; 1331 prl_to = sec2annotation(tosec);
1332 const char *const *s = mismatch->symbol_white_list;
1216 fprintf(stderr, 1333 fprintf(stderr,
1217 "The variable %s references\n" 1334 "The variable %s references\n"
1218 "the %s %s%s%s\n" 1335 "the %s %s%s%s\n"
1219 "If the reference is valid then annotate the\n" 1336 "If the reference is valid then annotate the\n"
1220 "variable with __exit* (see linux/init.h) or " 1337 "variable with __exit* (see linux/init.h) or "
1221 "name the variable:\n", 1338 "name the variable:\n",
1222 fromsym, to, sec2annotation(tosec), tosym, to_p); 1339 fromsym, to, prl_to, tosym, to_p);
1223 while (*s) 1340 while (*s)
1224 fprintf(stderr, "%s, ", *s++); 1341 fprintf(stderr, "%s, ", *s++);
1225 fprintf(stderr, "\n"); 1342 fprintf(stderr, "\n");
1343 free(prl_to);
1226 break; 1344 break;
1227 } 1345 }
1228 case XXXINIT_TO_INIT: 1346 case XXXINIT_TO_SOME_INIT:
1229 case XXXEXIT_TO_EXIT: 1347 case XXXEXIT_TO_SOME_EXIT:
1348 prl_from = sec2annotation(fromsec);
1349 prl_to = sec2annotation(tosec);
1230 fprintf(stderr, 1350 fprintf(stderr,
1231 "The %s %s%s%s references\n" 1351 "The %s %s%s%s references\n"
1232 "a %s %s%s%s.\n" 1352 "a %s %s%s%s.\n"
1233 "If %s is only used by %s then\n" 1353 "If %s is only used by %s then\n"
1234 "annotate %s with a matching annotation.\n", 1354 "annotate %s with a matching annotation.\n",
1235 from, sec2annotation(fromsec), fromsym, from_p, 1355 from, prl_from, fromsym, from_p,
1236 to, sec2annotation(tosec), tosym, to_p, 1356 to, prl_to, tosym, to_p,
1237 tosym, fromsym, tosym); 1357 tosym, fromsym, tosym);
1358 free(prl_from);
1359 free(prl_to);
1238 break; 1360 break;
1239 case INIT_TO_EXIT: 1361 case ANY_INIT_TO_ANY_EXIT:
1362 prl_from = sec2annotation(fromsec);
1363 prl_to = sec2annotation(tosec);
1240 fprintf(stderr, 1364 fprintf(stderr,
1241 "The %s %s%s%s references\n" 1365 "The %s %s%s%s references\n"
1242 "a %s %s%s%s.\n" 1366 "a %s %s%s%s.\n"
@@ -1245,11 +1369,15 @@ static void report_sec_mismatch(const char *modname, enum mismatch mismatch,
1245 "uses functionality in the exit path.\n" 1369 "uses functionality in the exit path.\n"
1246 "The fix is often to remove the %sannotation of\n" 1370 "The fix is often to remove the %sannotation of\n"
1247 "%s%s so it may be used outside an exit section.\n", 1371 "%s%s so it may be used outside an exit section.\n",
1248 from, sec2annotation(fromsec), fromsym, from_p, 1372 from, prl_from, fromsym, from_p,
1249 to, sec2annotation(tosec), tosym, to_p, 1373 to, prl_to, tosym, to_p,
1250 sec2annotation(tosec), tosym, to_p); 1374 prl_to, tosym, to_p);
1375 free(prl_from);
1376 free(prl_to);
1251 break; 1377 break;
1252 case EXIT_TO_INIT: 1378 case ANY_EXIT_TO_ANY_INIT:
1379 prl_from = sec2annotation(fromsec);
1380 prl_to = sec2annotation(tosec);
1253 fprintf(stderr, 1381 fprintf(stderr,
1254 "The %s %s%s%s references\n" 1382 "The %s %s%s%s references\n"
1255 "a %s %s%s%s.\n" 1383 "a %s %s%s%s.\n"
@@ -1258,18 +1386,20 @@ static void report_sec_mismatch(const char *modname, enum mismatch mismatch,
1258 "uses functionality in the init path.\n" 1386 "uses functionality in the init path.\n"
1259 "The fix is often to remove the %sannotation of\n" 1387 "The fix is often to remove the %sannotation of\n"
1260 "%s%s so it may be used outside an init section.\n", 1388 "%s%s so it may be used outside an init section.\n",
1261 from, sec2annotation(fromsec), fromsym, from_p, 1389 from, prl_from, fromsym, from_p,
1262 to, sec2annotation(tosec), tosym, to_p, 1390 to, prl_to, tosym, to_p,
1263 sec2annotation(tosec), tosym, to_p); 1391 prl_to, tosym, to_p);
1392 free(prl_from);
1393 free(prl_to);
1264 break; 1394 break;
1265 case EXPORT_TO_INIT_EXIT: 1395 case EXPORT_TO_INIT_EXIT:
1396 prl_to = sec2annotation(tosec);
1266 fprintf(stderr, 1397 fprintf(stderr,
1267 "The symbol %s is exported and annotated %s\n" 1398 "The symbol %s is exported and annotated %s\n"
1268 "Fix this by removing the %sannotation of %s " 1399 "Fix this by removing the %sannotation of %s "
1269 "or drop the export.\n", 1400 "or drop the export.\n",
1270 tosym, sec2annotation(tosec), sec2annotation(tosec), tosym); 1401 tosym, prl_to, prl_to, tosym);
1271 case NO_MISMATCH: 1402 free(prl_to);
1272 /* To get warnings on missing members */
1273 break; 1403 break;
1274 } 1404 }
1275 fprintf(stderr, "\n"); 1405 fprintf(stderr, "\n");
@@ -1279,11 +1409,11 @@ static void check_section_mismatch(const char *modname, struct elf_info *elf,
1279 Elf_Rela *r, Elf_Sym *sym, const char *fromsec) 1409 Elf_Rela *r, Elf_Sym *sym, const char *fromsec)
1280{ 1410{
1281 const char *tosec; 1411 const char *tosec;
1282 enum mismatch mismatch; 1412 const struct sectioncheck *mismatch;
1283 1413
1284 tosec = sec_name(elf, sym->st_shndx); 1414 tosec = sec_name(elf, get_secindex(elf, sym));
1285 mismatch = section_mismatch(fromsec, tosec); 1415 mismatch = section_mismatch(fromsec, tosec);
1286 if (mismatch != NO_MISMATCH) { 1416 if (mismatch) {
1287 Elf_Sym *to; 1417 Elf_Sym *to;
1288 Elf_Sym *from; 1418 Elf_Sym *from;
1289 const char *tosym; 1419 const char *tosym;
@@ -1295,7 +1425,8 @@ static void check_section_mismatch(const char *modname, struct elf_info *elf,
1295 tosym = sym_name(elf, to); 1425 tosym = sym_name(elf, to);
1296 1426
1297 /* check whitelist - we may ignore it */ 1427 /* check whitelist - we may ignore it */
1298 if (secref_whitelist(fromsec, fromsym, tosec, tosym)) { 1428 if (secref_whitelist(mismatch,
1429 fromsec, fromsym, tosec, tosym)) {
1299 report_sec_mismatch(modname, mismatch, 1430 report_sec_mismatch(modname, mismatch,
1300 fromsec, r->r_offset, fromsym, 1431 fromsec, r->r_offset, fromsym,
1301 is_function(from), tosec, tosym, 1432 is_function(from), tosec, tosym,
@@ -1308,10 +1439,10 @@ static unsigned int *reloc_location(struct elf_info *elf,
1308 Elf_Shdr *sechdr, Elf_Rela *r) 1439 Elf_Shdr *sechdr, Elf_Rela *r)
1309{ 1440{
1310 Elf_Shdr *sechdrs = elf->sechdrs; 1441 Elf_Shdr *sechdrs = elf->sechdrs;
1311 int section = sechdr->sh_info; 1442 int section = shndx2secindex(sechdr->sh_info);
1312 1443
1313 return (void *)elf->hdr + sechdrs[section].sh_offset + 1444 return (void *)elf->hdr + sechdrs[section].sh_offset +
1314 (r->r_offset - sechdrs[section].sh_addr); 1445 r->r_offset;
1315} 1446}
1316 1447
1317static int addend_386_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) 1448static int addend_386_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
@@ -1416,7 +1547,7 @@ static void section_rela(const char *modname, struct elf_info *elf,
1416 r.r_addend = TO_NATIVE(rela->r_addend); 1547 r.r_addend = TO_NATIVE(rela->r_addend);
1417 sym = elf->symtab_start + r_sym; 1548 sym = elf->symtab_start + r_sym;
1418 /* Skip special sections */ 1549 /* Skip special sections */
1419 if (sym->st_shndx >= SHN_LORESERVE) 1550 if (is_shndx_special(sym->st_shndx))
1420 continue; 1551 continue;
1421 check_section_mismatch(modname, elf, &r, sym, fromsec); 1552 check_section_mismatch(modname, elf, &r, sym, fromsec);
1422 } 1553 }
@@ -1474,7 +1605,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
1474 } 1605 }
1475 sym = elf->symtab_start + r_sym; 1606 sym = elf->symtab_start + r_sym;
1476 /* Skip special sections */ 1607 /* Skip special sections */
1477 if (sym->st_shndx >= SHN_LORESERVE) 1608 if (is_shndx_special(sym->st_shndx))
1478 continue; 1609 continue;
1479 check_section_mismatch(modname, elf, &r, sym, fromsec); 1610 check_section_mismatch(modname, elf, &r, sym, fromsec);
1480 } 1611 }
@@ -1499,7 +1630,7 @@ static void check_sec_ref(struct module *mod, const char *modname,
1499 Elf_Shdr *sechdrs = elf->sechdrs; 1630 Elf_Shdr *sechdrs = elf->sechdrs;
1500 1631
1501 /* Walk through all sections */ 1632 /* Walk through all sections */
1502 for (i = 0; i < elf->hdr->e_shnum; i++) { 1633 for (i = 0; i < elf->num_sections; i++) {
1503 check_section(modname, elf, &elf->sechdrs[i]); 1634 check_section(modname, elf, &elf->sechdrs[i]);
1504 /* We want to process only relocation sections and not .init */ 1635 /* We want to process only relocation sections and not .init */
1505 if (sechdrs[i].sh_type == SHT_RELA) 1636 if (sechdrs[i].sh_type == SHT_RELA)
@@ -1509,62 +1640,6 @@ static void check_sec_ref(struct module *mod, const char *modname,
1509 } 1640 }
1510} 1641}
1511 1642
1512static void get_markers(struct elf_info *info, struct module *mod)
1513{
1514 const Elf_Shdr *sh = &info->sechdrs[info->markers_strings_sec];
1515 const char *strings = (const char *) info->hdr + sh->sh_offset;
1516 const Elf_Sym *sym, *first_sym, *last_sym;
1517 size_t n;
1518
1519 if (!info->markers_strings_sec)
1520 return;
1521
1522 /*
1523 * First count the strings. We look for all the symbols defined
1524 * in the __markers_strings section named __mstrtab_*. For
1525 * these local names, the compiler puts a random .NNN suffix on,
1526 * so the names don't correspond exactly.
1527 */
1528 first_sym = last_sym = NULL;
1529 n = 0;
1530 for (sym = info->symtab_start; sym < info->symtab_stop; sym++)
1531 if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT &&
1532 sym->st_shndx == info->markers_strings_sec &&
1533 !strncmp(info->strtab + sym->st_name,
1534 "__mstrtab_", sizeof "__mstrtab_" - 1)) {
1535 if (first_sym == NULL)
1536 first_sym = sym;
1537 last_sym = sym;
1538 ++n;
1539 }
1540
1541 if (n == 0)
1542 return;
1543
1544 /*
1545 * Now collect each name and format into a line for the output.
1546 * Lines look like:
1547 * marker_name vmlinux marker %s format %d
1548 * The format string after the second \t can use whitespace.
1549 */
1550 mod->markers = NOFAIL(malloc(sizeof mod->markers[0] * n));
1551 mod->nmarkers = n;
1552
1553 n = 0;
1554 for (sym = first_sym; sym <= last_sym; sym++)
1555 if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT &&
1556 sym->st_shndx == info->markers_strings_sec &&
1557 !strncmp(info->strtab + sym->st_name,
1558 "__mstrtab_", sizeof "__mstrtab_" - 1)) {
1559 const char *name = strings + sym->st_value;
1560 const char *fmt = strchr(name, '\0') + 1;
1561 char *line = NULL;
1562 asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt);
1563 NOFAIL(line);
1564 mod->markers[n++] = line;
1565 }
1566}
1567
1568static void read_symbols(char *modname) 1643static void read_symbols(char *modname)
1569{ 1644{
1570 const char *symname; 1645 const char *symname;
@@ -1620,8 +1695,6 @@ static void read_symbols(char *modname)
1620 get_src_version(modname, mod->srcversion, 1695 get_src_version(modname, mod->srcversion,
1621 sizeof(mod->srcversion)-1); 1696 sizeof(mod->srcversion)-1);
1622 1697
1623 get_markers(&info, mod);
1624
1625 parse_elf_finish(&info); 1698 parse_elf_finish(&info);
1626 1699
1627 /* Our trick to get versioning for module struct etc. - it's 1700 /* Our trick to get versioning for module struct etc. - it's
@@ -1746,7 +1819,7 @@ static void add_header(struct buffer *b, struct module *mod)
1746 buf_printf(b, "};\n"); 1819 buf_printf(b, "};\n");
1747} 1820}
1748 1821
1749void add_staging_flag(struct buffer *b, const char *name) 1822static void add_staging_flag(struct buffer *b, const char *name)
1750{ 1823{
1751 static const char *staging_dir = "drivers/staging"; 1824 static const char *staging_dir = "drivers/staging";
1752 1825
@@ -1976,96 +2049,6 @@ static void write_dump(const char *fname)
1976 write_if_changed(&buf, fname); 2049 write_if_changed(&buf, fname);
1977} 2050}
1978 2051
1979static void add_marker(struct module *mod, const char *name, const char *fmt)
1980{
1981 char *line = NULL;
1982 asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt);
1983 NOFAIL(line);
1984
1985 mod->markers = NOFAIL(realloc(mod->markers, ((mod->nmarkers + 1) *
1986 sizeof mod->markers[0])));
1987 mod->markers[mod->nmarkers++] = line;
1988}
1989
1990static void read_markers(const char *fname)
1991{
1992 unsigned long size, pos = 0;
1993 void *file = grab_file(fname, &size);
1994 char *line;
1995
1996 if (!file) /* No old markers, silently ignore */
1997 return;
1998
1999 while ((line = get_next_line(&pos, file, size))) {
2000 char *marker, *modname, *fmt;
2001 struct module *mod;
2002
2003 marker = line;
2004 modname = strchr(marker, '\t');
2005 if (!modname)
2006 goto fail;
2007 *modname++ = '\0';
2008 fmt = strchr(modname, '\t');
2009 if (!fmt)
2010 goto fail;
2011 *fmt++ = '\0';
2012 if (*marker == '\0' || *modname == '\0')
2013 goto fail;
2014
2015 mod = find_module(modname);
2016 if (!mod) {
2017 mod = new_module(modname);
2018 mod->skip = 1;
2019 }
2020 if (is_vmlinux(modname)) {
2021 have_vmlinux = 1;
2022 mod->skip = 0;
2023 }
2024
2025 if (!mod->skip)
2026 add_marker(mod, marker, fmt);
2027 }
2028 release_file(file, size);
2029 return;
2030fail:
2031 fatal("parse error in markers list file\n");
2032}
2033
2034static int compare_strings(const void *a, const void *b)
2035{
2036 return strcmp(*(const char **) a, *(const char **) b);
2037}
2038
2039static void write_markers(const char *fname)
2040{
2041 struct buffer buf = { };
2042 struct module *mod;
2043 size_t i;
2044
2045 for (mod = modules; mod; mod = mod->next)
2046 if ((!external_module || !mod->skip) && mod->markers != NULL) {
2047 /*
2048 * Sort the strings so we can skip duplicates when
2049 * we write them out.
2050 */
2051 qsort(mod->markers, mod->nmarkers,
2052 sizeof mod->markers[0], &compare_strings);
2053 for (i = 0; i < mod->nmarkers; ++i) {
2054 char *line = mod->markers[i];
2055 buf_write(&buf, line, strlen(line));
2056 while (i + 1 < mod->nmarkers &&
2057 !strcmp(mod->markers[i],
2058 mod->markers[i + 1]))
2059 free(mod->markers[i++]);
2060 free(mod->markers[i]);
2061 }
2062 free(mod->markers);
2063 mod->markers = NULL;
2064 }
2065
2066 write_if_changed(&buf, fname);
2067}
2068
2069struct ext_sym_list { 2052struct ext_sym_list {
2070 struct ext_sym_list *next; 2053 struct ext_sym_list *next;
2071 const char *file; 2054 const char *file;
@@ -2077,8 +2060,6 @@ int main(int argc, char **argv)
2077 struct buffer buf = { }; 2060 struct buffer buf = { };
2078 char *kernel_read = NULL, *module_read = NULL; 2061 char *kernel_read = NULL, *module_read = NULL;
2079 char *dump_write = NULL; 2062 char *dump_write = NULL;
2080 char *markers_read = NULL;
2081 char *markers_write = NULL;
2082 int opt; 2063 int opt;
2083 int err; 2064 int err;
2084 struct ext_sym_list *extsym_iter; 2065 struct ext_sym_list *extsym_iter;
@@ -2122,12 +2103,6 @@ int main(int argc, char **argv)
2122 case 'w': 2103 case 'w':
2123 warn_unresolved = 1; 2104 warn_unresolved = 1;
2124 break; 2105 break;
2125 case 'M':
2126 markers_write = optarg;
2127 break;
2128 case 'K':
2129 markers_read = optarg;
2130 break;
2131 default: 2106 default:
2132 exit(1); 2107 exit(1);
2133 } 2108 }
@@ -2182,11 +2157,5 @@ int main(int argc, char **argv)
2182 "'make CONFIG_DEBUG_SECTION_MISMATCH=y'\n", 2157 "'make CONFIG_DEBUG_SECTION_MISMATCH=y'\n",
2183 sec_mismatch_count); 2158 sec_mismatch_count);
2184 2159
2185 if (markers_read)
2186 read_markers(markers_read);
2187
2188 if (markers_write)
2189 write_markers(markers_write);
2190
2191 return err; 2160 return err;
2192} 2161}
diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
index 09f58e33d227..0388cfccac8d 100644
--- a/scripts/mod/modpost.h
+++ b/scripts/mod/modpost.h
@@ -112,8 +112,6 @@ struct module {
112 int has_init; 112 int has_init;
113 int has_cleanup; 113 int has_cleanup;
114 struct buffer dev_table_buf; 114 struct buffer dev_table_buf;
115 char **markers;
116 size_t nmarkers;
117 char srcversion[25]; 115 char srcversion[25];
118}; 116};
119 117
@@ -128,12 +126,54 @@ struct elf_info {
128 Elf_Section export_gpl_sec; 126 Elf_Section export_gpl_sec;
129 Elf_Section export_unused_gpl_sec; 127 Elf_Section export_unused_gpl_sec;
130 Elf_Section export_gpl_future_sec; 128 Elf_Section export_gpl_future_sec;
131 Elf_Section markers_strings_sec;
132 const char *strtab; 129 const char *strtab;
133 char *modinfo; 130 char *modinfo;
134 unsigned int modinfo_len; 131 unsigned int modinfo_len;
132
133 /* support for 32bit section numbers */
134
135 unsigned int num_sections; /* max_secindex + 1 */
136 unsigned int secindex_strings;
137 /* if Nth symbol table entry has .st_shndx = SHN_XINDEX,
138 * take shndx from symtab_shndx_start[N] instead */
139 Elf32_Word *symtab_shndx_start;
140 Elf32_Word *symtab_shndx_stop;
135}; 141};
136 142
143static inline int is_shndx_special(unsigned int i)
144{
145 return i != SHN_XINDEX && i >= SHN_LORESERVE && i <= SHN_HIRESERVE;
146}
147
148/* shndx is in [0..SHN_LORESERVE) U (SHN_HIRESERVE, 0xfffffff], thus:
149 * shndx == 0 <=> sechdrs[0]
150 * ......
151 * shndx == SHN_LORESERVE-1 <=> sechdrs[SHN_LORESERVE-1]
152 * shndx == SHN_HIRESERVE+1 <=> sechdrs[SHN_LORESERVE]
153 * shndx == SHN_HIRESERVE+2 <=> sechdrs[SHN_LORESERVE+1]
154 * ......
155 * fyi: sym->st_shndx is uint16, SHN_LORESERVE = ff00, SHN_HIRESERVE = ffff,
156 * so basically we map 0000..feff -> 0000..feff
157 * ff00..ffff -> (you are a bad boy, dont do it)
158 * 10000..xxxx -> ff00..(xxxx-0x100)
159 */
160static inline unsigned int shndx2secindex(unsigned int i)
161{
162 if (i <= SHN_HIRESERVE)
163 return i;
164 return i - (SHN_HIRESERVE + 1 - SHN_LORESERVE);
165}
166
167/* Accessor for sym->st_shndx, hides ugliness of "64k sections" */
168static inline unsigned int get_secindex(const struct elf_info *info,
169 const Elf_Sym *sym)
170{
171 if (sym->st_shndx != SHN_XINDEX)
172 return sym->st_shndx;
173 return shndx2secindex(info->symtab_shndx_start[sym -
174 info->symtab_start]);
175}
176
137/* file2alias.c */ 177/* file2alias.c */
138extern unsigned int cross_build; 178extern unsigned int cross_build;
139void handle_moddevtable(struct module *mod, struct elf_info *info, 179void handle_moddevtable(struct module *mod, struct elf_info *info,
diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
index aadc5223dcdb..ecf9c7dc1825 100644
--- a/scripts/mod/sumversion.c
+++ b/scripts/mod/sumversion.c
@@ -334,8 +334,6 @@ static int parse_source_files(const char *objfile, struct md4_ctx *md)
334 deps_drivers/net/dummy.o := \ 334 deps_drivers/net/dummy.o := \
335 drivers/net/dummy.c \ 335 drivers/net/dummy.c \
336 $(wildcard include/config/net/fastroute.h) \ 336 $(wildcard include/config/net/fastroute.h) \
337 include/linux/config.h \
338 $(wildcard include/config/h.h) \
339 include/linux/module.h \ 337 include/linux/module.h \
340 338
341 Sum all files in the same dir or subdirs. 339 Sum all files in the same dir or subdirs.