| author | |
| committer | |
| log | 03ddb42b8bb96815c1bb4b857ffdfb94191ab861 |
| tree | 8a1cf269d06b18d137ff13fc1d6b8f5aa4193871 |
| parent | 6e04c2faabf4d632f80fa97ccbb0a20ad42a5e9f |
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; |
| 84 | 84 | ||
| 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 | }; |
| 136 | 137 | ||
| 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. |
| 138 | pub fn check(self: *CheckObjectStep, phrase: []const u8) void { | 139 | pub 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 | } |
| 143 | 144 | ||
| 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. |
| 146 | pub fn checkNext(self: *CheckObjectStep, phrase: []const u8) void { | 147 | pub 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. |
| 155 | pub fn checkInSymtab(self: *CheckObjectStep) void { | 156 | pub 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 | } |
| 159 | 164 | ||
| 160 | /// Creates a new standalone, singular check which allows running simple binary operations | 165 | /// 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 | }; |
| 275 | 280 | ||
| 276 | const MachODumper = struct { | 281 | const 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 allocator | 285 | 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 | } |
| 302 | 309 | ||
| 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(); |
| 15 | 15 | ||
| 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")); |
| 32 | 32 | ||
| 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"); |
| 39 | 39 | ||
| 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); |
| 42 | 42 | ||
| 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 { |
| 15 | 15 | ||
| 16 | const check_exe = exe.checkObject(.macho); | 16 | const check_exe = exe.checkObject(.macho); |
| 17 | 17 | ||
| 18 | check_exe.check("segname __TEXT"); | 18 | check_exe.checkStart("segname __TEXT"); |
| 19 | check_exe.checkNext("vmaddr {vmaddr}"); | 19 | check_exe.checkNext("vmaddr {vmaddr}"); |
| 20 | 20 | ||
| 21 | check_exe.check("cmd MAIN"); | 21 | check_exe.checkStart("cmd MAIN"); |
| 22 | check_exe.checkNext("entryoff {entryoff}"); | 22 | check_exe.checkNext("entryoff {entryoff}"); |
| 23 | 23 | ||
| 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"); |
| 15 | 15 | ||
| 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"); |
| 19 | 19 | ||
| 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; |
| 16 | 16 | ||
| 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"); |
| 22 | 22 | ||
| 23 | check.check("segname __TEXT"); | 23 | check.checkStart("segname __TEXT"); |
| 24 | check.checkNext("vmaddr 4000"); | 24 | check.checkNext("vmaddr 4000"); |
| 25 | 25 | ||
| 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; |
| 35 | 35 | ||
| 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"); |
| 40 | 40 |
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; |
| 15 | 15 | ||
| 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"); |
| 19 | 19 | ||
| 20 | test_step.dependOn(&check_exe.step); | 20 | test_step.dependOn(&check_exe.step); |