Makefile works again.
[AROS.git] / tools / collect-aros / backend-bfd.c
blobd4e5827bfa744f2b3c497f3b8266fe15fbeb357a
1 #include <bfd.h>
3 #include "misc.h"
4 #include "backend.h"
6 static void bfd_fatal(const char *msg)
8 fatal(msg, bfd_errmsg(bfd_get_error()));
11 int check_and_print_undefined_symbols(const char *file)
13 bfd_byte *cur, *minisyms;
14 asymbol *store;
15 long symcount;
16 unsigned int size;
17 int there_are_undefined_syms = 0;
18 bfd *abfd;
20 bfd_init();
24 (abfd = bfd_openr(file, "default")) == NULL ||
25 !bfd_check_format(abfd, bfd_object)
28 bfd_fatal(file);
31 symcount = bfd_read_minisymbols(abfd, FALSE, (void **)&minisyms, &size);
32 if (symcount < 0)
33 bfd_fatal (bfd_get_filename (abfd));
35 if (symcount == 0)
36 return 0;
38 store = bfd_make_empty_symbol(abfd);
39 if (store == NULL)
40 bfd_fatal(bfd_get_filename(abfd));
42 for (cur = minisyms; cur < (minisyms + (symcount * size)); cur += size)
44 asymbol *sym;
46 sym = bfd_minisymbol_to_symbol(abfd, FALSE, (const void *)cur, store);
47 if (sym == NULL)
48 bfd_fatal(bfd_get_filename (abfd));
50 if (bfd_is_und_section (sym->section))
52 if (!there_are_undefined_syms)
54 there_are_undefined_syms = 1;
56 fprintf(stderr, "There are undefined symbols in '%s':\n", bfd_get_filename(abfd));
59 fprintf(stderr, "%s\n", sym->name);
63 bfd_close(abfd);
64 /* We should free() minisyms, but since we're called only once, we let the system
65 do it for us. */
67 return there_are_undefined_syms;
70 static void setfunc(bfd *exe, asection *sect, PTR setlist_ptr)
72 parse_secname(sect->name, (setnode **)setlist_ptr);
75 void collect_sets(const char *file, setnode **setlist_ptr)
77 bfd_init();
79 bfd *abfd;
83 (abfd = bfd_openr(file, "default")) == NULL ||
84 !bfd_check_format(abfd, bfd_object)
87 bfd_fatal(file);
90 parse_format(abfd->xvec->name);
91 bfd_map_over_sections(abfd, setfunc, setlist_ptr);
93 bfd_close(abfd);