diff options
| author | Alex Rønne Petersen <alex@alexrp.com> | 2024-11-23 02:44:22 +0100 |
|---|---|---|
| committer | Alex Rønne Petersen <alex@alexrp.com> | 2024-11-23 03:10:58 +0100 |
| commit | 57e4fa14bb20a1f0006b14f3407ecdb20ab78120 (patch) | |
| tree | 7d859d90a652f58937c3e06dda346c9edc9c1396 /src | |
| parent | fc8a4c445d6f01ad0e0dab21129fa1594c55aae8 (diff) | |
| download | zig-57e4fa14bb20a1f0006b14f3407ecdb20ab78120.tar.gz zig-57e4fa14bb20a1f0006b14f3407ecdb20ab78120.zip | |
musl: Define TIME32 and FAMILY_* macros for libc.S as appropriate.
Also adjust ARCH_* logic for the updated gen_stubs.zig tool.
Diffstat (limited to 'src')
| -rw-r--r-- | src/musl.zig | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/src/musl.zig b/src/musl.zig index d1b2fd2e2d..ace72c0b07 100644 --- a/src/musl.zig +++ b/src/musl.zig @@ -138,17 +138,6 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro try addSrcFile(arena, &source_table, src_file); } - const time32_compat_arch_list = [_][]const u8{ - "arm", - "i386", - "m68k", - "microblaze", - "mips", - "mipsn32", - "or1k", - "powerpc", - "sh", - }; for (time32_compat_arch_list) |time32_compat_arch| { if (mem.eql(u8, arch_name, time32_compat_arch)) { for (compat_time32_files) |compat_time32_file| { @@ -239,13 +228,29 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro }); const target = comp.root_mod.resolved_target.result; - const arch_define = try std.fmt.allocPrint(arena, "-DARCH_{s}", .{ - @tagName(target.cpu.arch), - }); + const arch_name = std.zig.target.muslArchName(target.cpu.arch, target.abi); + const time32 = for (time32_compat_arch_list) |time32_compat_arch| { + if (mem.eql(u8, arch_name, time32_compat_arch)) break true; + } else false; + const arch_define = try std.fmt.allocPrint(arena, "-DARCH_{s}", .{arch_name}); + const family_define = switch (target.cpu.arch) { + .arm, .armeb, .thumb, .thumbeb => "-DFAMILY_arm", + .aarch64, .aarch64_be => "-DFAMILY_aarch64", + .loongarch64 => "-DFAMILY_loongarch", + .m68k => "-DFAMILY_m68k", + .mips, .mipsel, .mips64, .mips64el => "-DFAMILY_mips", + .powerpc, .powerpc64, .powerpc64le => "-DFAMILY_powerpc", + .riscv32, .riscv64 => "-DFAMILY_riscv", + .s390x => "-DFAMILY_s390x", + .x86, .x86_64 => "-DFAMILY_x86", + else => unreachable, + }; const cc_argv: []const []const u8 = if (target.ptrBitWidth() == 64) - &.{ "-DPTR64", arch_define } + &.{ "-DPTR64", arch_define, family_define } + else if (time32) + &.{ "-DTIME32", arch_define, family_define } else - &.{arch_define}; + &.{ arch_define, family_define }; const root_mod = try Module.create(arena, .{ .global_cache_directory = comp.global_cache_directory, @@ -347,6 +352,18 @@ pub fn needsCrt0(output_mode: std.builtin.OutputMode, link_mode: std.builtin.Lin }; } +const time32_compat_arch_list = [_][]const u8{ + "arm", + "i386", + "m68k", + "microblaze", + "mips", + "mipsn32", + "or1k", + "powerpc", + "sh", +}; + fn isArchName(name: []const u8) bool { const musl_arch_names = [_][]const u8{ "aarch64", |
