159
176
/* Covers gpl-only and normal symbols. */
160
177
if (strstarts(ptr+1, ksymstr))
161
add_symbol(ptr+1+ksymstr_len, NULL);
178
add_symbol(ptr+1+ksymstr_len, 0, NULL);
164
181
fclose(system_map);
166
/* __this_module is magic inserted by kernel loader. */
167
add_symbol("__this_module", NULL);
168
/* On S390, this is faked up too */
169
add_symbol("_GLOBAL_OFFSET_TABLE_", NULL);
185
static void load_module_symvers(const char *filename)
187
FILE *module_symvers;
190
module_symvers = fopen(filename, "r");
192
fatal("Could not open '%s': %s\n", filename, strerror(errno));
194
/* eg. "0xb352177e\tfind_first_bit\tvmlinux\tEXPORT_SYMBOL" */
195
while (fgets(line, sizeof(line)-1, module_symvers)) {
196
const char *ver, *sym, *where;
198
ver = strtok(line, " \t");
199
sym = strtok(NULL, " \t");
200
where = strtok(NULL, " \t");
201
if (!ver || !sym || !where)
204
if (streq(where, "vmlinux"))
205
add_symbol(sym, strtoull(ver, NULL, 16), NULL);
208
fclose(module_symvers);
172
212
static struct option options[] = { { "all", 0, NULL, 'a' },
173
213
{ "quick", 0, NULL, 'A' },
174
214
{ "basedir", 1, NULL, 'b' },
215
{ "config", 1, NULL, 'C' },
216
{ "symvers", 1, NULL, 'E' },
217
{ "filesyms", 1, NULL, 'F' },
175
218
{ "errsyms", 0, NULL, 'e' },
176
{ "filesyms", 1, NULL, 'F' },
177
{ "help", 0, NULL, 'h' },
178
{ "show", 0, NULL, 'n' },
179
{ "dry-run", 0, NULL, 'n' },
219
{ "unresolved-error", 0, NULL, 'u' },
180
220
{ "quiet", 0, NULL, 'q' },
181
221
{ "root", 0, NULL, 'r' },
182
{ "unresolved-error", 0, NULL, 'u' },
183
222
{ "verbose", 0, NULL, 'v' },
223
{ "show", 0, NULL, 'n' },
224
{ "dry-run", 0, NULL, 'n' },
225
{ "help", 0, NULL, 'h' },
184
226
{ "version", 0, NULL, 'V' },
185
{ "config", 1, NULL, 'C' },
186
{ "warn", 1, NULL, 'w' },
227
{ "warn", 0, NULL, 'w' },
187
228
{ "map", 0, NULL, 'm' },
188
229
{ NULL, 0, NULL, 0 } };
276
320
INIT_LIST_HEAD(&new->dep_list);
277
321
new->order = INDEX_PRIORITY_MIN;
279
new->data = grab_file(new->pathname, &new->len);
323
new->file = grab_elf_file(new->pathname);
281
325
warn("Can't read module %s: %s\n",
282
326
new->pathname, strerror(errno));
286
switch (elf_ident(new->data, new->len, &new->conv)) {
288
new->ops = &mod_ops32;
291
new->ops = &mod_ops64;
294
warn("Module %s is not an elf object\n", new->pathname);
297
warn("Module %s has unknown endianness\n", new->pathname);
300
warn("Module %s has unknown word size\n", new->pathname);
306
release_file(new->data, new->len);
312
333
struct module_traverse
691
/* Calculate the dependencies for this module */
692
static void calculate_deps(struct module *module)
695
struct string_table *symnames;
696
struct string_table *symtypes;
697
uint64_t *symvers = NULL;
698
struct elf_file *file;
700
module->num_deps = 0;
704
symnames = file->ops->load_dep_syms(file, &symtypes,
705
check_symvers ? &symvers : NULL);
706
if (!symnames || !symtypes)
709
for (i = 0; i < symnames->cnt; i++) {
712
struct module *owner;
715
name = symnames->str[i];
716
ver = symvers ? symvers[i] : 0;
717
weak = (*(symtypes->str[i]) == 'W');
718
owner = find_symbol(name, ver, module->pathname, weak);
720
info("%s needs \"%s\": %s\n",
721
module->pathname, name,
723
add_dep(module, owner);
670
732
static struct module *parse_modules(struct module *list)
672
734
struct module *i;
735
struct elf_file *file;
736
struct string_table *syms;
674
739
for (i = list; i; i = i->next) {
675
i->ops->load_symbols(i);
676
i->ops->fetch_tables(i);
740
uint64_t *symvers = NULL;
742
syms = file->ops->load_symbols(file,
743
check_symvers ? &symvers : NULL);
745
for (j = 0; j < syms->cnt; j++)
746
add_symbol(syms->str[j],
747
symvers ? symvers[j] : 0, i);
751
file->ops->fetch_tables(file, &i->tables);
679
754
for (i = list; i; i = i->next)
680
i->ops->calculate_deps(i);
682
757
/* Strip out modules with dependency loops. */
747
822
static void output_aliases(struct module *modules, FILE *out, char *dirname)
749
824
struct module *i;
825
struct elf_file *file;
826
struct string_table *tbl;
753
829
fprintf(out, "# Aliases extracted from modules themselves.\n");
754
830
for (i = modules; i; i = i->next) {
755
831
char modname[strlen(i->pathname)+1];
757
834
filename2modname(modname, i->pathname);
759
836
/* Grab from old-style .modalias section. */
760
for (p = i->ops->get_aliases(i, &size);
762
p = next_string(p, &size))
763
fprintf(out, "alias %s %s\n", p, modname);
837
tbl = file->ops->load_strings(file, ".modalias", NULL, fatal);
838
for (j = 0; tbl && j < tbl->cnt; j++)
839
fprintf(out, "alias %s %s\n", tbl->str[j], modname);
765
/* Grab form new-style .modinfo section. */
766
for (p = i->ops->get_modinfo(i, &size);
768
p = next_string(p, &size)) {
842
/* Grab from new-style .modinfo section. */
843
tbl = file->ops->load_strings(file, ".modinfo", NULL, fatal);
844
for (j = 0; tbl && j < tbl->cnt; j++) {
845
const char *p = tbl->str[j];
769
846
if (strstarts(p, "alias="))
770
847
fprintf(out, "alias %s %s\n",
771
848
p + strlen("alias="), modname);
776
854
static void output_aliases_bin(struct module *modules, FILE *out, char *dirname)
778
856
struct module *i;
857
struct elf_file *file;
858
struct string_table *tbl;
782
861
struct index_node *index;
787
866
for (i = modules; i; i = i->next) {
788
867
char modname[strlen(i->pathname)+1];
790
870
filename2modname(modname, i->pathname);
792
872
/* Grab from old-style .modalias section. */
793
for (p = i->ops->get_aliases(i, &size);
795
p = next_string(p, &size)) {
796
alias = NOFAIL(strdup(p));
873
tbl = file->ops->load_strings(file, ".modalias", NULL, fatal);
874
for (j = 0; tbl && j < tbl->cnt; j++) {
875
alias = NOFAIL(strdup(tbl->str[j]));
797
876
underscores(alias);
798
877
duplicate = index_insert(index, alias, modname, i->order);
799
878
if (duplicate && warn_dups)
1147
1228
int main(int argc, char *argv[])
1149
1230
int opt, all = 0, maybe_all = 0, doing_stdout = 0;
1150
char *basedir = "", *dirname, *version, *badopt = NULL,
1231
char *basedir = "", *dirname, *version;
1232
char *system_map = NULL, *module_symvers = NULL;
1153
1234
const char *config = NULL;
1155
1236
if (native_endianness() == 0)
1158
/* Don't print out any errors just yet, we might want to exec
1159
backwards compat version. */
1161
while ((opt = getopt_long(argc, argv, "ab:ArehnqruvVF:C:wm", options, NULL))
1239
while ((opt = getopt_long(argc, argv, "aAb:C:E:F:euqrvnhVwm", options, NULL))
1168
1249
basedir = optarg;
1169
1250
skipchars = strlen(basedir);
1256
module_symvers = optarg;
1175
1260
system_map = optarg;