| author | |
| committer | |
| log | d91e75f5cacebd80f574993160839f8af21a5984 |
| tree | 3ee85f0691a0f53e3be75b2ac05306bc198396f7 |
| parent | 0e1afee732c1007280b8afdab51aef3ceb860432 |
* std.Target.standardDynamicLinkerPath: macOS has a dynamic linker
* no need to override the default dynamic linker in the macos
CrossTarget initialization in the tests
* in getExternalExecutor, when validating the dynamic linker path, take
into account the standard dynamic linker path.3 files changed, 29 insertions(+), 21 deletions(-)
lib/std/target.zig+20-14| ... | ... | @@ -483,6 +483,16 @@ pub const Target = struct { |
| 483 | 483 | else => false, |
| 484 | 484 | }; |
| 485 | 485 | } |
| 486 | ||
| 487 | pub fn floatAbi(abi: Abi) FloatAbi { | |
| 488 | return switch (abi) { | |
| 489 | .gnueabihf, | |
| 490 | .eabihf, | |
| 491 | .musleabihf, | |
| 492 | => .hard, | |
| 493 | else => .soft, | |
| 494 | }; | |
| 495 | } | |
| 486 | 496 | }; |
| 487 | 497 | |
| 488 | 498 | pub const ObjectFormat = enum { |
| ... | ... | @@ -1259,13 +1269,7 @@ pub const Target = struct { |
| 1259 | 1269 | }; |
| 1260 | 1270 | |
| 1261 | 1271 | pub fn getFloatAbi(self: Target) FloatAbi { |
| 1262 | return switch (self.abi) { | |
| 1263 | .gnueabihf, | |
| 1264 | .eabihf, | |
| 1265 | .musleabihf, | |
| 1266 | => .hard, | |
| 1267 | else => .soft, | |
| 1268 | }; | |
| 1272 | return self.abi.floatAbi(); | |
| 1269 | 1273 | } |
| 1270 | 1274 | |
| 1271 | 1275 | pub fn hasDynamicLinker(self: Target) bool { |
| ... | ... | @@ -1336,12 +1340,12 @@ pub const Target = struct { |
| 1336 | 1340 | const print = S.print; |
| 1337 | 1341 | const copy = S.copy; |
| 1338 | 1342 | |
| 1339 | if (self.isAndroid()) { | |
| 1343 | if (self.abi == .android) { | |
| 1340 | 1344 | const suffix = if (self.cpu.arch.ptrBitWidth() == 64) "64" else ""; |
| 1341 | 1345 | return print(&result, "/system/bin/linker{}", .{suffix}); |
| 1342 | 1346 | } |
| 1343 | 1347 | |
| 1344 | if (self.isMusl()) { | |
| 1348 | if (self.abi.isMusl()) { | |
| 1345 | 1349 | const is_arm = switch (self.cpu.arch) { |
| 1346 | 1350 | .arm, .armeb, .thumb, .thumbeb => true, |
| 1347 | 1351 | else => false, |
| ... | ... | @@ -1351,7 +1355,7 @@ pub const Target = struct { |
| 1351 | 1355 | .armeb, .thumbeb => "armeb", |
| 1352 | 1356 | else => |arch| @tagName(arch), |
| 1353 | 1357 | }; |
| 1354 | const arch_suffix = if (is_arm and self.getFloatAbi() == .hard) "hf" else ""; | |
| 1358 | const arch_suffix = if (is_arm and self.abi.floatAbi() == .hard) "hf" else ""; | |
| 1355 | 1359 | return print(&result, "/lib/ld-musl-{}{}.so.1", .{ arch_part, arch_suffix }); |
| 1356 | 1360 | } |
| 1357 | 1361 | |
| ... | ... | @@ -1373,7 +1377,7 @@ pub const Target = struct { |
| 1373 | 1377 | .armeb, |
| 1374 | 1378 | .thumb, |
| 1375 | 1379 | .thumbeb, |
| 1376 | => return copy(&result, switch (self.getFloatAbi()) { | |
| 1380 | => return copy(&result, switch (self.abi.floatAbi()) { | |
| 1377 | 1381 | .hard => "/lib/ld-linux-armhf.so.3", |
| 1378 | 1382 | else => "/lib/ld-linux.so.3", |
| 1379 | 1383 | }), |
| ... | ... | @@ -1444,13 +1448,15 @@ pub const Target = struct { |
| 1444 | 1448 | => return result, |
| 1445 | 1449 | }, |
| 1446 | 1450 | |
| 1447 | // Operating systems in this list have been verified as not having a standard | |
| 1448 | // dynamic linker path. | |
| 1449 | .freestanding, | |
| 1450 | 1451 | .ios, |
| 1451 | 1452 | .tvos, |
| 1452 | 1453 | .watchos, |
| 1453 | 1454 | .macos, |
| 1455 | => return copy(&result, "/usr/lib/dyld"), | |
| 1456 | ||
| 1457 | // Operating systems in this list have been verified as not having a standard | |
| 1458 | // dynamic linker path. | |
| 1459 | .freestanding, | |
| 1454 | 1460 | .uefi, |
| 1455 | 1461 | .windows, |
| 1456 | 1462 | .emscripten, |
lib/std/zig/cross_target.zig+7-4| ... | ... | @@ -606,15 +606,18 @@ pub const CrossTarget = struct { |
| 606 | 606 | const os_match = os_tag == Target.current.os.tag; |
| 607 | 607 | |
| 608 | 608 | // If the OS and CPU arch match, the binary can be considered native. |
| 609 | // TODO additionally match the CPU features. This `getExternalExecutor` function should | |
| 610 | // be moved to std.Target and match any chosen target against the native target. | |
| 609 | 611 | if (os_match and cpu_arch == Target.current.cpu.arch) { |
| 610 | 612 | // However, we also need to verify that the dynamic linker path is valid. |
| 611 | 613 | if (self.os_tag == null) { |
| 612 | 614 | return .native; |
| 613 | 615 | } |
| 614 | if (self.dynamic_linker.max_byte) |len| blk: { | |
| 615 | std.fs.cwd().access(self.dynamic_linker.buffer[0..len + 1], .{}) catch { | |
| 616 | break :blk; | |
| 617 | }; | |
| 616 | // TODO here we call toTarget, a deprecated function, because of the above TODO about moving | |
| 617 | // this code to std.Target. | |
| 618 | const opt_dl = self.dynamic_linker.get() orelse self.toTarget().standardDynamicLinkerPath().get(); | |
| 619 | if (opt_dl) |dl| blk: { | |
| 620 | std.fs.cwd().access(dl, .{}) catch break :blk; | |
| 618 | 621 | return .native; |
| 619 | 622 | } |
| 620 | 623 | } |
test/stage2/test.zig+2-3| ... | ... | @@ -14,7 +14,6 @@ const linux_x64 = std.zig.CrossTarget{ |
| 14 | 14 | const macosx_x64 = std.zig.CrossTarget{ |
| 15 | 15 | .cpu_arch = .x86_64, |
| 16 | 16 | .os_tag = .macos, |
| 17 | .dynamic_linker = std.zig.CrossTarget.DynamicLinker.init("/usr/lib/dyld"), | |
| 18 | 17 | }; |
| 19 | 18 | |
| 20 | 19 | const linux_riscv64 = std.zig.CrossTarget{ |
| ... | ... | @@ -184,7 +183,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 184 | 183 | \\ ); |
| 185 | 184 | \\ unreachable; |
| 186 | 185 | \\} |
| 187 | , | |
| 186 | , | |
| 188 | 187 | "Hello, World!\n", |
| 189 | 188 | ); |
| 190 | 189 | // Now change the message only |
| ... | ... | @@ -994,7 +993,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 994 | 993 | \\ ); |
| 995 | 994 | \\ unreachable; |
| 996 | 995 | \\} |
| 997 | , | |
| 996 | , | |
| 998 | 997 | "Hello, World!\n", |
| 999 | 998 | ); |
| 1000 | 999 | try case.files.append(.{ |