authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-03-01 21:14:33+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-03-17 19:59:13+01:00
log066c1386a3dfe0acf4c9d11ba436e7e339d2310b
treeae60b7bb6531614ab98d32deec1deed60cef29d5
parentb0ee480177c5f146cc2a5540745572436e8ca510

zld: demote logs from warn to debug


2 files changed, 57 insertions(+), 58 deletions(-)

src/link/MachO/Object.zig+1-1
...@@ -149,7 +149,7 @@ pub fn readLoadCommands(self: *Object, reader: anytype, offset: ReadOffset) !voi...@@ -149,7 +149,7 @@ pub fn readLoadCommands(self: *Object, reader: anytype, offset: ReadOffset) !voi
149 self.build_version_cmd_index = i;149 self.build_version_cmd_index = i;
150 },150 },
151 else => {151 else => {
152 log.info("Unknown load command detected: 0x{x}.", .{cmd.cmd()});152 log.debug("Unknown load command detected: 0x{x}.", .{cmd.cmd()});
153 },153 },
154 }154 }
155 self.load_commands.appendAssumeCapacity(cmd);155 self.load_commands.appendAssumeCapacity(cmd);
src/link/MachO/Zld.zig+56-57
...@@ -331,7 +331,6 @@ fn mapAndUpdateSections(...@@ -331,7 +331,6 @@ fn mapAndUpdateSections(
331 const source_sect = source_seg.sections.items[source_sect_id];331 const source_sect = source_seg.sections.items[source_sect_id];
332 const target_seg = &self.load_commands.items[target_seg_id].Segment;332 const target_seg = &self.load_commands.items[target_seg_id].Segment;
333 const target_sect = &target_seg.sections.items[target_sect_id];333 const target_sect = &target_seg.sections.items[target_sect_id];
334 log.warn("{}", .{target_sect});
335334
336 const alignment = try math.powi(u32, 2, source_sect.@"align");335 const alignment = try math.powi(u32, 2, source_sect.@"align");
337 const offset = mem.alignForwardGeneric(u64, target_sect.size, alignment);336 const offset = mem.alignForwardGeneric(u64, target_sect.size, alignment);
...@@ -346,7 +345,7 @@ fn mapAndUpdateSections(...@@ -346,7 +345,7 @@ fn mapAndUpdateSections(
346 .target_sect_id = target_sect_id,345 .target_sect_id = target_sect_id,
347 .offset = @intCast(u32, offset),346 .offset = @intCast(u32, offset),
348 });347 });
349 log.warn("{s}: {s},{s} mapped to {s},{s} from 0x{x} to 0x{x}", .{348 log.debug("{s}: {s},{s} mapped to {s},{s} from 0x{x} to 0x{x}", .{
350 object.name,349 object.name,
351 parseName(&source_sect.segname),350 parseName(&source_sect.segname),
352 parseName(&source_sect.sectname),351 parseName(&source_sect.sectname),
...@@ -515,7 +514,7 @@ fn updateMetadata(self: *Zld, object_id: u16) !void {...@@ -515,7 +514,7 @@ fn updateMetadata(self: *Zld, object_id: u16) !void {
515 });514 });
516 },515 },
517 else => {516 else => {
518 log.warn("unhandled section type 0x{x} for '{s}/{s}'", .{ flags, segname, sectname });517 log.debug("unhandled section type 0x{x} for '{s}/{s}'", .{ flags, segname, sectname });
519 },518 },
520 }519 }
521 }520 }
...@@ -614,14 +613,14 @@ fn updateMetadata(self: *Zld, object_id: u16) !void {...@@ -614,14 +613,14 @@ fn updateMetadata(self: *Zld, object_id: u16) !void {
614 continue;613 continue;
615 }614 }
616 }615 }
617 log.warn("section '{s}/{s}' will be unmapped", .{ segname, sectname });616 log.debug("section '{s}/{s}' will be unmapped", .{ segname, sectname });
618 try self.unhandled_sections.putNoClobber(self.allocator, .{617 try self.unhandled_sections.putNoClobber(self.allocator, .{
619 .object_id = object_id,618 .object_id = object_id,
620 .source_sect_id = source_sect_id,619 .source_sect_id = source_sect_id,
621 }, 0);620 }, 0);
622 },621 },
623 else => {622 else => {
624 log.warn("section '{s}/{s}' will be unmapped", .{ segname, sectname });623 log.debug("section '{s}/{s}' will be unmapped", .{ segname, sectname });
625 try self.unhandled_sections.putNoClobber(self.allocator, .{624 try self.unhandled_sections.putNoClobber(self.allocator, .{
626 .object_id = object_id,625 .object_id = object_id,
627 .source_sect_id = source_sect_id,626 .source_sect_id = source_sect_id,
...@@ -785,7 +784,7 @@ fn resolveImports(self: *Zld) !void {...@@ -785,7 +784,7 @@ fn resolveImports(self: *Zld) !void {
785 mem.eql(u8, sym_name, "___stack_chk_guard") or784 mem.eql(u8, sym_name, "___stack_chk_guard") or
786 mem.eql(u8, sym_name, "_environ"))785 mem.eql(u8, sym_name, "_environ"))
787 {786 {
788 log.warn("writing nonlazy symbol '{s}'", .{sym_name});787 log.debug("writing nonlazy symbol '{s}'", .{sym_name});
789 const index = @intCast(u32, self.nonlazy_imports.items().len);788 const index = @intCast(u32, self.nonlazy_imports.items().len);
790 try self.nonlazy_imports.putNoClobber(self.allocator, key, .{789 try self.nonlazy_imports.putNoClobber(self.allocator, key, .{
791 .symbol = new_sym,790 .symbol = new_sym,
...@@ -793,7 +792,7 @@ fn resolveImports(self: *Zld) !void {...@@ -793,7 +792,7 @@ fn resolveImports(self: *Zld) !void {
793 .index = index,792 .index = index,
794 });793 });
795 } else if (mem.eql(u8, sym_name, "__tlv_bootstrap")) {794 } else if (mem.eql(u8, sym_name, "__tlv_bootstrap")) {
796 log.warn("writing threadlocal symbol '{s}'", .{sym_name});795 log.debug("writing threadlocal symbol '{s}'", .{sym_name});
797 const index = @intCast(u32, self.threadlocal_imports.items().len);796 const index = @intCast(u32, self.threadlocal_imports.items().len);
798 try self.threadlocal_imports.putNoClobber(self.allocator, key, .{797 try self.threadlocal_imports.putNoClobber(self.allocator, key, .{
799 .symbol = new_sym,798 .symbol = new_sym,
...@@ -801,7 +800,7 @@ fn resolveImports(self: *Zld) !void {...@@ -801,7 +800,7 @@ fn resolveImports(self: *Zld) !void {
801 .index = index,800 .index = index,
802 });801 });
803 } else {802 } else {
804 log.warn("writing lazy symbol '{s}'", .{sym_name});803 log.debug("writing lazy symbol '{s}'", .{sym_name});
805 const index = @intCast(u32, self.lazy_imports.items().len);804 const index = @intCast(u32, self.lazy_imports.items().len);
806 try self.lazy_imports.putNoClobber(self.allocator, key, .{805 try self.lazy_imports.putNoClobber(self.allocator, key, .{
807 .symbol = new_sym,806 .symbol = new_sym,
...@@ -813,7 +812,7 @@ fn resolveImports(self: *Zld) !void {...@@ -813,7 +812,7 @@ fn resolveImports(self: *Zld) !void {
813812
814 const n_strx = try self.makeString("dyld_stub_binder");813 const n_strx = try self.makeString("dyld_stub_binder");
815 const name = try self.allocator.dupe(u8, "dyld_stub_binder");814 const name = try self.allocator.dupe(u8, "dyld_stub_binder");
816 log.warn("writing nonlazy symbol 'dyld_stub_binder'", .{});815 log.debug("writing nonlazy symbol 'dyld_stub_binder'", .{});
817 const index = @intCast(u32, self.nonlazy_imports.items().len);816 const index = @intCast(u32, self.nonlazy_imports.items().len);
818 try self.nonlazy_imports.putNoClobber(self.allocator, name, .{817 try self.nonlazy_imports.putNoClobber(self.allocator, name, .{
819 .symbol = .{818 .symbol = .{
...@@ -1017,7 +1016,7 @@ fn writeStubHelperCommon(self: *Zld) !void {...@@ -1017,7 +1016,7 @@ fn writeStubHelperCommon(self: *Zld) !void {
1017 const new_this_addr = this_addr + @sizeOf(u32);1016 const new_this_addr = this_addr + @sizeOf(u32);
1018 const displacement = math.divExact(u64, target_addr - new_this_addr, 4) catch |_| break :binder_blk;1017 const displacement = math.divExact(u64, target_addr - new_this_addr, 4) catch |_| break :binder_blk;
1019 const literal = math.cast(u18, displacement) catch |_| break :binder_blk;1018 const literal = math.cast(u18, displacement) catch |_| break :binder_blk;
1020 log.warn("2: disp=0x{x}, literal=0x{x}", .{ displacement, literal });1019 log.debug("2: disp=0x{x}, literal=0x{x}", .{ displacement, literal });
1021 // Pad with nop to please division.1020 // Pad with nop to please division.
1022 // nop1021 // nop
1023 mem.writeIntLittle(u32, code[12..16], Arm64.nop().toU32());1022 mem.writeIntLittle(u32, code[12..16], Arm64.nop().toU32());
...@@ -1070,7 +1069,7 @@ fn writeLazySymbolPointer(self: *Zld, index: u32) !void {...@@ -1070,7 +1069,7 @@ fn writeLazySymbolPointer(self: *Zld, index: u32) !void {
1070 var buf: [@sizeOf(u64)]u8 = undefined;1069 var buf: [@sizeOf(u64)]u8 = undefined;
1071 mem.writeIntLittle(u64, &buf, end);1070 mem.writeIntLittle(u64, &buf, end);
1072 const off = la_symbol_ptr.offset + index * @sizeOf(u64);1071 const off = la_symbol_ptr.offset + index * @sizeOf(u64);
1073 log.warn("writing lazy symbol pointer entry 0x{x} at 0x{x}", .{ end, off });1072 log.debug("writing lazy symbol pointer entry 0x{x} at 0x{x}", .{ end, off });
1074 try self.file.?.pwriteAll(&buf, off);1073 try self.file.?.pwriteAll(&buf, off);
1075}1074}
10761075
...@@ -1083,7 +1082,7 @@ fn writeStub(self: *Zld, index: u32) !void {...@@ -1083,7 +1082,7 @@ fn writeStub(self: *Zld, index: u32) !void {
1083 const stub_off = stubs.offset + index * stubs.reserved2;1082 const stub_off = stubs.offset + index * stubs.reserved2;
1084 const stub_addr = stubs.addr + index * stubs.reserved2;1083 const stub_addr = stubs.addr + index * stubs.reserved2;
1085 const la_ptr_addr = la_symbol_ptr.addr + index * @sizeOf(u64);1084 const la_ptr_addr = la_symbol_ptr.addr + index * @sizeOf(u64);
1086 log.warn("writing stub at 0x{x}", .{stub_off});1085 log.debug("writing stub at 0x{x}", .{stub_off});
1087 var code = try self.allocator.alloc(u8, stubs.reserved2);1086 var code = try self.allocator.alloc(u8, stubs.reserved2);
1088 defer self.allocator.free(code);1087 defer self.allocator.free(code);
1089 switch (self.arch.?) {1088 switch (self.arch.?) {
...@@ -1230,7 +1229,7 @@ fn resolveSymbols(self: *Zld) !void {...@@ -1230,7 +1229,7 @@ fn resolveSymbols(self: *Zld) !void {
1230 const target_addr = target_sect.addr + target_mapping.offset;1229 const target_addr = target_sect.addr + target_mapping.offset;
1231 const n_value = sym.n_value - source_sect.addr + target_addr;1230 const n_value = sym.n_value - source_sect.addr + target_addr;
12321231
1233 log.warn("resolving '{s}':{} as {s} symbol at 0x{x}", .{ sym_name, sym, tt, n_value });1232 log.debug("resolving '{s}':{} as {s} symbol at 0x{x}", .{ sym_name, sym, tt, n_value });
12341233
1235 // TODO this assumes only two symbol-filled segments. Also, there might be a more1234 // TODO this assumes only two symbol-filled segments. Also, there might be a more
1236 // generic way of doing this.1235 // generic way of doing this.
...@@ -1260,8 +1259,8 @@ fn resolveSymbols(self: *Zld) !void {...@@ -1260,8 +1259,8 @@ fn resolveSymbols(self: *Zld) !void {
12601259
1261fn doRelocs(self: *Zld) !void {1260fn doRelocs(self: *Zld) !void {
1262 for (self.objects.items) |object, object_id| {1261 for (self.objects.items) |object, object_id| {
1263 log.warn("\n\n", .{});1262 log.debug("\n\n", .{});
1264 log.warn("relocating object {s}", .{object.name});1263 log.debug("relocating object {s}", .{object.name});
12651264
1266 const seg = object.load_commands.items[object.segment_cmd_index.?].Segment;1265 const seg = object.load_commands.items[object.segment_cmd_index.?].Segment;
12671266
...@@ -1284,7 +1283,7 @@ fn doRelocs(self: *Zld) !void {...@@ -1284,7 +1283,7 @@ fn doRelocs(self: *Zld) !void {
1284 .object_id = @intCast(u16, object_id),1283 .object_id = @intCast(u16, object_id),
1285 .source_sect_id = @intCast(u16, source_sect_id),1284 .source_sect_id = @intCast(u16, source_sect_id),
1286 }) orelse {1285 }) orelse {
1287 log.warn("no mapping for {s},{s}; skipping", .{ segname, sectname });1286 log.debug("no mapping for {s},{s}; skipping", .{ segname, sectname });
1288 continue;1287 continue;
1289 };1288 };
1290 const target_seg = self.load_commands.items[target_mapping.target_seg_id].Segment;1289 const target_seg = self.load_commands.items[target_mapping.target_seg_id].Segment;
...@@ -1302,34 +1301,34 @@ fn doRelocs(self: *Zld) !void {...@@ -1302,34 +1301,34 @@ fn doRelocs(self: *Zld) !void {
1302 switch (self.arch.?) {1301 switch (self.arch.?) {
1303 .aarch64 => {1302 .aarch64 => {
1304 const rel_type = @intToEnum(macho.reloc_type_arm64, rel.r_type);1303 const rel_type = @intToEnum(macho.reloc_type_arm64, rel.r_type);
1305 log.warn("{s}", .{rel_type});1304 log.debug("{s}", .{rel_type});
1306 log.warn(" | source address 0x{x}", .{this_addr});1305 log.debug(" | source address 0x{x}", .{this_addr});
1307 log.warn(" | offset 0x{x}", .{off});1306 log.debug(" | offset 0x{x}", .{off});
13081307
1309 if (rel_type == .ARM64_RELOC_ADDEND) {1308 if (rel_type == .ARM64_RELOC_ADDEND) {
1310 addend = rel.r_symbolnum;1309 addend = rel.r_symbolnum;
1311 log.warn(" | calculated addend = 0x{x}", .{addend});1310 log.debug(" | calculated addend = 0x{x}", .{addend});
1312 // TODO followed by either PAGE21 or PAGEOFF12 only.1311 // TODO followed by either PAGE21 or PAGEOFF12 only.
1313 continue;1312 continue;
1314 }1313 }
1315 },1314 },
1316 .x86_64 => {1315 .x86_64 => {
1317 const rel_type = @intToEnum(macho.reloc_type_x86_64, rel.r_type);1316 const rel_type = @intToEnum(macho.reloc_type_x86_64, rel.r_type);
1318 log.warn("{s}", .{rel_type});1317 log.debug("{s}", .{rel_type});
1319 log.warn(" | source address 0x{x}", .{this_addr});1318 log.debug(" | source address 0x{x}", .{this_addr});
1320 log.warn(" | offset 0x{x}", .{off});1319 log.debug(" | offset 0x{x}", .{off});
1321 },1320 },
1322 else => {},1321 else => {},
1323 }1322 }
13241323
1325 const target_addr = try self.relocTargetAddr(@intCast(u16, object_id), rel);1324 const target_addr = try self.relocTargetAddr(@intCast(u16, object_id), rel);
1326 log.warn(" | target address 0x{x}", .{target_addr});1325 log.debug(" | target address 0x{x}", .{target_addr});
1327 if (rel.r_extern == 1) {1326 if (rel.r_extern == 1) {
1328 const target_symname = object.getString(object.symtab.items[rel.r_symbolnum].n_strx);1327 const target_symname = object.getString(object.symtab.items[rel.r_symbolnum].n_strx);
1329 log.warn(" | target symbol '{s}'", .{target_symname});1328 log.debug(" | target symbol '{s}'", .{target_symname});
1330 } else {1329 } else {
1331 const target_sectname = seg.sections.items[rel.r_symbolnum - 1].sectname;1330 const target_sectname = seg.sections.items[rel.r_symbolnum - 1].sectname;
1332 log.warn(" | target section '{s}'", .{parseName(&target_sectname)});1331 log.debug(" | target section '{s}'", .{parseName(&target_sectname)});
1333 }1332 }
13341333
1335 switch (self.arch.?) {1334 switch (self.arch.?) {
...@@ -1379,7 +1378,7 @@ fn doRelocs(self: *Zld) !void {...@@ -1379,7 +1378,7 @@ fn doRelocs(self: *Zld) !void {
1379 break :blk correction;1378 break :blk correction;
1380 }1379 }
1381 };1380 };
1382 log.warn(" | calculated addend 0x{x}", .{offset});1381 log.debug(" | calculated addend 0x{x}", .{offset});
1383 const result = @intCast(i64, target_addr) - @intCast(i64, this_addr) - 4 + offset;1382 const result = @intCast(i64, target_addr) - @intCast(i64, this_addr) - 4 + offset;
1384 const displacement = @bitCast(u32, @intCast(i32, result));1383 const displacement = @bitCast(u32, @intCast(i32, result));
1385 mem.writeIntLittle(u32, inst, displacement);1384 mem.writeIntLittle(u32, inst, displacement);
...@@ -1392,7 +1391,7 @@ fn doRelocs(self: *Zld) !void {...@@ -1392,7 +1391,7 @@ fn doRelocs(self: *Zld) !void {
1392 3 => {1391 3 => {
1393 const inst = code[off..][0..8];1392 const inst = code[off..][0..8];
1394 const offset = mem.readIntLittle(i64, inst);1393 const offset = mem.readIntLittle(i64, inst);
1395 log.warn(" | calculated addend 0x{x}", .{offset});1394 log.debug(" | calculated addend 0x{x}", .{offset});
1396 const result = if (sub) |s|1395 const result = if (sub) |s|
1397 @intCast(i64, target_addr) - s + offset1396 @intCast(i64, target_addr) - s + offset
1398 else1397 else
...@@ -1423,7 +1422,7 @@ fn doRelocs(self: *Zld) !void {...@@ -1423,7 +1422,7 @@ fn doRelocs(self: *Zld) !void {
1423 2 => {1422 2 => {
1424 const inst = code[off..][0..4];1423 const inst = code[off..][0..4];
1425 const offset = mem.readIntLittle(i32, inst);1424 const offset = mem.readIntLittle(i32, inst);
1426 log.warn(" | calculated addend 0x{x}", .{offset});1425 log.debug(" | calculated addend 0x{x}", .{offset});
1427 const result = if (sub) |s|1426 const result = if (sub) |s|
1428 @intCast(i64, target_addr) - s + offset1427 @intCast(i64, target_addr) - s + offset
1429 else1428 else
...@@ -1460,7 +1459,7 @@ fn doRelocs(self: *Zld) !void {...@@ -1460,7 +1459,7 @@ fn doRelocs(self: *Zld) !void {
1460 const this_page = @intCast(i32, this_addr >> 12);1459 const this_page = @intCast(i32, this_addr >> 12);
1461 const target_page = @intCast(i32, ta >> 12);1460 const target_page = @intCast(i32, ta >> 12);
1462 const pages = @bitCast(u21, @intCast(i21, target_page - this_page));1461 const pages = @bitCast(u21, @intCast(i21, target_page - this_page));
1463 log.warn(" | moving by {} pages", .{pages});1462 log.debug(" | moving by {} pages", .{pages});
1464 var parsed = mem.bytesAsValue(meta.TagPayload(Arm64, Arm64.Address), inst);1463 var parsed = mem.bytesAsValue(meta.TagPayload(Arm64, Arm64.Address), inst);
1465 parsed.immhi = @truncate(u19, pages >> 2);1464 parsed.immhi = @truncate(u19, pages >> 2);
1466 parsed.immlo = @truncate(u2, pages);1465 parsed.immlo = @truncate(u2, pages);
...@@ -1471,14 +1470,14 @@ fn doRelocs(self: *Zld) !void {...@@ -1471,14 +1470,14 @@ fn doRelocs(self: *Zld) !void {
1471 => {1470 => {
1472 const inst = code[off..][0..4];1471 const inst = code[off..][0..4];
1473 if (Arm64.isArithmetic(inst)) {1472 if (Arm64.isArithmetic(inst)) {
1474 log.warn(" | detected ADD opcode", .{});1473 log.debug(" | detected ADD opcode", .{});
1475 // add1474 // add
1476 var parsed = mem.bytesAsValue(meta.TagPayload(Arm64, Arm64.Add), inst);1475 var parsed = mem.bytesAsValue(meta.TagPayload(Arm64, Arm64.Add), inst);
1477 const ta = if (addend) |a| target_addr + a else target_addr;1476 const ta = if (addend) |a| target_addr + a else target_addr;
1478 const narrowed = @truncate(u12, ta);1477 const narrowed = @truncate(u12, ta);
1479 parsed.offset = narrowed;1478 parsed.offset = narrowed;
1480 } else {1479 } else {
1481 log.warn(" | detected LDR/STR opcode", .{});1480 log.debug(" | detected LDR/STR opcode", .{});
1482 // ldr/str1481 // ldr/str
1483 var parsed = mem.bytesAsValue(meta.TagPayload(Arm64, Arm64.LoadRegister), inst);1482 var parsed = mem.bytesAsValue(meta.TagPayload(Arm64, Arm64.LoadRegister), inst);
1484 const ta = if (addend) |a| target_addr + a else target_addr;1483 const ta = if (addend) |a| target_addr + a else target_addr;
...@@ -1519,7 +1518,7 @@ fn doRelocs(self: *Zld) !void {...@@ -1519,7 +1518,7 @@ fn doRelocs(self: *Zld) !void {
1519 };1518 };
1520 const ta = if (addend) |a| target_addr + a else target_addr;1519 const ta = if (addend) |a| target_addr + a else target_addr;
1521 const narrowed = @truncate(u12, ta);1520 const narrowed = @truncate(u12, ta);
1522 log.warn(" | rewriting TLV access to ADD opcode", .{});1521 log.debug(" | rewriting TLV access to ADD opcode", .{});
1523 // For TLV, we always generate an add instruction.1522 // For TLV, we always generate an add instruction.
1524 mem.writeIntLittle(u32, inst, Arm64.add(parsed.rt, parsed.rn, narrowed, parsed.size).toU32());1523 mem.writeIntLittle(u32, inst, Arm64.add(parsed.rt, parsed.rn, narrowed, parsed.size).toU32());
1525 },1524 },
...@@ -1531,7 +1530,7 @@ fn doRelocs(self: *Zld) !void {...@@ -1531,7 +1530,7 @@ fn doRelocs(self: *Zld) !void {
1531 3 => {1530 3 => {
1532 const inst = code[off..][0..8];1531 const inst = code[off..][0..8];
1533 const offset = mem.readIntLittle(i64, inst);1532 const offset = mem.readIntLittle(i64, inst);
1534 log.warn(" | calculated addend 0x{x}", .{offset});1533 log.debug(" | calculated addend 0x{x}", .{offset});
1535 const result = if (sub) |s|1534 const result = if (sub) |s|
1536 @intCast(i64, target_addr) - s + offset1535 @intCast(i64, target_addr) - s + offset
1537 else1536 else
...@@ -1562,7 +1561,7 @@ fn doRelocs(self: *Zld) !void {...@@ -1562,7 +1561,7 @@ fn doRelocs(self: *Zld) !void {
1562 2 => {1561 2 => {
1563 const inst = code[off..][0..4];1562 const inst = code[off..][0..4];
1564 const offset = mem.readIntLittle(i32, inst);1563 const offset = mem.readIntLittle(i32, inst);
1565 log.warn(" | calculated addend 0x{x}", .{offset});1564 log.debug(" | calculated addend 0x{x}", .{offset});
1566 const result = if (sub) |s|1565 const result = if (sub) |s|
1567 @intCast(i64, target_addr) - s + offset1566 @intCast(i64, target_addr) - s + offset
1568 else1567 else
...@@ -1584,7 +1583,7 @@ fn doRelocs(self: *Zld) !void {...@@ -1584,7 +1583,7 @@ fn doRelocs(self: *Zld) !void {
1584 }1583 }
1585 }1584 }
15861585
1587 log.warn("writing contents of '{s},{s}' section from '{s}' from 0x{x} to 0x{x}", .{1586 log.debug("writing contents of '{s},{s}' section from '{s}' from 0x{x} to 0x{x}", .{
1588 segname,1587 segname,
1589 sectname,1588 sectname,
1590 object.name,1589 object.name,
...@@ -1596,7 +1595,7 @@ fn doRelocs(self: *Zld) !void {...@@ -1596,7 +1595,7 @@ fn doRelocs(self: *Zld) !void {
1596 target_sect.flags == macho.S_THREAD_LOCAL_ZEROFILL or1595 target_sect.flags == macho.S_THREAD_LOCAL_ZEROFILL or
1597 target_sect.flags == macho.S_THREAD_LOCAL_VARIABLES)1596 target_sect.flags == macho.S_THREAD_LOCAL_VARIABLES)
1598 {1597 {
1599 log.warn("zeroing out '{s},{s}' from 0x{x} to 0x{x}", .{1598 log.debug("zeroing out '{s},{s}' from 0x{x} to 0x{x}", .{
1600 parseName(&target_sect.segname),1599 parseName(&target_sect.segname),
1601 parseName(&target_sect.sectname),1600 parseName(&target_sect.sectname),
1602 target_sect_off,1601 target_sect_off,
...@@ -1630,7 +1629,7 @@ fn relocTargetAddr(self: *Zld, object_id: u16, rel: macho.relocation_info) !u64...@@ -1630,7 +1629,7 @@ fn relocTargetAddr(self: *Zld, object_id: u16, rel: macho.relocation_info) !u64
1630 const target_seg = self.load_commands.items[target_mapping.target_seg_id].Segment;1629 const target_seg = self.load_commands.items[target_mapping.target_seg_id].Segment;
1631 const target_sect = target_seg.sections.items[target_mapping.target_sect_id];1630 const target_sect = target_seg.sections.items[target_mapping.target_sect_id];
1632 const target_sect_addr = target_sect.addr + target_mapping.offset;1631 const target_sect_addr = target_sect.addr + target_mapping.offset;
1633 log.warn(" | symbol local to object", .{});1632 log.debug(" | symbol local to object", .{});
1634 break :blk target_sect_addr + sym.n_value - source_sect.addr;1633 break :blk target_sect_addr + sym.n_value - source_sect.addr;
1635 } else if (isImport(&sym)) {1634 } else if (isImport(&sym)) {
1636 // Relocate to either the artifact's local symbol, or an import from1635 // Relocate to either the artifact's local symbol, or an import from
...@@ -2190,7 +2189,7 @@ fn writeRebaseInfoTable(self: *Zld) !void {...@@ -2190,7 +2189,7 @@ fn writeRebaseInfoTable(self: *Zld) !void {
2190 dyld_info.rebase_size = @intCast(u32, mem.alignForwardGeneric(u64, buffer.len, @sizeOf(u64)));2189 dyld_info.rebase_size = @intCast(u32, mem.alignForwardGeneric(u64, buffer.len, @sizeOf(u64)));
2191 seg.inner.filesize += dyld_info.rebase_size;2190 seg.inner.filesize += dyld_info.rebase_size;
21922191
2193 log.warn("writing rebase info from 0x{x} to 0x{x}", .{ dyld_info.rebase_off, dyld_info.rebase_off + dyld_info.rebase_size });2192 log.debug("writing rebase info from 0x{x} to 0x{x}", .{ dyld_info.rebase_off, dyld_info.rebase_off + dyld_info.rebase_size });
21942193
2195 try self.file.?.pwriteAll(buffer, dyld_info.rebase_off);2194 try self.file.?.pwriteAll(buffer, dyld_info.rebase_off);
2196}2195}
...@@ -2243,7 +2242,7 @@ fn writeBindInfoTable(self: *Zld) !void {...@@ -2243,7 +2242,7 @@ fn writeBindInfoTable(self: *Zld) !void {
2243 dyld_info.bind_size = @intCast(u32, mem.alignForwardGeneric(u64, buffer.len, @alignOf(u64)));2242 dyld_info.bind_size = @intCast(u32, mem.alignForwardGeneric(u64, buffer.len, @alignOf(u64)));
2244 seg.inner.filesize += dyld_info.bind_size;2243 seg.inner.filesize += dyld_info.bind_size;
22452244
2246 log.warn("writing binding info from 0x{x} to 0x{x}", .{ dyld_info.bind_off, dyld_info.bind_off + dyld_info.bind_size });2245 log.debug("writing binding info from 0x{x} to 0x{x}", .{ dyld_info.bind_off, dyld_info.bind_off + dyld_info.bind_size });
22472246
2248 try self.file.?.pwriteAll(buffer, dyld_info.bind_off);2247 try self.file.?.pwriteAll(buffer, dyld_info.bind_off);
2249}2248}
...@@ -2282,7 +2281,7 @@ fn writeLazyBindInfoTable(self: *Zld) !void {...@@ -2282,7 +2281,7 @@ fn writeLazyBindInfoTable(self: *Zld) !void {
2282 dyld_info.lazy_bind_size = @intCast(u32, mem.alignForwardGeneric(u64, buffer.len, @alignOf(u64)));2281 dyld_info.lazy_bind_size = @intCast(u32, mem.alignForwardGeneric(u64, buffer.len, @alignOf(u64)));
2283 seg.inner.filesize += dyld_info.lazy_bind_size;2282 seg.inner.filesize += dyld_info.lazy_bind_size;
22842283
2285 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 });2284 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 });
22862285
2287 try self.file.?.pwriteAll(buffer, dyld_info.lazy_bind_off);2286 try self.file.?.pwriteAll(buffer, dyld_info.lazy_bind_off);
2288 try self.populateLazyBindOffsetsInStubHelper(buffer);2287 try self.populateLazyBindOffsetsInStubHelper(buffer);
...@@ -2384,7 +2383,7 @@ fn writeExportInfo(self: *Zld) !void {...@@ -2384,7 +2383,7 @@ fn writeExportInfo(self: *Zld) !void {
2384 dyld_info.export_size = @intCast(u32, mem.alignForwardGeneric(u64, buffer.len, @alignOf(u64)));2383 dyld_info.export_size = @intCast(u32, mem.alignForwardGeneric(u64, buffer.len, @alignOf(u64)));
2385 seg.inner.filesize += dyld_info.export_size;2384 seg.inner.filesize += dyld_info.export_size;
23862385
2387 log.warn("writing export info from 0x{x} to 0x{x}", .{ dyld_info.export_off, dyld_info.export_off + dyld_info.export_size });2386 log.debug("writing export info from 0x{x} to 0x{x}", .{ dyld_info.export_off, dyld_info.export_off + dyld_info.export_size });
23882387
2389 try self.file.?.pwriteAll(buffer, dyld_info.export_off);2388 try self.file.?.pwriteAll(buffer, dyld_info.export_off);
2390}2389}
...@@ -2518,7 +2517,7 @@ fn writeDebugInfo(self: *Zld) !void {...@@ -2518,7 +2517,7 @@ fn writeDebugInfo(self: *Zld) !void {
25182517
2519 const stabs_off = symtab.symoff;2518 const stabs_off = symtab.symoff;
2520 const stabs_size = symtab.nsyms * @sizeOf(macho.nlist_64);2519 const stabs_size = symtab.nsyms * @sizeOf(macho.nlist_64);
2521 log.warn("writing symbol stabs from 0x{x} to 0x{x}", .{ stabs_off, stabs_size + stabs_off });2520 log.debug("writing symbol stabs from 0x{x} to 0x{x}", .{ stabs_off, stabs_size + stabs_off });
2522 try self.file.?.pwriteAll(mem.sliceAsBytes(stabs.items), stabs_off);2521 try self.file.?.pwriteAll(mem.sliceAsBytes(stabs.items), stabs_off);
25232522
2524 linkedit.inner.filesize += stabs_size;2523 linkedit.inner.filesize += stabs_size;
...@@ -2536,12 +2535,12 @@ fn writeSymbolTable(self: *Zld) !void {...@@ -2536,12 +2535,12 @@ fn writeSymbolTable(self: *Zld) !void {
2536 defer locals.deinit();2535 defer locals.deinit();
25372536
2538 for (self.locals.items()) |entries| {2537 for (self.locals.items()) |entries| {
2539 log.warn("'{s}': {} entries", .{ entries.key, entries.value.items.len });2538 log.debug("'{s}': {} entries", .{ entries.key, entries.value.items.len });
2540 // var symbol: ?macho.nlist_64 = null;2539 // var symbol: ?macho.nlist_64 = null;
2541 for (entries.value.items) |entry| {2540 for (entries.value.items) |entry| {
2542 log.warn(" | {}", .{entry.inner});2541 log.debug(" | {}", .{entry.inner});
2543 log.warn(" | {}", .{entry.tt});2542 log.debug(" | {}", .{entry.tt});
2544 log.warn(" | {s}", .{self.objects.items[entry.object_id].name});2543 log.debug(" | {s}", .{self.objects.items[entry.object_id].name});
2545 // switch (entry.tt) {2544 // switch (entry.tt) {
2546 // .Global => {2545 // .Global => {
2547 // symbol = entry.inner;2546 // symbol = entry.inner;
...@@ -2586,17 +2585,17 @@ fn writeSymbolTable(self: *Zld) !void {...@@ -2586,17 +2585,17 @@ fn writeSymbolTable(self: *Zld) !void {
25862585
2587 const locals_off = symtab.symoff + symtab.nsyms * @sizeOf(macho.nlist_64);2586 const locals_off = symtab.symoff + symtab.nsyms * @sizeOf(macho.nlist_64);
2588 const locals_size = nlocals * @sizeOf(macho.nlist_64);2587 const locals_size = nlocals * @sizeOf(macho.nlist_64);
2589 log.warn("writing local symbols from 0x{x} to 0x{x}", .{ locals_off, locals_size + locals_off });2588 log.debug("writing local symbols from 0x{x} to 0x{x}", .{ locals_off, locals_size + locals_off });
2590 try self.file.?.pwriteAll(mem.sliceAsBytes(locals.items), locals_off);2589 try self.file.?.pwriteAll(mem.sliceAsBytes(locals.items), locals_off);
25912590
2592 const exports_off = locals_off + locals_size;2591 const exports_off = locals_off + locals_size;
2593 const exports_size = nexports * @sizeOf(macho.nlist_64);2592 const exports_size = nexports * @sizeOf(macho.nlist_64);
2594 log.warn("writing exported symbols from 0x{x} to 0x{x}", .{ exports_off, exports_size + exports_off });2593 log.debug("writing exported symbols from 0x{x} to 0x{x}", .{ exports_off, exports_size + exports_off });
2595 try self.file.?.pwriteAll(mem.sliceAsBytes(exports.items), exports_off);2594 try self.file.?.pwriteAll(mem.sliceAsBytes(exports.items), exports_off);
25962595
2597 const undefs_off = exports_off + exports_size;2596 const undefs_off = exports_off + exports_size;
2598 const undefs_size = nundefs * @sizeOf(macho.nlist_64);2597 const undefs_size = nundefs * @sizeOf(macho.nlist_64);
2599 log.warn("writing undefined symbols from 0x{x} to 0x{x}", .{ undefs_off, undefs_size + undefs_off });2598 log.debug("writing undefined symbols from 0x{x} to 0x{x}", .{ undefs_off, undefs_size + undefs_off });
2600 try self.file.?.pwriteAll(mem.sliceAsBytes(undefs.items), undefs_off);2599 try self.file.?.pwriteAll(mem.sliceAsBytes(undefs.items), undefs_off);
26012600
2602 symtab.nsyms += @intCast(u32, nlocals + nexports + nundefs);2601 symtab.nsyms += @intCast(u32, nlocals + nexports + nundefs);
...@@ -2627,7 +2626,7 @@ fn writeDynamicSymbolTable(self: *Zld) !void {...@@ -2627,7 +2626,7 @@ fn writeDynamicSymbolTable(self: *Zld) !void {
2627 const needed_size = dysymtab.nindirectsyms * @sizeOf(u32);2626 const needed_size = dysymtab.nindirectsyms * @sizeOf(u32);
2628 seg.inner.filesize += needed_size;2627 seg.inner.filesize += needed_size;
26292628
2630 log.warn("writing indirect symbol table from 0x{x} to 0x{x}", .{2629 log.debug("writing indirect symbol table from 0x{x} to 0x{x}", .{
2631 dysymtab.indirectsymoff,2630 dysymtab.indirectsymoff,
2632 dysymtab.indirectsymoff + needed_size,2631 dysymtab.indirectsymoff + needed_size,
2633 });2632 });
...@@ -2666,7 +2665,7 @@ fn writeStringTable(self: *Zld) !void {...@@ -2666,7 +2665,7 @@ fn writeStringTable(self: *Zld) !void {
2666 symtab.strsize = @intCast(u32, mem.alignForwardGeneric(u64, self.strtab.items.len, @alignOf(u64)));2665 symtab.strsize = @intCast(u32, mem.alignForwardGeneric(u64, self.strtab.items.len, @alignOf(u64)));
2667 seg.inner.filesize += symtab.strsize;2666 seg.inner.filesize += symtab.strsize;
26682667
2669 log.warn("writing string table from 0x{x} to 0x{x}", .{ symtab.stroff, symtab.stroff + symtab.strsize });2668 log.debug("writing string table from 0x{x} to 0x{x}", .{ symtab.stroff, symtab.stroff + symtab.strsize });
26702669
2671 try self.file.?.pwriteAll(self.strtab.items, symtab.stroff);2670 try self.file.?.pwriteAll(self.strtab.items, symtab.stroff);
26722671
...@@ -2692,7 +2691,7 @@ fn writeCodeSignaturePadding(self: *Zld) !void {...@@ -2692,7 +2691,7 @@ fn writeCodeSignaturePadding(self: *Zld) !void {
2692 seg.inner.filesize += needed_size;2691 seg.inner.filesize += needed_size;
2693 seg.inner.vmsize = mem.alignForwardGeneric(u64, seg.inner.filesize, self.page_size.?);2692 seg.inner.vmsize = mem.alignForwardGeneric(u64, seg.inner.filesize, self.page_size.?);
26942693
2695 log.warn("writing code signature padding from 0x{x} to 0x{x}", .{ fileoff, fileoff + needed_size });2694 log.debug("writing code signature padding from 0x{x} to 0x{x}", .{ fileoff, fileoff + needed_size });
26962695
2697 // Pad out the space. We need to do this to calculate valid hashes for everything in the file2696 // Pad out the space. We need to do this to calculate valid hashes for everything in the file
2698 // except for code signature data.2697 // except for code signature data.
...@@ -2718,7 +2717,7 @@ fn writeCodeSignature(self: *Zld) !void {...@@ -2718,7 +2717,7 @@ fn writeCodeSignature(self: *Zld) !void {
2718 var stream = std.io.fixedBufferStream(buffer);2717 var stream = std.io.fixedBufferStream(buffer);
2719 try code_sig.write(stream.writer());2718 try code_sig.write(stream.writer());
27202719
2721 log.warn("writing code signature from 0x{x} to 0x{x}", .{ code_sig_cmd.dataoff, code_sig_cmd.dataoff + buffer.len });2720 log.debug("writing code signature from 0x{x} to 0x{x}", .{ code_sig_cmd.dataoff, code_sig_cmd.dataoff + buffer.len });
27222721
2723 try self.file.?.pwriteAll(buffer, code_sig_cmd.dataoff);2722 try self.file.?.pwriteAll(buffer, code_sig_cmd.dataoff);
2724}2723}
...@@ -2737,7 +2736,7 @@ fn writeLoadCommands(self: *Zld) !void {...@@ -2737,7 +2736,7 @@ fn writeLoadCommands(self: *Zld) !void {
2737 }2736 }
27382737
2739 const off = @sizeOf(macho.mach_header_64);2738 const off = @sizeOf(macho.mach_header_64);
2740 log.warn("writing {} load commands from 0x{x} to 0x{x}", .{ self.load_commands.items.len, off, off + sizeofcmds });2739 log.debug("writing {} load commands from 0x{x} to 0x{x}", .{ self.load_commands.items.len, off, off + sizeofcmds });
2741 try self.file.?.pwriteAll(buffer, off);2740 try self.file.?.pwriteAll(buffer, off);
2742}2741}
27432742
...@@ -2775,7 +2774,7 @@ fn writeHeader(self: *Zld) !void {...@@ -2775,7 +2774,7 @@ fn writeHeader(self: *Zld) !void {
2775 for (self.load_commands.items) |cmd| {2774 for (self.load_commands.items) |cmd| {
2776 header.sizeofcmds += cmd.cmdsize();2775 header.sizeofcmds += cmd.cmdsize();
2777 }2776 }
2778 log.warn("writing Mach-O header {}", .{header});2777 log.debug("writing Mach-O header {}", .{header});
2779 try self.file.?.pwriteAll(mem.asBytes(&header), 0);2778 try self.file.?.pwriteAll(mem.asBytes(&header), 0);
2780}2779}
27812780
...@@ -2789,7 +2788,7 @@ pub fn makeStaticString(bytes: []const u8) [16]u8 {...@@ -2789,7 +2788,7 @@ pub fn makeStaticString(bytes: []const u8) [16]u8 {
2789fn makeString(self: *Zld, bytes: []const u8) !u32 {2788fn makeString(self: *Zld, bytes: []const u8) !u32 {
2790 try self.strtab.ensureCapacity(self.allocator, self.strtab.items.len + bytes.len + 1);2789 try self.strtab.ensureCapacity(self.allocator, self.strtab.items.len + bytes.len + 1);
2791 const offset = @intCast(u32, self.strtab.items.len);2790 const offset = @intCast(u32, self.strtab.items.len);
2792 log.warn("writing new string '{s}' into string table at offset 0x{x}", .{ bytes, offset });2791 log.debug("writing new string '{s}' into string table at offset 0x{x}", .{ bytes, offset });
2793 self.strtab.appendSliceAssumeCapacity(bytes);2792 self.strtab.appendSliceAssumeCapacity(bytes);
2794 self.strtab.appendAssumeCapacity(0);2793 self.strtab.appendAssumeCapacity(0);
2795 return offset;2794 return offset;