diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2022-07-23 00:01:09 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-23 00:01:09 -0700 |
| commit | a8bfddfaeae4f48c044fd134aac1e977e6a161f8 (patch) | |
| tree | 4b1b000767ba641f5ca7f7c40aa17e29991e9114 /lib/std/build/CheckObjectStep.zig | |
| parent | a035d75a1750e59e43bb9122f33d8586ed1ee385 (diff) | |
| parent | cf6cfc830db89e0031200d1a16c93eb7801cb911 (diff) | |
| download | zig-a8bfddfaeae4f48c044fd134aac1e977e6a161f8.tar.gz zig-a8bfddfaeae4f48c044fd134aac1e977e6a161f8.zip | |
Merge pull request #12140 from ziglang/macho-gc-sections
macho: add support for `-dead_strip` (GC sections) and simplify symbol resolution
Diffstat (limited to 'lib/std/build/CheckObjectStep.zig')
| -rw-r--r-- | lib/std/build/CheckObjectStep.zig | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/lib/std/build/CheckObjectStep.zig b/lib/std/build/CheckObjectStep.zig index cb91f883c9..b807e1de45 100644 --- a/lib/std/build/CheckObjectStep.zig +++ b/lib/std/build/CheckObjectStep.zig @@ -50,7 +50,7 @@ pub fn create(builder: *Builder, source: build.FileSource, obj_format: std.Targe /// For example, if the two extracted values were saved as `vmaddr` and `entryoff` respectively /// they could then be added with this simple program `vmaddr entryoff +`. const Action = struct { - tag: enum { match, compute_cmp }, + tag: enum { match, not_present, compute_cmp }, phrase: []const u8, expected: ?ComputeCompareExpected = null, @@ -63,7 +63,7 @@ const Action = struct { /// name {*}libobjc{*}.dylib => will match `name` followed by a token which contains `libobjc` and `.dylib` /// in that order with other letters in between fn match(act: Action, haystack: []const u8, global_vars: anytype) !bool { - assert(act.tag == .match); + assert(act.tag == .match or act.tag == .not_present); var candidate_var: ?struct { name: []const u8, value: u64 } = null; var hay_it = mem.tokenize(u8, mem.trim(u8, haystack, " "), " "); @@ -202,6 +202,13 @@ const Check = struct { }) catch unreachable; } + fn notPresent(self: *Check, phrase: []const u8) void { + self.actions.append(.{ + .tag = .not_present, + .phrase = self.builder.dupe(phrase), + }) catch unreachable; + } + fn computeCmp(self: *Check, phrase: []const u8, expected: ComputeCompareExpected) void { self.actions.append(.{ .tag = .compute_cmp, @@ -226,6 +233,15 @@ pub fn checkNext(self: *CheckObjectStep, phrase: []const u8) void { last.match(phrase); } +/// Adds another searched phrase to the latest created Check with `CheckObjectStep.checkStart(...)` +/// however ensures there is no matching phrase in the output. +/// Asserts at least one check already exists. +pub fn checkNotPresent(self: *CheckObjectStep, phrase: []const u8) void { + assert(self.checks.items.len > 0); + const last = &self.checks.items[self.checks.items.len - 1]; + last.notPresent(phrase); +} + /// Creates a new check checking specifically symbol table parsed and dumped from the object /// file. /// Issuing this check will force parsing and dumping of the symbol table. @@ -293,6 +309,21 @@ fn make(step: *Step) !void { return error.TestFailed; } }, + .not_present => { + while (it.next()) |line| { + if (try act.match(line, &vars)) { + std.debug.print( + \\ + \\========= Expected not to find: =================== + \\{s} + \\========= But parsed file does contain it: ======== + \\{s} + \\ + , .{ act.phrase, output }); + return error.TestFailed; + } + } + }, .compute_cmp => { const res = act.computeCmp(gpa, vars) catch |err| switch (err) { error.UnknownVariable => { |
