authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-02-25 09:47:26+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-03-17 19:59:13+01:00
loge825a15b0588d2ae4d3c6ab28fb8d8fd2ae05288
tree2b658a6fd9e32ae3d0132e146b45e1f2d3d301aa
parentf52f23618d51367bfd498403e303090039f3b6b6

zld: replace ldr with add if indivisible


1 files changed, 94 insertions(+), 63 deletions(-)

src/link/MachO/Zld.zig+94-63
......@@ -16,6 +16,7 @@ const CodeSignature = @import("CodeSignature.zig");
1616const Archive = @import("Archive.zig");
1717const Object = @import("Object.zig");
1818const Trie = @import("Trie.zig");
19const aarch64 = @import("../../codegen/aarch64.zig");
1920
2021usingnamespace @import("commands.zig");
2122usingnamespace @import("bind.zig");
......@@ -299,6 +300,7 @@ fn parseInputFiles(self: *Zld, files: []const []const u8) !void {
299300fn parseObjectFile(self: *Zld, object: *const Object) !void {
300301 const seg_cmd = object.load_commands.items[object.segment_cmd_index.?].Segment;
301302 for (seg_cmd.sections.items) |sect| {
303 const segname = parseName(&sect.segname);
302304 const sectname = parseName(&sect.sectname);
303305
304306 const seg_index = self.segments_directory.get(sect.segname) orelse {
......@@ -384,7 +386,7 @@ fn resolveImports(self: *Zld) !void {
384386 mem.eql(u8, sym_name, "___stack_chk_guard") or
385387 mem.eql(u8, sym_name, "_environ"))
386388 {
387 log.debug("writing nonlazy symbol '{s}'", .{sym_name});
389 log.warn("writing nonlazy symbol '{s}'", .{sym_name});
388390 const index = @intCast(u32, self.nonlazy_imports.items().len);
389391 try self.nonlazy_imports.putNoClobber(self.allocator, key, .{
390392 .symbol = new_sym,
......@@ -392,7 +394,7 @@ fn resolveImports(self: *Zld) !void {
392394 .index = index,
393395 });
394396 } else if (mem.eql(u8, sym_name, "__tlv_bootstrap")) {
395 log.debug("writing threadlocal symbol '{s}'", .{sym_name});
397 log.warn("writing threadlocal symbol '{s}'", .{sym_name});
396398 const index = @intCast(u32, self.threadlocal_imports.items().len);
397399 try self.threadlocal_imports.putNoClobber(self.allocator, key, .{
398400 .symbol = new_sym,
......@@ -400,7 +402,7 @@ fn resolveImports(self: *Zld) !void {
400402 .index = index,
401403 });
402404 } else {
403 log.debug("writing lazy symbol '{s}'", .{sym_name});
405 log.warn("writing lazy symbol '{s}'", .{sym_name});
404406 const index = @intCast(u32, self.lazy_imports.items().len);
405407 try self.lazy_imports.putNoClobber(self.allocator, key, .{
406408 .symbol = new_sym,
......@@ -412,7 +414,7 @@ fn resolveImports(self: *Zld) !void {
412414
413415 const n_strx = try self.makeString("dyld_stub_binder");
414416 const name = try self.allocator.dupe(u8, "dyld_stub_binder");
415 log.debug("writing nonlazy symbol 'dyld_stub_binder'", .{});
417 log.warn("writing nonlazy symbol 'dyld_stub_binder'", .{});
416418 const index = @intCast(u32, self.nonlazy_imports.items().len);
417419 try self.nonlazy_imports.putNoClobber(self.allocator, name, .{
418420 .symbol = .{
......@@ -606,7 +608,7 @@ fn writeLazySymbolPointer(self: *Zld, index: u32) !void {
606608 var buf: [@sizeOf(u64)]u8 = undefined;
607609 mem.writeIntLittle(u64, &buf, end);
608610 const off = la_symbol_ptr.offset + index * @sizeOf(u64);
609 log.debug("writing lazy symbol pointer entry 0x{x} at 0x{x}", .{ end, off });
611 log.warn("writing lazy symbol pointer entry 0x{x} at 0x{x}", .{ end, off });
610612 try self.file.?.pwriteAll(&buf, off);
611613}
612614
......@@ -619,7 +621,7 @@ fn writeStub(self: *Zld, index: u32) !void {
619621 const stub_off = stubs.offset + index * stubs.reserved2;
620622 const stub_addr = stubs.addr + index * stubs.reserved2;
621623 const la_ptr_addr = la_symbol_ptr.addr + index * @sizeOf(u64);
622 log.debug("writing stub at 0x{x}", .{stub_off});
624 log.warn("writing stub at 0x{x}", .{stub_off});
623625 var code = try self.allocator.alloc(u8, stubs.reserved2);
624626 defer self.allocator.free(code);
625627 switch (self.arch.?) {
......@@ -720,7 +722,7 @@ fn resolveSymbols(self: *Zld) !void {
720722 const sym_name = object.getString(sym.n_strx);
721723
722724 if (isLocal(&sym) and self.locals.get(sym_name) != null) {
723 log.debug("symbol '{s}' already exists; skipping", .{sym_name});
725 log.warn("symbol '{s}' already exists; skipping", .{sym_name});
724726 continue;
725727 }
726728
......@@ -734,7 +736,7 @@ fn resolveSymbols(self: *Zld) !void {
734736 const n_strx = try self.makeString(sym_name);
735737 const n_value = sym.n_value - sect.addr + next_address.get(key).?.addr;
736738
737 log.debug("resolving '{s}' as local symbol at 0x{x}", .{ sym_name, n_value });
739 log.warn("resolving '{s}' as local symbol at 0x{x}", .{ sym_name, n_value });
738740
739741 var n_sect = res.sect_index + 1;
740742 for (self.load_commands.items) |sseg, i| {
......@@ -766,8 +768,8 @@ fn doRelocs(self: *Zld) !void {
766768 defer next_space.deinit();
767769
768770 for (self.objects.items) |object| {
769 log.debug("\n\n", .{});
770 log.debug("relocating object {s}", .{object.name});
771 log.warn("\n\n", .{});
772 log.warn("relocating object {s}", .{object.name});
771773
772774 const seg = object.load_commands.items[object.segment_cmd_index.?].Segment;
773775
......@@ -802,9 +804,12 @@ fn doRelocs(self: *Zld) !void {
802804 };
803805 const next = next_space.get(key) orelse continue;
804806
805 var code = try self.allocator.alloc(u8, sect.size);
806 defer self.allocator.free(code);
807 _ = try object.file.preadAll(code, sect.offset);
807 var code = blk: {
808 var buf = try self.allocator.alloc(u8, sect.size);
809 _ = try object.file.preadAll(buf, sect.offset);
810 break :blk std.ArrayList(u8).fromOwnedSlice(self.allocator, buf);
811 };
812 defer code.deinit();
808813
809814 // Parse relocs (if any)
810815 var raw_relocs = try self.allocator.alloc(u8, @sizeOf(macho.relocation_info) * sect.nreloc);
......@@ -822,34 +827,34 @@ fn doRelocs(self: *Zld) !void {
822827 switch (self.arch.?) {
823828 .aarch64 => {
824829 const rel_type = @intToEnum(macho.reloc_type_arm64, rel.r_type);
825 log.debug("{s}", .{rel_type});
826 log.debug(" | source address 0x{x}", .{this_addr});
827 log.debug(" | offset 0x{x}", .{off});
830 log.warn("{s}", .{rel_type});
831 log.warn(" | source address 0x{x}", .{this_addr});
832 log.warn(" | offset 0x{x}", .{off});
828833
829834 if (rel_type == .ARM64_RELOC_ADDEND) {
830835 addend = rel.r_symbolnum;
831 log.debug(" | calculated addend = 0x{x}", .{addend});
836 log.warn(" | calculated addend = 0x{x}", .{addend});
832837 // TODO followed by either PAGE21 or PAGEOFF12 only.
833838 continue;
834839 }
835840 },
836841 .x86_64 => {
837842 const rel_type = @intToEnum(macho.reloc_type_x86_64, rel.r_type);
838 log.debug("{s}", .{rel_type});
839 log.debug(" | source address 0x{x}", .{this_addr});
840 log.debug(" | offset 0x{x}", .{off});
843 log.warn("{s}", .{rel_type});
844 log.warn(" | source address 0x{x}", .{this_addr});
845 log.warn(" | offset 0x{x}", .{off});
841846 },
842847 else => {},
843848 }
844849
845850 const target_addr = try self.relocTargetAddr(object, rel, next_space);
846 log.debug(" | target address 0x{x}", .{target_addr});
851 log.warn(" | target address 0x{x}", .{target_addr});
847852 if (rel.r_extern == 1) {
848853 const target_symname = object.getString(object.symtab.items[rel.r_symbolnum].n_strx);
849 log.debug(" | target symbol '{s}'", .{target_symname});
854 log.warn(" | target symbol '{s}'", .{target_symname});
850855 } else {
851856 const target_sectname = seg.sections.items[rel.r_symbolnum - 1].sectname;
852 log.debug(" | target section '{s}'", .{parseName(&target_sectname)});
857 log.warn(" | target section '{s}'", .{parseName(&target_sectname)});
853858 }
854859
855860 switch (self.arch.?) {
......@@ -862,16 +867,16 @@ fn doRelocs(self: *Zld) !void {
862867 .X86_64_RELOC_GOT,
863868 => {
864869 assert(rel.r_length == 2);
865 const inst = code[off..][0..4];
870 const inst = code.items[off..][0..4];
866871 const displacement = @bitCast(u32, @intCast(i32, @intCast(i64, target_addr) - @intCast(i64, this_addr) - 4));
867872 mem.writeIntLittle(u32, inst, displacement);
868873 },
869874 .X86_64_RELOC_TLV => {
870875 assert(rel.r_length == 2);
871876 // We need to rewrite the opcode from movq to leaq.
872 code[off - 2] = 0x8d;
877 code.items[off - 2] = 0x8d;
873878 // Add displacement.
874 const inst = code[off..][0..4];
879 const inst = code.items[off..][0..4];
875880 const displacement = @bitCast(u32, @intCast(i32, @intCast(i64, target_addr) - @intCast(i64, this_addr) - 4));
876881 mem.writeIntLittle(u32, inst, displacement);
877882 },
......@@ -881,7 +886,7 @@ fn doRelocs(self: *Zld) !void {
881886 .X86_64_RELOC_SIGNED_4,
882887 => {
883888 assert(rel.r_length == 2);
884 const inst = code[off..][0..4];
889 const inst = code.items[off..][0..4];
885890 const offset: i32 = blk: {
886891 if (rel.r_extern == 1) {
887892 break :blk mem.readIntLittle(i32, inst);
......@@ -899,7 +904,7 @@ fn doRelocs(self: *Zld) !void {
899904 break :blk correction;
900905 }
901906 };
902 log.debug(" | calculated addend 0x{x}", .{offset});
907 log.warn(" | calculated addend 0x{x}", .{offset});
903908 const result = @intCast(i64, target_addr) - @intCast(i64, this_addr) - 4 + offset;
904909 const displacement = @bitCast(u32, @intCast(i32, result));
905910 mem.writeIntLittle(u32, inst, displacement);
......@@ -910,9 +915,9 @@ fn doRelocs(self: *Zld) !void {
910915 .X86_64_RELOC_UNSIGNED => {
911916 switch (rel.r_length) {
912917 3 => {
913 const inst = code[off..][0..8];
918 const inst = code.items[off..][0..8];
914919 const offset = mem.readIntLittle(i64, inst);
915 log.debug(" | calculated addend 0x{x}", .{offset});
920 log.warn(" | calculated addend 0x{x}", .{offset});
916921 const result = if (sub) |s|
917922 @intCast(i64, target_addr) - s + offset
918923 else
......@@ -934,9 +939,9 @@ fn doRelocs(self: *Zld) !void {
934939 }
935940 },
936941 2 => {
937 const inst = code[off..][0..4];
942 const inst = code.items[off..][0..4];
938943 const offset = mem.readIntLittle(i32, inst);
939 log.debug(" | calculated addend 0x{x}", .{offset});
944 log.warn(" | calculated addend 0x{x}", .{offset});
940945 const result = if (sub) |s|
941946 @intCast(i64, target_addr) - s + offset
942947 else
......@@ -958,7 +963,7 @@ fn doRelocs(self: *Zld) !void {
958963 switch (rel_type) {
959964 .ARM64_RELOC_BRANCH26 => {
960965 assert(rel.r_length == 2);
961 const inst = code[off..][0..4];
966 const inst = code.items[off..][0..4];
962967 const displacement = @intCast(i28, @intCast(i64, target_addr) - @intCast(i64, this_addr));
963968 var parsed = mem.bytesAsValue(meta.TagPayload(Arm64, Arm64.Branch), inst);
964969 parsed.disp = @truncate(u26, @bitCast(u28, displacement) >> 2);
......@@ -968,12 +973,18 @@ fn doRelocs(self: *Zld) !void {
968973 .ARM64_RELOC_TLVP_LOAD_PAGE21,
969974 => {
970975 assert(rel.r_length == 2);
971 const inst = code[off..][0..4];
976 const inst = code.items[off..][0..4];
972977 const ta = if (addend) |a| target_addr + a else target_addr;
973978 const this_page = @intCast(i32, this_addr >> 12);
974979 const target_page = @intCast(i32, ta >> 12);
975980 const pages = @bitCast(u21, @intCast(i21, target_page - this_page));
976 log.debug(" | moving by {} pages", .{pages});
981 if (pages == 0) {
982 // No need to execute adrp. Instead, replace with a nop.
983 log.warn(" | replacing ADRP with NOP", .{});
984 mem.writeIntLittle(u32, inst, aarch64.Instruction.nop().toU32());
985 continue;
986 }
987 log.warn(" | moving by {} pages", .{pages});
977988 var parsed = mem.bytesAsValue(meta.TagPayload(Arm64, Arm64.Address), inst);
978989 parsed.immhi = @truncate(u19, pages >> 2);
979990 parsed.immlo = @truncate(u2, pages);
......@@ -982,22 +993,42 @@ fn doRelocs(self: *Zld) !void {
982993 .ARM64_RELOC_PAGEOFF12,
983994 .ARM64_RELOC_GOT_LOAD_PAGEOFF12,
984995 => {
985 const inst = code[off..][0..4];
996 const inst = code.items[off..][0..4];
986997 if (Arm64.isArithmetic(inst)) {
987 log.debug(" | detected ADD opcode", .{});
998 log.warn(" | detected ADD opcode", .{});
988999 // add
9891000 var parsed = mem.bytesAsValue(meta.TagPayload(Arm64, Arm64.Add), inst);
9901001 const ta = if (addend) |a| target_addr + a else target_addr;
9911002 const narrowed = @truncate(u12, ta);
1003 if (narrowed == 0) {
1004 // No need to execute add. Instead, replace with a nop.
1005 log.warn(" | replacing ADD with NOP", .{});
1006 mem.writeIntLittle(u32, inst, aarch64.Instruction.nop().toU32());
1007 continue;
1008 }
9921009 parsed.offset = narrowed;
9931010 } else {
994 log.debug(" | detected LDR/STR opcode", .{});
1011 log.warn(" | detected LDR/STR opcode", .{});
9951012 // ldr/str
9961013 var parsed = mem.bytesAsValue(meta.TagPayload(Arm64, Arm64.LoadRegister), inst);
9971014 const ta = if (addend) |a| target_addr + a else target_addr;
9981015 const narrowed = @truncate(u12, ta);
999 const offset = if (parsed.size == 1) @divExact(narrowed, 8) else @divExact(narrowed, 4);
1000 parsed.offset = @truncate(u12, offset);
1016 if (narrowed == 0) {
1017 // No need to execute ldr/str. Instead, replace with a nop.
1018 log.warn(" | replacing LDR/STR with NOP", .{});
1019 mem.writeIntLittle(u32, inst, aarch64.Instruction.nop().toU32());
1020 continue;
1021 }
1022 const denom: u12 = if (parsed.size == 1) 8 else 4;
1023 const offset = math.divExact(u12, narrowed, denom) catch |_| {
1024 // If we are here, then this means we are not able to divide the offset
1025 // exactly by the required denominator. Therefore, we will use add instead of
1026 // ldr as we expect ldr to follow this instruction nonetheless.
1027 // TODO I believe ldr/str can only occur for GOT_LOAD_PAGEOFF12.
1028 mem.writeIntLittle(u32, inst, Arm64.add(parsed.rn, parsed.rn, narrowed, parsed.size).toU32());
1029 continue;
1030 };
1031 parsed.offset = offset;
10011032 }
10021033 addend = null;
10031034 },
......@@ -1008,7 +1039,7 @@ fn doRelocs(self: *Zld) !void {
10081039 rn: u5,
10091040 size: u1,
10101041 };
1011 const inst = code[off..][0..4];
1042 const inst = code.items[off..][0..4];
10121043 const parsed: RegInfo = blk: {
10131044 if (Arm64.isArithmetic(inst)) {
10141045 const curr = mem.bytesAsValue(meta.TagPayload(Arm64, Arm64.Add), inst);
......@@ -1020,7 +1051,7 @@ fn doRelocs(self: *Zld) !void {
10201051 };
10211052 const ta = if (addend) |a| target_addr + a else target_addr;
10221053 const narrowed = @truncate(u12, ta);
1023 log.debug(" | rewriting TLV access to ADD opcode", .{});
1054 log.warn(" | rewriting TLV access to ADD opcode", .{});
10241055 // For TLV, we always generate an add instruction.
10251056 mem.writeIntLittle(u32, inst, Arm64.add(parsed.rt, parsed.rn, narrowed, parsed.size).toU32());
10261057 },
......@@ -1030,9 +1061,9 @@ fn doRelocs(self: *Zld) !void {
10301061 .ARM64_RELOC_UNSIGNED => {
10311062 switch (rel.r_length) {
10321063 3 => {
1033 const inst = code[off..][0..8];
1064 const inst = code.items[off..][0..8];
10341065 const offset = mem.readIntLittle(i64, inst);
1035 log.debug(" | calculated addend 0x{x}", .{offset});
1066 log.warn(" | calculated addend 0x{x}", .{offset});
10361067 const result = if (sub) |s|
10371068 @intCast(i64, target_addr) - s + offset
10381069 else
......@@ -1054,9 +1085,9 @@ fn doRelocs(self: *Zld) !void {
10541085 }
10551086 },
10561087 2 => {
1057 const inst = code[off..][0..4];
1088 const inst = code.items[off..][0..4];
10581089 const offset = mem.readIntLittle(i32, inst);
1059 log.debug(" | calculated addend 0x{x}", .{offset});
1090 log.warn(" | calculated addend 0x{x}", .{offset});
10601091 const result = if (sub) |s|
10611092 @intCast(i64, target_addr) - s + offset
10621093 else
......@@ -1078,7 +1109,7 @@ fn doRelocs(self: *Zld) !void {
10781109 }
10791110 }
10801111
1081 log.debug("writing contents of '{s},{s}' section from '{s}' from 0x{x} to 0x{x}", .{
1112 log.warn("writing contents of '{s},{s}' section from '{s}' from 0x{x} to 0x{x}", .{
10821113 segname,
10831114 sectname,
10841115 object.name,
......@@ -1096,7 +1127,7 @@ fn doRelocs(self: *Zld) !void {
10961127 mem.set(u8, zeroes, 0);
10971128 try self.file.?.pwriteAll(zeroes, next.offset);
10981129 } else {
1099 try self.file.?.pwriteAll(code, next.offset);
1130 try self.file.?.pwriteAll(code.items, next.offset);
11001131 }
11011132 }
11021133 }
......@@ -1672,7 +1703,7 @@ fn writeRebaseInfoTable(self: *Zld) !void {
16721703 dyld_info.rebase_size = @intCast(u32, mem.alignForwardGeneric(u64, buffer.len, @sizeOf(u64)));
16731704 seg.inner.filesize += dyld_info.rebase_size;
16741705
1675 log.debug("writing rebase info from 0x{x} to 0x{x}", .{ dyld_info.rebase_off, dyld_info.rebase_off + dyld_info.rebase_size });
1706 log.warn("writing rebase info from 0x{x} to 0x{x}", .{ dyld_info.rebase_off, dyld_info.rebase_off + dyld_info.rebase_size });
16761707
16771708 try self.file.?.pwriteAll(buffer, dyld_info.rebase_off);
16781709}
......@@ -1725,7 +1756,7 @@ fn writeBindInfoTable(self: *Zld) !void {
17251756 dyld_info.bind_size = @intCast(u32, mem.alignForwardGeneric(u64, buffer.len, @alignOf(u64)));
17261757 seg.inner.filesize += dyld_info.bind_size;
17271758
1728 log.debug("writing binding info from 0x{x} to 0x{x}", .{ dyld_info.bind_off, dyld_info.bind_off + dyld_info.bind_size });
1759 log.warn("writing binding info from 0x{x} to 0x{x}", .{ dyld_info.bind_off, dyld_info.bind_off + dyld_info.bind_size });
17291760
17301761 try self.file.?.pwriteAll(buffer, dyld_info.bind_off);
17311762}
......@@ -1764,7 +1795,7 @@ fn writeLazyBindInfoTable(self: *Zld) !void {
17641795 dyld_info.lazy_bind_size = @intCast(u32, mem.alignForwardGeneric(u64, buffer.len, @alignOf(u64)));
17651796 seg.inner.filesize += dyld_info.lazy_bind_size;
17661797
1767 log.debug("writing lazy binding info from 0x{x} to 0x{x}", .{ dyld_info.lazy_bind_off, dyld_info.lazy_bind_off + dyld_info.lazy_bind_size });
1798 log.warn("writing lazy binding info from 0x{x} to 0x{x}", .{ dyld_info.lazy_bind_off, dyld_info.lazy_bind_off + dyld_info.lazy_bind_size });
17681799
17691800 try self.file.?.pwriteAll(buffer, dyld_info.lazy_bind_off);
17701801 try self.populateLazyBindOffsetsInStubHelper(buffer);
......@@ -1866,7 +1897,7 @@ fn writeExportInfo(self: *Zld) !void {
18661897 dyld_info.export_size = @intCast(u32, mem.alignForwardGeneric(u64, buffer.len, @alignOf(u64)));
18671898 seg.inner.filesize += dyld_info.export_size;
18681899
1869 log.debug("writing export info from 0x{x} to 0x{x}", .{ dyld_info.export_off, dyld_info.export_off + dyld_info.export_size });
1900 log.warn("writing export info from 0x{x} to 0x{x}", .{ dyld_info.export_off, dyld_info.export_off + dyld_info.export_size });
18701901
18711902 try self.file.?.pwriteAll(buffer, dyld_info.export_off);
18721903}
......@@ -1995,7 +2026,7 @@ fn writeDebugInfo(self: *Zld) !void {
19952026
19962027 const stabs_off = symtab.symoff;
19972028 const stabs_size = symtab.nsyms * @sizeOf(macho.nlist_64);
1998 log.debug("writing symbol stabs from 0x{x} to 0x{x}", .{ stabs_off, stabs_size + stabs_off });
2029 log.warn("writing symbol stabs from 0x{x} to 0x{x}", .{ stabs_off, stabs_size + stabs_off });
19992030 try self.file.?.pwriteAll(mem.sliceAsBytes(stabs.items), stabs_off);
20002031
20012032 linkedit.inner.filesize += stabs_size;
......@@ -2044,17 +2075,17 @@ fn writeSymbolTable(self: *Zld) !void {
20442075
20452076 const locals_off = symtab.symoff + symtab.nsyms * @sizeOf(macho.nlist_64);
20462077 const locals_size = nlocals * @sizeOf(macho.nlist_64);
2047 log.debug("writing local symbols from 0x{x} to 0x{x}", .{ locals_off, locals_size + locals_off });
2078 log.warn("writing local symbols from 0x{x} to 0x{x}", .{ locals_off, locals_size + locals_off });
20482079 try self.file.?.pwriteAll(mem.sliceAsBytes(locals.items), locals_off);
20492080
20502081 const exports_off = locals_off + locals_size;
20512082 const exports_size = nexports * @sizeOf(macho.nlist_64);
2052 log.debug("writing exported symbols from 0x{x} to 0x{x}", .{ exports_off, exports_size + exports_off });
2083 log.warn("writing exported symbols from 0x{x} to 0x{x}", .{ exports_off, exports_size + exports_off });
20532084 try self.file.?.pwriteAll(mem.sliceAsBytes(exports.items), exports_off);
20542085
20552086 const undefs_off = exports_off + exports_size;
20562087 const undefs_size = nundefs * @sizeOf(macho.nlist_64);
2057 log.debug("writing undefined symbols from 0x{x} to 0x{x}", .{ undefs_off, undefs_size + undefs_off });
2088 log.warn("writing undefined symbols from 0x{x} to 0x{x}", .{ undefs_off, undefs_size + undefs_off });
20582089 try self.file.?.pwriteAll(mem.sliceAsBytes(undefs.items), undefs_off);
20592090
20602091 symtab.nsyms += @intCast(u32, nlocals + nexports + nundefs);
......@@ -2085,7 +2116,7 @@ fn writeDynamicSymbolTable(self: *Zld) !void {
20852116 const needed_size = dysymtab.nindirectsyms * @sizeOf(u32);
20862117 seg.inner.filesize += needed_size;
20872118
2088 log.debug("writing indirect symbol table from 0x{x} to 0x{x}", .{
2119 log.warn("writing indirect symbol table from 0x{x} to 0x{x}", .{
20892120 dysymtab.indirectsymoff,
20902121 dysymtab.indirectsymoff + needed_size,
20912122 });
......@@ -2124,7 +2155,7 @@ fn writeStringTable(self: *Zld) !void {
21242155 symtab.strsize = @intCast(u32, mem.alignForwardGeneric(u64, self.strtab.items.len, @alignOf(u64)));
21252156 seg.inner.filesize += symtab.strsize;
21262157
2127 log.debug("writing string table from 0x{x} to 0x{x}", .{ symtab.stroff, symtab.stroff + symtab.strsize });
2158 log.warn("writing string table from 0x{x} to 0x{x}", .{ symtab.stroff, symtab.stroff + symtab.strsize });
21282159
21292160 try self.file.?.pwriteAll(self.strtab.items, symtab.stroff);
21302161
......@@ -2150,7 +2181,7 @@ fn writeCodeSignaturePadding(self: *Zld) !void {
21502181 seg.inner.filesize += needed_size;
21512182 seg.inner.vmsize = mem.alignForwardGeneric(u64, seg.inner.filesize, self.page_size.?);
21522183
2153 log.debug("writing code signature padding from 0x{x} to 0x{x}", .{ fileoff, fileoff + needed_size });
2184 log.warn("writing code signature padding from 0x{x} to 0x{x}", .{ fileoff, fileoff + needed_size });
21542185
21552186 // Pad out the space. We need to do this to calculate valid hashes for everything in the file
21562187 // except for code signature data.
......@@ -2176,7 +2207,7 @@ fn writeCodeSignature(self: *Zld) !void {
21762207 var stream = std.io.fixedBufferStream(buffer);
21772208 try code_sig.write(stream.writer());
21782209
2179 log.debug("writing code signature from 0x{x} to 0x{x}", .{ code_sig_cmd.dataoff, code_sig_cmd.dataoff + buffer.len });
2210 log.warn("writing code signature from 0x{x} to 0x{x}", .{ code_sig_cmd.dataoff, code_sig_cmd.dataoff + buffer.len });
21802211
21812212 try self.file.?.pwriteAll(buffer, code_sig_cmd.dataoff);
21822213}
......@@ -2195,7 +2226,7 @@ fn writeLoadCommands(self: *Zld) !void {
21952226 }
21962227
21972228 const off = @sizeOf(macho.mach_header_64);
2198 log.debug("writing {} load commands from 0x{x} to 0x{x}", .{ self.load_commands.items.len, off, off + sizeofcmds });
2229 log.warn("writing {} load commands from 0x{x} to 0x{x}", .{ self.load_commands.items.len, off, off + sizeofcmds });
21992230 try self.file.?.pwriteAll(buffer, off);
22002231}
22012232
......@@ -2233,7 +2264,7 @@ fn writeHeader(self: *Zld) !void {
22332264 for (self.load_commands.items) |cmd| {
22342265 header.sizeofcmds += cmd.cmdsize();
22352266 }
2236 log.debug("writing Mach-O header {}", .{header});
2267 log.warn("writing Mach-O header {}", .{header});
22372268 try self.file.?.pwriteAll(mem.asBytes(&header), 0);
22382269}
22392270
......@@ -2247,7 +2278,7 @@ pub fn makeStaticString(bytes: []const u8) [16]u8 {
22472278fn makeString(self: *Zld, bytes: []const u8) !u32 {
22482279 try self.strtab.ensureCapacity(self.allocator, self.strtab.items.len + bytes.len + 1);
22492280 const offset = @intCast(u32, self.strtab.items.len);
2250 log.debug("writing new string '{s}' into string table at offset 0x{x}", .{ bytes, offset });
2281 log.warn("writing new string '{s}' into string table at offset 0x{x}", .{ bytes, offset });
22512282 self.strtab.appendSliceAssumeCapacity(bytes);
22522283 self.strtab.appendAssumeCapacity(0);
22532284 return offset;