authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-11-23 02:44:22+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-11-23 03:10:58+01:00
log57e4fa14bb20a1f0006b14f3407ecdb20ab78120
tree7d859d90a652f58937c3e06dda346c9edc9c1396
parentfc8a4c445d6f01ad0e0dab21129fa1594c55aae8
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

musl: Define TIME32 and FAMILY_* macros for libc.S as appropriate.

Also adjust ARCH_* logic for the updated gen_stubs.zig tool.

1 files changed, 33 insertions(+), 16 deletions(-)

src/musl.zig+33-16
......@@ -138,17 +138,6 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
138138 try addSrcFile(arena, &source_table, src_file);
139139 }
140140
141 const time32_compat_arch_list = [_][]const u8{
142 "arm",
143 "i386",
144 "m68k",
145 "microblaze",
146 "mips",
147 "mipsn32",
148 "or1k",
149 "powerpc",
150 "sh",
151 };
152141 for (time32_compat_arch_list) |time32_compat_arch| {
153142 if (mem.eql(u8, arch_name, time32_compat_arch)) {
154143 for (compat_time32_files) |compat_time32_file| {
......@@ -239,13 +228,29 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
239228 });
240229
241230 const target = comp.root_mod.resolved_target.result;
242 const arch_define = try std.fmt.allocPrint(arena, "-DARCH_{s}", .{
243 @tagName(target.cpu.arch),
244 });
231 const arch_name = std.zig.target.muslArchName(target.cpu.arch, target.abi);
232 const time32 = for (time32_compat_arch_list) |time32_compat_arch| {
233 if (mem.eql(u8, arch_name, time32_compat_arch)) break true;
234 } else false;
235 const arch_define = try std.fmt.allocPrint(arena, "-DARCH_{s}", .{arch_name});
236 const family_define = switch (target.cpu.arch) {
237 .arm, .armeb, .thumb, .thumbeb => "-DFAMILY_arm",
238 .aarch64, .aarch64_be => "-DFAMILY_aarch64",
239 .loongarch64 => "-DFAMILY_loongarch",
240 .m68k => "-DFAMILY_m68k",
241 .mips, .mipsel, .mips64, .mips64el => "-DFAMILY_mips",
242 .powerpc, .powerpc64, .powerpc64le => "-DFAMILY_powerpc",
243 .riscv32, .riscv64 => "-DFAMILY_riscv",
244 .s390x => "-DFAMILY_s390x",
245 .x86, .x86_64 => "-DFAMILY_x86",
246 else => unreachable,
247 };
245248 const cc_argv: []const []const u8 = if (target.ptrBitWidth() == 64)
246 &.{ "-DPTR64", arch_define }
249 &.{ "-DPTR64", arch_define, family_define }
250 else if (time32)
251 &.{ "-DTIME32", arch_define, family_define }
247252 else
248 &.{arch_define};
253 &.{ arch_define, family_define };
249254
250255 const root_mod = try Module.create(arena, .{
251256 .global_cache_directory = comp.global_cache_directory,
......@@ -347,6 +352,18 @@ pub fn needsCrt0(output_mode: std.builtin.OutputMode, link_mode: std.builtin.Lin
347352 };
348353}
349354
355const time32_compat_arch_list = [_][]const u8{
356 "arm",
357 "i386",
358 "m68k",
359 "microblaze",
360 "mips",
361 "mipsn32",
362 "or1k",
363 "powerpc",
364 "sh",
365};
366
350367fn isArchName(name: []const u8) bool {
351368 const musl_arch_names = [_][]const u8{
352369 "aarch64",