Commit 8b9627f01d

kcbanner <kcbanner@gmail.com>
2023-07-27 08:53:40
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
1 parent 78449b6
Changed files (4)
lib
std
Build
test
standalone
compiler_rt_panic
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: ===================
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);
+}
test/standalone/compiler_rt_panic/main.c
@@ -0,0 +1,11 @@
+#include <stddef.h>
+
+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];
+}
+
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");