Commit cbcd67ea90

Andrew Kelley <andrew@ziglang.org>
2024-10-16 23:38:46
link.MachO: fix missing input classification
1 parent 65d4208
Changed files (2)
src/link/MachO.zig
@@ -447,15 +447,25 @@ pub fn flushModule(self: *MachO, arena: Allocator, tid: Zcu.PerThread.Id, prog_n
     };
 
     for (system_libs.items) |lib| {
-        const dso_input = try link.openDsoInput(diags, lib.path, lib.needed, lib.weak, lib.reexport);
-        self.classifyInputFile(dso_input) catch |err|
-            diags.addParseError(lib.path, "failed to parse input file: {s}", .{@errorName(err)});
+        switch (Compilation.classifyFileExt(lib.path.sub_path)) {
+            .shared_library => {
+                const dso_input = try link.openDsoInput(diags, lib.path, lib.needed, lib.weak, lib.reexport);
+                self.classifyInputFile(dso_input) catch |err|
+                    diags.addParseError(lib.path, "failed to parse input file: {s}", .{@errorName(err)});
+            },
+            .static_library => {
+                const archive_input = try link.openArchiveInput(diags, lib.path, lib.must_link, lib.hidden);
+                self.classifyInputFile(archive_input) catch |err|
+                    diags.addParseError(lib.path, "failed to parse input file: {s}", .{@errorName(err)});
+            },
+            else => unreachable,
+        }
     }
 
     // Finally, link against compiler_rt.
     if (comp.compiler_rt_lib) |crt_file| {
         const path = crt_file.full_object_path;
-        self.classifyInputFile(try link.openArchiveInput(diags, path)) catch |err|
+        self.classifyInputFile(try link.openArchiveInput(diags, path, false, false)) catch |err|
             diags.addParseError(path, "failed to parse archive: {s}", .{@errorName(err)});
     } else if (comp.compiler_rt_obj) |crt_file| {
         const path = crt_file.full_object_path;
src/link.zig
@@ -1997,8 +1997,8 @@ pub fn openObjectInput(diags: *Diags, path: Path) error{LinkFailure}!Input {
     } };
 }
 
-pub fn openArchiveInput(diags: *Diags, path: Path) error{LinkFailure}!Input {
-    return .{ .archive = openObject(path, false, false) catch |err| {
+pub fn openArchiveInput(diags: *Diags, path: Path, must_link: bool, hidden: bool) error{LinkFailure}!Input {
+    return .{ .archive = openObject(path, must_link, hidden) catch |err| {
         return diags.failParse(path, "failed to open {}: {s}", .{ path, @errorName(err) });
     } };
 }