| ... | ... | @@ -127,7 +127,7 @@ const SectionIndexes = struct { |
| 127 | 127 | symtab: ?u32 = null, |
| 128 | 128 | }; |
| 129 | 129 | |
| 130 | | const ProgramHeaderList = std.ArrayList(elf.Elf64_Phdr); |
| 130 | const ProgramHeaderList = std.ArrayList(elf.Elf64.Phdr); |
| 131 | 131 | |
| 132 | 132 | const OptionalProgramHeaderIndex = enum(u16) { |
| 133 | 133 | none = std.math.maxInt(u16), |
| ... | ... | @@ -337,7 +337,7 @@ pub fn createEmpty( |
| 337 | 337 | // Initialize PT.PHDR program header |
| 338 | 338 | const p_align: u16 = switch (self.ptr_width) { |
| 339 | 339 | .p32 => @alignOf(elf.Elf32.Phdr), |
| 340 | | .p64 => @alignOf(elf.Elf64_Phdr), |
| 340 | .p64 => @alignOf(elf.Elf64.Phdr), |
| 341 | 341 | }; |
| 342 | 342 | const ehsize: u64 = switch (self.ptr_width) { |
| 343 | 343 | .p32 => @sizeOf(elf.Elf32_Ehdr), |
| ... | ... | @@ -345,7 +345,7 @@ pub fn createEmpty( |
| 345 | 345 | }; |
| 346 | 346 | const phsize: u64 = switch (self.ptr_width) { |
| 347 | 347 | .p32 => @sizeOf(elf.Elf32.Phdr), |
| 348 | | .p64 => @sizeOf(elf.Elf64_Phdr), |
| 348 | .p64 => @sizeOf(elf.Elf64.Phdr), |
| 349 | 349 | }; |
| 350 | 350 | const max_nphdrs = comptime getMaxNumberOfPhdrs(); |
| 351 | 351 | const reserved: u64 = mem.alignForward(u64, padToIdeal(max_nphdrs * phsize), self.page_size); |
| ... | ... | @@ -514,11 +514,11 @@ fn detectAllocCollision(self: *Elf, start: u64, size: u64) !?u64 { |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | for (self.phdrs.items) |phdr| { |
| 517 | | if (phdr.p_type != @backingInt(elf.PT.LOAD)) continue; |
| 518 | | const increased_size = padToIdeal(phdr.p_filesz); |
| 519 | | const test_end = phdr.p_offset +| increased_size; |
| 517 | if (phdr.type != .LOAD) continue; |
| 518 | const increased_size = padToIdeal(phdr.filesz); |
| 519 | const test_end = phdr.offset +| increased_size; |
| 520 | 520 | if (start < test_end) { |
| 521 | | if (end > phdr.p_offset) return test_end; |
| 521 | if (end > phdr.offset) return test_end; |
| 522 | 522 | if (test_end < std.math.maxInt(u64)) at_end = false; |
| 523 | 523 | } |
| 524 | 524 | } |
| ... | ... | @@ -538,8 +538,8 @@ pub fn allocatedSize(self: *Elf, start: u64) u64 { |
| 538 | 538 | if (section.sh_offset < min_pos) min_pos = section.sh_offset; |
| 539 | 539 | } |
| 540 | 540 | for (self.phdrs.items) |phdr| { |
| 541 | | if (phdr.p_offset <= start) continue; |
| 542 | | if (phdr.p_offset < min_pos) min_pos = phdr.p_offset; |
| 541 | if (phdr.offset <= start) continue; |
| 542 | if (phdr.offset < min_pos) min_pos = phdr.offset; |
| 543 | 543 | } |
| 544 | 544 | return min_pos - start; |
| 545 | 545 | } |
| ... | ... | @@ -1471,8 +1471,8 @@ fn writePhdrTable(self: *Elf) !void { |
| 1471 | 1471 | const phdr_table = &self.phdrs.items[self.phdr_indexes.table.int().?]; |
| 1472 | 1472 | |
| 1473 | 1473 | log.debug("writing program headers from 0x{x} to 0x{x}", .{ |
| 1474 | | phdr_table.p_offset, |
| 1475 | | phdr_table.p_offset + phdr_table.p_filesz, |
| 1474 | phdr_table.offset, |
| 1475 | phdr_table.offset + phdr_table.filesz, |
| 1476 | 1476 | }); |
| 1477 | 1477 | |
| 1478 | 1478 | switch (self.ptr_width) { |
| ... | ... | @@ -1486,19 +1486,19 @@ fn writePhdrTable(self: *Elf) !void { |
| 1486 | 1486 | mem.byteSwapAllFields(elf.Elf32.Phdr, phdr); |
| 1487 | 1487 | } |
| 1488 | 1488 | } |
| 1489 | | try self.pwriteAll(@ptrCast(buf), phdr_table.p_offset); |
| 1489 | try self.pwriteAll(@ptrCast(buf), phdr_table.offset); |
| 1490 | 1490 | }, |
| 1491 | 1491 | .p64 => { |
| 1492 | | const buf = try gpa.alloc(elf.Elf64_Phdr, self.phdrs.items.len); |
| 1492 | const buf = try gpa.alloc(elf.Elf64.Phdr, self.phdrs.items.len); |
| 1493 | 1493 | defer gpa.free(buf); |
| 1494 | 1494 | |
| 1495 | 1495 | for (buf, 0..) |*phdr, i| { |
| 1496 | 1496 | phdr.* = self.phdrs.items[i]; |
| 1497 | 1497 | if (foreign_endian) { |
| 1498 | | mem.byteSwapAllFields(elf.Elf64_Phdr, phdr); |
| 1498 | mem.byteSwapAllFields(elf.Elf64.Phdr, phdr); |
| 1499 | 1499 | } |
| 1500 | 1500 | } |
| 1501 | | try self.pwriteAll(@ptrCast(buf), phdr_table.p_offset); |
| 1501 | try self.pwriteAll(@ptrCast(buf), phdr_table.offset); |
| 1502 | 1502 | }, |
| 1503 | 1503 | } |
| 1504 | 1504 | } |
| ... | ... | @@ -1581,7 +1581,7 @@ pub fn writeElfHeader(self: *Elf) !void { |
| 1581 | 1581 | const entry_sym = obj.entrySymbol(self) orelse break :blk 0; |
| 1582 | 1582 | break :blk @intCast(entry_sym.address(.{}, self)); |
| 1583 | 1583 | } else 0; |
| 1584 | | const phdr_table_offset = if (self.phdr_indexes.table.int()) |phndx| self.phdrs.items[phndx].p_offset else 0; |
| 1584 | const phdr_table_offset = if (self.phdr_indexes.table.int()) |phndx| self.phdrs.items[phndx].offset else 0; |
| 1585 | 1585 | switch (self.ptr_width) { |
| 1586 | 1586 | .p32 => { |
| 1587 | 1587 | mem.writeInt(u32, hdr_buf[index..][0..4], @intCast(e_entry), endian); |
| ... | ... | @@ -1623,7 +1623,7 @@ pub fn writeElfHeader(self: *Elf) !void { |
| 1623 | 1623 | |
| 1624 | 1624 | const e_phentsize: u16 = switch (self.ptr_width) { |
| 1625 | 1625 | .p32 => @sizeOf(elf.Elf32.Phdr), |
| 1626 | | .p64 => @sizeOf(elf.Elf64_Phdr), |
| 1626 | .p64 => @sizeOf(elf.Elf64.Phdr), |
| 1627 | 1627 | }; |
| 1628 | 1628 | mem.writeInt(u16, hdr_buf[index..][0..2], e_phentsize, endian); |
| 1629 | 1629 | index += 2; |
| ... | ... | @@ -2260,15 +2260,15 @@ fn setHashSections(self: *Elf) !void { |
| 2260 | 2260 | } |
| 2261 | 2261 | } |
| 2262 | 2262 | |
| 2263 | | fn phdrRank(phdr: elf.Elf64_Phdr) u8 { |
| 2264 | | return switch (phdr.p_type) { |
| 2265 | | @backingInt(elf.PT.NULL) => 0, |
| 2266 | | @backingInt(elf.PT.PHDR) => 1, |
| 2267 | | @backingInt(elf.PT.INTERP) => 2, |
| 2268 | | @backingInt(elf.PT.LOAD) => 3, |
| 2269 | | @backingInt(elf.PT.DYNAMIC), @backingInt(elf.PT.TLS) => 4, |
| 2270 | | @backingInt(elf.PT.GNU_EH_FRAME) => 5, |
| 2271 | | @backingInt(elf.PT.GNU_STACK) => 6, |
| 2263 | fn phdrRank(phdr: elf.Elf64.Phdr) u8 { |
| 2264 | return switch (phdr.type) { |
| 2265 | .NULL => 0, |
| 2266 | .PHDR => 1, |
| 2267 | .INTERP => 2, |
| 2268 | .LOAD => 3, |
| 2269 | .DYNAMIC, .TLS => 4, |
| 2270 | .GNU_EH_FRAME => 5, |
| 2271 | .GNU_STACK => 6, |
| 2272 | 2272 | else => 7, |
| 2273 | 2273 | }; |
| 2274 | 2274 | } |
| ... | ... | @@ -2282,12 +2282,12 @@ fn sortPhdrs( |
| 2282 | 2282 | const Entry = struct { |
| 2283 | 2283 | phndx: u16, |
| 2284 | 2284 | |
| 2285 | | pub fn lessThan(program_headers: []const elf.Elf64_Phdr, lhs: @This(), rhs: @This()) bool { |
| 2285 | pub fn lessThan(program_headers: []const elf.Elf64.Phdr, lhs: @This(), rhs: @This()) bool { |
| 2286 | 2286 | const lhs_phdr = program_headers[lhs.phndx]; |
| 2287 | 2287 | const rhs_phdr = program_headers[rhs.phndx]; |
| 2288 | 2288 | const lhs_rank = phdrRank(lhs_phdr); |
| 2289 | 2289 | const rhs_rank = phdrRank(rhs_phdr); |
| 2290 | | if (lhs_rank == rhs_rank) return lhs_phdr.p_vaddr < rhs_phdr.p_vaddr; |
| 2290 | if (lhs_rank == rhs_rank) return lhs_phdr.vaddr < rhs_phdr.vaddr; |
| 2291 | 2291 | return lhs_rank < rhs_rank; |
| 2292 | 2292 | } |
| 2293 | 2293 | }; |
| ... | ... | @@ -2299,7 +2299,7 @@ fn sortPhdrs( |
| 2299 | 2299 | } |
| 2300 | 2300 | |
| 2301 | 2301 | // The `@as` here works around a bug in the C backend. |
| 2302 | | mem.sort(Entry, entries, @as([]const elf.Elf64_Phdr, phdrs.items), Entry.lessThan); |
| 2302 | mem.sort(Entry, entries, @as([]const elf.Elf64.Phdr, phdrs.items), Entry.lessThan); |
| 2303 | 2303 | |
| 2304 | 2304 | const backlinks = try gpa.alloc(u16, entries.len); |
| 2305 | 2305 | defer gpa.free(backlinks); |
| ... | ... | @@ -2673,10 +2673,10 @@ fn allocatePhdrTable(self: *Elf) error{OutOfMemory}!void { |
| 2673 | 2673 | }; |
| 2674 | 2674 | const phsize: u64 = switch (self.ptr_width) { |
| 2675 | 2675 | .p32 => @sizeOf(elf.Elf32.Phdr), |
| 2676 | | .p64 => @sizeOf(elf.Elf64_Phdr), |
| 2676 | .p64 => @sizeOf(elf.Elf64.Phdr), |
| 2677 | 2677 | }; |
| 2678 | 2678 | const needed_size = self.phdrs.items.len * phsize; |
| 2679 | | const available_space = self.allocatedSize(phdr_table.p_offset); |
| 2679 | const available_space = self.allocatedSize(phdr_table.offset); |
| 2680 | 2680 | |
| 2681 | 2681 | if (needed_size > available_space) { |
| 2682 | 2682 | // In this case, we have two options: |
| ... | ... | @@ -2689,10 +2689,10 @@ fn allocatePhdrTable(self: *Elf) error{OutOfMemory}!void { |
| 2689 | 2689 | err.addNote("required 0x{x}, available 0x{x}", .{ needed_size, available_space }); |
| 2690 | 2690 | } |
| 2691 | 2691 | |
| 2692 | | phdr_table_load.p_filesz = needed_size + ehsize; |
| 2693 | | phdr_table_load.p_memsz = needed_size + ehsize; |
| 2694 | | phdr_table.p_filesz = needed_size; |
| 2695 | | phdr_table.p_memsz = needed_size; |
| 2692 | phdr_table_load.filesz = needed_size + ehsize; |
| 2693 | phdr_table_load.memsz = needed_size + ehsize; |
| 2694 | phdr_table.filesz = needed_size; |
| 2695 | phdr_table.memsz = needed_size; |
| 2696 | 2696 | } |
| 2697 | 2697 | |
| 2698 | 2698 | /// Allocates alloc sections and creates load segments for sections |
| ... | ... | @@ -2758,7 +2758,7 @@ pub fn allocateAllocSections(self: *Elf) !void { |
| 2758 | 2758 | // of any section that is contained in a cover and use it to align |
| 2759 | 2759 | // the start address of the segement (and first section). |
| 2760 | 2760 | const phdr_table = &self.phdrs.items[self.phdr_indexes.table_load.int().?]; |
| 2761 | | var addr = phdr_table.p_vaddr + phdr_table.p_memsz; |
| 2761 | var addr = phdr_table.vaddr + phdr_table.memsz; |
| 2762 | 2762 | |
| 2763 | 2763 | for (covers) |cover| { |
| 2764 | 2764 | if (cover.items.len == 0) continue; |
| ... | ... | @@ -2819,12 +2819,12 @@ pub fn allocateAllocSections(self: *Elf) !void { |
| 2819 | 2819 | const first = slice.items(.shdr)[cover.items[0]]; |
| 2820 | 2820 | const phndx = self.getPhdr(.{ .type = @backingInt(elf.PT.LOAD), .flags = shdrToPhdrFlags(first.sh_flags) }).unwrap().?; |
| 2821 | 2821 | const phdr = &self.phdrs.items[phndx.int()]; |
| 2822 | | const allocated_size = self.allocatedSize(phdr.p_offset); |
| 2822 | const allocated_size = self.allocatedSize(phdr.offset); |
| 2823 | 2823 | if (filesz > allocated_size) { |
| 2824 | | const old_offset = phdr.p_offset; |
| 2825 | | phdr.p_offset = 0; |
| 2824 | const old_offset = phdr.offset; |
| 2825 | phdr.offset = 0; |
| 2826 | 2826 | var new_offset = try self.findFreeSpace(filesz, @"align"); |
| 2827 | | phdr.p_offset = new_offset; |
| 2827 | phdr.offset = new_offset; |
| 2828 | 2828 | |
| 2829 | 2829 | log.debug("moving phdr({d}) from 0x{x} to 0x{x}", .{ phndx, old_offset, new_offset }); |
| 2830 | 2830 | |
| ... | ... | @@ -2854,11 +2854,11 @@ pub fn allocateAllocSections(self: *Elf) !void { |
| 2854 | 2854 | } |
| 2855 | 2855 | } |
| 2856 | 2856 | |
| 2857 | | phdr.p_vaddr = first.sh_addr; |
| 2858 | | phdr.p_paddr = first.sh_addr; |
| 2859 | | phdr.p_memsz = memsz; |
| 2860 | | phdr.p_filesz = filesz; |
| 2861 | | phdr.p_align = @"align"; |
| 2857 | phdr.vaddr = first.sh_addr; |
| 2858 | phdr.paddr = first.sh_addr; |
| 2859 | phdr.memsz = memsz; |
| 2860 | phdr.filesz = filesz; |
| 2861 | phdr.@"align" = @"align"; |
| 2862 | 2862 | |
| 2863 | 2863 | addr = mem.alignForward(u64, addr, self.page_size); |
| 2864 | 2864 | } |
| ... | ... | @@ -2902,12 +2902,12 @@ fn allocateSpecialPhdrs(self: *Elf) void { |
| 2902 | 2902 | if (pair[0].int()) |index| { |
| 2903 | 2903 | const shdr = slice.items(.shdr)[pair[1].?]; |
| 2904 | 2904 | const phdr = &self.phdrs.items[index]; |
| 2905 | | phdr.p_align = shdr.sh_addralign; |
| 2906 | | phdr.p_offset = shdr.sh_offset; |
| 2907 | | phdr.p_vaddr = shdr.sh_addr; |
| 2908 | | phdr.p_paddr = shdr.sh_addr; |
| 2909 | | phdr.p_filesz = shdr.sh_size; |
| 2910 | | phdr.p_memsz = shdr.sh_size; |
| 2905 | phdr.@"align" = shdr.sh_addralign; |
| 2906 | phdr.offset = shdr.sh_offset; |
| 2907 | phdr.vaddr = shdr.sh_addr; |
| 2908 | phdr.paddr = shdr.sh_addr; |
| 2909 | phdr.filesz = shdr.sh_size; |
| 2910 | phdr.memsz = shdr.sh_size; |
| 2911 | 2911 | } |
| 2912 | 2912 | } |
| 2913 | 2913 | |
| ... | ... | @@ -2924,25 +2924,25 @@ fn allocateSpecialPhdrs(self: *Elf) void { |
| 2924 | 2924 | shndx += 1; |
| 2925 | 2925 | continue; |
| 2926 | 2926 | } |
| 2927 | | phdr.p_offset = shdr.sh_offset; |
| 2928 | | phdr.p_vaddr = shdr.sh_addr; |
| 2929 | | phdr.p_paddr = shdr.sh_addr; |
| 2930 | | phdr.p_align = shdr.sh_addralign; |
| 2927 | phdr.offset = shdr.sh_offset; |
| 2928 | phdr.vaddr = shdr.sh_addr; |
| 2929 | phdr.paddr = shdr.sh_addr; |
| 2930 | phdr.@"align" = shdr.sh_addralign; |
| 2931 | 2931 | shndx += 1; |
| 2932 | | phdr.p_align = @max(phdr.p_align, shdr.sh_addralign); |
| 2932 | phdr.@"align" = @max(phdr.@"align", shdr.sh_addralign); |
| 2933 | 2933 | if (shdr.sh_type != elf.SHT_NOBITS) { |
| 2934 | | phdr.p_filesz = shdr.sh_offset + shdr.sh_size - phdr.p_offset; |
| 2934 | phdr.filesz = shdr.sh_offset + shdr.sh_size - phdr.offset; |
| 2935 | 2935 | } |
| 2936 | | phdr.p_memsz = shdr.sh_addr + shdr.sh_size - phdr.p_vaddr; |
| 2936 | phdr.memsz = shdr.sh_addr + shdr.sh_size - phdr.vaddr; |
| 2937 | 2937 | |
| 2938 | 2938 | while (shndx < shdrs.len) : (shndx += 1) { |
| 2939 | 2939 | const next = shdrs[shndx]; |
| 2940 | 2940 | if (next.sh_flags & elf.SHF_TLS == 0) break; |
| 2941 | | phdr.p_align = @max(phdr.p_align, next.sh_addralign); |
| 2941 | phdr.@"align" = @max(phdr.@"align", next.sh_addralign); |
| 2942 | 2942 | if (next.sh_type != elf.SHT_NOBITS) { |
| 2943 | | phdr.p_filesz = next.sh_offset + next.sh_size - phdr.p_offset; |
| 2943 | phdr.filesz = next.sh_offset + next.sh_size - phdr.offset; |
| 2944 | 2944 | } |
| 2945 | | phdr.p_memsz = next.sh_addr + next.sh_size - phdr.p_vaddr; |
| 2945 | phdr.memsz = next.sh_addr + next.sh_size - phdr.vaddr; |
| 2946 | 2946 | } |
| 2947 | 2947 | } |
| 2948 | 2948 | } |
| ... | ... | @@ -3347,16 +3347,16 @@ pub fn archPtrWidthBytes(self: Elf) u8 { |
| 3347 | 3347 | return @intCast(@divExact(self.getTarget().ptrBitWidth(), 8)); |
| 3348 | 3348 | } |
| 3349 | 3349 | |
| 3350 | | fn phdrTo32(phdr: elf.Elf64_Phdr) elf.Elf32.Phdr { |
| 3350 | fn phdrTo32(phdr: elf.Elf64.Phdr) elf.Elf32.Phdr { |
| 3351 | 3351 | return .{ |
| 3352 | | .type = @fromBackingInt(phdr.p_type), |
| 3353 | | .flags = @fromBackingInt(phdr.p_flags), |
| 3354 | | .offset = @intCast(phdr.p_offset), |
| 3355 | | .vaddr = @intCast(phdr.p_vaddr), |
| 3356 | | .paddr = @intCast(phdr.p_paddr), |
| 3357 | | .filesz = @intCast(phdr.p_filesz), |
| 3358 | | .memsz = @intCast(phdr.p_memsz), |
| 3359 | | .@"align" = @intCast(phdr.p_align), |
| 3352 | .type = phdr.type, |
| 3353 | .flags = phdr.flags, |
| 3354 | .offset = @intCast(phdr.offset), |
| 3355 | .vaddr = @intCast(phdr.vaddr), |
| 3356 | .paddr = @intCast(phdr.paddr), |
| 3357 | .filesz = @intCast(phdr.filesz), |
| 3358 | .memsz = @intCast(phdr.memsz), |
| 3359 | .@"align" = @intCast(phdr.@"align"), |
| 3360 | 3360 | }; |
| 3361 | 3361 | } |
| 3362 | 3362 | |
| ... | ... | @@ -3397,7 +3397,7 @@ fn getPhdr(self: *Elf, opts: struct { |
| 3397 | 3397 | if (self.phdr_indexes.table_load.int()) |index| { |
| 3398 | 3398 | if (phndx == index) continue; |
| 3399 | 3399 | } |
| 3400 | | if (phdr.p_type == opts.type and phdr.p_flags == opts.flags) |
| 3400 | if (@backingInt(phdr.type) == opts.type and @backingInt(phdr.flags) == opts.flags) |
| 3401 | 3401 | return @fromBackingInt(@intCast(phndx)); |
| 3402 | 3402 | } |
| 3403 | 3403 | return .none; |
| ... | ... | @@ -3415,14 +3415,14 @@ fn addPhdr(self: *Elf, opts: struct { |
| 3415 | 3415 | const gpa = self.base.comp.gpa; |
| 3416 | 3416 | const index: ProgramHeaderIndex = @fromBackingInt(@intCast(self.phdrs.items.len)); |
| 3417 | 3417 | try self.phdrs.append(gpa, .{ |
| 3418 | | .p_type = opts.type, |
| 3419 | | .p_flags = opts.flags, |
| 3420 | | .p_offset = opts.offset, |
| 3421 | | .p_vaddr = opts.addr, |
| 3422 | | .p_paddr = opts.addr, |
| 3423 | | .p_filesz = opts.filesz, |
| 3424 | | .p_memsz = opts.memsz, |
| 3425 | | .p_align = opts.@"align", |
| 3418 | .type = @fromBackingInt(opts.type), |
| 3419 | .flags = @fromBackingInt(opts.flags), |
| 3420 | .offset = opts.offset, |
| 3421 | .vaddr = opts.addr, |
| 3422 | .paddr = opts.addr, |
| 3423 | .filesz = opts.filesz, |
| 3424 | .memsz = opts.memsz, |
| 3425 | .@"align" = opts.@"align", |
| 3426 | 3426 | }); |
| 3427 | 3427 | return index; |
| 3428 | 3428 | } |
| ... | ... | @@ -3673,9 +3673,9 @@ pub fn tpAddress(self: *Elf) i64 { |
| 3673 | 3673 | const index = self.phdr_indexes.tls.int() orelse return 0; |
| 3674 | 3674 | const phdr = self.phdrs.items[index]; |
| 3675 | 3675 | const addr = switch (self.getTarget().cpu.arch) { |
| 3676 | | .x86_64 => mem.alignForward(u64, phdr.p_vaddr + phdr.p_memsz, phdr.p_align), |
| 3677 | | .aarch64, .aarch64_be => mem.alignBackward(u64, phdr.p_vaddr - 16, phdr.p_align), |
| 3678 | | .riscv64, .riscv64be => phdr.p_vaddr, |
| 3676 | .x86_64 => mem.alignForward(u64, phdr.vaddr + phdr.memsz, phdr.@"align"), |
| 3677 | .aarch64, .aarch64_be => mem.alignBackward(u64, phdr.vaddr - 16, phdr.@"align"), |
| 3678 | .riscv64, .riscv64be => phdr.vaddr, |
| 3679 | 3679 | else => |arch| std.debug.panic("TODO implement getTpAddress for {s}", .{@tagName(arch)}), |
| 3680 | 3680 | }; |
| 3681 | 3681 | return @intCast(addr); |
| ... | ... | @@ -3684,13 +3684,13 @@ pub fn tpAddress(self: *Elf) i64 { |
| 3684 | 3684 | pub fn dtpAddress(self: *Elf) i64 { |
| 3685 | 3685 | const index = self.phdr_indexes.tls.int() orelse return 0; |
| 3686 | 3686 | const phdr = self.phdrs.items[index]; |
| 3687 | | return @intCast(phdr.p_vaddr); |
| 3687 | return @intCast(phdr.vaddr); |
| 3688 | 3688 | } |
| 3689 | 3689 | |
| 3690 | 3690 | pub fn tlsAddress(self: *Elf) i64 { |
| 3691 | 3691 | const index = self.phdr_indexes.tls.int() orelse return 0; |
| 3692 | 3692 | const phdr = self.phdrs.items[index]; |
| 3693 | | return @intCast(phdr.p_vaddr); |
| 3693 | return @intCast(phdr.vaddr); |
| 3694 | 3694 | } |
| 3695 | 3695 | |
| 3696 | 3696 | pub fn getShString(self: Elf, off: u32) [:0]const u8 { |
| ... | ... | @@ -3886,10 +3886,10 @@ fn formatShdrFlags(sh_flags: u64, writer: *std.Io.Writer) std.Io.Writer.Error!vo |
| 3886 | 3886 | |
| 3887 | 3887 | const FormatPhdr = struct { |
| 3888 | 3888 | elf_file: *Elf, |
| 3889 | | phdr: elf.Elf64_Phdr, |
| 3889 | phdr: elf.Elf64.Phdr, |
| 3890 | 3890 | }; |
| 3891 | 3891 | |
| 3892 | | fn fmtPhdr(self: *Elf, phdr: elf.Elf64_Phdr) std.fmt.Alt(FormatPhdr, formatPhdr) { |
| 3892 | fn fmtPhdr(self: *Elf, phdr: elf.Elf64.Phdr) std.fmt.Alt(FormatPhdr, formatPhdr) { |
| 3893 | 3893 | return .{ .data = .{ |
| 3894 | 3894 | .phdr = phdr, |
| 3895 | 3895 | .elf_file = self, |
| ... | ... | @@ -3898,28 +3898,28 @@ fn fmtPhdr(self: *Elf, phdr: elf.Elf64_Phdr) std.fmt.Alt(FormatPhdr, formatPhdr) |
| 3898 | 3898 | |
| 3899 | 3899 | fn formatPhdr(ctx: FormatPhdr, writer: *std.Io.Writer) std.Io.Writer.Error!void { |
| 3900 | 3900 | const phdr = ctx.phdr; |
| 3901 | | const write = phdr.p_flags & elf.PF_W != 0; |
| 3902 | | const read = phdr.p_flags & elf.PF_R != 0; |
| 3903 | | const exec = phdr.p_flags & elf.PF_X != 0; |
| 3901 | const write = phdr.flags.W; |
| 3902 | const read = phdr.flags.R; |
| 3903 | const exec = phdr.flags.X; |
| 3904 | 3904 | var flags: [3]u8 = @splat('_'); |
| 3905 | 3905 | if (exec) flags[0] = 'X'; |
| 3906 | 3906 | if (write) flags[1] = 'W'; |
| 3907 | 3907 | if (read) flags[2] = 'R'; |
| 3908 | | const p_type = switch (phdr.p_type) { |
| 3909 | | @backingInt(elf.PT.LOAD) => "LOAD", |
| 3910 | | @backingInt(elf.PT.TLS) => "TLS", |
| 3911 | | @backingInt(elf.PT.GNU_EH_FRAME) => "GNU_EH_FRAME", |
| 3912 | | @backingInt(elf.PT.GNU_STACK) => "GNU_STACK", |
| 3913 | | @backingInt(elf.PT.DYNAMIC) => "DYNAMIC", |
| 3914 | | @backingInt(elf.PT.INTERP) => "INTERP", |
| 3915 | | @backingInt(elf.PT.NULL) => "NULL", |
| 3916 | | @backingInt(elf.PT.PHDR) => "PHDR", |
| 3917 | | @backingInt(elf.PT.NOTE) => "NOTE", |
| 3908 | const p_type = switch (phdr.type) { |
| 3909 | .LOAD => "LOAD", |
| 3910 | .TLS => "TLS", |
| 3911 | .GNU_EH_FRAME => "GNU_EH_FRAME", |
| 3912 | .GNU_STACK => "GNU_STACK", |
| 3913 | .DYNAMIC => "DYNAMIC", |
| 3914 | .INTERP => "INTERP", |
| 3915 | .NULL => "NULL", |
| 3916 | .PHDR => "PHDR", |
| 3917 | .NOTE => "NOTE", |
| 3918 | 3918 | else => "UNKNOWN", |
| 3919 | 3919 | }; |
| 3920 | 3920 | try writer.print("{s} : {s} : @{x} ({x}) : align({x}) : filesz({x}) : memsz({x})", .{ |
| 3921 | | p_type, flags, phdr.p_offset, phdr.p_vaddr, |
| 3922 | | phdr.p_align, phdr.p_filesz, phdr.p_memsz, |
| 3921 | p_type, flags, phdr.offset, phdr.vaddr, |
| 3922 | phdr.@"align", phdr.filesz, phdr.memsz, |
| 3923 | 3923 | }); |
| 3924 | 3924 | } |
| 3925 | 3925 | |