authorgravatar for ryan.saunderson88@gmail.comdimenus <ryan.saunderson88@gmail.com> 2019-07-10 15:37:25-05:00
committergravatar for ryan.saunderson88@gmail.comdimenus <ryan.saunderson88@gmail.com> 2019-07-10 15:37:25-05:00
log540a40e2d9dcda5fcae1fa2088c3377e8c650a33
treed2a62e862f28e40c94486812fcb24ae8924c978a
parente9331dc5cf90fe0fff5258debc424ad0514507a2

fixing non system library linking


1 files changed, 36 insertions(+), 37 deletions(-)

src/link.cpp+36-37
...@@ -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");
10741074
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.
10771077
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 }
13781370
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 }
13841384
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);
13871387
1388 gen_lib_args.resize(0);1388 gen_lib_args.resize(0);
1389 gen_lib_args.append("link");1389 gen_lib_args.append("link");
13901390
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}
14041403