authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-16 12:51:02-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-16 12:51:02-04:00
log15ed47921f1d4305d29db222f501eba899453beb
tree60f9866aa56496da4141e3a2388e6e98c0356af1
parent3a67c13b5db7efe28d4656d5da808f42ac026cc3
parent540a40e2d9dcda5fcae1fa2088c3377e8c650a33
signaturelock-open Commit is signed but in an unrecognized format.

Merge branch 'msvc-libc-2064' of https://github.com/dimenus/zig into dimenus-msvc-libc-2064


1 files changed, 38 insertions(+), 35 deletions(-)

src/link.cpp+38-35
......@@ -1904,8 +1904,7 @@ static void add_uefi_link_args(LinkJob *lj) {
19041904static void add_msvc_link_args(LinkJob *lj, bool is_library) {
19051905 CodeGen *g = lj->codegen;
19061906
1907 // TODO: https://github.com/ziglang/zig/issues/2064
1908 bool is_dynamic = true; // g->is_dynamic;
1907 bool is_dynamic = g->is_dynamic;
19091908 const char *lib_str = is_dynamic ? "" : "lib";
19101909 const char *d_str = (g->build_mode == BuildModeDebug) ? "d" : "";
19111910
......@@ -2151,7 +2150,7 @@ static void add_win_link_args(LinkJob *lj, bool is_library, bool *have_windows_d
21512150
21522151static bool is_mingw_link_lib(Buf *name) {
21532152 for (size_t def_i = 0; def_i < array_length(mingw_def_list); def_i += 1) {
2154 if (buf_eql_str(name, mingw_def_list[def_i].name)) {
2153 if (buf_eql_str_ignore_case(name, mingw_def_list[def_i].name)) {
21552154 return true;
21562155 }
21572156 }
......@@ -2265,50 +2264,54 @@ static void construct_linker_job_coff(LinkJob *lj) {
22652264 if (buf_eql_str(link_lib->name, "c")) {
22662265 continue;
22672266 }
2268 if (have_windows_dll_import_libs && is_mingw_link_lib(link_lib->name)) {
2267 bool is_sys_lib = is_mingw_link_lib(link_lib->name);
2268 if (have_windows_dll_import_libs && is_sys_lib) {
22692269 continue;
22702270 }
2271 if (link_lib->provided_explicitly) {
2271 // If we're linking in the CRT or the libs are provided explictly we don't want to generate def/libs
2272 if ((lj->link_in_crt && is_sys_lib) || link_lib->provided_explicitly) {
22722273 if (target_abi_is_gnu(lj->codegen->zig_target->abi)) {
2273 Buf *lib_name = buf_sprintf("lib%s.a", buf_ptr(link_lib->name));
2274 Buf* lib_name = buf_sprintf("lib%s.a", buf_ptr(link_lib->name));
22742275 lj->args.append(buf_ptr(lib_name));
2275 } else {
2276 lj->args.append(buf_ptr(link_lib->name));
22772276 }
2278 } else {
2279 buf_resize(def_contents, 0);
2280 buf_appendf(def_contents, "LIBRARY %s\nEXPORTS\n", buf_ptr(link_lib->name));
2281 for (size_t exp_i = 0; exp_i < link_lib->symbols.length; exp_i += 1) {
2282 Buf *symbol_name = link_lib->symbols.at(exp_i);
2283 buf_appendf(def_contents, "%s\n", buf_ptr(symbol_name));
2277 else {
2278 Buf* lib_name = buf_sprintf("%s.lib", buf_ptr(link_lib->name));
2279 lj->args.append(buf_ptr(lib_name));
22842280 }
2285 buf_appendf(def_contents, "\n");
2281 continue;
2282 }
22862283
2287 Buf *def_path = buf_alloc();
2288 os_path_join(g->output_dir, buf_sprintf("%s.def", buf_ptr(link_lib->name)), def_path);
2289 if ((err = os_write_file(def_path, def_contents))) {
2290 zig_panic("error writing def file: %s", err_str(err));
2291 }
2284 buf_resize(def_contents, 0);
2285 buf_appendf(def_contents, "LIBRARY %s\nEXPORTS\n", buf_ptr(link_lib->name));
2286 for (size_t exp_i = 0; exp_i < link_lib->symbols.length; exp_i += 1) {
2287 Buf *symbol_name = link_lib->symbols.at(exp_i);
2288 buf_appendf(def_contents, "%s\n", buf_ptr(symbol_name));
2289 }
2290 buf_appendf(def_contents, "\n");
22922291
2293 Buf *generated_lib_path = buf_alloc();
2294 os_path_join(g->output_dir, buf_sprintf("%s.lib", buf_ptr(link_lib->name)), generated_lib_path);
2292 Buf *def_path = buf_alloc();
2293 os_path_join(g->output_dir, buf_sprintf("%s.def", buf_ptr(link_lib->name)), def_path);
2294 if ((err = os_write_file(def_path, def_contents))) {
2295 zig_panic("error writing def file: %s", err_str(err));
2296 }
22952297
2296 gen_lib_args.resize(0);
2297 gen_lib_args.append("link");
2298 Buf *generated_lib_path = buf_alloc();
2299 os_path_join(g->output_dir, buf_sprintf("%s.lib", buf_ptr(link_lib->name)), generated_lib_path);
22982300
2299 coff_append_machine_arg(g, &gen_lib_args);
2300 gen_lib_args.append(buf_ptr(buf_sprintf("-DEF:%s", buf_ptr(def_path))));
2301 gen_lib_args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(generated_lib_path))));
2302 Buf diag = BUF_INIT;
2303 ZigLLVM_ObjectFormatType target_ofmt = target_object_format(g->zig_target);
2304 if (!zig_lld_link(target_ofmt, gen_lib_args.items, gen_lib_args.length, &diag)) {
2305 fprintf(stderr, "%s\n", buf_ptr(&diag));
2306 exit(1);
2307 }
2308 lj->args.append(buf_ptr(generated_lib_path));
2301 gen_lib_args.resize(0);
2302 gen_lib_args.append("link");
2303
2304 coff_append_machine_arg(g, &gen_lib_args);
2305 gen_lib_args.append(buf_ptr(buf_sprintf("-DEF:%s", buf_ptr(def_path))));
2306 gen_lib_args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(generated_lib_path))));
2307 Buf diag = BUF_INIT;
2308 ZigLLVM_ObjectFormatType target_ofmt = target_object_format(g->zig_target);
2309 if (!zig_lld_link(target_ofmt, gen_lib_args.items, gen_lib_args.length, &diag)) {
2310 fprintf(stderr, "%s\n", buf_ptr(&diag));
2311 exit(1);
23092312 }
2313 lj->args.append(buf_ptr(generated_lib_path));
23102314 }
2311
23122315}
23132316
23142317