authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2021-05-12 22:39:10+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-13 00:44:56-04:00
log459c9f05359e3405f39e4c954c62c61a493e49ae
treebbb88d1dd59b9699f1f58f948412fc63f694695e
parent799d1f0d36f69c8aead5184a76f87b557d690d7b

stage2: fix build on OpenBSD/NetBSD

Apparently these systems do not provide libdl or librt.

2 files changed, 22 insertions(+), 9 deletions(-)

src/link/Elf.zig+1-9
...@@ -1650,15 +1650,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {...@@ -1650,15 +1650,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
1650 if (self.base.options.libc_installation != null) {1650 if (self.base.options.libc_installation != null) {
1651 const needs_grouping = self.base.options.link_mode == .Static;1651 const needs_grouping = self.base.options.link_mode == .Static;
1652 if (needs_grouping) try argv.append("--start-group");1652 if (needs_grouping) try argv.append("--start-group");
1653 // This matches the order of glibc.libs1653 try argv.appendSlice(target_util.libcFullLinkFlags(target));
1654 try argv.appendSlice(&[_][]const u8{
1655 "-lm",
1656 "-lpthread",
1657 "-lc",
1658 "-ldl",
1659 "-lrt",
1660 "-lutil",
1661 });
1662 if (needs_grouping) try argv.append("--end-group");1654 if (needs_grouping) try argv.append("--end-group");
1663 } else if (target.isGnuLibC()) {1655 } else if (target.isGnuLibC()) {
1664 try argv.append(comp.libunwind_static_lib.?.full_object_path);1656 try argv.append(comp.libunwind_static_lib.?.full_object_path);
src/target.zig+21
...@@ -374,3 +374,24 @@ pub fn hasRedZone(target: std.Target) bool {...@@ -374,3 +374,24 @@ pub fn hasRedZone(target: std.Target) bool {
374 else => false,374 else => false,
375 };375 };
376}376}
377
378pub fn libcFullLinkFlags(target: std.Target) []const []const u8 {
379 // The linking order of these is significant and should match the order other
380 // c compilers such as gcc or clang use.
381 return switch (target.os.tag) {
382 .netbsd, .openbsd => &[_][]const u8{
383 "-lm",
384 "-lpthread",
385 "-lc",
386 "-lutil",
387 },
388 else => &[_][]const u8{
389 "-lm",
390 "-lpthread",
391 "-lc",
392 "-ldl",
393 "-lrt",
394 "-lutil",
395 },
396 };
397}