stage2: fix build on OpenBSD/NetBSD

Apparently these systems do not provide libdl or librt.
This commit is contained in:
Isaac Freund
2021-05-12 22:39:10 +02:00
committed by Andrew Kelley
parent 799d1f0d36
commit 459c9f0535
2 changed files with 22 additions and 9 deletions

View File

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

View File

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