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
154154
155155 // Index 0 is always a null symbol.
156156 try self.locals.append(allocator, null_sym);
157
157 // Allocate atom index 0 to null atom
158 try self.atoms.append(allocator, .{});
158159 // There must always be a null section in index 0
159160 try self.sections.append(allocator, .{
160161 .shdr = .{
......@@ -212,6 +213,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Elf {
212213 if (use_llvm) {
213214 self.llvm_object = try LlvmObject.create(gpa, options);
214215 }
216
215217 return self;
216218}
217219
......@@ -2158,11 +2160,7 @@ pub fn createAtom(self: *Elf) !Atom.Index {
21582160 const atom_ptr = try self.atoms.addOne(gpa);
21592161 const sym_index = try self.allocateSymbol();
21602162 try self.atom_by_index_table.putNoClobber(gpa, sym_index, atom_index);
2161 atom_ptr.* = .{
2162 .sym_index = sym_index,
2163 .prev_index = null,
2164 .next_index = null,
2165 };
2163 atom_ptr.* = .{ .sym_index = sym_index };
21662164 log.debug("creating ATOM(%{d}) at index {d}", .{ sym_index, atom_index });
21672165 return atom_index;
21682166}
......@@ -2300,14 +2298,7 @@ pub fn allocateSymbol(self: *Elf) !u32 {
23002298 break :blk index;
23012299 }
23022300 };
2303 self.locals.items[index] = .{
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 };
2301 self.locals.items[index] = null_sym;
23112302 return index;
23122303}
23132304
src/link/Elf/Atom.zig+3-3
......@@ -4,12 +4,12 @@
44/// the symbol references, and adding that to the file offset of the section.
55/// If this field is 0, it means the codegen size = 0 and there is no symbol or
66/// offset table entry.
7sym_index: u32,
7sym_index: u32 = 0,
88
99/// Points to the previous and next neighbors, based on the `text_offset`.
1010/// This can be used to find, for example, the capacity of this `TextBlock`.
11prev_index: ?Index,
12next_index: ?Index,
11prev_index: ?Index = null,
12next_index: ?Index = null,
1313
1414pub const Index = u32;
1515