macho: remove dead code

This commit is contained in:
Jakub Konka 2023-08-18 16:47:48 +02:00
parent 3b2b9fcbc5
commit e6891b2422

View File

@ -3794,261 +3794,6 @@ pub fn findFirst(comptime T: type, haystack: []align(1) const T, start: usize, p
return i;
}
// fn snapshotState(self: *MachO) !void {
// const emit = self.base.options.emit orelse {
// log.debug("no emit directory found; skipping snapshot...", .{});
// return;
// };
// const Snapshot = struct {
// const Node = struct {
// const Tag = enum {
// section_start,
// section_end,
// atom_start,
// atom_end,
// relocation,
// pub fn jsonStringify(
// tag: Tag,
// options: std.json.StringifyOptions,
// out_stream: anytype,
// ) !void {
// _ = options;
// switch (tag) {
// .section_start => try out_stream.writeAll("\"section_start\""),
// .section_end => try out_stream.writeAll("\"section_end\""),
// .atom_start => try out_stream.writeAll("\"atom_start\""),
// .atom_end => try out_stream.writeAll("\"atom_end\""),
// .relocation => try out_stream.writeAll("\"relocation\""),
// }
// }
// };
// const Payload = struct {
// name: []const u8 = "",
// aliases: [][]const u8 = &[0][]const u8{},
// is_global: bool = false,
// target: u64 = 0,
// };
// address: u64,
// tag: Tag,
// payload: Payload,
// };
// timestamp: i128,
// nodes: []Node,
// };
// var arena_allocator = std.heap.ArenaAllocator.init(self.base.allocator);
// defer arena_allocator.deinit();
// const arena = arena_allocator.allocator();
// const out_file = try emit.directory.handle.createFile("snapshots.json", .{
// .truncate = false,
// .read = true,
// });
// defer out_file.close();
// if (out_file.seekFromEnd(-1)) {
// try out_file.writer().writeByte(',');
// } else |err| switch (err) {
// error.Unseekable => try out_file.writer().writeByte('['),
// else => |e| return e,
// }
// const writer = out_file.writer();
// var snapshot = Snapshot{
// .timestamp = std.time.nanoTimestamp(),
// .nodes = undefined,
// };
// var nodes = std.ArrayList(Snapshot.Node).init(arena);
// for (self.section_ordinals.keys()) |key| {
// const sect = self.getSection(key);
// const sect_name = try std.fmt.allocPrint(arena, "{s},{s}", .{ sect.segName(), sect.sectName() });
// try nodes.append(.{
// .address = sect.addr,
// .tag = .section_start,
// .payload = .{ .name = sect_name },
// });
// const is_tlv = sect.type_() == macho.S_THREAD_LOCAL_VARIABLES;
// var atom: *Atom = self.atoms.get(key) orelse {
// try nodes.append(.{
// .address = sect.addr + sect.size,
// .tag = .section_end,
// .payload = .{},
// });
// continue;
// };
// while (atom.prev) |prev| {
// atom = prev;
// }
// while (true) {
// const atom_sym = atom.getSymbol(self);
// var node = Snapshot.Node{
// .address = atom_sym.n_value,
// .tag = .atom_start,
// .payload = .{
// .name = atom.getName(self),
// .is_global = self.globals.contains(atom.getName(self)),
// },
// };
// var aliases = std.ArrayList([]const u8).init(arena);
// for (atom.contained.items) |sym_off| {
// if (sym_off.offset == 0) {
// try aliases.append(self.getSymbolName(.{
// .sym_index = sym_off.sym_index,
// .file = atom.file,
// }));
// }
// }
// node.payload.aliases = aliases.toOwnedSlice();
// try nodes.append(node);
// var relocs = try std.ArrayList(Snapshot.Node).initCapacity(arena, atom.relocs.items.len);
// for (atom.relocs.items) |rel| {
// const source_addr = blk: {
// const source_sym = atom.getSymbol(self);
// break :blk source_sym.n_value + rel.offset;
// };
// const target_addr = blk: {
// const target_atom = rel.getTargetAtom(self) orelse {
// // If there is no atom for target, we still need to check for special, atom-less
// // symbols such as `___dso_handle`.
// const target_name = self.getSymbolName(rel.target);
// if (self.globals.contains(target_name)) {
// const atomless_sym = self.getSymbol(rel.target);
// break :blk atomless_sym.n_value;
// }
// break :blk 0;
// };
// const target_sym = if (target_atom.isSymbolContained(rel.target, self))
// self.getSymbol(rel.target)
// else
// target_atom.getSymbol(self);
// const base_address: u64 = if (is_tlv) base_address: {
// const sect_id: u16 = sect_id: {
// if (self.tlv_data_section_index) |i| {
// break :sect_id i;
// } else if (self.tlv_bss_section_index) |i| {
// break :sect_id i;
// } else unreachable;
// };
// break :base_address self.getSection(.{
// .seg = self.data_segment_cmd_index.?,
// .sect = sect_id,
// }).addr;
// } else 0;
// break :blk target_sym.n_value - base_address;
// };
// relocs.appendAssumeCapacity(.{
// .address = source_addr,
// .tag = .relocation,
// .payload = .{ .target = target_addr },
// });
// }
// if (atom.contained.items.len == 0) {
// try nodes.appendSlice(relocs.items);
// } else {
// // Need to reverse iteration order of relocs since by default for relocatable sources
// // they come in reverse. For linking, this doesn't matter in any way, however, for
// // arranging the memoryline for displaying it does.
// std.mem.reverse(Snapshot.Node, relocs.items);
// var next_i: usize = 0;
// var last_rel: usize = 0;
// while (next_i < atom.contained.items.len) : (next_i += 1) {
// const loc = SymbolWithLoc{
// .sym_index = atom.contained.items[next_i].sym_index,
// .file = atom.file,
// };
// const cont_sym = self.getSymbol(loc);
// const cont_sym_name = self.getSymbolName(loc);
// var contained_node = Snapshot.Node{
// .address = cont_sym.n_value,
// .tag = .atom_start,
// .payload = .{
// .name = cont_sym_name,
// .is_global = self.globals.contains(cont_sym_name),
// },
// };
// // Accumulate aliases
// var inner_aliases = std.ArrayList([]const u8).init(arena);
// while (true) {
// if (next_i + 1 >= atom.contained.items.len) break;
// const next_sym_loc = SymbolWithLoc{
// .sym_index = atom.contained.items[next_i + 1].sym_index,
// .file = atom.file,
// };
// const next_sym = self.getSymbol(next_sym_loc);
// if (next_sym.n_value != cont_sym.n_value) break;
// const next_sym_name = self.getSymbolName(next_sym_loc);
// if (self.globals.contains(next_sym_name)) {
// try inner_aliases.append(contained_node.payload.name);
// contained_node.payload.name = next_sym_name;
// contained_node.payload.is_global = true;
// } else try inner_aliases.append(next_sym_name);
// next_i += 1;
// }
// const cont_size = if (next_i + 1 < atom.contained.items.len)
// self.getSymbol(.{
// .sym_index = atom.contained.items[next_i + 1].sym_index,
// .file = atom.file,
// }).n_value - cont_sym.n_value
// else
// atom_sym.n_value + atom.size - cont_sym.n_value;
// contained_node.payload.aliases = inner_aliases.toOwnedSlice();
// try nodes.append(contained_node);
// for (relocs.items[last_rel..]) |rel| {
// if (rel.address >= cont_sym.n_value + cont_size) {
// break;
// }
// try nodes.append(rel);
// last_rel += 1;
// }
// try nodes.append(.{
// .address = cont_sym.n_value + cont_size,
// .tag = .atom_end,
// .payload = .{},
// });
// }
// }
// try nodes.append(.{
// .address = atom_sym.n_value + atom.size,
// .tag = .atom_end,
// .payload = .{},
// });
// if (atom.next) |next| {
// atom = next;
// } else break;
// }
// try nodes.append(.{
// .address = sect.addr + sect.size,
// .tag = .section_end,
// .payload = .{},
// });
// }
// snapshot.nodes = nodes.toOwnedSlice();
// try std.json.stringify(snapshot, .{}, writer);
// try writer.writeByte(']');
// }
pub fn logSections(self: *MachO) void {
log.debug("sections:", .{});
for (self.sections.items(.header), 0..) |header, i| {