authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-05 14:37:32-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-05 14:37:32-05:00
log0d10ab0680c8cd0c75bf6f6cc7d4a153ac742db8
tree80ece3404adc10e93c68eb97913b5529ac80dcec
parentdd263eccb716ba167fdad5bb3a4544dace6bf6a1
signature Commit is signed but in an unrecognized format.

stop linking against gcc files


4 files changed, 3 insertions(+), 175 deletions(-)

src/codegen.cpp-2
......@@ -9027,8 +9027,6 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
90279027 cache_buf(ch, &g->libc->include_dir);
90289028 cache_buf(ch, &g->libc->sys_include_dir);
90299029 cache_buf(ch, &g->libc->crt_dir);
9030 cache_buf(ch, &g->libc->lib_dir);
9031 cache_buf(ch, &g->libc->static_lib_dir);
90329030 cache_buf(ch, &g->libc->msvc_lib_dir);
90339031 cache_buf(ch, &g->libc->kernel32_lib_dir);
90349032 cache_buf(ch, &g->libc->dynamic_linker_path);
src/libc_installation.cpp+3-52
......@@ -14,8 +14,6 @@ static const char *zig_libc_keys[] = {
1414 "include_dir",
1515 "sys_include_dir",
1616 "crt_dir",
17 "lib_dir",
18 "static_lib_dir",
1917 "msvc_lib_dir",
2018 "kernel32_lib_dir",
2119 "dynamic_linker_path",
......@@ -37,8 +35,6 @@ static void zig_libc_init_empty(ZigLibCInstallation *libc) {
3735 buf_init_from_str(&libc->include_dir, "");
3836 buf_init_from_str(&libc->sys_include_dir, "");
3937 buf_init_from_str(&libc->crt_dir, "");
40 buf_init_from_str(&libc->lib_dir, "");
41 buf_init_from_str(&libc->static_lib_dir, "");
4238 buf_init_from_str(&libc->msvc_lib_dir, "");
4339 buf_init_from_str(&libc->kernel32_lib_dir, "");
4440 buf_init_from_str(&libc->dynamic_linker_path, "");
......@@ -80,11 +76,9 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget
8076 match = match || zig_libc_match_key(name, value, found_keys, 0, &libc->include_dir);
8177 match = match || zig_libc_match_key(name, value, found_keys, 1, &libc->sys_include_dir);
8278 match = match || zig_libc_match_key(name, value, found_keys, 2, &libc->crt_dir);
83 match = match || zig_libc_match_key(name, value, found_keys, 3, &libc->lib_dir);
84 match = match || zig_libc_match_key(name, value, found_keys, 4, &libc->static_lib_dir);
85 match = match || zig_libc_match_key(name, value, found_keys, 5, &libc->msvc_lib_dir);
86 match = match || zig_libc_match_key(name, value, found_keys, 6, &libc->kernel32_lib_dir);
87 match = match || zig_libc_match_key(name, value, found_keys, 7, &libc->dynamic_linker_path);
79 match = match || zig_libc_match_key(name, value, found_keys, 3, &libc->msvc_lib_dir);
80 match = match || zig_libc_match_key(name, value, found_keys, 4, &libc->kernel32_lib_dir);
81 match = match || zig_libc_match_key(name, value, found_keys, 5, &libc->dynamic_linker_path);
8882 }
8983
9084 for (size_t i = 0; i < zig_libc_keys_len; i += 1) {
......@@ -119,24 +113,6 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget
119113 }
120114 }
121115
122 if (buf_len(&libc->lib_dir) == 0) {
123 if (!target_is_darwin(target) && target->os != OsWindows) {
124 if (verbose) {
125 fprintf(stderr, "lib_dir may not be empty for %s\n", target_os_name(target->os));
126 }
127 return ErrorSemanticAnalyzeFail;
128 }
129 }
130
131 if (buf_len(&libc->static_lib_dir) == 0) {
132 if (!target_is_darwin(target) && target->os != OsWindows) {
133 if (verbose) {
134 fprintf(stderr, "static_lib_dir may not be empty for %s\n", target_os_name(target->os));
135 }
136 return ErrorSemanticAnalyzeFail;
137 }
138 }
139
140116 if (buf_len(&libc->msvc_lib_dir) == 0) {
141117 if (target->os == OsWindows) {
142118 if (verbose) {
......@@ -363,13 +339,6 @@ static Error zig_libc_cc_print_file_name(const char *o_file, Buf *out, bool want
363339static Error zig_libc_find_native_crt_dir_posix(ZigLibCInstallation *self, bool verbose) {
364340 return zig_libc_cc_print_file_name("crt1.o", &self->crt_dir, true, verbose);
365341}
366static Error zig_libc_find_native_lib_dir_posix(ZigLibCInstallation *self, bool verbose) {
367 return zig_libc_cc_print_file_name("libgcc_s.so", &self->lib_dir, true, verbose);
368}
369
370static Error zig_libc_find_native_static_lib_dir_posix(ZigLibCInstallation *self, bool verbose) {
371 return zig_libc_cc_print_file_name("crtbegin.o", &self->static_lib_dir, true, verbose);
372}
373342#endif
374343
375344static Error zig_libc_find_native_dynamic_linker_posix(ZigLibCInstallation *self, bool verbose) {
......@@ -414,16 +383,6 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file) {
414383 "# Not needed when targeting MacOS.\n"
415384 "crt_dir=%s\n"
416385 "\n"
417 "# The directory that contains `libgcc_s.so`.\n"
418 "# On POSIX, can be found with `cc -print-file-name=libgcc_s.so`.\n"
419 "# Not needed when targeting MacOS or Windows.\n"
420 "lib_dir=%s\n"
421 "\n"
422 "# The directory that contains `crtbegin.o`.\n"
423 "# On POSIX, can be found with `cc -print-file-name=crtbegin.o`.\n"
424 "# Not needed when targeting MacOS or Windows.\n"
425 "static_lib_dir=%s\n"
426 "\n"
427386 "# The directory that contains `vcruntime.lib`.\n"
428387 "# Only needed when targeting Windows.\n"
429388 "msvc_lib_dir=%s\n"
......@@ -440,8 +399,6 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file) {
440399 buf_ptr(&self->include_dir),
441400 buf_ptr(&self->sys_include_dir),
442401 buf_ptr(&self->crt_dir),
443 buf_ptr(&self->lib_dir),
444 buf_ptr(&self->static_lib_dir),
445402 buf_ptr(&self->msvc_lib_dir),
446403 buf_ptr(&self->kernel32_lib_dir),
447404 buf_ptr(&self->dynamic_linker_path)
......@@ -481,15 +438,9 @@ Error zig_libc_find_native(ZigLibCInstallation *self, bool verbose) {
481438 return err;
482439#if defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD)
483440 buf_init_from_str(&self->crt_dir, "/usr/lib");
484 buf_init_from_str(&self->lib_dir, "/usr/lib");
485 buf_init_from_str(&self->static_lib_dir, "/usr/lib");
486441#elif !defined(ZIG_OS_DARWIN)
487442 if ((err = zig_libc_find_native_crt_dir_posix(self, verbose)))
488443 return err;
489 if ((err = zig_libc_find_native_lib_dir_posix(self, verbose)))
490 return err;
491 if ((err = zig_libc_find_native_static_lib_dir_posix(self, verbose)))
492 return err;
493444#endif
494445 if ((err = zig_libc_find_native_dynamic_linker_posix(self, verbose)))
495446 return err;
src/libc_installation.hpp-2
......@@ -19,8 +19,6 @@ struct ZigLibCInstallation {
1919 Buf include_dir;
2020 Buf sys_include_dir;
2121 Buf crt_dir;
22 Buf lib_dir;
23 Buf static_lib_dir;
2422 Buf msvc_lib_dir;
2523 Buf kernel32_lib_dir;
2624 Buf dynamic_linker_path;
src/link.cpp-119
......@@ -305,13 +305,6 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) {
305305 }
306306}
307307
308static const char *get_libc_static_file(CodeGen *g, const char *file) {
309 assert(g->libc != nullptr);
310 Buf *out_buf = buf_alloc();
311 os_path_join(&g->libc->static_lib_dir, buf_create_from_str(file), out_buf);
312 return buf_ptr(out_buf);
313}
314
315308static Buf *build_a_raw(CodeGen *parent_gen, const char *aname, Buf *full_path) {
316309 // The Mach-O LLD code is not well maintained, and trips an assertion
317310 // when we link compiler_rt and builtin as libraries rather than objects.
......@@ -432,11 +425,6 @@ static void add_rpath(LinkJob *lj, Buf *rpath) {
432425 lj->rpath_table.put(rpath, true);
433426}
434427
435// TODO: try to get away with completely removing this functionality
436static bool want_gcc_objects(CodeGen *g) {
437 return g->libc != nullptr && buf_len(&g->libc->static_lib_dir) != 0;
438}
439
440428static void construct_linker_job_elf(LinkJob *lj) {
441429 CodeGen *g = lj->codegen;
442430
......@@ -480,22 +468,15 @@ static void construct_linker_job_elf(LinkJob *lj) {
480468
481469 if (lj->link_in_crt) {
482470 const char *crt1o;
483 const char *crtbegino;
484471 if (g->zig_target->os == OsNetBSD) {
485472 crt1o = "crt0.o";
486 crtbegino = "crtbegin.o";
487473 } else if (g->is_static) {
488474 crt1o = "crt1.o";
489 crtbegino = "crtbeginT.o";
490475 } else {
491476 crt1o = "Scrt1.o";
492 crtbegino = "crtbegin.o";
493477 }
494478 lj->args.append(get_libc_crt_file(g, crt1o));
495479 lj->args.append(get_libc_crt_file(g, "crti.o"));
496 if (want_gcc_objects(g)) {
497 lj->args.append(get_libc_static_file(g, crtbegino));
498 }
499480 }
500481
501482 for (size_t i = 0; i < g->rpath_list.length; i += 1) {
......@@ -533,14 +514,6 @@ static void construct_linker_job_elf(LinkJob *lj) {
533514 if (g->libc != nullptr) {
534515 lj->args.append("-L");
535516 lj->args.append(buf_ptr(&g->libc->crt_dir));
536
537 if (!buf_eql_buf(&g->libc->crt_dir, &g->libc->lib_dir)) {
538 lj->args.append("-L");
539 lj->args.append(buf_ptr(&g->libc->lib_dir));
540 }
541
542 lj->args.append("-L");
543 lj->args.append(buf_ptr(&g->libc->static_lib_dir));
544517 }
545518
546519 if (!g->is_static) {
......@@ -624,9 +597,6 @@ static void construct_linker_job_elf(LinkJob *lj) {
624597
625598 // crt end
626599 if (lj->link_in_crt) {
627 if (want_gcc_objects(g)) {
628 lj->args.append(get_libc_static_file(g, "crtend.o"));
629 }
630600 lj->args.append(get_libc_crt_file(g, "crtn.o"));
631601 }
632602
......@@ -731,95 +701,6 @@ static void add_nt_link_args(LinkJob *lj, bool is_library) {
731701 }
732702}
733703
734// These are n actual command lines from LINK.EXE UEFI builds (app & driver) to be used as guidance cleaning
735// up a bit for building the COFF linker args:
736// /OUT:"J:\coding\nebulae\k\x64\Release\k.efi" /LTCG:incremental /Driver /PDB:"J:\coding\nebulae\k\x64\Release\k.pdb" "UefiApplicationEntryPoint.lib" "UefiRuntimeLib.lib" "UefiHiiLib.lib" "UefiHiiServicesLib.lib" "UefiSortLib.lib" "UefiShellLib.lib" "GlueLib.lib" "BaseLib.lib" "BaseDebugPrintErrorLevelLib.lib" "BasePrintLib.lib" "UefiLib.lib" "UefiBootServicesTableLib.lib" "UefiRuntimeServicesTableLib.lib" "UefiDevicePathLibDevicePathProtocol.lib" "UefiDebugLibConOut.lib" "UefiMemoryLib.lib" "UefiMemoryAllocationLib.lib" "BaseSynchronizationLib.lib" "UefiFileHandleLib.lib" /IMPLIB:"J:\coding\nebulae\k\x64\Release\k.lib" /DEBUG:FASTLINK /BASE:"0" /MACHINE:X64 /ENTRY:"EfiMain" /OPT:REF /SAFESEH:NO /SUBSYSTEM:EFI_APPLICATION /MERGE:".rdata=.data" /NOLOGO /ALIGN:32 /NODEFAULTLIB /SECTION:".xdata,D"
737// /OUT:"J:\coding\VisualUefi\samples\x64\Release\UefiDriver.efi" /LTCG:incremental /Driver /PDB:"J:\coding\VisualUefi\samples\x64\Release\UefiDriver.pdb" "UefiDriverEntryPoint.lib" "UefiHiiLib.lib" "UefiHiiServicesLib.lib" "UefiSortLib.lib" "UefiShellLib.lib" "GlueLib.lib" "BaseLib.lib" "BaseDebugPrintErrorLevelLib.lib" "BasePrintLib.lib" "UefiLib.lib" "UefiBootServicesTableLib.lib" "UefiRuntimeServicesTableLib.lib" "UefiDevicePathLibDevicePathProtocol.lib" "UefiDebugLibConOut.lib" "UefiMemoryLib.lib" "UefiMemoryAllocationLib.lib" "BaseSynchronizationLib.lib" "UefiFileHandleLib.lib" /IMPLIB:"J:\coding\VisualUefi\samples\x64\Release\UefiDriver.lib" /DEBUG:FASTLINK /BASE:"0" /MACHINE:X64 /ENTRY:"EfiMain" /OPT:REF /SAFESEH:NO /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /MERGE:".rdata=.data" /NOLOGO /ALIGN:32 /NODEFAULTLIB /SECTION:".xdata,D"
738// This commented out stuff is from when we linked with MinGW
739// Now that we're linking with LLD it remains to be determined
740// how to handle --target-environ gnu
741// These comments are a clue
742//bool dll = g->out_type == OutTypeLib;
743//bool shared = !g->is_static && dll;
744//if (g->is_static) {
745// lj->args.append("-Bstatic");
746//} else {
747// if (dll) {
748// lj->args.append("--dll");
749// } else if (shared) {
750// lj->args.append("--shared");
751// }
752// lj->args.append("-Bdynamic");
753// if (dll || shared) {
754// lj->args.append("-e");
755// if (g->zig_target.arch == ZigLLVM_x86) {
756// lj->args.append("_DllMainCRTStartup@12");
757// } else {
758// lj->args.append("DllMainCRTStartup");
759// }
760// lj->args.append("--enable-auto-image-base");
761// }
762//}
763//if (shared || dll) {
764// lj->args.append(get_libc_file(g, "dllcrt2.o"));
765//} else {
766// if (g->windows_linker_unicode) {
767// lj->args.append(get_libc_file(g, "crt2u.o"));
768// } else {
769// lj->args.append(get_libc_file(g, "crt2.o"));
770// }
771//}
772//lj->args.append(get_libc_static_file(g, "crtbegin.o"));
773//if (g->libc_link_lib != nullptr) {
774//if (g->is_static) {
775// lj->args.append("--start-group");
776//}
777
778//lj->args.append("-lmingw32");
779
780//lj->args.append("-lgcc");
781//bool is_android = (g->zig_target.abi == ZigLLVM_Android);
782//bool is_cyg_ming = is_target_cyg_mingw(&g->zig_target);
783//if (!g->is_static && !is_android) {
784// if (!is_cyg_ming) {
785// lj->args.append("--as-needed");
786// }
787// //lj->args.append("-lgcc_s");
788// if (!is_cyg_ming) {
789// lj->args.append("--no-as-needed");
790// }
791//}
792//if (g->is_static && !is_android) {
793// //lj->args.append("-lgcc_eh");
794//}
795//if (is_android && !g->is_static) {
796// lj->args.append("-ldl");
797//}
798
799//lj->args.append("-lmoldname");
800//lj->args.append("-lmingwex");
801//lj->args.append("-lmsvcrt");
802
803
804//if (g->windows_subsystem_windows) {
805// lj->args.append("-lgdi32");
806// lj->args.append("-lcomdlg32");
807//}
808//lj->args.append("-ladvapi32");
809//lj->args.append("-lshell32");
810//lj->args.append("-luser32");
811//lj->args.append("-lkernel32");
812
813//if (g->is_static) {
814// lj->args.append("--end-group");
815//}
816
817//if (lj->link_in_crt) {
818// lj->args.append(get_libc_static_file(g, "crtend.o"));
819//}
820//}
821
822
823704static void construct_linker_job_coff(LinkJob *lj) {
824705 CodeGen *g = lj->codegen;
825706