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.
This commit is contained in:
LemonBoy 2021-05-11 12:43:58 +02:00
parent 780f510ac0
commit 2bb8e1ff55
2 changed files with 7 additions and 11 deletions

View File

@ -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 },

View File

@ -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| {