authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2020-12-11 23:02:35+01:00
committergravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2020-12-13 00:40:35+01:00
log1d8f33ca98493d63c509e0a23b8dc512f4d7b79f
treef81c326ceef3cb9a010f85af5092274d908381ad
parent078a64f8d9b50ad99afe12ba3038afc3e68f507c
signaturelock-open Commit is signed but in an unrecognized format.

stage2: link musl dynamically by default if native

If targeting the native OS and the system libc is musl, link against it dynamically by default.

8 files changed, 26 insertions(+), 1 deletions(-)

src/Compilation.zig+17-1
......@@ -385,6 +385,7 @@ pub const InitOptions = struct {
385385 single_threaded: bool = false,
386386 function_sections: bool = false,
387387 is_native_os: bool,
388 is_native_abi: bool,
388389 time_report: bool = false,
389390 stack_report: bool = false,
390391 link_eh_frame_hdr: bool = false,
......@@ -600,7 +601,19 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
600601
601602 break :dl false;
602603 };
603 const default_link_mode: std.builtin.LinkMode = if (must_dynamic_link) .Dynamic else .Static;
604 const default_link_mode: std.builtin.LinkMode = blk: {
605 if (must_dynamic_link) {
606 break :blk .Dynamic;
607 } else if (is_exe_or_dyn_lib and link_libc and
608 options.is_native_abi and options.target.abi.isMusl())
609 {
610 // If targeting the system's native ABI and the system's
611 // libc is musl, link dynamically by default.
612 break :blk .Dynamic;
613 } else {
614 break :blk .Static;
615 }
616 };
604617 const link_mode: std.builtin.LinkMode = if (options.link_mode) |lm| blk: {
605618 if (lm == .Static and must_dynamic_link) {
606619 return error.UnableToStaticLink;
......@@ -910,6 +923,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
910923 .rpath_list = options.rpath_list,
911924 .strip = strip,
912925 .is_native_os = options.is_native_os,
926 .is_native_abi = options.is_native_abi,
913927 .function_sections = options.function_sections,
914928 .allow_shlib_undefined = options.linker_allow_shlib_undefined,
915929 .bind_global_refs_locally = options.linker_bind_global_refs_locally orelse false,
......@@ -2778,6 +2792,7 @@ fn buildOutputFromZig(
27782792 .emit_h = null,
27792793 .strip = comp.bin_file.options.strip,
27802794 .is_native_os = comp.bin_file.options.is_native_os,
2795 .is_native_abi = comp.bin_file.options.is_native_abi,
27812796 .self_exe_path = comp.self_exe_path,
27822797 .verbose_cc = comp.verbose_cc,
27832798 .verbose_link = comp.bin_file.options.verbose_link,
......@@ -3148,6 +3163,7 @@ pub fn build_crt_file(
31483163 .emit_h = null,
31493164 .strip = comp.bin_file.options.strip,
31503165 .is_native_os = comp.bin_file.options.is_native_os,
3166 .is_native_abi = comp.bin_file.options.is_native_abi,
31513167 .self_exe_path = comp.self_exe_path,
31523168 .c_source_files = c_source_files,
31533169 .verbose_cc = comp.verbose_cc,
src/glibc.zig+1
......@@ -945,6 +945,7 @@ fn buildSharedLib(
945945 .emit_h = null,
946946 .strip = comp.bin_file.options.strip,
947947 .is_native_os = false,
948 .is_native_abi = false,
948949 .self_exe_path = comp.self_exe_path,
949950 .verbose_cc = comp.verbose_cc,
950951 .verbose_link = comp.bin_file.options.verbose_link,
src/libcxx.zig+2
......@@ -175,6 +175,7 @@ pub fn buildLibCXX(comp: *Compilation) !void {
175175 .emit_h = null,
176176 .strip = comp.bin_file.options.strip,
177177 .is_native_os = comp.bin_file.options.is_native_os,
178 .is_native_abi = comp.bin_file.options.is_native_abi,
178179 .self_exe_path = comp.self_exe_path,
179180 .c_source_files = c_source_files.items,
180181 .verbose_cc = comp.verbose_cc,
......@@ -293,6 +294,7 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
293294 .emit_h = null,
294295 .strip = comp.bin_file.options.strip,
295296 .is_native_os = comp.bin_file.options.is_native_os,
297 .is_native_abi = comp.bin_file.options.is_native_abi,
296298 .self_exe_path = comp.self_exe_path,
297299 .c_source_files = &c_source_files,
298300 .verbose_cc = comp.verbose_cc,
src/libunwind.zig+1
......@@ -108,6 +108,7 @@ pub fn buildStaticLib(comp: *Compilation) !void {
108108 .emit_h = null,
109109 .strip = comp.bin_file.options.strip,
110110 .is_native_os = comp.bin_file.options.is_native_os,
111 .is_native_abi = comp.bin_file.options.is_native_abi,
111112 .self_exe_path = comp.self_exe_path,
112113 .c_source_files = &c_source_files,
113114 .verbose_cc = comp.verbose_cc,
src/link.zig+1
......@@ -71,6 +71,7 @@ pub const Options = struct {
7171 z_defs: bool,
7272 bind_global_refs_locally: bool,
7373 is_native_os: bool,
74 is_native_abi: bool,
7475 pic: bool,
7576 pie: bool,
7677 valgrind: bool,
src/main.zig+2
......@@ -1685,6 +1685,7 @@ fn buildOutputType(
16851685 .root_name = root_name,
16861686 .target = target_info.target,
16871687 .is_native_os = cross_target.isNativeOs(),
1688 .is_native_abi = cross_target.isNativeAbi(),
16881689 .dynamic_linker = target_info.dynamic_linker.get(),
16891690 .output_mode = output_mode,
16901691 .root_pkg = root_pkg,
......@@ -2415,6 +2416,7 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
24152416 .root_name = "build",
24162417 .target = target_info.target,
24172418 .is_native_os = cross_target.isNativeOs(),
2419 .is_native_abi = cross_target.isNativeAbi(),
24182420 .dynamic_linker = target_info.dynamic_linker.get(),
24192421 .output_mode = .Exe,
24202422 .root_pkg = &root_pkg,
src/musl.zig+1
......@@ -210,6 +210,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
210210 .emit_h = null,
211211 .strip = comp.bin_file.options.strip,
212212 .is_native_os = false,
213 .is_native_abi = false,
213214 .self_exe_path = comp.self_exe_path,
214215 .verbose_cc = comp.verbose_cc,
215216 .verbose_link = comp.bin_file.options.verbose_link,
src/test.zig+1
......@@ -561,6 +561,7 @@ pub const TestContext = struct {
561561 .keep_source_files_loaded = true,
562562 .object_format = ofmt,
563563 .is_native_os = case.target.isNativeOs(),
564 .is_native_abi = case.target.isNativeAbi(),
564565 });
565566 defer comp.destroy();
566567