From 22948616ff8da42f9ae9d7b292d80a01537f2a7e Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 21 Oct 2024 17:17:06 -0700 Subject: [PATCH] split a fat test case --- test/link/elf.zig | 152 +++++++++++++++++++++++----------------------- 1 file changed, 77 insertions(+), 75 deletions(-) diff --git a/test/link/elf.zig b/test/link/elf.zig index 63359aa33b..9a324c0502 100644 --- a/test/link/elf.zig +++ b/test/link/elf.zig @@ -51,6 +51,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step { elf_step.dependOn(testEmitRelocatable(b, .{ .target = musl_target })); elf_step.dependOn(testRelocatableArchive(b, .{ .target = musl_target })); elf_step.dependOn(testRelocatableEhFrame(b, .{ .target = musl_target })); + elf_step.dependOn(testRelocatableEhFrameComdatHeavy(b, .{ .target = musl_target })); elf_step.dependOn(testRelocatableNoEhFrame(b, .{ .target = musl_target })); // Exercise linker in ar mode @@ -2723,86 +2724,87 @@ fn testRelocatableArchive(b: *Build, opts: Options) *Step { fn testRelocatableEhFrame(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "relocatable-eh-frame", opts); - { - const obj = addObject(b, opts, .{ - .name = "obj1", - .cpp_source_bytes = - \\#include - \\int try_me() { - \\ throw std::runtime_error("Oh no!"); - \\} - , - }); - addCppSourceBytes(obj, - \\extern int try_me(); - \\int try_again() { - \\ return try_me(); - \\} - , &.{}); - obj.linkLibCpp(); + const obj = addObject(b, opts, .{ + .name = "obj1", + .cpp_source_bytes = + \\#include + \\int try_me() { + \\ throw std::runtime_error("Oh no!"); + \\} + , + }); + addCppSourceBytes(obj, + \\extern int try_me(); + \\int try_again() { + \\ return try_me(); + \\} + , &.{}); + obj.linkLibCpp(); - const exe = addExecutable(b, opts, .{ .name = "test1" }); - addCppSourceBytes(exe, - \\#include - \\#include - \\extern int try_again(); - \\int main() { - \\ try { - \\ try_again(); - \\ } catch (const std::exception &e) { - \\ std::cout << "exception=" << e.what(); - \\ } - \\ return 0; - \\} - , &.{}); - exe.addObject(obj); - exe.linkLibCpp(); + const exe = addExecutable(b, opts, .{ .name = "test1" }); + addCppSourceBytes(exe, + \\#include + \\#include + \\extern int try_again(); + \\int main() { + \\ try { + \\ try_again(); + \\ } catch (const std::exception &e) { + \\ std::cout << "exception=" << e.what(); + \\ } + \\ return 0; + \\} + , &.{}); + exe.addObject(obj); + exe.linkLibCpp(); - const run = addRunArtifact(exe); - run.expectStdOutEqual("exception=Oh no!"); - test_step.dependOn(&run.step); - } + const run = addRunArtifact(exe); + run.expectStdOutEqual("exception=Oh no!"); + test_step.dependOn(&run.step); - { - // Let's make the object file COMDAT group heavy! - const obj = addObject(b, opts, .{ - .name = "obj2", - .cpp_source_bytes = - \\#include - \\int try_me() { - \\ throw std::runtime_error("Oh no!"); - \\} - , - }); - addCppSourceBytes(obj, - \\extern int try_me(); - \\int try_again() { - \\ return try_me(); - \\} - , &.{}); - addCppSourceBytes(obj, - \\#include - \\#include - \\extern int try_again(); - \\int main() { - \\ try { - \\ try_again(); - \\ } catch (const std::exception &e) { - \\ std::cout << "exception=" << e.what(); - \\ } - \\ return 0; - \\} - , &.{}); - obj.linkLibCpp(); + return test_step; +} - const exe = addExecutable(b, opts, .{ .name = "test2" }); - exe.addObject(obj); - exe.linkLibCpp(); +fn testRelocatableEhFrameComdatHeavy(b: *Build, opts: Options) *Step { + const test_step = addTestStep(b, "relocatable-eh-frame-comdat-heavy", opts); - const run = addRunArtifact(exe); - run.expectStdOutEqual("exception=Oh no!"); - test_step.dependOn(&run.step); - } + const obj = addObject(b, opts, .{ + .name = "obj2", + .cpp_source_bytes = + \\#include + \\int try_me() { + \\ throw std::runtime_error("Oh no!"); + \\} + , + }); + addCppSourceBytes(obj, + \\extern int try_me(); + \\int try_again() { + \\ return try_me(); + \\} + , &.{}); + addCppSourceBytes(obj, + \\#include + \\#include + \\extern int try_again(); + \\int main() { + \\ try { + \\ try_again(); + \\ } catch (const std::exception &e) { + \\ std::cout << "exception=" << e.what(); + \\ } + \\ return 0; + \\} + , &.{}); + obj.linkLibCpp(); + + const exe = addExecutable(b, opts, .{ .name = "test2" }); + exe.addObject(obj); + exe.linkLibCpp(); + + const run = addRunArtifact(exe); + run.expectStdOutEqual("exception=Oh no!"); + test_step.dependOn(&run.step); return test_step; }