authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-08-30 08:58:06-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-08-30 09:24:32-04:00
log7305184203dd94fd48da69f8a468b3094b848533
treec176221151b9079e54e5977f5e9f1a027b5d9c1d
parentf0c0f697a6be87f1e926a03b6a61579cddde08e7

dwarf: share and use `std.dwarf.EH_PE` constants


3 files changed, 11 insertions(+), 47 deletions(-)

src/link/Dwarf.zig+1-1
...@@ -3825,7 +3825,7 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void {...@@ -3825,7 +3825,7 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void {
3825 sleb128(header.fixedWriter(), dwarf.debug_frame.header.data_alignment_factor) catch unreachable;3825 sleb128(header.fixedWriter(), dwarf.debug_frame.header.data_alignment_factor) catch unreachable;
3826 uleb128(header.fixedWriter(), dwarf.debug_frame.header.return_address_register) catch unreachable;3826 uleb128(header.fixedWriter(), dwarf.debug_frame.header.return_address_register) catch unreachable;
3827 uleb128(header.fixedWriter(), 1) catch unreachable;3827 uleb128(header.fixedWriter(), 1) catch unreachable;
3828 header.appendAssumeCapacity(0x10 | 0x08 | 0x03);3828 header.appendAssumeCapacity(DW.EH.PE.pcrel | DW.EH.PE.sdata4);
3829 header.appendAssumeCapacity(DW.CFA.def_cfa_sf);3829 header.appendAssumeCapacity(DW.CFA.def_cfa_sf);
3830 uleb128(header.fixedWriter(), Register.rsp.dwarfNum()) catch unreachable;3830 uleb128(header.fixedWriter(), Register.rsp.dwarfNum()) catch unreachable;
3831 sleb128(header.fixedWriter(), -1) catch unreachable;3831 sleb128(header.fixedWriter(), -1) catch unreachable;
src/link/Elf/eh_frame.zig+4-22
...@@ -482,9 +482,9 @@ pub fn writeEhFrameHdr(elf_file: *Elf, writer: anytype) !void {...@@ -482,9 +482,9 @@ pub fn writeEhFrameHdr(elf_file: *Elf, writer: anytype) !void {
482 const gpa = comp.gpa;482 const gpa = comp.gpa;
483483
484 try writer.writeByte(1); // version484 try writer.writeByte(1); // version
485 try writer.writeByte(EH_PE.pcrel | EH_PE.sdata4);485 try writer.writeByte(DW_EH_PE.pcrel | DW_EH_PE.sdata4);
486 try writer.writeByte(EH_PE.udata4);486 try writer.writeByte(DW_EH_PE.udata4);
487 try writer.writeByte(EH_PE.datarel | EH_PE.sdata4);487 try writer.writeByte(DW_EH_PE.datarel | DW_EH_PE.sdata4);
488488
489 const shdrs = elf_file.sections.items(.shdr);489 const shdrs = elf_file.sections.items(.shdr);
490 const eh_frame_shdr = shdrs[elf_file.eh_frame_section_index.?];490 const eh_frame_shdr = shdrs[elf_file.eh_frame_section_index.?];
...@@ -543,25 +543,6 @@ pub fn writeEhFrameHdr(elf_file: *Elf, writer: anytype) !void {...@@ -543,25 +543,6 @@ pub fn writeEhFrameHdr(elf_file: *Elf, writer: anytype) !void {
543543
544const eh_frame_hdr_header_size: usize = 12;544const eh_frame_hdr_header_size: usize = 12;
545545
546const EH_PE = struct {
547 pub const absptr = 0x00;
548 pub const uleb128 = 0x01;
549 pub const udata2 = 0x02;
550 pub const udata4 = 0x03;
551 pub const udata8 = 0x04;
552 pub const sleb128 = 0x09;
553 pub const sdata2 = 0x0A;
554 pub const sdata4 = 0x0B;
555 pub const sdata8 = 0x0C;
556 pub const pcrel = 0x10;
557 pub const textrel = 0x20;
558 pub const datarel = 0x30;
559 pub const funcrel = 0x40;
560 pub const aligned = 0x50;
561 pub const indirect = 0x80;
562 pub const omit = 0xFF;
563};
564
565const x86_64 = struct {546const x86_64 = struct {
566 fn resolveReloc(rec: anytype, elf_file: *Elf, rel: elf.Elf64_Rela, source: i64, target: i64, data: []u8) !void {547 fn resolveReloc(rec: anytype, elf_file: *Elf, rel: elf.Elf64_Rela, source: i64, target: i64, data: []u8) !void {
567 const r_type: elf.R_X86_64 = @enumFromInt(rel.r_type());548 const r_type: elf.R_X86_64 = @enumFromInt(rel.r_type());
...@@ -619,6 +600,7 @@ const relocation = @import("relocation.zig");...@@ -619,6 +600,7 @@ const relocation = @import("relocation.zig");
619600
620const Allocator = std.mem.Allocator;601const Allocator = std.mem.Allocator;
621const Atom = @import("Atom.zig");602const Atom = @import("Atom.zig");
603const DW_EH_PE = std.dwarf.EH.PE;
622const Elf = @import("../Elf.zig");604const Elf = @import("../Elf.zig");
623const Object = @import("Object.zig");605const Object = @import("Object.zig");
624const Symbol = @import("Symbol.zig");606const Symbol = @import("Symbol.zig");
src/link/MachO/eh_frame.zig+6-24
...@@ -29,22 +29,22 @@ pub const Cie = struct {...@@ -29,22 +29,22 @@ pub const Cie = struct {
29 for (aug[1..]) |ch| switch (ch) {29 for (aug[1..]) |ch| switch (ch) {
30 'R' => {30 'R' => {
31 const enc = try reader.readByte();31 const enc = try reader.readByte();
32 if (enc & 0xf != EH_PE.absptr or enc & EH_PE.pcrel == 0) {32 if (enc != DW_EH_PE.pcrel | DW_EH_PE.absptr) {
33 @panic("unexpected pointer encoding"); // TODO error33 @panic("unexpected pointer encoding"); // TODO error
34 }34 }
35 },35 },
36 'P' => {36 'P' => {
37 const enc = try reader.readByte();37 const enc = try reader.readByte();
38 if (enc != EH_PE.pcrel | EH_PE.indirect | EH_PE.sdata4) {38 if (enc != DW_EH_PE.pcrel | DW_EH_PE.indirect | DW_EH_PE.sdata4) {
39 @panic("unexpected personality pointer encoding"); // TODO error39 @panic("unexpected personality pointer encoding"); // TODO error
40 }40 }
41 _ = try reader.readInt(u32, .little); // personality pointer41 _ = try reader.readInt(u32, .little); // personality pointer
42 },42 },
43 'L' => {43 'L' => {
44 const enc = try reader.readByte();44 const enc = try reader.readByte();
45 switch (enc & 0xf) {45 switch (enc & DW_EH_PE.type_mask) {
46 EH_PE.sdata4 => cie.lsda_size = .p32,46 DW_EH_PE.sdata4 => cie.lsda_size = .p32,
47 EH_PE.absptr => cie.lsda_size = .p64,47 DW_EH_PE.absptr => cie.lsda_size = .p64,
48 else => unreachable, // TODO error48 else => unreachable, // TODO error
49 }49 }
50 },50 },
...@@ -538,25 +538,6 @@ pub fn writeRelocs(macho_file: *MachO, code: []u8, relocs: []macho.relocation_in...@@ -538,25 +538,6 @@ pub fn writeRelocs(macho_file: *MachO, code: []u8, relocs: []macho.relocation_in
538 assert(relocs.len == i);538 assert(relocs.len == i);
539}539}
540540
541pub const EH_PE = struct {
542 pub const absptr = 0x00;
543 pub const uleb128 = 0x01;
544 pub const udata2 = 0x02;
545 pub const udata4 = 0x03;
546 pub const udata8 = 0x04;
547 pub const sleb128 = 0x09;
548 pub const sdata2 = 0x0A;
549 pub const sdata4 = 0x0B;
550 pub const sdata8 = 0x0C;
551 pub const pcrel = 0x10;
552 pub const textrel = 0x20;
553 pub const datarel = 0x30;
554 pub const funcrel = 0x40;
555 pub const aligned = 0x50;
556 pub const indirect = 0x80;
557 pub const omit = 0xFF;
558};
559
560const assert = std.debug.assert;541const assert = std.debug.assert;
561const leb = std.leb;542const leb = std.leb;
562const macho = std.macho;543const macho = std.macho;
...@@ -567,6 +548,7 @@ const trace = @import("../../tracy.zig").trace;...@@ -567,6 +548,7 @@ const trace = @import("../../tracy.zig").trace;
567548
568const Allocator = std.mem.Allocator;549const Allocator = std.mem.Allocator;
569const Atom = @import("Atom.zig");550const Atom = @import("Atom.zig");
551const DW_EH_PE = std.dwarf.EH.PE;
570const File = @import("file.zig").File;552const File = @import("file.zig").File;
571const MachO = @import("../MachO.zig");553const MachO = @import("../MachO.zig");
572const Object = @import("Object.zig");554const Object = @import("Object.zig");