diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-10-16 01:14:28 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-10-16 01:14:28 -0400 |
| commit | d08c57741ae190c587c42861e71b0e361903733e (patch) | |
| tree | ee79c77ec4a568d90ae1cfaefa6fd786cc788926 /src | |
| parent | 78b753af9dd9818b9dc848f590330c61b2ca7c3f (diff) | |
| download | zig-d08c57741ae190c587c42861e71b0e361903733e.tar.gz zig-d08c57741ae190c587c42861e71b0e361903733e.zip | |
ability to make a DLL
See #302
Diffstat (limited to 'src')
| -rw-r--r-- | src/all_types.hpp | 1 | ||||
| -rw-r--r-- | src/analyze.cpp | 4 | ||||
| -rw-r--r-- | src/codegen.cpp | 3 | ||||
| -rw-r--r-- | src/link.cpp | 15 |
4 files changed, 19 insertions, 4 deletions
diff --git a/src/all_types.hpp b/src/all_types.hpp index 57ff028d40..a5244b87b8 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -1456,6 +1456,7 @@ struct CodeGen { bool have_c_main; bool have_winmain; bool have_winmain_crt_startup; + bool have_dllmain_crt_startup; bool have_pub_panic; Buf *libc_lib_dir; Buf *libc_static_lib_dir; diff --git a/src/analyze.cpp b/src/analyze.cpp index 5e702964d3..3bb4fe6511 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -3200,6 +3200,10 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *a buf_eql_str(proto_name, "WinMainCRTStartup") && g->zig_target.os == ZigLLVM_Win32) { g->have_winmain_crt_startup = true; + } else if (proto_node->data.fn_proto.visib_mod == VisibModExport && + buf_eql_str(proto_name, "DllMainCRTStartup") && g->zig_target.os == ZigLLVM_Win32) + { + g->have_dllmain_crt_startup = true; } } diff --git a/src/codegen.cpp b/src/codegen.cpp index e119b714a8..2ffb2c49c2 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -5228,6 +5228,9 @@ static void gen_root_source(CodeGen *g) { { g->bootstrap_import = add_special_code(g, create_bootstrap_pkg(g, g->root_package), "bootstrap.zig"); } + if (g->zig_target.os == ZigLLVM_Win32 && !g->have_dllmain_crt_startup && g->out_type == OutTypeLib) { + g->bootstrap_import = add_special_code(g, create_bootstrap_pkg(g, g->root_package), "bootstrap_lib.zig"); + } ImportTableEntry *import_with_panic; if (g->have_pub_panic) { import_with_panic = g->root_import; diff --git a/src/link.cpp b/src/link.cpp index 475e42fd7b..0a25471d3c 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -372,6 +372,7 @@ static void construct_linker_job_coff(LinkJob *lj) { // how to handle --target-environ gnu // These comments are a clue + bool is_library = g->out_type == OutTypeLib; //bool dll = g->out_type == OutTypeLib; //bool shared = !g->is_static && dll; //if (g->is_static) { @@ -422,13 +423,19 @@ static void construct_linker_job_coff(LinkJob *lj) { //lj->args.append(get_libc_static_file(g, "crtbegin.o")); } else { lj->args.append("-NODEFAULTLIB"); - if (g->have_winmain) { - lj->args.append("-ENTRY:WinMain"); - } else { - lj->args.append("-ENTRY:WinMainCRTStartup"); + if (!is_library) { + if (g->have_winmain) { + lj->args.append("-ENTRY:WinMain"); + } else { + lj->args.append("-ENTRY:WinMainCRTStartup"); + } } } + if (is_library && !g->is_static) { + lj->args.append("-DLL"); + } + for (size_t i = 0; i < g->lib_dirs.length; i += 1) { const char *lib_dir = g->lib_dirs.at(i); lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", lib_dir))); |
