| ... | @@ -305,6 +305,13 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) { | ... | @@ -305,6 +305,13 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) { |
| 305 | } | 305 | } |
| 306 | } | 306 | } |
| 307 | | 307 | |
| | 308 | static const char *get_libc_static_file(CodeGen *g, const char *file) { |
| | 309 | assert(g->libc != nullptr); |
| | 310 | Buf *out_buf = buf_alloc(); |
| | 311 | os_path_join(&g->libc->static_lib_dir, buf_create_from_str(file), out_buf); |
| | 312 | return buf_ptr(out_buf); |
| | 313 | } |
| | 314 | |
| 308 | static Buf *build_a_raw(CodeGen *parent_gen, const char *aname, Buf *full_path) { | 315 | static Buf *build_a_raw(CodeGen *parent_gen, const char *aname, Buf *full_path) { |
| 309 | // The Mach-O LLD code is not well maintained, and trips an assertion | 316 | // The Mach-O LLD code is not well maintained, and trips an assertion |
| 310 | // when we link compiler_rt and builtin as libraries rather than objects. | 317 | // when we link compiler_rt and builtin as libraries rather than objects. |
| ... | @@ -425,6 +432,11 @@ static void add_rpath(LinkJob *lj, Buf *rpath) { | ... | @@ -425,6 +432,11 @@ static void add_rpath(LinkJob *lj, Buf *rpath) { |
| 425 | lj->rpath_table.put(rpath, true); | 432 | lj->rpath_table.put(rpath, true); |
| 426 | } | 433 | } |
| 427 | | 434 | |
| | 435 | // TODO: try to get away with completely removing this functionality |
| | 436 | static bool want_gcc_objects(CodeGen *g) { |
| | 437 | return g->libc != nullptr && buf_len(&g->libc->static_lib_dir) != 0; |
| | 438 | } |
| | 439 | |
| 428 | static void construct_linker_job_elf(LinkJob *lj) { | 440 | static void construct_linker_job_elf(LinkJob *lj) { |
| 429 | CodeGen *g = lj->codegen; | 441 | CodeGen *g = lj->codegen; |
| 430 | | 442 | |
| ... | @@ -468,15 +480,22 @@ static void construct_linker_job_elf(LinkJob *lj) { | ... | @@ -468,15 +480,22 @@ static void construct_linker_job_elf(LinkJob *lj) { |
| 468 | | 480 | |
| 469 | if (lj->link_in_crt) { | 481 | if (lj->link_in_crt) { |
| 470 | const char *crt1o; | 482 | const char *crt1o; |
| | 483 | const char *crtbegino; |
| 471 | if (g->zig_target->os == OsNetBSD) { | 484 | if (g->zig_target->os == OsNetBSD) { |
| 472 | crt1o = "crt0.o"; | 485 | crt1o = "crt0.o"; |
| | 486 | crtbegino = "crtbegin.o"; |
| 473 | } else if (g->is_static) { | 487 | } else if (g->is_static) { |
| 474 | crt1o = "crt1.o"; | 488 | crt1o = "crt1.o"; |
| | 489 | crtbegino = "crtbeginT.o"; |
| 475 | } else { | 490 | } else { |
| 476 | crt1o = "Scrt1.o"; | 491 | crt1o = "Scrt1.o"; |
| | 492 | crtbegino = "crtbegin.o"; |
| 477 | } | 493 | } |
| 478 | lj->args.append(get_libc_crt_file(g, crt1o)); | 494 | lj->args.append(get_libc_crt_file(g, crt1o)); |
| 479 | lj->args.append(get_libc_crt_file(g, "crti.o")); | 495 | lj->args.append(get_libc_crt_file(g, "crti.o")); |
| | 496 | if (want_gcc_objects(g)) { |
| | 497 | lj->args.append(get_libc_static_file(g, crtbegino)); |
| | 498 | } |
| 480 | } | 499 | } |
| 481 | | 500 | |
| 482 | for (size_t i = 0; i < g->rpath_list.length; i += 1) { | 501 | for (size_t i = 0; i < g->rpath_list.length; i += 1) { |
| ... | @@ -605,6 +624,9 @@ static void construct_linker_job_elf(LinkJob *lj) { | ... | @@ -605,6 +624,9 @@ static void construct_linker_job_elf(LinkJob *lj) { |
| 605 | | 624 | |
| 606 | // crt end | 625 | // crt end |
| 607 | if (lj->link_in_crt) { | 626 | if (lj->link_in_crt) { |
| | 627 | if (want_gcc_objects(g)) { |
| | 628 | lj->args.append(get_libc_static_file(g, "crtend.o")); |
| | 629 | } |
| 608 | lj->args.append(get_libc_crt_file(g, "crtn.o")); | 630 | lj->args.append(get_libc_crt_file(g, "crtn.o")); |
| 609 | } | 631 | } |
| 610 | | 632 | |