1 /* Generate assembler source containing symbol information
3 * Copyright 2002 by Kai Germaschewski
5 * This software may be used and distributed according to the terms
6 * of the GNU General Public License, incorporated herein by reference.
8 * Usage: nm -n vmlinux | scripts/kallsyms [--all-symbols] > symbols.S
17 unsigned long long addr
;
23 static struct sym_entry
*table
;
25 static unsigned long long _stext
, _etext
, _sinittext
, _einittext
;
26 static int all_symbols
= 0;
31 fprintf(stderr
, "Usage: kallsyms [--all-symbols] < in.map > out.S\n");
36 read_symbol(FILE *in
, struct sym_entry
*s
)
41 rc
= fscanf(in
, "%llx %c %499s\n", &s
->addr
, &s
->type
, str
);
50 /* Ignore most absolute/undefined (?) symbols. */
51 if (strcmp(str
, "_stext") == 0)
53 else if (strcmp(str
, "_etext") == 0)
55 else if (strcmp(str
, "_sinittext") == 0)
57 else if (strcmp(str
, "_einittext") == 0)
59 else if (toupper(s
->type
) == 'A' || toupper(s
->type
) == 'U')
67 symbol_valid(struct sym_entry
*s
)
70 if ((s
->addr
< _stext
|| s
->addr
> _etext
)
71 && (s
->addr
< _sinittext
|| s
->addr
> _einittext
))
75 /* Exclude symbols which vary between passes. Passes 1 and 2 must have
76 * identical symbol lists. The kallsyms_* symbols below are only added
77 * after pass 1, they would be included in pass 2 when --all-symbols is
78 * specified so exclude them to get a stable symbol list.
80 if (strstr(s
->sym
, "_compiled.") ||
81 strcmp(s
->sym
, "kallsyms_addresses") == 0 ||
82 strcmp(s
->sym
, "kallsyms_num_syms") == 0 ||
83 strcmp(s
->sym
, "kallsyms_names") == 0)
86 /* Exclude linker generated symbols which vary between passes */
87 if (strcmp(s
->sym
, "_SDA_BASE_") == 0 || /* ppc */
88 strcmp(s
->sym
, "_SDA2_BASE_") == 0) /* ppc */
100 table
= realloc(table
, sizeof(*table
) * size
);
102 fprintf(stderr
, "out of memory\n");
106 if (read_symbol(in
, &table
[cnt
]) == 0)
117 printf("#include <asm/types.h>\n");
118 printf("#if BITS_PER_LONG == 64\n");
119 printf("#define PTR .quad\n");
120 printf("#define ALGN .align 8\n");
122 printf("#define PTR .long\n");
123 printf("#define ALGN .align 4\n");
128 printf(".globl kallsyms_addresses\n");
130 printf("kallsyms_addresses:\n");
131 for (i
= 0; i
< cnt
; i
++) {
132 if (!symbol_valid(&table
[i
]))
135 printf("\tPTR\t%#llx\n", table
[i
].addr
);
140 printf(".globl kallsyms_num_syms\n");
142 printf("kallsyms_num_syms:\n");
143 printf("\tPTR\t%d\n", valid
);
146 printf(".globl kallsyms_names\n");
148 printf("kallsyms_names:\n");
150 for (i
= 0; i
< cnt
; i
++) {
153 if (!symbol_valid(&table
[i
]))
156 for (k
= 0; table
[i
].sym
[k
] && table
[i
].sym
[k
] == prev
[k
]; ++k
)
159 printf("\t.byte 0x%02x\n\t.asciz\t\"%s\"\n", k
, table
[i
].sym
+ k
);
166 main(int argc
, char **argv
)
168 if (argc
== 2 && strcmp(argv
[1], "--all-symbols") == 0)