PE32+ Executable Emitter¶
Source: src/compiler/pe32.odin
Generates PE32+ Windows executable files.
Functions¶
emit_pe32_exe {#emit_pe32_exe}¶
Function: emit_pe32_exe Emits a PE32+ executable to output_path. Iterates over packages, encodes all function bodies into machine code, builds a small x86-64 entry stub that calls the first function found, and writes PE headers with .text and .data sections.
align_up {#align_up}¶
Function: align_up Rounds val up to the nearest multiple of alignment. Both values must be powers of two. Returns the aligned result.
w_u16 {#w_u16}¶
Function: w_u16 Writes a little-endian u16 value into buf at byte offset off.
w_u32 {#w_u32}¶
Function: w_u32 Writes a little-endian u32 value into buf at byte offset off.
w_u64 {#w_u64}¶
Function: w_u64 Writes a little-endian u64 value into buf at byte offset off.
write_zeros {#write_zeros}¶
Function: write_zeros Writes count zero bytes to file f, flushing in 256-byte chunks.
write_sec_hdr {#write_sec_hdr}¶
Function: write_sec_hdr Writes a COFF-style section header into buf at offset off. Fields include the section name (up to 8 bytes), virtual size/address, raw data size/pointer, and characteristics flags.
Constants¶
PE32_PLUS_MAGIC {#pe32_plus_magic}¶
Constant: PE32_PLUS_MAGIC The PE32+ magic number (0x20B) identifying a 64-bit portable executable.
IMAGE_BASE {#image_base}¶
Constant: IMAGE_BASE Default preferred base address (0x140000000) at which the PE32+ image is loaded.
SECTION_ALIGNMENT {#section_alignment}¶
Constant: SECTION_ALIGNMENT Section alignment in memory (4 KiB). Each section starts on this boundary.
FILE_ALIGNMENT {#file_alignment}¶
Constant: FILE_ALIGNMENT Section alignment on disk (512 bytes). Raw data is padded to this boundary.
SUBSYSTEM_CONSOLE {#subsystem_console}¶
Constant: SUBSYSTEM_CONSOLE Windows subsystem value (3) indicating a console application.
MAGIC_DOS {#magic_dos}¶
Constant: MAGIC_DOS DOS stub magic number (0x5A4D, "MZ") placed at the start of the file.