From 8b9627f01d44b94fad744f6d515dc32438130628 Mon Sep 17 00:00:00 2001 From: kcbanner Date: Thu, 27 Jul 2023 02:53:40 -0400 Subject: [PATCH] test: add a test that verifies no debug handlers get pulled into compiler_rt build: fix CheckObject checkNotPresent only checking a single line of the haystack --- lib/std/Build/Step/CheckObject.zig | 3 +-- test/standalone.zig | 4 ++++ test/standalone/compiler_rt_panic/build.zig | 26 +++++++++++++++++++++ test/standalone/compiler_rt_panic/main.c | 11 +++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 test/standalone/compiler_rt_panic/build.zig create mode 100644 test/standalone/compiler_rt_panic/main.c diff --git a/lib/std/Build/Step/CheckObject.zig b/lib/std/Build/Step/CheckObject.zig index 5a816b4103..e79468ec9b 100644 --- a/lib/std/Build/Step/CheckObject.zig +++ b/lib/std/Build/Step/CheckObject.zig @@ -478,8 +478,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { }, .not_present => { while (it.next()) |line| { - if (act.notPresent(b, step, line)) break; - } else { + if (act.notPresent(b, step, line)) continue; return step.fail( \\ \\========= expected not to find: =================== diff --git a/test/standalone.zig b/test/standalone.zig index 7cbe452934..3725456fa1 100644 --- a/test/standalone.zig +++ b/test/standalone.zig @@ -241,6 +241,10 @@ pub const build_cases = [_]BuildCase{ .build_root = "test/standalone/coff_dwarf", .import = @import("standalone/coff_dwarf/build.zig"), }, + .{ + .build_root = "test/standalone/compiler_rt_panic", + .import = @import("standalone/compiler_rt_panic/build.zig"), + }, }; const std = @import("std"); diff --git a/test/standalone/compiler_rt_panic/build.zig b/test/standalone/compiler_rt_panic/build.zig new file mode 100644 index 0000000000..9bfe7f73fa --- /dev/null +++ b/test/standalone/compiler_rt_panic/build.zig @@ -0,0 +1,26 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const test_step = b.step("test", "Test it"); + b.default_step = test_step; + + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + if (target.getObjectFormat() != .elf) return; + + const exe = b.addExecutable(.{ + .name = "main", + .optimize = optimize, + .target = target, + }); + exe.addCSourceFile("main.c", &.{}); + exe.link_gc_sections = false; + exe.bundle_compiler_rt = true; + + // Verify compiler_rt hasn't pulled in any debug handlers + const check_exe = exe.checkObject(); + check_exe.checkInSymtab(); + check_exe.checkNotPresent("debug.readElfDebugInfo"); + test_step.dependOn(&check_exe.step); +} diff --git a/test/standalone/compiler_rt_panic/main.c b/test/standalone/compiler_rt_panic/main.c new file mode 100644 index 0000000000..be64216ab7 --- /dev/null +++ b/test/standalone/compiler_rt_panic/main.c @@ -0,0 +1,11 @@ +#include + +void* __memset(void* dest, char c, size_t n, size_t dest_n); + +char foo[128]; + +int main() { + __memset(&foo[0], 0xff, 128, 128); + return foo[64]; +} +