-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
Copy pathgen_stubs.zig
734 lines (669 loc) · 23.7 KB
/
gen_stubs.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
//! Example usage:
//! ./gen_stubs /path/to/musl/build-all >libc.S
//!
//! The directory 'build-all' is expected to contain these subdirectories:
//!
//! * aarch64
//! * arm
//! * i386
//! * hexagon
//! * loongarch64
//! * mips
//! * mips64
//! * mipsn32
//! * powerpc
//! * powerpc64
//! * riscv32
//! * riscv64
//! * s390x
//! * x32 (currently broken)
//! * x86_64
//!
//! ...each with 'lib/libc.so' inside of them.
//!
//! When building the resulting libc.S file, these defines are required:
//! * `-DTIME32`: When the target's primary time ABI is 32-bit
//! * `-DPTR64`: When the target has 64-bit pointers
//! * One of the following, corresponding to the CPU architecture:
//! - `-DARCH_aarch64`
//! - `-DARCH_arm`
//! - `-DARCH_i386`
//! - `-DARCH_hexagon`
//! - `-DARCH_loongarch64`
//! - `-DARCH_mips`
//! - `-DARCH_mips64`
//! - `-DARCH_mipsn32`
//! - `-DARCH_powerpc`
//! - `-DARCH_powerpc64`
//! - `-DARCH_riscv32`
//! - `-DARCH_riscv64`
//! - `-DARCH_s390x`
//! - `-DARCH_x32`
//! - `-DARCH_x86_64`
//! * One of the following, corresponding to the CPU architecture family:
//! - `-DFAMILY_aarch64`
//! - `-DFAMILY_arm`
//! - `-DFAMILY_hexagon`
//! - `-DFAMILY_loongarch`
//! - `-DFAMILY_mips`
//! - `-DFAMILY_powerpc`
//! - `-DFAMILY_riscv`
//! - `-DFAMILY_s390x`
//! - `-DFAMILY_x86`
// TODO: pick the best index to put them into instead of at the end
// - e.g. find a common previous symbol and put it after that one
// - they definitely need to go into the correct section
const std = @import("std");
const builtin = std.builtin;
const mem = std.mem;
const log = std.log;
const elf = std.elf;
const native_endian = @import("builtin").cpu.arch.endian();
const Arch = enum {
aarch64,
arm,
i386,
hexagon,
loongarch64,
mips,
mips64,
mipsn32,
powerpc,
powerpc64,
riscv32,
riscv64,
s390x,
x86_64,
pub fn ptrSize(arch: Arch) u16 {
return switch (arch) {
.arm,
.hexagon,
.i386,
.mips,
.mipsn32,
.powerpc,
.riscv32,
=> 4,
.aarch64,
.loongarch64,
.mips64,
.powerpc64,
.riscv64,
.s390x,
.x86_64,
=> 8,
};
}
pub fn isTime32(arch: Arch) bool {
return switch (arch) {
// This list will never grow; newer 32-bit ports will be time64 (e.g. riscv32).
.arm,
.i386,
.mips,
.mipsn32,
.powerpc,
=> true,
else => false,
};
}
pub fn family(arch: Arch) Family {
return switch (arch) {
.aarch64 => .aarch64,
.arm => .arm,
.i386, .x86_64 => .x86,
.hexagon => .hexagon,
.loongarch64 => .loongarch,
.mips, .mips64, .mipsn32 => .mips,
.powerpc, .powerpc64 => .powerpc,
.riscv32, .riscv64 => .riscv,
.s390x => .s390x,
};
}
};
const Family = enum {
aarch64,
arm,
hexagon,
loongarch,
mips,
powerpc,
riscv,
s390x,
x86,
};
const arches: [@typeInfo(Arch).@"enum".fields.len]Arch = blk: {
var result: [@typeInfo(Arch).@"enum".fields.len]Arch = undefined;
for (@typeInfo(Arch).@"enum".fields) |field| {
const arch: Arch = @enumFromInt(field.value);
result[archIndex(arch)] = arch;
}
break :blk result;
};
const MultiSym = struct {
size: [arches.len]u64,
present: [arches.len]bool,
binding: [arches.len]u4,
section: u16,
ty: u4,
visib: elf.STV,
fn isSingleArch(ms: MultiSym) ?Arch {
var result: ?Arch = null;
inline for (@typeInfo(Arch).@"enum".fields) |field| {
const arch: Arch = @enumFromInt(field.value);
if (ms.present[archIndex(arch)]) {
if (result != null) return null;
result = arch;
}
}
return result;
}
fn isFamily(ms: MultiSym) ?Family {
var result: ?Family = null;
inline for (@typeInfo(Arch).@"enum".fields) |field| {
const arch: Arch = @enumFromInt(field.value);
if (ms.present[archIndex(arch)]) {
const family = arch.family();
if (result) |r| if (family != r) return null;
result = family;
}
}
return result;
}
fn allPresent(ms: MultiSym) bool {
for (arches, 0..) |_, i| {
if (!ms.present[i]) {
return false;
}
}
return true;
}
fn isTime32Only(ms: MultiSym) bool {
inline for (@typeInfo(Arch).@"enum".fields) |field| {
const arch: Arch = @enumFromInt(field.value);
if (ms.present[archIndex(arch)] != arch.isTime32()) {
return false;
}
}
return true;
}
fn commonSize(ms: MultiSym) ?u64 {
var size: ?u64 = null;
for (arches, 0..) |_, i| {
if (!ms.present[i]) continue;
if (size) |s| {
if (ms.size[i] != s) {
return null;
}
} else {
size = ms.size[i];
}
}
return size.?;
}
fn commonBinding(ms: MultiSym) ?u4 {
var binding: ?u4 = null;
for (arches, 0..) |_, i| {
if (!ms.present[i]) continue;
if (binding) |b| {
if (ms.binding[i] != b) {
return null;
}
} else {
binding = ms.binding[i];
}
}
return binding.?;
}
fn isPtrSize(ms: MultiSym, mult: u16) bool {
inline for (@typeInfo(Arch).@"enum".fields) |field| {
const arch: Arch = @enumFromInt(field.value);
const arch_index = archIndex(arch);
if (ms.present[arch_index] and ms.size[arch_index] != arch.ptrSize() * mult) {
return false;
}
}
return true;
}
fn isWeak64(ms: MultiSym) bool {
inline for (@typeInfo(Arch).@"enum".fields) |field| {
const arch: Arch = @enumFromInt(field.value);
const arch_index = archIndex(arch);
const binding: u4 = switch (arch.ptrSize()) {
4 => std.elf.STB_GLOBAL,
8 => std.elf.STB_WEAK,
else => unreachable,
};
if (ms.present[arch_index] and ms.binding[arch_index] != binding) {
return false;
}
}
return true;
}
fn isWeakTime64(ms: MultiSym) bool {
inline for (@typeInfo(Arch).@"enum".fields) |field| {
const arch: Arch = @enumFromInt(field.value);
const arch_index = archIndex(arch);
const binding: u4 = if (arch.isTime32()) std.elf.STB_GLOBAL else std.elf.STB_WEAK;
if (ms.present[arch_index] and ms.binding[arch_index] != binding) {
return false;
}
}
return true;
}
};
const Parse = struct {
arena: mem.Allocator,
sym_table: *std.StringArrayHashMap(MultiSym),
sections: *std.StringArrayHashMap(void),
elf_bytes: []align(@alignOf(elf.Elf64_Ehdr)) u8,
header: elf.Header,
arch: Arch,
};
pub fn main() !void {
var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena_instance.deinit();
const arena = arena_instance.allocator();
const args = try std.process.argsAlloc(arena);
const build_all_path = args[1];
var build_all_dir = try std.fs.cwd().openDir(build_all_path, .{});
var sym_table = std.StringArrayHashMap(MultiSym).init(arena);
var sections = std.StringArrayHashMap(void).init(arena);
for (arches) |arch| {
const libc_so_path = try std.fmt.allocPrint(arena, "{s}/lib/libc.so", .{
@tagName(arch),
});
// Read the ELF header.
const elf_bytes = build_all_dir.readFileAllocOptions(
arena,
libc_so_path,
100 * 1024 * 1024,
1 * 1024 * 1024,
@alignOf(elf.Elf64_Ehdr),
null,
) catch |err| {
std.debug.panic("unable to read '{s}/{s}': {s}", .{
build_all_path, libc_so_path, @errorName(err),
});
};
const header = try elf.Header.parse(elf_bytes[0..@sizeOf(elf.Elf64_Ehdr)]);
const parse: Parse = .{
.arena = arena,
.sym_table = &sym_table,
.sections = §ions,
.elf_bytes = elf_bytes,
.header = header,
.arch = arch,
};
switch (header.is_64) {
true => switch (header.endian) {
.big => try parseElf(parse, true, .big),
.little => try parseElf(parse, true, .little),
},
false => switch (header.endian) {
.big => try parseElf(parse, false, .big),
.little => try parseElf(parse, false, .little),
},
}
}
const stdout = std.io.getStdOut().writer();
try stdout.writeAll(
\\#ifdef PTR64
\\#define WEAK64 .weak
\\#define PTR_SIZE_BYTES 8
\\#define PTR2_SIZE_BYTES 16
\\#else
\\#define WEAK64 .globl
\\#define PTR_SIZE_BYTES 4
\\#define PTR2_SIZE_BYTES 8
\\#endif
\\
\\#ifdef TIME32
\\#define WEAKTIME64 .globl
\\#else
\\#define WEAKTIME64 .weak
\\#endif
\\
\\
);
// Sort the symbols for deterministic output and cleaner vcs diffs.
const SymTableSort = struct {
sections: *const std.StringArrayHashMap(void),
sym_table: *const std.StringArrayHashMap(MultiSym),
/// Sort first by section name, then by symbol name
pub fn lessThan(ctx: @This(), index_a: usize, index_b: usize) bool {
const multi_sym_a = ctx.sym_table.values()[index_a];
const multi_sym_b = ctx.sym_table.values()[index_b];
const section_a = ctx.sections.keys()[multi_sym_a.section];
const section_b = ctx.sections.keys()[multi_sym_b.section];
switch (mem.order(u8, section_a, section_b)) {
.lt => return true,
.gt => return false,
.eq => {},
}
const symbol_a = ctx.sym_table.keys()[index_a];
const symbol_b = ctx.sym_table.keys()[index_b];
switch (mem.order(u8, symbol_a, symbol_b)) {
.lt => return true,
.gt, .eq => return false,
}
}
};
sym_table.sort(SymTableSort{ .sym_table = &sym_table, .sections = §ions });
var prev_section: u16 = std.math.maxInt(u16);
var prev_pp_state: union(enum) { all, single: Arch, multi, family: Family, time32 } = .all;
for (sym_table.values(), 0..) |multi_sym, sym_index| {
const name = sym_table.keys()[sym_index];
if (multi_sym.section != prev_section) {
prev_section = multi_sym.section;
const sh_name = sections.keys()[multi_sym.section];
try stdout.print("{s}\n", .{sh_name});
}
if (multi_sym.allPresent()) {
switch (prev_pp_state) {
.all => {},
.single, .multi, .family, .time32 => {
try stdout.writeAll("#endif\n");
prev_pp_state = .all;
},
}
} else if (multi_sym.isSingleArch()) |arch| {
switch (prev_pp_state) {
.all => {
try stdout.print("#ifdef ARCH_{s}\n", .{@tagName(arch)});
prev_pp_state = .{ .single = arch };
},
.multi, .family, .time32 => {
try stdout.print("#endif\n#ifdef ARCH_{s}\n", .{@tagName(arch)});
prev_pp_state = .{ .single = arch };
},
.single => |prev_arch| {
if (arch != prev_arch) {
try stdout.print("#endif\n#ifdef ARCH_{s}\n", .{@tagName(arch)});
prev_pp_state = .{ .single = arch };
}
},
}
} else if (multi_sym.isFamily()) |family| {
switch (prev_pp_state) {
.all => {
try stdout.print("#ifdef FAMILY_{s}\n", .{@tagName(family)});
prev_pp_state = .{ .family = family };
},
.single, .multi, .time32 => {
try stdout.print("#endif\n#ifdef FAMILY_{s}\n", .{@tagName(family)});
prev_pp_state = .{ .family = family };
},
.family => |prev_family| {
if (family != prev_family) {
try stdout.print("#endif\n#ifdef FAMILY_{s}\n", .{@tagName(family)});
prev_pp_state = .{ .family = family };
}
},
}
} else if (multi_sym.isTime32Only()) {
switch (prev_pp_state) {
.all => {
try stdout.writeAll("#ifdef TIME32\n");
prev_pp_state = .time32;
},
.single, .multi, .family => {
try stdout.writeAll("#endif\n#ifdef TIME32\n");
prev_pp_state = .time32;
},
.time32 => {},
}
} else {
switch (prev_pp_state) {
.all => {},
.single, .multi, .family, .time32 => {
try stdout.writeAll("#endif\n");
},
}
prev_pp_state = .multi;
var first = true;
try stdout.writeAll("#if ");
for (arches, 0..) |arch, i| {
if (multi_sym.present[i]) continue;
if (!first) try stdout.writeAll(" && ");
first = false;
try stdout.print("!defined(ARCH_{s})", .{@tagName(arch)});
}
try stdout.writeAll("\n");
}
if (multi_sym.commonBinding()) |binding| {
switch (binding) {
elf.STB_GLOBAL => {
try stdout.print(".globl {s}\n", .{name});
},
elf.STB_WEAK => {
try stdout.print(".weak {s}\n", .{name});
},
else => unreachable,
}
} else if (multi_sym.isWeak64()) {
try stdout.print("WEAK64 {s}\n", .{name});
} else if (multi_sym.isWeakTime64()) {
try stdout.print("WEAKTIME64 {s}\n", .{name});
} else {
for (arches, 0..) |arch, i| {
log.info("symbol '{s}' binding on {s}: {d}", .{
name, @tagName(arch), multi_sym.binding[i],
});
}
}
switch (multi_sym.ty) {
elf.STT_NOTYPE => {},
elf.STT_FUNC => {
try stdout.print(".type {s}, %function;\n", .{name});
// omitting the size is OK for functions
},
elf.STT_OBJECT => {
try stdout.print(".type {s}, %object;\n", .{name});
if (multi_sym.commonSize()) |size| {
try stdout.print(".size {s}, {d}\n", .{ name, size });
} else if (multi_sym.isPtrSize(1)) {
try stdout.print(".size {s}, PTR_SIZE_BYTES\n", .{name});
} else if (multi_sym.isPtrSize(2)) {
try stdout.print(".size {s}, PTR2_SIZE_BYTES\n", .{name});
} else {
for (arches, 0..) |arch, i| {
log.info("symbol '{s}' size on {s}: {d}", .{
name, @tagName(arch), multi_sym.size[i],
});
}
//try stdout.print(".size {s}, {d}\n", .{ name, size });
}
},
else => unreachable,
}
switch (multi_sym.visib) {
.DEFAULT => {},
.PROTECTED => try stdout.print(".protected {s}\n", .{name}),
.INTERNAL, .HIDDEN => unreachable,
}
try stdout.print("{s}:\n", .{name});
}
switch (prev_pp_state) {
.all => {},
.single, .multi, .family, .time32 => try stdout.writeAll("#endif\n"),
}
}
fn parseElf(parse: Parse, comptime is_64: bool, comptime endian: builtin.Endian) !void {
const arena = parse.arena;
const elf_bytes = parse.elf_bytes;
const header = parse.header;
const Sym = if (is_64) elf.Elf64_Sym else elf.Elf32_Sym;
const S = struct {
fn endianSwap(x: anytype) @TypeOf(x) {
if (endian != native_endian) {
return @byteSwap(x);
} else {
return x;
}
}
fn symbolAddrLessThan(_: void, lhs: Sym, rhs: Sym) bool {
return endianSwap(lhs.st_value) < endianSwap(rhs.st_value);
}
};
// A little helper to do endian swapping.
const s = S.endianSwap;
// Obtain list of sections.
const Shdr = if (is_64) elf.Elf64_Shdr else elf.Elf32_Shdr;
const shdrs = mem.bytesAsSlice(Shdr, elf_bytes[header.shoff..])[0..header.shnum];
// Obtain the section header string table.
const shstrtab_offset = s(shdrs[header.shstrndx].sh_offset);
log.debug("shstrtab is at offset {d}", .{shstrtab_offset});
const shstrtab = elf_bytes[shstrtab_offset..];
// Maps this ELF file's section header index to the multi arch section ArrayHashMap index.
const section_index_map = try arena.alloc(u16, shdrs.len);
// Find the offset of the dynamic symbol table.
var dynsym_index: u16 = 0;
for (shdrs, 0..) |shdr, i| {
const sh_name = try arena.dupe(u8, mem.sliceTo(shstrtab[s(shdr.sh_name)..], 0));
log.debug("found section: {s}", .{sh_name});
if (mem.eql(u8, sh_name, ".dynsym")) {
dynsym_index = @as(u16, @intCast(i));
}
const gop = try parse.sections.getOrPut(sh_name);
section_index_map[i] = @as(u16, @intCast(gop.index));
}
if (dynsym_index == 0) @panic("did not find the .dynsym section");
log.debug("found .dynsym section at index {d}", .{dynsym_index});
// Read the dynamic symbols into a list.
const dyn_syms_off = s(shdrs[dynsym_index].sh_offset);
const dyn_syms_size = s(shdrs[dynsym_index].sh_size);
const dyn_syms = mem.bytesAsSlice(Sym, elf_bytes[dyn_syms_off..][0..dyn_syms_size]);
const dynstr_offset = s(shdrs[s(shdrs[dynsym_index].sh_link)].sh_offset);
const dynstr = elf_bytes[dynstr_offset..];
// Sort the list by address, ascending.
// We need a copy to fix alignment.
const copied_dyn_syms = copy: {
const ptr = try arena.alloc(Sym, dyn_syms.len);
@memcpy(ptr, dyn_syms);
break :copy ptr;
};
mem.sort(Sym, copied_dyn_syms, {}, S.symbolAddrLessThan);
for (copied_dyn_syms) |sym| {
const this_section = s(sym.st_shndx);
const name = try arena.dupe(u8, mem.sliceTo(dynstr[s(sym.st_name)..], 0));
const ty = @as(u4, @truncate(sym.st_info));
const binding = @as(u4, @truncate(sym.st_info >> 4));
const visib = @as(elf.STV, @enumFromInt(@as(u2, @truncate(sym.st_other))));
const size = s(sym.st_size);
if (size == 0) {
log.warn("{s}: symbol '{s}' has size 0", .{ @tagName(parse.arch), name });
}
if (sym.st_shndx == elf.SHN_UNDEF) {
log.debug("{s}: skipping '{s}' due to it being undefined", .{
@tagName(parse.arch), name,
});
continue;
}
switch (binding) {
elf.STB_GLOBAL, elf.STB_WEAK => {},
else => {
log.debug("{s}: skipping '{s}' due to it having binding '{d}'", .{
@tagName(parse.arch), name, binding,
});
continue;
},
}
switch (ty) {
elf.STT_NOTYPE, elf.STT_FUNC, elf.STT_OBJECT => {},
else => {
log.debug("{s}: skipping '{s}' due to it having type '{d}'", .{
@tagName(parse.arch), name, ty,
});
continue;
},
}
switch (visib) {
.DEFAULT, .PROTECTED => {},
.INTERNAL, .HIDDEN => {
log.debug("{s}: skipping '{s}' due to it having visibility '{s}'", .{
@tagName(parse.arch), name, @tagName(visib),
});
continue;
},
}
const gop = try parse.sym_table.getOrPut(name);
if (gop.found_existing) {
if (gop.value_ptr.section != section_index_map[this_section]) {
const sh_name = mem.sliceTo(shstrtab[s(shdrs[this_section].sh_name)..], 0);
fatal("symbol '{s}' in arch {s} is in section {s} but in arch {s} is in section {s}", .{
name,
@tagName(parse.arch),
sh_name,
archSetName(gop.value_ptr.present),
parse.sections.keys()[gop.value_ptr.section],
});
}
if (gop.value_ptr.ty != ty) blk: {
if (ty == elf.STT_NOTYPE) {
log.warn("symbol '{s}' in arch {s} has type {d} but in arch {s} has type {d}. going with the one that is not STT_NOTYPE", .{
name,
@tagName(parse.arch),
ty,
archSetName(gop.value_ptr.present),
gop.value_ptr.ty,
});
break :blk;
}
if (gop.value_ptr.ty == elf.STT_NOTYPE) {
log.warn("symbol '{s}' in arch {s} has type {d} but in arch {s} has type {d}. going with the one that is not STT_NOTYPE", .{
name,
@tagName(parse.arch),
ty,
archSetName(gop.value_ptr.present),
gop.value_ptr.ty,
});
gop.value_ptr.ty = ty;
break :blk;
}
fatal("symbol '{s}' in arch {s} has type {d} but in arch {s} has type {d}", .{
name,
@tagName(parse.arch),
ty,
archSetName(gop.value_ptr.present),
gop.value_ptr.ty,
});
}
if (gop.value_ptr.visib != visib) {
fatal("symbol '{s}' in arch {s} has visib {s} but in arch {s} has visib {s}", .{
name,
@tagName(parse.arch),
@tagName(visib),
archSetName(gop.value_ptr.present),
@tagName(gop.value_ptr.visib),
});
}
} else {
gop.value_ptr.* = .{
.present = [1]bool{false} ** arches.len,
.section = section_index_map[this_section],
.ty = ty,
.binding = [1]u4{0} ** arches.len,
.visib = visib,
.size = [1]u64{0} ** arches.len,
};
}
gop.value_ptr.present[archIndex(parse.arch)] = true;
gop.value_ptr.size[archIndex(parse.arch)] = size;
gop.value_ptr.binding[archIndex(parse.arch)] = binding;
}
}
fn archIndex(arch: Arch) u8 {
return @intFromEnum(arch);
}
fn archSetName(arch_set: [arches.len]bool) []const u8 {
for (arches, arch_set) |arch, set_item| {
if (set_item) {
return @tagName(arch);
}
}
return "(none)";
}
fn fatal(comptime format: []const u8, args: anytype) noreturn {
log.err(format, args);
std.process.exit(1);
}