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 {
38253825 sleb128(header.fixedWriter(), dwarf.debug_frame.header.data_alignment_factor) catch unreachable;
38263826 uleb128(header.fixedWriter(), dwarf.debug_frame.header.return_address_register) catch unreachable;
38273827 uleb128(header.fixedWriter(), 1) catch unreachable;
3828 header.appendAssumeCapacity(0x10 | 0x08 | 0x03);
3828 header.appendAssumeCapacity(DW.EH.PE.pcrel | DW.EH.PE.sdata4);
38293829 header.appendAssumeCapacity(DW.CFA.def_cfa_sf);
38303830 uleb128(header.fixedWriter(), Register.rsp.dwarfNum()) catch unreachable;
38313831 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 {
482482 const gpa = comp.gpa;
483483
484484 try writer.writeByte(1); // version
485 try writer.writeByte(EH_PE.pcrel | EH_PE.sdata4);
486 try writer.writeByte(EH_PE.udata4);
487 try writer.writeByte(EH_PE.datarel | EH_PE.sdata4);
485 try writer.writeByte(DW_EH_PE.pcrel | DW_EH_PE.sdata4);
486 try writer.writeByte(DW_EH_PE.udata4);
487 try writer.writeByte(DW_EH_PE.datarel | DW_EH_PE.sdata4);
488488
489489 const shdrs = elf_file.sections.items(.shdr);
490490 const eh_frame_shdr = shdrs[elf_file.eh_frame_section_index.?];
......@@ -543,25 +543,6 @@ pub fn writeEhFrameHdr(elf_file: *Elf, writer: anytype) !void {
543543
544544const 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
565546const x86_64 = struct {
566547 fn resolveReloc(rec: anytype, elf_file: *Elf, rel: elf.Elf64_Rela, source: i64, target: i64, data: []u8) !void {
567548 const r_type: elf.R_X86_64 = @enumFromInt(rel.r_type());
......@@ -619,6 +600,7 @@ const relocation = @import("relocation.zig");
619600
620601const Allocator = std.mem.Allocator;
621602const Atom = @import("Atom.zig");
603const DW_EH_PE = std.dwarf.EH.PE;
622604const Elf = @import("../Elf.zig");
623605const Object = @import("Object.zig");
624606const Symbol = @import("Symbol.zig");
src/link/MachO/eh_frame.zig+6-24
......@@ -29,22 +29,22 @@ pub const Cie = struct {
2929 for (aug[1..]) |ch| switch (ch) {
3030 'R' => {
3131 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) {
3333 @panic("unexpected pointer encoding"); // TODO error
3434 }
3535 },
3636 'P' => {
3737 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) {
3939 @panic("unexpected personality pointer encoding"); // TODO error
4040 }
4141 _ = try reader.readInt(u32, .little); // personality pointer
4242 },
4343 'L' => {
4444 const enc = try reader.readByte();
45 switch (enc & 0xf) {
46 EH_PE.sdata4 => cie.lsda_size = .p32,
47 EH_PE.absptr => cie.lsda_size = .p64,
45 switch (enc & DW_EH_PE.type_mask) {
46 DW_EH_PE.sdata4 => cie.lsda_size = .p32,
47 DW_EH_PE.absptr => cie.lsda_size = .p64,
4848 else => unreachable, // TODO error
4949 }
5050 },
......@@ -538,25 +538,6 @@ pub fn writeRelocs(macho_file: *MachO, code: []u8, relocs: []macho.relocation_in
538538 assert(relocs.len == i);
539539}
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
560541const assert = std.debug.assert;
561542const leb = std.leb;
562543const macho = std.macho;
......@@ -567,6 +548,7 @@ const trace = @import("../../tracy.zig").trace;
567548
568549const Allocator = std.mem.Allocator;
569550const Atom = @import("Atom.zig");
551const DW_EH_PE = std.dwarf.EH.PE;
570552const File = @import("file.zig").File;
571553const MachO = @import("../MachO.zig");
572554const Object = @import("Object.zig");