aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2023-11-09 11:49:04 +0100
committerJakub Konka <kubkon@jakubkonka.com>2023-11-09 11:49:04 +0100
commitf607126614ab249dbf8f965ca0911fda560bc580 (patch)
treef97a48cfada0db7ae0d07cddbf992af16affb714 /test
parent0de5dd2ef144a5a53c5bdbf1d8e45c1d2becd47b (diff)
downloadzig-f607126614ab249dbf8f965ca0911fda560bc580.tar.gz
zig-f607126614ab249dbf8f965ca0911fda560bc580.zip
test/link/elf: verify we can output a valid relocatable with .eh_frame section
Diffstat (limited to 'test')
-rw-r--r--test/link/elf.zig43
1 files changed, 43 insertions, 0 deletions
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 <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);