zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 2bb8e1ff550ef2b2676e4f7ec3fdaf17aee8d715 (tree)
parent 780f510ac0137512ad2923835e4ecdb22a81028e
Author: LemonBoy <thatlemon@gmail.com>
Date:   Tue, 11 May 2021 12:43:58 +0200

stage2: Change libc components' linking order

Use the same order as Clang (and, by extension, GCC) for the three most
important libc components: lm comes first, followed by lpthread and then
lc.

Diffstat:
Msrc/glibc.zig | 3++-
Msrc/link/Elf.zig | 15+++++----------
2 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/src/glibc.zig b/src/glibc.zig @@ -40,10 +40,11 @@ pub const ABI = struct { } }; +// The order of the elements in this array defines the linking order. pub const libs = [_]Lib{ - .{ .name = "c", .sover = 6 }, .{ .name = "m", .sover = 6 }, .{ .name = "pthread", .sover = 0 }, + .{ .name = "c", .sover = 6 }, .{ .name = "dl", .sover = 2 }, .{ .name = "rt", .sover = 1 }, .{ .name = "ld", .sover = 2 }, diff --git a/src/link/Elf.zig b/src/link/Elf.zig @@ -1648,17 +1648,12 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void { // libc dep if (self.base.options.link_libc) { if (self.base.options.libc_installation != null) { - if (self.base.options.link_mode == .Static) { - try argv.append("--start-group"); - try argv.append("-lc"); - try argv.append("-lm"); - try argv.append("--end-group"); - } else { - try argv.append("-lc"); - try argv.append("-lm"); - } - + const needs_grouping = self.base.options.link_mode == .Static; + if (needs_grouping) try argv.append("--start-group"); + try argv.append("-lm"); try argv.append("-lpthread"); + try argv.append("-lc"); + if (needs_grouping) try argv.append("--end-group"); } else if (target.isGnuLibC()) { try argv.append(comp.libunwind_static_lib.?.full_object_path); for (glibc.libs) |lib| {