stage2: only build and link libunwind when linking libc++

This commit is contained in:
Andrew Kelley 2021-05-13 11:52:58 -07:00
parent 173142cc36
commit 76a259799d
2 changed files with 4 additions and 7 deletions

View File

@ -3023,6 +3023,7 @@ fn wantBuildLibUnwindFromSource(comp: *Compilation) bool {
.Exe => true,
};
return comp.bin_file.options.link_libc and is_exe_or_dyn_lib and
comp.bin_file.options.link_libcpp and
target_util.libcNeedsLibUnwind(comp.getTarget());
}

View File

@ -1643,20 +1643,19 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
if (self.base.options.link_libcpp) {
try argv.append(comp.libcxxabi_static_lib.?.full_object_path);
try argv.append(comp.libcxx_static_lib.?.full_object_path);
if (target_util.libcNeedsLibUnwind(target)) {
try argv.append(comp.libunwind_static_lib.?.full_object_path);
}
}
// libc dep
if (self.base.options.link_libc) {
if (self.base.options.libc_installation != null) {
if (target_util.libcNeedsLibUnwind(target)) {
try argv.append(comp.libunwind_static_lib.?.full_object_path);
}
const needs_grouping = self.base.options.link_mode == .Static;
if (needs_grouping) try argv.append("--start-group");
try argv.appendSlice(target_util.libcFullLinkFlags(target));
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| {
const lib_path = try std.fmt.allocPrint(arena, "{s}{c}lib{s}.so.{d}", .{
comp.glibc_so_files.?.dir_path, fs.path.sep, lib.name, lib.sover,
@ -1665,13 +1664,10 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
}
try argv.append(try comp.get_libc_crt_file(arena, "libc_nonshared.a"));
} else if (target.isMusl()) {
try argv.append(comp.libunwind_static_lib.?.full_object_path);
try argv.append(try comp.get_libc_crt_file(arena, switch (self.base.options.link_mode) {
.Static => "libc.a",
.Dynamic => "libc.so",
}));
} else if (self.base.options.link_libcpp) {
try argv.append(comp.libunwind_static_lib.?.full_object_path);
} else {
unreachable; // Compiler was supposed to emit an error for not being able to provide libc.
}