authorgravatar for emekankurumeh@outlook.comemekoi <emekankurumeh@outlook.com> 2019-04-27 00:24:26-05:00
committergravatar for emekankurumeh@outlook.comemekoi <emekankurumeh@outlook.com> 2019-04-27 00:24:26-05:00
logdfada0cc77cb77a337baa784e4e96c7a94d217bb
tree95285d61908a6cadd5a5fbea4e969ddb6ddafa17
parentf4c5fa7ff46ad088e437dba237518df76736f087

added static_crt_dir to libc file


3 files changed, 56 insertions(+), 56 deletions(-)

src/libc_installation.cpp+30-6
......@@ -14,6 +14,7 @@ static const char *zig_libc_keys[] = {
1414 "include_dir",
1515 "sys_include_dir",
1616 "crt_dir",
17 "static_crt_dir",
1718 "msvc_lib_dir",
1819 "kernel32_lib_dir",
1920};
......@@ -34,6 +35,7 @@ static void zig_libc_init_empty(ZigLibCInstallation *libc) {
3435 buf_init_from_str(&libc->include_dir, "");
3536 buf_init_from_str(&libc->sys_include_dir, "");
3637 buf_init_from_str(&libc->crt_dir, "");
38 buf_init_from_str(&libc->static_crt_dir, "");
3739 buf_init_from_str(&libc->msvc_lib_dir, "");
3840 buf_init_from_str(&libc->kernel32_lib_dir, "");
3941}
......@@ -74,8 +76,9 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget
7476 match = match || zig_libc_match_key(name, value, found_keys, 0, &libc->include_dir);
7577 match = match || zig_libc_match_key(name, value, found_keys, 1, &libc->sys_include_dir);
7678 match = match || zig_libc_match_key(name, value, found_keys, 2, &libc->crt_dir);
77 match = match || zig_libc_match_key(name, value, found_keys, 3, &libc->msvc_lib_dir);
78 match = match || zig_libc_match_key(name, value, found_keys, 4, &libc->kernel32_lib_dir);
79 match = match || zig_libc_match_key(name, value, found_keys, 3, &libc->static_crt_dir);
80 match = match || zig_libc_match_key(name, value, found_keys, 4, &libc->msvc_lib_dir);
81 match = match || zig_libc_match_key(name, value, found_keys, 5, &libc->kernel32_lib_dir);
7982 }
8083
8184 for (size_t i = 0; i < zig_libc_keys_len; i += 1) {
......@@ -110,6 +113,15 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget
110113 }
111114 }
112115
116 if (buf_len(&libc->static_crt_dir) == 0) {
117 if (target->os == OsWindows && target_abi_is_gnu(target->abi)) {
118 if (verbose) {
119 fprintf(stderr, "static_crt_dir may not be empty for %s\n", target_os_name(target->os));
120 }
121 return ErrorSemanticAnalyzeFail;
122 }
123 }
124
113125 if (buf_len(&libc->msvc_lib_dir) == 0) {
114126 if (target->os == OsWindows && !target_abi_is_gnu(target->abi)) {
115127 if (verbose) {
......@@ -261,7 +273,7 @@ static Error zig_libc_find_native_include_dir_posix(ZigLibCInstallation *self, b
261273 return ErrorFileNotFound;
262274}
263275
264Error zig_libc_cc_print_file_name(const char *o_file, Buf *out, bool want_dirname, bool verbose) {
276static Error zig_libc_cc_print_file_name(const char *o_file, Buf *out, bool want_dirname, bool verbose) {
265277 const char *cc_exe = getenv("CC");
266278 cc_exe = (cc_exe == nullptr) ? CC_EXE : cc_exe;
267279 ZigList<const char *> args = {};
......@@ -308,6 +320,10 @@ static Error zig_libc_find_native_crt_dir_posix(ZigLibCInstallation *self, bool
308320 return zig_libc_cc_print_file_name("crt1.o", &self->crt_dir, true, verbose);
309321}
310322
323static Error zig_libc_find_native_static_crt_dir_posix(ZigLibCInstallation *self, bool verbose) {
324 return zig_libc_cc_print_file_name("crtbegin.o", &self->static_crt_dir, true, verbose);
325}
326
311327#if defined(ZIG_OS_WINDOWS)
312328static Error zig_libc_find_native_include_dir_windows(ZigLibCInstallation *self, ZigWindowsSDK *sdk, bool verbose) {
313329 Error err;
......@@ -320,7 +336,7 @@ static Error zig_libc_find_native_include_dir_windows(ZigLibCInstallation *self,
320336 return ErrorNone;
321337}
322338
323static Error zig_libc_find_crt_dir_windows(ZigLibCInstallation *self, ZigWindowsSDK *sdk, ZigTarget *target,
339static Error zig_libc_find_native_crt_dir_windows(ZigLibCInstallation *self, ZigWindowsSDK *sdk, ZigTarget *target,
324340 bool verbose)
325341{
326342 Error err;
......@@ -396,11 +412,16 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file) {
396412 "# On POSIX it's the directory that includes `sys/errno.h`.\n"
397413 "sys_include_dir=%s\n"
398414 "\n"
399 "# The directory that contains `crt1.o`.\n"
415 "# The directory that contains `crt1.o` or `crt2.o`.\n"
400416 "# On POSIX, can be found with `cc -print-file-name=crt1.o`.\n"
401417 "# Not needed when targeting MacOS.\n"
402418 "crt_dir=%s\n"
403419 "\n"
420 "# The directory that contains `crtbegin.o`.\n"
421 "# On POSIX, can be found with `cc -print-file-name=crtbegin.o`.\n"
422 "# Not needed when targeting MacOS.\n"
423 "static_crt_dir=%s\n"
424 "\n"
404425 "# The directory that contains `vcruntime.lib`.\n"
405426 "# Only needed when targeting MSVC on Windows.\n"
406427 "msvc_lib_dir=%s\n"
......@@ -413,6 +434,7 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file) {
413434 buf_ptr(&self->include_dir),
414435 buf_ptr(&self->sys_include_dir),
415436 buf_ptr(&self->crt_dir),
437 buf_ptr(&self->static_crt_dir),
416438 buf_ptr(&self->msvc_lib_dir),
417439 buf_ptr(&self->kernel32_lib_dir)
418440 );
......@@ -429,6 +451,8 @@ Error zig_libc_find_native(ZigLibCInstallation *self, bool verbose) {
429451 return err;
430452 if ((err = zig_libc_find_native_crt_dir_posix(self, verbose)))
431453 return err;
454 if ((err = zig_libc_find_native_static_crt_dir_posix(self, verbose)))
455 return err;
432456 return ErrorNone;
433457 } else {
434458 ZigWindowsSDK *sdk;
......@@ -442,7 +466,7 @@ Error zig_libc_find_native(ZigLibCInstallation *self, bool verbose) {
442466 return err;
443467 if ((err = zig_libc_find_native_include_dir_windows(self, sdk, verbose)))
444468 return err;
445 if ((err = zig_libc_find_crt_dir_windows(self, sdk, &native_target, verbose)))
469 if ((err = zig_libc_find_native_crt_dir_windows(self, sdk, &native_target, verbose)))
446470 return err;
447471 return ErrorNone;
448472 case ZigFindWindowsSdkErrorOutOfMemory:
src/libc_installation.hpp+1-2
......@@ -19,6 +19,7 @@ struct ZigLibCInstallation {
1919 Buf include_dir;
2020 Buf sys_include_dir;
2121 Buf crt_dir;
22 Buf static_crt_dir;
2223 Buf msvc_lib_dir;
2324 Buf kernel32_lib_dir;
2425};
......@@ -29,6 +30,4 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file);
2930
3031Error ATTRIBUTE_MUST_USE zig_libc_find_native(ZigLibCInstallation *self, bool verbose);
3132
32Error zig_libc_cc_print_file_name(const char *o_file, Buf *out, bool want_dirname, bool verbose);
33
3433#endif
src/link.cpp+25-48
......@@ -1170,12 +1170,8 @@ static const char *get_libc_file(ZigLibCInstallation *lib, const char *file) {
11701170}
11711171
11721172static const char *get_libc_static_file(ZigLibCInstallation *lib, const char *file) {
1173 Buf *static_crt_dir = buf_alloc();
11741173 Buf *out_buf = buf_alloc();
1175 if (zig_libc_cc_print_file_name(file, static_crt_dir, true, true) != ErrorNone) {
1176 abort();
1177 }
1178 os_path_join(static_crt_dir, buf_create_from_str(file), out_buf);
1174 os_path_join(&lib->static_crt_dir, buf_create_from_str(file), out_buf);
11791175 return buf_ptr(out_buf);
11801176}
11811177
......@@ -1198,35 +1194,33 @@ static void add_mingw_link_args(LinkJob *lj, bool is_library) {
11981194
11991195 lj->args.append(get_libc_static_file(g->libc, "crtbegin.o"));
12001196
1201 if (g->libc_link_lib != nullptr) {
1202 lj->args.append("libmingw32.a");
1197 lj->args.append(get_libc_file(g->libc, "libmingw32.a"));
12031198
1204 if (is_dll) {
1205 lj->args.append(get_libc_static_file(g->libc, "libgcc_s.a"));
1206 lj->args.append(get_libc_static_file(g->libc, "libgcc.a"));
1207 } else {
1208 lj->args.append(get_libc_static_file(g->libc, "libgcc.a"));
1209 lj->args.append(get_libc_static_file(g->libc, "libgcc_eh.a"));
1210 }
1199 if (is_dll) {
1200 lj->args.append(get_libc_static_file(g->libc, "libgcc_s.a"));
1201 lj->args.append(get_libc_static_file(g->libc, "libgcc.a"));
1202 } else {
1203 lj->args.append(get_libc_static_file(g->libc, "libgcc.a"));
1204 lj->args.append(get_libc_static_file(g->libc, "libgcc_eh.a"));
1205 }
12111206
1212 lj->args.append(get_libc_static_file(g->libc, "libssp.a"));
1213 lj->args.append("libmoldname.a");
1214 lj->args.append("libmingwex.a");
1215 lj->args.append("libmsvcrt.a");
1207 lj->args.append(get_libc_static_file(g->libc, "libssp.a"));
1208 lj->args.append(get_libc_file(g->libc, "libmoldname.a"));
1209 lj->args.append(get_libc_file(g->libc, "libmingwex.a"));
1210 lj->args.append(get_libc_file(g->libc, "libmsvcrt.a"));
12161211
1217 if (g->subsystem == TargetSubsystemWindows) {
1218 lj->args.append("libgdi32.a");
1219 lj->args.append("libcomdlg32.a");
1220 }
1212 if (g->subsystem == TargetSubsystemWindows) {
1213 lj->args.append(get_libc_file(g->libc, "libgdi32.a"));
1214 lj->args.append(get_libc_file(g->libc, "libcomdlg32.a"));
1215 }
12211216
1222 lj->args.append("libadvapi32.a");
1223 lj->args.append("libadvapi32.a");
1224 lj->args.append("libshell32.a");
1225 lj->args.append("libuser32.a");
1226 lj->args.append("libkernel32.a");
1217 lj->args.append(get_libc_file(g->libc, "libadvapi32.a"));
1218 lj->args.append(get_libc_file(g->libc, "libadvapi32.a"));
1219 lj->args.append(get_libc_file(g->libc, "libshell32.a"));
1220 lj->args.append(get_libc_file(g->libc, "libuser32.a"));
1221 lj->args.append(get_libc_file(g->libc, "libkernel32.a"));
12271222
1228 lj->args.append(get_libc_static_file(g->libc, "crtend.o"));
1229 }
1223 lj->args.append(get_libc_static_file(g->libc, "crtend.o"));
12301224}
12311225
12321226static void add_win_link_args(LinkJob *lj, bool is_library) {
......@@ -1359,25 +1353,8 @@ static void construct_linker_job_coff(LinkJob *lj) {
13591353 }
13601354 if (link_lib->provided_explicitly) {
13611355 if (target_abi_is_gnu(lj->codegen->zig_target->abi)) {
1362 static const char *test_names[3] = { "%s\\lib%s.dll.a", "%s\\lib%s.a", nullptr };
1363 bool exists = false;
1364
1365 for (size_t i = 0; test_names[i] != nullptr && !exists; i++) {
1366 for (size_t j = 0; j < g->lib_dirs.length; j += 1) {
1367 const char *lib_dir = g->lib_dirs.at(j);
1368 Buf *test_path = buf_sprintf(test_names[i], lib_dir, buf_ptr(link_lib->name));
1369 if (os_file_exists(test_path, &exists) != ErrorNone) {
1370 zig_panic("link: unable to check if file exists: %s", buf_ptr(test_path));
1371 } else if (exists) {
1372 lj->args.append(buf_ptr(test_path));
1373 break;
1374 }
1375 }
1376 }
1377
1378 if (!exists) {
1379 zig_panic("link: unable to find library: %s", buf_ptr(link_lib->name));
1380 }
1356 Buf *lib_name = buf_sprintf("lib%s.a", buf_ptr(link_lib->name));
1357 lj->args.append(buf_ptr(lib_name));
13811358 } else {
13821359 lj->args.append(buf_ptr(link_lib->name));
13831360 }