2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
15 static FILE *my_popen(const char *command
, const char *file
)
17 static char command_buf
[MAXPATHLEN
];
19 size_t command_len
= strlen(command
);
20 size_t file_len
= strlen(file
);
24 if (file_len
+ command_len
>= sizeof(command_buf
))
25 fatal("collect_sets()", strerror(ENAMETOOLONG
));
27 memcpy(command_buf
, command
, command_len
);
28 memcpy(command_buf
+ command_len
, file
, file_len
+ 1);
32 pipe
= popen(command_buf
, "r");
34 fatal(command_buf
, strerror(errno
));
41 This routine is slow, but does the work and it's the simplest to write down.
42 All this will get integrated into the linker anyway, so there's no point
43 in doing optimizations
45 void collect_sets(const char *file
, setnode
**setlist_ptr
)
49 FILE *pipe
= my_popen(OBJDUMP_NAME
" -h ", file
);
51 /* This fscanf() simply splits the whole stream into separate words */
52 while (fscanf(pipe
, " %200s ", secname
) > 0)
54 parse_format(secname
);
55 parse_secname(secname
, setlist_ptr
);
62 This routine is slow, but does the work and it's the simplest to write down.
63 All this will get integrated into the linker anyway, so there's no point
64 in doing optimizations
66 void collect_libs(const char *file
, setnode
**liblist_ptr
)
73 FILE *pipe
= my_popen("nm ", file
);
75 /* This fscanf() simply splits the whole stream into separate words */
76 while (fgets(buff
, sizeof(buff
), pipe
)) {
82 if (sscanf(buff
, "%lx %c %200s ", &offset
, &type
, secname
) != 3 &&
83 sscanf(buff
, " %c %200s", &type
, secname
) != 2)
86 if (strncmp(secname
, "__aros_libreq_", 14) != 0)
92 cp
= strchr(secname
+ 14, '.');
96 pri
= strtoul(cp
+1, &tmp
, 0);
101 } else if (type
== 'w') {
107 node
= calloc(sizeof(*node
),1);
108 node
->secname
= strdup(secname
);
109 node
->off_setname
= 14;
111 node
->next
= *liblist_ptr
;
119 int check_and_print_undefined_symbols(const char *file
)
121 int there_are_undefined_syms
= 0;
125 FILE *pipe
= my_popen(NM_NAME
" -ulC ", file
);
127 while ((cnt
= fread(buf
, 1, sizeof(buf
), pipe
)) != 0)
129 if (!there_are_undefined_syms
)
131 there_are_undefined_syms
= 1;
132 fprintf(stderr
, "There are undefined symbols in '%s':\n", file
);
135 fwrite(buf
, cnt
, 1, stderr
);
140 return there_are_undefined_syms
;