Unified · Split
| @@ -2277,13 +2277,49 @@ static int ld_next(TCCState *s1, char *name, int name_size) · 2276 unmodified lines | ||
| 2277 | 2277 | return c; |
| 2278 | 2278 | } |
| 2279 | 2279 | |
| 2280 | +static int ld_add_file_list(TCCState *s1, int as_needed) | |
| 2281 | +{ | |
| 2282 | + char filename[1024]; | |
| 2283 | + int t, ret; | |
| 2284 | + | |
| 2285 | + t = ld_next(s1, filename, sizeof(filename)); | |
| 2286 | + if (t != '(') | |
| 2287 | + expect("("); | |
| 2288 | + t = ld_next(s1, filename, sizeof(filename)); | |
| 2289 | + for(;;) { | |
| 2290 | + if (t == LD_TOK_EOF) { | |
| 2291 | + error_noabort("unexpected end of file"); | |
| 2292 | + return -1; | |
| 2293 | + } else if (t == ')') { | |
| 2294 | + break; | |
| 2295 | + } else if (t != LD_TOK_NAME) { | |
| 2296 | + error_noabort("filename expected"); | |
| 2297 | + return -1; | |
| 2298 | + } | |
| 2299 | + if (!strcmp(filename, "AS_NEEDED")) { | |
| 2300 | + ret = ld_add_file_list(s1, 1); | |
| 2301 | + if (ret) | |
| 2302 | + return ret; | |
| 2303 | + } else { | |
| 2304 | + /* TODO: Implement AS_NEEDED support. Ignore it for now */ | |
| 2305 | + if (!as_needed) | |
| 2306 | + tcc_add_file(s1, filename); | |
| 2307 | + } | |
| 2308 | + t = ld_next(s1, filename, sizeof(filename)); | |
| 2309 | + if (t == ',') { | |
| 2310 | + t = ld_next(s1, filename, sizeof(filename)); | |
| 2311 | + } | |
| 2312 | + } | |
| 2313 | + return 0; | |
| 2314 | +} | |
| 2315 | + | |
| 2280 | 2316 | /* interpret a subset of GNU ldscripts to handle the dummy libc.so |
| 2281 | 2317 | files */ |
| 2282 | 2318 | static int tcc_load_ldscript(TCCState *s1) |
| 2283 | 2319 | { |
| 2284 | 2320 | char cmd[64]; |
| 2285 | 2321 | char filename[1024]; |
| 2286 | − int t; | |
| 2322 | + int t, ret; | |
| 2287 | 2323 | |
| 2288 | 2324 | ch = file->buf_ptr[0]; |
| 2289 | 2325 | ch = handle_eob(); |
| @@ -2295,26 +2331,9 @@ static int tcc_load_ldscript(TCCState *s1) · 5 unmodified lines | ||
| 2295 | 2331 | return -1; |
| 2296 | 2332 | if (!strcmp(cmd, "INPUT") || |
| 2297 | 2333 | !strcmp(cmd, "GROUP")) { |
| 2298 | − t = ld_next(s1, cmd, sizeof(cmd)); | |
| 2299 | − if (t != '(') | |
| 2300 | − expect("("); | |
| 2301 | − t = ld_next(s1, filename, sizeof(filename)); | |
| 2302 | − for(;;) { | |
| 2303 | − if (t == LD_TOK_EOF) { | |
| 2304 | − error_noabort("unexpected end of file"); | |
| 2305 | − return -1; | |
| 2306 | − } else if (t == ')') { | |
| 2307 | − break; | |
| 2308 | − } else if (t != LD_TOK_NAME) { | |
| 2309 | − error_noabort("filename expected"); | |
| 2310 | − return -1; | |
| 2311 | − } | |
| 2312 | − tcc_add_file(s1, filename); | |
| 2313 | − t = ld_next(s1, filename, sizeof(filename)); | |
| 2314 | − if (t == ',') { | |
| 2315 | − t = ld_next(s1, filename, sizeof(filename)); | |
| 2316 | − } | |
| 2317 | − } | |
| 2334 | + ret = ld_add_file_list(s1, 0); | |
| 2335 | + if (ret) | |
| 2336 | + return ret; | |
| 2318 | 2337 | } else if (!strcmp(cmd, "OUTPUT_FORMAT") || |
| 2319 | 2338 | !strcmp(cmd, "TARGET")) { |
| 2320 | 2339 | /* ignore some commands */ |