ld support arguments to multiple-letter options being passed in two ways: * -opt=arg * -opt arg libtool generate command line of the second form. This commit add support for the second form so that libtool works with tcc. The way it is done is to concatenate all -Wl options into one and then pass it to set_linker.
Unified · Split
| @@ -1566,6 +1566,9 @@ PUB_FUNC const char * tcc_set_linker(TCCState *s, char *option, int multi) · 1565 unmodified lines | ||
| 1566 | 1566 | s->text_addr = strtoull(p, &end, 16); |
| 1567 | 1567 | s->has_text_addr = 1; |
| 1568 | 1568 | } else { |
| 1569 | + char *comma_ptr = strchr(option, ','); | |
| 1570 | + if (comma_ptr) | |
| 1571 | + *comma_ptr = '\0'; | |
| 1569 | 1572 | return option; |
| 1570 | 1573 | } |
| 1571 | 1574 | |
| @@ -280,6 +280,8 @@ static int parse_args(TCCState *s, int argc, char **argv) · 279 unmodified lines | ||
| 280 | 280 | const char *optarg, *p1, *r1; |
| 281 | 281 | char *r; |
| 282 | 282 | int was_pthread; |
| 283 | + char *linker_arg = NULL; | |
| 284 | + unsigned long linker_argsize = 0; | |
| 283 | 285 | |
| 284 | 286 | was_pthread = 0; /* is set if commandline contains -pthread key */ |
| 285 | 287 | |
| @@ -442,8 +444,17 @@ static int parse_args(TCCState *s, int argc, char **argv) · 156 unmodified lines | ||
| 442 | 444 | s->rdynamic = 1; |
| 443 | 445 | break; |
| 444 | 446 | case TCC_OPTION_Wl: |
| 445 | − if ((r = (char *) tcc_set_linker(s, (char *)optarg, TRUE))) | |
| 446 | − tcc_error("unsupported linker option '%s'", r); | |
| 447 | + if (!linker_arg) { | |
| 448 | + linker_argsize = strlen(optarg) + 1; | |
| 449 | + linker_arg = tcc_malloc(linker_argsize); | |
| 450 | + pstrcpy(linker_arg, linker_argsize, optarg); | |
| 451 | + } | |
| 452 | + else { | |
| 453 | + linker_argsize += strlen(optarg) + 1; | |
| 454 | + linker_arg = tcc_realloc(linker_arg, linker_argsize); | |
| 455 | + pstrcat(linker_arg, linker_argsize, ","); | |
| 456 | + pstrcat(linker_arg, linker_argsize, optarg); | |
| 457 | + } | |
| 447 | 458 | break; |
| 448 | 459 | case TCC_OPTION_E: |
| 449 | 460 | output_type = TCC_OUTPUT_PREPROCESS; |
| @@ -465,6 +476,9 @@ static int parse_args(TCCState *s, int argc, char **argv) · 15 unmodified lines | ||
| 465 | 476 | } |
| 466 | 477 | } |
| 467 | 478 | } |
| 479 | + if ((r = (char *) tcc_set_linker(s, (char *)linker_arg, TRUE))) | |
| 480 | + tcc_error("unsupported linker option '%s'", r); | |
| 481 | + tcc_free(linker_arg); | |
| 468 | 482 | /* fixme: these options could be different on your platform */ |
| 469 | 483 | if (was_pthread && output_type != TCC_OUTPUT_OBJ) { |
| 470 | 484 | dynarray_add((void ***)&files, &nb_files, "-lpthread"); |