aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2024-01-15 10:32:25 +0100
committerJakub Konka <kubkon@jakubkonka.com>2024-01-24 12:34:40 +0100
commit4cf94bb14869641316f337903ab24eef52eb7899 (patch)
tree9474291a637ab95d9d60810a38f7beed3348c334
parent4dc1907a88c950daa8273ed4db1b46f7537e20fc (diff)
downloadzig-4cf94bb14869641316f337903ab24eef52eb7899.tar.gz
zig-4cf94bb14869641316f337903ab24eef52eb7899.zip
test/link/macho: test attribute "used" on vars in presence of dead_strip
-rw-r--r--test/link/macho.zig27
1 files changed, 27 insertions, 0 deletions
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);