Skip to content

std.Target: Introduce Abi.androideabi to distinguish the soft float case. #21504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/compiler/aro/aro/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
1 change: 1 addition & 0 deletions lib/compiler/aro/aro/target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions lib/compiler_rt/common.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler_rt/emutls.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}
Expand Down
15 changes: 13 additions & 2 deletions lib/std/Target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ pub const Abi = enum {
eabihf,
ilp32,
android,
androideabi,
musl,
musleabi,
musleabihf,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -2391,6 +2400,7 @@ pub fn cTypeAlignment(target: Target, c_type: CType) u16 {
.eabi,
.eabihf,
.android,
.androideabi,
.musleabi,
.musleabihf,
=> 8,
Expand Down Expand Up @@ -2463,6 +2473,7 @@ pub fn cTypePreferredAlignment(target: Target, c_type: CType) u16 {
.eabi,
.eabihf,
.android,
.androideabi,
.musleabi,
.musleabihf,
=> {},
Expand Down
2 changes: 1 addition & 1 deletion lib/std/Target/Query.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/std/c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"),
};
},
Expand Down Expand Up @@ -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,
},
Expand Down
1 change: 1 addition & 0 deletions lib/std/zig/LibCDirs.zig
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ fn libCGenericName(target: std.Target) [:0]const u8 {
.eabihf,
.ilp32,
.android,
.androideabi,
.msvc,
.itanium,
.cygnus,
Expand Down
1 change: 1 addition & 0 deletions src/codegen/llvm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 11 additions & 14 deletions src/target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
};
}
Expand Down