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[] = {...@@ -14,6 +14,7 @@ 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 "static_crt_dir",
17 "msvc_lib_dir",18 "msvc_lib_dir",
18 "kernel32_lib_dir",19 "kernel32_lib_dir",
19};20};
...@@ -34,6 +35,7 @@ static void zig_libc_init_empty(ZigLibCInstallation *libc) {...@@ -34,6 +35,7 @@ static void zig_libc_init_empty(ZigLibCInstallation *libc) {
34 buf_init_from_str(&libc->include_dir, "");35 buf_init_from_str(&libc->include_dir, "");
35 buf_init_from_str(&libc->sys_include_dir, "");36 buf_init_from_str(&libc->sys_include_dir, "");
36 buf_init_from_str(&libc->crt_dir, "");37 buf_init_from_str(&libc->crt_dir, "");
38 buf_init_from_str(&libc->static_crt_dir, "");
37 buf_init_from_str(&libc->msvc_lib_dir, "");39 buf_init_from_str(&libc->msvc_lib_dir, "");
38 buf_init_from_str(&libc->kernel32_lib_dir, "");40 buf_init_from_str(&libc->kernel32_lib_dir, "");
39}41}
...@@ -74,8 +76,9 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget...@@ -74,8 +76,9 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget
74 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);
75 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);
76 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);
77 match = match || zig_libc_match_key(name, value, found_keys, 3, &libc->msvc_lib_dir);79 match = match || zig_libc_match_key(name, value, found_keys, 3, &libc->static_crt_dir);
78 match = match || zig_libc_match_key(name, value, found_keys, 4, &libc->kernel32_lib_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);
79 }82 }
8083
81 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) {
...@@ -110,6 +113,15 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget...@@ -110,6 +113,15 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget
110 }113 }
111 }114 }
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
113 if (buf_len(&libc->msvc_lib_dir) == 0) {125 if (buf_len(&libc->msvc_lib_dir) == 0) {
114 if (target->os == OsWindows && !target_abi_is_gnu(target->abi)) {126 if (target->os == OsWindows && !target_abi_is_gnu(target->abi)) {
115 if (verbose) {127 if (verbose) {
...@@ -261,7 +273,7 @@ static Error zig_libc_find_native_include_dir_posix(ZigLibCInstallation *self, b...@@ -261,7 +273,7 @@ static Error zig_libc_find_native_include_dir_posix(ZigLibCInstallation *self, b
261 return ErrorFileNotFound;273 return ErrorFileNotFound;
262}274}
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) {
265 const char *cc_exe = getenv("CC");277 const char *cc_exe = getenv("CC");
266 cc_exe = (cc_exe == nullptr) ? CC_EXE : cc_exe;278 cc_exe = (cc_exe == nullptr) ? CC_EXE : cc_exe;
267 ZigList<const char *> args = {};279 ZigList<const char *> args = {};
...@@ -308,6 +320,10 @@ static Error zig_libc_find_native_crt_dir_posix(ZigLibCInstallation *self, bool...@@ -308,6 +320,10 @@ static Error zig_libc_find_native_crt_dir_posix(ZigLibCInstallation *self, bool
308 return zig_libc_cc_print_file_name("crt1.o", &self->crt_dir, true, verbose);320 return zig_libc_cc_print_file_name("crt1.o", &self->crt_dir, true, verbose);
309}321}
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
311#if defined(ZIG_OS_WINDOWS)327#if defined(ZIG_OS_WINDOWS)
312static Error zig_libc_find_native_include_dir_windows(ZigLibCInstallation *self, ZigWindowsSDK *sdk, bool verbose) {328static Error zig_libc_find_native_include_dir_windows(ZigLibCInstallation *self, ZigWindowsSDK *sdk, bool verbose) {
313 Error err;329 Error err;
...@@ -320,7 +336,7 @@ static Error zig_libc_find_native_include_dir_windows(ZigLibCInstallation *self,...@@ -320,7 +336,7 @@ static Error zig_libc_find_native_include_dir_windows(ZigLibCInstallation *self,
320 return ErrorNone;336 return ErrorNone;
321}337}
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,
324 bool verbose)340 bool verbose)
325{341{
326 Error err;342 Error err;
...@@ -396,11 +412,16 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file) {...@@ -396,11 +412,16 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file) {
396 "# On POSIX it's the directory that includes `sys/errno.h`.\n"412 "# On POSIX it's the directory that includes `sys/errno.h`.\n"
397 "sys_include_dir=%s\n"413 "sys_include_dir=%s\n"
398 "\n"414 "\n"
399 "# The directory that contains `crt1.o`.\n"415 "# The directory that contains `crt1.o` or `crt2.o`.\n"
400 "# On POSIX, can be found with `cc -print-file-name=crt1.o`.\n"416 "# On POSIX, can be found with `cc -print-file-name=crt1.o`.\n"
401 "# Not needed when targeting MacOS.\n"417 "# Not needed when targeting MacOS.\n"
402 "crt_dir=%s\n"418 "crt_dir=%s\n"
403 "\n"419 "\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"
404 "# The directory that contains `vcruntime.lib`.\n"425 "# The directory that contains `vcruntime.lib`.\n"
405 "# Only needed when targeting MSVC on Windows.\n"426 "# Only needed when targeting MSVC on Windows.\n"
406 "msvc_lib_dir=%s\n"427 "msvc_lib_dir=%s\n"
...@@ -413,6 +434,7 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file) {...@@ -413,6 +434,7 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file) {
413 buf_ptr(&self->include_dir),434 buf_ptr(&self->include_dir),
414 buf_ptr(&self->sys_include_dir),435 buf_ptr(&self->sys_include_dir),
415 buf_ptr(&self->crt_dir),436 buf_ptr(&self->crt_dir),
437 buf_ptr(&self->static_crt_dir),
416 buf_ptr(&self->msvc_lib_dir),438 buf_ptr(&self->msvc_lib_dir),
417 buf_ptr(&self->kernel32_lib_dir)439 buf_ptr(&self->kernel32_lib_dir)
418 );440 );
...@@ -429,6 +451,8 @@ Error zig_libc_find_native(ZigLibCInstallation *self, bool verbose) {...@@ -429,6 +451,8 @@ Error zig_libc_find_native(ZigLibCInstallation *self, bool verbose) {
429 return err;451 return err;
430 if ((err = zig_libc_find_native_crt_dir_posix(self, verbose)))452 if ((err = zig_libc_find_native_crt_dir_posix(self, verbose)))
431 return err;453 return err;
454 if ((err = zig_libc_find_native_static_crt_dir_posix(self, verbose)))
455 return err;
432 return ErrorNone;456 return ErrorNone;
433 } else {457 } else {
434 ZigWindowsSDK *sdk;458 ZigWindowsSDK *sdk;
...@@ -442,7 +466,7 @@ Error zig_libc_find_native(ZigLibCInstallation *self, bool verbose) {...@@ -442,7 +466,7 @@ Error zig_libc_find_native(ZigLibCInstallation *self, bool verbose) {
442 return err;466 return err;
443 if ((err = zig_libc_find_native_include_dir_windows(self, sdk, verbose)))467 if ((err = zig_libc_find_native_include_dir_windows(self, sdk, verbose)))
444 return err;468 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)))
446 return err;470 return err;
447 return ErrorNone;471 return ErrorNone;
448 case ZigFindWindowsSdkErrorOutOfMemory:472 case ZigFindWindowsSdkErrorOutOfMemory:
src/libc_installation.hpp+1-2
...@@ -19,6 +19,7 @@ struct ZigLibCInstallation {...@@ -19,6 +19,7 @@ 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 static_crt_dir;
22 Buf msvc_lib_dir;23 Buf msvc_lib_dir;
23 Buf kernel32_lib_dir;24 Buf kernel32_lib_dir;
24};25};
...@@ -29,6 +30,4 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file);...@@ -29,6 +30,4 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file);
2930
30Error ATTRIBUTE_MUST_USE zig_libc_find_native(ZigLibCInstallation *self, bool verbose);31Error 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
34#endif33#endif
src/link.cpp+25-48
...@@ -1170,12 +1170,8 @@ static const char *get_libc_file(ZigLibCInstallation *lib, const char *file) {...@@ -1170,12 +1170,8 @@ static const char *get_libc_file(ZigLibCInstallation *lib, const char *file) {
1170}1170}
11711171
1172static const char *get_libc_static_file(ZigLibCInstallation *lib, const char *file) {1172static const char *get_libc_static_file(ZigLibCInstallation *lib, const char *file) {
1173 Buf *static_crt_dir = buf_alloc();
1174 Buf *out_buf = buf_alloc();1173 Buf *out_buf = buf_alloc();
1175 if (zig_libc_cc_print_file_name(file, static_crt_dir, true, true) != ErrorNone) {1174 os_path_join(&lib->static_crt_dir, buf_create_from_str(file), out_buf);
1176 abort();
1177 }
1178 os_path_join(static_crt_dir, buf_create_from_str(file), out_buf);
1179 return buf_ptr(out_buf);1175 return buf_ptr(out_buf);
1180}1176}
11811177
...@@ -1198,35 +1194,33 @@ static void add_mingw_link_args(LinkJob *lj, bool is_library) {...@@ -1198,35 +1194,33 @@ static void add_mingw_link_args(LinkJob *lj, bool is_library) {
11981194
1199 lj->args.append(get_libc_static_file(g->libc, "crtbegin.o"));1195 lj->args.append(get_libc_static_file(g->libc, "crtbegin.o"));
12001196
1201 if (g->libc_link_lib != nullptr) {1197 lj->args.append(get_libc_file(g->libc, "libmingw32.a"));
1202 lj->args.append("libmingw32.a");
12031198
1204 if (is_dll) {1199 if (is_dll) {
1205 lj->args.append(get_libc_static_file(g->libc, "libgcc_s.a"));1200 lj->args.append(get_libc_static_file(g->libc, "libgcc_s.a"));
1206 lj->args.append(get_libc_static_file(g->libc, "libgcc.a"));1201 lj->args.append(get_libc_static_file(g->libc, "libgcc.a"));
1207 } else {1202 } else {
1208 lj->args.append(get_libc_static_file(g->libc, "libgcc.a"));1203 lj->args.append(get_libc_static_file(g->libc, "libgcc.a"));
1209 lj->args.append(get_libc_static_file(g->libc, "libgcc_eh.a"));1204 lj->args.append(get_libc_static_file(g->libc, "libgcc_eh.a"));
1210 }1205 }
12111206
1212 lj->args.append(get_libc_static_file(g->libc, "libssp.a"));1207 lj->args.append(get_libc_static_file(g->libc, "libssp.a"));
1213 lj->args.append("libmoldname.a");1208 lj->args.append(get_libc_file(g->libc, "libmoldname.a"));
1214 lj->args.append("libmingwex.a");1209 lj->args.append(get_libc_file(g->libc, "libmingwex.a"));
1215 lj->args.append("libmsvcrt.a");1210 lj->args.append(get_libc_file(g->libc, "libmsvcrt.a"));
12161211
1217 if (g->subsystem == TargetSubsystemWindows) {1212 if (g->subsystem == TargetSubsystemWindows) {
1218 lj->args.append("libgdi32.a");1213 lj->args.append(get_libc_file(g->libc, "libgdi32.a"));
1219 lj->args.append("libcomdlg32.a");1214 lj->args.append(get_libc_file(g->libc, "libcomdlg32.a"));
1220 }1215 }
12211216
1222 lj->args.append("libadvapi32.a");1217 lj->args.append(get_libc_file(g->libc, "libadvapi32.a"));
1223 lj->args.append("libadvapi32.a");1218 lj->args.append(get_libc_file(g->libc, "libadvapi32.a"));
1224 lj->args.append("libshell32.a");1219 lj->args.append(get_libc_file(g->libc, "libshell32.a"));
1225 lj->args.append("libuser32.a");1220 lj->args.append(get_libc_file(g->libc, "libuser32.a"));
1226 lj->args.append("libkernel32.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"));1223 lj->args.append(get_libc_static_file(g->libc, "crtend.o"));
1229 }
1230}1224}
12311225
1232static void add_win_link_args(LinkJob *lj, bool is_library) {1226static void add_win_link_args(LinkJob *lj, bool is_library) {
...@@ -1359,25 +1353,8 @@ static void construct_linker_job_coff(LinkJob *lj) {...@@ -1359,25 +1353,8 @@ static void construct_linker_job_coff(LinkJob *lj) {
1359 }1353 }
1360 if (link_lib->provided_explicitly) {1354 if (link_lib->provided_explicitly) {
1361 if (target_abi_is_gnu(lj->codegen->zig_target->abi)) {1355 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 };1356 Buf *lib_name = buf_sprintf("lib%s.a", buf_ptr(link_lib->name));
1363 bool exists = false;1357 lj->args.append(buf_ptr(lib_name));
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 }
1381 } else {1358 } else {
1382 lj->args.append(buf_ptr(link_lib->name));1359 lj->args.append(buf_ptr(link_lib->name));
1383 }1360 }