From 4cf94bb14869641316f337903ab24eef52eb7899 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Mon, 15 Jan 2024 10:32:25 +0100 Subject: [PATCH] test/link/macho: test attribute "used" on vars in presence of dead_strip --- test/link/macho.zig | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/link/macho.zig b/test/link/macho.zig index 03c3b71c59..7b87448d58 100644 --- a/test/link/macho.zig +++ b/test/link/macho.zig @@ -25,6 +25,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step { macho_step.dependOn(testLargeBss(b, .{ .target = default_target })); macho_step.dependOn(testLayout(b, .{ .target = default_target })); macho_step.dependOn(testMhExecuteHeader(b, .{ .target = default_target })); + macho_step.dependOn(testNoDeadStrip(b, .{ .target = default_target })); macho_step.dependOn(testRelocatable(b, .{ .target = default_target })); macho_step.dependOn(testRelocatableZig(b, .{ .target = default_target })); macho_step.dependOn(testSectionBoundarySymbols(b, .{ .target = default_target })); @@ -745,6 +746,32 @@ fn testMhExecuteHeader(b: *Build, opts: Options) *Step { return test_step; } +fn testNoDeadStrip(b: *Build, opts: Options) *Step { + const test_step = addTestStep(b, "macho-no-dead-strip", opts); + + const exe = addExecutable(b, opts, .{ .name = "name", .c_source_bytes = + \\__attribute__((used)) int bogus1 = 0; + \\int bogus2 = 0; + \\int foo = 42; + \\int main() { + \\ return foo - 42; + \\} + }); + exe.link_gc_sections = true; + + const check = exe.checkObject(); + check.checkInSymtab(); + check.checkContains("external _bogus1"); + check.checkInSymtab(); + check.checkNotPresent("external _bogus2"); + test_step.dependOn(&check.step); + + const run = addRunArtifact(exe); + test_step.dependOn(&run.step); + + return test_step; +} + fn testNeededFramework(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "macho-needed-framework", opts);