Commit 459c9f0535
Changed files (2)
src
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",
+ },
+ };
+}