| ... | ... | @@ -767,7 +767,9 @@ fn resolveImports(self: *Zld) !void { |
| 767 | 767 | mem.eql(u8, sym_name, "___stderrp") or |
| 768 | 768 | mem.eql(u8, sym_name, "___stdinp") or |
| 769 | 769 | mem.eql(u8, sym_name, "___stack_chk_guard") or |
| 770 | | mem.eql(u8, sym_name, "_environ")) |
| 770 | mem.eql(u8, sym_name, "_environ") or |
| 771 | mem.eql(u8, sym_name, "__DefaultRuneLocale") or |
| 772 | mem.eql(u8, sym_name, "_mach_task_self_")) |
| 771 | 773 | { |
| 772 | 774 | log.debug("writing nonlazy symbol '{s}'", .{sym_name}); |
| 773 | 775 | const index = @intCast(u32, self.nonlazy_imports.items().len); |
| ... | ... | @@ -1192,6 +1194,8 @@ fn writeStubInStubHelper(self: *Zld, index: u32) !void { |
| 1192 | 1194 | fn resolveSymbols(self: *Zld) !void { |
| 1193 | 1195 | for (self.objects.items) |object, object_id| { |
| 1194 | 1196 | const seg = object.load_commands.items[object.segment_cmd_index.?].Segment; |
| 1197 | log.debug("\n\n", .{}); |
| 1198 | log.debug("resolving symbols in {s}", .{object.name}); |
| 1195 | 1199 | |
| 1196 | 1200 | for (object.symtab.items) |sym| { |
| 1197 | 1201 | if (isImport(&sym)) continue; |
| ... | ... | @@ -1219,8 +1223,10 @@ fn resolveSymbols(self: *Zld) !void { |
| 1219 | 1223 | if (tt == .Global) { |
| 1220 | 1224 | for (locs.entry.value.items) |ss| { |
| 1221 | 1225 | if (ss.tt == .Global) { |
| 1222 | | log.err("symbol '{s}' defined multiple times", .{sym_name}); |
| 1223 | | return error.MultipleSymbolDefinitions; |
| 1226 | log.debug("symbol already defined '{s}'", .{sym_name}); |
| 1227 | continue; |
| 1228 | // log.err("symbol '{s}' defined multiple times: {}", .{ sym_name, sym }); |
| 1229 | // return error.MultipleSymbolDefinitions; |
| 1224 | 1230 | } |
| 1225 | 1231 | } |
| 1226 | 1232 | } |
| ... | ... | @@ -1589,8 +1595,28 @@ fn doRelocs(self: *Zld) !void { |
| 1589 | 1595 | ), |
| 1590 | 1596 | inst, |
| 1591 | 1597 | ); |
| 1598 | |
| 1592 | 1599 | const ta = if (addend) |a| target_addr + a else target_addr; |
| 1593 | 1600 | const narrowed = @truncate(u12, ta); |
| 1601 | log.debug(" | narrowed 0x{x}", .{narrowed}); |
| 1602 | log.debug(" | parsed.size 0x{x}", .{parsed.size}); |
| 1603 | |
| 1604 | if (rel_type == .ARM64_RELOC_GOT_LOAD_PAGEOFF12) blk: { |
| 1605 | const data_const_seg = self.load_commands.items[self.data_const_segment_cmd_index.?].Segment; |
| 1606 | const got = data_const_seg.sections.items[self.got_section_index.?]; |
| 1607 | if (got.addr <= target_addr and target_addr < got.addr + got.size) break :blk; |
| 1608 | |
| 1609 | log.debug(" | rewriting to add", .{}); |
| 1610 | mem.writeIntLittle(u32, inst, aarch64.Instruction.add( |
| 1611 | @intToEnum(aarch64.Register, parsed.rt), |
| 1612 | @intToEnum(aarch64.Register, parsed.rn), |
| 1613 | narrowed, |
| 1614 | false, |
| 1615 | ).toU32()); |
| 1616 | addend = null; |
| 1617 | continue; |
| 1618 | } |
| 1619 | |
| 1594 | 1620 | const offset: u12 = blk: { |
| 1595 | 1621 | if (parsed.size == 0) { |
| 1596 | 1622 | if (parsed.v == 1) { |
| ... | ... | @@ -2628,8 +2654,16 @@ fn writeDebugInfo(self: *Zld) !void { |
| 2628 | 2654 | }); |
| 2629 | 2655 | // Path to object file with debug info |
| 2630 | 2656 | var buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined; |
| 2631 | | const path = object.name; |
| 2632 | | const full_path = try std.os.realpath(path, &buffer); |
| 2657 | const full_path = blk: { |
| 2658 | if (object.ar_name) |prefix| { |
| 2659 | const path = try std.os.realpath(prefix, &buffer); |
| 2660 | break :blk try std.fmt.allocPrint(self.allocator, "{s}({s})", .{ path, object.name }); |
| 2661 | } else { |
| 2662 | const path = try std.os.realpath(object.name, &buffer); |
| 2663 | break :blk try mem.dupe(self.allocator, u8, path); |
| 2664 | } |
| 2665 | }; |
| 2666 | defer self.allocator.free(full_path); |
| 2633 | 2667 | const stat = try object.file.stat(); |
| 2634 | 2668 | const mtime = @intCast(u64, @divFloor(stat.mtime, 1_000_000_000)); |
| 2635 | 2669 | try stabs.append(.{ |
| ... | ... | @@ -2640,6 +2674,7 @@ fn writeDebugInfo(self: *Zld) !void { |
| 2640 | 2674 | .n_value = mtime, |
| 2641 | 2675 | }); |
| 2642 | 2676 | } |
| 2677 | log.debug("analyzing debug info in '{s}'", .{object.name}); |
| 2643 | 2678 | |
| 2644 | 2679 | for (object.symtab.items) |source_sym| { |
| 2645 | 2680 | const symname = object.getString(source_sym.n_strx); |