From f580c7fa4330a0c181226060d2e778285fa38dc0 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 15 Feb 2016 16:52:37 -0700 Subject: [PATCH] handle libc include path and libc lib path differently --- src/analyze.cpp | 13 ++++++++----- src/analyze.hpp | 3 ++- src/codegen.cpp | 2 +- src/link.cpp | 15 +++++++++------ 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/analyze.cpp b/src/analyze.cpp index d2381a9156..eddda4ed18 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -1370,7 +1370,7 @@ static void resolve_c_import_decl(CodeGen *g, ImportTableEntry *parent_import, A return; } - find_libc_path(g); + find_libc_include_path(g); ImportTableEntry *child_import = allocate(1); child_import->fn_table.init(32); @@ -6107,7 +6107,13 @@ bool handle_is_ptr(TypeTableEntry *type_entry) { zig_unreachable(); } -void find_libc_path(CodeGen *g) { +void find_libc_include_path(CodeGen *g) { + if (!g->libc_include_dir || buf_len(g->libc_include_dir) == 0) { + zig_panic("Unable to determine libc include path."); + } +} + +void find_libc_lib_path(CodeGen *g) { // later we can handle this better by reporting an error via the normal mechanism if (!g->libc_lib_dir || buf_len(g->libc_lib_dir) == 0) { zig_panic("Unable to determine libc lib path."); @@ -6115,9 +6121,6 @@ void find_libc_path(CodeGen *g) { if (!g->libc_static_lib_dir || buf_len(g->libc_static_lib_dir) == 0) { zig_panic("Unable to determine libc static lib path."); } - if (!g->libc_include_dir || buf_len(g->libc_include_dir) == 0) { - zig_panic("Unable to determine libc include path."); - } } static uint32_t hash_ptr(void *ptr) { diff --git a/src/analyze.hpp b/src/analyze.hpp index a65ade28a0..441211d2fa 100644 --- a/src/analyze.hpp +++ b/src/analyze.hpp @@ -30,7 +30,8 @@ TypeTableEntry *get_partial_container_type(CodeGen *g, ImportTableEntry *import, ContainerKind kind, AstNode *decl_node, const char *name); TypeTableEntry *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x); bool handle_is_ptr(TypeTableEntry *type_entry); -void find_libc_path(CodeGen *g); +void find_libc_include_path(CodeGen *g); +void find_libc_lib_path(CodeGen *g); TypeTableEntry *get_underlying_type(TypeTableEntry *type_entry); bool type_has_bits(TypeTableEntry *type_entry); diff --git a/src/codegen.cpp b/src/codegen.cpp index f7b05bf37b..530fb33f68 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -3695,7 +3695,7 @@ static void init(CodeGen *g, Buf *source_path) { } void codegen_parseh(CodeGen *g, Buf *src_dirname, Buf *src_basename, Buf *source_code) { - find_libc_path(g); + find_libc_include_path(g); Buf *full_path = buf_alloc(); os_path_join(src_dirname, src_basename, full_path); diff --git a/src/link.cpp b/src/link.cpp index 5fbcdfefb7..14fd7cd040 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -127,6 +127,11 @@ static const char *getLDMOption(const ZigTarget *t) { static void construct_linker_job_linux(LinkJob *lj) { CodeGen *g = lj->codegen; + if (lj->link_in_crt) { + find_libc_lib_path(g); + } + + lj->args.append("-m"); lj->args.append(getLDMOption(&g->zig_target)); @@ -253,6 +258,10 @@ static bool is_target_cyg_mingw(const ZigTarget *target) { static void construct_linker_job_mingw(LinkJob *lj) { CodeGen *g = lj->codegen; + if (lj->link_in_crt) { + find_libc_lib_path(g); + } + if (g->zig_target.arch.arch == ZigLLVM_x86) { lj->args.append("-m"); lj->args.append("i386pe"); @@ -526,12 +535,6 @@ void codegen_link(CodeGen *g, const char *out_file) { } lj.link_in_crt = (g->link_libc && g->out_type == OutTypeExe); - if (lj.link_in_crt) { - find_libc_path(g); - } - - - // invoke `ld` ensure_we_have_linker_path(g);