aboutsummaryrefslogtreecommitdiff
path: root/src/link/Elf.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-12-27 16:12:06 -0700
committerAndrew Kelley <andrew@ziglang.org>2024-01-01 19:49:07 -0700
commit6509c492ad7908c515a0c00751e1348b26dda4e7 (patch)
tree4424e28452be76d1ad081d6284e1f625955efbee /src/link/Elf.zig
parent791e83c22396e029e0f2bc19b75fd86f8cd7851f (diff)
downloadzig-6509c492ad7908c515a0c00751e1348b26dda4e7.tar.gz
zig-6509c492ad7908c515a0c00751e1348b26dda4e7.zip
move misc_errors from linker to Compilation
So that they can be referenced by getAllErrorsAlloc(). Fixes missing compile errors.
Diffstat (limited to 'src/link/Elf.zig')
-rw-r--r--src/link/Elf.zig55
1 files changed, 29 insertions, 26 deletions
diff --git a/src/link/Elf.zig b/src/link/Elf.zig
index f20282a802..a74b4b5ae6 100644
--- a/src/link/Elf.zig
+++ b/src/link/Elf.zig
@@ -1170,7 +1170,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
}
// libc dep
- self.base.error_flags.missing_libc = false;
+ comp.link_error_flags.missing_libc = false;
if (comp.config.link_libc) {
if (comp.libc_installation) |lc| {
const flags = target_util.libcFullLinkFlags(target);
@@ -1221,7 +1221,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
});
try system_libs.append(.{ .path = path });
} else {
- self.base.error_flags.missing_libc = true;
+ comp.link_error_flags.missing_libc = true;
}
}
@@ -1259,7 +1259,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
};
}
- if (self.base.misc_errors.items.len > 0) return error.FlushFailure;
+ if (comp.link_errors.items.len > 0) return error.FlushFailure;
// Init all objects
for (self.objects.items) |index| {
@@ -1269,7 +1269,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
try self.file(index).?.shared_object.init(self);
}
- if (self.base.misc_errors.items.len > 0) return error.FlushFailure;
+ if (comp.link_errors.items.len > 0) return error.FlushFailure;
// Dedup shared objects
{
@@ -1388,14 +1388,14 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
if (self.entry_index == null and self.base.isExe()) {
log.debug("flushing. no_entry_point_found = true", .{});
- self.base.error_flags.no_entry_point_found = true;
+ comp.link_error_flags.no_entry_point_found = true;
} else {
log.debug("flushing. no_entry_point_found = false", .{});
- self.base.error_flags.no_entry_point_found = false;
+ comp.link_error_flags.no_entry_point_found = false;
try self.writeElfHeader();
}
- if (self.base.misc_errors.items.len > 0) return error.FlushFailure;
+ if (comp.link_errors.items.len > 0) return error.FlushFailure;
}
pub fn flushStaticLib(self: *Elf, comp: *Compilation, module_obj_path: ?[]const u8) link.File.FlushError!void {
@@ -1427,7 +1427,7 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation, module_obj_path: ?[]const
};
}
- if (self.base.misc_errors.items.len > 0) return error.FlushFailure;
+ if (comp.link_errors.items.len > 0) return error.FlushFailure;
// First, we flush relocatable object file generated with our backends.
if (self.zigObjectPtr()) |zig_object| {
@@ -1539,7 +1539,7 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation, module_obj_path: ?[]const
try self.base.file.?.setEndPos(total_size);
try self.base.file.?.pwriteAll(buffer.items, 0);
- if (self.base.misc_errors.items.len > 0) return error.FlushFailure;
+ if (comp.link_errors.items.len > 0) return error.FlushFailure;
}
pub fn flushObject(self: *Elf, comp: *Compilation, module_obj_path: ?[]const u8) link.File.FlushError!void {
@@ -1570,14 +1570,14 @@ pub fn flushObject(self: *Elf, comp: *Compilation, module_obj_path: ?[]const u8)
};
}
- if (self.base.misc_errors.items.len > 0) return error.FlushFailure;
+ if (comp.link_errors.items.len > 0) return error.FlushFailure;
// Init all objects
for (self.objects.items) |index| {
try self.file(index).?.object.init(self);
}
- if (self.base.misc_errors.items.len > 0) return error.FlushFailure;
+ if (comp.link_errors.items.len > 0) return error.FlushFailure;
// Now, we are ready to resolve the symbols across all input files.
// We will first resolve the files in the ZigObject, next in the parsed
@@ -1611,7 +1611,7 @@ pub fn flushObject(self: *Elf, comp: *Compilation, module_obj_path: ?[]const u8)
try self.writeShdrTable();
try self.writeElfHeader();
- if (self.base.misc_errors.items.len > 0) return error.FlushFailure;
+ if (comp.link_errors.items.len > 0) return error.FlushFailure;
}
/// --verbose-link output
@@ -2888,7 +2888,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
}
// libc dep
- self.base.error_flags.missing_libc = false;
+ comp.link_error_flags.missing_libc = false;
if (comp.config.link_libc) {
if (self.base.comp.libc_installation != null) {
const needs_grouping = link_mode == .Static;
@@ -2909,7 +2909,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
.Dynamic => "libc.so",
}));
} else {
- self.base.error_flags.missing_libc = true;
+ comp.link_error_flags.missing_libc = true;
}
}
}
@@ -3132,7 +3132,8 @@ fn writePhdrTable(self: *Elf) !void {
}
fn writeElfHeader(self: *Elf) !void {
- if (self.base.misc_errors.items.len > 0) return; // We had errors, so skip flushing to render the output unusable
+ const comp = self.base.comp;
+ if (comp.link_errors.items.len > 0) return; // We had errors, so skip flushing to render the output unusable
var hdr_buf: [@sizeOf(elf.Elf64_Ehdr)]u8 = undefined;
@@ -3146,7 +3147,6 @@ fn writeElfHeader(self: *Elf) !void {
};
index += 1;
- const comp = self.base.comp;
const target = comp.root_mod.resolved_target.result;
const endian = target.cpu.arch.endian();
hdr_buf[index] = switch (endian) {
@@ -6055,7 +6055,7 @@ pub fn tlsAddress(self: *Elf) u64 {
}
const ErrorWithNotes = struct {
- /// Allocated index in misc_errors array.
+ /// Allocated index in comp.link_errors array.
index: usize,
/// Next available note slot.
@@ -6069,7 +6069,7 @@ const ErrorWithNotes = struct {
) error{OutOfMemory}!void {
const comp = elf_file.base.comp;
const gpa = comp.gpa;
- const err_msg = &elf_file.base.misc_errors.items[err.index];
+ const err_msg = &comp.link_errors.items[err.index];
err_msg.msg = try std.fmt.allocPrint(gpa, format, args);
}
@@ -6081,7 +6081,7 @@ const ErrorWithNotes = struct {
) error{OutOfMemory}!void {
const comp = elf_file.base.comp;
const gpa = comp.gpa;
- const err_msg = &elf_file.base.misc_errors.items[err.index];
+ const err_msg = &comp.link_errors.items[err.index];
assert(err.note_slot < err_msg.notes.len);
err_msg.notes[err.note_slot] = .{ .msg = try std.fmt.allocPrint(gpa, format, args) };
err.note_slot += 1;
@@ -6089,15 +6089,17 @@ const ErrorWithNotes = struct {
};
pub fn addErrorWithNotes(self: *Elf, note_count: usize) error{OutOfMemory}!ErrorWithNotes {
- const gpa = self.base.comp.gpa;
- try self.base.misc_errors.ensureUnusedCapacity(gpa, 1);
+ const comp = self.base.comp;
+ const gpa = comp.gpa;
+ try comp.link_errors.ensureUnusedCapacity(gpa, 1);
return self.addErrorWithNotesAssumeCapacity(note_count);
}
fn addErrorWithNotesAssumeCapacity(self: *Elf, note_count: usize) error{OutOfMemory}!ErrorWithNotes {
- const gpa = self.base.comp.gpa;
- const index = self.base.misc_errors.items.len;
- const err = self.base.misc_errors.addOneAssumeCapacity();
+ const comp = self.base.comp;
+ const gpa = comp.gpa;
+ const index = comp.link_errors.items.len;
+ const err = comp.link_errors.addOneAssumeCapacity();
err.* = .{ .msg = undefined, .notes = try gpa.alloc(link.File.ErrorMsg, note_count) };
return .{ .index = index };
}
@@ -6129,10 +6131,11 @@ pub fn insertDynString(self: *Elf, name: []const u8) error{OutOfMemory}!u32 {
}
fn reportUndefinedSymbols(self: *Elf, undefs: anytype) !void {
- const gpa = self.base.comp.gpa;
+ const comp = self.base.comp;
+ const gpa = comp.gpa;
const max_notes = 4;
- try self.base.misc_errors.ensureUnusedCapacity(gpa, undefs.count());
+ try comp.link_errors.ensureUnusedCapacity(gpa, undefs.count());
var it = undefs.iterator();
while (it.next()) |entry| {