authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-06-23 12:56:28+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-06-23 13:16:03+02:00
log03ddb42b8bb96815c1bb4b857ffdfb94191ab861
tree8a1cf269d06b18d137ff13fc1d6b8f5aa4193871
parent6e04c2faabf4d632f80fa97ccbb0a20ad42a5e9f

link-tests: rename check() to checkStart()

Do not hardcode the symtab label; instead allow each parser to define its own. Check for missing extractor value in the matcher when matching `{}`.

6 files changed, 22 insertions(+), 15 deletions(-)

lib/std/build/CheckObjectStep.zig+11-4
......@@ -83,6 +83,7 @@ const MatchAction = struct {
8383 if (closing_brace != needle_tok.len - 1) return error.ClosingBraceNotLast;
8484
8585 const name = needle_tok[1..closing_brace];
86 if (name.len == 0) return error.MissingBraceValue;
8687 const value = try std.fmt.parseInt(u64, hay_tok, 16);
8788 try global_vars.putNoClobber(name, value);
8889 } else {
......@@ -135,13 +136,13 @@ const Check = struct {
135136};
136137
137138/// Creates a new sequence of actions with `phrase` as the first anchor searched phrase.
138pub fn check(self: *CheckObjectStep, phrase: []const u8) void {
139pub fn checkStart(self: *CheckObjectStep, phrase: []const u8) void {
139140 var new_check = Check.create(self.builder);
140141 new_check.match(phrase);
141142 self.checks.append(new_check) catch unreachable;
142143}
143144
144/// Adds another searched phrase to the latest created Check with `CheckObjectStep.check(...)`.
145/// Adds another searched phrase to the latest created Check with `CheckObjectStep.checkStart(...)`.
145146/// Asserts at least one check already exists.
146147pub fn checkNext(self: *CheckObjectStep, phrase: []const u8) void {
147148 assert(self.checks.items.len > 0);
......@@ -154,7 +155,11 @@ pub fn checkNext(self: *CheckObjectStep, phrase: []const u8) void {
154155/// Issuing this check will force parsing and dumping of the symbol table.
155156pub fn checkInSymtab(self: *CheckObjectStep) void {
156157 self.dump_symtab = true;
157 self.check("symtab");
158 const symtab_label = switch (self.obj_format) {
159 .macho => MachODumper.symtab_label,
160 else => @panic("TODO other parsers"),
161 };
162 self.checkStart(symtab_label);
158163}
159164
160165/// Creates a new standalone, singular check which allows running simple binary operations
......@@ -274,6 +279,8 @@ const Opts = struct {
274279};
275280
276281const MachODumper = struct {
282 const symtab_label = "symtab";
283
277284 fn parseAndDump(bytes: []const u8, opts: Opts) ![]const u8 {
278285 const gpa = opts.gpa orelse unreachable; // MachO dumper requires an allocator
279286 var stream = std.io.fixedBufferStream(bytes);
......@@ -301,7 +308,7 @@ const MachODumper = struct {
301308 }
302309
303310 if (symtab_cmd) |cmd| {
304 try writer.writeAll("symtab\n");
311 try writer.writeAll(symtab_label ++ "\n");
305312 const strtab = bytes[cmd.stroff..][0..cmd.strsize];
306313 const raw_symtab = bytes[cmd.symoff..][0 .. cmd.nsyms * @sizeOf(macho.nlist_64)];
307314 const symtab = mem.bytesAsSlice(macho.nlist_64, raw_symtab);
test/link/macho/dylib/build.zig+3-3
......@@ -14,7 +14,7 @@ pub fn build(b: *Builder) void {
1414 dylib.install();
1515
1616 const check_dylib = dylib.checkObject(.macho);
17 check_dylib.check("cmd ID_DYLIB");
17 check_dylib.checkStart("cmd ID_DYLIB");
1818 check_dylib.checkNext("name @rpath/liba.dylib");
1919 check_dylib.checkNext("timestamp 2");
2020 check_dylib.checkNext("current version 10000");
......@@ -31,13 +31,13 @@ pub fn build(b: *Builder) void {
3131 exe.addRPath(b.pathFromRoot("zig-out/lib"));
3232
3333 const check_exe = exe.checkObject(.macho);
34 check_exe.check("cmd LOAD_DYLIB");
34 check_exe.checkStart("cmd LOAD_DYLIB");
3535 check_exe.checkNext("name @rpath/liba.dylib");
3636 check_exe.checkNext("timestamp 2");
3737 check_exe.checkNext("current version 10000");
3838 check_exe.checkNext("compatibility version 10000");
3939
40 check_exe.check("cmd RPATH");
40 check_exe.checkStart("cmd RPATH");
4141 check_exe.checkNext(std.fmt.allocPrint(b.allocator, "path {s}", .{b.pathFromRoot("zig-out/lib")}) catch unreachable);
4242
4343 test_step.dependOn(&check_exe.step);
test/link/macho/entry/build.zig+2-2
......@@ -15,10 +15,10 @@ pub fn build(b: *Builder) void {
1515
1616 const check_exe = exe.checkObject(.macho);
1717
18 check_exe.check("segname __TEXT");
18 check_exe.checkStart("segname __TEXT");
1919 check_exe.checkNext("vmaddr {vmaddr}");
2020
21 check_exe.check("cmd MAIN");
21 check_exe.checkStart("cmd MAIN");
2222 check_exe.checkNext("entryoff {entryoff}");
2323
2424 check_exe.checkInSymtab();
test/link/macho/frameworks/build.zig+2-2
......@@ -14,12 +14,12 @@ pub fn build(b: *Builder) void {
1414 exe.linkFramework("Cocoa");
1515
1616 const check = exe.checkObject(.macho);
17 check.check("cmd LOAD_DYLIB");
17 check.checkStart("cmd LOAD_DYLIB");
1818 check.checkNext("name {*}Cocoa");
1919
2020 switch (mode) {
2121 .Debug, .ReleaseSafe => {
22 check.check("cmd LOAD_DYLIB");
22 check.checkStart("cmd LOAD_DYLIB");
2323 check.checkNext("name {*}libobjc{*}.dylib");
2424 },
2525 else => {},
test/link/macho/pagezero/build.zig+3-3
......@@ -15,12 +15,12 @@ pub fn build(b: *Builder) void {
1515 exe.pagezero_size = 0x4000;
1616
1717 const check = exe.checkObject(.macho);
18 check.check("LC 0");
18 check.checkStart("LC 0");
1919 check.checkNext("segname __PAGEZERO");
2020 check.checkNext("vmaddr 0");
2121 check.checkNext("vmsize 4000");
2222
23 check.check("segname __TEXT");
23 check.checkStart("segname __TEXT");
2424 check.checkNext("vmaddr 4000");
2525
2626 test_step.dependOn(&check.step);
......@@ -34,7 +34,7 @@ pub fn build(b: *Builder) void {
3434 exe.pagezero_size = 0;
3535
3636 const check = exe.checkObject(.macho);
37 check.check("LC 0");
37 check.checkStart("LC 0");
3838 check.checkNext("segname __TEXT");
3939 check.checkNext("vmaddr 0");
4040
test/link/macho/stack_size/build.zig+1-1
......@@ -14,7 +14,7 @@ pub fn build(b: *Builder) void {
1414 exe.stack_size = 0x100000000;
1515
1616 const check_exe = exe.checkObject(.macho);
17 check_exe.check("cmd MAIN");
17 check_exe.checkStart("cmd MAIN");
1818 check_exe.checkNext("stacksize 100000000");
1919
2020 test_step.dependOn(&check_exe.step);