Commit 459c9f0535

Isaac Freund <ifreund@ifreund.xyz>
2021-05-12 22:39:10
stage2: fix build on OpenBSD/NetBSD
Apparently these systems do not provide libdl or librt.
1 parent 799d1f0
Changed files (2)
src/link/Elf.zig
@@ -1650,15 +1650,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
                 if (self.base.options.libc_installation != null) {
                     const needs_grouping = self.base.options.link_mode == .Static;
                     if (needs_grouping) try argv.append("--start-group");
-                    // This matches the order of glibc.libs
-                    try argv.appendSlice(&[_][]const u8{
-                        "-lm",
-                        "-lpthread",
-                        "-lc",
-                        "-ldl",
-                        "-lrt",
-                        "-lutil",
-                    });
+                    try argv.appendSlice(target_util.libcFullLinkFlags(target));
                     if (needs_grouping) try argv.append("--end-group");
                 } else if (target.isGnuLibC()) {
                     try argv.append(comp.libunwind_static_lib.?.full_object_path);
src/target.zig
@@ -374,3 +374,24 @@ pub fn hasRedZone(target: std.Target) bool {
         else => false,
     };
 }
+
+pub fn libcFullLinkFlags(target: std.Target) []const []const u8 {
+    // The linking order of these is significant and should match the order other
+    // c compilers such as gcc or clang use.
+    return switch (target.os.tag) {
+        .netbsd, .openbsd => &[_][]const u8{
+            "-lm",
+            "-lpthread",
+            "-lc",
+            "-lutil",
+        },
+        else => &[_][]const u8{
+            "-lm",
+            "-lpthread",
+            "-lc",
+            "-ldl",
+            "-lrt",
+            "-lutil",
+        },
+    };
+}