Commit 727d9431c8

Jakub Konka <kubkon@jakubkonka.com>
2023-10-04 12:20:28
elf: link hello-world in c++
1 parent d6cec5a
Changed files (1)
src
link
src/link/Elf.zig
@@ -1140,6 +1140,18 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
 
     var system_libs = std.ArrayList(SystemLib).init(arena);
 
+    // libc++ dep
+    if (self.base.options.link_libcpp) {
+        try system_libs.ensureUnusedCapacity(2);
+        system_libs.appendAssumeCapacity(.{ .path = comp.libcxxabi_static_lib.?.full_object_path });
+        system_libs.appendAssumeCapacity(.{ .path = comp.libcxx_static_lib.?.full_object_path });
+    }
+
+    // libunwind dep
+    if (self.base.options.link_libunwind) {
+        try system_libs.append(.{ .path = comp.libunwind_static_lib.?.full_object_path });
+    }
+
     // libc dep
     self.error_flags.missing_libc = false;
     if (self.base.options.link_libc) {
@@ -1240,7 +1252,6 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
         self.files.set(index, .{ .linker_defined = .{ .index = index } });
         self.linker_defined_index = index;
     }
-    try self.addLinkerDefinedSymbols();
 
     // Now, we are ready to resolve the symbols across all input files.
     // We will first resolve the files in the ZigModule, next in the parsed
@@ -1248,6 +1259,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
     // Any qualifing unresolved symbol will be upgraded to an absolute, weak
     // symbol for potential resolution at load-time.
     self.resolveSymbols();
+    try self.addLinkerDefinedSymbols();
     self.markEhFrameAtomsDead();
     self.markImportsExports();
     self.claimUnresolved();