authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-03-14 22:44:44+00:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-03-22 21:44:46-04:00
log9f235a105b29c6f1c0c773f66c40e7ee655da559
tree7cf5939a5b39ea6b75f54b4b06e36819972b97ef
parent9c9d3931df4c1decffec610e5e47b3049b147c8d

link: mark prelink tasks as procesed under `-fno-emit-bin`

The old logic only decremented `remaining_prelink_tasks` if `bin_file` was not `null`. This meant that on `-fno-emit-bin` builds with registered prelink tasks (e.g. C source files), we exited from `Compilation.performAllTheWorkInner` early, assuming a prelink error. Instead, when `bin_file` is `null`, we still decrement `remaining_prelink_tasks`; we just don't do any actual work. Resolves: #22682

1 files changed, 14 insertions(+), 6 deletions(-)

src/link.zig+14-6
......@@ -1457,8 +1457,10 @@ pub const Task = union(enum) {
14571457pub fn doTask(comp: *Compilation, tid: usize, task: Task) void {
14581458 const diags = &comp.link_diags;
14591459 switch (task) {
1460 .load_explicitly_provided => if (comp.bin_file) |base| {
1460 .load_explicitly_provided => {
14611461 comp.remaining_prelink_tasks -= 1;
1462 const base = comp.bin_file orelse return;
1463
14621464 const prog_node = comp.work_queue_progress_node.start("Parse Linker Inputs", comp.link_inputs.len);
14631465 defer prog_node.end();
14641466 for (comp.link_inputs) |input| {
......@@ -1475,8 +1477,10 @@ pub fn doTask(comp: *Compilation, tid: usize, task: Task) void {
14751477 prog_node.completeOne();
14761478 }
14771479 },
1478 .load_host_libc => if (comp.bin_file) |base| {
1480 .load_host_libc => {
14791481 comp.remaining_prelink_tasks -= 1;
1482 const base = comp.bin_file orelse return;
1483
14801484 const prog_node = comp.work_queue_progress_node.start("Linker Parse Host libc", 0);
14811485 defer prog_node.end();
14821486
......@@ -1535,8 +1539,9 @@ pub fn doTask(comp: *Compilation, tid: usize, task: Task) void {
15351539 }
15361540 }
15371541 },
1538 .load_object => |path| if (comp.bin_file) |base| {
1542 .load_object => |path| {
15391543 comp.remaining_prelink_tasks -= 1;
1544 const base = comp.bin_file orelse return;
15401545 const prog_node = comp.work_queue_progress_node.start("Linker Parse Object", 0);
15411546 defer prog_node.end();
15421547 base.openLoadObject(path) catch |err| switch (err) {
......@@ -1544,8 +1549,9 @@ pub fn doTask(comp: *Compilation, tid: usize, task: Task) void {
15441549 else => |e| diags.addParseError(path, "failed to parse object: {s}", .{@errorName(e)}),
15451550 };
15461551 },
1547 .load_archive => |path| if (comp.bin_file) |base| {
1552 .load_archive => |path| {
15481553 comp.remaining_prelink_tasks -= 1;
1554 const base = comp.bin_file orelse return;
15491555 const prog_node = comp.work_queue_progress_node.start("Linker Parse Archive", 0);
15501556 defer prog_node.end();
15511557 base.openLoadArchive(path, null) catch |err| switch (err) {
......@@ -1553,8 +1559,9 @@ pub fn doTask(comp: *Compilation, tid: usize, task: Task) void {
15531559 else => |e| diags.addParseError(path, "failed to parse archive: {s}", .{@errorName(e)}),
15541560 };
15551561 },
1556 .load_dso => |path| if (comp.bin_file) |base| {
1562 .load_dso => |path| {
15571563 comp.remaining_prelink_tasks -= 1;
1564 const base = comp.bin_file orelse return;
15581565 const prog_node = comp.work_queue_progress_node.start("Linker Parse Shared Library", 0);
15591566 defer prog_node.end();
15601567 base.openLoadDso(path, .{
......@@ -1565,8 +1572,9 @@ pub fn doTask(comp: *Compilation, tid: usize, task: Task) void {
15651572 else => |e| diags.addParseError(path, "failed to parse shared library: {s}", .{@errorName(e)}),
15661573 };
15671574 },
1568 .load_input => |input| if (comp.bin_file) |base| {
1575 .load_input => |input| {
15691576 comp.remaining_prelink_tasks -= 1;
1577 const base = comp.bin_file orelse return;
15701578 const prog_node = comp.work_queue_progress_node.start("Linker Parse Input", 0);
15711579 defer prog_node.end();
15721580 base.loadInput(input) catch |err| switch (err) {