diff options
| author | Veikka Tuominen <git@vexu.eu> | 2023-05-26 23:29:05 +0300 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-05-26 21:42:19 -0700 |
| commit | ca16f1e8a703491bcaac0d13379d2556e8ca837d (patch) | |
| tree | fefadd0912e8e3deedbf0a7261219fbd7ee5149f /src/link | |
| parent | dbd44658ff2d392451ea4f3a38ca4bd26da34314 (diff) | |
| download | zig-ca16f1e8a703491bcaac0d13379d2556e8ca837d.tar.gz zig-ca16f1e8a703491bcaac0d13379d2556e8ca837d.zip | |
std.Target adjustments
* move `ptrBitWidth` from Arch to Target since it needs to know about the abi
* double isn't always 8 bits
* AVR uses 1-byte alignment for everything in GCC
Diffstat (limited to 'src/link')
| -rw-r--r-- | src/link/Coff.zig | 2 | ||||
| -rw-r--r-- | src/link/Coff/lld.zig | 2 | ||||
| -rw-r--r-- | src/link/Dwarf.zig | 6 | ||||
| -rw-r--r-- | src/link/Elf.zig | 12 | ||||
| -rw-r--r-- | src/link/Elf/Atom.zig | 2 | ||||
| -rw-r--r-- | src/link/Plan9.zig | 2 |
6 files changed, 13 insertions, 13 deletions
diff --git a/src/link/Coff.zig b/src/link/Coff.zig index 01f18a73b3..62a208406e 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -245,7 +245,7 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option } pub fn createEmpty(gpa: Allocator, options: link.Options) !*Coff { - const ptr_width: PtrWidth = switch (options.target.cpu.arch.ptrBitWidth()) { + const ptr_width: PtrWidth = switch (options.target.ptrBitWidth()) { 0...32 => .p32, 33...64 => .p64, else => return error.UnsupportedCOFFArchitecture, diff --git a/src/link/Coff/lld.zig b/src/link/Coff/lld.zig index 78eb2d39e5..656b0f9a97 100644 --- a/src/link/Coff/lld.zig +++ b/src/link/Coff/lld.zig @@ -199,7 +199,7 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod } else if (target.cpu.arch == .x86_64) { try argv.append("-MACHINE:X64"); } else if (target.cpu.arch.isARM()) { - if (target.cpu.arch.ptrBitWidth() == 32) { + if (target.ptrBitWidth() == 32) { try argv.append("-MACHINE:ARM"); } else { try argv.append("-MACHINE:ARM64"); diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig index 1a064049fc..1d358a29ab 100644 --- a/src/link/Dwarf.zig +++ b/src/link/Dwarf.zig @@ -260,7 +260,7 @@ pub const DeclState = struct { .Pointer => { if (ty.isSlice()) { // Slices are structs: struct { .ptr = *, .len = N } - const ptr_bits = target.cpu.arch.ptrBitWidth(); + const ptr_bits = target.ptrBitWidth(); const ptr_bytes = @intCast(u8, @divExact(ptr_bits, 8)); // DW.AT.structure_type try dbg_info_buffer.ensureUnusedCapacity(2); @@ -751,7 +751,7 @@ pub const DeclState = struct { .memory, .linker_load, => { - const ptr_width = @intCast(u8, @divExact(target.cpu.arch.ptrBitWidth(), 8)); + const ptr_width = @intCast(u8, @divExact(target.ptrBitWidth(), 8)); try dbg_info.ensureUnusedCapacity(2 + ptr_width); dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc 1 + ptr_width + @boolToInt(is_ptr), @@ -928,7 +928,7 @@ const min_nop_size = 2; const ideal_factor = 3; pub fn init(allocator: Allocator, bin_file: *File, target: std.Target) Dwarf { - const ptr_width: PtrWidth = switch (target.cpu.arch.ptrBitWidth()) { + const ptr_width: PtrWidth = switch (target.ptrBitWidth()) { 0...32 => .p32, 33...64 => .p64, else => unreachable, diff --git a/src/link/Elf.zig b/src/link/Elf.zig index f90f4ebd46..9fa48a9e62 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -273,7 +273,7 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option } pub fn createEmpty(gpa: Allocator, options: link.Options) !*Elf { - const ptr_width: PtrWidth = switch (options.target.cpu.arch.ptrBitWidth()) { + const ptr_width: PtrWidth = switch (options.target.ptrBitWidth()) { 0...32 => .p32, 33...64 => .p64, else => return error.UnsupportedELFArchitecture, @@ -474,7 +474,7 @@ pub fn populateMissingMetadata(self: *Elf) !void { if (self.phdr_table_load_index == null) { self.phdr_table_load_index = @intCast(u16, self.program_headers.items.len); // TODO Same as for GOT - const phdr_addr: u64 = if (self.base.options.target.cpu.arch.ptrBitWidth() >= 32) 0x1000000 else 0x1000; + const phdr_addr: u64 = if (self.base.options.target.ptrBitWidth() >= 32) 0x1000000 else 0x1000; const p_align = self.page_size; try self.program_headers.append(gpa, .{ .p_type = elf.PT_LOAD, @@ -521,7 +521,7 @@ pub fn populateMissingMetadata(self: *Elf) !void { // TODO instead of hard coding the vaddr, make a function to find a vaddr to put things at. // we'll need to re-use that function anyway, in case the GOT grows and overlaps something // else in virtual memory. - const got_addr: u32 = if (self.base.options.target.cpu.arch.ptrBitWidth() >= 32) 0x4000000 else 0x8000; + const got_addr: u32 = if (self.base.options.target.ptrBitWidth() >= 32) 0x4000000 else 0x8000; try self.program_headers.append(gpa, .{ .p_type = elf.PT_LOAD, .p_offset = off, @@ -544,7 +544,7 @@ pub fn populateMissingMetadata(self: *Elf) !void { const off = self.findFreeSpace(file_size, p_align); log.debug("found PT_LOAD RO free space 0x{x} to 0x{x}", .{ off, off + file_size }); // TODO Same as for GOT - const rodata_addr: u32 = if (self.base.options.target.cpu.arch.ptrBitWidth() >= 32) 0xc000000 else 0xa000; + const rodata_addr: u32 = if (self.base.options.target.ptrBitWidth() >= 32) 0xc000000 else 0xa000; try self.program_headers.append(gpa, .{ .p_type = elf.PT_LOAD, .p_offset = off, @@ -567,7 +567,7 @@ pub fn populateMissingMetadata(self: *Elf) !void { const off = self.findFreeSpace(file_size, p_align); log.debug("found PT_LOAD RW free space 0x{x} to 0x{x}", .{ off, off + file_size }); // TODO Same as for GOT - const rwdata_addr: u32 = if (self.base.options.target.cpu.arch.ptrBitWidth() >= 32) 0x10000000 else 0xc000; + const rwdata_addr: u32 = if (self.base.options.target.ptrBitWidth() >= 32) 0x10000000 else 0xc000; try self.program_headers.append(gpa, .{ .p_type = elf.PT_LOAD, .p_offset = off, @@ -3180,7 +3180,7 @@ fn ptrWidthBytes(self: Elf) u8 { /// Does not necessarily match `ptrWidthBytes` for example can be 2 bytes /// in a 32-bit ELF file. fn archPtrWidthBytes(self: Elf) u8 { - return @intCast(u8, self.base.options.target.cpu.arch.ptrBitWidth() / 8); + return @intCast(u8, self.base.options.target.ptrBitWidth() / 8); } fn progHeaderTo32(phdr: elf.Elf64_Phdr) elf.Elf32_Phdr { diff --git a/src/link/Elf/Atom.zig b/src/link/Elf/Atom.zig index 70be5abbca..b437be3282 100644 --- a/src/link/Elf/Atom.zig +++ b/src/link/Elf/Atom.zig @@ -59,7 +59,7 @@ pub fn getOffsetTableAddress(self: Atom, elf_file: *Elf) u64 { const sym_index = self.getSymbolIndex().?; const got_entry_index = elf_file.got_table.lookup.get(sym_index).?; const target = elf_file.base.options.target; - const ptr_bits = target.cpu.arch.ptrBitWidth(); + const ptr_bits = target.ptrBitWidth(); const ptr_bytes: u64 = @divExact(ptr_bits, 8); const got = elf_file.program_headers.items[elf_file.phdr_got_index.?]; return got.p_vaddr + got_entry_index * ptr_bytes; diff --git a/src/link/Plan9.zig b/src/link/Plan9.zig index bef06d1c87..a785f084cb 100644 --- a/src/link/Plan9.zig +++ b/src/link/Plan9.zig @@ -183,7 +183,7 @@ pub fn defaultBaseAddrs(arch: std.Target.Cpu.Arch) Bases { pub fn createEmpty(gpa: Allocator, options: link.Options) !*Plan9 { if (options.use_llvm) return error.LLVMBackendDoesNotSupportPlan9; - const sixtyfour_bit: bool = switch (options.target.cpu.arch.ptrBitWidth()) { + const sixtyfour_bit: bool = switch (options.target.ptrBitWidth()) { 0...32 => false, 33...64 => true, else => return error.UnsupportedP9Architecture, |
