Fixes for compiling on 64bit and outside the source dir
[AROS.git] / tools / collect-aros / backend-generic.c
blob6d47652852107c6bc490d0210f59d0cd2c4b0acf
1 #include "misc.h"
2 #include "backend.h"
3 #include <sys/param.h>
4 #include <string.h>
5 #include <errno.h>
7 static FILE *my_popen(const char *command, const char *file)
9 static char command_buf[MAXPATHLEN];
11 size_t command_len = strlen(command);
12 size_t file_len = strlen(file);
14 FILE *pipe;
16 if (file_len + command_len >= sizeof(command_buf))
17 fatal("collect_sets()", strerror(ENAMETOOLONG));
19 memcpy(command_buf, command, command_len);
20 memcpy(command_buf + command_len, file, file_len + 1);
22 set_compiler_path();
24 pipe = popen(command_buf, "r");
25 if (pipe == NULL)
26 fatal(command_buf, strerror(errno));
28 return pipe;
33 This routine is slow, but does the work and it's the simplest to write down.
34 All this will get integrated into the linker anyway, so there's no point
35 in doing optimizations
37 void collect_sets(const char *file, setnode **setlist_ptr)
39 char secname[201];
41 FILE *pipe = my_popen("objdump -h ", file);
43 /* This fscanf() simply splits the whole stream into separate words */
44 while (fscanf(pipe, " %200s ", secname) > 0)
46 parse_format(secname);
47 parse_secname(secname, setlist_ptr);
50 pclose(pipe);
53 int check_and_print_undefined_symbols(const char *file)
55 int there_are_undefined_syms = 0;
56 char buf[200];
57 size_t cnt;
59 FILE *pipe = my_popen("nm -ulC ", file);
61 while ((cnt = fread(buf, 1, sizeof(buf), pipe)) != 0)
63 if (!there_are_undefined_syms)
65 there_are_undefined_syms = 1;
66 fprintf(stderr, "There are undefined symbols in '%s':\n", file);
69 fwrite(buf, cnt, 1, stderr);
72 pclose(pipe);
74 return there_are_undefined_syms;