authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-09-04 22:41:50+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-09-04 22:41:50+02:00
log02451bdebfe2685c283f6955488d978047e4e9d8
tree37979504506ad16221780db7b03fb160690d97b5
parent7d396110d63c7c15d9fe12dbbfc63f1ab0700df4

elf: atom.index of 0 reserved for null atom


2 files changed, 8 insertions(+), 17 deletions(-)

src/link/Elf.zig+5-14
...@@ -154,7 +154,8 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option...@@ -154,7 +154,8 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option
154154
155 // Index 0 is always a null symbol.155 // Index 0 is always a null symbol.
156 try self.locals.append(allocator, null_sym);156 try self.locals.append(allocator, null_sym);
157157 // Allocate atom index 0 to null atom
158 try self.atoms.append(allocator, .{});
158 // There must always be a null section in index 0159 // There must always be a null section in index 0
159 try self.sections.append(allocator, .{160 try self.sections.append(allocator, .{
160 .shdr = .{161 .shdr = .{
...@@ -212,6 +213,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Elf {...@@ -212,6 +213,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Elf {
212 if (use_llvm) {213 if (use_llvm) {
213 self.llvm_object = try LlvmObject.create(gpa, options);214 self.llvm_object = try LlvmObject.create(gpa, options);
214 }215 }
216
215 return self;217 return self;
216}218}
217219
...@@ -2158,11 +2160,7 @@ pub fn createAtom(self: *Elf) !Atom.Index {...@@ -2158,11 +2160,7 @@ pub fn createAtom(self: *Elf) !Atom.Index {
2158 const atom_ptr = try self.atoms.addOne(gpa);2160 const atom_ptr = try self.atoms.addOne(gpa);
2159 const sym_index = try self.allocateSymbol();2161 const sym_index = try self.allocateSymbol();
2160 try self.atom_by_index_table.putNoClobber(gpa, sym_index, atom_index);2162 try self.atom_by_index_table.putNoClobber(gpa, sym_index, atom_index);
2161 atom_ptr.* = .{2163 atom_ptr.* = .{ .sym_index = sym_index };
2162 .sym_index = sym_index,
2163 .prev_index = null,
2164 .next_index = null,
2165 };
2166 log.debug("creating ATOM(%{d}) at index {d}", .{ sym_index, atom_index });2164 log.debug("creating ATOM(%{d}) at index {d}", .{ sym_index, atom_index });
2167 return atom_index;2165 return atom_index;
2168}2166}
...@@ -2300,14 +2298,7 @@ pub fn allocateSymbol(self: *Elf) !u32 {...@@ -2300,14 +2298,7 @@ pub fn allocateSymbol(self: *Elf) !u32 {
2300 break :blk index;2298 break :blk index;
2301 }2299 }
2302 };2300 };
2303 self.locals.items[index] = .{2301 self.locals.items[index] = null_sym;
2304 .st_name = 0,
2305 .st_info = 0,
2306 .st_other = 0,
2307 .st_shndx = 0,
2308 .st_value = 0,
2309 .st_size = 0,
2310 };
2311 return index;2302 return index;
2312}2303}
23132304
src/link/Elf/Atom.zig+3-3
...@@ -4,12 +4,12 @@...@@ -4,12 +4,12 @@
4/// the symbol references, and adding that to the file offset of the section.4/// the symbol references, and adding that to the file offset of the section.
5/// If this field is 0, it means the codegen size = 0 and there is no symbol or5/// If this field is 0, it means the codegen size = 0 and there is no symbol or
6/// offset table entry.6/// offset table entry.
7sym_index: u32,7sym_index: u32 = 0,
88
9/// Points to the previous and next neighbors, based on the `text_offset`.9/// Points to the previous and next neighbors, based on the `text_offset`.
10/// This can be used to find, for example, the capacity of this `TextBlock`.10/// This can be used to find, for example, the capacity of this `TextBlock`.
11prev_index: ?Index,11prev_index: ?Index = null,
12next_index: ?Index,12next_index: ?Index = null,
1313
14pub const Index = u32;14pub const Index = u32;
1515