From b7fd61196c79f8ffeae0d65acb1636058f6934c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Larouche?= Date: Wed, 11 Mar 2020 08:12:54 -0400 Subject: [PATCH] Fix compile with emit_raw --- lib/std/build/emit_raw.zig | 6 ++---- lib/std/elf.zig | 32 ++++++++++++++++---------------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/lib/std/build/emit_raw.zig b/lib/std/build/emit_raw.zig index 63c232994..77840498c 100644 --- a/lib/std/build/emit_raw.zig +++ b/lib/std/build/emit_raw.zig @@ -36,7 +36,7 @@ const BinaryElfOutput = struct { const Self = @This(); - pub fn deinit(self: *Self) void { + pub fn deinit(self: Self) void { self.sections.deinit(); self.segments.deinit(); } @@ -48,8 +48,6 @@ const BinaryElfOutput = struct { }; const elf_hdrs = try std.elf.readAllHeaders(allocator, elf_file); - var binaryElfOutput = BinaryElfOutput.init(arena_allocator); - for (elf_hdrs.section_headers) |section, i| { if (sectionValidForOutput(section)) { const newSection = try allocator.create(BinaryElfSection); @@ -164,7 +162,7 @@ fn emitRaw(allocator: *Allocator, elf_path: []const u8, raw_path: []const u8) !v var out_file = try fs.cwd().createFile(raw_path, .{}); defer out_file.close(); - const binary_elf_output = BinaryElfOutput.parse(allocator, elf_file); + const binary_elf_output = try BinaryElfOutput.parse(allocator, elf_file); defer binary_elf_output.deinit(); for (binary_elf_output.sections.toSlice()) |section| { diff --git a/lib/std/elf.zig b/lib/std/elf.zig index 3aefd87f0..83430015d 100644 --- a/lib/std/elf.zig +++ b/lib/std/elf.zig @@ -346,15 +346,15 @@ const Header = struct { pub fn readHeader(file: File) !Header { var hdr_buf: [@sizeOf(Elf64_Ehdr)]u8 align(@alignOf(Elf64_Ehdr)) = undefined; - try in_stream.preadAll(&hdr_buf, 0); - const hdr32 = @ptrCast(*elf.Elf32_Ehdr, &hdr_buf); - const hdr64 = @ptrCast(*elf.Elf64_Ehdr, &hdr_buf); + try file.preadAll(&hdr_buf, 0); + const hdr32 = @ptrCast(*Elf32_Ehdr, &hdr_buf); + const hdr64 = @ptrCast(*Elf64_Ehdr, &hdr_buf); if (!mem.eql(u8, hdr32.e_ident[0..4], "\x7fELF")) return error.InvalidElfMagic; if (hdr32.e_ident[EI_VERSION] != 1) return error.InvalidElfVersion; - const endian = switch (hdr32.e_ident[elf.EI_DATA]) { - ELFDATA2LSB => .Little, - ELFDATA2MSB => .Big, + const endian = switch (hdr32.e_ident[EI_DATA]) { + ELFDATA2LSB => builtin.Endian.Little, + ELFDATA2MSB => builtin.Endian.Big, else => return error.InvalidElfEndian, }; const need_bswap = endian != std.builtin.endian; @@ -406,8 +406,8 @@ pub fn readAllHeaders(allocator: *mem.Allocator, file: File) !AllHeaders { // Treat section headers and program headers as byte buffers. For 32-bit ELF and // non-matching endian files, we post-process to correct integer endianness and offsets. - const shdr_buf = std.mem.sliceToBytes(hdrs.section_headers)[0 .. hdrs.header.shentsize * hdrs.header.shnum]; - const phdr_buf = std.mem.sliceToBytes(hdrs.section_headers)[0 .. hdrs.header.phentsize * hdrs.header.phnum]; + const shdr_buf = std.mem.sliceAsBytes(hdrs.section_headers)[0 .. hdrs.header.shentsize * hdrs.header.shnum]; + const phdr_buf = std.mem.sliceAsBytes(hdrs.section_headers)[0 .. hdrs.header.phentsize * hdrs.header.phnum]; try file.preadAll(phdr_buf, hdrs.header.phoff); try file.preadAll(shdr_buf, hdrs.header.shoff); @@ -430,14 +430,14 @@ pub fn readAllHeaders(allocator: *mem.Allocator, file: File) !AllHeaders { } for (hdrs.program_headers) |*phdr, i| { phdr.* = .{ - .p_type = int(is_64, need_bswap, phdrs32[i].p_type, shdr.p_type), - .p_offset = int(is_64, need_bswap, phdrs32[i].p_offset, shdr.p_offset), - .p_vaddr = int(is_64, need_bswap, phdrs32[i].p_vaddr, shdr.p_vaddr), - .p_paddr = int(is_64, need_bswap, phdrs32[i].p_paddr, shdr.p_paddr), - .p_filesz = int(is_64, need_bswap, phdrs32[i].p_filesz, shdr.p_filesz), - .p_memsz = int(is_64, need_bswap, phdrs32[i].p_memsz, shdr.p_memsz), - .p_flags = int(is_64, need_bswap, phdrs32[i].p_flags, shdr.p_flags), - .p_align = int(is_64, need_bswap, phdrs32[i].p_align, shdr.p_align), + .p_type = int(is_64, need_bswap, phdrs32[i].p_type, phdr.p_type), + .p_offset = int(is_64, need_bswap, phdrs32[i].p_offset, phdr.p_offset), + .p_vaddr = int(is_64, need_bswap, phdrs32[i].p_vaddr, phdr.p_vaddr), + .p_paddr = int(is_64, need_bswap, phdrs32[i].p_paddr, phdr.p_paddr), + .p_filesz = int(is_64, need_bswap, phdrs32[i].p_filesz, phdr.p_filesz), + .p_memsz = int(is_64, need_bswap, phdrs32[i].p_memsz, phdr.p_memsz), + .p_flags = int(is_64, need_bswap, phdrs32[i].p_flags, phdr.p_flags), + .p_align = int(is_64, need_bswap, phdrs32[i].p_align, phdr.p_align), }; } return hdrs; -- 2.25.1.windows.1