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 {...@@ -385,6 +385,7 @@ pub const InitOptions = struct {
385 single_threaded: bool = false,385 single_threaded: bool = false,
386 function_sections: bool = false,386 function_sections: bool = false,
387 is_native_os: bool,387 is_native_os: bool,
388 is_native_abi: bool,
388 time_report: bool = false,389 time_report: bool = false,
389 stack_report: bool = false,390 stack_report: bool = false,
390 link_eh_frame_hdr: bool = false,391 link_eh_frame_hdr: bool = false,
...@@ -600,7 +601,19 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -600,7 +601,19 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
600601
601 break :dl false;602 break :dl false;
602 };603 };
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 };
604 const link_mode: std.builtin.LinkMode = if (options.link_mode) |lm| blk: {617 const link_mode: std.builtin.LinkMode = if (options.link_mode) |lm| blk: {
605 if (lm == .Static and must_dynamic_link) {618 if (lm == .Static and must_dynamic_link) {
606 return error.UnableToStaticLink;619 return error.UnableToStaticLink;
...@@ -910,6 +923,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -910,6 +923,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
910 .rpath_list = options.rpath_list,923 .rpath_list = options.rpath_list,
911 .strip = strip,924 .strip = strip,
912 .is_native_os = options.is_native_os,925 .is_native_os = options.is_native_os,
926 .is_native_abi = options.is_native_abi,
913 .function_sections = options.function_sections,927 .function_sections = options.function_sections,
914 .allow_shlib_undefined = options.linker_allow_shlib_undefined,928 .allow_shlib_undefined = options.linker_allow_shlib_undefined,
915 .bind_global_refs_locally = options.linker_bind_global_refs_locally orelse false,929 .bind_global_refs_locally = options.linker_bind_global_refs_locally orelse false,
...@@ -2778,6 +2792,7 @@ fn buildOutputFromZig(...@@ -2778,6 +2792,7 @@ fn buildOutputFromZig(
2778 .emit_h = null,2792 .emit_h = null,
2779 .strip = comp.bin_file.options.strip,2793 .strip = comp.bin_file.options.strip,
2780 .is_native_os = comp.bin_file.options.is_native_os,2794 .is_native_os = comp.bin_file.options.is_native_os,
2795 .is_native_abi = comp.bin_file.options.is_native_abi,
2781 .self_exe_path = comp.self_exe_path,2796 .self_exe_path = comp.self_exe_path,
2782 .verbose_cc = comp.verbose_cc,2797 .verbose_cc = comp.verbose_cc,
2783 .verbose_link = comp.bin_file.options.verbose_link,2798 .verbose_link = comp.bin_file.options.verbose_link,
...@@ -3148,6 +3163,7 @@ pub fn build_crt_file(...@@ -3148,6 +3163,7 @@ pub fn build_crt_file(
3148 .emit_h = null,3163 .emit_h = null,
3149 .strip = comp.bin_file.options.strip,3164 .strip = comp.bin_file.options.strip,
3150 .is_native_os = comp.bin_file.options.is_native_os,3165 .is_native_os = comp.bin_file.options.is_native_os,
3166 .is_native_abi = comp.bin_file.options.is_native_abi,
3151 .self_exe_path = comp.self_exe_path,3167 .self_exe_path = comp.self_exe_path,
3152 .c_source_files = c_source_files,3168 .c_source_files = c_source_files,
3153 .verbose_cc = comp.verbose_cc,3169 .verbose_cc = comp.verbose_cc,
src/glibc.zig+1
...@@ -945,6 +945,7 @@ fn buildSharedLib(...@@ -945,6 +945,7 @@ fn buildSharedLib(
945 .emit_h = null,945 .emit_h = null,
946 .strip = comp.bin_file.options.strip,946 .strip = comp.bin_file.options.strip,
947 .is_native_os = false,947 .is_native_os = false,
948 .is_native_abi = false,
948 .self_exe_path = comp.self_exe_path,949 .self_exe_path = comp.self_exe_path,
949 .verbose_cc = comp.verbose_cc,950 .verbose_cc = comp.verbose_cc,
950 .verbose_link = comp.bin_file.options.verbose_link,951 .verbose_link = comp.bin_file.options.verbose_link,
src/libcxx.zig+2
...@@ -175,6 +175,7 @@ pub fn buildLibCXX(comp: *Compilation) !void {...@@ -175,6 +175,7 @@ pub fn buildLibCXX(comp: *Compilation) !void {
175 .emit_h = null,175 .emit_h = null,
176 .strip = comp.bin_file.options.strip,176 .strip = comp.bin_file.options.strip,
177 .is_native_os = comp.bin_file.options.is_native_os,177 .is_native_os = comp.bin_file.options.is_native_os,
178 .is_native_abi = comp.bin_file.options.is_native_abi,
178 .self_exe_path = comp.self_exe_path,179 .self_exe_path = comp.self_exe_path,
179 .c_source_files = c_source_files.items,180 .c_source_files = c_source_files.items,
180 .verbose_cc = comp.verbose_cc,181 .verbose_cc = comp.verbose_cc,
...@@ -293,6 +294,7 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {...@@ -293,6 +294,7 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
293 .emit_h = null,294 .emit_h = null,
294 .strip = comp.bin_file.options.strip,295 .strip = comp.bin_file.options.strip,
295 .is_native_os = comp.bin_file.options.is_native_os,296 .is_native_os = comp.bin_file.options.is_native_os,
297 .is_native_abi = comp.bin_file.options.is_native_abi,
296 .self_exe_path = comp.self_exe_path,298 .self_exe_path = comp.self_exe_path,
297 .c_source_files = &c_source_files,299 .c_source_files = &c_source_files,
298 .verbose_cc = comp.verbose_cc,300 .verbose_cc = comp.verbose_cc,
src/libunwind.zig+1
...@@ -108,6 +108,7 @@ pub fn buildStaticLib(comp: *Compilation) !void {...@@ -108,6 +108,7 @@ pub fn buildStaticLib(comp: *Compilation) !void {
108 .emit_h = null,108 .emit_h = null,
109 .strip = comp.bin_file.options.strip,109 .strip = comp.bin_file.options.strip,
110 .is_native_os = comp.bin_file.options.is_native_os,110 .is_native_os = comp.bin_file.options.is_native_os,
111 .is_native_abi = comp.bin_file.options.is_native_abi,
111 .self_exe_path = comp.self_exe_path,112 .self_exe_path = comp.self_exe_path,
112 .c_source_files = &c_source_files,113 .c_source_files = &c_source_files,
113 .verbose_cc = comp.verbose_cc,114 .verbose_cc = comp.verbose_cc,
src/link.zig+1
...@@ -71,6 +71,7 @@ pub const Options = struct {...@@ -71,6 +71,7 @@ pub const Options = struct {
71 z_defs: bool,71 z_defs: bool,
72 bind_global_refs_locally: bool,72 bind_global_refs_locally: bool,
73 is_native_os: bool,73 is_native_os: bool,
74 is_native_abi: bool,
74 pic: bool,75 pic: bool,
75 pie: bool,76 pie: bool,
76 valgrind: bool,77 valgrind: bool,
src/main.zig+2
...@@ -1685,6 +1685,7 @@ fn buildOutputType(...@@ -1685,6 +1685,7 @@ fn buildOutputType(
1685 .root_name = root_name,1685 .root_name = root_name,
1686 .target = target_info.target,1686 .target = target_info.target,
1687 .is_native_os = cross_target.isNativeOs(),1687 .is_native_os = cross_target.isNativeOs(),
1688 .is_native_abi = cross_target.isNativeAbi(),
1688 .dynamic_linker = target_info.dynamic_linker.get(),1689 .dynamic_linker = target_info.dynamic_linker.get(),
1689 .output_mode = output_mode,1690 .output_mode = output_mode,
1690 .root_pkg = root_pkg,1691 .root_pkg = root_pkg,
...@@ -2415,6 +2416,7 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v...@@ -2415,6 +2416,7 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
2415 .root_name = "build",2416 .root_name = "build",
2416 .target = target_info.target,2417 .target = target_info.target,
2417 .is_native_os = cross_target.isNativeOs(),2418 .is_native_os = cross_target.isNativeOs(),
2419 .is_native_abi = cross_target.isNativeAbi(),
2418 .dynamic_linker = target_info.dynamic_linker.get(),2420 .dynamic_linker = target_info.dynamic_linker.get(),
2419 .output_mode = .Exe,2421 .output_mode = .Exe,
2420 .root_pkg = &root_pkg,2422 .root_pkg = &root_pkg,
src/musl.zig+1
...@@ -210,6 +210,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {...@@ -210,6 +210,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
210 .emit_h = null,210 .emit_h = null,
211 .strip = comp.bin_file.options.strip,211 .strip = comp.bin_file.options.strip,
212 .is_native_os = false,212 .is_native_os = false,
213 .is_native_abi = false,
213 .self_exe_path = comp.self_exe_path,214 .self_exe_path = comp.self_exe_path,
214 .verbose_cc = comp.verbose_cc,215 .verbose_cc = comp.verbose_cc,
215 .verbose_link = comp.bin_file.options.verbose_link,216 .verbose_link = comp.bin_file.options.verbose_link,
src/test.zig+1
...@@ -561,6 +561,7 @@ pub const TestContext = struct {...@@ -561,6 +561,7 @@ pub const TestContext = struct {
561 .keep_source_files_loaded = true,561 .keep_source_files_loaded = true,
562 .object_format = ofmt,562 .object_format = ofmt,
563 .is_native_os = case.target.isNativeOs(),563 .is_native_os = case.target.isNativeOs(),
564 .is_native_abi = case.target.isNativeAbi(),
564 });565 });
565 defer comp.destroy();566 defer comp.destroy();
566567