zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 73fd4ed54b639bfd4d8a142102b54762d290763e (tree)
parent 08882234d17a93dd44181323db697db993aebe3d
Author: Jakub Konka <kubkon@jakubkonka.com>
Date:   Thu,  9 Nov 2023 23:22:47 +0100

test/link/elf: make .eh_frame relocatable test also verify COMDATs we emit

Diffstat:
Mtest/link/elf.zig | 107++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------
1 file changed, 74 insertions(+), 33 deletions(-)

diff --git 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 <stdexcept> - \\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 <stdexcept> + \\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 <iostream> - \\#include <stdexcept> - \\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 <iostream> + \\#include <stdexcept> + \\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 <stdexcept> + \\int try_me() { + \\ throw std::runtime_error("Oh no!"); + \\} + , &.{}); + addCppSourceBytes(obj, + \\extern int try_me(); + \\int try_again() { + \\ return try_me(); + \\} + , &.{}); + addCppSourceBytes(obj, + \\#include <iostream> + \\#include <stdexcept> + \\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; }