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 {...@@ -40,10 +40,11 @@ pub const ABI = struct {
40 }40 }
41};41};
4242
43// The order of the elements in this array defines the linking order.
43pub const libs = [_]Lib{44pub const libs = [_]Lib{
44 .{ .name = "c", .sover = 6 },
45 .{ .name = "m", .sover = 6 },45 .{ .name = "m", .sover = 6 },
46 .{ .name = "pthread", .sover = 0 },46 .{ .name = "pthread", .sover = 0 },
47 .{ .name = "c", .sover = 6 },
47 .{ .name = "dl", .sover = 2 },48 .{ .name = "dl", .sover = 2 },
48 .{ .name = "rt", .sover = 1 },49 .{ .name = "rt", .sover = 1 },
49 .{ .name = "ld", .sover = 2 },50 .{ .name = "ld", .sover = 2 },
src/link/Elf.zig+5-10
...@@ -1648,17 +1648,12 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {...@@ -1648,17 +1648,12 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
1648 // libc dep1648 // libc dep
1649 if (self.base.options.link_libc) {1649 if (self.base.options.link_libc) {
1650 if (self.base.options.libc_installation != null) {1650 if (self.base.options.libc_installation != null) {
1651 if (self.base.options.link_mode == .Static) {1651 const needs_grouping = self.base.options.link_mode == .Static;
1652 try argv.append("--start-group");1652 if (needs_grouping) try argv.append("--start-group");
1653 try argv.append("-lc");1653 try argv.append("-lm");
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
1661 try argv.append("-lpthread");1654 try argv.append("-lpthread");
1655 try argv.append("-lc");
1656 if (needs_grouping) try argv.append("--end-group");
1662 } else if (target.isGnuLibC()) {1657 } else if (target.isGnuLibC()) {
1663 try argv.append(comp.libunwind_static_lib.?.full_object_path);1658 try argv.append(comp.libunwind_static_lib.?.full_object_path);
1664 for (glibc.libs) |lib| {1659 for (glibc.libs) |lib| {