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 {...@@ -83,6 +83,7 @@ const MatchAction = struct {
83 if (closing_brace != needle_tok.len - 1) return error.ClosingBraceNotLast;83 if (closing_brace != needle_tok.len - 1) return error.ClosingBraceNotLast;
8484
85 const name = needle_tok[1..closing_brace];85 const name = needle_tok[1..closing_brace];
86 if (name.len == 0) return error.MissingBraceValue;
86 const value = try std.fmt.parseInt(u64, hay_tok, 16);87 const value = try std.fmt.parseInt(u64, hay_tok, 16);
87 try global_vars.putNoClobber(name, value);88 try global_vars.putNoClobber(name, value);
88 } else {89 } else {
...@@ -135,13 +136,13 @@ const Check = struct {...@@ -135,13 +136,13 @@ const Check = struct {
135};136};
136137
137/// Creates a new sequence of actions with `phrase` as the first anchor searched phrase.138/// 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 {
139 var new_check = Check.create(self.builder);140 var new_check = Check.create(self.builder);
140 new_check.match(phrase);141 new_check.match(phrase);
141 self.checks.append(new_check) catch unreachable;142 self.checks.append(new_check) catch unreachable;
142}143}
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(...)`.
145/// Asserts at least one check already exists.146/// Asserts at least one check already exists.
146pub fn checkNext(self: *CheckObjectStep, phrase: []const u8) void {147pub fn checkNext(self: *CheckObjectStep, phrase: []const u8) void {
147 assert(self.checks.items.len > 0);148 assert(self.checks.items.len > 0);
...@@ -154,7 +155,11 @@ pub fn checkNext(self: *CheckObjectStep, phrase: []const u8) void {...@@ -154,7 +155,11 @@ pub fn checkNext(self: *CheckObjectStep, phrase: []const u8) void {
154/// Issuing this check will force parsing and dumping of the symbol table.155/// Issuing this check will force parsing and dumping of the symbol table.
155pub fn checkInSymtab(self: *CheckObjectStep) void {156pub fn checkInSymtab(self: *CheckObjectStep) void {
156 self.dump_symtab = true;157 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);
158}163}
159164
160/// Creates a new standalone, singular check which allows running simple binary operations165/// Creates a new standalone, singular check which allows running simple binary operations
...@@ -274,6 +279,8 @@ const Opts = struct {...@@ -274,6 +279,8 @@ const Opts = struct {
274};279};
275280
276const MachODumper = struct {281const MachODumper = struct {
282 const symtab_label = "symtab";
283
277 fn parseAndDump(bytes: []const u8, opts: Opts) ![]const u8 {284 fn parseAndDump(bytes: []const u8, opts: Opts) ![]const u8 {
278 const gpa = opts.gpa orelse unreachable; // MachO dumper requires an allocator285 const gpa = opts.gpa orelse unreachable; // MachO dumper requires an allocator
279 var stream = std.io.fixedBufferStream(bytes);286 var stream = std.io.fixedBufferStream(bytes);
...@@ -301,7 +308,7 @@ const MachODumper = struct {...@@ -301,7 +308,7 @@ const MachODumper = struct {
301 }308 }
302309
303 if (symtab_cmd) |cmd| {310 if (symtab_cmd) |cmd| {
304 try writer.writeAll("symtab\n");311 try writer.writeAll(symtab_label ++ "\n");
305 const strtab = bytes[cmd.stroff..][0..cmd.strsize];312 const strtab = bytes[cmd.stroff..][0..cmd.strsize];
306 const raw_symtab = bytes[cmd.symoff..][0 .. cmd.nsyms * @sizeOf(macho.nlist_64)];313 const raw_symtab = bytes[cmd.symoff..][0 .. cmd.nsyms * @sizeOf(macho.nlist_64)];
307 const symtab = mem.bytesAsSlice(macho.nlist_64, raw_symtab);314 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 {...@@ -14,7 +14,7 @@ pub fn build(b: *Builder) void {
14 dylib.install();14 dylib.install();
1515
16 const check_dylib = dylib.checkObject(.macho);16 const check_dylib = dylib.checkObject(.macho);
17 check_dylib.check("cmd ID_DYLIB");17 check_dylib.checkStart("cmd ID_DYLIB");
18 check_dylib.checkNext("name @rpath/liba.dylib");18 check_dylib.checkNext("name @rpath/liba.dylib");
19 check_dylib.checkNext("timestamp 2");19 check_dylib.checkNext("timestamp 2");
20 check_dylib.checkNext("current version 10000");20 check_dylib.checkNext("current version 10000");
...@@ -31,13 +31,13 @@ pub fn build(b: *Builder) void {...@@ -31,13 +31,13 @@ pub fn build(b: *Builder) void {
31 exe.addRPath(b.pathFromRoot("zig-out/lib"));31 exe.addRPath(b.pathFromRoot("zig-out/lib"));
3232
33 const check_exe = exe.checkObject(.macho);33 const check_exe = exe.checkObject(.macho);
34 check_exe.check("cmd LOAD_DYLIB");34 check_exe.checkStart("cmd LOAD_DYLIB");
35 check_exe.checkNext("name @rpath/liba.dylib");35 check_exe.checkNext("name @rpath/liba.dylib");
36 check_exe.checkNext("timestamp 2");36 check_exe.checkNext("timestamp 2");
37 check_exe.checkNext("current version 10000");37 check_exe.checkNext("current version 10000");
38 check_exe.checkNext("compatibility version 10000");38 check_exe.checkNext("compatibility version 10000");
3939
40 check_exe.check("cmd RPATH");40 check_exe.checkStart("cmd RPATH");
41 check_exe.checkNext(std.fmt.allocPrint(b.allocator, "path {s}", .{b.pathFromRoot("zig-out/lib")}) catch unreachable);41 check_exe.checkNext(std.fmt.allocPrint(b.allocator, "path {s}", .{b.pathFromRoot("zig-out/lib")}) catch unreachable);
4242
43 test_step.dependOn(&check_exe.step);43 test_step.dependOn(&check_exe.step);
test/link/macho/entry/build.zig+2-2
...@@ -15,10 +15,10 @@ pub fn build(b: *Builder) void {...@@ -15,10 +15,10 @@ pub fn build(b: *Builder) void {
1515
16 const check_exe = exe.checkObject(.macho);16 const check_exe = exe.checkObject(.macho);
1717
18 check_exe.check("segname __TEXT");18 check_exe.checkStart("segname __TEXT");
19 check_exe.checkNext("vmaddr {vmaddr}");19 check_exe.checkNext("vmaddr {vmaddr}");
2020
21 check_exe.check("cmd MAIN");21 check_exe.checkStart("cmd MAIN");
22 check_exe.checkNext("entryoff {entryoff}");22 check_exe.checkNext("entryoff {entryoff}");
2323
24 check_exe.checkInSymtab();24 check_exe.checkInSymtab();
test/link/macho/frameworks/build.zig+2-2
...@@ -14,12 +14,12 @@ pub fn build(b: *Builder) void {...@@ -14,12 +14,12 @@ pub fn build(b: *Builder) void {
14 exe.linkFramework("Cocoa");14 exe.linkFramework("Cocoa");
1515
16 const check = exe.checkObject(.macho);16 const check = exe.checkObject(.macho);
17 check.check("cmd LOAD_DYLIB");17 check.checkStart("cmd LOAD_DYLIB");
18 check.checkNext("name {*}Cocoa");18 check.checkNext("name {*}Cocoa");
1919
20 switch (mode) {20 switch (mode) {
21 .Debug, .ReleaseSafe => {21 .Debug, .ReleaseSafe => {
22 check.check("cmd LOAD_DYLIB");22 check.checkStart("cmd LOAD_DYLIB");
23 check.checkNext("name {*}libobjc{*}.dylib");23 check.checkNext("name {*}libobjc{*}.dylib");
24 },24 },
25 else => {},25 else => {},
test/link/macho/pagezero/build.zig+3-3
...@@ -15,12 +15,12 @@ pub fn build(b: *Builder) void {...@@ -15,12 +15,12 @@ pub fn build(b: *Builder) void {
15 exe.pagezero_size = 0x4000;15 exe.pagezero_size = 0x4000;
1616
17 const check = exe.checkObject(.macho);17 const check = exe.checkObject(.macho);
18 check.check("LC 0");18 check.checkStart("LC 0");
19 check.checkNext("segname __PAGEZERO");19 check.checkNext("segname __PAGEZERO");
20 check.checkNext("vmaddr 0");20 check.checkNext("vmaddr 0");
21 check.checkNext("vmsize 4000");21 check.checkNext("vmsize 4000");
2222
23 check.check("segname __TEXT");23 check.checkStart("segname __TEXT");
24 check.checkNext("vmaddr 4000");24 check.checkNext("vmaddr 4000");
2525
26 test_step.dependOn(&check.step);26 test_step.dependOn(&check.step);
...@@ -34,7 +34,7 @@ pub fn build(b: *Builder) void {...@@ -34,7 +34,7 @@ pub fn build(b: *Builder) void {
34 exe.pagezero_size = 0;34 exe.pagezero_size = 0;
3535
36 const check = exe.checkObject(.macho);36 const check = exe.checkObject(.macho);
37 check.check("LC 0");37 check.checkStart("LC 0");
38 check.checkNext("segname __TEXT");38 check.checkNext("segname __TEXT");
39 check.checkNext("vmaddr 0");39 check.checkNext("vmaddr 0");
4040
test/link/macho/stack_size/build.zig+1-1
...@@ -14,7 +14,7 @@ pub fn build(b: *Builder) void {...@@ -14,7 +14,7 @@ pub fn build(b: *Builder) void {
14 exe.stack_size = 0x100000000;14 exe.stack_size = 0x100000000;
1515
16 const check_exe = exe.checkObject(.macho);16 const check_exe = exe.checkObject(.macho);
17 check_exe.check("cmd MAIN");17 check_exe.checkStart("cmd MAIN");
18 check_exe.checkNext("stacksize 100000000");18 check_exe.checkNext("stacksize 100000000");
1919
20 test_step.dependOn(&check_exe.step);20 test_step.dependOn(&check_exe.step);