authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-03-04 18:35:26+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-03-17 19:59:13+01:00
log5d8944edc1361aeb36a55d8435ef1feecf714958
treef670c5341b7597e9a2a7e685c33c32e7e0aec5c1
parenta1b0ec5277c08b82411f830ab0e82487a6a00184

Revert log.warn hack


1 files changed, 60 insertions(+), 60 deletions(-)

src/link/MachO/Zld.zig+60-60
...@@ -345,7 +345,7 @@ fn mapAndUpdateSections(...@@ -345,7 +345,7 @@ fn mapAndUpdateSections(
345 .target_sect_id = target_sect_id,345 .target_sect_id = target_sect_id,
346 .offset = @intCast(u32, offset),346 .offset = @intCast(u32, offset),
347 });347 });
348 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}", .{
349 object.name,349 object.name,
350 parseName(&source_sect.segname),350 parseName(&source_sect.segname),
351 parseName(&source_sect.sectname),351 parseName(&source_sect.sectname),
...@@ -513,7 +513,7 @@ fn updateMetadata(self: *Zld, object_id: u16) !void {...@@ -513,7 +513,7 @@ fn updateMetadata(self: *Zld, object_id: u16) !void {
513 });513 });
514 },514 },
515 else => {515 else => {
516 log.warn("unhandled section type 0x{x} for '{s}/{s}'", .{ flags, segname, sectname });516 log.debug("unhandled section type 0x{x} for '{s}/{s}'", .{ flags, segname, sectname });
517 },517 },
518 }518 }
519 }519 }
...@@ -537,7 +537,7 @@ fn updateMetadata(self: *Zld, object_id: u16) !void {...@@ -537,7 +537,7 @@ fn updateMetadata(self: *Zld, object_id: u16) !void {
537537
538 const segname = parseName(&source_sect.segname);538 const segname = parseName(&source_sect.segname);
539 const sectname = parseName(&source_sect.sectname);539 const sectname = parseName(&source_sect.sectname);
540 log.warn("section '{s}/{s}' will be unmapped", .{ segname, sectname });540 log.debug("section '{s}/{s}' will be unmapped", .{ segname, sectname });
541 try self.unhandled_sections.putNoClobber(self.allocator, .{541 try self.unhandled_sections.putNoClobber(self.allocator, .{
542 .object_id = object_id,542 .object_id = object_id,
543 .source_sect_id = source_sect_id,543 .source_sect_id = source_sect_id,
...@@ -780,7 +780,7 @@ fn resolveImports(self: *Zld) !void {...@@ -780,7 +780,7 @@ fn resolveImports(self: *Zld) !void {
780 mem.eql(u8, sym_name, "___stack_chk_guard") or780 mem.eql(u8, sym_name, "___stack_chk_guard") or
781 mem.eql(u8, sym_name, "_environ"))781 mem.eql(u8, sym_name, "_environ"))
782 {782 {
783 log.warn("writing nonlazy symbol '{s}'", .{sym_name});783 log.debug("writing nonlazy symbol '{s}'", .{sym_name});
784 const index = @intCast(u32, self.nonlazy_imports.items().len);784 const index = @intCast(u32, self.nonlazy_imports.items().len);
785 try self.nonlazy_imports.putNoClobber(self.allocator, key, .{785 try self.nonlazy_imports.putNoClobber(self.allocator, key, .{
786 .symbol = new_sym,786 .symbol = new_sym,
...@@ -788,7 +788,7 @@ fn resolveImports(self: *Zld) !void {...@@ -788,7 +788,7 @@ fn resolveImports(self: *Zld) !void {
788 .index = index,788 .index = index,
789 });789 });
790 } else if (mem.eql(u8, sym_name, "__tlv_bootstrap")) {790 } else if (mem.eql(u8, sym_name, "__tlv_bootstrap")) {
791 log.warn("writing threadlocal symbol '{s}'", .{sym_name});791 log.debug("writing threadlocal symbol '{s}'", .{sym_name});
792 const index = @intCast(u32, self.threadlocal_imports.items().len);792 const index = @intCast(u32, self.threadlocal_imports.items().len);
793 try self.threadlocal_imports.putNoClobber(self.allocator, key, .{793 try self.threadlocal_imports.putNoClobber(self.allocator, key, .{
794 .symbol = new_sym,794 .symbol = new_sym,
...@@ -796,7 +796,7 @@ fn resolveImports(self: *Zld) !void {...@@ -796,7 +796,7 @@ fn resolveImports(self: *Zld) !void {
796 .index = index,796 .index = index,
797 });797 });
798 } else {798 } else {
799 log.warn("writing lazy symbol '{s}'", .{sym_name});799 log.debug("writing lazy symbol '{s}'", .{sym_name});
800 const index = @intCast(u32, self.lazy_imports.items().len);800 const index = @intCast(u32, self.lazy_imports.items().len);
801 try self.lazy_imports.putNoClobber(self.allocator, key, .{801 try self.lazy_imports.putNoClobber(self.allocator, key, .{
802 .symbol = new_sym,802 .symbol = new_sym,
...@@ -808,7 +808,7 @@ fn resolveImports(self: *Zld) !void {...@@ -808,7 +808,7 @@ fn resolveImports(self: *Zld) !void {
808808
809 const n_strx = try self.makeString("dyld_stub_binder");809 const n_strx = try self.makeString("dyld_stub_binder");
810 const name = try self.allocator.dupe(u8, "dyld_stub_binder");810 const name = try self.allocator.dupe(u8, "dyld_stub_binder");
811 log.warn("writing nonlazy symbol 'dyld_stub_binder'", .{});811 log.debug("writing nonlazy symbol 'dyld_stub_binder'", .{});
812 const index = @intCast(u32, self.nonlazy_imports.items().len);812 const index = @intCast(u32, self.nonlazy_imports.items().len);
813 try self.nonlazy_imports.putNoClobber(self.allocator, name, .{813 try self.nonlazy_imports.putNoClobber(self.allocator, name, .{
814 .symbol = .{814 .symbol = .{
...@@ -1012,7 +1012,7 @@ fn writeStubHelperCommon(self: *Zld) !void {...@@ -1012,7 +1012,7 @@ fn writeStubHelperCommon(self: *Zld) !void {
1012 const new_this_addr = this_addr + @sizeOf(u32);1012 const new_this_addr = this_addr + @sizeOf(u32);
1013 const displacement = math.divExact(u64, target_addr - new_this_addr, 4) catch |_| break :binder_blk;1013 const displacement = math.divExact(u64, target_addr - new_this_addr, 4) catch |_| break :binder_blk;
1014 const literal = math.cast(u18, displacement) catch |_| break :binder_blk;1014 const literal = math.cast(u18, displacement) catch |_| break :binder_blk;
1015 log.warn("2: disp=0x{x}, literal=0x{x}", .{ displacement, literal });1015 log.debug("2: disp=0x{x}, literal=0x{x}", .{ displacement, literal });
1016 // Pad with nop to please division.1016 // Pad with nop to please division.
1017 // nop1017 // nop
1018 mem.writeIntLittle(u32, code[12..16], Arm64.nop().toU32());1018 mem.writeIntLittle(u32, code[12..16], Arm64.nop().toU32());
...@@ -1065,7 +1065,7 @@ fn writeLazySymbolPointer(self: *Zld, index: u32) !void {...@@ -1065,7 +1065,7 @@ fn writeLazySymbolPointer(self: *Zld, index: u32) !void {
1065 var buf: [@sizeOf(u64)]u8 = undefined;1065 var buf: [@sizeOf(u64)]u8 = undefined;
1066 mem.writeIntLittle(u64, &buf, end);1066 mem.writeIntLittle(u64, &buf, end);
1067 const off = la_symbol_ptr.offset + index * @sizeOf(u64);1067 const off = la_symbol_ptr.offset + index * @sizeOf(u64);
1068 log.warn("writing lazy symbol pointer entry 0x{x} at 0x{x}", .{ end, off });1068 log.debug("writing lazy symbol pointer entry 0x{x} at 0x{x}", .{ end, off });
1069 try self.file.?.pwriteAll(&buf, off);1069 try self.file.?.pwriteAll(&buf, off);
1070}1070}
10711071
...@@ -1078,7 +1078,7 @@ fn writeStub(self: *Zld, index: u32) !void {...@@ -1078,7 +1078,7 @@ fn writeStub(self: *Zld, index: u32) !void {
1078 const stub_off = stubs.offset + index * stubs.reserved2;1078 const stub_off = stubs.offset + index * stubs.reserved2;
1079 const stub_addr = stubs.addr + index * stubs.reserved2;1079 const stub_addr = stubs.addr + index * stubs.reserved2;
1080 const la_ptr_addr = la_symbol_ptr.addr + index * @sizeOf(u64);1080 const la_ptr_addr = la_symbol_ptr.addr + index * @sizeOf(u64);
1081 log.warn("writing stub at 0x{x}", .{stub_off});1081 log.debug("writing stub at 0x{x}", .{stub_off});
1082 var code = try self.allocator.alloc(u8, stubs.reserved2);1082 var code = try self.allocator.alloc(u8, stubs.reserved2);
1083 defer self.allocator.free(code);1083 defer self.allocator.free(code);
1084 switch (self.arch.?) {1084 switch (self.arch.?) {
...@@ -1225,7 +1225,7 @@ fn resolveSymbols(self: *Zld) !void {...@@ -1225,7 +1225,7 @@ fn resolveSymbols(self: *Zld) !void {
1225 const target_addr = target_sect.addr + target_mapping.offset;1225 const target_addr = target_sect.addr + target_mapping.offset;
1226 const n_value = sym.n_value - source_sect.addr + target_addr;1226 const n_value = sym.n_value - source_sect.addr + target_addr;
12271227
1228 log.warn("resolving '{s}':{} as {s} symbol at 0x{x}", .{ sym_name, sym, tt, n_value });1228 log.debug("resolving '{s}':{} as {s} symbol at 0x{x}", .{ sym_name, sym, tt, n_value });
12291229
1230 // TODO this assumes only two symbol-filled segments. Also, there might be a more1230 // TODO this assumes only two symbol-filled segments. Also, there might be a more
1231 // generic way of doing this.1231 // generic way of doing this.
...@@ -1255,8 +1255,8 @@ fn resolveSymbols(self: *Zld) !void {...@@ -1255,8 +1255,8 @@ fn resolveSymbols(self: *Zld) !void {
12551255
1256fn doRelocs(self: *Zld) !void {1256fn doRelocs(self: *Zld) !void {
1257 for (self.objects.items) |object, object_id| {1257 for (self.objects.items) |object, object_id| {
1258 log.warn("\n\n", .{});1258 log.debug("\n\n", .{});
1259 log.warn("relocating object {s}", .{object.name});1259 log.debug("relocating object {s}", .{object.name});
12601260
1261 const seg = object.load_commands.items[object.segment_cmd_index.?].Segment;1261 const seg = object.load_commands.items[object.segment_cmd_index.?].Segment;
12621262
...@@ -1279,7 +1279,7 @@ fn doRelocs(self: *Zld) !void {...@@ -1279,7 +1279,7 @@ fn doRelocs(self: *Zld) !void {
1279 .object_id = @intCast(u16, object_id),1279 .object_id = @intCast(u16, object_id),
1280 .source_sect_id = @intCast(u16, source_sect_id),1280 .source_sect_id = @intCast(u16, source_sect_id),
1281 }) orelse {1281 }) orelse {
1282 log.warn("no mapping for {s},{s}; skipping", .{ segname, sectname });1282 log.debug("no mapping for {s},{s}; skipping", .{ segname, sectname });
1283 continue;1283 continue;
1284 };1284 };
1285 const target_seg = self.load_commands.items[target_mapping.target_seg_id].Segment;1285 const target_seg = self.load_commands.items[target_mapping.target_seg_id].Segment;
...@@ -1297,34 +1297,34 @@ fn doRelocs(self: *Zld) !void {...@@ -1297,34 +1297,34 @@ fn doRelocs(self: *Zld) !void {
1297 switch (self.arch.?) {1297 switch (self.arch.?) {
1298 .aarch64 => {1298 .aarch64 => {
1299 const rel_type = @intToEnum(macho.reloc_type_arm64, rel.r_type);1299 const rel_type = @intToEnum(macho.reloc_type_arm64, rel.r_type);
1300 log.warn("{s}", .{rel_type});1300 log.debug("{s}", .{rel_type});
1301 log.warn(" | source address 0x{x}", .{this_addr});1301 log.debug(" | source address 0x{x}", .{this_addr});
1302 log.warn(" | offset 0x{x}", .{off});1302 log.debug(" | offset 0x{x}", .{off});
13031303
1304 if (rel_type == .ARM64_RELOC_ADDEND) {1304 if (rel_type == .ARM64_RELOC_ADDEND) {
1305 addend = rel.r_symbolnum;1305 addend = rel.r_symbolnum;
1306 log.warn(" | calculated addend = 0x{x}", .{addend});1306 log.debug(" | calculated addend = 0x{x}", .{addend});
1307 // TODO followed by either PAGE21 or PAGEOFF12 only.1307 // TODO followed by either PAGE21 or PAGEOFF12 only.
1308 continue;1308 continue;
1309 }1309 }
1310 },1310 },
1311 .x86_64 => {1311 .x86_64 => {
1312 const rel_type = @intToEnum(macho.reloc_type_x86_64, rel.r_type);1312 const rel_type = @intToEnum(macho.reloc_type_x86_64, rel.r_type);
1313 log.warn("{s}", .{rel_type});1313 log.debug("{s}", .{rel_type});
1314 log.warn(" | source address 0x{x}", .{this_addr});1314 log.debug(" | source address 0x{x}", .{this_addr});
1315 log.warn(" | offset 0x{x}", .{off});1315 log.debug(" | offset 0x{x}", .{off});
1316 },1316 },
1317 else => {},1317 else => {},
1318 }1318 }
13191319
1320 const target_addr = try self.relocTargetAddr(@intCast(u16, object_id), rel);1320 const target_addr = try self.relocTargetAddr(@intCast(u16, object_id), rel);
1321 log.warn(" | target address 0x{x}", .{target_addr});1321 log.debug(" | target address 0x{x}", .{target_addr});
1322 if (rel.r_extern == 1) {1322 if (rel.r_extern == 1) {
1323 const target_symname = object.getString(object.symtab.items[rel.r_symbolnum].n_strx);1323 const target_symname = object.getString(object.symtab.items[rel.r_symbolnum].n_strx);
1324 log.warn(" | target symbol '{s}'", .{target_symname});1324 log.debug(" | target symbol '{s}'", .{target_symname});
1325 } else {1325 } else {
1326 const target_sectname = seg.sections.items[rel.r_symbolnum - 1].sectname;1326 const target_sectname = seg.sections.items[rel.r_symbolnum - 1].sectname;
1327 log.warn(" | target section '{s}'", .{parseName(&target_sectname)});1327 log.debug(" | target section '{s}'", .{parseName(&target_sectname)});
1328 }1328 }
13291329
1330 switch (self.arch.?) {1330 switch (self.arch.?) {
...@@ -1358,7 +1358,7 @@ fn doRelocs(self: *Zld) !void {...@@ -1358,7 +1358,7 @@ fn doRelocs(self: *Zld) !void {
1358 assert(rel.r_length == 2);1358 assert(rel.r_length == 2);
1359 const inst = code[off..][0..4];1359 const inst = code[off..][0..4];
1360 const offset = @intCast(i64, mem.readIntLittle(i32, inst));1360 const offset = @intCast(i64, mem.readIntLittle(i32, inst));
1361 log.warn(" | calculated addend 0x{x}", .{offset});1361 log.debug(" | calculated addend 0x{x}", .{offset});
1362 const actual_target_addr = blk: {1362 const actual_target_addr = blk: {
1363 if (rel.r_extern == 1) {1363 if (rel.r_extern == 1) {
1364 break :blk @intCast(i64, target_addr) + offset;1364 break :blk @intCast(i64, target_addr) + offset;
...@@ -1370,7 +1370,7 @@ fn doRelocs(self: *Zld) !void {...@@ -1370,7 +1370,7 @@ fn doRelocs(self: *Zld) !void {
1370 .X86_64_RELOC_SIGNED_4 => 4,1370 .X86_64_RELOC_SIGNED_4 => 4,
1371 else => unreachable,1371 else => unreachable,
1372 };1372 };
1373 log.warn(" | calculated correction 0x{x}", .{correction});1373 log.debug(" | calculated correction 0x{x}", .{correction});
13741374
1375 // The value encoded in the instruction is a displacement - 4 - correction.1375 // The value encoded in the instruction is a displacement - 4 - correction.
1376 // To obtain the adjusted target address in the final binary, we need1376 // To obtain the adjusted target address in the final binary, we need
...@@ -1385,9 +1385,9 @@ fn doRelocs(self: *Zld) !void {...@@ -1385,9 +1385,9 @@ fn doRelocs(self: *Zld) !void {
1385 const orig_seg = object.load_commands.items[object.segment_cmd_index.?].Segment;1385 const orig_seg = object.load_commands.items[object.segment_cmd_index.?].Segment;
1386 const orig_sect = orig_seg.sections.items[orig_sect_id];1386 const orig_sect = orig_seg.sections.items[orig_sect_id];
1387 const orig_offset = off + offset + 4 + correction - @intCast(i64, orig_sect.addr);1387 const orig_offset = off + offset + 4 + correction - @intCast(i64, orig_sect.addr);
1388 log.warn(" | original offset 0x{x}", .{orig_offset});1388 log.debug(" | original offset 0x{x}", .{orig_offset});
1389 const adjusted = @intCast(i64, target_addr) + orig_offset;1389 const adjusted = @intCast(i64, target_addr) + orig_offset;
1390 log.warn(" | adjusted target address 0x{x}", .{adjusted});1390 log.debug(" | adjusted target address 0x{x}", .{adjusted});
1391 break :blk adjusted - correction;1391 break :blk adjusted - correction;
1392 }1392 }
1393 };1393 };
...@@ -1406,7 +1406,7 @@ fn doRelocs(self: *Zld) !void {...@@ -1406,7 +1406,7 @@ fn doRelocs(self: *Zld) !void {
14061406
1407 const result = outer: {1407 const result = outer: {
1408 if (rel.r_extern == 1) {1408 if (rel.r_extern == 1) {
1409 log.warn(" | calculated addend 0x{x}", .{offset});1409 log.debug(" | calculated addend 0x{x}", .{offset});
1410 if (sub) |s| {1410 if (sub) |s| {
1411 break :outer @intCast(i64, target_addr) - s + offset;1411 break :outer @intCast(i64, target_addr) - s + offset;
1412 } else {1412 } else {
...@@ -1433,7 +1433,7 @@ fn doRelocs(self: *Zld) !void {...@@ -1433,7 +1433,7 @@ fn doRelocs(self: *Zld) !void {
1433 break :inner @intCast(i64, target_addr) + orig_offset;1433 break :inner @intCast(i64, target_addr) + orig_offset;
1434 }1434 }
1435 };1435 };
1436 log.warn(" | adjusted target address 0x{x}", .{actual_target_addr});1436 log.debug(" | adjusted target address 0x{x}", .{actual_target_addr});
1437 break :outer actual_target_addr;1437 break :outer actual_target_addr;
1438 }1438 }
1439 };1439 };
...@@ -1463,7 +1463,7 @@ fn doRelocs(self: *Zld) !void {...@@ -1463,7 +1463,7 @@ fn doRelocs(self: *Zld) !void {
1463 2 => {1463 2 => {
1464 const inst = code[off..][0..4];1464 const inst = code[off..][0..4];
1465 const offset = mem.readIntLittle(i32, inst);1465 const offset = mem.readIntLittle(i32, inst);
1466 log.warn(" | calculated addend 0x{x}", .{offset});1466 log.debug(" | calculated addend 0x{x}", .{offset});
1467 const result = if (sub) |s|1467 const result = if (sub) |s|
1468 @intCast(i64, target_addr) - s + offset1468 @intCast(i64, target_addr) - s + offset
1469 else1469 else
...@@ -1500,7 +1500,7 @@ fn doRelocs(self: *Zld) !void {...@@ -1500,7 +1500,7 @@ fn doRelocs(self: *Zld) !void {
1500 const this_page = @intCast(i32, this_addr >> 12);1500 const this_page = @intCast(i32, this_addr >> 12);
1501 const target_page = @intCast(i32, ta >> 12);1501 const target_page = @intCast(i32, ta >> 12);
1502 const pages = @bitCast(u21, @intCast(i21, target_page - this_page));1502 const pages = @bitCast(u21, @intCast(i21, target_page - this_page));
1503 log.warn(" | moving by {} pages", .{pages});1503 log.debug(" | moving by {} pages", .{pages});
1504 var parsed = mem.bytesAsValue(meta.TagPayload(Arm64, Arm64.Address), inst);1504 var parsed = mem.bytesAsValue(meta.TagPayload(Arm64, Arm64.Address), inst);
1505 parsed.immhi = @truncate(u19, pages >> 2);1505 parsed.immhi = @truncate(u19, pages >> 2);
1506 parsed.immlo = @truncate(u2, pages);1506 parsed.immlo = @truncate(u2, pages);
...@@ -1511,14 +1511,14 @@ fn doRelocs(self: *Zld) !void {...@@ -1511,14 +1511,14 @@ fn doRelocs(self: *Zld) !void {
1511 => {1511 => {
1512 const inst = code[off..][0..4];1512 const inst = code[off..][0..4];
1513 if (Arm64.isArithmetic(inst)) {1513 if (Arm64.isArithmetic(inst)) {
1514 log.warn(" | detected ADD opcode", .{});1514 log.debug(" | detected ADD opcode", .{});
1515 // add1515 // add
1516 var parsed = mem.bytesAsValue(meta.TagPayload(Arm64, Arm64.Add), inst);1516 var parsed = mem.bytesAsValue(meta.TagPayload(Arm64, Arm64.Add), inst);
1517 const ta = if (addend) |a| target_addr + a else target_addr;1517 const ta = if (addend) |a| target_addr + a else target_addr;
1518 const narrowed = @truncate(u12, ta);1518 const narrowed = @truncate(u12, ta);
1519 parsed.offset = narrowed;1519 parsed.offset = narrowed;
1520 } else {1520 } else {
1521 log.warn(" | detected LDR/STR opcode", .{});1521 log.debug(" | detected LDR/STR opcode", .{});
1522 // ldr/str1522 // ldr/str
1523 var parsed = mem.bytesAsValue(meta.TagPayload(Arm64, Arm64.LoadRegister), inst);1523 var parsed = mem.bytesAsValue(meta.TagPayload(Arm64, Arm64.LoadRegister), inst);
1524 const ta = if (addend) |a| target_addr + a else target_addr;1524 const ta = if (addend) |a| target_addr + a else target_addr;
...@@ -1559,7 +1559,7 @@ fn doRelocs(self: *Zld) !void {...@@ -1559,7 +1559,7 @@ fn doRelocs(self: *Zld) !void {
1559 };1559 };
1560 const ta = if (addend) |a| target_addr + a else target_addr;1560 const ta = if (addend) |a| target_addr + a else target_addr;
1561 const narrowed = @truncate(u12, ta);1561 const narrowed = @truncate(u12, ta);
1562 log.warn(" | rewriting TLV access to ADD opcode", .{});1562 log.debug(" | rewriting TLV access to ADD opcode", .{});
1563 // For TLV, we always generate an add instruction.1563 // For TLV, we always generate an add instruction.
1564 mem.writeIntLittle(u32, inst, Arm64.add(parsed.rt, parsed.rn, narrowed, parsed.size).toU32());1564 mem.writeIntLittle(u32, inst, Arm64.add(parsed.rt, parsed.rn, narrowed, parsed.size).toU32());
1565 },1565 },
...@@ -1571,7 +1571,7 @@ fn doRelocs(self: *Zld) !void {...@@ -1571,7 +1571,7 @@ fn doRelocs(self: *Zld) !void {
1571 3 => {1571 3 => {
1572 const inst = code[off..][0..8];1572 const inst = code[off..][0..8];
1573 const offset = mem.readIntLittle(i64, inst);1573 const offset = mem.readIntLittle(i64, inst);
1574 log.warn(" | calculated addend 0x{x}", .{offset});1574 log.debug(" | calculated addend 0x{x}", .{offset});
1575 const result = if (sub) |s|1575 const result = if (sub) |s|
1576 @intCast(i64, target_addr) - s + offset1576 @intCast(i64, target_addr) - s + offset
1577 else1577 else
...@@ -1602,7 +1602,7 @@ fn doRelocs(self: *Zld) !void {...@@ -1602,7 +1602,7 @@ fn doRelocs(self: *Zld) !void {
1602 2 => {1602 2 => {
1603 const inst = code[off..][0..4];1603 const inst = code[off..][0..4];
1604 const offset = mem.readIntLittle(i32, inst);1604 const offset = mem.readIntLittle(i32, inst);
1605 log.warn(" | calculated addend 0x{x}", .{offset});1605 log.debug(" | calculated addend 0x{x}", .{offset});
1606 const result = if (sub) |s|1606 const result = if (sub) |s|
1607 @intCast(i64, target_addr) - s + offset1607 @intCast(i64, target_addr) - s + offset
1608 else1608 else
...@@ -1624,7 +1624,7 @@ fn doRelocs(self: *Zld) !void {...@@ -1624,7 +1624,7 @@ fn doRelocs(self: *Zld) !void {
1624 }1624 }
1625 }1625 }
16261626
1627 log.warn("writing contents of '{s},{s}' section from '{s}' from 0x{x} to 0x{x}", .{1627 log.debug("writing contents of '{s},{s}' section from '{s}' from 0x{x} to 0x{x}", .{
1628 segname,1628 segname,
1629 sectname,1629 sectname,
1630 object.name,1630 object.name,
...@@ -1636,7 +1636,7 @@ fn doRelocs(self: *Zld) !void {...@@ -1636,7 +1636,7 @@ fn doRelocs(self: *Zld) !void {
1636 target_sect.flags == macho.S_THREAD_LOCAL_ZEROFILL or1636 target_sect.flags == macho.S_THREAD_LOCAL_ZEROFILL or
1637 target_sect.flags == macho.S_THREAD_LOCAL_VARIABLES)1637 target_sect.flags == macho.S_THREAD_LOCAL_VARIABLES)
1638 {1638 {
1639 log.warn("zeroing out '{s},{s}' from 0x{x} to 0x{x}", .{1639 log.debug("zeroing out '{s},{s}' from 0x{x} to 0x{x}", .{
1640 parseName(&target_sect.segname),1640 parseName(&target_sect.segname),
1641 parseName(&target_sect.sectname),1641 parseName(&target_sect.sectname),
1642 target_sect_off,1642 target_sect_off,
...@@ -1670,7 +1670,7 @@ fn relocTargetAddr(self: *Zld, object_id: u16, rel: macho.relocation_info) !u64...@@ -1670,7 +1670,7 @@ fn relocTargetAddr(self: *Zld, object_id: u16, rel: macho.relocation_info) !u64
1670 const target_seg = self.load_commands.items[target_mapping.target_seg_id].Segment;1670 const target_seg = self.load_commands.items[target_mapping.target_seg_id].Segment;
1671 const target_sect = target_seg.sections.items[target_mapping.target_sect_id];1671 const target_sect = target_seg.sections.items[target_mapping.target_sect_id];
1672 const target_sect_addr = target_sect.addr + target_mapping.offset;1672 const target_sect_addr = target_sect.addr + target_mapping.offset;
1673 log.warn(" | symbol local to object", .{});1673 log.debug(" | symbol local to object", .{});
1674 break :blk target_sect_addr + sym.n_value - source_sect.addr;1674 break :blk target_sect_addr + sym.n_value - source_sect.addr;
1675 } else if (isImport(&sym)) {1675 } else if (isImport(&sym)) {
1676 // Relocate to either the artifact's local symbol, or an import from1676 // Relocate to either the artifact's local symbol, or an import from
...@@ -2275,7 +2275,7 @@ fn writeRebaseInfoTable(self: *Zld) !void {...@@ -2275,7 +2275,7 @@ fn writeRebaseInfoTable(self: *Zld) !void {
2275 dyld_info.rebase_size = @intCast(u32, mem.alignForwardGeneric(u64, buffer.len, @sizeOf(u64)));2275 dyld_info.rebase_size = @intCast(u32, mem.alignForwardGeneric(u64, buffer.len, @sizeOf(u64)));
2276 seg.inner.filesize += dyld_info.rebase_size;2276 seg.inner.filesize += dyld_info.rebase_size;
22772277
2278 log.warn("writing rebase info from 0x{x} to 0x{x}", .{ dyld_info.rebase_off, dyld_info.rebase_off + dyld_info.rebase_size });2278 log.debug("writing rebase info from 0x{x} to 0x{x}", .{ dyld_info.rebase_off, dyld_info.rebase_off + dyld_info.rebase_size });
22792279
2280 try self.file.?.pwriteAll(buffer, dyld_info.rebase_off);2280 try self.file.?.pwriteAll(buffer, dyld_info.rebase_off);
2281}2281}
...@@ -2336,7 +2336,7 @@ fn writeBindInfoTable(self: *Zld) !void {...@@ -2336,7 +2336,7 @@ fn writeBindInfoTable(self: *Zld) !void {
2336 dyld_info.bind_size = @intCast(u32, mem.alignForwardGeneric(u64, buffer.len, @alignOf(u64)));2336 dyld_info.bind_size = @intCast(u32, mem.alignForwardGeneric(u64, buffer.len, @alignOf(u64)));
2337 seg.inner.filesize += dyld_info.bind_size;2337 seg.inner.filesize += dyld_info.bind_size;
23382338
2339 log.warn("writing binding info from 0x{x} to 0x{x}", .{ dyld_info.bind_off, dyld_info.bind_off + dyld_info.bind_size });2339 log.debug("writing binding info from 0x{x} to 0x{x}", .{ dyld_info.bind_off, dyld_info.bind_off + dyld_info.bind_size });
23402340
2341 try self.file.?.pwriteAll(buffer, dyld_info.bind_off);2341 try self.file.?.pwriteAll(buffer, dyld_info.bind_off);
2342}2342}
...@@ -2375,7 +2375,7 @@ fn writeLazyBindInfoTable(self: *Zld) !void {...@@ -2375,7 +2375,7 @@ fn writeLazyBindInfoTable(self: *Zld) !void {
2375 dyld_info.lazy_bind_size = @intCast(u32, mem.alignForwardGeneric(u64, buffer.len, @alignOf(u64)));2375 dyld_info.lazy_bind_size = @intCast(u32, mem.alignForwardGeneric(u64, buffer.len, @alignOf(u64)));
2376 seg.inner.filesize += dyld_info.lazy_bind_size;2376 seg.inner.filesize += dyld_info.lazy_bind_size;
23772377
2378 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 });2378 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 });
23792379
2380 try self.file.?.pwriteAll(buffer, dyld_info.lazy_bind_off);2380 try self.file.?.pwriteAll(buffer, dyld_info.lazy_bind_off);
2381 try self.populateLazyBindOffsetsInStubHelper(buffer);2381 try self.populateLazyBindOffsetsInStubHelper(buffer);
...@@ -2477,7 +2477,7 @@ fn writeExportInfo(self: *Zld) !void {...@@ -2477,7 +2477,7 @@ fn writeExportInfo(self: *Zld) !void {
2477 dyld_info.export_size = @intCast(u32, mem.alignForwardGeneric(u64, buffer.len, @alignOf(u64)));2477 dyld_info.export_size = @intCast(u32, mem.alignForwardGeneric(u64, buffer.len, @alignOf(u64)));
2478 seg.inner.filesize += dyld_info.export_size;2478 seg.inner.filesize += dyld_info.export_size;
24792479
2480 log.warn("writing export info from 0x{x} to 0x{x}", .{ dyld_info.export_off, dyld_info.export_off + dyld_info.export_size });2480 log.debug("writing export info from 0x{x} to 0x{x}", .{ dyld_info.export_off, dyld_info.export_off + dyld_info.export_size });
24812481
2482 try self.file.?.pwriteAll(buffer, dyld_info.export_off);2482 try self.file.?.pwriteAll(buffer, dyld_info.export_off);
2483}2483}
...@@ -2611,7 +2611,7 @@ fn writeDebugInfo(self: *Zld) !void {...@@ -2611,7 +2611,7 @@ fn writeDebugInfo(self: *Zld) !void {
26112611
2612 const stabs_off = symtab.symoff;2612 const stabs_off = symtab.symoff;
2613 const stabs_size = symtab.nsyms * @sizeOf(macho.nlist_64);2613 const stabs_size = symtab.nsyms * @sizeOf(macho.nlist_64);
2614 log.warn("writing symbol stabs from 0x{x} to 0x{x}", .{ stabs_off, stabs_size + stabs_off });2614 log.debug("writing symbol stabs from 0x{x} to 0x{x}", .{ stabs_off, stabs_size + stabs_off });
2615 try self.file.?.pwriteAll(mem.sliceAsBytes(stabs.items), stabs_off);2615 try self.file.?.pwriteAll(mem.sliceAsBytes(stabs.items), stabs_off);
26162616
2617 linkedit.inner.filesize += stabs_size;2617 linkedit.inner.filesize += stabs_size;
...@@ -2629,12 +2629,12 @@ fn writeSymbolTable(self: *Zld) !void {...@@ -2629,12 +2629,12 @@ fn writeSymbolTable(self: *Zld) !void {
2629 defer locals.deinit();2629 defer locals.deinit();
26302630
2631 for (self.locals.items()) |entries| {2631 for (self.locals.items()) |entries| {
2632 log.warn("'{s}': {} entries", .{ entries.key, entries.value.items.len });2632 log.debug("'{s}': {} entries", .{ entries.key, entries.value.items.len });
2633 // var symbol: ?macho.nlist_64 = null;2633 // var symbol: ?macho.nlist_64 = null;
2634 for (entries.value.items) |entry| {2634 for (entries.value.items) |entry| {
2635 log.warn(" | {}", .{entry.inner});2635 log.debug(" | {}", .{entry.inner});
2636 log.warn(" | {}", .{entry.tt});2636 log.debug(" | {}", .{entry.tt});
2637 log.warn(" | {s}", .{self.objects.items[entry.object_id].name});2637 log.debug(" | {s}", .{self.objects.items[entry.object_id].name});
2638 // switch (entry.tt) {2638 // switch (entry.tt) {
2639 // .Global => {2639 // .Global => {
2640 // symbol = entry.inner;2640 // symbol = entry.inner;
...@@ -2679,17 +2679,17 @@ fn writeSymbolTable(self: *Zld) !void {...@@ -2679,17 +2679,17 @@ fn writeSymbolTable(self: *Zld) !void {
26792679
2680 const locals_off = symtab.symoff + symtab.nsyms * @sizeOf(macho.nlist_64);2680 const locals_off = symtab.symoff + symtab.nsyms * @sizeOf(macho.nlist_64);
2681 const locals_size = nlocals * @sizeOf(macho.nlist_64);2681 const locals_size = nlocals * @sizeOf(macho.nlist_64);
2682 log.warn("writing local symbols from 0x{x} to 0x{x}", .{ locals_off, locals_size + locals_off });2682 log.debug("writing local symbols from 0x{x} to 0x{x}", .{ locals_off, locals_size + locals_off });
2683 try self.file.?.pwriteAll(mem.sliceAsBytes(locals.items), locals_off);2683 try self.file.?.pwriteAll(mem.sliceAsBytes(locals.items), locals_off);
26842684
2685 const exports_off = locals_off + locals_size;2685 const exports_off = locals_off + locals_size;
2686 const exports_size = nexports * @sizeOf(macho.nlist_64);2686 const exports_size = nexports * @sizeOf(macho.nlist_64);
2687 log.warn("writing exported symbols from 0x{x} to 0x{x}", .{ exports_off, exports_size + exports_off });2687 log.debug("writing exported symbols from 0x{x} to 0x{x}", .{ exports_off, exports_size + exports_off });
2688 try self.file.?.pwriteAll(mem.sliceAsBytes(exports.items), exports_off);2688 try self.file.?.pwriteAll(mem.sliceAsBytes(exports.items), exports_off);
26892689
2690 const undefs_off = exports_off + exports_size;2690 const undefs_off = exports_off + exports_size;
2691 const undefs_size = nundefs * @sizeOf(macho.nlist_64);2691 const undefs_size = nundefs * @sizeOf(macho.nlist_64);
2692 log.warn("writing undefined symbols from 0x{x} to 0x{x}", .{ undefs_off, undefs_size + undefs_off });2692 log.debug("writing undefined symbols from 0x{x} to 0x{x}", .{ undefs_off, undefs_size + undefs_off });
2693 try self.file.?.pwriteAll(mem.sliceAsBytes(undefs.items), undefs_off);2693 try self.file.?.pwriteAll(mem.sliceAsBytes(undefs.items), undefs_off);
26942694
2695 symtab.nsyms += @intCast(u32, nlocals + nexports + nundefs);2695 symtab.nsyms += @intCast(u32, nlocals + nexports + nundefs);
...@@ -2720,7 +2720,7 @@ fn writeDynamicSymbolTable(self: *Zld) !void {...@@ -2720,7 +2720,7 @@ fn writeDynamicSymbolTable(self: *Zld) !void {
2720 const needed_size = dysymtab.nindirectsyms * @sizeOf(u32);2720 const needed_size = dysymtab.nindirectsyms * @sizeOf(u32);
2721 seg.inner.filesize += needed_size;2721 seg.inner.filesize += needed_size;
27222722
2723 log.warn("writing indirect symbol table from 0x{x} to 0x{x}", .{2723 log.debug("writing indirect symbol table from 0x{x} to 0x{x}", .{
2724 dysymtab.indirectsymoff,2724 dysymtab.indirectsymoff,
2725 dysymtab.indirectsymoff + needed_size,2725 dysymtab.indirectsymoff + needed_size,
2726 });2726 });
...@@ -2759,7 +2759,7 @@ fn writeStringTable(self: *Zld) !void {...@@ -2759,7 +2759,7 @@ fn writeStringTable(self: *Zld) !void {
2759 symtab.strsize = @intCast(u32, mem.alignForwardGeneric(u64, self.strtab.items.len, @alignOf(u64)));2759 symtab.strsize = @intCast(u32, mem.alignForwardGeneric(u64, self.strtab.items.len, @alignOf(u64)));
2760 seg.inner.filesize += symtab.strsize;2760 seg.inner.filesize += symtab.strsize;
27612761
2762 log.warn("writing string table from 0x{x} to 0x{x}", .{ symtab.stroff, symtab.stroff + symtab.strsize });2762 log.debug("writing string table from 0x{x} to 0x{x}", .{ symtab.stroff, symtab.stroff + symtab.strsize });
27632763
2764 try self.file.?.pwriteAll(self.strtab.items, symtab.stroff);2764 try self.file.?.pwriteAll(self.strtab.items, symtab.stroff);
27652765
...@@ -2806,7 +2806,7 @@ fn writeDataInCode(self: *Zld) !void {...@@ -2806,7 +2806,7 @@ fn writeDataInCode(self: *Zld) !void {
2806 dice_cmd.datasize = datasize;2806 dice_cmd.datasize = datasize;
2807 seg.inner.filesize += datasize;2807 seg.inner.filesize += datasize;
28082808
2809 log.warn("writing data-in-code from 0x{x} to 0x{x}", .{ fileoff, fileoff + datasize });2809 log.debug("writing data-in-code from 0x{x} to 0x{x}", .{ fileoff, fileoff + datasize });
28102810
2811 try self.file.?.pwriteAll(buf.items, fileoff);2811 try self.file.?.pwriteAll(buf.items, fileoff);
2812}2812}
...@@ -2827,7 +2827,7 @@ fn writeCodeSignaturePadding(self: *Zld) !void {...@@ -2827,7 +2827,7 @@ fn writeCodeSignaturePadding(self: *Zld) !void {
2827 seg.inner.filesize += needed_size;2827 seg.inner.filesize += needed_size;
2828 seg.inner.vmsize = mem.alignForwardGeneric(u64, seg.inner.filesize, self.page_size.?);2828 seg.inner.vmsize = mem.alignForwardGeneric(u64, seg.inner.filesize, self.page_size.?);
28292829
2830 log.warn("writing code signature padding from 0x{x} to 0x{x}", .{ fileoff, fileoff + needed_size });2830 log.debug("writing code signature padding from 0x{x} to 0x{x}", .{ fileoff, fileoff + needed_size });
28312831
2832 // Pad out the space. We need to do this to calculate valid hashes for everything in the file2832 // Pad out the space. We need to do this to calculate valid hashes for everything in the file
2833 // except for code signature data.2833 // except for code signature data.
...@@ -2853,7 +2853,7 @@ fn writeCodeSignature(self: *Zld) !void {...@@ -2853,7 +2853,7 @@ fn writeCodeSignature(self: *Zld) !void {
2853 var stream = std.io.fixedBufferStream(buffer);2853 var stream = std.io.fixedBufferStream(buffer);
2854 try code_sig.write(stream.writer());2854 try code_sig.write(stream.writer());
28552855
2856 log.warn("writing code signature from 0x{x} to 0x{x}", .{ code_sig_cmd.dataoff, code_sig_cmd.dataoff + buffer.len });2856 log.debug("writing code signature from 0x{x} to 0x{x}", .{ code_sig_cmd.dataoff, code_sig_cmd.dataoff + buffer.len });
28572857
2858 try self.file.?.pwriteAll(buffer, code_sig_cmd.dataoff);2858 try self.file.?.pwriteAll(buffer, code_sig_cmd.dataoff);
2859}2859}
...@@ -2872,7 +2872,7 @@ fn writeLoadCommands(self: *Zld) !void {...@@ -2872,7 +2872,7 @@ fn writeLoadCommands(self: *Zld) !void {
2872 }2872 }
28732873
2874 const off = @sizeOf(macho.mach_header_64);2874 const off = @sizeOf(macho.mach_header_64);
2875 log.warn("writing {} load commands from 0x{x} to 0x{x}", .{ self.load_commands.items.len, off, off + sizeofcmds });2875 log.debug("writing {} load commands from 0x{x} to 0x{x}", .{ self.load_commands.items.len, off, off + sizeofcmds });
2876 try self.file.?.pwriteAll(buffer, off);2876 try self.file.?.pwriteAll(buffer, off);
2877}2877}
28782878
...@@ -2910,7 +2910,7 @@ fn writeHeader(self: *Zld) !void {...@@ -2910,7 +2910,7 @@ fn writeHeader(self: *Zld) !void {
2910 for (self.load_commands.items) |cmd| {2910 for (self.load_commands.items) |cmd| {
2911 header.sizeofcmds += cmd.cmdsize();2911 header.sizeofcmds += cmd.cmdsize();
2912 }2912 }
2913 log.warn("writing Mach-O header {}", .{header});2913 log.debug("writing Mach-O header {}", .{header});
2914 try self.file.?.pwriteAll(mem.asBytes(&header), 0);2914 try self.file.?.pwriteAll(mem.asBytes(&header), 0);
2915}2915}
29162916
...@@ -2924,7 +2924,7 @@ pub fn makeStaticString(bytes: []const u8) [16]u8 {...@@ -2924,7 +2924,7 @@ pub fn makeStaticString(bytes: []const u8) [16]u8 {
2924fn makeString(self: *Zld, bytes: []const u8) !u32 {2924fn makeString(self: *Zld, bytes: []const u8) !u32 {
2925 try self.strtab.ensureCapacity(self.allocator, self.strtab.items.len + bytes.len + 1);2925 try self.strtab.ensureCapacity(self.allocator, self.strtab.items.len + bytes.len + 1);
2926 const offset = @intCast(u32, self.strtab.items.len);2926 const offset = @intCast(u32, self.strtab.items.len);
2927 log.warn("writing new string '{s}' into string table at offset 0x{x}", .{ bytes, offset });2927 log.debug("writing new string '{s}' into string table at offset 0x{x}", .{ bytes, offset });
2928 self.strtab.appendSliceAssumeCapacity(bytes);2928 self.strtab.appendSliceAssumeCapacity(bytes);
2929 self.strtab.appendAssumeCapacity(0);2929 self.strtab.appendAssumeCapacity(0);
2930 return offset;2930 return offset;