Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,6 @@ set(ZIG_STAGE2_SOURCES
src/libs/libunwind.zig
src/link.zig
src/link/C.zig
src/link/Coff.zig
src/link/Dwarf.zig
src/link/Elf.zig
src/link/Elf/Archive.zig
Expand Down
44 changes: 22 additions & 22 deletions lib/compiler/resinator/cvtres.zig
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub fn parseNameOrOrdinal(allocator: Allocator, reader: *std.Io.Reader) !NameOrO
}

pub const CoffOptions = struct {
target: std.coff.MachineType = .X64,
target: std.coff.IMAGE.FILE.MACHINE = .AMD64,
/// If true, zeroes will be written to all timestamp fields
reproducible: bool = true,
/// If true, the MEM_WRITE flag will not be set in the .rsrc section header
Expand Down Expand Up @@ -210,19 +210,19 @@ pub fn writeCoff(allocator: Allocator, writer: *std.Io.Writer, resources: []cons
const lengths = resource_tree.dataLengths();
const byte_size_of_relocation = 10;
const relocations_len: u32 = @intCast(byte_size_of_relocation * resources.len);
const pointer_to_rsrc01_data = @sizeOf(std.coff.CoffHeader) + (@sizeOf(std.coff.SectionHeader) * 2);
const pointer_to_rsrc01_data = @sizeOf(std.coff.Header) + (@sizeOf(std.coff.SectionHeader) * 2);
const pointer_to_relocations = pointer_to_rsrc01_data + lengths.rsrc01;
const pointer_to_rsrc02_data = pointer_to_relocations + relocations_len;
const pointer_to_symbol_table = pointer_to_rsrc02_data + lengths.rsrc02;

const timestamp: i64 = if (options.reproducible) 0 else std.time.timestamp();
const size_of_optional_header = 0;
const machine_type: std.coff.MachineType = options.target;
const flags = std.coff.CoffHeaderFlags{
.@"32BIT_MACHINE" = 1,
const machine_type: std.coff.IMAGE.FILE.MACHINE = options.target;
const flags = std.coff.Header.Flags{
.@"32BIT_MACHINE" = true,
};
const number_of_symbols = 5 + @as(u32, @intCast(resources.len)) + @intFromBool(options.define_external_symbol != null);
const coff_header = std.coff.CoffHeader{
const coff_header = std.coff.Header{
.machine = machine_type,
.number_of_sections = 2,
.time_date_stamp = @as(u32, @truncate(@as(u64, @bitCast(timestamp)))),
Expand All @@ -245,9 +245,9 @@ pub fn writeCoff(allocator: Allocator, writer: *std.Io.Writer, resources: []cons
.number_of_relocations = @intCast(resources.len),
.number_of_linenumbers = 0,
.flags = .{
.CNT_INITIALIZED_DATA = 1,
.MEM_WRITE = @intFromBool(!options.read_only),
.MEM_READ = 1,
.CNT_INITIALIZED_DATA = true,
.MEM_WRITE = !options.read_only,
.MEM_READ = true,
},
};
try writer.writeStruct(rsrc01_header, .little);
Expand All @@ -263,9 +263,9 @@ pub fn writeCoff(allocator: Allocator, writer: *std.Io.Writer, resources: []cons
.number_of_relocations = 0,
.number_of_linenumbers = 0,
.flags = .{
.CNT_INITIALIZED_DATA = 1,
.MEM_WRITE = @intFromBool(!options.read_only),
.MEM_READ = 1,
.CNT_INITIALIZED_DATA = true,
.MEM_WRITE = !options.read_only,
.MEM_READ = true,
},
};
try writer.writeStruct(rsrc02_header, .little);
Expand Down Expand Up @@ -1005,9 +1005,9 @@ pub const supported_targets = struct {
x86_64,
aarch64,

pub fn toCoffMachineType(arch: Arch) std.coff.MachineType {
pub fn toCoffMachineType(arch: Arch) std.coff.IMAGE.FILE.MACHINE {
return switch (arch) {
.x64, .amd64, .x86_64 => .X64,
.x64, .amd64, .x86_64 => .AMD64,
.x86, .i386 => .I386,
.arm, .armnt => .ARMNT,
.arm64, .aarch64 => .ARM64,
Expand Down Expand Up @@ -1079,26 +1079,26 @@ pub const supported_targets = struct {
};

// https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#type-indicators
pub fn rvaRelocationTypeIndicator(target: std.coff.MachineType) ?u16 {
pub fn rvaRelocationTypeIndicator(target: std.coff.IMAGE.FILE.MACHINE) ?u16 {
return switch (target) {
.X64 => 0x3, // IMAGE_REL_AMD64_ADDR32NB
.I386 => 0x7, // IMAGE_REL_I386_DIR32NB
.ARMNT => 0x2, // IMAGE_REL_ARM_ADDR32NB
.ARM64, .ARM64EC, .ARM64X => 0x2, // IMAGE_REL_ARM64_ADDR32NB
.IA64 => 0x10, // IMAGE_REL_IA64_DIR32NB
.AMD64 => @intFromEnum(std.coff.IMAGE.REL.AMD64.ADDR32NB),
.I386 => @intFromEnum(std.coff.IMAGE.REL.I386.DIR32NB),
.ARMNT => @intFromEnum(std.coff.IMAGE.REL.ARM.ADDR32NB),
.ARM64, .ARM64EC, .ARM64X => @intFromEnum(std.coff.IMAGE.REL.ARM64.ADDR32NB),
.IA64 => @intFromEnum(std.coff.IMAGE.REL.IA64.DIR32NB),
.EBC => 0x1, // This is what cvtres.exe writes for this target, unsure where it comes from
else => null,
};
}

pub fn isSupported(target: std.coff.MachineType) bool {
pub fn isSupported(target: std.coff.IMAGE.FILE.MACHINE) bool {
return rvaRelocationTypeIndicator(target) != null;
}

comptime {
// Enforce two things:
// 1. Arch enum field names are all lowercase (necessary for how fromStringIgnoreCase is implemented)
// 2. All enum fields in Arch have an associated RVA relocation type when converted to a coff.MachineType
// 2. All enum fields in Arch have an associated RVA relocation type when converted to a coff.IMAGE.FILE.MACHINE
for (@typeInfo(Arch).@"enum".fields) |enum_field| {
const all_lower = all_lower: for (enum_field.name) |c| {
if (std.ascii.isUpper(c)) break :all_lower false;
Expand Down
6 changes: 3 additions & 3 deletions lib/compiler/resinator/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ const LazyIncludePaths = struct {
arena: std.mem.Allocator,
auto_includes_option: cli.Options.AutoIncludes,
zig_lib_dir: []const u8,
target_machine_type: std.coff.MachineType,
target_machine_type: std.coff.IMAGE.FILE.MACHINE,
resolved_include_paths: ?[]const []const u8 = null,

pub fn get(self: *LazyIncludePaths, error_handler: *ErrorHandler) ![]const []const u8 {
Expand Down Expand Up @@ -555,11 +555,11 @@ const LazyIncludePaths = struct {
}
};

fn getIncludePaths(arena: std.mem.Allocator, auto_includes_option: cli.Options.AutoIncludes, zig_lib_dir: []const u8, target_machine_type: std.coff.MachineType) ![]const []const u8 {
fn getIncludePaths(arena: std.mem.Allocator, auto_includes_option: cli.Options.AutoIncludes, zig_lib_dir: []const u8, target_machine_type: std.coff.IMAGE.FILE.MACHINE) ![]const []const u8 {
if (auto_includes_option == .none) return &[_][]const u8{};

const includes_arch: std.Target.Cpu.Arch = switch (target_machine_type) {
.X64 => .x86_64,
.AMD64 => .x86_64,
.I386 => .x86,
.ARMNT => .thumb,
.ARM64 => .aarch64,
Expand Down
4 changes: 2 additions & 2 deletions lib/std/Target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ pub fn toElfMachine(target: *const Target) std.elf.EM {
};
}

pub fn toCoffMachine(target: *const Target) std.coff.MachineType {
pub fn toCoffMachine(target: *const Target) std.coff.IMAGE.FILE.MACHINE {
return switch (target.cpu.arch) {
.arm => .ARM,
.thumb => .ARMNT,
Expand All @@ -1092,7 +1092,7 @@ pub fn toCoffMachine(target: *const Target) std.coff.MachineType {
.riscv32 => .RISCV32,
.riscv64 => .RISCV64,
.x86 => .I386,
.x86_64 => .X64,
.x86_64 => .AMD64,

.amdgcn,
.arc,
Expand Down
2 changes: 1 addition & 1 deletion lib/std/array_hash_map.zig
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn eqlString(a: []const u8, b: []const u8) bool {
}

pub fn hashString(s: []const u8) u32 {
return @as(u32, @truncate(std.hash.Wyhash.hash(0, s)));
return @truncate(std.hash.Wyhash.hash(0, s));
}

/// Deprecated in favor of `ArrayHashMapWithAllocator` (no code changes needed)
Expand Down
Loading