diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-12-12 18:46:07 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-12 18:46:07 -0500 |
| commit | 4fd27719b4cee287f873c452a515927977bde0cd (patch) | |
| tree | c55fdc32807ad2420192e7a85db53ed1c3c9dcf2 /src/Compilation.zig | |
| parent | 6b7ddfbafe7ff8f9bc9952f838737e8514c9b26b (diff) | |
| parent | 1d8f33ca98493d63c509e0a23b8dc512f4d7b79f (diff) | |
| download | zig-4fd27719b4cee287f873c452a515927977bde0cd.tar.gz zig-4fd27719b4cee287f873c452a515927977bde0cd.zip | |
Merge pull request #7406 from ifreund/dyn-musl2
stage2: support dynamically linking musl libc
Diffstat (limited to 'src/Compilation.zig')
| -rw-r--r-- | src/Compilation.zig | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index 96bf7b5797..81a2bff37b 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -385,6 +385,7 @@ pub const InitOptions = struct { single_threaded: bool = false, function_sections: bool = false, is_native_os: bool, + is_native_abi: bool, time_report: bool = false, stack_report: bool = false, link_eh_frame_hdr: bool = false, @@ -600,7 +601,19 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { break :dl false; }; - const default_link_mode: std.builtin.LinkMode = if (must_dynamic_link) .Dynamic else .Static; + const default_link_mode: std.builtin.LinkMode = blk: { + if (must_dynamic_link) { + break :blk .Dynamic; + } else if (is_exe_or_dyn_lib and link_libc and + options.is_native_abi and options.target.abi.isMusl()) + { + // If targeting the system's native ABI and the system's + // libc is musl, link dynamically by default. + break :blk .Dynamic; + } else { + break :blk .Static; + } + }; const link_mode: std.builtin.LinkMode = if (options.link_mode) |lm| blk: { if (lm == .Static and must_dynamic_link) { return error.UnableToStaticLink; @@ -910,6 +923,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { .rpath_list = options.rpath_list, .strip = strip, .is_native_os = options.is_native_os, + .is_native_abi = options.is_native_abi, .function_sections = options.function_sections, .allow_shlib_undefined = options.linker_allow_shlib_undefined, .bind_global_refs_locally = options.linker_bind_global_refs_locally orelse false, @@ -1025,7 +1039,10 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { .{ .musl_crt_file = .crt1_o }, .{ .musl_crt_file = .scrt1_o }, .{ .musl_crt_file = .rcrt1_o }, - .{ .musl_crt_file = .libc_a }, + switch (comp.bin_file.options.link_mode) { + .Static => .{ .musl_crt_file = .libc_a }, + .Dynamic => .{ .musl_crt_file = .libc_so }, + }, }); } if (comp.wantBuildMinGWFromSource()) { @@ -2775,6 +2792,7 @@ fn buildOutputFromZig( .emit_h = null, .strip = comp.bin_file.options.strip, .is_native_os = comp.bin_file.options.is_native_os, + .is_native_abi = comp.bin_file.options.is_native_abi, .self_exe_path = comp.self_exe_path, .verbose_cc = comp.verbose_cc, .verbose_link = comp.bin_file.options.verbose_link, @@ -3145,6 +3163,7 @@ pub fn build_crt_file( .emit_h = null, .strip = comp.bin_file.options.strip, .is_native_os = comp.bin_file.options.is_native_os, + .is_native_abi = comp.bin_file.options.is_native_abi, .self_exe_path = comp.self_exe_path, .c_source_files = c_source_files, .verbose_cc = comp.verbose_cc, |
