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) {
305305 }
306306}
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
308315static Buf *build_a_raw(CodeGen *parent_gen, const char *aname, Buf *full_path) {
309316 // The Mach-O LLD code is not well maintained, and trips an assertion
310317 // when we link compiler_rt and builtin as libraries rather than objects.
......@@ -425,6 +432,11 @@ static void add_rpath(LinkJob *lj, Buf *rpath) {
425432 lj->rpath_table.put(rpath, true);
426433}
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
428440static void construct_linker_job_elf(LinkJob *lj) {
429441 CodeGen *g = lj->codegen;
430442
......@@ -468,15 +480,22 @@ static void construct_linker_job_elf(LinkJob *lj) {
468480
469481 if (lj->link_in_crt) {
470482 const char *crt1o;
483 const char *crtbegino;
471484 if (g->zig_target->os == OsNetBSD) {
472485 crt1o = "crt0.o";
486 crtbegino = "crtbegin.o";
473487 } else if (g->is_static) {
474488 crt1o = "crt1.o";
489 crtbegino = "crtbeginT.o";
475490 } else {
476491 crt1o = "Scrt1.o";
492 crtbegino = "crtbegin.o";
477493 }
478494 lj->args.append(get_libc_crt_file(g, crt1o));
479495 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 }
480499 }
481500
482501 for (size_t i = 0; i < g->rpath_list.length; i += 1) {
......@@ -605,6 +624,9 @@ static void construct_linker_job_elf(LinkJob *lj) {
605624
606625 // crt end
607626 if (lj->link_in_crt) {
627 if (want_gcc_objects(g)) {
628 lj->args.append(get_libc_static_file(g, "crtend.o"));
629 }
608630 lj->args.append(get_libc_crt_file(g, "crtn.o"));
609631 }
610632