authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-13 19:33:19-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-13 19:50:41-04:00
log5d2edac12dc9eec626977a5bf9b0630504b28c15
tree07df535ed5e89f616d064ca0facf8941d59681b7
parent85d0f0d45bf1529db8965b8176f8021d1ca27534
signaturelock-open Commit is signed but in an unrecognized format.

breaking: remove --static; add -dynamic

`--static` is no longer an option. Instead, Zig makes things as static as possible by default. `-dynamic` can be used to choose a dynamic library rather than a static one. `--enable-pic` is a new option. Usually it will be enabled automatically, but in the case of build-exe with no dynamic libraries on Linux or freestanding, Zig chooses off by default. closes #1703 closes #1828

9 files changed, 212 insertions(+), 137 deletions(-)

src/all_types.hpp+10-2
......@@ -1616,6 +1616,12 @@ enum ValgrindSupport {
16161616 ValgrindSupportEnabled,
16171617};
16181618
1619enum WantPIC {
1620 WantPICAuto,
1621 WantPICDisabled,
1622 WantPICEnabled,
1623};
1624
16191625struct CFile {
16201626 ZigList<const char *> args;
16211627 const char *source_path;
......@@ -1791,6 +1797,8 @@ struct CodeGen {
17911797 bool have_dllmain_crt_startup;
17921798 bool have_pub_panic;
17931799 bool have_err_ret_tracing;
1800 bool have_pic;
1801 bool have_dynamic_link; // this is whether the final thing will be dynamically linked. see also is_dynamic
17941802 bool c_want_stdint;
17951803 bool c_want_stdbool;
17961804 bool verbose_tokenize;
......@@ -1834,13 +1842,13 @@ struct CodeGen {
18341842 const ZigTarget *zig_target;
18351843 TargetSubsystem subsystem;
18361844 ValgrindSupport valgrind_support;
1837 bool is_static;
1845 WantPIC want_pic;
1846 bool is_dynamic; // shared library rather than static library. dynamic musl rather than static musl.
18381847 bool strip_debug_symbols;
18391848 bool is_test_build;
18401849 bool is_single_threaded;
18411850 bool linker_rdynamic;
18421851 bool each_lib_rpath;
1843 bool disable_pic;
18441852 bool is_dummy_so;
18451853 bool disable_gen_h;
18461854
src/codegen.cpp+67-29
......@@ -182,13 +182,13 @@ CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget
182182 } else {
183183 g->each_lib_rpath = true;
184184
185 if (target_is_darwin(g->zig_target)) {
185 if (target_os_is_darwin(g->zig_target->os)) {
186186 init_darwin_native(g);
187187 }
188188
189189 }
190190
191 if (target_requires_libc(g->zig_target)) {
191 if (target_os_requires_libc(g->zig_target->os)) {
192192 g->libc_link_lib = create_link_lib(buf_create_from_str("c"));
193193 g->link_libs_list.append(g->libc_link_lib);
194194 }
......@@ -3370,7 +3370,7 @@ static LLVMValueRef gen_valgrind_client_request(CodeGen *g, LLVMValueRef default
33703370 bool asm_has_side_effects = true;
33713371 bool asm_is_alignstack = false;
33723372 if (g->zig_target->arch == ZigLLVM_x86_64) {
3373 if (g->zig_target->os == OsLinux || target_is_darwin(g->zig_target) || g->zig_target->os == OsSolaris ||
3373 if (g->zig_target->os == OsLinux || target_os_is_darwin(g->zig_target->os) || g->zig_target->os == OsSolaris ||
33743374 (g->zig_target->os == OsWindows && g->zig_target->abi != ZigLLVM_MSVC))
33753375 {
33763376 if (g->cur_fn->valgrind_client_request_array == nullptr) {
......@@ -7283,7 +7283,44 @@ static const char *build_mode_to_str(BuildMode build_mode) {
72837283 zig_unreachable();
72847284}
72857285
7286static bool detect_dynamic_link(CodeGen *g) {
7287 if (g->is_dynamic)
7288 return true;
7289 if (g->zig_target->os == OsFreestanding)
7290 return false;
7291 if (target_requires_pic(g->zig_target))
7292 return true;
7293 if (g->out_type == OutTypeExe) {
7294 // If there are no dynamic libraries then we can disable PIC
7295 for (size_t i = 0; i < g->link_libs_list.length; i += 1) {
7296 LinkLib *link_lib = g->link_libs_list.at(i);
7297 if (target_is_libc_lib_name(g->zig_target, buf_ptr(link_lib->name)))
7298 continue;
7299 return true;
7300 }
7301 return false;
7302 }
7303 return true;
7304}
7305
7306static bool detect_pic(CodeGen *g) {
7307 if (target_requires_pic(g->zig_target))
7308 return true;
7309 switch (g->want_pic) {
7310 case WantPICDisabled:
7311 return false;
7312 case WantPICEnabled:
7313 return true;
7314 case WantPICAuto:
7315 return g->have_dynamic_link;
7316 }
7317 zig_unreachable();
7318}
7319
72867320Buf *codegen_generate_builtin_source(CodeGen *g) {
7321 g->have_dynamic_link = detect_dynamic_link(g);
7322 g->have_pic = detect_pic(g);
7323
72877324 Buf *contents = buf_alloc();
72887325
72897326 // NOTE: when editing this file, you may need to make modifications to the
......@@ -7683,6 +7720,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
76837720 buf_appendf(contents, "pub const link_libc = %s;\n", bool_to_str(g->libc_link_lib != nullptr));
76847721 buf_appendf(contents, "pub const have_error_return_tracing = %s;\n", bool_to_str(g->have_err_ret_tracing));
76857722 buf_appendf(contents, "pub const valgrind_support = %s;\n", bool_to_str(want_valgrind_support(g)));
7723 buf_appendf(contents, "pub const position_independent_code = %s;\n", bool_to_str(g->have_pic));
76867724
76877725 buf_appendf(contents, "pub const __zig_test_fn_slice = {}; // overwritten later\n");
76887726
......@@ -7777,6 +7815,9 @@ static void init(CodeGen *g) {
77777815 if (g->module)
77787816 return;
77797817
7818 g->have_dynamic_link = detect_dynamic_link(g);
7819 g->have_pic = detect_pic(g);
7820
77807821 if (g->is_test_build) {
77817822 g->subsystem = TargetSubsystemConsole;
77827823 }
......@@ -7807,10 +7848,7 @@ static void init(CodeGen *g) {
78077848 bool is_optimized = g->build_mode != BuildModeDebug;
78087849 LLVMCodeGenOptLevel opt_level = is_optimized ? LLVMCodeGenLevelAggressive : LLVMCodeGenLevelNone;
78097850
7810 if (g->out_type == OutTypeExe && g->is_static) {
7811 g->disable_pic = true;
7812 }
7813 LLVMRelocMode reloc_mode = g->disable_pic ? LLVMRelocStatic : LLVMRelocPIC;
7851 LLVMRelocMode reloc_mode = g->have_pic ? LLVMRelocPIC: LLVMRelocStatic;
78147852
78157853 const char *target_specific_cpu_args;
78167854 const char *target_specific_features;
......@@ -7892,8 +7930,13 @@ static void init(CodeGen *g) {
78927930}
78937931
78947932static void detect_dynamic_linker(CodeGen *g) {
7895 if (g->dynamic_linker_path != nullptr || g->is_static)
7933 if (g->dynamic_linker_path != nullptr)
78967934 return;
7935 if (!g->have_dynamic_link)
7936 return;
7937 if (g->out_type == OutTypeObj || (g->out_type == OutTypeLib && !g->is_dynamic))
7938 return;
7939
78977940 const char *standard_ld_path = target_dynamic_linker(g->zig_target);
78987941 if (standard_ld_path == nullptr)
78997942 return;
......@@ -7944,13 +7987,6 @@ static void detect_libc(CodeGen *g) {
79447987 if (g->libc != nullptr || g->libc_link_lib == nullptr)
79457988 return;
79467989
7947 if (g->zig_target->os == OsLinux && target_abi_is_gnu(g->zig_target->abi) &&
7948 g->is_static && g->out_type == OutTypeExe)
7949 {
7950 fprintf(stderr, "glibc does not support static linking\n");
7951 exit(1);
7952 }
7953
79547990 if (target_can_build_libc(g->zig_target)) {
79557991 const char *generic_name = target_libc_generic_name(g->zig_target);
79567992
......@@ -8010,17 +8046,16 @@ static void detect_libc(CodeGen *g) {
80108046 if (want_sys_dir) {
80118047 g->libc_include_dir_list[1] = &g->libc->sys_include_dir;
80128048 }
8013 } else if ((g->out_type == OutTypeExe || (g->out_type == OutTypeLib && !g->is_static)) &&
8014 !target_is_darwin(g->zig_target))
8049 } else if ((g->out_type == OutTypeExe || (g->out_type == OutTypeLib && g->is_dynamic)) &&
8050 !target_os_is_darwin(g->zig_target->os))
80158051 {
8052 Buf triple_buf = BUF_INIT;
8053 get_target_triple(&triple_buf, g->zig_target);
80168054 fprintf(stderr,
8017 "Zig is unable to provide a libc for the chosen target '%s-%s-%s'.\n"
8055 "Zig is unable to provide a libc for the chosen target '%s'.\n"
80188056 "The target is non-native, so Zig also cannot use the native libc installation.\n"
80198057 "Choose a target which has a libc available, or provide a libc installation text file.\n"
8020 "See `zig libc --help` for more details.\n",
8021 target_arch_name(g->zig_target->arch),
8022 target_os_name(g->zig_target->os),
8023 target_abi_name(g->zig_target->abi));
8058 "See `zig libc --help` for more details.\n", buf_ptr(&triple_buf));
80248059 exit(1);
80258060 }
80268061}
......@@ -8203,7 +8238,7 @@ static void gen_root_source(CodeGen *g) {
82038238 g->bootstrap_import = add_special_code(g, create_bootstrap_pkg(g, g->root_package), "bootstrap.zig");
82048239 }
82058240 if (g->zig_target->os == OsWindows && !g->have_dllmain_crt_startup &&
8206 g->out_type == OutTypeLib && !g->is_static)
8241 g->out_type == OutTypeLib && g->is_dynamic)
82078242 {
82088243 g->bootstrap_import = add_special_code(g, create_bootstrap_pkg(g, g->root_package), "bootstrap_lib.zig");
82098244 }
......@@ -8297,7 +8332,8 @@ Error create_c_object_cache(CodeGen *g, CacheHash **out_cache_hash, bool verbose
82978332 cache_int(cache_hash, g->zig_target->abi);
82988333 cache_bool(cache_hash, g->strip_debug_symbols);
82998334 cache_int(cache_hash, g->build_mode);
8300 cache_bool(cache_hash, g->disable_pic);
8335 cache_bool(cache_hash, g->have_pic);
8336 cache_bool(cache_hash, want_valgrind_support(g));
83018337 for (size_t arg_i = 0; arg_i < g->clang_argv_len; arg_i += 1) {
83028338 cache_str(cache_hash, g->clang_argv[arg_i]);
83038339 }
......@@ -8451,7 +8487,7 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {
84518487 args.append("-c");
84528488 args.append(buf_ptr(c_source_file));
84538489
8454 if (target_supports_fpic(g->zig_target) && !g->disable_pic) {
8490 if (target_supports_fpic(g->zig_target) && g->have_pic) {
84558491 args.append("-fPIC");
84568492 }
84578493
......@@ -9064,7 +9100,6 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
90649100 cache_int(ch, g->zig_target->os);
90659101 cache_int(ch, g->zig_target->abi);
90669102 cache_int(ch, g->subsystem);
9067 cache_bool(ch, g->is_static);
90689103 cache_bool(ch, g->strip_debug_symbols);
90699104 cache_bool(ch, g->is_test_build);
90709105 if (g->is_test_build) {
......@@ -9074,9 +9109,10 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
90749109 cache_bool(ch, g->is_single_threaded);
90759110 cache_bool(ch, g->linker_rdynamic);
90769111 cache_bool(ch, g->each_lib_rpath);
9077 cache_bool(ch, g->disable_pic);
90789112 cache_bool(ch, g->disable_gen_h);
9079 cache_bool(ch, g->valgrind_support);
9113 cache_bool(ch, want_valgrind_support(g));
9114 cache_bool(ch, g->have_pic);
9115 cache_bool(ch, g->have_dynamic_link);
90809116 cache_bool(ch, g->is_dummy_so);
90819117 cache_buf_opt(ch, g->mmacosx_version_min);
90829118 cache_buf_opt(ch, g->mios_version_min);
......@@ -9150,7 +9186,7 @@ static void resolve_out_paths(CodeGen *g) {
91509186 buf_resize(out_basename, 0);
91519187 buf_append_str(out_basename, target_lib_file_prefix(g->zig_target));
91529188 buf_append_buf(out_basename, g->root_out_name);
9153 buf_append_str(out_basename, target_lib_file_ext(g->zig_target, g->is_static,
9189 buf_append_str(out_basename, target_lib_file_ext(g->zig_target, !g->is_dynamic,
91549190 g->version_major, g->version_minor, g->version_patch));
91559191 break;
91569192 }
......@@ -9182,6 +9218,8 @@ void codegen_build_and_link(CodeGen *g) {
91829218 g->output_dir = buf_create_from_str(".");
91839219 }
91849220
9221 g->have_dynamic_link = detect_dynamic_link(g);
9222 g->have_pic = detect_pic(g);
91859223 detect_libc(g);
91869224 detect_dynamic_linker(g);
91879225
src/ir.cpp+12-3
......@@ -15543,9 +15543,8 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1554315543}
1554415544
1554515545static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name, AstNode *source_node) {
15546 if (buf_eql_str(lib_name, "c") && ira->codegen->libc_link_lib == nullptr &&
15547 !ira->codegen->reported_bad_link_libc_error)
15548 {
15546 bool is_libc = target_is_libc_lib_name(ira->codegen->zig_target, buf_ptr(lib_name));
15547 if (is_libc && ira->codegen->libc_link_lib == nullptr && !ira->codegen->reported_bad_link_libc_error) {
1554915548 ir_add_error_node(ira, source_node,
1555015549 buf_sprintf("dependency on library c must be explicitly specified in the build command"));
1555115550 ira->codegen->reported_bad_link_libc_error = true;
......@@ -15558,6 +15557,16 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name,
1555815557 return;
1555915558 }
1556015559 }
15560
15561 if (!is_libc && !ira->codegen->have_pic && !ira->codegen->reported_bad_link_libc_error) {
15562 ErrorMsg *msg = ir_add_error_node(ira, source_node,
15563 buf_sprintf("dependency on dynamic library '%s' requires enabling Position Independent Code",
15564 buf_ptr(lib_name)));
15565 add_error_note(ira->codegen, msg, source_node,
15566 buf_sprintf("fixed by `--library %s` or `--enable-pic`", buf_ptr(lib_name)));
15567 ira->codegen->reported_bad_link_libc_error = true;
15568 }
15569
1556115570 for (size_t i = 0; i < ira->codegen->forbidden_libs.length; i += 1) {
1556215571 Buf *forbidden_lib_name = ira->codegen->forbidden_libs.at(i);
1556315572 if (buf_eql_buf(lib_name, forbidden_lib_name)) {
src/libc_installation.cpp+1-1
......@@ -102,7 +102,7 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget
102102 }
103103
104104 if (buf_len(&libc->crt_dir) == 0) {
105 if (!target_is_darwin(target)) {
105 if (!target_os_is_darwin(target->os)) {
106106 if (verbose) {
107107 fprintf(stderr, "crt_dir may not be empty for %s\n", target_os_name(target->os));
108108 }
src/link.cpp+25-53
......@@ -35,7 +35,7 @@ static CodeGen *create_child_codegen(CodeGen *parent_gen, Buf *root_src_path, Ou
3535 child_gen->llvm_argv = parent_gen->llvm_argv;
3636
3737 codegen_set_strip(child_gen, parent_gen->strip_debug_symbols);
38 child_gen->disable_pic = parent_gen->disable_pic;
38 child_gen->want_pic = parent_gen->have_pic ? WantPICEnabled : WantPICDisabled;
3939 child_gen->valgrind_support = ValgrindSupportDisabled;
4040
4141 codegen_set_errmsg_color(child_gen, parent_gen->err_color);
......@@ -48,15 +48,6 @@ static CodeGen *create_child_codegen(CodeGen *parent_gen, Buf *root_src_path, Ou
4848 return child_gen;
4949}
5050
51
52static bool target_is_glibc(CodeGen *g) {
53 return g->zig_target->os == OsLinux && target_abi_is_gnu(g->zig_target->abi);
54}
55
56static bool target_is_musl(CodeGen *g) {
57 return g->zig_target->os == OsLinux && target_abi_is_musl(g->zig_target->abi);
58}
59
6051static const char *build_libc_object(CodeGen *parent_gen, const char *name, CFile *c_file) {
6152 CodeGen *child_gen = create_child_codegen(parent_gen, nullptr, OutTypeObj, nullptr);
6253 codegen_set_out_name(child_gen, buf_create_from_str(name));
......@@ -97,7 +88,7 @@ static const char *build_dummy_so(CodeGen *parent, const char *name, size_t majo
9788 CodeGen *child_gen = create_child_codegen(parent, glibc_dummy_root_src, OutTypeLib, nullptr);
9889 codegen_set_out_name(child_gen, buf_create_from_str(name));
9990 codegen_set_lib_version(child_gen, major_version, 0, 0);
100 child_gen->is_static = false;
91 child_gen->is_dynamic = true;
10192 child_gen->is_dummy_so = true;
10293 codegen_build_and_link(child_gen);
10394 return buf_ptr(&child_gen->output_file_path);
......@@ -106,7 +97,6 @@ static const char *build_dummy_so(CodeGen *parent, const char *name, size_t majo
10697static const char *build_libunwind(CodeGen *parent) {
10798 CodeGen *child_gen = create_child_codegen(parent, nullptr, OutTypeLib, nullptr);
10899 codegen_set_out_name(child_gen, buf_create_from_str("unwind"));
109 child_gen->is_static = true;
110100 LinkLib *new_link_lib = codegen_add_link_lib(child_gen, buf_create_from_str("c"));
111101 new_link_lib->provided_explicitly = false;
112102 enum SrcKind {
......@@ -490,7 +480,6 @@ static bool is_musl_arch_name(const char *name) {
490480static const char *build_musl(CodeGen *parent) {
491481 CodeGen *child_gen = create_child_codegen(parent, nullptr, OutTypeLib, nullptr);
492482 codegen_set_out_name(child_gen, buf_create_from_str("c"));
493 child_gen->is_static = true;
494483
495484 // When there is a src/<arch>/foo.* then it should substitute for src/foo.*
496485 // Even a .s file can substitute for a .c file.
......@@ -608,7 +597,7 @@ static const char *build_musl(CodeGen *parent) {
608597
609598
610599static const char *get_libc_crt_file(CodeGen *parent, const char *file) {
611 if (parent->libc == nullptr && target_is_glibc(parent)) {
600 if (parent->libc == nullptr && target_is_glibc(parent->zig_target)) {
612601 if (strcmp(file, "crti.o") == 0) {
613602 CFile *c_file = allocate<CFile>(1);
614603 c_file->source_path = glibc_start_asm_path(parent, "crti.S");
......@@ -677,7 +666,6 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) {
677666 } else if (strcmp(file, "libc_nonshared.a") == 0) {
678667 CodeGen *child_gen = create_child_codegen(parent, nullptr, OutTypeLib, nullptr);
679668 codegen_set_out_name(child_gen, buf_create_from_str("c_nonshared"));
680 child_gen->is_static = true;
681669 {
682670 CFile *c_file = allocate<CFile>(1);
683671 c_file->source_path = path_from_libc(parent, "glibc" OS_SEP "csu" OS_SEP "elf-init.c");
......@@ -755,7 +743,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) {
755743 } else {
756744 zig_unreachable();
757745 }
758 } else if (parent->libc == nullptr && target_is_musl(parent)) {
746 } else if (parent->libc == nullptr && target_is_musl(parent->zig_target)) {
759747 if (strcmp(file, "crti.o") == 0) {
760748 return build_asm_object(parent, "crti", musl_start_asm_path(parent, "crti.s"));
761749 } else if (strcmp(file, "crtn.o") == 0) {
......@@ -799,7 +787,6 @@ static Buf *build_a_raw(CodeGen *parent_gen, const char *aname, Buf *full_path)
799787
800788 CodeGen *child_gen = create_child_codegen(parent_gen, full_path, child_out_type,
801789 parent_gen->libc);
802 child_gen->is_static = true;
803790 codegen_set_out_name(child_gen, buf_create_from_str(aname));
804791
805792 // This is so that compiler_rt and builtin libraries know whether they
......@@ -924,9 +911,9 @@ static void construct_linker_job_elf(LinkJob *lj) {
924911 lj->args.append(getLDMOption(g->zig_target));
925912
926913 bool is_lib = g->out_type == OutTypeLib;
927 bool is_dyn_lib = !g->is_static && is_lib;
914 bool is_dyn_lib = g->is_dynamic && is_lib;
928915 Buf *soname = nullptr;
929 if (g->is_static) {
916 if (!g->have_dynamic_link) {
930917 if (g->zig_target->arch == ZigLLVM_arm || g->zig_target->arch == ZigLLVM_armeb ||
931918 g->zig_target->arch == ZigLLVM_thumb || g->zig_target->arch == ZigLLVM_thumbeb)
932919 {
......@@ -948,7 +935,7 @@ static void construct_linker_job_elf(LinkJob *lj) {
948935 const char *crt1o;
949936 if (g->zig_target->os == OsNetBSD) {
950937 crt1o = "crt0.o";
951 } else if (g->is_static) {
938 } else if (!g->have_dynamic_link) {
952939 crt1o = "crt1.o";
953940 } else {
954941 crt1o = "Scrt1.o";
......@@ -994,12 +981,11 @@ static void construct_linker_job_elf(LinkJob *lj) {
994981 lj->args.append(buf_ptr(&g->libc->crt_dir));
995982 }
996983
997 if (!g->is_static) {
984 if (g->have_dynamic_link && (is_dyn_lib || g->out_type == OutTypeExe)) {
998985 assert(g->dynamic_linker_path != nullptr);
999986 lj->args.append("-dynamic-linker");
1000987 lj->args.append(buf_ptr(g->dynamic_linker_path));
1001988 }
1002
1003989 }
1004990
1005991 if (is_dyn_lib) {
......@@ -1012,16 +998,14 @@ static void construct_linker_job_elf(LinkJob *lj) {
1012998 lj->args.append((const char *)buf_ptr(g->link_objects.at(i)));
1013999 }
10141000
1015 if (g->out_type == OutTypeExe || (g->out_type == OutTypeLib && !g->is_static)) {
1016 if (g->libc_link_lib == nullptr && !g->is_dummy_so) {
1001 if (!g->is_dummy_so && (g->out_type == OutTypeExe || is_dyn_lib)) {
1002 if (g->libc_link_lib == nullptr) {
10171003 Buf *builtin_a_path = build_a(g, "builtin");
10181004 lj->args.append(buf_ptr(builtin_a_path));
10191005 }
10201006
1021 if (!g->is_dummy_so) {
1022 Buf *compiler_rt_o_path = build_compiler_rt(g);
1023 lj->args.append(buf_ptr(compiler_rt_o_path));
1024 }
1007 Buf *compiler_rt_o_path = build_compiler_rt(g);
1008 lj->args.append(buf_ptr(compiler_rt_o_path));
10251009 }
10261010
10271011 for (size_t i = 0; i < g->link_libs_list.length; i += 1) {
......@@ -1030,17 +1014,9 @@ static void construct_linker_job_elf(LinkJob *lj) {
10301014 // libc is linked specially
10311015 continue;
10321016 }
1033 if (g->libc == nullptr && (target_is_glibc(g) || target_is_musl(g))) {
1017 if (g->libc == nullptr && target_is_libc_lib_name(g->zig_target, buf_ptr(link_lib->name))) {
10341018 // these libraries are always linked below when targeting glibc
1035 if (buf_eql_str(link_lib->name, "m")) {
1036 continue;
1037 } else if (buf_eql_str(link_lib->name, "pthread")) {
1038 continue;
1039 } else if (buf_eql_str(link_lib->name, "dl")) {
1040 continue;
1041 } else if (buf_eql_str(link_lib->name, "rt")) {
1042 continue;
1043 }
1019 continue;
10441020 }
10451021 Buf *arg;
10461022 if (buf_starts_with_str(link_lib->name, "/") || buf_ends_with_str(link_lib->name, ".a") ||
......@@ -1057,7 +1033,7 @@ static void construct_linker_job_elf(LinkJob *lj) {
10571033 // libc dep
10581034 if (g->libc_link_lib != nullptr) {
10591035 if (g->libc != nullptr) {
1060 if (g->is_static) {
1036 if (!g->have_dynamic_link) {
10611037 lj->args.append("--start-group");
10621038 lj->args.append("-lgcc");
10631039 lj->args.append("-lgcc_eh");
......@@ -1076,7 +1052,7 @@ static void construct_linker_job_elf(LinkJob *lj) {
10761052 lj->args.append("-lgcc_s");
10771053 lj->args.append("--no-as-needed");
10781054 }
1079 } else if (target_is_glibc(g)) {
1055 } else if (target_is_glibc(g->zig_target)) {
10801056 lj->args.append(build_libunwind(g));
10811057 lj->args.append(build_dummy_so(g, "c", 6));
10821058 lj->args.append(build_dummy_so(g, "m", 6));
......@@ -1084,7 +1060,7 @@ static void construct_linker_job_elf(LinkJob *lj) {
10841060 lj->args.append(build_dummy_so(g, "dl", 2));
10851061 lj->args.append(build_dummy_so(g, "rt", 1));
10861062 lj->args.append(get_libc_crt_file(g, "libc_nonshared.a"));
1087 } else if (target_is_musl(g)) {
1063 } else if (target_is_musl(g->zig_target)) {
10881064 lj->args.append(build_libunwind(g));
10891065 lj->args.append(build_musl(g));
10901066 } else {
......@@ -1158,10 +1134,10 @@ static void add_nt_link_args(LinkJob *lj, bool is_library) {
11581134 CodeGen *g = lj->codegen;
11591135
11601136 if (lj->link_in_crt) {
1161 const char *lib_str = g->is_static ? "lib" : "";
1137 const char *lib_str = g->is_dynamic ? "" : "lib";
11621138 const char *d_str = (g->build_mode == BuildModeDebug) ? "d" : "";
11631139
1164 if (g->is_static) {
1140 if (!g->is_dynamic) {
11651141 Buf *cmt_lib_name = buf_sprintf("libcmt%s.lib", d_str);
11661142 lj->args.append(buf_ptr(cmt_lib_name));
11671143 } else {
......@@ -1265,7 +1241,7 @@ static void construct_linker_job_coff(LinkJob *lj) {
12651241 lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(&g->libc->crt_dir))));
12661242 }
12671243
1268 if (is_library && !g->is_static) {
1244 if (is_library && g->is_dynamic) {
12691245 lj->args.append("-DLL");
12701246 }
12711247
......@@ -1278,7 +1254,7 @@ static void construct_linker_job_coff(LinkJob *lj) {
12781254 lj->args.append((const char *)buf_ptr(g->link_objects.at(i)));
12791255 }
12801256
1281 if (g->out_type == OutTypeExe || (g->out_type == OutTypeLib && !g->is_static)) {
1257 if (g->out_type == OutTypeExe || (g->out_type == OutTypeLib && g->is_dynamic)) {
12821258 if (g->libc_link_lib == nullptr && !g->is_dummy_so) {
12831259 Buf *builtin_a_path = build_a(g, "builtin");
12841260 lj->args.append(buf_ptr(builtin_a_path));
......@@ -1457,8 +1433,8 @@ static void construct_linker_job_macho(LinkJob *lj) {
14571433 }
14581434
14591435 bool is_lib = g->out_type == OutTypeLib;
1460 bool is_dyn_lib = !g->is_static && is_lib;
1461 if (g->is_static) {
1436 bool is_dyn_lib = g->is_dynamic && is_lib;
1437 if (!g->is_dynamic) {
14621438 lj->args.append("-static");
14631439 } else {
14641440 lj->args.append("-dynamic");
......@@ -1509,11 +1485,7 @@ static void construct_linker_job_macho(LinkJob *lj) {
15091485
15101486
15111487 if (g->out_type == OutTypeExe) {
1512 if (g->is_static) {
1513 lj->args.append("-no_pie");
1514 } else {
1515 lj->args.append("-pie");
1516 }
1488 lj->args.append("-pie");
15171489 }
15181490
15191491 lj->args.append("-o");
......@@ -1629,7 +1601,7 @@ void codegen_link(CodeGen *g) {
16291601 lj.args.append("-r");
16301602 }
16311603
1632 if (g->out_type == OutTypeLib && g->is_static) {
1604 if (g->out_type == OutTypeLib && !g->is_dynamic) {
16331605 ZigList<const char *> file_names = {};
16341606 for (size_t i = 0; i < g->link_objects.length; i += 1) {
16351607 file_names.append((const char *)buf_ptr(g->link_objects.at(i)));
src/main.cpp+28-19
......@@ -52,7 +52,8 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {
5252 " --cache [auto|off|on] build in cache, print output path to stdout\n"
5353 " --color [auto|off|on] enable or disable colored error messages\n"
5454 " --disable-gen-h do not generate a C header file (.h)\n"
55 " --disable-pic disable Position Independent Code for libraries\n"
55 " --disable-pic disable Position Independent Code\n"
56 " --enable-pic enable Position Independent Code\n"
5657 " --disable-valgrind omit valgrind client requests in debug builds\n"
5758 " --enable-valgrind include valgrind client requests release builds\n"
5859 " --emit [asm|bin|llvm-ir] emit a specific file format as compilation output\n"
......@@ -67,7 +68,7 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {
6768 " --release-safe build with optimizations on and safety on\n"
6869 " --release-small build with size optimizations on and safety off\n"
6970 " --single-threaded source may assume it is only used single-threaded\n"
70 " --static output will be statically linked\n"
71 " -dynamic create a shared library (.so; .dll; .dylib)\n"
7172 " --strip exclude debug symbols\n"
7273 " -target [name] <arch><sub>-<os>-<abi> see the targets command\n"
7374 " --verbose-tokenize enable compiler debug output for tokenization\n"
......@@ -397,7 +398,7 @@ int main(int argc, char **argv) {
397398 const char *in_file = nullptr;
398399 Buf *output_dir = nullptr;
399400 bool strip = false;
400 bool is_static = false;
401 bool is_dynamic = false;
401402 OutType out_type = OutTypeUnknown;
402403 const char *out_name = nullptr;
403404 bool verbose_tokenize = false;
......@@ -432,7 +433,6 @@ int main(int argc, char **argv) {
432433 size_t ver_minor = 0;
433434 size_t ver_patch = 0;
434435 bool timing_info = false;
435 bool disable_pic = false;
436436 const char *cache_dir = nullptr;
437437 CliPkg *cur_pkg = allocate<CliPkg>(1);
438438 BuildMode build_mode = BuildModeDebug;
......@@ -445,6 +445,7 @@ int main(int argc, char **argv) {
445445 Buf *override_std_dir = nullptr;
446446 Buf *main_pkg_path = nullptr;
447447 ValgrindSupport valgrind_support = ValgrindSupportAuto;
448 WantPIC want_pic = WantPICAuto;
448449
449450 ZigList<const char *> llvm_argv = {0};
450451 llvm_argv.append("zig (LLVM option parsing)");
......@@ -620,8 +621,8 @@ int main(int argc, char **argv) {
620621 }
621622 } else if (strcmp(arg, "--strip") == 0) {
622623 strip = true;
623 } else if (strcmp(arg, "--static") == 0) {
624 is_static = true;
624 } else if (strcmp(arg, "-dynamic") == 0) {
625 is_dynamic = true;
625626 } else if (strcmp(arg, "--verbose-tokenize") == 0) {
626627 verbose_tokenize = true;
627628 } else if (strcmp(arg, "--verbose-ast") == 0) {
......@@ -642,12 +643,14 @@ int main(int argc, char **argv) {
642643 each_lib_rpath = true;
643644 } else if (strcmp(arg, "-ftime-report") == 0) {
644645 timing_info = true;
645 } else if (strcmp(arg, "--disable-pic") == 0) {
646 disable_pic = true;
647646 } else if (strcmp(arg, "--enable-valgrind") == 0) {
648647 valgrind_support = ValgrindSupportEnabled;
649648 } else if (strcmp(arg, "--disable-valgrind") == 0) {
650649 valgrind_support = ValgrindSupportDisabled;
650 } else if (strcmp(arg, "--enable-pic") == 0) {
651 want_pic = WantPICEnabled;
652 } else if (strcmp(arg, "--disable-pic") == 0) {
653 want_pic = WantPICDisabled;
651654 } else if (strcmp(arg, "--system-linker-hack") == 0) {
652655 system_linker_hack = true;
653656 } else if (strcmp(arg, "--single-threaded") == 0) {
......@@ -904,12 +907,24 @@ int main(int argc, char **argv) {
904907 }
905908
906909 if (output_dir != nullptr && enable_cache == CacheOptOn) {
907 fprintf(stderr, "The --output-dir argument is incompatible with --cache on.\n");
910 fprintf(stderr, "`--output-dir` is incompatible with --cache on.\n");
911 return print_error_usage(arg0);
912 }
913
914 if (target_requires_pic(&target) && want_pic == WantPICDisabled) {
915 Buf triple_buf = BUF_INIT;
916 get_target_triple(&triple_buf, &target);
917 fprintf(stderr, "`--disable-pic` is incompatible with target '%s'\n", buf_ptr(&triple_buf));
908918 return print_error_usage(arg0);
909919 }
910920
911921 if (emit_file_type != EmitFileTypeBinary && in_file == nullptr) {
912 fprintf(stderr, "A root source file is required when using --emit asm or --emit llvm-ir");
922 fprintf(stderr, "A root source file is required when using `--emit asm` or `--emit llvm-ir`\n");
923 return print_error_usage(arg0);
924 }
925
926 if (out_type != OutTypeLib && is_dynamic) {
927 fprintf(stderr, "`-dynamic` may only be specified with `build-lib`.\n");
913928 return print_error_usage(arg0);
914929 }
915930
......@@ -936,6 +951,7 @@ int main(int argc, char **argv) {
936951 CodeGen *g = codegen_create(main_pkg_path, nullptr, &target,
937952 out_type, build_mode, get_zig_lib_dir(), override_std_dir, nullptr, nullptr);
938953 g->valgrind_support = valgrind_support;
954 g->want_pic = want_pic;
939955 g->is_single_threaded = is_single_threaded;
940956 Buf *builtin_source = codegen_generate_builtin_source(g);
941957 if (fwrite(buf_ptr(builtin_source), 1, buf_len(builtin_source), stdout) != buf_len(builtin_source)) {
......@@ -1027,16 +1043,9 @@ int main(int argc, char **argv) {
10271043 get_zig_lib_dir(), override_std_dir, libc, cache_dir_buf);
10281044 if (llvm_argv.length >= 2) codegen_set_llvm_argv(g, llvm_argv.items + 1, llvm_argv.length - 2);
10291045 g->valgrind_support = valgrind_support;
1046 g->want_pic = want_pic;
10301047 g->subsystem = subsystem;
10311048
1032 if (disable_pic) {
1033 if (out_type != OutTypeLib || !is_static) {
1034 fprintf(stderr, "--disable-pic only applies to static libraries");
1035 return EXIT_FAILURE;
1036 }
1037 g->disable_pic = true;
1038 }
1039
10401049 g->enable_time_report = timing_info;
10411050 codegen_set_out_name(g, buf_out_name);
10421051 codegen_set_lib_version(g, ver_major, ver_minor, ver_patch);
......@@ -1049,7 +1058,7 @@ int main(int argc, char **argv) {
10491058 codegen_set_clang_argv(g, clang_argv.items, clang_argv.length);
10501059
10511060 codegen_set_strip(g, strip);
1052 g->is_static = is_static;
1061 g->is_dynamic = is_dynamic;
10531062 g->dynamic_linker_path = dynamic_linker;
10541063 g->verbose_tokenize = verbose_tokenize;
10551064 g->verbose_ast = verbose_ast;
src/target.cpp+46-7
......@@ -693,8 +693,8 @@ void get_target_triple(Buf *triple, const ZigTarget *target) {
693693 ZigLLVMGetEnvironmentTypeName(target->abi));
694694}
695695
696bool target_is_darwin(const ZigTarget *target) {
697 switch (target->os) {
696bool target_os_is_darwin(Os os) {
697 switch (os) {
698698 case OsMacOSX:
699699 case OsIOS:
700700 case OsWatchOS:
......@@ -708,7 +708,7 @@ bool target_is_darwin(const ZigTarget *target) {
708708ZigLLVM_ObjectFormatType target_object_format(const ZigTarget *target) {
709709 if (target->os == OsUefi || target->os == OsWindows) {
710710 return ZigLLVM_COFF;
711 } else if (target_is_darwin(target)) {
711 } else if (target_os_is_darwin(target->os)) {
712712 return ZigLLVM_MachO;
713713 }
714714 if (target->arch == ZigLLVM_wasm32 ||
......@@ -942,7 +942,7 @@ const char *target_lib_file_ext(const ZigTarget *target, bool is_static,
942942 } else {
943943 if (is_static) {
944944 return ".a";
945 } else if (target_is_darwin(target)) {
945 } else if (target_os_is_darwin(target->os)) {
946946 return buf_ptr(buf_sprintf(".%" ZIG_PRI_usize ".%" ZIG_PRI_usize ".%" ZIG_PRI_usize ".dylib",
947947 version_major, version_minor, version_patch));
948948 } else {
......@@ -1279,7 +1279,7 @@ bool target_has_valgrind_support(const ZigTarget *target) {
12791279 case ZigLLVM_UnknownArch:
12801280 zig_unreachable();
12811281 case ZigLLVM_x86_64:
1282 return (target->os == OsLinux || target_is_darwin(target) || target->os == OsSolaris ||
1282 return (target->os == OsLinux || target_os_is_darwin(target->os) || target->os == OsSolaris ||
12831283 (target->os == OsWindows && target->abi != ZigLLVM_MSVC));
12841284 default:
12851285 return false;
......@@ -1287,11 +1287,11 @@ bool target_has_valgrind_support(const ZigTarget *target) {
12871287 zig_unreachable();
12881288}
12891289
1290bool target_requires_libc(const ZigTarget *target) {
1290bool target_os_requires_libc(Os os) {
12911291 // On Darwin, we always link libSystem which contains libc.
12921292 // Similarly on FreeBSD and NetBSD we always link system libc
12931293 // since this is the stable syscall interface.
1294 return (target_is_darwin(target) || target->os == OsFreeBSD || target->os == OsNetBSD);
1294 return (target_os_is_darwin(os) || os == OsFreeBSD || os == OsNetBSD);
12951295}
12961296
12971297bool target_supports_fpic(const ZigTarget *target) {
......@@ -1300,6 +1300,19 @@ bool target_supports_fpic(const ZigTarget *target) {
13001300 return target->os != OsWindows;
13011301}
13021302
1303bool target_requires_pic(const ZigTarget *target) {
1304 // This function returns whether non-pic code is completely invalid on the given target.
1305 return target->os == OsWindows || target_os_requires_libc(target->os) || target_is_glibc(target);
1306}
1307
1308bool target_is_glibc(const ZigTarget *target) {
1309 return target->os == OsLinux && target_abi_is_gnu(target->abi);
1310}
1311
1312bool target_is_musl(const ZigTarget *target) {
1313 return target->os == OsLinux && target_abi_is_musl(target->abi);
1314}
1315
13031316ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) {
13041317 switch (os) {
13051318 case OsFreestanding:
......@@ -1458,3 +1471,29 @@ const char *target_libc_generic_name(const ZigTarget *target) {
14581471 }
14591472 zig_unreachable();
14601473}
1474
1475bool target_is_libc_lib_name(const ZigTarget *target, const char *name) {
1476 if (strcmp(name, "c") == 0)
1477 return true;
1478
1479 if (target_abi_is_gnu(target->abi) || target_abi_is_musl(target->abi)) {
1480 if (strcmp(name, "m") == 0)
1481 return true;
1482 if (strcmp(name, "rt") == 0)
1483 return true;
1484 if (strcmp(name, "pthread") == 0)
1485 return true;
1486 if (strcmp(name, "crypt") == 0)
1487 return true;
1488 if (strcmp(name, "util") == 0)
1489 return true;
1490 if (strcmp(name, "xnet") == 0)
1491 return true;
1492 if (strcmp(name, "resolv") == 0)
1493 return true;
1494 if (strcmp(name, "dl") == 0)
1495 return true;
1496 }
1497
1498 return false;
1499}
src/target.hpp+6-2
......@@ -155,13 +155,17 @@ ZigLLVM_OSType get_llvm_os_type(Os os_type);
155155bool target_is_arm(const ZigTarget *target);
156156bool target_allows_addr_zero(const ZigTarget *target);
157157bool target_has_valgrind_support(const ZigTarget *target);
158bool target_is_darwin(const ZigTarget *target);
159bool target_requires_libc(const ZigTarget *target);
158bool target_os_is_darwin(Os os);
159bool target_os_requires_libc(Os os);
160160bool target_can_build_libc(const ZigTarget *target);
161161const char *target_libc_generic_name(const ZigTarget *target);
162bool target_is_libc_lib_name(const ZigTarget *target, const char *name);
162163bool target_supports_fpic(const ZigTarget *target);
164bool target_requires_pic(const ZigTarget *target);
163165bool target_abi_is_gnu(ZigLLVM_EnvironmentType abi);
164166bool target_abi_is_musl(ZigLLVM_EnvironmentType abi);
167bool target_is_glibc(const ZigTarget *target);
168bool target_is_musl(const ZigTarget *target);
165169
166170uint32_t target_arch_pointer_bit_width(ZigLLVM_ArchType arch);
167171
std/build.zig+17-21
......@@ -157,10 +157,6 @@ pub const Builder = struct {
157157 return LibExeObjStep.createExecutable(self, name, root_src, false);
158158 }
159159
160 pub fn addStaticExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
161 return LibExeObjStep.createExecutable(self, name, root_src, true);
162 }
163
164160 pub fn addObject(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
165161 return LibExeObjStep.createObject(self, name, root_src);
166162 }
......@@ -920,7 +916,7 @@ pub const LibExeObjStep = struct {
920916 target: Target,
921917 linker_script: ?[]const u8,
922918 out_filename: []const u8,
923 static: bool,
919 is_dynamic: bool,
924920 version: Version,
925921 build_mode: builtin.Mode,
926922 kind: Kind,
......@@ -975,13 +971,13 @@ pub const LibExeObjStep = struct {
975971
976972 pub fn createSharedLibrary(builder: *Builder, name: []const u8, root_src: ?[]const u8, ver: Version) *LibExeObjStep {
977973 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
978 self.* = initExtraArgs(builder, name, root_src, Kind.Lib, false, ver);
974 self.* = initExtraArgs(builder, name, root_src, Kind.Lib, true, ver);
979975 return self;
980976 }
981977
982978 pub fn createStaticLibrary(builder: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
983979 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
984 self.* = initExtraArgs(builder, name, root_src, Kind.Lib, true, builder.version(0, 0, 0));
980 self.* = initExtraArgs(builder, name, root_src, Kind.Lib, false, builder.version(0, 0, 0));
985981 return self;
986982 }
987983
......@@ -991,9 +987,9 @@ pub const LibExeObjStep = struct {
991987 return self;
992988 }
993989
994 pub fn createExecutable(builder: *Builder, name: []const u8, root_src: ?[]const u8, static: bool) *LibExeObjStep {
990 pub fn createExecutable(builder: *Builder, name: []const u8, root_src: ?[]const u8, is_dynamic: bool) *LibExeObjStep {
995991 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
996 self.* = initExtraArgs(builder, name, root_src, Kind.Exe, static, builder.version(0, 0, 0));
992 self.* = initExtraArgs(builder, name, root_src, Kind.Exe, is_dynamic, builder.version(0, 0, 0));
997993 return self;
998994 }
999995
......@@ -1003,14 +999,14 @@ pub const LibExeObjStep = struct {
1003999 return self;
10041000 }
10051001
1006 fn initExtraArgs(builder: *Builder, name: []const u8, root_src: ?[]const u8, kind: Kind, static: bool, ver: Version) LibExeObjStep {
1002 fn initExtraArgs(builder: *Builder, name: []const u8, root_src: ?[]const u8, kind: Kind, is_dynamic: bool, ver: Version) LibExeObjStep {
10071003 var self = LibExeObjStep{
10081004 .strip = false,
10091005 .builder = builder,
10101006 .verbose_link = false,
10111007 .verbose_cc = false,
10121008 .build_mode = builtin.Mode.Debug,
1013 .static = static,
1009 .is_dynamic = is_dynamic,
10141010 .kind = kind,
10151011 .root_src = root_src,
10161012 .name = name,
......@@ -1057,7 +1053,7 @@ pub const LibExeObjStep = struct {
10571053 self.out_filename = self.builder.fmt("test{}", self.target.exeFileExt());
10581054 },
10591055 Kind.Lib => {
1060 if (self.static) {
1056 if (!self.is_dynamic) {
10611057 switch (self.target.getOs()) {
10621058 builtin.Os.windows => {
10631059 self.out_filename = self.builder.fmt("{}.lib", self.name);
......@@ -1147,7 +1143,7 @@ pub const LibExeObjStep = struct {
11471143 }
11481144
11491145 pub fn isDynamicLibrary(self: *LibExeObjStep) bool {
1150 return self.kind == Kind.Lib and !self.static;
1146 return self.kind == Kind.Lib and self.is_dynamic;
11511147 }
11521148
11531149 pub fn linkSystemLibrary(self: *LibExeObjStep, name: []const u8) void {
......@@ -1333,7 +1329,7 @@ pub const LibExeObjStep = struct {
13331329 try zig_args.append(other.getOutputPath());
13341330 },
13351331 LibExeObjStep.Kind.Lib => {
1336 if (other.static or self.target.isWindows()) {
1332 if (!other.is_dynamic or self.target.isWindows()) {
13371333 try zig_args.append("--object");
13381334 try zig_args.append(other.getOutputLibPath());
13391335 } else {
......@@ -1413,7 +1409,7 @@ pub const LibExeObjStep = struct {
14131409 zig_args.append("--name") catch unreachable;
14141410 zig_args.append(self.name) catch unreachable;
14151411
1416 if (self.kind == Kind.Lib and !self.static) {
1412 if (self.kind == Kind.Lib and self.is_dynamic) {
14171413 zig_args.append("--ver-major") catch unreachable;
14181414 zig_args.append(builder.fmt("{}", self.version.major)) catch unreachable;
14191415
......@@ -1423,8 +1419,8 @@ pub const LibExeObjStep = struct {
14231419 zig_args.append("--ver-patch") catch unreachable;
14241420 zig_args.append(builder.fmt("{}", self.version.patch)) catch unreachable;
14251421 }
1426 if (self.static) {
1427 zig_args.append("--static") catch unreachable;
1422 if (self.is_dynamic) {
1423 try zig_args.append("-dynamic");
14281424 }
14291425
14301426 switch (self.target) {
......@@ -1531,7 +1527,7 @@ pub const LibExeObjStep = struct {
15311527 self.output_dir = os.path.dirname(output_path).?;
15321528 }
15331529
1534 if (self.kind == Kind.Lib and !self.static and self.target.wantSharedLibSymLinks()) {
1530 if (self.kind == Kind.Lib and self.is_dynamic and self.target.wantSharedLibSymLinks()) {
15351531 try doAtomicSymLinks(builder.allocator, self.getOutputPath(), self.major_only_filename, self.name_only_filename);
15361532 }
15371533 }
......@@ -1677,7 +1673,7 @@ const InstallArtifactStep = struct {
16771673 };
16781674 self.step.dependOn(&artifact.step);
16791675 builder.pushInstalledFile(self.dest_file);
1680 if (self.artifact.kind == LibExeObjStep.Kind.Lib and !self.artifact.static) {
1676 if (self.artifact.kind == LibExeObjStep.Kind.Lib and self.artifact.is_dynamic) {
16811677 builder.pushInstalledFile(os.path.join(
16821678 builder.allocator,
16831679 [][]const u8{ builder.lib_dir, artifact.major_only_filename },
......@@ -1700,11 +1696,11 @@ const InstallArtifactStep = struct {
17001696 LibExeObjStep.Kind.Obj => unreachable,
17011697 LibExeObjStep.Kind.Test => unreachable,
17021698 LibExeObjStep.Kind.Exe => u32(0o755),
1703 LibExeObjStep.Kind.Lib => if (self.artifact.static) u32(0o666) else u32(0o755),
1699 LibExeObjStep.Kind.Lib => if (!self.artifact.is_dynamic) u32(0o666) else u32(0o755),
17041700 },
17051701 };
17061702 try builder.copyFileMode(self.artifact.getOutputPath(), self.dest_file, mode);
1707 if (self.artifact.kind == LibExeObjStep.Kind.Lib and !self.artifact.static) {
1703 if (self.artifact.isDynamicLibrary()) {
17081704 try doAtomicSymLinks(builder.allocator, self.dest_file, self.artifact.major_only_filename, self.artifact.name_only_filename);
17091705 }
17101706 }