| ... | @@ -729,15 +729,19 @@ pub fn flushModule(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod | ... | @@ -729,15 +729,19 @@ pub fn flushModule(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod |
| 729 | index += 2; | 729 | index += 2; |
| 730 | | 730 | |
| 731 | // Characteristics | 731 | // 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 | }; |
| 733 | if (output_mode == .Exe) { | 737 | if (output_mode == .Exe) { |
| 734 | characteristics |= std.coff.IMAGE_FILE_EXECUTABLE_IMAGE; | 738 | flags.EXECUTABLE_IMAGE = 1; |
| 735 | } | 739 | } |
| 736 | switch (self.ptr_width) { | 740 | switch (self.ptr_width) { |
| 737 | .p32 => characteristics |= std.coff.IMAGE_FILE_32BIT_MACHINE, | 741 | .p32 => flags.@"32BIT_MACHINE" = 1, |
| 738 | .p64 => characteristics |= std.coff.IMAGE_FILE_LARGE_ADDRESS_AWARE, | 742 | .p64 => flags.LARGE_ADDRESS_AWARE = 1, |
| 739 | } | 743 | } |
| 740 | mem.writeIntLittle(u16, hdr_data[index..][0..2], characteristics); | 744 | mem.writeIntLittle(u16, hdr_data[index..][0..2], @bitCast(u16, flags)); |
| 741 | index += 2; | 745 | index += 2; |
| 742 | | 746 | |
| 743 | assert(index == 20); | 747 | assert(index == 20); |
| ... | @@ -877,7 +881,10 @@ pub fn flushModule(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod | ... | @@ -877,7 +881,10 @@ pub fn flushModule(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod |
| 877 | mem.set(u8, hdr_data[index..][0..12], 0); | 881 | mem.set(u8, hdr_data[index..][0..12], 0); |
| 878 | index += 12; | 882 | index += 12; |
| 879 | // Section flags | 883 | // 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 | })); |
| 881 | index += 4; | 888 | index += 4; |
| 882 | // Then, the .text section | 889 | // Then, the .text section |
| 883 | hdr_data[index..][0..8].* = ".text\x00\x00\x00".*; | 890 | 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 | ... | @@ -903,11 +910,12 @@ pub fn flushModule(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod |
| 903 | mem.set(u8, hdr_data[index..][0..12], 0); | 910 | mem.set(u8, hdr_data[index..][0..12], 0); |
| 904 | index += 12; | 911 | index += 12; |
| 905 | // Section flags | 912 | // Section flags |
| 906 | mem.writeIntLittle( | 913 | mem.writeIntLittle(u32, hdr_data[index..][0..4], @bitCast(u32, std.coff.SectionHeaderFlags{ |
| 907 | u32, | 914 | .CNT_CODE = 1, |
| 908 | hdr_data[index..][0..4], | 915 | .MEM_EXECUTE = 1, |
| 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, | 916 | .MEM_READ = 1, |
| 910 | ); | 917 | .MEM_WRITE = 1, |
| | 918 | })); |
| 911 | index += 4; | 919 | index += 4; |
| 912 | | 920 | |
| 913 | assert(index == optional_header_size + section_table_size); | 921 | assert(index == optional_header_size + section_table_size); |