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) {...@@ -9027,8 +9027,6 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
9027 cache_buf(ch, &g->libc->include_dir);9027 cache_buf(ch, &g->libc->include_dir);
9028 cache_buf(ch, &g->libc->sys_include_dir);9028 cache_buf(ch, &g->libc->sys_include_dir);
9029 cache_buf(ch, &g->libc->crt_dir);9029 cache_buf(ch, &g->libc->crt_dir);
9030 cache_buf(ch, &g->libc->lib_dir);
9031 cache_buf(ch, &g->libc->static_lib_dir);
9032 cache_buf(ch, &g->libc->msvc_lib_dir);9030 cache_buf(ch, &g->libc->msvc_lib_dir);
9033 cache_buf(ch, &g->libc->kernel32_lib_dir);9031 cache_buf(ch, &g->libc->kernel32_lib_dir);
9034 cache_buf(ch, &g->libc->dynamic_linker_path);9032 cache_buf(ch, &g->libc->dynamic_linker_path);
src/libc_installation.cpp+3-52
...@@ -14,8 +14,6 @@ static const char *zig_libc_keys[] = {...@@ -14,8 +14,6 @@ static const char *zig_libc_keys[] = {
14 "include_dir",14 "include_dir",
15 "sys_include_dir",15 "sys_include_dir",
16 "crt_dir",16 "crt_dir",
17 "lib_dir",
18 "static_lib_dir",
19 "msvc_lib_dir",17 "msvc_lib_dir",
20 "kernel32_lib_dir",18 "kernel32_lib_dir",
21 "dynamic_linker_path",19 "dynamic_linker_path",
...@@ -37,8 +35,6 @@ static void zig_libc_init_empty(ZigLibCInstallation *libc) {...@@ -37,8 +35,6 @@ static void zig_libc_init_empty(ZigLibCInstallation *libc) {
37 buf_init_from_str(&libc->include_dir, "");35 buf_init_from_str(&libc->include_dir, "");
38 buf_init_from_str(&libc->sys_include_dir, "");36 buf_init_from_str(&libc->sys_include_dir, "");
39 buf_init_from_str(&libc->crt_dir, "");37 buf_init_from_str(&libc->crt_dir, "");
40 buf_init_from_str(&libc->lib_dir, "");
41 buf_init_from_str(&libc->static_lib_dir, "");
42 buf_init_from_str(&libc->msvc_lib_dir, "");38 buf_init_from_str(&libc->msvc_lib_dir, "");
43 buf_init_from_str(&libc->kernel32_lib_dir, "");39 buf_init_from_str(&libc->kernel32_lib_dir, "");
44 buf_init_from_str(&libc->dynamic_linker_path, "");40 buf_init_from_str(&libc->dynamic_linker_path, "");
...@@ -80,11 +76,9 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget...@@ -80,11 +76,9 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget
80 match = match || zig_libc_match_key(name, value, found_keys, 0, &libc->include_dir);76 match = match || zig_libc_match_key(name, value, found_keys, 0, &libc->include_dir);
81 match = match || zig_libc_match_key(name, value, found_keys, 1, &libc->sys_include_dir);77 match = match || zig_libc_match_key(name, value, found_keys, 1, &libc->sys_include_dir);
82 match = match || zig_libc_match_key(name, value, found_keys, 2, &libc->crt_dir);78 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);79 match = match || zig_libc_match_key(name, value, found_keys, 3, &libc->msvc_lib_dir);
84 match = match || zig_libc_match_key(name, value, found_keys, 4, &libc->static_lib_dir);80 match = match || zig_libc_match_key(name, value, found_keys, 4, &libc->kernel32_lib_dir);
85 match = match || zig_libc_match_key(name, value, found_keys, 5, &libc->msvc_lib_dir);81 match = match || zig_libc_match_key(name, value, found_keys, 5, &libc->dynamic_linker_path);
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);
88 }82 }
8983
90 for (size_t i = 0; i < zig_libc_keys_len; i += 1) {84 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...@@ -119,24 +113,6 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget
119 }113 }
120 }114 }
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
140 if (buf_len(&libc->msvc_lib_dir) == 0) {116 if (buf_len(&libc->msvc_lib_dir) == 0) {
141 if (target->os == OsWindows) {117 if (target->os == OsWindows) {
142 if (verbose) {118 if (verbose) {
...@@ -363,13 +339,6 @@ static Error zig_libc_cc_print_file_name(const char *o_file, Buf *out, bool want...@@ -363,13 +339,6 @@ static Error zig_libc_cc_print_file_name(const char *o_file, Buf *out, bool want
363static Error zig_libc_find_native_crt_dir_posix(ZigLibCInstallation *self, bool verbose) {339static Error zig_libc_find_native_crt_dir_posix(ZigLibCInstallation *self, bool verbose) {
364 return zig_libc_cc_print_file_name("crt1.o", &self->crt_dir, true, verbose);340 return zig_libc_cc_print_file_name("crt1.o", &self->crt_dir, true, verbose);
365}341}
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}
373#endif342#endif
374343
375static Error zig_libc_find_native_dynamic_linker_posix(ZigLibCInstallation *self, bool verbose) {344static Error zig_libc_find_native_dynamic_linker_posix(ZigLibCInstallation *self, bool verbose) {
...@@ -414,16 +383,6 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file) {...@@ -414,16 +383,6 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file) {
414 "# Not needed when targeting MacOS.\n"383 "# Not needed when targeting MacOS.\n"
415 "crt_dir=%s\n"384 "crt_dir=%s\n"
416 "\n"385 "\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"
427 "# The directory that contains `vcruntime.lib`.\n"386 "# The directory that contains `vcruntime.lib`.\n"
428 "# Only needed when targeting Windows.\n"387 "# Only needed when targeting Windows.\n"
429 "msvc_lib_dir=%s\n"388 "msvc_lib_dir=%s\n"
...@@ -440,8 +399,6 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file) {...@@ -440,8 +399,6 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file) {
440 buf_ptr(&self->include_dir),399 buf_ptr(&self->include_dir),
441 buf_ptr(&self->sys_include_dir),400 buf_ptr(&self->sys_include_dir),
442 buf_ptr(&self->crt_dir),401 buf_ptr(&self->crt_dir),
443 buf_ptr(&self->lib_dir),
444 buf_ptr(&self->static_lib_dir),
445 buf_ptr(&self->msvc_lib_dir),402 buf_ptr(&self->msvc_lib_dir),
446 buf_ptr(&self->kernel32_lib_dir),403 buf_ptr(&self->kernel32_lib_dir),
447 buf_ptr(&self->dynamic_linker_path)404 buf_ptr(&self->dynamic_linker_path)
...@@ -481,15 +438,9 @@ Error zig_libc_find_native(ZigLibCInstallation *self, bool verbose) {...@@ -481,15 +438,9 @@ Error zig_libc_find_native(ZigLibCInstallation *self, bool verbose) {
481 return err;438 return err;
482#if defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD)439#if defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD)
483 buf_init_from_str(&self->crt_dir, "/usr/lib");440 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");
486#elif !defined(ZIG_OS_DARWIN)441#elif !defined(ZIG_OS_DARWIN)
487 if ((err = zig_libc_find_native_crt_dir_posix(self, verbose)))442 if ((err = zig_libc_find_native_crt_dir_posix(self, verbose)))
488 return err;443 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;
493#endif444#endif
494 if ((err = zig_libc_find_native_dynamic_linker_posix(self, verbose)))445 if ((err = zig_libc_find_native_dynamic_linker_posix(self, verbose)))
495 return err;446 return err;
src/libc_installation.hpp-2
...@@ -19,8 +19,6 @@ struct ZigLibCInstallation {...@@ -19,8 +19,6 @@ struct ZigLibCInstallation {
19 Buf include_dir;19 Buf include_dir;
20 Buf sys_include_dir;20 Buf sys_include_dir;
21 Buf crt_dir;21 Buf crt_dir;
22 Buf lib_dir;
23 Buf static_lib_dir;
24 Buf msvc_lib_dir;22 Buf msvc_lib_dir;
25 Buf kernel32_lib_dir;23 Buf kernel32_lib_dir;
26 Buf dynamic_linker_path;24 Buf dynamic_linker_path;
src/link.cpp-119
...@@ -305,13 +305,6 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) {...@@ -305,13 +305,6 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) {
305 }305 }
306}306}
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
315static Buf *build_a_raw(CodeGen *parent_gen, const char *aname, Buf *full_path) {308static Buf *build_a_raw(CodeGen *parent_gen, const char *aname, Buf *full_path) {
316 // The Mach-O LLD code is not well maintained, and trips an assertion309 // The Mach-O LLD code is not well maintained, and trips an assertion
317 // when we link compiler_rt and builtin as libraries rather than objects.310 // when we link compiler_rt and builtin as libraries rather than objects.
...@@ -432,11 +425,6 @@ static void add_rpath(LinkJob *lj, Buf *rpath) {...@@ -432,11 +425,6 @@ static void add_rpath(LinkJob *lj, Buf *rpath) {
432 lj->rpath_table.put(rpath, true);425 lj->rpath_table.put(rpath, true);
433}426}
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
440static void construct_linker_job_elf(LinkJob *lj) {428static void construct_linker_job_elf(LinkJob *lj) {
441 CodeGen *g = lj->codegen;429 CodeGen *g = lj->codegen;
442430
...@@ -480,22 +468,15 @@ static void construct_linker_job_elf(LinkJob *lj) {...@@ -480,22 +468,15 @@ static void construct_linker_job_elf(LinkJob *lj) {
480468
481 if (lj->link_in_crt) {469 if (lj->link_in_crt) {
482 const char *crt1o;470 const char *crt1o;
483 const char *crtbegino;
484 if (g->zig_target->os == OsNetBSD) {471 if (g->zig_target->os == OsNetBSD) {
485 crt1o = "crt0.o";472 crt1o = "crt0.o";
486 crtbegino = "crtbegin.o";
487 } else if (g->is_static) {473 } else if (g->is_static) {
488 crt1o = "crt1.o";474 crt1o = "crt1.o";
489 crtbegino = "crtbeginT.o";
490 } else {475 } else {
491 crt1o = "Scrt1.o";476 crt1o = "Scrt1.o";
492 crtbegino = "crtbegin.o";
493 }477 }
494 lj->args.append(get_libc_crt_file(g, crt1o));478 lj->args.append(get_libc_crt_file(g, crt1o));
495 lj->args.append(get_libc_crt_file(g, "crti.o"));479 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 }
499 }480 }
500481
501 for (size_t i = 0; i < g->rpath_list.length; i += 1) {482 for (size_t i = 0; i < g->rpath_list.length; i += 1) {
...@@ -533,14 +514,6 @@ static void construct_linker_job_elf(LinkJob *lj) {...@@ -533,14 +514,6 @@ static void construct_linker_job_elf(LinkJob *lj) {
533 if (g->libc != nullptr) {514 if (g->libc != nullptr) {
534 lj->args.append("-L");515 lj->args.append("-L");
535 lj->args.append(buf_ptr(&g->libc->crt_dir));516 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));
544 }517 }
545518
546 if (!g->is_static) {519 if (!g->is_static) {
...@@ -624,9 +597,6 @@ static void construct_linker_job_elf(LinkJob *lj) {...@@ -624,9 +597,6 @@ static void construct_linker_job_elf(LinkJob *lj) {
624597
625 // crt end598 // crt end
626 if (lj->link_in_crt) {599 if (lj->link_in_crt) {
627 if (want_gcc_objects(g)) {
628 lj->args.append(get_libc_static_file(g, "crtend.o"));
629 }
630 lj->args.append(get_libc_crt_file(g, "crtn.o"));600 lj->args.append(get_libc_crt_file(g, "crtn.o"));
631 }601 }
632602
...@@ -731,95 +701,6 @@ static void add_nt_link_args(LinkJob *lj, bool is_library) {...@@ -731,95 +701,6 @@ static void add_nt_link_args(LinkJob *lj, bool is_library) {
731 }701 }
732}702}
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
823static void construct_linker_job_coff(LinkJob *lj) {704static void construct_linker_job_coff(LinkJob *lj) {
824 CodeGen *g = lj->codegen;705 CodeGen *g = lj->codegen;
825706