From f607126614ab249dbf8f965ca0911fda560bc580 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Thu, 9 Nov 2023 11:49:04 +0100 Subject: [PATCH] test/link/elf: verify we can output a valid relocatable with .eh_frame section --- test/link/elf.zig | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/test/link/elf.zig b/test/link/elf.zig index 24a4b941fb..4ab7df288c 100644 --- a/test/link/elf.zig +++ b/test/link/elf.zig @@ -24,6 +24,7 @@ pub fn build(b: *Build) void { // Exercise linker in -r mode elf_step.dependOn(testEmitRelocatable(b, .{ .use_llvm = false, .target = musl_target })); elf_step.dependOn(testEmitRelocatable(b, .{ .target = musl_target })); + elf_step.dependOn(testRelocatableEhFrame(b, .{ .target = musl_target })); // Exercise linker in ar mode elf_step.dependOn(testEmitStaticLib(b, .{ .target = musl_target })); @@ -2139,6 +2140,48 @@ fn testPreinitArray(b: *Build, opts: Options) *Step { return test_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 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() << std::endl; + \\ } + \\ return 0; + \\} + , &.{}); + exe.addObject(obj); + exe.linkLibCpp(); + + const run = addRunArtifact(exe); + run.expectStdOutEqual("exception=Oh no!"); + test_step.dependOn(&run.step); + + return test_step; +} + fn testSharedAbsSymbol(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "shared-abs-symbol", opts);