From 84e192c88b2a970b249c7a7480e14717535b6096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sat, 5 Oct 2024 15:13:37 +0200 Subject: [PATCH 1/6] std.Target: Introduce Abi.ohoseabi to distinguish the soft float case. For the same reason as #21504. --- lib/compiler/aro/aro/target.zig | 3 ++- lib/std/Target.zig | 17 ++++++++++++++--- lib/std/zig/LibCDirs.zig | 1 + src/codegen/llvm.zig | 1 + src/target.zig | 2 +- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/compiler/aro/aro/target.zig b/lib/compiler/aro/aro/target.zig index 1799dac5da..c07935a420 100644 --- a/lib/compiler/aro/aro/target.zig +++ b/lib/compiler/aro/aro/target.zig @@ -699,7 +699,8 @@ pub fn toLLVMTriple(target: std.Target, buf: []u8) []const u8 { .cygnus => "cygnus", .simulator => "simulator", .macabi => "macabi", - .ohos => "openhos", + .ohos => "ohos", + .ohoseabi => "ohoseabi", }; writer.writeAll(llvm_abi) catch unreachable; return stream.getWritten(); diff --git a/lib/std/Target.zig b/lib/std/Target.zig index 223730073f..541e050ad6 100644 --- a/lib/std/Target.zig +++ b/lib/std/Target.zig @@ -677,6 +677,7 @@ pub const Abi = enum { simulator, macabi, ohos, + ohoseabi, // LLVM tags deliberately omitted: // - amplification @@ -766,8 +767,18 @@ pub const Abi = enum { pub inline fn isMusl(abi: Abi) bool { return switch (abi) { - .musl, .musleabi, .musleabihf, .muslx32 => true, - .ohos => true, + .musl, + .musleabi, + .musleabihf, + .muslx32, + => true, + else => abi.isOpenHarmony(), + }; + } + + pub inline fn isOpenHarmony(abi: Abi) bool { + return switch (abi) { + .ohos, .ohoseabi => true, else => false, }; } @@ -786,7 +797,7 @@ pub const Abi = enum { .gnueabi, .musleabi, .gnusf, - .ohos, + .ohoseabi, => .soft, else => .hard, }; diff --git a/lib/std/zig/LibCDirs.zig b/lib/std/zig/LibCDirs.zig index 2df5bd0932..8b8a3a8d42 100644 --- a/lib/std/zig/LibCDirs.zig +++ b/lib/std/zig/LibCDirs.zig @@ -242,6 +242,7 @@ fn libCGenericName(target: std.Target) [:0]const u8 { .muslx32, .none, .ohos, + .ohoseabi, => return "musl", .code16, .eabi, diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 927cedbb96..b91b13d95f 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -185,6 +185,7 @@ pub fn targetTriple(allocator: Allocator, target: std.Target) ![]const u8 { .simulator => "simulator", .macabi => "macabi", .ohos => "ohos", + .ohoseabi => "ohoseabi", }; try llvm_triple.appendSlice(llvm_abi); diff --git a/src/target.zig b/src/target.zig index 5847d3d8cd..2d7917c196 100644 --- a/src/target.zig +++ b/src/target.zig @@ -46,7 +46,7 @@ pub fn requiresPIC(target: std.Target, linking_libc: bool) bool { target.os.tag == .windows or target.os.tag == .uefi or osRequiresLibC(target) or (linking_libc and target.isGnuLibC()) or - (target.abi == .ohos and target.cpu.arch == .aarch64); + (target.cpu.arch == .aarch64 and target.abi == .ohos); } pub fn picLevel(target: std.Target) u32 { From 09efa95f48e977e99f3a3aeb3c3bf89598c73439 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sat, 5 Oct 2024 15:14:16 +0200 Subject: [PATCH 2/6] compiler: Don't link to nonexistent libc libraries for ohos. --- src/target.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/target.zig b/src/target.zig index 2d7917c196..25129a6224 100644 --- a/src/target.zig +++ b/src/target.zig @@ -306,7 +306,7 @@ pub fn libcFullLinkFlags(target: std.Target) []const []const u8 { "-lc", "-lnetwork", }, - else => if (target.isAndroid()) &[_][]const u8{ + else => if (target.isAndroid() or target.abi.isOpenHarmony()) &[_][]const u8{ "-lm", "-lc", "-ldl", From 25ee7b0ea8250510a983ec23dc14460385c44a5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sat, 5 Oct 2024 15:19:14 +0200 Subject: [PATCH 3/6] compiler: Don't require PIC for aarch64-linux-ohos. While Clang defaults to PIC for this target, it's not actually required. --- src/target.zig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/target.zig b/src/target.zig index 25129a6224..95c9798f65 100644 --- a/src/target.zig +++ b/src/target.zig @@ -45,8 +45,7 @@ pub fn requiresPIC(target: std.Target, linking_libc: bool) bool { return target.isAndroid() or target.os.tag == .windows or target.os.tag == .uefi or osRequiresLibC(target) or - (linking_libc and target.isGnuLibC()) or - (target.cpu.arch == .aarch64 and target.abi == .ohos); + (linking_libc and target.isGnuLibC()); } pub fn picLevel(target: std.Target) u32 { From e3e60491ba4b94a933d24a38e21759443d3dfd43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 6 Oct 2024 10:22:39 +0200 Subject: [PATCH 4/6] test: Add ohos/ohoseabi triples to llvm_targets. --- test/llvm_targets.zig | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/llvm_targets.zig b/test/llvm_targets.zig index e1661cfbd4..b2fde75450 100644 --- a/test/llvm_targets.zig +++ b/test/llvm_targets.zig @@ -16,6 +16,7 @@ const targets = [_]std.Target.Query{ .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .gnu }, .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .gnuilp32 }, .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .none }, + .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .ohos }, .{ .cpu_arch = .aarch64, .os_tag = .macos, .abi = .none }, .{ .cpu_arch = .aarch64, .os_tag = .netbsd, .abi = .none }, .{ .cpu_arch = .aarch64, .os_tag = .openbsd, .abi = .none }, @@ -60,6 +61,7 @@ const targets = [_]std.Target.Query{ .{ .cpu_arch = .arm, .os_tag = .linux, .abi = .gnueabihf }, .{ .cpu_arch = .arm, .os_tag = .linux, .abi = .musleabi }, .{ .cpu_arch = .arm, .os_tag = .linux, .abi = .musleabihf }, + .{ .cpu_arch = .arm, .os_tag = .linux, .abi = .ohoseabi }, .{ .cpu_arch = .arm, .os_tag = .netbsd, .abi = .eabi }, .{ .cpu_arch = .arm, .os_tag = .netbsd, .abi = .eabihf }, .{ .cpu_arch = .arm, .os_tag = .openbsd, .abi = .eabi }, @@ -223,6 +225,7 @@ const targets = [_]std.Target.Query{ .{ .cpu_arch = .riscv32, .os_tag = .linux, .abi = .gnu }, .{ .cpu_arch = .riscv32, .os_tag = .linux, .abi = .musl }, .{ .cpu_arch = .riscv32, .os_tag = .linux, .abi = .none }, + .{ .cpu_arch = .riscv32, .os_tag = .linux, .abi = .ohos }, .{ .cpu_arch = .riscv32, .os_tag = .rtems, .abi = .none }, .{ .cpu_arch = .riscv32, .os_tag = .uefi, .abi = .none }, @@ -234,6 +237,7 @@ const targets = [_]std.Target.Query{ .{ .cpu_arch = .riscv64, .os_tag = .linux, .abi = .gnu }, .{ .cpu_arch = .riscv64, .os_tag = .linux, .abi = .musl }, .{ .cpu_arch = .riscv64, .os_tag = .linux, .abi = .none }, + .{ .cpu_arch = .riscv64, .os_tag = .linux, .abi = .ohos }, .{ .cpu_arch = .riscv64, .os_tag = .netbsd, .abi = .none }, .{ .cpu_arch = .riscv64, .os_tag = .openbsd, .abi = .none }, .{ .cpu_arch = .riscv64, .os_tag = .rtems, .abi = .none }, @@ -314,6 +318,7 @@ const targets = [_]std.Target.Query{ .{ .cpu_arch = .x86, .os_tag = .linux, .abi = .gnu }, .{ .cpu_arch = .x86, .os_tag = .linux, .abi = .musl }, .{ .cpu_arch = .x86, .os_tag = .linux, .abi = .none }, + .{ .cpu_arch = .x86, .os_tag = .linux, .abi = .ohos }, .{ .cpu_arch = .x86, .os_tag = .netbsd, .abi = .none }, .{ .cpu_arch = .x86, .os_tag = .openbsd, .abi = .none }, .{ .cpu_arch = .x86, .os_tag = .rtems, .abi = .none }, @@ -341,6 +346,7 @@ const targets = [_]std.Target.Query{ .{ .cpu_arch = .x86_64, .os_tag = .ios, .abi = .macabi }, .{ .cpu_arch = .x86_64, .os_tag = .ios, .abi = .simulator }, .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .none }, + .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .ohos }, .{ .cpu_arch = .x86_64, .os_tag = .macos, .abi = .none }, .{ .cpu_arch = .x86_64, .os_tag = .netbsd, .abi = .none }, .{ .cpu_arch = .x86_64, .os_tag = .openbsd, .abi = .none }, From 5e9764c5122febf3ef0f3c43131b60e3b4b7843f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 6 Oct 2024 10:24:35 +0200 Subject: [PATCH 5/6] test: Add android/androideabi triples to llvm_targets. --- test/llvm_targets.zig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/llvm_targets.zig b/test/llvm_targets.zig index b2fde75450..9a2306b6a0 100644 --- a/test/llvm_targets.zig +++ b/test/llvm_targets.zig @@ -13,6 +13,7 @@ const targets = [_]std.Target.Query{ .{ .cpu_arch = .aarch64, .os_tag = .ios, .abi = .macabi }, .{ .cpu_arch = .aarch64, .os_tag = .ios, .abi = .none }, .{ .cpu_arch = .aarch64, .os_tag = .ios, .abi = .simulator }, + .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .android }, .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .gnu }, .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .gnuilp32 }, .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .none }, @@ -55,6 +56,7 @@ const targets = [_]std.Target.Query{ .{ .cpu_arch = .arm, .os_tag = .freestanding, .abi = .eabihf }, .{ .cpu_arch = .arm, .os_tag = .haiku, .abi = .eabi }, .{ .cpu_arch = .arm, .os_tag = .haiku, .abi = .eabihf }, + .{ .cpu_arch = .arm, .os_tag = .linux, .abi = .androideabi }, .{ .cpu_arch = .arm, .os_tag = .linux, .abi = .eabi }, .{ .cpu_arch = .arm, .os_tag = .linux, .abi = .eabihf }, .{ .cpu_arch = .arm, .os_tag = .linux, .abi = .gnueabi }, @@ -234,6 +236,7 @@ const targets = [_]std.Target.Query{ .{ .cpu_arch = .riscv64, .os_tag = .fuchsia, .abi = .none }, .{ .cpu_arch = .riscv64, .os_tag = .haiku, .abi = .none }, .{ .cpu_arch = .riscv64, .os_tag = .hermit, .abi = .none }, + .{ .cpu_arch = .riscv64, .os_tag = .linux, .abi = .android }, .{ .cpu_arch = .riscv64, .os_tag = .linux, .abi = .gnu }, .{ .cpu_arch = .riscv64, .os_tag = .linux, .abi = .musl }, .{ .cpu_arch = .riscv64, .os_tag = .linux, .abi = .none }, @@ -315,6 +318,7 @@ const targets = [_]std.Target.Query{ .{ .cpu_arch = .x86, .os_tag = .freestanding, .abi = .none }, .{ .cpu_arch = .x86, .os_tag = .haiku, .abi = .none }, .{ .cpu_arch = .x86, .os_tag = .hurd, .abi = .gnu }, + .{ .cpu_arch = .x86, .os_tag = .linux, .abi = .android }, .{ .cpu_arch = .x86, .os_tag = .linux, .abi = .gnu }, .{ .cpu_arch = .x86, .os_tag = .linux, .abi = .musl }, .{ .cpu_arch = .x86, .os_tag = .linux, .abi = .none }, @@ -345,6 +349,7 @@ const targets = [_]std.Target.Query{ .{ .cpu_arch = .x86_64, .os_tag = .illumos, .abi = .none }, .{ .cpu_arch = .x86_64, .os_tag = .ios, .abi = .macabi }, .{ .cpu_arch = .x86_64, .os_tag = .ios, .abi = .simulator }, + .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .android }, .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .none }, .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .ohos }, .{ .cpu_arch = .x86_64, .os_tag = .macos, .abi = .none }, From 19924280446ca02bb680357ad976857a087e91d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 6 Oct 2024 10:26:00 +0200 Subject: [PATCH 6/6] test: Add some missing x86_64-linux-* triples to llvm_targets. --- test/llvm_targets.zig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/llvm_targets.zig b/test/llvm_targets.zig index 9a2306b6a0..06aabeaeb8 100644 --- a/test/llvm_targets.zig +++ b/test/llvm_targets.zig @@ -350,6 +350,10 @@ const targets = [_]std.Target.Query{ .{ .cpu_arch = .x86_64, .os_tag = .ios, .abi = .macabi }, .{ .cpu_arch = .x86_64, .os_tag = .ios, .abi = .simulator }, .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .android }, + .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .gnu }, + .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .gnux32 }, + .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .musl }, + .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .muslx32 }, .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .none }, .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .ohos }, .{ .cpu_arch = .x86_64, .os_tag = .macos, .abi = .none },