authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-09-24 09:23:24+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-09-24 09:23:24+02:00
logebbc50d8be3582cb67baa952ce7a52296a04a3c1
treefd3a12c330d762a9ac72eedb7fad276d33e2bc75
parentd3ba5f397d3270047bcf05c7ed21c5bd6b97e75b
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

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.

10 files changed, 34 insertions(+), 22 deletions(-)

lib/compiler/aro/aro/Compilation.zig+1-1
...@@ -308,7 +308,7 @@ fn generateSystemDefines(comp: *Compilation, w: anytype) !void {...@@ -308,7 +308,7 @@ fn generateSystemDefines(comp: *Compilation, w: anytype) !void {
308 ),308 ),
309 else => {},309 else => {},
310 }310 }
311 if (comp.target.abi == .android) {311 if (comp.target.isAndroid()) {
312 try w.writeAll("#define __ANDROID__ 1\n");312 try w.writeAll("#define __ANDROID__ 1\n");
313 }313 }
314314
lib/compiler/aro/aro/target.zig+1
...@@ -690,6 +690,7 @@ pub fn toLLVMTriple(target: std.Target, buf: []u8) []const u8 {...@@ -690,6 +690,7 @@ pub fn toLLVMTriple(target: std.Target, buf: []u8) []const u8 {
690 .eabi => "eabi",690 .eabi => "eabi",
691 .eabihf => "eabihf",691 .eabihf => "eabihf",
692 .android => "android",692 .android => "android",
693 .androideabi => "androideabi",
693 .musl => "musl",694 .musl => "musl",
694 .musleabi => "musleabi",695 .musleabi => "musleabi",
695 .musleabihf => "musleabihf",696 .musleabihf => "musleabihf",
lib/compiler_rt/common.zig+1
...@@ -22,6 +22,7 @@ pub const want_aeabi = switch (builtin.abi) {...@@ -22,6 +22,7 @@ pub const want_aeabi = switch (builtin.abi) {
22 .gnueabi,22 .gnueabi,
23 .gnueabihf,23 .gnueabihf,
24 .android,24 .android,
25 .androideabi,
25 => switch (builtin.cpu.arch) {26 => switch (builtin.cpu.arch) {
26 .arm, .armeb, .thumb, .thumbeb => true,27 .arm, .armeb, .thumb, .thumbeb => true,
27 else => false,28 else => false,
lib/compiler_rt/emutls.zig+1-1
...@@ -18,7 +18,7 @@ const gcc_word = usize;...@@ -18,7 +18,7 @@ const gcc_word = usize;
18pub const panic = common.panic;18pub const panic = common.panic;
1919
20comptime {20comptime {
21 if (builtin.link_libc and (builtin.abi == .android or builtin.os.tag == .openbsd)) {21 if (builtin.link_libc and (builtin.abi.isAndroid() or builtin.os.tag == .openbsd)) {
22 @export(&__emutls_get_address, .{ .name = "__emutls_get_address", .linkage = common.linkage, .visibility = common.visibility });22 @export(&__emutls_get_address, .{ .name = "__emutls_get_address", .linkage = common.linkage, .visibility = common.visibility });
23 }23 }
24}24}
lib/std/Target.zig+13-2
...@@ -664,6 +664,7 @@ pub const Abi = enum {...@@ -664,6 +664,7 @@ pub const Abi = enum {
664 eabihf,664 eabihf,
665 ilp32,665 ilp32,
666 android,666 android,
667 androideabi,
667 musl,668 musl,
668 musleabi,669 musleabi,
669 musleabihf,670 musleabihf,
...@@ -770,8 +771,16 @@ pub const Abi = enum {...@@ -770,8 +771,16 @@ pub const Abi = enum {
770 };771 };
771 }772 }
772773
774 pub inline fn isAndroid(abi: Abi) bool {
775 return switch (abi) {
776 .android, .androideabi => true,
777 else => false,
778 };
779 }
780
773 pub inline fn floatAbi(abi: Abi) FloatAbi {781 pub inline fn floatAbi(abi: Abi) FloatAbi {
774 return switch (abi) {782 return switch (abi) {
783 .androideabi,
775 .eabi,784 .eabi,
776 .gnueabi,785 .gnueabi,
777 .musleabi,786 .musleabi,
...@@ -1617,7 +1626,7 @@ pub inline fn isMusl(target: Target) bool {...@@ -1617,7 +1626,7 @@ pub inline fn isMusl(target: Target) bool {
1617}1626}
16181627
1619pub inline fn isAndroid(target: Target) bool {1628pub inline fn isAndroid(target: Target) bool {
1620 return target.abi == .android;1629 return target.abi.isAndroid();
1621}1630}
16221631
1623pub inline fn isWasm(target: Target) bool {1632pub inline fn isWasm(target: Target) bool {
...@@ -1724,7 +1733,7 @@ pub const DynamicLinker = struct {...@@ -1724,7 +1733,7 @@ pub const DynamicLinker = struct {
1724 }1733 }
17251734
1726 pub fn standard(cpu: Cpu, os_tag: Os.Tag, abi: Abi) DynamicLinker {1735 pub fn standard(cpu: Cpu, os_tag: Os.Tag, abi: Abi) DynamicLinker {
1727 return if (abi == .android) initFmt("/system/bin/linker{s}", .{1736 return if (abi.isAndroid()) initFmt("/system/bin/linker{s}", .{
1728 if (ptrBitWidth_cpu_abi(cpu, abi) == 64) "64" else "",1737 if (ptrBitWidth_cpu_abi(cpu, abi) == 64) "64" else "",
1729 }) catch unreachable else if (abi.isMusl()) return initFmt("/lib/ld-musl-{s}{s}.so.1", .{1738 }) catch unreachable else if (abi.isMusl()) return initFmt("/lib/ld-musl-{s}{s}.so.1", .{
1730 @tagName(switch (cpu.arch) {1739 @tagName(switch (cpu.arch) {
...@@ -2391,6 +2400,7 @@ pub fn cTypeAlignment(target: Target, c_type: CType) u16 {...@@ -2391,6 +2400,7 @@ pub fn cTypeAlignment(target: Target, c_type: CType) u16 {
2391 .eabi,2400 .eabi,
2392 .eabihf,2401 .eabihf,
2393 .android,2402 .android,
2403 .androideabi,
2394 .musleabi,2404 .musleabi,
2395 .musleabihf,2405 .musleabihf,
2396 => 8,2406 => 8,
...@@ -2463,6 +2473,7 @@ pub fn cTypePreferredAlignment(target: Target, c_type: CType) u16 {...@@ -2463,6 +2473,7 @@ pub fn cTypePreferredAlignment(target: Target, c_type: CType) u16 {
2463 .eabi,2473 .eabi,
2464 .eabihf,2474 .eabihf,
2465 .android,2475 .android,
2476 .androideabi,
2466 .musleabi,2477 .musleabi,
2467 .musleabihf,2478 .musleabihf,
2468 => {},2479 => {},
lib/std/Target/Query.zig+1-1
...@@ -374,7 +374,7 @@ pub fn canDetectLibC(self: Query) bool {...@@ -374,7 +374,7 @@ pub fn canDetectLibC(self: Query) bool {
374 if (self.isNativeOs()) return true;374 if (self.isNativeOs()) return true;
375 if (self.os_tag) |os| {375 if (self.os_tag) |os| {
376 if (builtin.os.tag == .macos and os.isDarwin()) return true;376 if (builtin.os.tag == .macos and os.isDarwin()) return true;
377 if (os == .linux and self.abi == .android) return true;377 if (os == .linux and self.abi.isAndroid()) return true;
378 }378 }
379 return false;379 return false;
380}380}
lib/std/c.zig+3-3
...@@ -5946,7 +5946,7 @@ pub const PR = switch (native_os) {...@@ -5946,7 +5946,7 @@ pub const PR = switch (native_os) {
5946};5946};
5947pub const _errno = switch (native_os) {5947pub const _errno = switch (native_os) {
5948 .linux => switch (native_abi) {5948 .linux => switch (native_abi) {
5949 .android => private.__errno,5949 .android, .androideabi => private.__errno,
5950 else => private.__errno_location,5950 else => private.__errno_location,
5951 },5951 },
5952 .emscripten => private.__errno_location,5952 .emscripten => private.__errno_location,
...@@ -6754,7 +6754,7 @@ pub const pthread_mutex_t = switch (native_os) {...@@ -6754,7 +6754,7 @@ pub const pthread_mutex_t = switch (native_os) {
6754 .mips64, .powerpc64, .powerpc64le, .sparc64 => 40,6754 .mips64, .powerpc64, .powerpc64le, .sparc64 => 40,
6755 else => if (@sizeOf(usize) == 8) 40 else 24,6755 else => if (@sizeOf(usize) == 8) 40 else 24,
6756 },6756 },
6757 .android => if (@sizeOf(usize) == 8) 40 else 4,6757 .android, .androideabi => if (@sizeOf(usize) == 8) 40 else 4,
6758 else => @compileError("unsupported ABI"),6758 else => @compileError("unsupported ABI"),
6759 };6759 };
6760 },6760 },
...@@ -6848,7 +6848,7 @@ pub const pthread_cond_t = switch (native_os) {...@@ -6848,7 +6848,7 @@ pub const pthread_cond_t = switch (native_os) {
68486848
6849pub const pthread_rwlock_t = switch (native_os) {6849pub const pthread_rwlock_t = switch (native_os) {
6850 .linux => switch (native_abi) {6850 .linux => switch (native_abi) {
6851 .android => switch (@sizeOf(usize)) {6851 .android, .androideabi => switch (@sizeOf(usize)) {
6852 4 => extern struct {6852 4 => extern struct {
6853 data: [40]u8 align(@alignOf(usize)) = [_]u8{0} ** 40,6853 data: [40]u8 align(@alignOf(usize)) = [_]u8{0} ** 40,
6854 },6854 },
lib/std/zig/LibCDirs.zig+1
...@@ -248,6 +248,7 @@ fn libCGenericName(target: std.Target) [:0]const u8 {...@@ -248,6 +248,7 @@ fn libCGenericName(target: std.Target) [:0]const u8 {
248 .eabihf,248 .eabihf,
249 .ilp32,249 .ilp32,
250 .android,250 .android,
251 .androideabi,
251 .msvc,252 .msvc,
252 .itanium,253 .itanium,
253 .cygnus,254 .cygnus,
src/codegen/llvm.zig+1
...@@ -172,6 +172,7 @@ pub fn targetTriple(allocator: Allocator, target: std.Target) ![]const u8 {...@@ -172,6 +172,7 @@ pub fn targetTriple(allocator: Allocator, target: std.Target) ![]const u8 {
172 .eabi => "eabi",172 .eabi => "eabi",
173 .eabihf => "eabihf",173 .eabihf => "eabihf",
174 .android => "android",174 .android => "android",
175 .androideabi => "androideabi",
175 .musl => "musl",176 .musl => "musl",
176 .musleabi => "musleabi",177 .musleabi => "musleabi",
177 .musleabihf => "musleabihf",178 .musleabihf => "musleabihf",
src/target.zig+11-14
...@@ -304,20 +304,17 @@ pub fn libcFullLinkFlags(target: std.Target) []const []const u8 {...@@ -304,20 +304,17 @@ pub fn libcFullLinkFlags(target: std.Target) []const []const u8 {
304 "-lc",304 "-lc",
305 "-lnetwork",305 "-lnetwork",
306 },306 },
307 else => switch (target.abi) {307 else => if (target.isAndroid()) &[_][]const u8{
308 .android => &[_][]const u8{308 "-lm",
309 "-lm",309 "-lc",
310 "-lc",310 "-ldl",
311 "-ldl",311 } else &[_][]const u8{
312 },312 "-lm",
313 else => &[_][]const u8{313 "-lpthread",
314 "-lm",314 "-lc",
315 "-lpthread",315 "-ldl",
316 "-lc",316 "-lrt",
317 "-ldl",317 "-lutil",
318 "-lrt",
319 "-lutil",
320 },
321 },318 },
322 };319 };
323}320}