authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-28 13:27:52-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-28 14:51:56-05:00
log500dde32d5cf59f5700fb3f69ae6c7a0defd8a93
tree135d6b28fdb7690a8ef117b378cec0f11392d1ee
parent07f52119de2a8bdb84389c73332e113cf12ac997
signature Commit is signed but in an unrecognized format.

dynamic_linker becomes a field of std.zig.CrossTarget


13 files changed, 137 insertions(+), 127 deletions(-)

lib/std/build.zig+5-7
......@@ -1177,8 +1177,6 @@ pub const LibExeObjStep = struct {
11771177 /// that contains the path `aarch64-linux-gnu/lib/ld-linux-aarch64.so.1`.
11781178 glibc_multi_install_dir: ?[]const u8 = null,
11791179
1180 dynamic_linker: ?[]const u8 = null,
1181
11821180 /// Position Independent Code
11831181 force_pic: ?bool = null,
11841182
......@@ -1978,6 +1976,11 @@ pub const LibExeObjStep = struct {
19781976 }
19791977 try zig_args.append(mcpu_buffer.toSliceConst());
19801978 }
1979
1980 if (self.target.dynamic_linker.get()) |dynamic_linker| {
1981 try zig_args.append("--dynamic-linker");
1982 try zig_args.append(dynamic_linker);
1983 }
19811984 }
19821985
19831986 if (self.linker_script) |linker_script| {
......@@ -1985,11 +1988,6 @@ pub const LibExeObjStep = struct {
19851988 zig_args.append(builder.pathFromRoot(linker_script)) catch unreachable;
19861989 }
19871990
1988 if (self.dynamic_linker) |dynamic_linker| {
1989 try zig_args.append("--dynamic-linker");
1990 try zig_args.append(dynamic_linker);
1991 }
1992
19931991 if (self.version_script) |version_script| {
19941992 try zig_args.append("--version-script");
19951993 try zig_args.append(builder.pathFromRoot(version_script));
lib/std/target.zig+64-28
......@@ -1099,16 +1099,52 @@ pub const Target = struct {
10991099 }
11001100 }
11011101
1102 pub const DynamicLinker = struct {
1103 /// Contains the memory used to store the dynamic linker path. This field should
1104 /// not be used directly. See `get` and `set`. This field exists so that this API requires no allocator.
1105 buffer: [255]u8 = undefined,
1106
1107 /// Used to construct the dynamic linker path. This field should not be used
1108 /// directly. See `get` and `set`.
1109 max_byte: ?u8 = null,
1110
1111 /// Asserts that the length is less than or equal to 255 bytes.
1112 pub fn init(dl_or_null: ?[]const u8) DynamicLinker {
1113 var result: DynamicLinker = undefined;
1114 result.set(dl_or_null);
1115 return result;
1116 }
1117
1118 /// The returned memory has the same lifetime as the `DynamicLinker`.
1119 pub fn get(self: *const DynamicLinker) ?[]const u8 {
1120 const m: usize = self.max_byte orelse return null;
1121 return self.buffer[0 .. m + 1];
1122 }
1123
1124 /// Asserts that the length is less than or equal to 255 bytes.
1125 pub fn set(self: *DynamicLinker, dl_or_null: ?[]const u8) void {
1126 if (dl_or_null) |dl| {
1127 mem.copy(u8, &self.buffer, dl);
1128 self.max_byte = @intCast(u8, dl.len - 1);
1129 } else {
1130 self.max_byte = null;
1131 }
1132 }
1133 };
1134
11021135 /// The result will be a byte index *pointing at the final byte*. In other words, length minus one.
11031136 /// A return value of `null` means the concept of a dynamic linker is not meaningful for that target.
1104 pub fn standardDynamicLinkerPath(self: Target, buffer: *[255]u8) ?u8 {
1137 pub fn standardDynamicLinkerPath(self: Target) DynamicLinker {
1138 var result: DynamicLinker = .{};
11051139 const S = struct {
1106 fn print(b: *[255]u8, comptime fmt: []const u8, args: var) u8 {
1107 return @intCast(u8, (std.fmt.bufPrint(b, fmt, args) catch unreachable).len - 1);
1140 fn print(r: *DynamicLinker, comptime fmt: []const u8, args: var) DynamicLinker {
1141 r.max_byte = @intCast(u8, (std.fmt.bufPrint(&r.buffer, fmt, args) catch unreachable).len - 1);
1142 return r.*;
11081143 }
1109 fn copy(b: *[255]u8, s: []const u8) u8 {
1110 mem.copy(u8, b, s);
1111 return @intCast(u8, s.len - 1);
1144 fn copy(r: *DynamicLinker, s: []const u8) DynamicLinker {
1145 mem.copy(u8, &r.buffer, s);
1146 r.max_byte = @intCast(u8, s.len - 1);
1147 return r.*;
11121148 }
11131149 };
11141150 const print = S.print;
......@@ -1116,7 +1152,7 @@ pub const Target = struct {
11161152
11171153 if (self.isAndroid()) {
11181154 const suffix = if (self.cpu.arch.ptrBitWidth() == 64) "64" else "";
1119 return print(buffer, "/system/bin/linker{}", .{suffix});
1155 return print(&result, "/system/bin/linker{}", .{suffix});
11201156 }
11211157
11221158 if (self.isMusl()) {
......@@ -1130,28 +1166,28 @@ pub const Target = struct {
11301166 else => |arch| @tagName(arch),
11311167 };
11321168 const arch_suffix = if (is_arm and self.getFloatAbi() == .hard) "hf" else "";
1133 return print(buffer, "/lib/ld-musl-{}{}.so.1", .{ arch_part, arch_suffix });
1169 return print(&result, "/lib/ld-musl-{}{}.so.1", .{ arch_part, arch_suffix });
11341170 }
11351171
11361172 switch (self.os.tag) {
1137 .freebsd => return copy(buffer, "/libexec/ld-elf.so.1"),
1138 .netbsd => return copy(buffer, "/libexec/ld.elf_so"),
1139 .dragonfly => return copy(buffer, "/libexec/ld-elf.so.2"),
1173 .freebsd => return copy(&result, "/libexec/ld-elf.so.1"),
1174 .netbsd => return copy(&result, "/libexec/ld.elf_so"),
1175 .dragonfly => return copy(&result, "/libexec/ld-elf.so.2"),
11401176 .linux => switch (self.cpu.arch) {
11411177 .i386,
11421178 .sparc,
11431179 .sparcel,
1144 => return copy(buffer, "/lib/ld-linux.so.2"),
1180 => return copy(&result, "/lib/ld-linux.so.2"),
11451181
1146 .aarch64 => return copy(buffer, "/lib/ld-linux-aarch64.so.1"),
1147 .aarch64_be => return copy(buffer, "/lib/ld-linux-aarch64_be.so.1"),
1148 .aarch64_32 => return copy(buffer, "/lib/ld-linux-aarch64_32.so.1"),
1182 .aarch64 => return copy(&result, "/lib/ld-linux-aarch64.so.1"),
1183 .aarch64_be => return copy(&result, "/lib/ld-linux-aarch64_be.so.1"),
1184 .aarch64_32 => return copy(&result, "/lib/ld-linux-aarch64_32.so.1"),
11491185
11501186 .arm,
11511187 .armeb,
11521188 .thumb,
11531189 .thumbeb,
1154 => return copy(buffer, switch (self.getFloatAbi()) {
1190 => return copy(&result, switch (self.getFloatAbi()) {
11551191 .hard => "/lib/ld-linux-armhf.so.3",
11561192 else => "/lib/ld-linux.so.3",
11571193 }),
......@@ -1168,20 +1204,20 @@ pub const Target = struct {
11681204 };
11691205 const is_nan_2008 = mips.featureSetHas(self.cpu.features, .nan2008);
11701206 const loader = if (is_nan_2008) "ld-linux-mipsn8.so.1" else "ld.so.1";
1171 return print(buffer, "/lib{}/{}", .{ lib_suffix, loader });
1207 return print(&result, "/lib{}/{}", .{ lib_suffix, loader });
11721208 },
11731209
1174 .powerpc => return copy(buffer, "/lib/ld.so.1"),
1175 .powerpc64, .powerpc64le => return copy(buffer, "/lib64/ld64.so.2"),
1176 .s390x => return copy(buffer, "/lib64/ld64.so.1"),
1177 .sparcv9 => return copy(buffer, "/lib64/ld-linux.so.2"),
1178 .x86_64 => return copy(buffer, switch (self.abi) {
1210 .powerpc => return copy(&result, "/lib/ld.so.1"),
1211 .powerpc64, .powerpc64le => return copy(&result, "/lib64/ld64.so.2"),
1212 .s390x => return copy(&result, "/lib64/ld64.so.1"),
1213 .sparcv9 => return copy(&result, "/lib64/ld-linux.so.2"),
1214 .x86_64 => return copy(&result, switch (self.abi) {
11791215 .gnux32 => "/libx32/ld-linux-x32.so.2",
11801216 else => "/lib64/ld-linux-x86-64.so.2",
11811217 }),
11821218
1183 .riscv32 => return copy(buffer, "/lib/ld-linux-riscv32-ilp32.so.1"),
1184 .riscv64 => return copy(buffer, "/lib/ld-linux-riscv64-lp64.so.1"),
1219 .riscv32 => return copy(&result, "/lib/ld-linux-riscv32-ilp32.so.1"),
1220 .riscv64 => return copy(&result, "/lib/ld-linux-riscv64-lp64.so.1"),
11851221
11861222 // Architectures in this list have been verified as not having a standard
11871223 // dynamic linker path.
......@@ -1191,7 +1227,7 @@ pub const Target = struct {
11911227 .bpfeb,
11921228 .nvptx,
11931229 .nvptx64,
1194 => return null,
1230 => return result,
11951231
11961232 // TODO go over each item in this list and either move it to the above list, or
11971233 // implement the standard dynamic linker path code for it.
......@@ -1217,7 +1253,7 @@ pub const Target = struct {
12171253 .lanai,
12181254 .renderscript32,
12191255 .renderscript64,
1220 => return null,
1256 => return result,
12211257 },
12221258
12231259 // Operating systems in this list have been verified as not having a standard
......@@ -1232,7 +1268,7 @@ pub const Target = struct {
12321268 .emscripten,
12331269 .wasi,
12341270 .other,
1235 => return null,
1271 => return result,
12361272
12371273 // TODO go over each item in this list and either move it to the above list, or
12381274 // implement the standard dynamic linker path code for it.
......@@ -1259,7 +1295,7 @@ pub const Target = struct {
12591295 .amdpal,
12601296 .hermit,
12611297 .hurd,
1262 => return null,
1298 => return result,
12631299 }
12641300 }
12651301};
lib/std/zig/cross_target.zig+14-3
......@@ -40,6 +40,10 @@ pub const CrossTarget = struct {
4040 /// If `isGnuLibC()` is `false`, this must be `null` and is ignored.
4141 glibc_version: ?SemVer = null,
4242
43 /// When `os_tag` is `null`, then `null` means native. Otherwise it means the standard path
44 /// based on the `os_tag`.
45 dynamic_linker: DynamicLinker = DynamicLinker{},
46
4347 pub const OsVersion = union(enum) {
4448 none: void,
4549 semver: SemVer,
......@@ -48,6 +52,8 @@ pub const CrossTarget = struct {
4852
4953 pub const SemVer = std.builtin.Version;
5054
55 pub const DynamicLinker = Target.DynamicLinker;
56
5157 pub fn fromTarget(target: Target) CrossTarget {
5258 var result: CrossTarget = .{
5359 .cpu_arch = target.cpu.arch,
......@@ -170,6 +176,10 @@ pub const CrossTarget = struct {
170176 /// parsed CPU Architecture. If native, then this will be "native". Otherwise, it will be "baseline".
171177 cpu_features: ?[]const u8 = null,
172178
179 /// Absolute path to dynamic linker, to override the default, which is either a natively
180 /// detected path, or a standard path.
181 dynamic_linker: ?[]const u8 = null,
182
173183 /// If this is provided, the function will populate some information about parsing failures,
174184 /// so that user-friendly error messages can be delivered.
175185 diagnostics: ?*Diagnostics = null,
......@@ -199,8 +209,9 @@ pub const CrossTarget = struct {
199209 var dummy_diags: ParseOptions.Diagnostics = undefined;
200210 const diags = args.diagnostics orelse &dummy_diags;
201211
202 // Start with everything initialized to default values.
203 var result: CrossTarget = .{};
212 var result: CrossTarget = .{
213 .dynamic_linker = DynamicLinker.init(args.dynamic_linker),
214 };
204215
205216 var it = mem.separate(args.arch_os_abi, "-");
206217 const arch_name = it.next().?;
......@@ -446,7 +457,7 @@ pub const CrossTarget = struct {
446457 return self.cpu_arch == null and self.cpu_model == null and
447458 self.cpu_features_sub.isEmpty() and self.cpu_features_add.isEmpty() and
448459 self.os_tag == null and self.os_version_min == null and self.os_version_max == null and
449 self.abi == null;
460 self.abi == null and self.dynamic_linker.get() == null;
450461 }
451462
452463 pub fn zigTriple(self: CrossTarget, allocator: *mem.Allocator) error{OutOfMemory}![:0]u8 {
lib/std/zig/system.zig+25-52
......@@ -168,14 +168,9 @@ pub const NativePaths = struct {
168168pub const NativeTargetInfo = struct {
169169 target: Target,
170170
171 /// Contains the memory used to store the dynamic linker path. This field should
172 /// not be used directly. See `dynamicLinker` and `setDynamicLinker`. This field
173 /// exists so that this API requires no allocator.
174 dynamic_linker_buffer: [255]u8 = undefined,
171 dynamic_linker: DynamicLinker = DynamicLinker{},
175172
176 /// Used to construct the dynamic linker path. This field should not be used
177 /// directly. See `dynamicLinker` and `setDynamicLinker`.
178 dynamic_linker_max: ?u8 = null,
173 pub const DynamicLinker = Target.DynamicLinker;
179174
180175 pub const DetectError = error{
181176 OutOfMemory,
......@@ -220,21 +215,6 @@ pub const NativeTargetInfo = struct {
220215 return detectAbiAndDynamicLinker(allocator, cpu, os);
221216 }
222217
223 /// The returned memory has the same lifetime as the `NativeTargetInfo`.
224 pub fn dynamicLinker(self: *const NativeTargetInfo) ?[]const u8 {
225 const m: usize = self.dynamic_linker_max orelse return null;
226 return self.dynamic_linker_buffer[0 .. m + 1];
227 }
228
229 pub fn setDynamicLinker(self: *NativeTargetInfo, dl_or_null: ?[]const u8) void {
230 if (dl_or_null) |dl| {
231 mem.copy(u8, &self.dynamic_linker_buffer, dl);
232 self.dynamic_linker_max = @intCast(u8, dl.len - 1);
233 } else {
234 self.dynamic_linker_max = null;
235 }
236 }
237
238218 /// First we attempt to use the executable's own binary. If it is dynamically
239219 /// linked, then it should answer both the C ABI question and the dynamic linker question.
240220 /// If it is statically linked, then we try /usr/bin/env. If that does not provide the answer, then
......@@ -273,15 +253,14 @@ pub const NativeTargetInfo = struct {
273253 .os = os,
274254 .abi = abi,
275255 };
276 const ld_info = &ld_info_list_buffer[ld_info_list_len];
277 ld_info_list_len += 1;
256 const ld = target.standardDynamicLinkerPath();
257 if (ld.get() == null) continue;
278258
279 ld_info.* = .{
280 .ld_path_buffer = undefined,
281 .ld_path_max = undefined,
259 ld_info_list_buffer[ld_info_list_len] = .{
260 .ld = ld,
282261 .abi = abi,
283262 };
284 ld_info.ld_path_max = target.standardDynamicLinkerPath(&ld_info.ld_path_buffer) orelse continue;
263 ld_info_list_len += 1;
285264 }
286265 const ld_info_list = ld_info_list_buffer[0..ld_info_list_len];
287266
......@@ -298,7 +277,7 @@ pub const NativeTargetInfo = struct {
298277 // This is O(N^M) but typical case here is N=2 and M=10.
299278 find_ld: for (lib_paths) |lib_path| {
300279 for (ld_info_list) |ld_info| {
301 const standard_ld_basename = fs.path.basename(ld_info.ldPath());
280 const standard_ld_basename = fs.path.basename(ld_info.ld.get().?);
302281 if (std.mem.endsWith(u8, lib_path, standard_ld_basename)) {
303282 found_ld_info = ld_info;
304283 found_ld_path = lib_path;
......@@ -329,8 +308,8 @@ pub const NativeTargetInfo = struct {
329308 .os = os_adjusted,
330309 .abi = found_ld_info.abi,
331310 },
311 .dynamic_linker = DynamicLinker.init(found_ld_path),
332312 };
333 result.setDynamicLinker(found_ld_path);
334313 return result;
335314 }
336315
......@@ -472,18 +451,18 @@ pub const NativeTargetInfo = struct {
472451 elf.PT_INTERP => {
473452 const p_offset = elfInt(is_64, need_bswap, ph32.p_offset, ph64.p_offset);
474453 const p_filesz = elfInt(is_64, need_bswap, ph32.p_filesz, ph64.p_filesz);
475 if (p_filesz > result.dynamic_linker_buffer.len) return error.NameTooLong;
476 _ = try preadFull(env_file, result.dynamic_linker_buffer[0..p_filesz], p_offset, p_filesz);
454 if (p_filesz > result.dynamic_linker.buffer.len) return error.NameTooLong;
455 _ = try preadFull(env_file, result.dynamic_linker.buffer[0..p_filesz], p_offset, p_filesz);
477456 // PT_INTERP includes a null byte in p_filesz.
478457 const len = p_filesz - 1;
479 // dynamic_linker_max is "max", not "len".
480 // We know it will fit in u8 because we check against dynamic_linker_buffer.len above.
481 result.dynamic_linker_max = @intCast(u8, len - 1);
458 // dynamic_linker.max_byte is "max", not "len".
459 // We know it will fit in u8 because we check against dynamic_linker.buffer.len above.
460 result.dynamic_linker.max_byte = @intCast(u8, len - 1);
482461
483462 // Use it to determine ABI.
484 const full_ld_path = result.dynamic_linker_buffer[0..len];
463 const full_ld_path = result.dynamic_linker.buffer[0..len];
485464 for (ld_info_list) |ld_info| {
486 const standard_ld_basename = fs.path.basename(ld_info.ldPath());
465 const standard_ld_basename = fs.path.basename(ld_info.ld.get().?);
487466 if (std.mem.endsWith(u8, full_ld_path, standard_ld_basename)) {
488467 result.target.abi = ld_info.abi;
489468 break;
......@@ -679,26 +658,20 @@ pub const NativeTargetInfo = struct {
679658 }
680659
681660 fn defaultAbiAndDynamicLinker(cpu: Target.Cpu, os: Target.Os) !NativeTargetInfo {
682 var result: NativeTargetInfo = .{
683 .target = .{
684 .cpu = cpu,
685 .os = os,
686 .abi = Target.Abi.default(cpu.arch, os),
687 },
661 const target: Target = .{
662 .cpu = cpu,
663 .os = os,
664 .abi = Target.Abi.default(cpu.arch, os),
665 };
666 return NativeTargetInfo{
667 .target = target,
668 .dynamic_linker = target.standardDynamicLinkerPath(),
688669 };
689 result.dynamic_linker_max = result.target.standardDynamicLinkerPath(&result.dynamic_linker_buffer);
690 return result;
691670 }
692671
693672 const LdInfo = struct {
694 ld_path_buffer: [255]u8,
695 ld_path_max: u8,
673 ld: DynamicLinker,
696674 abi: Target.Abi,
697
698 pub fn ldPath(self: *const LdInfo) []const u8 {
699 const m: usize = self.ld_path_max;
700 return self.ld_path_buffer[0 .. m + 1];
701 }
702675 };
703676
704677 fn elfInt(is_64: bool, need_bswap: bool, int_32: var, int_64: var) @TypeOf(int_64) {
src-self-hosted/stage2.zig+8-7
......@@ -651,8 +651,9 @@ export fn stage2_target_parse(
651651 target: *Stage2Target,
652652 zig_triple: ?[*:0]const u8,
653653 mcpu: ?[*:0]const u8,
654 dynamic_linker: ?[*:0]const u8,
654655) Error {
655 stage2TargetParse(target, zig_triple, mcpu) catch |err| switch (err) {
656 stage2TargetParse(target, zig_triple, mcpu, dynamic_linker) catch |err| switch (err) {
656657 error.OutOfMemory => return .OutOfMemory,
657658 error.UnknownArchitecture => return .UnknownArchitecture,
658659 error.UnknownOperatingSystem => return .UnknownOperatingSystem,
......@@ -676,14 +677,17 @@ fn stage2TargetParse(
676677 stage1_target: *Stage2Target,
677678 zig_triple_oz: ?[*:0]const u8,
678679 mcpu_oz: ?[*:0]const u8,
680 dynamic_linker_oz: ?[*:0]const u8,
679681) !void {
680682 const target: CrossTarget = if (zig_triple_oz) |zig_triple_z| blk: {
681683 const zig_triple = mem.toSliceConst(u8, zig_triple_z);
682684 const mcpu = if (mcpu_oz) |mcpu_z| mem.toSliceConst(u8, mcpu_z) else null;
685 const dynamic_linker = if (dynamic_linker_oz) |dl_z| mem.toSliceConst(u8, dl_z) else null;
683686 var diags: CrossTarget.ParseOptions.Diagnostics = .{};
684687 break :blk CrossTarget.parse(.{
685688 .arch_os_abi = zig_triple,
686689 .cpu_features = mcpu,
690 .dynamic_linker = dynamic_linker,
687691 .diagnostics = &diags,
688692 }) catch |err| switch (err) {
689693 error.UnknownCpuModel => {
......@@ -1170,7 +1174,7 @@ fn crossTargetToTarget(cross_target: CrossTarget, dynamic_linker_ptr: *?[*:0]u8)
11701174 if (cross_target.os_tag == null) {
11711175 adjusted_target.os = detected_info.target.os;
11721176
1173 if (detected_info.dynamicLinker()) |dl| {
1177 if (detected_info.dynamic_linker.get()) |dl| {
11741178 have_native_dl = true;
11751179 dynamic_linker_ptr.* = try mem.dupeZ(std.heap.c_allocator, u8, dl);
11761180 }
......@@ -1182,11 +1186,8 @@ fn crossTargetToTarget(cross_target: CrossTarget, dynamic_linker_ptr: *?[*:0]u8)
11821186 }
11831187 }
11841188 if (!have_native_dl) {
1185 var buf: [255]u8 = undefined;
1186 dynamic_linker_ptr.* = if (adjusted_target.standardDynamicLinkerPath(&buf)) |m|
1187 try mem.dupeZ(std.heap.c_allocator, u8, buf[0 .. @as(usize, m) + 1])
1188 else
1189 null;
1189 const dl = adjusted_target.standardDynamicLinkerPath();
1190 dynamic_linker_ptr.* = if (dl.get()) |s| try mem.dupeZ(std.heap.c_allocator, u8, s) else null;
11901191 }
11911192 return adjusted_target;
11921193}
src/all_types.hpp-1
......@@ -2255,7 +2255,6 @@ struct CodeGen {
22552255 Buf *test_name_prefix;
22562256 Buf *zig_lib_dir;
22572257 Buf *zig_std_dir;
2258 Buf *dynamic_linker_path;
22592258 Buf *version_script_path;
22602259
22612260 const char **llvm_argv;
src/codegen.cpp+3-16
......@@ -8832,19 +8832,6 @@ static void init(CodeGen *g) {
88328832 }
88338833}
88348834
8835static void detect_dynamic_linker(CodeGen *g) {
8836 if (g->dynamic_linker_path != nullptr)
8837 return;
8838 if (!g->have_dynamic_link)
8839 return;
8840 if (g->out_type == OutTypeObj || (g->out_type == OutTypeLib && !g->is_dynamic))
8841 return;
8842
8843 if (g->zig_target->dynamic_linker != nullptr) {
8844 g->dynamic_linker_path = buf_create_from_str(g->zig_target->dynamic_linker);
8845 }
8846}
8847
88488835static void detect_libc(CodeGen *g) {
88498836 Error err;
88508837
......@@ -10285,6 +10272,9 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
1028510272 cache_int(ch, g->zig_target->glibc_or_darwin_version->minor);
1028610273 cache_int(ch, g->zig_target->glibc_or_darwin_version->patch);
1028710274 }
10275 if (g->zig_target->dynamic_linker != nullptr) {
10276 cache_str(ch, g->zig_target->dynamic_linker);
10277 }
1028810278 cache_int(ch, detect_subsystem(g));
1028910279 cache_bool(ch, g->strip_debug_symbols);
1029010280 cache_bool(ch, g->is_test_build);
......@@ -10325,7 +10315,6 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
1032510315 cache_str(ch, g->libc->msvc_lib_dir);
1032610316 cache_str(ch, g->libc->kernel32_lib_dir);
1032710317 }
10328 cache_buf_opt(ch, g->dynamic_linker_path);
1032910318 cache_buf_opt(ch, g->version_script_path);
1033010319
1033110320 // gen_c_objects appends objects to g->link_objects which we want to include in the hash
......@@ -10422,7 +10411,6 @@ void codegen_build_and_link(CodeGen *g) {
1042210411 g->have_err_ret_tracing = detect_err_ret_tracing(g);
1042310412 g->have_sanitize_c = detect_sanitize_c(g);
1042410413 detect_libc(g);
10425 detect_dynamic_linker(g);
1042610414
1042710415 Buf digest = BUF_INIT;
1042810416 if (g->enable_cache) {
......@@ -10619,7 +10607,6 @@ CodeGen *create_child_codegen(CodeGen *parent_gen, Buf *root_src_path, OutType o
1061910607 child_gen->verbose_cc = parent_gen->verbose_cc;
1062010608 child_gen->verbose_llvm_cpu_features = parent_gen->verbose_llvm_cpu_features;
1062110609 child_gen->llvm_argv = parent_gen->llvm_argv;
10622 child_gen->dynamic_linker_path = parent_gen->dynamic_linker_path;
1062310610
1062410611 codegen_set_strip(child_gen, parent_gen->strip_debug_symbols);
1062510612 child_gen->want_pic = parent_gen->have_pic ? WantPICEnabled : WantPICDisabled;
src/link.cpp+2-2
......@@ -1751,9 +1751,9 @@ static void construct_linker_job_elf(LinkJob *lj) {
17511751 }
17521752
17531753 if (g->have_dynamic_link && (is_dyn_lib || g->out_type == OutTypeExe)) {
1754 assert(g->dynamic_linker_path != nullptr);
1754 assert(g->zig_target->dynamic_linker != nullptr);
17551755 lj->args.append("-dynamic-linker");
1756 lj->args.append(buf_ptr(g->dynamic_linker_path));
1756 lj->args.append(g->zig_target->dynamic_linker);
17571757 }
17581758 }
17591759
src/main.cpp+5-6
......@@ -401,7 +401,7 @@ static int main0(int argc, char **argv) {
401401 bool link_eh_frame_hdr = false;
402402 ErrColor color = ErrColorAuto;
403403 CacheOpt enable_cache = CacheOptAuto;
404 Buf *dynamic_linker = nullptr;
404 const char *dynamic_linker = nullptr;
405405 const char *libc_txt = nullptr;
406406 ZigList<const char *> clang_argv = {0};
407407 ZigList<const char *> lib_dirs = {0};
......@@ -496,7 +496,7 @@ static int main0(int argc, char **argv) {
496496 os_path_join(get_zig_special_dir(zig_lib_dir), buf_create_from_str("build_runner.zig"), build_runner_path);
497497
498498 ZigTarget target;
499 if ((err = target_parse_triple(&target, "native", nullptr))) {
499 if ((err = target_parse_triple(&target, "native", nullptr, nullptr))) {
500500 fprintf(stderr, "Unable to get native target: %s\n", err_str(err));
501501 return EXIT_FAILURE;
502502 }
......@@ -766,7 +766,7 @@ static int main0(int argc, char **argv) {
766766 } else if (strcmp(arg, "--name") == 0) {
767767 out_name = argv[i];
768768 } else if (strcmp(arg, "--dynamic-linker") == 0) {
769 dynamic_linker = buf_create_from_str(argv[i]);
769 dynamic_linker = argv[i];
770770 } else if (strcmp(arg, "--libc") == 0) {
771771 libc_txt = argv[i];
772772 } else if (strcmp(arg, "-D") == 0) {
......@@ -968,7 +968,7 @@ static int main0(int argc, char **argv) {
968968 init_all_targets();
969969
970970 ZigTarget target;
971 if ((err = target_parse_triple(&target, target_string, mcpu))) {
971 if ((err = target_parse_triple(&target, target_string, mcpu, dynamic_linker))) {
972972 fprintf(stderr, "invalid target: %s\n"
973973 "See `%s targets` to display valid targets.\n", err_str(err), arg0);
974974 return print_error_usage(arg0);
......@@ -1193,7 +1193,6 @@ static int main0(int argc, char **argv) {
11931193
11941194 codegen_set_strip(g, strip);
11951195 g->is_dynamic = is_dynamic;
1196 g->dynamic_linker_path = dynamic_linker;
11971196 g->verbose_tokenize = verbose_tokenize;
11981197 g->verbose_ast = verbose_ast;
11991198 g->verbose_link = verbose_link;
......@@ -1320,7 +1319,7 @@ static int main0(int argc, char **argv) {
13201319 return main_exit(root_progress_node, EXIT_SUCCESS);
13211320 } else if (cmd == CmdTest) {
13221321 ZigTarget native;
1323 if ((err = target_parse_triple(&native, "native", nullptr))) {
1322 if ((err = target_parse_triple(&native, "native", nullptr, nullptr))) {
13241323 fprintf(stderr, "Unable to get native target: %s\n", err_str(err));
13251324 return EXIT_FAILURE;
13261325 }
src/stage2.cpp+6-1
......@@ -191,7 +191,9 @@ static void get_native_target(ZigTarget *target) {
191191 }
192192}
193193
194Error stage2_target_parse(struct ZigTarget *target, const char *zig_triple, const char *mcpu) {
194Error stage2_target_parse(struct ZigTarget *target, const char *zig_triple, const char *mcpu,
195 const char *dynamic_linker)
196{
195197 Error err;
196198
197199 if (zig_triple == nullptr) {
......@@ -249,6 +251,9 @@ Error stage2_target_parse(struct ZigTarget *target, const char *zig_triple, cons
249251 target->cache_hash = "\n\n";
250252 }
251253
254 if (dynamic_linker != nullptr) {
255 target->dynamic_linker = dynamic_linker;
256 }
252257 return ErrorNone;
253258}
254259
src/stage2.h+2-1
......@@ -298,7 +298,8 @@ struct ZigTarget {
298298};
299299
300300// ABI warning
301ZIG_EXTERN_C enum Error stage2_target_parse(struct ZigTarget *target, const char *zig_triple, const char *mcpu);
301ZIG_EXTERN_C enum Error stage2_target_parse(struct ZigTarget *target, const char *zig_triple, const char *mcpu,
302 const char *dynamic_linker);
302303
303304
304305// ABI warning
src/target.cpp+2-2
......@@ -410,8 +410,8 @@ Error target_parse_abi(ZigLLVM_EnvironmentType *out_abi, const char *abi_ptr, si
410410 return ErrorUnknownABI;
411411}
412412
413Error target_parse_triple(ZigTarget *target, const char *triple, const char *mcpu) {
414 return stage2_target_parse(target, triple, mcpu);
413Error target_parse_triple(ZigTarget *target, const char *triple, const char *mcpu, const char *dynamic_linker) {
414 return stage2_target_parse(target, triple, mcpu, dynamic_linker);
415415}
416416
417417const char *target_arch_name(ZigLLVM_ArchType arch) {
src/target.hpp+1-1
......@@ -41,7 +41,7 @@ enum CIntType {
4141 CIntTypeCount,
4242};
4343
44Error target_parse_triple(ZigTarget *target, const char *triple, const char *mcpu);
44Error target_parse_triple(ZigTarget *target, const char *triple, const char *mcpu, const char *dynamic_linker);
4545Error target_parse_arch(ZigLLVM_ArchType *arch, const char *arch_ptr, size_t arch_len);
4646Error target_parse_os(Os *os, const char *os_ptr, size_t os_len);
4747Error target_parse_abi(ZigLLVM_EnvironmentType *abi, const char *abi_ptr, size_t abi_len);