aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2023-09-04 22:41:50 +0200
committerJakub Konka <kubkon@jakubkonka.com>2023-09-04 22:41:50 +0200
commit02451bdebfe2685c283f6955488d978047e4e9d8 (patch)
tree37979504506ad16221780db7b03fb160690d97b5 /src
parent7d396110d63c7c15d9fe12dbbfc63f1ab0700df4 (diff)
downloadzig-02451bdebfe2685c283f6955488d978047e4e9d8.tar.gz
zig-02451bdebfe2685c283f6955488d978047e4e9d8.zip
elf: atom.index of 0 reserved for null atom
Diffstat (limited to 'src')
-rw-r--r--src/link/Elf.zig19
-rw-r--r--src/link/Elf/Atom.zig6
2 files changed, 8 insertions, 17 deletions
diff --git a/src/link/Elf.zig b/src/link/Elf.zig
index 38855dff7b..fd4a997333 100644
--- a/src/link/Elf.zig
+++ b/src/link/Elf.zig
@@ -154,7 +154,8 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option
// Index 0 is always a null symbol.
try self.locals.append(allocator, null_sym);
-
+ // Allocate atom index 0 to null atom
+ try self.atoms.append(allocator, .{});
// There must always be a null section in index 0
try self.sections.append(allocator, .{
.shdr = .{
@@ -212,6 +213,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Elf {
if (use_llvm) {
self.llvm_object = try LlvmObject.create(gpa, options);
}
+
return self;
}
@@ -2158,11 +2160,7 @@ pub fn createAtom(self: *Elf) !Atom.Index {
const atom_ptr = try self.atoms.addOne(gpa);
const sym_index = try self.allocateSymbol();
try self.atom_by_index_table.putNoClobber(gpa, sym_index, atom_index);
- atom_ptr.* = .{
- .sym_index = sym_index,
- .prev_index = null,
- .next_index = null,
- };
+ atom_ptr.* = .{ .sym_index = sym_index };
log.debug("creating ATOM(%{d}) at index {d}", .{ sym_index, atom_index });
return atom_index;
}
@@ -2300,14 +2298,7 @@ pub fn allocateSymbol(self: *Elf) !u32 {
break :blk index;
}
};
- self.locals.items[index] = .{
- .st_name = 0,
- .st_info = 0,
- .st_other = 0,
- .st_shndx = 0,
- .st_value = 0,
- .st_size = 0,
- };
+ self.locals.items[index] = null_sym;
return index;
}
diff --git a/src/link/Elf/Atom.zig b/src/link/Elf/Atom.zig
index 7edb36f0a4..aa1d3920fb 100644
--- a/src/link/Elf/Atom.zig
+++ b/src/link/Elf/Atom.zig
@@ -4,12 +4,12 @@
/// the symbol references, and adding that to the file offset of the section.
/// If this field is 0, it means the codegen size = 0 and there is no symbol or
/// offset table entry.
-sym_index: u32,
+sym_index: u32 = 0,
/// Points to the previous and next neighbors, based on the `text_offset`.
/// This can be used to find, for example, the capacity of this `TextBlock`.
-prev_index: ?Index,
-next_index: ?Index,
+prev_index: ?Index = null,
+next_index: ?Index = null,
pub const Index = u32;