authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-05-11 12:43:58+02:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-05-11 12:43:58+02:00
log2bb8e1ff550ef2b2676e4f7ec3fdaf17aee8d715
tree968872435a832f456ba52d54ac51c9b1c5dc0939
parent780f510ac0137512ad2923835e4ecdb22a81028e

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.

2 files changed, 7 insertions(+), 11 deletions(-)

src/glibc.zig+2-1
......@@ -40,10 +40,11 @@ pub const ABI = struct {
4040 }
4141};
4242
43// The order of the elements in this array defines the linking order.
4344pub const libs = [_]Lib{
44 .{ .name = "c", .sover = 6 },
4545 .{ .name = "m", .sover = 6 },
4646 .{ .name = "pthread", .sover = 0 },
47 .{ .name = "c", .sover = 6 },
4748 .{ .name = "dl", .sover = 2 },
4849 .{ .name = "rt", .sover = 1 },
4950 .{ .name = "ld", .sover = 2 },
src/link/Elf.zig+5-10
......@@ -1648,17 +1648,12 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
16481648 // libc dep
16491649 if (self.base.options.link_libc) {
16501650 if (self.base.options.libc_installation != null) {
1651 if (self.base.options.link_mode == .Static) {
1652 try argv.append("--start-group");
1653 try argv.append("-lc");
1654 try argv.append("-lm");
1655 try argv.append("--end-group");
1656 } else {
1657 try argv.append("-lc");
1658 try argv.append("-lm");
1659 }
1660
1651 const needs_grouping = self.base.options.link_mode == .Static;
1652 if (needs_grouping) try argv.append("--start-group");
1653 try argv.append("-lm");
16611654 try argv.append("-lpthread");
1655 try argv.append("-lc");
1656 if (needs_grouping) try argv.append("--end-group");
16621657 } else if (target.isGnuLibC()) {
16631658 try argv.append(comp.libunwind_static_lib.?.full_object_path);
16641659 for (glibc.libs) |lib| {