| ... | @@ -1073,7 +1073,7 @@ static void construct_linker_job_wasm(LinkJob *lj) { | ... | @@ -1073,7 +1073,7 @@ static void construct_linker_job_wasm(LinkJob *lj) { |
| 1073 | lj->args.append("-error-limit=0"); | 1073 | lj->args.append("-error-limit=0"); |
| 1074 | | 1074 | |
| 1075 | if (g->out_type != OutTypeExe) { | 1075 | if (g->out_type != OutTypeExe) { |
| 1076 | 	 lj->args.append("--no-entry"); // So lld doesn't look for _start. | 1076 | lj->args.append("--no-entry"); // So lld doesn't look for _start. |
| 1077 | | 1077 | |
| 1078 | // If there are any C source files we cannot rely on individual exports. | 1078 | // If there are any C source files we cannot rely on individual exports. |
| 1079 | if (g->c_source_files.length != 0) { | 1079 | if (g->c_source_files.length != 0) { |
| ... | @@ -1354,51 +1354,50 @@ static void construct_linker_job_coff(LinkJob *lj) { | ... | @@ -1354,51 +1354,50 @@ static void construct_linker_job_coff(LinkJob *lj) { |
| 1354 | if (buf_eql_str(link_lib->name, "c")) { | 1354 | if (buf_eql_str(link_lib->name, "c")) { |
| 1355 | continue; | 1355 | continue; |
| 1356 | } | 1356 | } |
| 1357 | if (link_lib->provided_explicitly) { | 1357 | |
| | 1358 | //note(dimenus): If we're linking in the CRT or the libs are provided explictly we don't want to generate def/libs |
| | 1359 | if (lj->link_in_crt || link_lib->provided_explicitly) { |
| 1358 | if (target_abi_is_gnu(lj->codegen->zig_target->abi)) { | 1360 | if (target_abi_is_gnu(lj->codegen->zig_target->abi)) { |
| 1359 | Buf *lib_name = buf_sprintf("lib%s.a", buf_ptr(link_lib->name)); | 1361 | Buf* lib_name = buf_sprintf("lib%s.a", buf_ptr(link_lib->name)); |
| 1360 | lj->args.append(buf_ptr(lib_name)); | | |
| 1361 | } else { | | |
| 1362 | 				Buf* lib_name = buf_sprintf("%s.lib", buf_ptr(link_lib->name)); | | |
| 1363 | lj->args.append(buf_ptr(lib_name)); | 1362 | lj->args.append(buf_ptr(lib_name)); |
| 1364 | } | 1363 | } |
| 1365 | } else { | 1364 | else { |
| 1366 | 			//note(dimenus): If we're linking in the CRT we need to link in existing system librarys not generate def/libs | 1365 | Buf* lib_name = buf_sprintf("%s.lib", buf_ptr(link_lib->name)); |
| 1367 | 			if (lj->link_in_crt) { | 1366 | lj->args.append(buf_ptr(lib_name)); |
| 1368 | 				continue; | | |
| 1369 | 			} | | |
| 1370 | | | |
| 1371 | buf_resize(def_contents, 0); | | |
| 1372 | buf_appendf(def_contents, "LIBRARY %s\nEXPORTS\n", buf_ptr(link_lib->name)); | | |
| 1373 | for (size_t exp_i = 0; exp_i < link_lib->symbols.length; exp_i += 1) { | | |
| 1374 | Buf *symbol_name = link_lib->symbols.at(exp_i); | | |
| 1375 | buf_appendf(def_contents, "%s\n", buf_ptr(symbol_name)); | | |
| 1376 | } | 1367 | } |
| 1377 | buf_appendf(def_contents, "\n"); | 1368 | continue; |
| | 1369 | } |
| 1378 | | 1370 | |
| 1379 | Buf *def_path = buf_alloc(); | 1371 | buf_resize(def_contents, 0); |
| 1380 | os_path_join(g->output_dir, buf_sprintf("%s.def", buf_ptr(link_lib->name)), def_path); | 1372 | buf_appendf(def_contents, "LIBRARY %s\nEXPORTS\n", buf_ptr(link_lib->name)); |
| 1381 | if ((err = os_write_file(def_path, def_contents))) { | 1373 | for (size_t exp_i = 0; exp_i < link_lib->symbols.length; exp_i += 1) { |
| 1382 | zig_panic("error writing def file: %s", err_str(err)); | 1374 | Buf *symbol_name = link_lib->symbols.at(exp_i); |
| 1383 | } | 1375 | buf_appendf(def_contents, "%s\n", buf_ptr(symbol_name)); |
| | 1376 | } |
| | 1377 | buf_appendf(def_contents, "\n"); |
| | 1378 | |
| | 1379 | Buf *def_path = buf_alloc(); |
| | 1380 | os_path_join(g->output_dir, buf_sprintf("%s.def", buf_ptr(link_lib->name)), def_path); |
| | 1381 | if ((err = os_write_file(def_path, def_contents))) { |
| | 1382 | zig_panic("error writing def file: %s", err_str(err)); |
| | 1383 | } |
| 1384 | | 1384 | |
| 1385 | Buf *generated_lib_path = buf_alloc(); | 1385 | Buf *generated_lib_path = buf_alloc(); |
| 1386 | os_path_join(g->output_dir, buf_sprintf("%s.lib", buf_ptr(link_lib->name)), generated_lib_path); | 1386 | os_path_join(g->output_dir, buf_sprintf("%s.lib", buf_ptr(link_lib->name)), generated_lib_path); |
| 1387 | | 1387 | |
| 1388 | gen_lib_args.resize(0); | 1388 | gen_lib_args.resize(0); |
| 1389 | gen_lib_args.append("link"); | 1389 | gen_lib_args.append("link"); |
| 1390 | | 1390 | |
| 1391 | coff_append_machine_arg(g, &gen_lib_args); | 1391 | coff_append_machine_arg(g, &gen_lib_args); |
| 1392 | gen_lib_args.append(buf_ptr(buf_sprintf("-DEF:%s", buf_ptr(def_path)))); | 1392 | gen_lib_args.append(buf_ptr(buf_sprintf("-DEF:%s", buf_ptr(def_path)))); |
| 1393 | gen_lib_args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(generated_lib_path)))); | 1393 | gen_lib_args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(generated_lib_path)))); |
| 1394 | Buf diag = BUF_INIT; | 1394 | Buf diag = BUF_INIT; |
| 1395 | ZigLLVM_ObjectFormatType target_ofmt = target_object_format(g->zig_target); | 1395 | ZigLLVM_ObjectFormatType target_ofmt = target_object_format(g->zig_target); |
| 1396 | if (!zig_lld_link(target_ofmt, gen_lib_args.items, gen_lib_args.length, &diag)) { | 1396 | if (!zig_lld_link(target_ofmt, gen_lib_args.items, gen_lib_args.length, &diag)) { |
| 1397 | fprintf(stderr, "%s\n", buf_ptr(&diag)); | 1397 | fprintf(stderr, "%s\n", buf_ptr(&diag)); |
| 1398 | exit(1); | 1398 | exit(1); |
| 1399 | } | | |
| 1400 | lj->args.append(buf_ptr(generated_lib_path)); | | |
| 1401 | } | 1399 | } |
| | 1400 | lj->args.append(buf_ptr(generated_lib_path)); |
| 1402 | } | 1401 | } |
| 1403 | } | 1402 | } |
| 1404 | | 1403 | |