Added close gadget and increased hight of default con window.
[AROS.git] / tools / collect-aros / backend-bfd.c
blob40f80d6242377695bfa5d075cc6bd1e4cf649538
1 #define PACKAGE
2 #define PACKAGE_VERSION
3 #include <bfd.h>
4 #include <string.h>
5 #include <stdlib.h>
6 #include <errno.h>
8 #include <sys/param.h>
10 #include "misc.h"
11 #include "backend.h"
13 static void bfd_fatal(const char *msg)
15 fatal(msg, bfd_errmsg(bfd_get_error()));
18 int check_and_print_undefined_symbols(const char *file)
20 bfd_byte *cur, *minisyms;
21 asymbol *store;
22 long symcount;
23 unsigned int size;
24 int there_are_undefined_syms = 0;
25 bfd *abfd;
27 bfd_init();
31 (abfd = bfd_openr(file, "default")) == NULL ||
32 !bfd_check_format(abfd, bfd_object)
35 bfd_fatal(file);
38 symcount = bfd_read_minisymbols(abfd, FALSE, (void **)&minisyms, &size);
39 if (symcount < 0)
40 bfd_fatal (bfd_get_filename (abfd));
42 if (symcount == 0)
43 return 0;
45 store = bfd_make_empty_symbol(abfd);
46 if (store == NULL)
47 bfd_fatal(bfd_get_filename(abfd));
49 for (cur = minisyms; cur < (minisyms + (symcount * size)); cur += size)
51 asymbol *sym;
53 sym = bfd_minisymbol_to_symbol(abfd, FALSE, (const void *)cur, store);
54 if (sym == NULL)
55 bfd_fatal(bfd_get_filename (abfd));
57 if (bfd_is_und_section (sym->section))
59 if (!there_are_undefined_syms)
61 there_are_undefined_syms = 1;
63 fprintf(stderr, "There are undefined symbols in '%s':\n", bfd_get_filename(abfd));
66 fprintf(stderr, "%s\n", sym->name);
70 bfd_close(abfd);
71 /* We should free() minisyms, but since we're called only once, we let the system
72 do it for us. */
74 return there_are_undefined_syms;
77 static void setfunc(bfd *exe, asection *sect, PTR setlist_ptr)
79 parse_secname(sect->name, (setnode **)setlist_ptr);
82 void collect_sets(const char *file, setnode **setlist_ptr)
84 bfd_init();
86 bfd *abfd;
90 (abfd = bfd_openr(file, "default")) == NULL ||
91 !bfd_check_format(abfd, bfd_object)
94 bfd_fatal(file);
97 parse_format(abfd->xvec->name);
98 bfd_map_over_sections(abfd, setfunc, setlist_ptr);
100 bfd_close(abfd);
103 static void collect_lib(asymbol *sym, setnode **liblist_ptr)
105 setnode *node;
106 char *cp, *name;
107 int pri;
109 if (strncmp(sym->name, "__aros_libreq_", 14) != 0)
110 return;
112 node = xmalloc(sizeof(*node)+strlen(sym->name)+1);
113 name = (char *)(&node[1]);
114 strcpy(name, sym->name);
116 cp = strchr(name + 14, '.');
117 if (cp != NULL) {
118 char *tmp;
119 pri = strtoul(cp+1, &tmp, 0);
121 if ((cp+1) == tmp) {
122 free(node);
123 return;
126 *(cp++) = 0;
128 } else {
129 pri = 0;
132 node->secname = name;
133 node->off_setname = 14;
134 node->pri = pri;
135 node->next = *liblist_ptr;
136 *liblist_ptr = node;
139 void collect_libs(const char *file, setnode **liblist_ptr)
141 long symtab_size;
142 bfd *abfd;
144 /* We assume bfd_init() has already been colled by
145 * collect_sets
150 (abfd = bfd_openr(file, "default")) == NULL ||
151 !bfd_check_format(abfd, bfd_object)
154 bfd_fatal(file);
157 symtab_size = bfd_get_symtab_upper_bound(abfd);
158 if (symtab_size > 0) {
159 asymbol **symtab;
160 long symbols;
162 symtab = (asymbol **)xmalloc(symtab_size);
163 symbols = bfd_canonicalize_symtab(abfd, symtab);
164 if (symbols > 0) {
165 long i;
167 for (i = 0; i < symbols; i++)
168 collect_lib(symtab[i], liblist_ptr);
171 free(symtab);
174 bfd_close(abfd);