From ebbc50d8be3582cb67baa952ce7a52296a04a3c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Tue, 24 Sep 2024 09:23:24 +0200 Subject: [PATCH] std.Target: Introduce Abi.androideabi to distinguish the soft float case. Abi.android on its own is not enough to know whether soft float or hard float should be used. In the C world, androideabi is typically used for the soft float case, so let's go with that. Note that Android doesn't have a hard float ABI, so no androideabihf. Closes #21488. --- lib/compiler/aro/aro/Compilation.zig | 2 +- lib/compiler/aro/aro/target.zig | 1 + lib/compiler_rt/common.zig | 1 + lib/compiler_rt/emutls.zig | 2 +- lib/std/Target.zig | 15 +++++++++++++-- lib/std/Target/Query.zig | 2 +- lib/std/c.zig | 6 +++--- lib/std/zig/LibCDirs.zig | 1 + src/codegen/llvm.zig | 1 + src/target.zig | 25 +++++++++++-------------- 10 files changed, 34 insertions(+), 22 deletions(-) diff --git a/lib/compiler/aro/aro/Compilation.zig b/lib/compiler/aro/aro/Compilation.zig index 22ca9c00ed89e43b122fab471980909fae1f5234..414cdb45f00415fe8e0b1e96f2d63121114b1185 100644 --- a/lib/compiler/aro/aro/Compilation.zig +++ b/lib/compiler/aro/aro/Compilation.zig @@ -308,7 +308,7 @@ fn generateSystemDefines(comp: *Compilation, w: anytype) !void { ), else => {}, } - if (comp.target.abi == .android) { + if (comp.target.isAndroid()) { try w.writeAll("#define __ANDROID__ 1\n"); } diff --git a/lib/compiler/aro/aro/target.zig b/lib/compiler/aro/aro/target.zig index 5b05e5c9b6e24e3bddba1cf4e2698646eab535f7..b4b5bb896ad49e77191fc7a6d826748fa4f4575f 100644 --- a/lib/compiler/aro/aro/target.zig +++ b/lib/compiler/aro/aro/target.zig @@ -690,6 +690,7 @@ pub fn toLLVMTriple(target: std.Target, buf: []u8) []const u8 { .eabi => "eabi", .eabihf => "eabihf", .android => "android", + .androideabi => "androideabi", .musl => "musl", .musleabi => "musleabi", .musleabihf => "musleabihf", diff --git a/lib/compiler_rt/common.zig b/lib/compiler_rt/common.zig index a6fd9533790a1fa420fa0c7902d8728b05da5d66..c811ccc654409cfbbbd790f655fc02ca2f09276e 100644 --- a/lib/compiler_rt/common.zig +++ b/lib/compiler_rt/common.zig @@ -22,6 +22,7 @@ pub const want_aeabi = switch (builtin.abi) { .gnueabi, .gnueabihf, .android, + .androideabi, => switch (builtin.cpu.arch) { .arm, .armeb, .thumb, .thumbeb => true, else => false, diff --git a/lib/compiler_rt/emutls.zig b/lib/compiler_rt/emutls.zig index 55927b8b3791d637b4500f5aa32b8d3d786e97a9..b0244a14f551cca68d78b23c880b66b4df7add2b 100644 --- a/lib/compiler_rt/emutls.zig +++ b/lib/compiler_rt/emutls.zig @@ -18,7 +18,7 @@ const gcc_word = usize; pub const panic = common.panic; comptime { - if (builtin.link_libc and (builtin.abi == .android or builtin.os.tag == .openbsd)) { + if (builtin.link_libc and (builtin.abi.isAndroid() or builtin.os.tag == .openbsd)) { @export(&__emutls_get_address, .{ .name = "__emutls_get_address", .linkage = common.linkage, .visibility = common.visibility }); } } diff --git a/lib/std/Target.zig b/lib/std/Target.zig index 146af1cf9f0c63859c2abede7bdb9d1d7585c7e8..d1f2243f32b97402f5c51456f5686609d7c4fbb1 100644 --- a/lib/std/Target.zig +++ b/lib/std/Target.zig @@ -664,6 +664,7 @@ pub const Abi = enum { eabihf, ilp32, android, + androideabi, musl, musleabi, musleabihf, @@ -770,8 +771,16 @@ pub const Abi = enum { }; } + pub inline fn isAndroid(abi: Abi) bool { + return switch (abi) { + .android, .androideabi => true, + else => false, + }; + } + pub inline fn floatAbi(abi: Abi) FloatAbi { return switch (abi) { + .androideabi, .eabi, .gnueabi, .musleabi, @@ -1617,7 +1626,7 @@ pub inline fn isMusl(target: Target) bool { } pub inline fn isAndroid(target: Target) bool { - return target.abi == .android; + return target.abi.isAndroid(); } pub inline fn isWasm(target: Target) bool { @@ -1724,7 +1733,7 @@ pub const DynamicLinker = struct { } pub fn standard(cpu: Cpu, os_tag: Os.Tag, abi: Abi) DynamicLinker { - return if (abi == .android) initFmt("/system/bin/linker{s}", .{ + return if (abi.isAndroid()) initFmt("/system/bin/linker{s}", .{ if (ptrBitWidth_cpu_abi(cpu, abi) == 64) "64" else "", }) catch unreachable else if (abi.isMusl()) return initFmt("/lib/ld-musl-{s}{s}.so.1", .{ @tagName(switch (cpu.arch) { @@ -2391,6 +2400,7 @@ pub fn cTypeAlignment(target: Target, c_type: CType) u16 { .eabi, .eabihf, .android, + .androideabi, .musleabi, .musleabihf, => 8, @@ -2463,6 +2473,7 @@ pub fn cTypePreferredAlignment(target: Target, c_type: CType) u16 { .eabi, .eabihf, .android, + .androideabi, .musleabi, .musleabihf, => {}, diff --git a/lib/std/Target/Query.zig b/lib/std/Target/Query.zig index f18d211853bec59a384258ec50db8b70e77a0301..e22fbcbf53143f2d7fc9684eca4e80247349b002 100644 --- a/lib/std/Target/Query.zig +++ b/lib/std/Target/Query.zig @@ -374,7 +374,7 @@ pub fn canDetectLibC(self: Query) bool { if (self.isNativeOs()) return true; if (self.os_tag) |os| { if (builtin.os.tag == .macos and os.isDarwin()) return true; - if (os == .linux and self.abi == .android) return true; + if (os == .linux and self.abi.isAndroid()) return true; } return false; } diff --git a/lib/std/c.zig b/lib/std/c.zig index 12524667d27813fd14bb2313cab41078f49784be..c1523cd68a54973da1bbc0964252dee1330205d7 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -5946,7 +5946,7 @@ pub const PR = switch (native_os) { }; pub const _errno = switch (native_os) { .linux => switch (native_abi) { - .android => private.__errno, + .android, .androideabi => private.__errno, else => private.__errno_location, }, .emscripten => private.__errno_location, @@ -6754,7 +6754,7 @@ pub const pthread_mutex_t = switch (native_os) { .mips64, .powerpc64, .powerpc64le, .sparc64 => 40, else => if (@sizeOf(usize) == 8) 40 else 24, }, - .android => if (@sizeOf(usize) == 8) 40 else 4, + .android, .androideabi => if (@sizeOf(usize) == 8) 40 else 4, else => @compileError("unsupported ABI"), }; }, @@ -6848,7 +6848,7 @@ pub const pthread_cond_t = switch (native_os) { pub const pthread_rwlock_t = switch (native_os) { .linux => switch (native_abi) { - .android => switch (@sizeOf(usize)) { + .android, .androideabi => switch (@sizeOf(usize)) { 4 => extern struct { data: [40]u8 align(@alignOf(usize)) = [_]u8{0} ** 40, }, diff --git a/lib/std/zig/LibCDirs.zig b/lib/std/zig/LibCDirs.zig index c0f26ffa82513960fe2ef888399a4d87d689d72a..f425590a9bac535c967e28c457dcbd32518204b9 100644 --- a/lib/std/zig/LibCDirs.zig +++ b/lib/std/zig/LibCDirs.zig @@ -248,6 +248,7 @@ fn libCGenericName(target: std.Target) [:0]const u8 { .eabihf, .ilp32, .android, + .androideabi, .msvc, .itanium, .cygnus, diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 816975955a15bd12cb0443f76f67a42a63c97f5e..ac3d8bcf20f23926ec339e5d1b3e11a4487a9e7f 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -172,6 +172,7 @@ pub fn targetTriple(allocator: Allocator, target: std.Target) ![]const u8 { .eabi => "eabi", .eabihf => "eabihf", .android => "android", + .androideabi => "androideabi", .musl => "musl", .musleabi => "musleabi", .musleabihf => "musleabihf", diff --git a/src/target.zig b/src/target.zig index d85981ec8403dd1911338a04fca57f1a9ed8d52a..3b90c4f4133d5637e6deac79837239f41ebff5fb 100644 --- a/src/target.zig +++ b/src/target.zig @@ -304,20 +304,17 @@ pub fn libcFullLinkFlags(target: std.Target) []const []const u8 { "-lc", "-lnetwork", }, - else => switch (target.abi) { - .android => &[_][]const u8{ - "-lm", - "-lc", - "-ldl", - }, - else => &[_][]const u8{ - "-lm", - "-lpthread", - "-lc", - "-ldl", - "-lrt", - "-lutil", - }, + else => if (target.isAndroid()) &[_][]const u8{ + "-lm", + "-lc", + "-ldl", + } else &[_][]const u8{ + "-lm", + "-lpthread", + "-lc", + "-ldl", + "-lrt", + "-lutil", }, }; } -- 2.54.0