commit f607126614ab249dbf8f965ca0911fda560bc580 (tree)
parent 0de5dd2ef144a5a53c5bdbf1d8e45c1d2becd47b
Author: Jakub Konka <kubkon@jakubkonka.com>
Date: Thu, 9 Nov 2023 11:49:04 +0100
test/link/elf: verify we can output a valid relocatable with .eh_frame section
Diffstat:
1 file changed, 43 insertions(+), 0 deletions(-)
diff --git 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 <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() << 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);