From 73fd4ed54b639bfd4d8a142102b54762d290763e Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Thu, 9 Nov 2023 23:22:47 +0100 Subject: [PATCH] test/link/elf: make .eh_frame relocatable test also verify COMDATs we emit --- test/link/elf.zig | 107 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 74 insertions(+), 33 deletions(-) diff --git a/test/link/elf.zig b/test/link/elf.zig index f458fbb8de..09847e382c 100644 --- a/test/link/elf.zig +++ b/test/link/elf.zig @@ -2143,41 +2143,82 @@ fn testPreinitArray(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, "obj", opts); - addCppSourceBytes(obj, - \\#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, "obj1", opts); + addCppSourceBytes(obj, + \\#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, "test", opts); - 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, "test1", opts); + 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, "obj2", opts); + addCppSourceBytes(obj, + \\#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, "test2", opts); + exe.addObject(obj); + exe.linkLibCpp(); + + const run = addRunArtifact(exe); + run.expectStdOutEqual("exception=Oh no!"); + test_step.dependOn(&run.step); + } return test_step; }