stop linking against gcc files

This commit is contained in:
Andrew Kelley 2019-03-05 14:37:32 -05:00
parent dd263eccb7
commit 0d10ab0680
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
4 changed files with 3 additions and 175 deletions

View File

@ -9027,8 +9027,6 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
cache_buf(ch, &g->libc->include_dir);
cache_buf(ch, &g->libc->sys_include_dir);
cache_buf(ch, &g->libc->crt_dir);
cache_buf(ch, &g->libc->lib_dir);
cache_buf(ch, &g->libc->static_lib_dir);
cache_buf(ch, &g->libc->msvc_lib_dir);
cache_buf(ch, &g->libc->kernel32_lib_dir);
cache_buf(ch, &g->libc->dynamic_linker_path);

View File

@ -14,8 +14,6 @@ static const char *zig_libc_keys[] = {
"include_dir",
"sys_include_dir",
"crt_dir",
"lib_dir",
"static_lib_dir",
"msvc_lib_dir",
"kernel32_lib_dir",
"dynamic_linker_path",
@ -37,8 +35,6 @@ static void zig_libc_init_empty(ZigLibCInstallation *libc) {
buf_init_from_str(&libc->include_dir, "");
buf_init_from_str(&libc->sys_include_dir, "");
buf_init_from_str(&libc->crt_dir, "");
buf_init_from_str(&libc->lib_dir, "");
buf_init_from_str(&libc->static_lib_dir, "");
buf_init_from_str(&libc->msvc_lib_dir, "");
buf_init_from_str(&libc->kernel32_lib_dir, "");
buf_init_from_str(&libc->dynamic_linker_path, "");
@ -80,11 +76,9 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget
match = match || zig_libc_match_key(name, value, found_keys, 0, &libc->include_dir);
match = match || zig_libc_match_key(name, value, found_keys, 1, &libc->sys_include_dir);
match = match || zig_libc_match_key(name, value, found_keys, 2, &libc->crt_dir);
match = match || zig_libc_match_key(name, value, found_keys, 3, &libc->lib_dir);
match = match || zig_libc_match_key(name, value, found_keys, 4, &libc->static_lib_dir);
match = match || zig_libc_match_key(name, value, found_keys, 5, &libc->msvc_lib_dir);
match = match || zig_libc_match_key(name, value, found_keys, 6, &libc->kernel32_lib_dir);
match = match || zig_libc_match_key(name, value, found_keys, 7, &libc->dynamic_linker_path);
match = match || zig_libc_match_key(name, value, found_keys, 3, &libc->msvc_lib_dir);
match = match || zig_libc_match_key(name, value, found_keys, 4, &libc->kernel32_lib_dir);
match = match || zig_libc_match_key(name, value, found_keys, 5, &libc->dynamic_linker_path);
}
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
}
}
if (buf_len(&libc->lib_dir) == 0) {
if (!target_is_darwin(target) && target->os != OsWindows) {
if (verbose) {
fprintf(stderr, "lib_dir may not be empty for %s\n", target_os_name(target->os));
}
return ErrorSemanticAnalyzeFail;
}
}
if (buf_len(&libc->static_lib_dir) == 0) {
if (!target_is_darwin(target) && target->os != OsWindows) {
if (verbose) {
fprintf(stderr, "static_lib_dir may not be empty for %s\n", target_os_name(target->os));
}
return ErrorSemanticAnalyzeFail;
}
}
if (buf_len(&libc->msvc_lib_dir) == 0) {
if (target->os == OsWindows) {
if (verbose) {
@ -363,13 +339,6 @@ static Error zig_libc_cc_print_file_name(const char *o_file, Buf *out, bool want
static Error zig_libc_find_native_crt_dir_posix(ZigLibCInstallation *self, bool verbose) {
return zig_libc_cc_print_file_name("crt1.o", &self->crt_dir, true, verbose);
}
static Error zig_libc_find_native_lib_dir_posix(ZigLibCInstallation *self, bool verbose) {
return zig_libc_cc_print_file_name("libgcc_s.so", &self->lib_dir, true, verbose);
}
static Error zig_libc_find_native_static_lib_dir_posix(ZigLibCInstallation *self, bool verbose) {
return zig_libc_cc_print_file_name("crtbegin.o", &self->static_lib_dir, true, verbose);
}
#endif
static Error zig_libc_find_native_dynamic_linker_posix(ZigLibCInstallation *self, bool verbose) {
@ -414,16 +383,6 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file) {
"# Not needed when targeting MacOS.\n"
"crt_dir=%s\n"
"\n"
"# The directory that contains `libgcc_s.so`.\n"
"# On POSIX, can be found with `cc -print-file-name=libgcc_s.so`.\n"
"# Not needed when targeting MacOS or Windows.\n"
"lib_dir=%s\n"
"\n"
"# The directory that contains `crtbegin.o`.\n"
"# On POSIX, can be found with `cc -print-file-name=crtbegin.o`.\n"
"# Not needed when targeting MacOS or Windows.\n"
"static_lib_dir=%s\n"
"\n"
"# The directory that contains `vcruntime.lib`.\n"
"# Only needed when targeting Windows.\n"
"msvc_lib_dir=%s\n"
@ -440,8 +399,6 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file) {
buf_ptr(&self->include_dir),
buf_ptr(&self->sys_include_dir),
buf_ptr(&self->crt_dir),
buf_ptr(&self->lib_dir),
buf_ptr(&self->static_lib_dir),
buf_ptr(&self->msvc_lib_dir),
buf_ptr(&self->kernel32_lib_dir),
buf_ptr(&self->dynamic_linker_path)
@ -481,15 +438,9 @@ Error zig_libc_find_native(ZigLibCInstallation *self, bool verbose) {
return err;
#if defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD)
buf_init_from_str(&self->crt_dir, "/usr/lib");
buf_init_from_str(&self->lib_dir, "/usr/lib");
buf_init_from_str(&self->static_lib_dir, "/usr/lib");
#elif !defined(ZIG_OS_DARWIN)
if ((err = zig_libc_find_native_crt_dir_posix(self, verbose)))
return err;
if ((err = zig_libc_find_native_lib_dir_posix(self, verbose)))
return err;
if ((err = zig_libc_find_native_static_lib_dir_posix(self, verbose)))
return err;
#endif
if ((err = zig_libc_find_native_dynamic_linker_posix(self, verbose)))
return err;

View File

@ -19,8 +19,6 @@ struct ZigLibCInstallation {
Buf include_dir;
Buf sys_include_dir;
Buf crt_dir;
Buf lib_dir;
Buf static_lib_dir;
Buf msvc_lib_dir;
Buf kernel32_lib_dir;
Buf dynamic_linker_path;

View File

@ -305,13 +305,6 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) {
}
}
static const char *get_libc_static_file(CodeGen *g, const char *file) {
assert(g->libc != nullptr);
Buf *out_buf = buf_alloc();
os_path_join(&g->libc->static_lib_dir, buf_create_from_str(file), out_buf);
return buf_ptr(out_buf);
}
static Buf *build_a_raw(CodeGen *parent_gen, const char *aname, Buf *full_path) {
// The Mach-O LLD code is not well maintained, and trips an assertion
// when we link compiler_rt and builtin as libraries rather than objects.
@ -432,11 +425,6 @@ static void add_rpath(LinkJob *lj, Buf *rpath) {
lj->rpath_table.put(rpath, true);
}
// TODO: try to get away with completely removing this functionality
static bool want_gcc_objects(CodeGen *g) {
return g->libc != nullptr && buf_len(&g->libc->static_lib_dir) != 0;
}
static void construct_linker_job_elf(LinkJob *lj) {
CodeGen *g = lj->codegen;
@ -480,22 +468,15 @@ static void construct_linker_job_elf(LinkJob *lj) {
if (lj->link_in_crt) {
const char *crt1o;
const char *crtbegino;
if (g->zig_target->os == OsNetBSD) {
crt1o = "crt0.o";
crtbegino = "crtbegin.o";
} else if (g->is_static) {
crt1o = "crt1.o";
crtbegino = "crtbeginT.o";
} else {
crt1o = "Scrt1.o";
crtbegino = "crtbegin.o";
}
lj->args.append(get_libc_crt_file(g, crt1o));
lj->args.append(get_libc_crt_file(g, "crti.o"));
if (want_gcc_objects(g)) {
lj->args.append(get_libc_static_file(g, crtbegino));
}
}
for (size_t i = 0; i < g->rpath_list.length; i += 1) {
@ -533,14 +514,6 @@ static void construct_linker_job_elf(LinkJob *lj) {
if (g->libc != nullptr) {
lj->args.append("-L");
lj->args.append(buf_ptr(&g->libc->crt_dir));
if (!buf_eql_buf(&g->libc->crt_dir, &g->libc->lib_dir)) {
lj->args.append("-L");
lj->args.append(buf_ptr(&g->libc->lib_dir));
}
lj->args.append("-L");
lj->args.append(buf_ptr(&g->libc->static_lib_dir));
}
if (!g->is_static) {
@ -624,9 +597,6 @@ static void construct_linker_job_elf(LinkJob *lj) {
// crt end
if (lj->link_in_crt) {
if (want_gcc_objects(g)) {
lj->args.append(get_libc_static_file(g, "crtend.o"));
}
lj->args.append(get_libc_crt_file(g, "crtn.o"));
}
@ -731,95 +701,6 @@ static void add_nt_link_args(LinkJob *lj, bool is_library) {
}
}
// These are n actual command lines from LINK.EXE UEFI builds (app & driver) to be used as guidance cleaning
// up a bit for building the COFF linker args:
// /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"
// /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"
// This commented out stuff is from when we linked with MinGW
// Now that we're linking with LLD it remains to be determined
// how to handle --target-environ gnu
// These comments are a clue
//bool dll = g->out_type == OutTypeLib;
//bool shared = !g->is_static && dll;
//if (g->is_static) {
// lj->args.append("-Bstatic");
//} else {
// if (dll) {
// lj->args.append("--dll");
// } else if (shared) {
// lj->args.append("--shared");
// }
// lj->args.append("-Bdynamic");
// if (dll || shared) {
// lj->args.append("-e");
// if (g->zig_target.arch == ZigLLVM_x86) {
// lj->args.append("_DllMainCRTStartup@12");
// } else {
// lj->args.append("DllMainCRTStartup");
// }
// lj->args.append("--enable-auto-image-base");
// }
//}
//if (shared || dll) {
// lj->args.append(get_libc_file(g, "dllcrt2.o"));
//} else {
// if (g->windows_linker_unicode) {
// lj->args.append(get_libc_file(g, "crt2u.o"));
// } else {
// lj->args.append(get_libc_file(g, "crt2.o"));
// }
//}
//lj->args.append(get_libc_static_file(g, "crtbegin.o"));
//if (g->libc_link_lib != nullptr) {
//if (g->is_static) {
// lj->args.append("--start-group");
//}
//lj->args.append("-lmingw32");
//lj->args.append("-lgcc");
//bool is_android = (g->zig_target.abi == ZigLLVM_Android);
//bool is_cyg_ming = is_target_cyg_mingw(&g->zig_target);
//if (!g->is_static && !is_android) {
// if (!is_cyg_ming) {
// lj->args.append("--as-needed");
// }
// //lj->args.append("-lgcc_s");
// if (!is_cyg_ming) {
// lj->args.append("--no-as-needed");
// }
//}
//if (g->is_static && !is_android) {
// //lj->args.append("-lgcc_eh");
//}
//if (is_android && !g->is_static) {
// lj->args.append("-ldl");
//}
//lj->args.append("-lmoldname");
//lj->args.append("-lmingwex");
//lj->args.append("-lmsvcrt");
//if (g->windows_subsystem_windows) {
// lj->args.append("-lgdi32");
// lj->args.append("-lcomdlg32");
//}
//lj->args.append("-ladvapi32");
//lj->args.append("-lshell32");
//lj->args.append("-luser32");
//lj->args.append("-lkernel32");
//if (g->is_static) {
// lj->args.append("--end-group");
//}
//if (lj->link_in_crt) {
// lj->args.append(get_libc_static_file(g, "crtend.o"));
//}
//}
static void construct_linker_job_coff(LinkJob *lj) {
CodeGen *g = lj->codegen;