Commit 73fd4ed54b

Jakub Konka <kubkon@jakubkonka.com>
2023-11-09 23:22:47
test/link/elf: make .eh_frame relocatable test also verify COMDATs we emit
1 parent 0888223
Changed files (1)
test
link
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;
 }