authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-05 22:45:41-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-05 22:45:41-05:00
logba144b366c40790f6d77a68b25d4567502601dc1
tree6a56ae71620ac0b5994d9564eb0a88af11eb9a64
parent5cecb5e479cc543a929ae6856d6efdea2a59844f
signaturelock-open Commit is signed but in an unrecognized format.

build libunwind.a from source and link it


4 files changed, 374 insertions(+), 37 deletions(-)

CMakeLists.txt+224
......@@ -1408,6 +1408,219 @@ set(ZIG_LIBC_FILES
14081408 "glibc/time/time.h"
14091409)
14101410
1411set(ZIG_LIBUNWIND_FILES
1412 "include/__libunwind_config.h"
1413 "include/libunwind.h"
1414 "include/mach-o/compact_unwind_encoding.h"
1415 "include/unwind.h"
1416 "src/AddressSpace.hpp"
1417 "src/CompactUnwinder.hpp"
1418 "src/DwarfInstructions.hpp"
1419 "src/DwarfParser.hpp"
1420 "src/EHHeaderParser.hpp"
1421 "src/RWMutex.hpp"
1422 "src/Registers.hpp"
1423 "src/Unwind-EHABI.cpp"
1424 "src/Unwind-EHABI.h"
1425 "src/Unwind-seh.cpp"
1426 "src/Unwind-sjlj.c"
1427 "src/UnwindCursor.hpp"
1428 "src/UnwindLevel1-gcc-ext.c"
1429 "src/UnwindLevel1.c"
1430 "src/UnwindRegistersRestore.S"
1431 "src/UnwindRegistersSave.S"
1432 "src/Unwind_AppleExtras.cpp"
1433 "src/assembly.h"
1434 "src/config.h"
1435 "src/dwarf2.h"
1436 "src/libunwind.cpp"
1437 "src/libunwind_ext.h"
1438)
1439
1440set(ZIG_LIBCXX_FILES
1441 "include/__bit_reference"
1442 "include/__bsd_locale_defaults.h"
1443 "include/__bsd_locale_fallbacks.h"
1444 "include/__config"
1445 "include/__config_site.in"
1446 "include/__debug"
1447 "include/__errc"
1448 "include/__functional_03"
1449 "include/__functional_base"
1450 "include/__functional_base_03"
1451 "include/__hash_table"
1452 "include/__libcpp_version"
1453 "include/__locale"
1454 "include/__mutex_base"
1455 "include/__node_handle"
1456 "include/__nullptr"
1457 "include/__split_buffer"
1458 "include/__sso_allocator"
1459 "include/__std_stream"
1460 "include/__string"
1461 "include/__threading_support"
1462 "include/__tree"
1463 "include/__tuple"
1464 "include/__undef_macros"
1465 "include/algorithm"
1466 "include/any"
1467 "include/array"
1468 "include/atomic"
1469 "include/bit"
1470 "include/bitset"
1471 "include/cassert"
1472 "include/ccomplex"
1473 "include/cctype"
1474 "include/cerrno"
1475 "include/cfenv"
1476 "include/cfloat"
1477 "include/charconv"
1478 "include/chrono"
1479 "include/cinttypes"
1480 "include/ciso646"
1481 "include/climits"
1482 "include/clocale"
1483 "include/cmath"
1484 "include/codecvt"
1485 "include/compare"
1486 "include/complex"
1487 "include/complex.h"
1488 "include/condition_variable"
1489 "include/csetjmp"
1490 "include/csignal"
1491 "include/cstdarg"
1492 "include/cstdbool"
1493 "include/cstddef"
1494 "include/cstdint"
1495 "include/cstdio"
1496 "include/cstdlib"
1497 "include/cstring"
1498 "include/ctgmath"
1499 "include/ctime"
1500 "include/ctype.h"
1501 "include/cwchar"
1502 "include/cwctype"
1503 "include/deque"
1504 "include/errno.h"
1505 "include/exception"
1506 "include/experimental/__config"
1507 "include/experimental/__memory"
1508 "include/experimental/algorithm"
1509 "include/experimental/any"
1510 "include/experimental/chrono"
1511 "include/experimental/coroutine"
1512 "include/experimental/deque"
1513 "include/experimental/filesystem"
1514 "include/experimental/forward_list"
1515 "include/experimental/functional"
1516 "include/experimental/iterator"
1517 "include/experimental/list"
1518 "include/experimental/map"
1519 "include/experimental/memory_resource"
1520 "include/experimental/numeric"
1521 "include/experimental/optional"
1522 "include/experimental/propagate_const"
1523 "include/experimental/ratio"
1524 "include/experimental/regex"
1525 "include/experimental/set"
1526 "include/experimental/simd"
1527 "include/experimental/string"
1528 "include/experimental/string_view"
1529 "include/experimental/system_error"
1530 "include/experimental/tuple"
1531 "include/experimental/type_traits"
1532 "include/experimental/unordered_map"
1533 "include/experimental/unordered_set"
1534 "include/experimental/utility"
1535 "include/experimental/vector"
1536 "include/ext/__hash"
1537 "include/ext/hash_map"
1538 "include/ext/hash_set"
1539 "include/filesystem"
1540 "include/float.h"
1541 "include/forward_list"
1542 "include/fstream"
1543 "include/functional"
1544 "include/future"
1545 "include/initializer_list"
1546 "include/inttypes.h"
1547 "include/iomanip"
1548 "include/ios"
1549 "include/iosfwd"
1550 "include/iostream"
1551 "include/istream"
1552 "include/iterator"
1553 "include/limits"
1554 "include/limits.h"
1555 "include/list"
1556 "include/locale"
1557 "include/locale.h"
1558 "include/map"
1559 "include/math.h"
1560 "include/memory"
1561 "include/module.modulemap"
1562 "include/mutex"
1563 "include/new"
1564 "include/numeric"
1565 "include/optional"
1566 "include/ostream"
1567 "include/queue"
1568 "include/random"
1569 "include/ratio"
1570 "include/regex"
1571 "include/scoped_allocator"
1572 "include/set"
1573 "include/setjmp.h"
1574 "include/shared_mutex"
1575 "include/span"
1576 "include/sstream"
1577 "include/stack"
1578 "include/stdbool.h"
1579 "include/stddef.h"
1580 "include/stdexcept"
1581 "include/stdint.h"
1582 "include/stdio.h"
1583 "include/stdlib.h"
1584 "include/streambuf"
1585 "include/string"
1586 "include/string.h"
1587 "include/string_view"
1588 "include/strstream"
1589 "include/support/android/locale_bionic.h"
1590 "include/support/fuchsia/xlocale.h"
1591 "include/support/ibm/limits.h"
1592 "include/support/ibm/locale_mgmt_aix.h"
1593 "include/support/ibm/support.h"
1594 "include/support/ibm/xlocale.h"
1595 "include/support/musl/xlocale.h"
1596 "include/support/newlib/xlocale.h"
1597 "include/support/solaris/floatingpoint.h"
1598 "include/support/solaris/wchar.h"
1599 "include/support/solaris/xlocale.h"
1600 "include/support/win32/limits_msvc_win32.h"
1601 "include/support/win32/locale_win32.h"
1602 "include/support/xlocale/__nop_locale_mgmt.h"
1603 "include/support/xlocale/__posix_l_fallback.h"
1604 "include/support/xlocale/__strtonum_fallback.h"
1605 "include/support/xlocale/xlocale.h"
1606 "include/system_error"
1607 "include/tgmath.h"
1608 "include/thread"
1609 "include/tuple"
1610 "include/type_traits"
1611 "include/typeindex"
1612 "include/typeinfo"
1613 "include/unordered_map"
1614 "include/unordered_set"
1615 "include/utility"
1616 "include/valarray"
1617 "include/variant"
1618 "include/vector"
1619 "include/version"
1620 "include/wchar.h"
1621 "include/wctype.h"
1622)
1623
14111624if(MSVC)
14121625 set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK")
14131626 if (IS_DIRECTORY ${MSVC_DIA_SDK_DIR})
......@@ -1419,6 +1632,8 @@ endif()
14191632set(ZIG_LIB_DIR "lib/zig")
14201633set(C_HEADERS_DEST "${ZIG_LIB_DIR}/include")
14211634set(LIBC_FILES_DEST "${ZIG_LIB_DIR}/libc")
1635set(LIBUNWIND_FILES_DEST "${ZIG_LIB_DIR}/libunwind")
1636set(LIBCXX_FILES_DEST "${ZIG_LIB_DIR}/libcxx")
14221637set(ZIG_STD_DEST "${ZIG_LIB_DIR}/std")
14231638set(CONFIGURE_OUT_FILE "${CMAKE_BINARY_DIR}/config.h")
14241639configure_file (
......@@ -1527,6 +1742,15 @@ foreach(file ${ZIG_LIBC_FILES})
15271742 install(FILES "${CMAKE_SOURCE_DIR}/libc/${file}" DESTINATION "${file_dir}")
15281743endforeach()
15291744
1745foreach(file ${ZIG_LIBUNWIND_FILES})
1746 get_filename_component(file_dir "${LIBUNWIND_FILES_DEST}/${file}" DIRECTORY)
1747 install(FILES "${CMAKE_SOURCE_DIR}/libunwind/${file}" DESTINATION "${file_dir}")
1748endforeach()
1749
1750foreach(file ${ZIG_LIBCXX_FILES})
1751 get_filename_component(file_dir "${LIBCXX_FILES_DEST}/${file}" DIRECTORY)
1752 install(FILES "${CMAKE_SOURCE_DIR}/libcxx/${file}" DESTINATION "${file_dir}")
1753endforeach()
15301754
15311755install(FILES "${CMAKE_SOURCE_DIR}/src-self-hosted/arg.zig" DESTINATION "${ZIG_STD_DEST}/special/fmt/")
15321756install(FILES "${CMAKE_SOURCE_DIR}/src-self-hosted/main.zig" DESTINATION "${ZIG_STD_DEST}/special/fmt/")
src/codegen.cpp+35-20
......@@ -8275,7 +8275,8 @@ static Error get_tmp_filename(CodeGen *g, Buf *out, Buf *suffix) {
82758275 return ErrorNone;
82768276}
82778277
8278static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {
8278// returns true if it was a cache miss
8279static bool gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {
82798280 Error err;
82808281
82818282 Buf *artifact_dir;
......@@ -8346,8 +8347,8 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {
83468347 }
83478348 exit(1);
83488349 }
8349 if (buf_len(&digest) == 0) {
8350 // cache miss
8350 bool is_cache_miss = (buf_len(&digest) == 0);
8351 if (is_cache_miss) {
83518352 // we can't know the digest until we do the C compiler invocation, so we
83528353 // need a tmp filename.
83538354 Buf *out_obj_path = buf_alloc();
......@@ -8428,10 +8429,12 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {
84288429 }
84298430 break;
84308431 case BuildModeFastRelease:
8432 args.append("-DNDEBUG");
84318433 args.append("-O2");
84328434 args.append("-fno-stack-protector");
84338435 break;
84348436 case BuildModeSmallRelease:
8437 args.append("-DNDEBUG");
84358438 args.append("-Os");
84368439 args.append("-fno-stack-protector");
84378440 break;
......@@ -8504,13 +8507,17 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {
85048507
85058508 g->link_objects.append(o_final_path);
85068509 g->caches_to_release.append(cache_hash);
8510
8511 return is_cache_miss;
85078512}
85088513
8509static void gen_c_objects(CodeGen *g) {
8514// returns true if we had any cache misses
8515static bool gen_c_objects(CodeGen *g) {
85108516 Error err;
8517 bool any_cache_misses = false;
85118518
85128519 if (g->c_source_files.length == 0)
8513 return;
8520 return any_cache_misses;
85148521
85158522 Buf *self_exe_path = buf_alloc();
85168523 if ((err = os_self_exe_path(self_exe_path))) {
......@@ -8522,8 +8529,10 @@ static void gen_c_objects(CodeGen *g) {
85228529
85238530 for (size_t c_file_i = 0; c_file_i < g->c_source_files.length; c_file_i += 1) {
85248531 CFile *c_file = g->c_source_files.at(c_file_i);
8525 gen_c_object(g, self_exe_path, c_file);
8532 bool is_cache_miss = gen_c_object(g, self_exe_path, c_file);
8533 any_cache_misses = any_cache_misses || is_cache_miss;
85268534 }
8535 return any_cache_misses;
85278536}
85288537
85298538void codegen_add_object(CodeGen *g, Buf *object_path) {
......@@ -9020,7 +9029,8 @@ static void add_cache_pkg(CodeGen *g, CacheHash *ch, ZigPackage *pkg) {
90209029}
90219030
90229031// Called before init()
9023static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
9032// is_cache_hit takes into account gen_c_objects
9033static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest, bool *c_objects_generated) {
90249034 Error err;
90259035
90269036 Buf *compiler_id;
......@@ -9081,7 +9091,7 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
90819091 }
90829092 cache_buf(ch, g->dynamic_linker_path);
90839093
9084 gen_c_objects(g);
9094 *c_objects_generated = gen_c_objects(g);
90859095
90869096 buf_resize(digest, 0);
90879097 if ((err = cache_hit(ch, digest)))
......@@ -9188,11 +9198,12 @@ void codegen_build_and_link(CodeGen *g) {
91889198
91899199 Buf *artifact_dir = buf_alloc();
91909200 Buf digest = BUF_INIT;
9201 bool any_c_objects_generated;
91919202 if (g->enable_cache) {
91929203 Buf *manifest_dir = buf_alloc();
91939204 os_path_join(g->cache_dir, buf_create_from_str("build"), manifest_dir);
91949205
9195 if ((err = check_cache(g, manifest_dir, &digest))) {
9206 if ((err = check_cache(g, manifest_dir, &digest, &any_c_objects_generated))) {
91969207 if (err == ErrorCacheUnavailable) {
91979208 // message already printed
91989209 } else {
......@@ -9204,24 +9215,28 @@ void codegen_build_and_link(CodeGen *g) {
92049215 os_path_join(g->cache_dir, buf_create_from_str("artifact"), artifact_dir);
92059216 } else {
92069217 // There is a call to this in check_cache
9207 gen_c_objects(g);
9218 any_c_objects_generated = gen_c_objects(g);
92089219 }
92099220
9210 if (g->enable_cache && buf_len(&digest) != 0) {
9221 if (g->enable_cache && buf_len(&digest) != 0 && !any_c_objects_generated) {
92119222 os_path_join(artifact_dir, &digest, &g->artifact_dir);
92129223 resolve_out_paths(g);
92139224 } else {
9214 init(g);
9225 if (need_llvm_module(g)) {
9226 init(g);
92159227
9216 codegen_add_time_event(g, "Semantic Analysis");
9228 codegen_add_time_event(g, "Semantic Analysis");
92179229
9218 gen_global_asm(g);
9219 gen_root_source(g);
9230 gen_global_asm(g);
9231 gen_root_source(g);
92209232
9233 }
92219234 if (g->enable_cache) {
9222 if ((err = cache_final(&g->cache_hash, &digest))) {
9223 fprintf(stderr, "Unable to finalize cache hash: %s\n", err_str(err));
9224 exit(1);
9235 if (buf_len(&digest) == 0) {
9236 if ((err = cache_final(&g->cache_hash, &digest))) {
9237 fprintf(stderr, "Unable to finalize cache hash: %s\n", err_str(err));
9238 exit(1);
9239 }
92259240 }
92269241 os_path_join(artifact_dir, &digest, &g->artifact_dir);
92279242 } else {
......@@ -9233,9 +9248,9 @@ void codegen_build_and_link(CodeGen *g) {
92339248 }
92349249 resolve_out_paths(g);
92359250
9236 codegen_add_time_event(g, "Code Generation");
9237
92389251 if (need_llvm_module(g)) {
9252 codegen_add_time_event(g, "Code Generation");
9253
92399254 do_code_gen(g);
92409255 codegen_add_time_event(g, "LLVM Emit Output");
92419256 zig_llvm_emit_output(g);
src/compiler.cpp+31-13
......@@ -10,6 +10,7 @@ static Buf saved_lib_dir = BUF_INIT;
1010static Buf saved_special_dir = BUF_INIT;
1111static Buf saved_std_dir = BUF_INIT;
1212static Buf saved_dynamic_linker_path = BUF_INIT;
13static bool searched_for_dyn_linker = false;
1314
1415Buf *get_stage1_cache_path(void) {
1516 if (saved_stage1_path.list.length != 0) {
......@@ -24,6 +25,35 @@ Buf *get_stage1_cache_path(void) {
2425 return &saved_stage1_path;
2526}
2627
28static void detect_dynamic_linker(Buf *lib_path) {
29#if defined(ZIG_OS_LINUX) && defined(ZIG_ARCH_X86_64)
30 if (buf_ends_with_str(lib_path, "ld-linux-x86-64.so.2")) {
31 buf_init_from_buf(&saved_dynamic_linker_path, lib_path);
32 } else if (buf_ends_with_str(lib_path, "ld-musl-x86-64.so.1")) {
33 buf_init_from_buf(&saved_dynamic_linker_path, lib_path);
34 }
35#endif
36}
37
38Buf *get_self_dynamic_linker_path(void) {
39 for (;;) {
40 if (saved_dynamic_linker_path.list.length != 0) {
41 return &saved_dynamic_linker_path;
42 }
43 if (searched_for_dyn_linker)
44 return nullptr;
45 ZigList<Buf *> lib_paths = {};
46 Error err;
47 if ((err = os_self_exe_shared_libs(lib_paths)))
48 return nullptr;
49 for (size_t i = 0; i < lib_paths.length; i += 1) {
50 Buf *lib_path = lib_paths.at(i);
51 detect_dynamic_linker(lib_path);
52 }
53 searched_for_dyn_linker = true;
54 }
55}
56
2757Error get_compiler_id(Buf **result) {
2858 if (saved_compiler_id.list.length != 0) {
2959 *result = &saved_compiler_id;
......@@ -57,15 +87,9 @@ Error get_compiler_id(Buf **result) {
5787 return err;
5888 for (size_t i = 0; i < lib_paths.length; i += 1) {
5989 Buf *lib_path = lib_paths.at(i);
90 detect_dynamic_linker(lib_path);
6091 if ((err = cache_add_file(ch, lib_path)))
6192 return err;
62#if defined(ZIG_OS_LINUX) && defined(ZIG_ARCH_X86_64)
63 if (buf_ends_with_str(lib_path, "ld-linux-x86-64.so.2")) {
64 buf_init_from_buf(&saved_dynamic_linker_path, lib_path);
65 } else if (buf_ends_with_str(lib_path, "ld-musl-x86-64.so.1")) {
66 buf_init_from_buf(&saved_dynamic_linker_path, lib_path);
67 }
68#endif
6993 }
7094 if ((err = cache_final(ch, &saved_compiler_id)))
7195 return err;
......@@ -76,12 +100,6 @@ Error get_compiler_id(Buf **result) {
76100 return ErrorNone;
77101}
78102
79Buf *get_self_dynamic_linker_path(void) {
80 Buf *dontcare;
81 (void)get_compiler_id(&dontcare); // for the side-effects of caching the dynamic linker path
82 return (saved_dynamic_linker_path.list.length == 0) ? nullptr : &saved_dynamic_linker_path;
83}
84
85103static bool test_zig_install_prefix(Buf *test_path, Buf *out_zig_lib_dir) {
86104 Buf lib_buf = BUF_INIT;
87105 buf_init_from_str(&lib_buf, "lib");
src/link.cpp+84-4
......@@ -62,14 +62,22 @@ static const char *build_libc_object(CodeGen *parent_gen, const char *name, CFil
6262 return buf_ptr(&child_gen->output_file_path);
6363}
6464
65static const char *path_from_libc(CodeGen *g, const char *subpath) {
66 Buf *libc_dir = buf_alloc();
67 os_path_join(g->zig_lib_dir, buf_create_from_str("libc"), libc_dir);
65static const char *path_from_zig_lib(CodeGen *g, const char *dir, const char *subpath) {
66 Buf *dir1 = buf_alloc();
67 os_path_join(g->zig_lib_dir, buf_create_from_str(dir), dir1);
6868 Buf *result = buf_alloc();
69 os_path_join(libc_dir, buf_create_from_str(subpath), result);
69 os_path_join(dir1, buf_create_from_str(subpath), result);
7070 return buf_ptr(result);
7171}
7272
73static const char *path_from_libc(CodeGen *g, const char *subpath) {
74 return path_from_zig_lib(g, "libc", subpath);
75}
76
77static const char *path_from_libunwind(CodeGen *g, const char *subpath) {
78 return path_from_zig_lib(g, "libunwind", subpath);
79}
80
7381static const char *build_dummy_so(CodeGen *parent, const char *name, size_t major_version) {
7482 Buf *glibc_dummy_root_src = buf_sprintf("%s" OS_SEP "libc" OS_SEP "dummy" OS_SEP "%s.zig",
7583 buf_ptr(parent->zig_lib_dir), name);
......@@ -81,6 +89,70 @@ static const char *build_dummy_so(CodeGen *parent, const char *name, size_t majo
8189 return buf_ptr(&child_gen->output_file_path);
8290}
8391
92static const char *build_libunwind(CodeGen *parent) {
93 CodeGen *child_gen = create_child_codegen(parent, nullptr, OutTypeLib, nullptr);
94 codegen_set_out_name(child_gen, buf_create_from_str("unwind"));
95 child_gen->is_static = true;
96 LinkLib *new_link_lib = codegen_add_link_lib(child_gen, buf_create_from_str("c"));
97 new_link_lib->provided_explicitly = false;
98 enum SrcKind {
99 SrcCpp,
100 SrcC,
101 SrcAsm,
102 };
103 static const struct {
104 const char *path;
105 SrcKind kind;
106 } unwind_src[] = {
107 {"src" OS_SEP "libunwind.cpp", SrcCpp},
108 {"src" OS_SEP "Unwind-EHABI.cpp", SrcCpp},
109 {"src" OS_SEP "Unwind-seh.cpp", SrcCpp},
110
111 {"src" OS_SEP "UnwindLevel1.c", SrcC},
112 {"src" OS_SEP "UnwindLevel1-gcc-ext.c", SrcC},
113 {"src" OS_SEP "Unwind-sjlj.c", SrcC},
114
115 {"src" OS_SEP "UnwindRegistersRestore.S", SrcAsm},
116 {"src" OS_SEP "UnwindRegistersSave.S", SrcAsm},
117 };
118 ZigList<CFile *> c_source_files = {0};
119 for (size_t i = 0; i < array_length(unwind_src); i += 1) {
120 CFile *c_file = allocate<CFile>(1);
121 c_file->source_path = path_from_libunwind(parent, unwind_src[i].path);
122 switch (unwind_src[i].kind) {
123 case SrcC:
124 c_file->args.append("-std=c99");
125 break;
126 case SrcCpp:
127 c_file->args.append("-fno-rtti");
128 c_file->args.append("-I");
129 c_file->args.append(path_from_zig_lib(parent, "libcxx", "include"));
130 break;
131 case SrcAsm:
132 break;
133 }
134 c_file->args.append("-I");
135 c_file->args.append(path_from_libunwind(parent, "include"));
136 c_file->args.append("-fPIC");
137 c_file->args.append("-D_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS");
138 if (parent->zig_target->is_native) {
139 c_file->args.append("-D_LIBUNWIND_IS_NATIVE_ONLY");
140 }
141 if (parent->build_mode == BuildModeDebug) {
142 c_file->args.append("-D_DEBUG");
143 } else {
144 c_file->args.append("-NDEBUG");
145 }
146 if (parent->is_single_threaded) {
147 c_file->args.append("-D_LIBUNWIND_HAS_NO_THREADS");
148 }
149 c_source_files.append(c_file);
150 }
151 child_gen->c_source_files = c_source_files;
152 codegen_build_and_link(child_gen);
153 return buf_ptr(&child_gen->output_file_path);
154}
155
84156static const char *get_libc_crt_file(CodeGen *parent, const char *file) {
85157 if (parent->libc == nullptr && target_is_glibc(parent)) {
86158 if (strcmp(file, "crti.o") == 0) {
......@@ -611,6 +683,7 @@ static void construct_linker_job_elf(LinkJob *lj) {
611683 lj->args.append("-lgcc_s");
612684 lj->args.append("--no-as-needed");
613685 } else if (target_is_glibc(g)) {
686 lj->args.append(build_libunwind(g));
614687 lj->args.append(get_libc_crt_file(g, "libc.so.6")); // this is our dummy so file
615688 lj->args.append(get_libc_crt_file(g, "libc_nonshared.a"));
616689 } else {
......@@ -1192,6 +1265,13 @@ void codegen_link(CodeGen *g) {
11921265 }
11931266 ZigLLVM_OSType os_type = get_llvm_os_type(g->zig_target->os);
11941267 codegen_add_time_event(g, "LLVM Link");
1268 if (g->verbose_link) {
1269 fprintf(stderr, "ar rcs %s", buf_ptr(&g->output_file_path));
1270 for (size_t i = 0; i < g->link_objects.length; i += 1) {
1271 fprintf(stderr, " %s", (const char *)buf_ptr(g->link_objects.at(i)));
1272 }
1273 fprintf(stderr, "\n");
1274 }
11951275 if (ZigLLVMWriteArchive(buf_ptr(&g->output_file_path), file_names.items, file_names.length, os_type)) {
11961276 fprintf(stderr, "Unable to write archive '%s'\n", buf_ptr(&g->output_file_path));
11971277 exit(1);