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

This commit is contained in:
Jakub Konka 2023-11-09 23:22:47 +01:00
parent 08882234d1
commit 73fd4ed54b

View File

@ -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;
}