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 18:45:34-07:00
logc71b78eb0196cbad9fbb01ce9137d09796b48726
treefc0358a06b60dc96f002cb518a780095b7940fa6
parent59bdd7722939219c8d4267d301cdf063d9c26421

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) {...@@ -1457,8 +1457,10 @@ pub const Task = union(enum) {
1457pub fn doTask(comp: *Compilation, tid: usize, task: Task) void {1457pub fn doTask(comp: *Compilation, tid: usize, task: Task) void {
1458 const diags = &comp.link_diags;1458 const diags = &comp.link_diags;
1459 switch (task) {1459 switch (task) {
1460 .load_explicitly_provided => if (comp.bin_file) |base| {1460 .load_explicitly_provided => {
1461 comp.remaining_prelink_tasks -= 1;1461 comp.remaining_prelink_tasks -= 1;
1462 const base = comp.bin_file orelse return;
1463
1462 const prog_node = comp.work_queue_progress_node.start("Parse Linker Inputs", comp.link_inputs.len);1464 const prog_node = comp.work_queue_progress_node.start("Parse Linker Inputs", comp.link_inputs.len);
1463 defer prog_node.end();1465 defer prog_node.end();
1464 for (comp.link_inputs) |input| {1466 for (comp.link_inputs) |input| {
...@@ -1475,8 +1477,10 @@ pub fn doTask(comp: *Compilation, tid: usize, task: Task) void {...@@ -1475,8 +1477,10 @@ pub fn doTask(comp: *Compilation, tid: usize, task: Task) void {
1475 prog_node.completeOne();1477 prog_node.completeOne();
1476 }1478 }
1477 },1479 },
1478 .load_host_libc => if (comp.bin_file) |base| {1480 .load_host_libc => {
1479 comp.remaining_prelink_tasks -= 1;1481 comp.remaining_prelink_tasks -= 1;
1482 const base = comp.bin_file orelse return;
1483
1480 const prog_node = comp.work_queue_progress_node.start("Linker Parse Host libc", 0);1484 const prog_node = comp.work_queue_progress_node.start("Linker Parse Host libc", 0);
1481 defer prog_node.end();1485 defer prog_node.end();
14821486
...@@ -1535,8 +1539,9 @@ pub fn doTask(comp: *Compilation, tid: usize, task: Task) void {...@@ -1535,8 +1539,9 @@ pub fn doTask(comp: *Compilation, tid: usize, task: Task) void {
1535 }1539 }
1536 }1540 }
1537 },1541 },
1538 .load_object => |path| if (comp.bin_file) |base| {1542 .load_object => |path| {
1539 comp.remaining_prelink_tasks -= 1;1543 comp.remaining_prelink_tasks -= 1;
1544 const base = comp.bin_file orelse return;
1540 const prog_node = comp.work_queue_progress_node.start("Linker Parse Object", 0);1545 const prog_node = comp.work_queue_progress_node.start("Linker Parse Object", 0);
1541 defer prog_node.end();1546 defer prog_node.end();
1542 base.openLoadObject(path) catch |err| switch (err) {1547 base.openLoadObject(path) catch |err| switch (err) {
...@@ -1544,8 +1549,9 @@ pub fn doTask(comp: *Compilation, tid: usize, task: Task) void {...@@ -1544,8 +1549,9 @@ pub fn doTask(comp: *Compilation, tid: usize, task: Task) void {
1544 else => |e| diags.addParseError(path, "failed to parse object: {s}", .{@errorName(e)}),1549 else => |e| diags.addParseError(path, "failed to parse object: {s}", .{@errorName(e)}),
1545 };1550 };
1546 },1551 },
1547 .load_archive => |path| if (comp.bin_file) |base| {1552 .load_archive => |path| {
1548 comp.remaining_prelink_tasks -= 1;1553 comp.remaining_prelink_tasks -= 1;
1554 const base = comp.bin_file orelse return;
1549 const prog_node = comp.work_queue_progress_node.start("Linker Parse Archive", 0);1555 const prog_node = comp.work_queue_progress_node.start("Linker Parse Archive", 0);
1550 defer prog_node.end();1556 defer prog_node.end();
1551 base.openLoadArchive(path, null) catch |err| switch (err) {1557 base.openLoadArchive(path, null) catch |err| switch (err) {
...@@ -1553,8 +1559,9 @@ pub fn doTask(comp: *Compilation, tid: usize, task: Task) void {...@@ -1553,8 +1559,9 @@ pub fn doTask(comp: *Compilation, tid: usize, task: Task) void {
1553 else => |e| diags.addParseError(path, "failed to parse archive: {s}", .{@errorName(e)}),1559 else => |e| diags.addParseError(path, "failed to parse archive: {s}", .{@errorName(e)}),
1554 };1560 };
1555 },1561 },
1556 .load_dso => |path| if (comp.bin_file) |base| {1562 .load_dso => |path| {
1557 comp.remaining_prelink_tasks -= 1;1563 comp.remaining_prelink_tasks -= 1;
1564 const base = comp.bin_file orelse return;
1558 const prog_node = comp.work_queue_progress_node.start("Linker Parse Shared Library", 0);1565 const prog_node = comp.work_queue_progress_node.start("Linker Parse Shared Library", 0);
1559 defer prog_node.end();1566 defer prog_node.end();
1560 base.openLoadDso(path, .{1567 base.openLoadDso(path, .{
...@@ -1565,8 +1572,9 @@ pub fn doTask(comp: *Compilation, tid: usize, task: Task) void {...@@ -1565,8 +1572,9 @@ pub fn doTask(comp: *Compilation, tid: usize, task: Task) void {
1565 else => |e| diags.addParseError(path, "failed to parse shared library: {s}", .{@errorName(e)}),1572 else => |e| diags.addParseError(path, "failed to parse shared library: {s}", .{@errorName(e)}),
1566 };1573 };
1567 },1574 },
1568 .load_input => |input| if (comp.bin_file) |base| {1575 .load_input => |input| {
1569 comp.remaining_prelink_tasks -= 1;1576 comp.remaining_prelink_tasks -= 1;
1577 const base = comp.bin_file orelse return;
1570 const prog_node = comp.work_queue_progress_node.start("Linker Parse Input", 0);1578 const prog_node = comp.work_queue_progress_node.start("Linker Parse Input", 0);
1571 defer prog_node.end();1579 defer prog_node.end();
1572 base.loadInput(input) catch |err| switch (err) {1580 base.loadInput(input) catch |err| switch (err) {