Commit 0ebeb58d91

Jakub Konka <kubkon@jakubkonka.com>
2022-08-31 21:49:51
coff: populate import address table dir
1 parent 1ab149c
Changed files (1)
src
src/link/Coff.zig
@@ -1346,6 +1346,7 @@ pub fn flushModule(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
         }
     }
     try self.writeBaseRelocations();
+    try self.writeImportTable();
 
     if (self.getEntryPoint()) |entry_sym_loc| {
         self.entry_addr = self.getSymbol(entry_sym_loc).value;
@@ -1484,6 +1485,22 @@ fn writeBaseRelocations(self: *Coff) !void {
     };
 }
 
+fn writeImportTable(self: *Coff) !void {
+    const gpa = self.base.allocator;
+    _ = gpa;
+
+    const section = self.sections.get(self.idata_section_index.?);
+    const iat_rva = section.header.virtual_address;
+    const iat_size = blk: {
+        const last_atom = section.last_atom.?;
+        break :blk last_atom.getSymbol(self).value + last_atom.size - iat_rva;
+    };
+    self.data_directories[@enumToInt(coff.DirectoryEntry.IAT)] = .{
+        .virtual_address = iat_rva,
+        .size = iat_size,
+    };
+}
+
 fn writeStrtab(self: *Coff) !void {
     const allocated_size = self.allocatedSize(self.strtab_offset.?);
     const needed_size = @intCast(u32, self.strtab.len());