authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-05 14:12:31-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-05 14:12:46-05:00
logdd263eccb716ba167fdad5bb3a4544dace6bf6a1
tree6d1a2d445ebe0c5d83c99ec04b1a867bd1230916
parentc5fdea59d36dffcac95b71c20609a44d34b1935a
signature Commit is signed but in an unrecognized format.

support crtbegin.o and crtend.o when using explicit libc


1 files changed, 22 insertions(+), 0 deletions(-)

src/link.cpp+22
...@@ -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}
307307
308static 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
308static Buf *build_a_raw(CodeGen *parent_gen, const char *aname, Buf *full_path) {315static 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 assertion316 // 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}
427434
435// TODO: try to get away with completely removing this functionality
436static bool want_gcc_objects(CodeGen *g) {
437 return g->libc != nullptr && buf_len(&g->libc->static_lib_dir) != 0;
438}
439
428static void construct_linker_job_elf(LinkJob *lj) {440static void construct_linker_job_elf(LinkJob *lj) {
429 CodeGen *g = lj->codegen;441 CodeGen *g = lj->codegen;
430442
...@@ -468,15 +480,22 @@ static void construct_linker_job_elf(LinkJob *lj) {...@@ -468,15 +480,22 @@ static void construct_linker_job_elf(LinkJob *lj) {
468480
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 }
481500
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) {
605624
606 // crt end625 // 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 }
610632