authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-02 09:58:10+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-16 19:33:03+02:00
log52f8a1a24c274c7ad6b28562498da0b58e91ccbf
tree2a5319f7a424f1150b37c7e0a39afe64efb7fdf9
parent7b9165b37576ed4c4962c0ad2afb62921524aa08

elf: move initializing string buffers out of populateMissingMetadata


1 files changed, 12 insertions(+), 12 deletions(-)

src/link/Elf.zig+12-12
......@@ -224,6 +224,17 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option
224224 .sh_addralign = 0,
225225 .sh_entsize = 0,
226226 });
227 // Append null byte to string tables
228 try self.shstrtab.buffer.append(allocator, 0);
229 try self.strtab.buffer.append(allocator, 0);
230
231 if (options.module != null and !options.use_llvm) {
232 if (!options.strip) {
233 self.dwarf = Dwarf.init(allocator, &self.base, options.target);
234 }
235
236 // TODO move populateMissingMetadata here renamed to zig_module.initMetadata();
237 }
227238
228239 try self.populateMissingMetadata();
229240
......@@ -249,12 +260,6 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Elf {
249260 else
250261 elf.VER_NDX_LOCAL;
251262
252 const use_llvm = options.use_llvm;
253 var dwarf: ?Dwarf = if (!options.strip and options.module != null and !use_llvm)
254 Dwarf.init(gpa, &self.base, options.target)
255 else
256 null;
257
258263 self.* = .{
259264 .base = .{
260265 .tag = .elf,
......@@ -262,12 +267,11 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Elf {
262267 .allocator = gpa,
263268 .file = null,
264269 },
265 .dwarf = dwarf,
266270 .ptr_width = ptr_width,
267271 .page_size = page_size,
268272 .default_sym_version = default_sym_version,
269273 };
270 if (use_llvm and options.module != null) {
274 if (options.use_llvm and options.module != null) {
271275 self.llvm_object = try LlvmObject.create(gpa, options);
272276 }
273277
......@@ -734,8 +738,6 @@ pub fn populateMissingMetadata(self: *Elf) !void {
734738 }
735739
736740 if (self.shstrtab_section_index == null) {
737 assert(self.shstrtab.buffer.items.len == 0);
738 try self.shstrtab.buffer.append(gpa, 0); // need a 0 at position 0
739741 self.shstrtab_section_index = try self.allocateNonAllocSection(.{
740742 .name = ".shstrtab",
741743 .size = @intCast(self.shstrtab.buffer.items.len),
......@@ -745,8 +747,6 @@ pub fn populateMissingMetadata(self: *Elf) !void {
745747 }
746748
747749 if (self.strtab_section_index == null) {
748 assert(self.strtab.buffer.items.len == 0);
749 try self.strtab.buffer.append(gpa, 0); // need a 0 at position 0
750750 self.strtab_section_index = try self.allocateNonAllocSection(.{
751751 .name = ".strtab",
752752 .size = @intCast(self.strtab.buffer.items.len),