authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-08-26 10:28:33+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-08-30 10:42:21+02:00
log580bfe01c89c4e95cfb341b73514b8ec769ce635
tree096c986a9c816946a5702fa644a6c0795c6af565
parent3c10221030c47a68c17b4e037abd8afcdfd08486

coff: fix after rebase


1 files changed, 19 insertions(+), 11 deletions(-)

src/link/Coff.zig+19-11
......@@ -729,15 +729,19 @@ pub fn flushModule(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
729729 index += 2;
730730
731731 // Characteristics
732 var characteristics: u16 = std.coff.IMAGE_FILE_DEBUG_STRIPPED | std.coff.IMAGE_FILE_RELOCS_STRIPPED; // TODO Remove debug info stripped flag when necessary
732 var flags: std.coff.CoffHeaderFlags = .{
733 // TODO Remove debug info stripped flag when necessary
734 .DEBUG_STRIPPED = 1,
735 .RELOCS_STRIPPED = 1,
736 };
733737 if (output_mode == .Exe) {
734 characteristics |= std.coff.IMAGE_FILE_EXECUTABLE_IMAGE;
738 flags.EXECUTABLE_IMAGE = 1;
735739 }
736740 switch (self.ptr_width) {
737 .p32 => characteristics |= std.coff.IMAGE_FILE_32BIT_MACHINE,
738 .p64 => characteristics |= std.coff.IMAGE_FILE_LARGE_ADDRESS_AWARE,
741 .p32 => flags.@"32BIT_MACHINE" = 1,
742 .p64 => flags.LARGE_ADDRESS_AWARE = 1,
739743 }
740 mem.writeIntLittle(u16, hdr_data[index..][0..2], characteristics);
744 mem.writeIntLittle(u16, hdr_data[index..][0..2], @bitCast(u16, flags));
741745 index += 2;
742746
743747 assert(index == 20);
......@@ -877,7 +881,10 @@ pub fn flushModule(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
877881 mem.set(u8, hdr_data[index..][0..12], 0);
878882 index += 12;
879883 // Section flags
880 mem.writeIntLittle(u32, hdr_data[index..][0..4], std.coff.IMAGE_SCN_CNT_INITIALIZED_DATA | std.coff.IMAGE_SCN_MEM_READ);
884 mem.writeIntLittle(u32, hdr_data[index..][0..4], @bitCast(u32, std.coff.SectionHeaderFlags{
885 .CNT_INITIALIZED_DATA = 1,
886 .MEM_READ = 1,
887 }));
881888 index += 4;
882889 // Then, the .text section
883890 hdr_data[index..][0..8].* = ".text\x00\x00\x00".*;
......@@ -903,11 +910,12 @@ pub fn flushModule(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
903910 mem.set(u8, hdr_data[index..][0..12], 0);
904911 index += 12;
905912 // Section flags
906 mem.writeIntLittle(
907 u32,
908 hdr_data[index..][0..4],
909 std.coff.IMAGE_SCN_CNT_CODE | std.coff.IMAGE_SCN_MEM_EXECUTE | std.coff.IMAGE_SCN_MEM_READ | std.coff.IMAGE_SCN_MEM_WRITE,
910 );
913 mem.writeIntLittle(u32, hdr_data[index..][0..4], @bitCast(u32, std.coff.SectionHeaderFlags{
914 .CNT_CODE = 1,
915 .MEM_EXECUTE = 1,
916 .MEM_READ = 1,
917 .MEM_WRITE = 1,
918 }));
911919 index += 4;
912920
913921 assert(index == optional_header_size + section_table_size);