From 7aeca9bfed654f7f5d0e4b9775459b878f4726ed Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 21 Sep 2016 17:40:50 -0400 Subject: [PATCH] fix incorrect linking from previous commit --- src/link.cpp | 36 +++++++++++++++++++++--------------- std/debug.zig | 2 +- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/link.cpp b/src/link.cpp index b36140d551..81ae90602c 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -31,6 +31,14 @@ static const char *get_libc_static_file(CodeGen *g, const char *file) { return buf_ptr(out_buf); } +static const char *get_o_file_extension(CodeGen *g) { + if (g->zig_target.env_type == ZigLLVM_MSVC) { + return ".obj"; + } else { + return ".o"; + } +} + static Buf *build_o(CodeGen *parent_gen, const char *oname) { Buf *source_basename = buf_sprintf("%s.zig", oname); Buf *std_dir_path = parent_gen->zig_std_dir; @@ -62,20 +70,13 @@ static Buf *build_o(CodeGen *parent_gen, const char *oname) { } codegen_add_root_code(child_gen, std_dir_path, source_basename, &source_code); - Buf *o_out = buf_sprintf("%s.o", oname); + const char *o_ext = get_o_file_extension(child_gen); + Buf *o_out = buf_sprintf("%s%s", oname, o_ext); codegen_link(child_gen, buf_ptr(o_out)); return o_out; } -static const char *get_o_file_extension(CodeGen *g) { - if (g->zig_target.env_type == ZigLLVM_MSVC) { - return ".obj"; - } else { - return ".o"; - } -} - static const char *get_exe_file_extension(CodeGen *g) { if (g->zig_target.os == ZigLLVM_Win32) { return ".exe"; @@ -786,16 +787,21 @@ void codegen_link(CodeGen *g, const char *out_file) { fprintf(stderr, "-------\n"); } - if (buf_len(&lj.out_file) == 0) { + bool override_out_file = (buf_len(&lj.out_file) != 0); + if (!override_out_file) { assert(g->root_out_name); - buf_init_from_buf(&lj.out_file, g->root_out_name); - buf_append_str(&lj.out_file, get_exe_file_extension(g)); - } + buf_init_from_buf(&lj.out_file, g->root_out_name); + if (g->out_type == OutTypeExe) { + buf_append_str(&lj.out_file, get_exe_file_extension(g)); + } + } buf_init_from_buf(&lj.out_file_o, &lj.out_file); - const char *o_ext = get_o_file_extension(g); - buf_append_str(&lj.out_file_o, o_ext); + if (g->out_type != OutTypeObj || !override_out_file) { + const char *o_ext = get_o_file_extension(g); + buf_append_str(&lj.out_file_o, o_ext); + } char *err_msg = nullptr; if (LLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(&lj.out_file_o), diff --git a/std/debug.zig b/std/debug.zig index d8d2ea4b48..bdd33298d8 100644 --- a/std/debug.zig +++ b/std/debug.zig @@ -196,7 +196,7 @@ fn parseFormValue(in_stream: &io.InStream, form_id: u64, is_64: bool) -> %FormVa const child_form_id = %return readULeb128(in_stream); parseFormValue(in_stream, child_form_id, is_64) }, - else => return error.InvalidDebugInfo, + else => error.InvalidDebugInfo, } }