aboutsummaryrefslogtreecommitdiff
path: root/src/link/Elf/ZigObject.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2023-10-30 19:44:27 +0100
committerJakub Konka <kubkon@jakubkonka.com>2023-10-30 19:44:27 +0100
commitb1a735ac65126c9fb383ae894e31fb53b94ce0b8 (patch)
tree523309fa751985059807957591d6cb42003b51a2 /src/link/Elf/ZigObject.zig
parent9bdbb6312f78764c0a5760ab035341f6cf09255b (diff)
downloadzig-b1a735ac65126c9fb383ae894e31fb53b94ce0b8.tar.gz
zig-b1a735ac65126c9fb383ae894e31fb53b94ce0b8.zip
elf: put init logic of ZigObject in init function
Diffstat (limited to 'src/link/Elf/ZigObject.zig')
-rw-r--r--src/link/Elf/ZigObject.zig25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/link/Elf/ZigObject.zig b/src/link/Elf/ZigObject.zig
index 39789460e9..1999c29cb1 100644
--- a/src/link/Elf/ZigObject.zig
+++ b/src/link/Elf/ZigObject.zig
@@ -56,6 +56,30 @@ pub const global_symbol_bit: u32 = 0x80000000;
pub const symbol_mask: u32 = 0x7fffffff;
pub const SHN_ATOM: u16 = 0x100;
+pub fn init(self: *ZigObject, elf_file: *Elf) !void {
+ const gpa = elf_file.base.allocator;
+
+ try self.atoms.append(gpa, 0); // null input section
+
+ const name_off = try elf_file.strtab.insert(gpa, std.fs.path.stem(self.path));
+ const symbol_index = try elf_file.addSymbol();
+ try self.local_symbols.append(gpa, symbol_index);
+ const symbol_ptr = elf_file.symbol(symbol_index);
+ symbol_ptr.file_index = self.index;
+ symbol_ptr.name_offset = name_off;
+
+ const esym_index = try self.addLocalEsym(gpa);
+ const esym = &self.local_esyms.items(.elf_sym)[esym_index];
+ esym.st_name = name_off;
+ esym.st_info |= elf.STT_FILE;
+ esym.st_shndx = elf.SHN_ABS;
+ symbol_ptr.esym_index = esym_index;
+
+ if (!elf_file.base.options.strip) {
+ self.dwarf = Dwarf.init(gpa, &elf_file.base, .dwarf32);
+ }
+}
+
pub fn deinit(self: *ZigObject, allocator: Allocator) void {
self.local_esyms.deinit(allocator);
self.global_esyms.deinit(allocator);
@@ -119,7 +143,6 @@ pub fn addGlobalEsym(self: *ZigObject, allocator: Allocator) !Symbol.Index {
pub fn addAtom(self: *ZigObject, elf_file: *Elf) !Symbol.Index {
const gpa = elf_file.base.allocator;
-
const atom_index = try elf_file.addAtom();
const symbol_index = try elf_file.addSymbol();
const esym_index = try self.addLocalEsym(gpa);