From 6fece14cfbb852c108c2094ae0879da76f2f445e Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 26 Dec 2017 19:44:08 -0500 Subject: self-hosted: build against zig_llvm and embedded LLD Now the self-hosted compiler re-uses the same C++ code for interfacing with LLVM as the C++ code. It also links against the same LLD library files. --- src/link.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/link.cpp') diff --git a/src/link.cpp b/src/link.cpp index bc84b27b89..f07364e5bc 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -351,6 +351,16 @@ static void coff_append_machine_arg(CodeGen *g, ZigList *list) { } } +static void link_diag_callback(void *context, const char *ptr, size_t len) { + Buf *diag = reinterpret_cast(context); + buf_append_mem(diag, ptr, len); +} + +static bool zig_lld_link(ZigLLVM_ObjectFormatType oformat, const char **args, size_t arg_count, Buf *diag) { + buf_resize(diag, 0); + return ZigLLDLink(oformat, args, arg_count, link_diag_callback, diag); +} + static void construct_linker_job_coff(LinkJob *lj) { CodeGen *g = lj->codegen; @@ -515,7 +525,7 @@ static void construct_linker_job_coff(LinkJob *lj) { gen_lib_args.append(buf_ptr(buf_sprintf("-DEF:%s", buf_ptr(def_path)))); gen_lib_args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(generated_lib_path)))); Buf diag = BUF_INIT; - if (!ZigLLDLink(g->zig_target.oformat, gen_lib_args.items, gen_lib_args.length, &diag)) { + if (!zig_lld_link(g->zig_target.oformat, gen_lib_args.items, gen_lib_args.length, &diag)) { fprintf(stderr, "%s\n", buf_ptr(&diag)); exit(1); } @@ -930,7 +940,7 @@ void codegen_link(CodeGen *g, const char *out_file) { Buf diag = BUF_INIT; codegen_add_time_event(g, "LLVM Link"); - if (!ZigLLDLink(g->zig_target.oformat, lj.args.items, lj.args.length, &diag)) { + if (!zig_lld_link(g->zig_target.oformat, lj.args.items, lj.args.length, &diag)) { fprintf(stderr, "%s\n", buf_ptr(&diag)); exit(1); } -- cgit v1.2.3