link: ELF, COFF, WASM: honor the "must_link" flag of positionals

Previously only the MachO linker was honoring the flag.
This commit is contained in:
Andrew Kelley 2022-01-28 12:18:53 -07:00
parent 0e6d2184ca
commit d7deffee8d
3 changed files with 31 additions and 5 deletions

View File

@ -1121,7 +1121,11 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {
try argv.ensureUnusedCapacity(self.base.options.objects.len);
for (self.base.options.objects) |obj| {
argv.appendAssumeCapacity(obj.path);
if (obj.must_link) {
argv.appendAssumeCapacity(try allocPrint(arena, "-WHOLEARCHIVE:{s}", .{obj.path}));
} else {
argv.appendAssumeCapacity(obj.path);
}
}
for (comp.c_object_table.keys()) |key| {

View File

@ -1732,9 +1732,20 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
}
// Positional arguments to the linker such as object files.
try argv.ensureUnusedCapacity(self.base.options.objects.len);
var whole_archive = false;
for (self.base.options.objects) |obj| {
argv.appendAssumeCapacity(obj.path);
if (obj.must_link and !whole_archive) {
try argv.append("-whole-archive");
whole_archive = true;
} else if (!obj.must_link and whole_archive) {
try argv.append("-no-whole-archive");
whole_archive = false;
}
try argv.append(obj.path);
}
if (whole_archive) {
try argv.append("-no-whole-archive");
whole_archive = false;
}
for (comp.c_object_table.keys()) |key| {

View File

@ -1437,9 +1437,20 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
}
// Positional arguments to the linker such as object files.
try argv.ensureUnusedCapacity(self.base.options.objects.len);
var whole_archive = false;
for (self.base.options.objects) |obj| {
argv.appendAssumeCapacity(obj.path);
if (obj.must_link and !whole_archive) {
try argv.append("-whole-archive");
whole_archive = true;
} else if (!obj.must_link and whole_archive) {
try argv.append("-no-whole-archive");
whole_archive = false;
}
try argv.append(obj.path);
}
if (whole_archive) {
try argv.append("-no-whole-archive");
whole_archive = false;
}
for (comp.c_object_table.keys()) |key| {