authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-12-13 18:47:09+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-12-13 18:47:09+01:00
log4574dea13a4b1d38c97fe73c257d895f605b78ca
tree0a1af823ce5c7c2ff0546c32f37cfe45b1f5ea6f
parenta38af5f542199378483aba9f4598634ebf012b7b
parent5d12622469db5c53fe4857dfd95be033c16b4056
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #18271 from ziglang/check-object-scoped-checks

lib/std/Build/CheckObject: introduce scoped checks

29 files changed, 454 insertions(+), 242 deletions(-)

lib/std/Build/Step/CheckObject.zig+370-158
......@@ -246,10 +246,12 @@ const ComputeCompareExpected = struct {
246246};
247247
248248const Check = struct {
249 kind: Kind,
249250 actions: std.ArrayList(Action),
250251
251 fn create(allocator: Allocator) Check {
252 fn create(allocator: Allocator, kind: Kind) Check {
252253 return .{
254 .kind = kind,
253255 .actions = std.ArrayList(Action).init(allocator),
254256 };
255257 }
......@@ -289,15 +291,30 @@ const Check = struct {
289291 .expected = expected,
290292 }) catch @panic("OOM");
291293 }
294
295 const Kind = enum {
296 headers,
297 symtab,
298 indirect_symtab,
299 dynamic_symtab,
300 archive_symtab,
301 dynamic_section,
302 dyld_rebase,
303 dyld_bind,
304 dyld_weak_bind,
305 dyld_lazy_bind,
306 exports,
307 compute_compare,
308 };
292309};
293310
294311/// Creates a new empty sequence of actions.
295pub fn checkStart(self: *CheckObject) void {
296 const new_check = Check.create(self.step.owner.allocator);
312fn checkStart(self: *CheckObject, kind: Check.Kind) void {
313 const new_check = Check.create(self.step.owner.allocator, kind);
297314 self.checks.append(new_check) catch @panic("OOM");
298315}
299316
300/// Adds an exact match phrase to the latest created Check with `CheckObject.checkStart()`.
317/// Adds an exact match phrase to the latest created Check.
301318pub fn checkExact(self: *CheckObject, phrase: []const u8) void {
302319 self.checkExactInner(phrase, null);
303320}
......@@ -314,7 +331,7 @@ fn checkExactInner(self: *CheckObject, phrase: []const u8, file_source: ?std.Bui
314331 last.exact(.{ .string = self.step.owner.dupe(phrase), .file_source = file_source });
315332}
316333
317/// Adds a fuzzy match phrase to the latest created Check with `CheckObject.checkStart()`.
334/// Adds a fuzzy match phrase to the latest created Check.
318335pub fn checkContains(self: *CheckObject, phrase: []const u8) void {
319336 self.checkContainsInner(phrase, null);
320337}
......@@ -331,8 +348,7 @@ fn checkContainsInner(self: *CheckObject, phrase: []const u8, file_source: ?std.
331348 last.contains(.{ .string = self.step.owner.dupe(phrase), .file_source = file_source });
332349}
333350
334/// Adds an exact match phrase with variable extractor to the latest created Check
335/// with `CheckObject.checkStart()`.
351/// Adds an exact match phrase with variable extractor to the latest created Check.
336352pub fn checkExtract(self: *CheckObject, phrase: []const u8) void {
337353 self.checkExtractInner(phrase, null);
338354}
......@@ -349,7 +365,7 @@ fn checkExtractInner(self: *CheckObject, phrase: []const u8, file_source: ?std.B
349365 last.extract(.{ .string = self.step.owner.dupe(phrase), .file_source = file_source });
350366}
351367
352/// Adds another searched phrase to the latest created Check with `CheckObject.checkStart(...)`
368/// Adds another searched phrase to the latest created Check
353369/// however ensures there is no matching phrase in the output.
354370pub fn checkNotPresent(self: *CheckObject, phrase: []const u8) void {
355371 self.checkNotPresentInner(phrase, null);
......@@ -367,6 +383,11 @@ fn checkNotPresentInner(self: *CheckObject, phrase: []const u8, file_source: ?st
367383 last.notPresent(.{ .string = self.step.owner.dupe(phrase), .file_source = file_source });
368384}
369385
386/// Creates a new check checking in the file headers (section, program headers, etc.).
387pub fn checkInHeaders(self: *CheckObject) void {
388 self.checkStart(.headers);
389}
390
370391/// Creates a new check checking specifically symbol table parsed and dumped from the object
371392/// file.
372393pub fn checkInSymtab(self: *CheckObject) void {
......@@ -377,19 +398,79 @@ pub fn checkInSymtab(self: *CheckObject) void {
377398 .coff => @panic("TODO symtab for coff"),
378399 else => @panic("TODO other file formats"),
379400 };
380 self.checkStart();
401 self.checkStart(.symtab);
402 self.checkExact(label);
403}
404
405/// Creates a new check checking specifically dyld rebase opcodes contents parsed and dumped
406/// from the object file.
407/// This check is target-dependent and applicable to MachO only.
408pub fn checkInDyldRebase(self: *CheckObject) void {
409 const label = switch (self.obj_format) {
410 .macho => MachODumper.dyld_rebase_label,
411 else => @panic("Unsupported target platform"),
412 };
413 self.checkStart(.dyld_rebase);
414 self.checkExact(label);
415}
416
417/// Creates a new check checking specifically dyld bind opcodes contents parsed and dumped
418/// from the object file.
419/// This check is target-dependent and applicable to MachO only.
420pub fn checkInDyldBind(self: *CheckObject) void {
421 const label = switch (self.obj_format) {
422 .macho => MachODumper.dyld_bind_label,
423 else => @panic("Unsupported target platform"),
424 };
425 self.checkStart(.dyld_bind);
426 self.checkExact(label);
427}
428
429/// Creates a new check checking specifically dyld weak bind opcodes contents parsed and dumped
430/// from the object file.
431/// This check is target-dependent and applicable to MachO only.
432pub fn checkInDyldWeakBind(self: *CheckObject) void {
433 const label = switch (self.obj_format) {
434 .macho => MachODumper.dyld_weak_bind_label,
435 else => @panic("Unsupported target platform"),
436 };
437 self.checkStart(.dyld_weak_bind);
381438 self.checkExact(label);
382439}
383440
384/// Creates a new check checking specifically dyld_info_only contents parsed and dumped
441/// Creates a new check checking specifically dyld lazy bind opcodes contents parsed and dumped
385442/// from the object file.
386443/// This check is target-dependent and applicable to MachO only.
387pub fn checkInDyldInfo(self: *CheckObject) void {
444pub fn checkInDyldLazyBind(self: *CheckObject) void {
388445 const label = switch (self.obj_format) {
389 .macho => MachODumper.dyld_info_label,
446 .macho => MachODumper.dyld_lazy_bind_label,
390447 else => @panic("Unsupported target platform"),
391448 };
392 self.checkStart();
449 self.checkStart(.dyld_lazy_bind);
450 self.checkExact(label);
451}
452
453/// Creates a new check checking specifically exports info contents parsed and dumped
454/// from the object file.
455/// This check is target-dependent and applicable to MachO only.
456pub fn checkInExports(self: *CheckObject) void {
457 const label = switch (self.obj_format) {
458 .macho => MachODumper.exports_label,
459 else => @panic("Unsupported target platform"),
460 };
461 self.checkStart(.exports);
462 self.checkExact(label);
463}
464
465/// Creates a new check checking specifically indirect symbol table parsed and dumped
466/// from the object file.
467/// This check is target-dependent and applicable to MachO only.
468pub fn checkInIndirectSymtab(self: *CheckObject) void {
469 const label = switch (self.obj_format) {
470 .macho => MachODumper.indirect_symtab_label,
471 else => @panic("Unsupported target platform"),
472 };
473 self.checkStart(.indirect_symtab);
393474 self.checkExact(label);
394475}
395476
......@@ -401,7 +482,7 @@ pub fn checkInDynamicSymtab(self: *CheckObject) void {
401482 .elf => ElfDumper.dynamic_symtab_label,
402483 else => @panic("Unsupported target platform"),
403484 };
404 self.checkStart();
485 self.checkStart(.dynamic_symtab);
405486 self.checkExact(label);
406487}
407488
......@@ -413,7 +494,7 @@ pub fn checkInDynamicSection(self: *CheckObject) void {
413494 .elf => ElfDumper.dynamic_section_label,
414495 else => @panic("Unsupported target platform"),
415496 };
416 self.checkStart();
497 self.checkStart(.dynamic_section);
417498 self.checkExact(label);
418499}
419500
......@@ -424,7 +505,7 @@ pub fn checkInArchiveSymtab(self: *CheckObject) void {
424505 .elf => ElfDumper.archive_symtab_label,
425506 else => @panic("TODO other file formats"),
426507 };
427 self.checkStart();
508 self.checkStart(.archive_symtab);
428509 self.checkExact(label);
429510}
430511
......@@ -436,7 +517,7 @@ pub fn checkComputeCompare(
436517 program: []const u8,
437518 expected: ComputeCompareExpected,
438519) void {
439 var new_check = Check.create(self.step.owner.allocator);
520 var new_check = Check.create(self.step.owner.allocator, .compute_compare);
440521 new_check.computeCmp(.{ .string = self.step.owner.dupe(program) }, expected);
441522 self.checks.append(new_check) catch @panic("OOM");
442523}
......@@ -457,17 +538,35 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
457538 null,
458539 ) catch |err| return step.fail("unable to read '{s}': {s}", .{ src_path, @errorName(err) });
459540
460 const output = switch (self.obj_format) {
461 .macho => try MachODumper.parseAndDump(step, contents),
462 .elf => try ElfDumper.parseAndDump(step, contents),
463 .coff => @panic("TODO coff parser"),
464 .wasm => try WasmDumper.parseAndDump(step, contents),
465 else => unreachable,
466 };
467
468541 var vars = std.StringHashMap(u64).init(gpa);
469
470542 for (self.checks.items) |chk| {
543 if (chk.kind == .compute_compare) {
544 assert(chk.actions.items.len == 1);
545 const act = chk.actions.items[0];
546 assert(act.tag == .compute_cmp);
547 const res = act.computeCmp(b, step, vars) catch |err| switch (err) {
548 error.UnknownVariable => return step.fail("Unknown variable", .{}),
549 else => |e| return e,
550 };
551 if (!res) {
552 return step.fail(
553 \\
554 \\========= comparison failed for action: ===========
555 \\{s} {}
556 \\===================================================
557 , .{ act.phrase.resolve(b, step), act.expected.? });
558 }
559 continue;
560 }
561
562 const output = switch (self.obj_format) {
563 .macho => try MachODumper.parseAndDump(step, chk.kind, contents),
564 .elf => try ElfDumper.parseAndDump(step, chk.kind, contents),
565 .coff => return step.fail("TODO coff parser", .{}),
566 .wasm => try WasmDumper.parseAndDump(step, chk.kind, contents),
567 else => unreachable,
568 };
569
471570 var it = mem.tokenizeAny(u8, output, "\r\n");
472571 for (chk.actions.items) |act| {
473572 switch (act.tag) {
......@@ -485,6 +584,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
485584 , .{ act.phrase.resolve(b, step), output });
486585 }
487586 },
587
488588 .contains => {
489589 while (it.next()) |line| {
490590 if (act.contains(b, step, line)) break;
......@@ -499,6 +599,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
499599 , .{ act.phrase.resolve(b, step), output });
500600 }
501601 },
602
502603 .not_present => {
503604 while (it.next()) |line| {
504605 if (act.notPresent(b, step, line)) continue;
......@@ -512,6 +613,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
512613 , .{ act.phrase.resolve(b, step), output });
513614 }
514615 },
616
515617 .extract => {
516618 while (it.next()) |line| {
517619 if (try act.extract(b, step, line, &vars)) break;
......@@ -526,28 +628,8 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
526628 , .{ act.phrase.resolve(b, step), output });
527629 }
528630 },
529 .compute_cmp => {
530 const res = act.computeCmp(b, step, vars) catch |err| switch (err) {
531 error.UnknownVariable => {
532 return step.fail(
533 \\========= from parsed file: =====================
534 \\{s}
535 \\=================================================
536 , .{output});
537 },
538 else => |e| return e,
539 };
540 if (!res) {
541 return step.fail(
542 \\
543 \\========= comparison failed for action: ===========
544 \\{s} {}
545 \\========= from parsed file: =======================
546 \\{s}
547 \\===================================================
548 , .{ act.phrase.resolve(b, step), act.expected.?, output });
549 }
550 },
631
632 .compute_cmp => unreachable,
551633 }
552634 }
553635 }
......@@ -555,15 +637,26 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
555637
556638const MachODumper = struct {
557639 const LoadCommandIterator = macho.LoadCommandIterator;
558 const dyld_info_label = "dyld info data";
640 const dyld_rebase_label = "dyld rebase data";
641 const dyld_bind_label = "dyld bind data";
642 const dyld_weak_bind_label = "dyld weak bind data";
643 const dyld_lazy_bind_label = "dyld lazy bind data";
644 const exports_label = "exports data";
559645 const symtab_label = "symbol table";
646 const indirect_symtab_label = "indirect symbol table";
560647
561648 const Symtab = struct {
562 symbols: []align(1) const macho.nlist_64,
563 strings: []const u8,
649 symbols: []align(1) const macho.nlist_64 = &[0]macho.nlist_64{},
650 strings: []const u8 = &[0]u8{},
651 indirect_symbols: []align(1) const u32 = &[0]u32{},
652
653 fn getString(symtab: Symtab, off: u32) []const u8 {
654 assert(off < symtab.strings.len);
655 return mem.sliceTo(@as([*:0]const u8, @ptrCast(symtab.strings.ptr + off)), 0);
656 }
564657 };
565658
566 fn parseAndDump(step: *Step, bytes: []const u8) ![]const u8 {
659 fn parseAndDump(step: *Step, kind: Check.Kind, bytes: []const u8) ![]const u8 {
567660 const gpa = step.owner.allocator;
568661 var stream = std.io.fixedBufferStream(bytes);
569662 const reader = stream.reader();
......@@ -576,7 +669,7 @@ const MachODumper = struct {
576669 var output = std.ArrayList(u8).init(gpa);
577670 const writer = output.writer();
578671
579 var symtab: ?Symtab = null;
672 var symtab: Symtab = .{};
580673 var segments = std.ArrayList(macho.segment_command_64).init(gpa);
581674 defer segments.deinit();
582675 var sections = std.ArrayList(macho.section_64).init(gpa);
......@@ -586,82 +679,129 @@ const MachODumper = struct {
586679 var text_seg: ?u8 = null;
587680 var dyld_info_lc: ?macho.dyld_info_command = null;
588681
589 try dumpHeader(hdr, writer);
682 {
683 var it: LoadCommandIterator = .{
684 .ncmds = hdr.ncmds,
685 .buffer = bytes[@sizeOf(macho.mach_header_64)..][0..hdr.sizeofcmds],
686 };
687 var i: usize = 0;
688 while (it.next()) |cmd| {
689 switch (cmd.cmd()) {
690 .SEGMENT_64 => {
691 const seg = cmd.cast(macho.segment_command_64).?;
692 try sections.ensureUnusedCapacity(seg.nsects);
693 for (cmd.getSections()) |sect| {
694 sections.appendAssumeCapacity(sect);
695 }
696 const seg_id: u8 = @intCast(segments.items.len);
697 try segments.append(seg);
698 if (mem.eql(u8, seg.segName(), "__TEXT")) {
699 text_seg = seg_id;
700 }
701 },
702 .SYMTAB => {
703 const lc = cmd.cast(macho.symtab_command).?;
704 const symbols = @as([*]align(1) const macho.nlist_64, @ptrCast(bytes.ptr + lc.symoff))[0..lc.nsyms];
705 const strings = bytes[lc.stroff..][0..lc.strsize];
706 symtab.symbols = symbols;
707 symtab.strings = strings;
708 },
709 .DYSYMTAB => {
710 const lc = cmd.cast(macho.dysymtab_command).?;
711 const indexes = @as([*]align(1) const u32, @ptrCast(bytes.ptr + lc.indirectsymoff))[0..lc.nindirectsyms];
712 symtab.indirect_symbols = indexes;
713 },
714 .LOAD_DYLIB,
715 .LOAD_WEAK_DYLIB,
716 .REEXPORT_DYLIB,
717 => {
718 try imports.append(cmd.getDylibPathName());
719 },
720 .DYLD_INFO_ONLY => {
721 dyld_info_lc = cmd.cast(macho.dyld_info_command).?;
722 },
723 else => {},
724 }
590725
591 var it: LoadCommandIterator = .{
592 .ncmds = hdr.ncmds,
593 .buffer = bytes[@sizeOf(macho.mach_header_64)..][0..hdr.sizeofcmds],
594 };
595 var i: usize = 0;
596 while (it.next()) |cmd| {
597 switch (cmd.cmd()) {
598 .SEGMENT_64 => {
599 const seg = cmd.cast(macho.segment_command_64).?;
600 try sections.ensureUnusedCapacity(seg.nsects);
601 for (cmd.getSections()) |sect| {
602 sections.appendAssumeCapacity(sect);
603 }
604 const seg_id: u8 = @intCast(segments.items.len);
605 try segments.append(seg);
606 if (mem.eql(u8, seg.segName(), "__TEXT")) {
607 text_seg = seg_id;
608 }
609 },
610 .SYMTAB => {
611 const lc = cmd.cast(macho.symtab_command).?;
612 const symbols = @as([*]align(1) const macho.nlist_64, @ptrCast(bytes.ptr + lc.symoff))[0..lc.nsyms];
613 const strings = bytes[lc.stroff..][0..lc.strsize];
614 symtab = .{ .symbols = symbols, .strings = strings };
615 },
616 .LOAD_DYLIB,
617 .LOAD_WEAK_DYLIB,
618 .REEXPORT_DYLIB,
619 => {
620 try imports.append(cmd.getDylibPathName());
621 },
622 .DYLD_INFO_ONLY => {
623 dyld_info_lc = cmd.cast(macho.dyld_info_command).?;
624 },
625 else => {},
726 i += 1;
626727 }
728 }
627729
628 try dumpLoadCommand(cmd, i, writer);
629 try writer.writeByte('\n');
730 switch (kind) {
731 .headers => {
732 try dumpHeader(hdr, writer);
630733
631 i += 1;
632 }
734 var it: LoadCommandIterator = .{
735 .ncmds = hdr.ncmds,
736 .buffer = bytes[@sizeOf(macho.mach_header_64)..][0..hdr.sizeofcmds],
737 };
738 var i: usize = 0;
739 while (it.next()) |cmd| {
740 try dumpLoadCommand(cmd, i, writer);
741 try writer.writeByte('\n');
633742
634 if (symtab) |stab| {
635 try dumpSymtab(sections.items, imports.items, stab, writer);
636 }
743 i += 1;
744 }
745 },
637746
638 if (dyld_info_lc) |lc| {
639 try writer.writeAll(dyld_info_label ++ "\n");
640 if (lc.rebase_size > 0) {
641 const data = bytes[lc.rebase_off..][0..lc.rebase_size];
642 try writer.writeAll("rebase info\n");
643 try dumpRebaseInfo(gpa, data, segments.items, writer);
644 }
645 if (lc.bind_size > 0) {
646 const data = bytes[lc.bind_off..][0..lc.bind_size];
647 try writer.writeAll("bind info\n");
648 try dumpBindInfo(gpa, data, segments.items, imports.items, writer);
649 }
650 if (lc.weak_bind_size > 0) {
651 const data = bytes[lc.weak_bind_off..][0..lc.weak_bind_size];
652 try writer.writeAll("weak bind info\n");
653 try dumpBindInfo(gpa, data, segments.items, imports.items, writer);
654 }
655 if (lc.lazy_bind_size > 0) {
656 const data = bytes[lc.lazy_bind_off..][0..lc.lazy_bind_size];
657 try writer.writeAll("lazy bind info\n");
658 try dumpBindInfo(gpa, data, segments.items, imports.items, writer);
659 }
660 if (lc.export_size > 0) {
661 const data = bytes[lc.export_off..][0..lc.export_size];
662 try writer.writeAll("exports\n");
663 try dumpExportsTrie(gpa, data, segments.items[text_seg.?], writer);
664 }
747 .symtab => if (symtab.symbols.len > 0) {
748 try dumpSymtab(sections.items, imports.items, symtab, writer);
749 } else return step.fail("no symbol table found", .{}),
750
751 .indirect_symtab => if (symtab.symbols.len > 0 and symtab.indirect_symbols.len > 0) {
752 try dumpIndirectSymtab(gpa, sections.items, symtab, writer);
753 } else return step.fail("no indirect symbol table found", .{}),
754
755 .dyld_rebase,
756 .dyld_bind,
757 .dyld_weak_bind,
758 .dyld_lazy_bind,
759 => {
760 if (dyld_info_lc == null) return step.fail("no dyld info found", .{});
761 const lc = dyld_info_lc.?;
762
763 switch (kind) {
764 .dyld_rebase => if (lc.rebase_size > 0) {
765 const data = bytes[lc.rebase_off..][0..lc.rebase_size];
766 try writer.writeAll(dyld_rebase_label ++ "\n");
767 try dumpRebaseInfo(gpa, data, segments.items, writer);
768 } else return step.fail("no rebase data found", .{}),
769
770 .dyld_bind => if (lc.bind_size > 0) {
771 const data = bytes[lc.bind_off..][0..lc.bind_size];
772 try writer.writeAll(dyld_bind_label ++ "\n");
773 try dumpBindInfo(gpa, data, segments.items, imports.items, writer);
774 } else return step.fail("no bind data found", .{}),
775
776 .dyld_weak_bind => if (lc.weak_bind_size > 0) {
777 const data = bytes[lc.weak_bind_off..][0..lc.weak_bind_size];
778 try writer.writeAll(dyld_weak_bind_label ++ "\n");
779 try dumpBindInfo(gpa, data, segments.items, imports.items, writer);
780 } else return step.fail("no weak bind data found", .{}),
781
782 .dyld_lazy_bind => if (lc.lazy_bind_size > 0) {
783 const data = bytes[lc.lazy_bind_off..][0..lc.lazy_bind_size];
784 try writer.writeAll(dyld_lazy_bind_label ++ "\n");
785 try dumpBindInfo(gpa, data, segments.items, imports.items, writer);
786 } else return step.fail("no lazy bind data found", .{}),
787
788 else => unreachable,
789 }
790 },
791
792 .exports => blk: {
793 if (dyld_info_lc) |lc| {
794 if (lc.export_size > 0) {
795 const data = bytes[lc.export_off..][0..lc.export_size];
796 try writer.writeAll(exports_label ++ "\n");
797 try dumpExportsTrie(gpa, data, segments.items[text_seg.?], writer);
798 break :blk;
799 }
800 }
801 return step.fail("no exports data found", .{});
802 },
803
804 else => return step.fail("invalid check kind for MachO file format: {s}", .{@tagName(kind)}),
665805 }
666806
667807 return output.toOwnedSlice();
......@@ -971,7 +1111,7 @@ const MachODumper = struct {
9711111
9721112 for (symtab.symbols) |sym| {
9731113 if (sym.stab()) continue;
974 const sym_name = mem.sliceTo(@as([*:0]const u8, @ptrCast(symtab.strings.ptr + sym.n_strx)), 0);
1114 const sym_name = symtab.getString(sym.n_strx);
9751115 if (sym.sect()) {
9761116 const sect = sections[sym.n_sect - 1];
9771117 try writer.print("{x} ({s},{s})", .{
......@@ -1021,6 +1161,52 @@ const MachODumper = struct {
10211161 }
10221162 }
10231163
1164 fn dumpIndirectSymtab(
1165 gpa: Allocator,
1166 sections: []const macho.section_64,
1167 symtab: Symtab,
1168 writer: anytype,
1169 ) !void {
1170 try writer.writeAll(indirect_symtab_label ++ "\n");
1171
1172 var sects = std.ArrayList(macho.section_64).init(gpa);
1173 defer sects.deinit();
1174 try sects.ensureUnusedCapacity(3);
1175
1176 for (sections) |sect| {
1177 if (mem.eql(u8, sect.sectName(), "__stubs")) sects.appendAssumeCapacity(sect);
1178 if (mem.eql(u8, sect.sectName(), "__got")) sects.appendAssumeCapacity(sect);
1179 if (mem.eql(u8, sect.sectName(), "__la_symbol_ptr")) sects.appendAssumeCapacity(sect);
1180 }
1181
1182 const sortFn = struct {
1183 fn sortFn(ctx: void, lhs: macho.section_64, rhs: macho.section_64) bool {
1184 _ = ctx;
1185 return lhs.reserved1 < rhs.reserved1;
1186 }
1187 }.sortFn;
1188 mem.sort(macho.section_64, sects.items, {}, sortFn);
1189
1190 var i: usize = 0;
1191 while (i < sects.items.len) : (i += 1) {
1192 const sect = sects.items[i];
1193 const start = sect.reserved1;
1194 const end = if (i + 1 >= sects.items.len) symtab.indirect_symbols.len else sects.items[i + 1].reserved1;
1195 const entry_size = blk: {
1196 if (mem.eql(u8, sect.sectName(), "__stubs")) break :blk sect.reserved2;
1197 break :blk @sizeOf(u64);
1198 };
1199
1200 try writer.print("{s},{s}\n", .{ sect.segName(), sect.sectName() });
1201 try writer.print("nentries {d}\n", .{end - start});
1202 for (symtab.indirect_symbols[start..end], 0..) |index, j| {
1203 const sym = symtab.symbols[index];
1204 const addr = sect.addr + entry_size * j;
1205 try writer.print("0x{x} {d} {s}\n", .{ addr, index, symtab.getString(sym.n_strx) });
1206 }
1207 }
1208 }
1209
10241210 fn dumpRebaseInfo(
10251211 gpa: Allocator,
10261212 data: []const u8,
......@@ -1443,15 +1629,15 @@ const ElfDumper = struct {
14431629 const dynamic_section_label = "dynamic section";
14441630 const archive_symtab_label = "archive symbol table";
14451631
1446 fn parseAndDump(step: *Step, bytes: []const u8) ![]const u8 {
1447 const gpa = step.owner.allocator;
1448 return parseAndDumpArchive(gpa, bytes) catch |err| switch (err) {
1449 error.InvalidArchiveMagicNumber => try parseAndDumpObject(gpa, bytes),
1632 fn parseAndDump(step: *Step, kind: Check.Kind, bytes: []const u8) ![]const u8 {
1633 return parseAndDumpArchive(step, kind, bytes) catch |err| switch (err) {
1634 error.InvalidArchiveMagicNumber => try parseAndDumpObject(step, kind, bytes),
14501635 else => |e| return e,
14511636 };
14521637 }
14531638
1454 fn parseAndDumpArchive(gpa: Allocator, bytes: []const u8) ![]const u8 {
1639 fn parseAndDumpArchive(step: *Step, kind: Check.Kind, bytes: []const u8) ![]const u8 {
1640 const gpa = step.owner.allocator;
14551641 var stream = std.io.fixedBufferStream(bytes);
14561642 const reader = stream.reader();
14571643
......@@ -1512,8 +1698,15 @@ const ElfDumper = struct {
15121698 var output = std.ArrayList(u8).init(gpa);
15131699 const writer = output.writer();
15141700
1515 try ctx.dumpSymtab(writer);
1516 try ctx.dumpObjects(writer);
1701 switch (kind) {
1702 .archive_symtab => if (ctx.symtab.items.len > 0) {
1703 try ctx.dumpSymtab(writer);
1704 } else return step.fail("no archive symbol table found", .{}),
1705
1706 else => if (ctx.objects.items.len > 0) {
1707 try ctx.dumpObjects(step, kind, writer);
1708 } else return step.fail("empty archive", .{}),
1709 }
15171710
15181711 return output.toOwnedSlice();
15191712 }
......@@ -1555,8 +1748,6 @@ const ElfDumper = struct {
15551748 }
15561749
15571750 fn dumpSymtab(ctx: ArchiveContext, writer: anytype) !void {
1558 if (ctx.symtab.items.len == 0) return;
1559
15601751 var files = std.AutoHashMap(usize, []const u8).init(ctx.gpa);
15611752 defer files.deinit();
15621753 try files.ensureUnusedCapacity(@intCast(ctx.objects.items.len));
......@@ -1590,10 +1781,10 @@ const ElfDumper = struct {
15901781 }
15911782 }
15921783
1593 fn dumpObjects(ctx: ArchiveContext, writer: anytype) !void {
1784 fn dumpObjects(ctx: ArchiveContext, step: *Step, kind: Check.Kind, writer: anytype) !void {
15941785 for (ctx.objects.items) |object| {
15951786 try writer.print("object {s}\n", .{object.name});
1596 const output = try parseAndDumpObject(ctx.gpa, ctx.data[object.off..][0..object.len]);
1787 const output = try parseAndDumpObject(step, kind, ctx.data[object.off..][0..object.len]);
15971788 defer ctx.gpa.free(output);
15981789 try writer.print("{s}\n", .{output});
15991790 }
......@@ -1611,7 +1802,8 @@ const ElfDumper = struct {
16111802 };
16121803 };
16131804
1614 fn parseAndDumpObject(gpa: Allocator, bytes: []const u8) ![]const u8 {
1805 fn parseAndDumpObject(step: *Step, kind: Check.Kind, bytes: []const u8) ![]const u8 {
1806 const gpa = step.owner.allocator;
16151807 var stream = std.io.fixedBufferStream(bytes);
16161808 const reader = stream.reader();
16171809
......@@ -1663,12 +1855,27 @@ const ElfDumper = struct {
16631855 var output = std.ArrayList(u8).init(gpa);
16641856 const writer = output.writer();
16651857
1666 try ctx.dumpHeader(writer);
1667 try ctx.dumpShdrs(writer);
1668 try ctx.dumpPhdrs(writer);
1669 try ctx.dumpDynamicSection(writer);
1670 try ctx.dumpSymtab(.symtab, writer);
1671 try ctx.dumpSymtab(.dysymtab, writer);
1858 switch (kind) {
1859 .headers => {
1860 try ctx.dumpHeader(writer);
1861 try ctx.dumpShdrs(writer);
1862 try ctx.dumpPhdrs(writer);
1863 },
1864
1865 .symtab => if (ctx.symtab.symbols.len > 0) {
1866 try ctx.dumpSymtab(.symtab, writer);
1867 } else return step.fail("no symbol table found", .{}),
1868
1869 .dynamic_symtab => if (ctx.dysymtab.symbols.len > 0) {
1870 try ctx.dumpSymtab(.dysymtab, writer);
1871 } else return step.fail("no dynamic symbol table found", .{}),
1872
1873 .dynamic_section => if (ctx.getSectionByName(".dynamic")) |shndx| {
1874 try ctx.dumpDynamicSection(shndx, writer);
1875 } else return step.fail("no .dynamic section found", .{}),
1876
1877 else => return step.fail("invalid check kind for ELF file format: {s}", .{@tagName(kind)}),
1878 }
16721879
16731880 return output.toOwnedSlice();
16741881 }
......@@ -1680,8 +1887,8 @@ const ElfDumper = struct {
16801887 shdrs: []align(1) const elf.Elf64_Shdr,
16811888 phdrs: []align(1) const elf.Elf64_Phdr,
16821889 shstrtab: []const u8,
1683 symtab: ?Symtab = null,
1684 dysymtab: ?Symtab = null,
1890 symtab: Symtab = .{},
1891 dysymtab: Symtab = .{},
16851892
16861893 fn dumpHeader(ctx: ObjectContext, writer: anytype) !void {
16871894 try writer.writeAll("header\n");
......@@ -1745,8 +1952,7 @@ const ElfDumper = struct {
17451952 }
17461953 }
17471954
1748 fn dumpDynamicSection(ctx: ObjectContext, writer: anytype) !void {
1749 const shndx = ctx.getSectionByName(".dynamic") orelse return;
1955 fn dumpDynamicSection(ctx: ObjectContext, shndx: usize, writer: anytype) !void {
17501956 const shdr = ctx.shdrs[shndx];
17511957 const strtab = ctx.getSectionContents(shdr.sh_link);
17521958 const data = ctx.getSectionContents(shndx);
......@@ -1888,7 +2094,7 @@ const ElfDumper = struct {
18882094 const symtab = switch (@"type") {
18892095 .symtab => ctx.symtab,
18902096 .dysymtab => ctx.dysymtab,
1891 } orelse return;
2097 };
18922098
18932099 try writer.writeAll(switch (@"type") {
18942100 .symtab => symtab_label,
......@@ -1986,8 +2192,8 @@ const ElfDumper = struct {
19862192 };
19872193
19882194 const Symtab = struct {
1989 symbols: []align(1) const elf.Elf64_Sym,
1990 strings: []const u8,
2195 symbols: []align(1) const elf.Elf64_Sym = &[0]elf.Elf64_Sym{},
2196 strings: []const u8 = &[0]u8{},
19912197
19922198 fn get(st: Symtab, index: usize) ?elf.Elf64_Sym {
19932199 if (index >= st.symbols.len) return null;
......@@ -2090,7 +2296,7 @@ const ElfDumper = struct {
20902296const WasmDumper = struct {
20912297 const symtab_label = "symbols";
20922298
2093 fn parseAndDump(step: *Step, bytes: []const u8) ![]const u8 {
2299 fn parseAndDump(step: *Step, kind: Check.Kind, bytes: []const u8) ![]const u8 {
20942300 const gpa = step.owner.allocator;
20952301 var fbs = std.io.fixedBufferStream(bytes);
20962302 const reader = fbs.reader();
......@@ -2107,15 +2313,21 @@ const WasmDumper = struct {
21072313 errdefer output.deinit();
21082314 const writer = output.writer();
21092315
2110 while (reader.readByte()) |current_byte| {
2111 const section = std.meta.intToEnum(std.wasm.Section, current_byte) catch {
2112 return step.fail("Found invalid section id '{d}'", .{current_byte});
2113 };
2316 switch (kind) {
2317 .headers => {
2318 while (reader.readByte()) |current_byte| {
2319 const section = std.meta.intToEnum(std.wasm.Section, current_byte) catch {
2320 return step.fail("Found invalid section id '{d}'", .{current_byte});
2321 };
2322
2323 const section_length = try std.leb.readULEB128(u32, reader);
2324 try parseAndDumpSection(step, section, bytes[fbs.pos..][0..section_length], writer);
2325 fbs.pos += section_length;
2326 } else |_| {} // reached end of stream
2327 },
21142328
2115 const section_length = try std.leb.readULEB128(u32, reader);
2116 try parseAndDumpSection(step, section, bytes[fbs.pos..][0..section_length], writer);
2117 fbs.pos += section_length;
2118 } else |_| {} // reached end of stream
2329 else => return step.fail("invalid check kind for Wasm file format: {s}", .{@tagName(kind)}),
2330 }
21192331
21202332 return output.toOwnedSlice();
21212333 }
test/link/elf.zig+26-26
......@@ -506,7 +506,7 @@ fn testCopyrelAlignment(b: *Build, opts: Options) *Step {
506506 test_step.dependOn(&run.step);
507507
508508 const check = exe.checkObject();
509 check.checkStart();
509 check.checkInHeaders();
510510 check.checkExact("section headers");
511511 check.checkExact("name .copyrel");
512512 check.checkExact("addralign 20");
......@@ -525,7 +525,7 @@ fn testCopyrelAlignment(b: *Build, opts: Options) *Step {
525525 test_step.dependOn(&run.step);
526526
527527 const check = exe.checkObject();
528 check.checkStart();
528 check.checkInHeaders();
529529 check.checkExact("section headers");
530530 check.checkExact("name .copyrel");
531531 check.checkExact("addralign 8");
......@@ -544,7 +544,7 @@ fn testCopyrelAlignment(b: *Build, opts: Options) *Step {
544544 test_step.dependOn(&run.step);
545545
546546 const check = exe.checkObject();
547 check.checkStart();
547 check.checkInHeaders();
548548 check.checkExact("section headers");
549549 check.checkExact("name .copyrel");
550550 check.checkExact("addralign 100");
......@@ -815,7 +815,7 @@ fn testEntryPoint(b: *Build, opts: Options) *Step {
815815 exe.entry = .{ .symbol_name = "foo" };
816816
817817 const check = exe.checkObject();
818 check.checkStart();
818 check.checkInHeaders();
819819 check.checkExact("header");
820820 check.checkExact("entry 1000");
821821 test_step.dependOn(&check.step);
......@@ -831,7 +831,7 @@ fn testEntryPoint(b: *Build, opts: Options) *Step {
831831 exe.entry = .{ .symbol_name = "bar" };
832832
833833 const check = exe.checkObject();
834 check.checkStart();
834 check.checkInHeaders();
835835 check.checkExact("header");
836836 check.checkExact("entry 2000");
837837 test_step.dependOn(&check.step);
......@@ -1460,13 +1460,13 @@ fn testIFuncStaticPie(b: *Build, opts: Options) *Step {
14601460 test_step.dependOn(&run.step);
14611461
14621462 const check = exe.checkObject();
1463 check.checkStart();
1463 check.checkInHeaders();
14641464 check.checkExact("header");
14651465 check.checkExact("type DYN");
1466 check.checkStart();
1466 check.checkInHeaders();
14671467 check.checkExact("section headers");
14681468 check.checkExact("name .dynamic");
1469 check.checkStart();
1469 check.checkInHeaders();
14701470 check.checkExact("section headers");
14711471 check.checkNotPresent("name .interp");
14721472 test_step.dependOn(&check.step);
......@@ -1494,7 +1494,7 @@ fn testImageBase(b: *Build, opts: Options) *Step {
14941494 test_step.dependOn(&run.step);
14951495
14961496 const check = exe.checkObject();
1497 check.checkStart();
1497 check.checkInHeaders();
14981498 check.checkExact("header");
14991499 check.checkExtract("entry {addr}");
15001500 check.checkComputeCompare("addr", .{ .op = .gte, .value = .{ .literal = 0x8000000 } });
......@@ -1507,7 +1507,7 @@ fn testImageBase(b: *Build, opts: Options) *Step {
15071507 exe.image_base = 0xffffffff8000000;
15081508
15091509 const check = exe.checkObject();
1510 check.checkStart();
1510 check.checkInHeaders();
15111511 check.checkExact("header");
15121512 check.checkExtract("entry {addr}");
15131513 check.checkComputeCompare("addr", .{ .op = .gte, .value = .{ .literal = 0xffffffff8000000 } });
......@@ -1937,10 +1937,10 @@ fn testLinkingC(b: *Build, opts: Options) *Step {
19371937 test_step.dependOn(&run.step);
19381938
19391939 const check = exe.checkObject();
1940 check.checkStart();
1940 check.checkInHeaders();
19411941 check.checkExact("header");
19421942 check.checkExact("type EXEC");
1943 check.checkStart();
1943 check.checkInHeaders();
19441944 check.checkExact("section headers");
19451945 check.checkNotPresent("name .dynamic");
19461946 test_step.dependOn(&check.step);
......@@ -1967,10 +1967,10 @@ fn testLinkingCpp(b: *Build, opts: Options) *Step {
19671967 test_step.dependOn(&run.step);
19681968
19691969 const check = exe.checkObject();
1970 check.checkStart();
1970 check.checkInHeaders();
19711971 check.checkExact("header");
19721972 check.checkExact("type EXEC");
1973 check.checkStart();
1973 check.checkInHeaders();
19741974 check.checkExact("section headers");
19751975 check.checkNotPresent("name .dynamic");
19761976 test_step.dependOn(&check.step);
......@@ -2055,10 +2055,10 @@ fn testLinkingZig(b: *Build, opts: Options) *Step {
20552055 test_step.dependOn(&run.step);
20562056
20572057 const check = exe.checkObject();
2058 check.checkStart();
2058 check.checkInHeaders();
20592059 check.checkExact("header");
20602060 check.checkExact("type EXEC");
2061 check.checkStart();
2061 check.checkInHeaders();
20622062 check.checkExact("section headers");
20632063 check.checkNotPresent("name .dynamic");
20642064 test_step.dependOn(&check.step);
......@@ -2075,7 +2075,7 @@ fn testNoEhFrameHdr(b: *Build, opts: Options) *Step {
20752075 exe.linkLibC();
20762076
20772077 const check = exe.checkObject();
2078 check.checkStart();
2078 check.checkInHeaders();
20792079 check.checkExact("section headers");
20802080 check.checkNotPresent("name .eh_frame_hdr");
20812081 test_step.dependOn(&check.step);
......@@ -2103,10 +2103,10 @@ fn testPie(b: *Build, opts: Options) *Step {
21032103 test_step.dependOn(&run.step);
21042104
21052105 const check = exe.checkObject();
2106 check.checkStart();
2106 check.checkInHeaders();
21072107 check.checkExact("header");
21082108 check.checkExact("type DYN");
2109 check.checkStart();
2109 check.checkInHeaders();
21102110 check.checkExact("section headers");
21112111 check.checkExact("name .dynamic");
21122112 test_step.dependOn(&check.step);
......@@ -2326,13 +2326,13 @@ fn testRelocatableNoEhFrame(b: *Build, opts: Options) *Step {
23262326 obj2.addObject(obj1);
23272327
23282328 const check1 = obj1.checkObject();
2329 check1.checkStart();
2329 check1.checkInHeaders();
23302330 check1.checkExact("section headers");
23312331 check1.checkNotPresent(".eh_frame");
23322332 test_step.dependOn(&check1.step);
23332333
23342334 const check2 = obj2.checkObject();
2335 check2.checkStart();
2335 check2.checkInHeaders();
23362336 check2.checkExact("section headers");
23372337 check2.checkNotPresent(".eh_frame");
23382338 test_step.dependOn(&check2.step);
......@@ -2369,7 +2369,7 @@ fn testSharedAbsSymbol(b: *Build, opts: Options) *Step {
23692369 test_step.dependOn(&run.step);
23702370
23712371 const check = exe.checkObject();
2372 check.checkStart();
2372 check.checkInHeaders();
23732373 check.checkExact("header");
23742374 check.checkExact("type DYN");
23752375 // TODO fix/improve in CheckObject
......@@ -2390,7 +2390,7 @@ fn testSharedAbsSymbol(b: *Build, opts: Options) *Step {
23902390 // test_step.dependOn(&run.step);
23912391
23922392 // const check = exe.checkObject();
2393 // check.checkStart();
2393 // check.checkInHeaders();
23942394 // check.checkExact("header");
23952395 // check.checkExact("type EXEC");
23962396 // // TODO fix/improve in CheckObject
......@@ -2422,7 +2422,7 @@ fn testStrip(b: *Build, opts: Options) *Step {
24222422 exe.linkLibC();
24232423
24242424 const check = exe.checkObject();
2425 check.checkStart();
2425 check.checkInHeaders();
24262426 check.checkExact("section headers");
24272427 check.checkExact("name .debug_info");
24282428 test_step.dependOn(&check.step);
......@@ -2435,7 +2435,7 @@ fn testStrip(b: *Build, opts: Options) *Step {
24352435 exe.linkLibC();
24362436
24372437 const check = exe.checkObject();
2438 check.checkStart();
2438 check.checkInHeaders();
24392439 check.checkExact("section headers");
24402440 check.checkNotPresent("name .debug_info");
24412441 test_step.dependOn(&check.step);
......@@ -3521,7 +3521,7 @@ fn testZStackSize(b: *Build, opts: Options) *Step {
35213521 exe.linkLibC();
35223522
35233523 const check = exe.checkObject();
3524 check.checkStart();
3524 check.checkInHeaders();
35253525 check.checkExact("program headers");
35263526 check.checkExact("type GNU_STACK");
35273527 check.checkExact("memsz 800000");
test/link/macho/dead_strip_dylibs/build.zig+2-2
......@@ -19,11 +19,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
1919 const exe = createScenario(b, optimize, "no-dead-strip");
2020
2121 const check = exe.checkObject();
22 check.checkStart();
22 check.checkInHeaders();
2323 check.checkExact("cmd LOAD_DYLIB");
2424 check.checkContains("Cocoa");
2525
26 check.checkStart();
26 check.checkInHeaders();
2727 check.checkExact("cmd LOAD_DYLIB");
2828 check.checkContains("libobjc");
2929
test/link/macho/dylib/build.zig+3-3
......@@ -25,7 +25,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2525 dylib.linkLibC();
2626
2727 const check_dylib = dylib.checkObject();
28 check_dylib.checkStart();
28 check_dylib.checkInHeaders();
2929 check_dylib.checkExact("cmd ID_DYLIB");
3030 check_dylib.checkExact("name @rpath/liba.dylib");
3131 check_dylib.checkExact("timestamp 2");
......@@ -46,14 +46,14 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
4646 exe.linkLibC();
4747
4848 const check_exe = exe.checkObject();
49 check_exe.checkStart();
49 check_exe.checkInHeaders();
5050 check_exe.checkExact("cmd LOAD_DYLIB");
5151 check_exe.checkExact("name @rpath/liba.dylib");
5252 check_exe.checkExact("timestamp 2");
5353 check_exe.checkExact("current version 10000");
5454 check_exe.checkExact("compatibility version 10000");
5555
56 check_exe.checkStart();
56 check_exe.checkInHeaders();
5757 check_exe.checkExact("cmd RPATH");
5858 check_exe.checkExactPath("path", dylib.getOutputDirectorySource());
5959 test_step.dependOn(&check_exe.step);
test/link/macho/entry/build.zig+2-2
......@@ -24,11 +24,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2424
2525 const check_exe = exe.checkObject();
2626
27 check_exe.checkStart();
27 check_exe.checkInHeaders();
2828 check_exe.checkExact("segname __TEXT");
2929 check_exe.checkExtract("vmaddr {vmaddr}");
3030
31 check_exe.checkStart();
31 check_exe.checkInHeaders();
3232 check_exe.checkExact("cmd MAIN");
3333 check_exe.checkExtract("entryoff {entryoff}");
3434
test/link/macho/entry_in_dylib/build.zig+3-3
......@@ -34,15 +34,15 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
3434 exe.forceUndefinedSymbol("_my_main");
3535
3636 const check_exe = exe.checkObject();
37 check_exe.checkStart();
37 check_exe.checkInHeaders();
3838 check_exe.checkExact("segname __TEXT");
3939 check_exe.checkExtract("vmaddr {text_vmaddr}");
4040
41 check_exe.checkStart();
41 check_exe.checkInHeaders();
4242 check_exe.checkExact("sectname __stubs");
4343 check_exe.checkExtract("addr {stubs_vmaddr}");
4444
45 check_exe.checkStart();
45 check_exe.checkInHeaders();
4646 check_exe.checkExact("cmd MAIN");
4747 check_exe.checkExtract("entryoff {entryoff}");
4848
test/link/macho/headerpad/build.zig+4-4
......@@ -21,7 +21,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2121 exe.headerpad_max_install_names = true;
2222
2323 const check = exe.checkObject();
24 check.checkStart();
24 check.checkInHeaders();
2525 check.checkExact("sectname __text");
2626 check.checkExtract("offset {offset}");
2727
......@@ -47,7 +47,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
4747 exe.headerpad_size = 0x10000;
4848
4949 const check = exe.checkObject();
50 check.checkStart();
50 check.checkInHeaders();
5151 check.checkExact("sectname __text");
5252 check.checkExtract("offset {offset}");
5353 check.checkComputeCompare("offset", .{ .op = .gte, .value = .{ .literal = 0x10000 } });
......@@ -65,7 +65,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
6565 exe.headerpad_size = 0x10000;
6666
6767 const check = exe.checkObject();
68 check.checkStart();
68 check.checkInHeaders();
6969 check.checkExact("sectname __text");
7070 check.checkExtract("offset {offset}");
7171 check.checkComputeCompare("offset", .{ .op = .gte, .value = .{ .literal = 0x10000 } });
......@@ -83,7 +83,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
8383 exe.headerpad_max_install_names = true;
8484
8585 const check = exe.checkObject();
86 check.checkStart();
86 check.checkInHeaders();
8787 check.checkExact("sectname __text");
8888 check.checkExtract("offset {offset}");
8989
test/link/macho/needed_framework/build.zig+1-1
......@@ -26,7 +26,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2626 exe.dead_strip_dylibs = true;
2727
2828 const check = exe.checkObject();
29 check.checkStart();
29 check.checkInHeaders();
3030 check.checkExact("cmd LOAD_DYLIB");
3131 check.checkContains("Cocoa");
3232 test_step.dependOn(&check.step);
test/link/macho/needed_library/build.zig+1-1
......@@ -39,7 +39,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
3939 exe.dead_strip_dylibs = true;
4040
4141 const check = exe.checkObject();
42 check.checkStart();
42 check.checkInHeaders();
4343 check.checkExact("cmd LOAD_DYLIB");
4444 check.checkExact("name @rpath/liba.dylib");
4545 test_step.dependOn(&check.step);
test/link/macho/pagezero/build.zig+3-3
......@@ -20,13 +20,13 @@ pub fn build(b: *std.Build) void {
2020 exe.pagezero_size = 0x4000;
2121
2222 const check = exe.checkObject();
23 check.checkStart();
23 check.checkInHeaders();
2424 check.checkExact("LC 0");
2525 check.checkExact("segname __PAGEZERO");
2626 check.checkExact("vmaddr 0");
2727 check.checkExact("vmsize 4000");
2828
29 check.checkStart();
29 check.checkInHeaders();
3030 check.checkExact("segname __TEXT");
3131 check.checkExact("vmaddr 4000");
3232
......@@ -44,7 +44,7 @@ pub fn build(b: *std.Build) void {
4444 exe.pagezero_size = 0;
4545
4646 const check = exe.checkObject();
47 check.checkStart();
47 check.checkInHeaders();
4848 check.checkExact("LC 0");
4949 check.checkExact("segname __TEXT");
5050 check.checkExact("vmaddr 0");
test/link/macho/search_strategy/build.zig+1-1
......@@ -20,7 +20,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2020 const exe = createScenario(b, optimize, target, "search_dylibs_first", .mode_first);
2121
2222 const check = exe.checkObject();
23 check.checkStart();
23 check.checkInHeaders();
2424 check.checkExact("cmd LOAD_DYLIB");
2525 check.checkExact("name @rpath/libsearch_dylibs_first.dylib");
2626 test_step.dependOn(&check.step);
test/link/macho/stack_size/build.zig+1-1
......@@ -25,7 +25,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2525 exe.stack_size = 0x100000000;
2626
2727 const check_exe = exe.checkObject();
28 check_exe.checkStart();
28 check_exe.checkInHeaders();
2929 check_exe.checkExact("cmd MAIN");
3030 check_exe.checkExact("stacksize 100000000");
3131 test_step.dependOn(&check_exe.step);
test/link/macho/strict_validation/build.zig+7-7
......@@ -26,13 +26,13 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2626
2727 const check_exe = exe.checkObject();
2828
29 check_exe.checkStart();
29 check_exe.checkInHeaders();
3030 check_exe.checkExact("cmd SEGMENT_64");
3131 check_exe.checkExact("segname __LINKEDIT");
3232 check_exe.checkExtract("fileoff {fileoff}");
3333 check_exe.checkExtract("filesz {filesz}");
3434
35 check_exe.checkStart();
35 check_exe.checkInHeaders();
3636 check_exe.checkExact("cmd DYLD_INFO_ONLY");
3737 check_exe.checkExtract("rebaseoff {rebaseoff}");
3838 check_exe.checkExtract("rebasesize {rebasesize}");
......@@ -43,31 +43,31 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
4343 check_exe.checkExtract("exportoff {exportoff}");
4444 check_exe.checkExtract("exportsize {exportsize}");
4545
46 check_exe.checkStart();
46 check_exe.checkInHeaders();
4747 check_exe.checkExact("cmd FUNCTION_STARTS");
4848 check_exe.checkExtract("dataoff {fstartoff}");
4949 check_exe.checkExtract("datasize {fstartsize}");
5050
51 check_exe.checkStart();
51 check_exe.checkInHeaders();
5252 check_exe.checkExact("cmd DATA_IN_CODE");
5353 check_exe.checkExtract("dataoff {diceoff}");
5454 check_exe.checkExtract("datasize {dicesize}");
5555
56 check_exe.checkStart();
56 check_exe.checkInHeaders();
5757 check_exe.checkExact("cmd SYMTAB");
5858 check_exe.checkExtract("symoff {symoff}");
5959 check_exe.checkExtract("nsyms {symnsyms}");
6060 check_exe.checkExtract("stroff {stroff}");
6161 check_exe.checkExtract("strsize {strsize}");
6262
63 check_exe.checkStart();
63 check_exe.checkInHeaders();
6464 check_exe.checkExact("cmd DYSYMTAB");
6565 check_exe.checkExtract("indirectsymoff {dysymoff}");
6666 check_exe.checkExtract("nindirectsyms {dysymnsyms}");
6767
6868 switch (builtin.cpu.arch) {
6969 .aarch64 => {
70 check_exe.checkStart();
70 check_exe.checkInHeaders();
7171 check_exe.checkExact("cmd CODE_SIGNATURE");
7272 check_exe.checkExtract("dataoff {codesigoff}");
7373 check_exe.checkExtract("datasize {codesigsize}");
test/link/macho/unwind_info/build.zig+1-1
......@@ -32,7 +32,7 @@ fn testUnwindInfo(
3232 exe.link_gc_sections = dead_strip;
3333
3434 const check = exe.checkObject();
35 check.checkStart();
35 check.checkInHeaders();
3636 check.checkExact("segname __TEXT");
3737 check.checkExact("sectname __gcc_except_tab");
3838 check.checkExact("sectname __unwind_info");
test/link/macho/weak_framework/build.zig+1-1
......@@ -23,7 +23,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2323 exe.linkFrameworkWeak("Cocoa");
2424
2525 const check = exe.checkObject();
26 check.checkStart();
26 check.checkInHeaders();
2727 check.checkExact("cmd LOAD_WEAK_DYLIB");
2828 check.checkContains("Cocoa");
2929 test_step.dependOn(&check.step);
test/link/macho/weak_library/build.zig+1-1
......@@ -37,7 +37,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
3737 exe.addRPath(dylib.getEmittedBinDirectory());
3838
3939 const check = exe.checkObject();
40 check.checkStart();
40 check.checkInHeaders();
4141 check.checkExact("cmd LOAD_WEAK_DYLIB");
4242 check.checkExact("name @rpath/liba.dylib");
4343
test/link/wasm/archive/build.zig+1-1
......@@ -27,7 +27,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2727 lib.strip = false;
2828
2929 const check = lib.checkObject();
30 check.checkStart();
30 check.checkInHeaders();
3131 check.checkExact("Section custom");
3232 check.checkExact("name __trunch"); // Ensure it was imported and resolved
3333
test/link/wasm/basic-features/build.zig+1-1
......@@ -21,7 +21,7 @@ pub fn build(b: *std.Build) void {
2121
2222 // Verify the result contains the features explicitly set on the target for the library.
2323 const check = lib.checkObject();
24 check.checkStart();
24 check.checkInHeaders();
2525 check.checkExact("name target_features");
2626 check.checkExact("features 1");
2727 check.checkExact("+ atomics");
test/link/wasm/bss/build.zig+4-4
......@@ -31,18 +31,18 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt
3131 const check_lib = lib.checkObject();
3232
3333 // since we import memory, make sure it exists with the correct naming
34 check_lib.checkStart();
34 check_lib.checkInHeaders();
3535 check_lib.checkExact("Section import");
3636 check_lib.checkExact("entries 1");
3737 check_lib.checkExact("module env"); // default module name is "env"
3838 check_lib.checkExact("name memory"); // as per linker specification
3939
4040 // since we are importing memory, ensure it's not exported
41 check_lib.checkStart();
41 check_lib.checkInHeaders();
4242 check_lib.checkNotPresent("Section export");
4343
4444 // validate the name of the stack pointer
45 check_lib.checkStart();
45 check_lib.checkInHeaders();
4646 check_lib.checkExact("Section custom");
4747 check_lib.checkExact("type data_segment");
4848 check_lib.checkExact("names 2");
......@@ -77,7 +77,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt
7777 lib.link_gc_sections = false;
7878
7979 const check_lib = lib.checkObject();
80 check_lib.checkStart();
80 check_lib.checkInHeaders();
8181 check_lib.checkExact("Section custom");
8282 check_lib.checkExact("type data_segment");
8383 check_lib.checkExact("names 2");
test/link/wasm/export-data/build.zig+2-2
......@@ -22,7 +22,7 @@ pub fn build(b: *std.Build) void {
2222
2323 const check_lib = lib.checkObject();
2424
25 check_lib.checkStart();
25 check_lib.checkInHeaders();
2626 check_lib.checkExact("Section global");
2727 check_lib.checkExact("entries 3");
2828 check_lib.checkExact("type i32"); // stack pointer so skip other fields
......@@ -35,7 +35,7 @@ pub fn build(b: *std.Build) void {
3535 check_lib.checkComputeCompare("foo_address", .{ .op = .eq, .value = .{ .literal = 4 } });
3636 check_lib.checkComputeCompare("bar_address", .{ .op = .eq, .value = .{ .literal = 0 } });
3737
38 check_lib.checkStart();
38 check_lib.checkInHeaders();
3939 check_lib.checkExact("Section export");
4040 check_lib.checkExact("entries 3");
4141 check_lib.checkExact("name foo");
test/link/wasm/export/build.zig+3-3
......@@ -46,21 +46,21 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
4646 force_export.use_lld = false;
4747
4848 const check_no_export = no_export.checkObject();
49 check_no_export.checkStart();
49 check_no_export.checkInHeaders();
5050 check_no_export.checkExact("Section export");
5151 check_no_export.checkExact("entries 1");
5252 check_no_export.checkExact("name memory");
5353 check_no_export.checkExact("kind memory");
5454
5555 const check_dynamic_export = dynamic_export.checkObject();
56 check_dynamic_export.checkStart();
56 check_dynamic_export.checkInHeaders();
5757 check_dynamic_export.checkExact("Section export");
5858 check_dynamic_export.checkExact("entries 2");
5959 check_dynamic_export.checkExact("name foo");
6060 check_dynamic_export.checkExact("kind function");
6161
6262 const check_force_export = force_export.checkObject();
63 check_force_export.checkStart();
63 check_force_export.checkInHeaders();
6464 check_force_export.checkExact("Section export");
6565 check_force_export.checkExact("entries 2");
6666 check_force_export.checkExact("name foo");
test/link/wasm/extern-mangle/build.zig+1-1
......@@ -22,7 +22,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2222 lib.rdynamic = true; // export `foo`
2323
2424 const check_lib = lib.checkObject();
25 check_lib.checkStart();
25 check_lib.checkInHeaders();
2626 check_lib.checkExact("Section import");
2727 check_lib.checkExact("entries 2"); // a.hello & b.hello
2828 check_lib.checkExact("module a");
test/link/wasm/function-table/build.zig+4-4
......@@ -52,7 +52,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
5252 const check_export = export_table.checkObject();
5353 const check_regular = regular_table.checkObject();
5454
55 check_import.checkStart();
55 check_import.checkInHeaders();
5656 check_import.checkExact("Section import");
5757 check_import.checkExact("entries 1");
5858 check_import.checkExact("module env");
......@@ -63,20 +63,20 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
6363 check_import.checkNotPresent("max"); // when importing, we do not provide a max
6464 check_import.checkNotPresent("Section table"); // we're importing it
6565
66 check_export.checkStart();
66 check_export.checkInHeaders();
6767 check_export.checkExact("Section export");
6868 check_export.checkExact("entries 2");
6969 check_export.checkExact("name __indirect_function_table"); // as per linker specification
7070 check_export.checkExact("kind table");
7171
72 check_regular.checkStart();
72 check_regular.checkInHeaders();
7373 check_regular.checkExact("Section table");
7474 check_regular.checkExact("entries 1");
7575 check_regular.checkExact("type funcref");
7676 check_regular.checkExact("min 2"); // index starts at 1 & 1 function pointer = 2.
7777 check_regular.checkExact("max 2");
7878
79 check_regular.checkStart();
79 check_regular.checkInHeaders();
8080 check_regular.checkExact("Section element");
8181 check_regular.checkExact("entries 1");
8282 check_regular.checkExact("table index 0");
test/link/wasm/infer-features/build.zig+1-1
......@@ -34,7 +34,7 @@ pub fn build(b: *std.Build) void {
3434
3535 // Verify the result contains the features from the C Object file.
3636 const check = lib.checkObject();
37 check.checkStart();
37 check.checkInHeaders();
3838 check.checkExact("name target_features");
3939 check.checkExact("features 7");
4040 check.checkExact("+ atomics");
test/link/wasm/producers/build.zig+1-1
......@@ -29,7 +29,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2929 const version_fmt = "version " ++ builtin.zig_version_string;
3030
3131 const check_lib = lib.checkObject();
32 check_lib.checkStart();
32 check_lib.checkInHeaders();
3333 check_lib.checkExact("name producers");
3434 check_lib.checkExact("fields 2");
3535 check_lib.checkExact("field_name language");
test/link/wasm/segments/build.zig+4-4
......@@ -27,15 +27,15 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2727 b.installArtifact(lib);
2828
2929 const check_lib = lib.checkObject();
30 check_lib.checkStart();
30 check_lib.checkInHeaders();
3131 check_lib.checkExact("Section data");
3232 check_lib.checkExact("entries 2"); // rodata & data, no bss because we're exporting memory
3333
34 check_lib.checkStart();
34 check_lib.checkInHeaders();
3535 check_lib.checkExact("Section custom");
36 check_lib.checkStart();
36 check_lib.checkInHeaders();
3737 check_lib.checkExact("name name"); // names custom section
38 check_lib.checkStart();
38 check_lib.checkInHeaders();
3939 check_lib.checkExact("type data_segment");
4040 check_lib.checkExact("names 2");
4141 check_lib.checkExact("index 0");
test/link/wasm/stack_pointer/build.zig+3-3
......@@ -30,7 +30,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
3030 const check_lib = lib.checkObject();
3131
3232 // ensure global exists and its initial value is equal to explitic stack size
33 check_lib.checkStart();
33 check_lib.checkInHeaders();
3434 check_lib.checkExact("Section global");
3535 check_lib.checkExact("entries 1");
3636 check_lib.checkExact("type i32"); // on wasm32 the stack pointer must be i32
......@@ -39,13 +39,13 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
3939 check_lib.checkComputeCompare("stack_pointer", .{ .op = .eq, .value = .{ .literal = lib.stack_size.? } });
4040
4141 // validate memory section starts after virtual stack
42 check_lib.checkStart();
42 check_lib.checkInHeaders();
4343 check_lib.checkExact("Section data");
4444 check_lib.checkExtract("i32.const {data_start}");
4545 check_lib.checkComputeCompare("data_start", .{ .op = .eq, .value = .{ .variable = "stack_pointer" } });
4646
4747 // validate the name of the stack pointer
48 check_lib.checkStart();
48 check_lib.checkInHeaders();
4949 check_lib.checkExact("Section custom");
5050 check_lib.checkExact("type global");
5151 check_lib.checkExact("names 1");
test/link/wasm/type/build.zig+1-1
......@@ -26,7 +26,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2626 b.installArtifact(lib);
2727
2828 const check_lib = lib.checkObject();
29 check_lib.checkStart();
29 check_lib.checkInHeaders();
3030 check_lib.checkExact("Section type");
3131 // only 2 entries, although we have more functions.
3232 // This is to test functions with the same function signature
test/standalone/ios/build.zig+1-1
......@@ -30,7 +30,7 @@ pub fn build(b: *std.Build) void {
3030 exe.linkLibC();
3131
3232 const check = exe.checkObject();
33 check.checkStart();
33 check.checkInHeaders();
3434 check.checkExact("cmd BUILD_VERSION");
3535 check.checkExact("platform IOS");
3636 test_step.dependOn(&check.step);