compiler: update all instances of std.fmt.Formatter
This commit is contained in:
6
lib/compiler/aro/aro/Diagnostics.zig
vendored
6
lib/compiler/aro/aro/Diagnostics.zig
vendored
@@ -542,15 +542,15 @@ const MsgWriter = struct {
|
||||
}
|
||||
|
||||
pub fn print(m: *MsgWriter, comptime fmt: []const u8, args: anytype) void {
|
||||
m.w.writer().print(fmt, args) catch {};
|
||||
m.w.interface.print(fmt, args) catch {};
|
||||
}
|
||||
|
||||
fn write(m: *MsgWriter, msg: []const u8) void {
|
||||
m.w.writer().writeAll(msg) catch {};
|
||||
m.w.interface.writeAll(msg) catch {};
|
||||
}
|
||||
|
||||
fn setColor(m: *MsgWriter, color: std.io.tty.Color) void {
|
||||
m.config.setColor(m.w.writer(), color) catch {};
|
||||
m.config.setColor(m.w.interface, color) catch {};
|
||||
}
|
||||
|
||||
fn location(m: *MsgWriter, path: []const u8, line: u32, col: u32) void {
|
||||
|
||||
@@ -6012,9 +6012,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
|
||||
|
||||
// In .rc files, a " within a quoted string is escaped as ""
|
||||
const fmtRcEscape = struct {
|
||||
fn formatRcEscape(bytes: []const u8, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
|
||||
_ = fmt;
|
||||
_ = options;
|
||||
fn formatRcEscape(bytes: []const u8, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
for (bytes) |byte| switch (byte) {
|
||||
'"' => try writer.writeAll("\"\""),
|
||||
'\\' => try writer.writeAll("\\\\"),
|
||||
@@ -6022,7 +6020,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
|
||||
};
|
||||
}
|
||||
|
||||
pub fn fmtRcEscape(bytes: []const u8) std.fmt.Formatter(formatRcEscape) {
|
||||
pub fn fmtRcEscape(bytes: []const u8) std.fmt.Formatter([]const u8, formatRcEscape) {
|
||||
return .{ .data = bytes };
|
||||
}
|
||||
}.fmtRcEscape;
|
||||
|
||||
35
src/Type.zig
35
src/Type.zig
@@ -121,15 +121,14 @@ pub fn eql(a: Type, b: Type, zcu: *const Zcu) bool {
|
||||
return a.toIntern() == b.toIntern();
|
||||
}
|
||||
|
||||
pub fn format(ty: Type, comptime unused_fmt_string: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
|
||||
pub fn format(ty: Type, writer: *std.io.Writer, comptime unused_fmt_string: []const u8) !void {
|
||||
_ = ty;
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
_ = writer;
|
||||
@compileError("do not format types directly; use either ty.fmtDebug() or ty.fmt()");
|
||||
}
|
||||
|
||||
pub const Formatter = std.fmt.Formatter(format2);
|
||||
pub const Formatter = std.fmt.Formatter(Format, Format.default);
|
||||
|
||||
pub fn fmt(ty: Type, pt: Zcu.PerThread) Formatter {
|
||||
return .{ .data = .{
|
||||
@@ -138,42 +137,28 @@ pub fn fmt(ty: Type, pt: Zcu.PerThread) Formatter {
|
||||
} };
|
||||
}
|
||||
|
||||
const FormatContext = struct {
|
||||
const Format = struct {
|
||||
ty: Type,
|
||||
pt: Zcu.PerThread,
|
||||
|
||||
fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
return print(f.ty, writer, f.pt);
|
||||
}
|
||||
};
|
||||
|
||||
fn format2(
|
||||
ctx: FormatContext,
|
||||
comptime unused_format_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
comptime assert(unused_format_string.len == 0);
|
||||
_ = options;
|
||||
return print(ctx.ty, writer, ctx.pt);
|
||||
}
|
||||
|
||||
pub fn fmtDebug(ty: Type) std.fmt.Formatter(dump) {
|
||||
pub fn fmtDebug(ty: Type) std.fmt.Formatter(Type, dump) {
|
||||
return .{ .data = ty };
|
||||
}
|
||||
|
||||
/// This is a debug function. In order to print types in a meaningful way
|
||||
/// we also need access to the module.
|
||||
pub fn dump(
|
||||
start_type: Type,
|
||||
comptime unused_format_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) @TypeOf(writer).Error!void {
|
||||
_ = options;
|
||||
comptime assert(unused_format_string.len == 0);
|
||||
pub fn dump(start_type: Type, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
return writer.print("{any}", .{start_type.ip_index});
|
||||
}
|
||||
|
||||
/// Prints a name suitable for `@typeName`.
|
||||
/// TODO: take an `opt_sema` to pass to `fmtValue` when printing sentinels.
|
||||
pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error!void {
|
||||
pub fn print(ty: Type, writer: *std.io.Writer, pt: Zcu.PerThread) std.io.Writer.Error!void {
|
||||
const zcu = pt.zcu;
|
||||
const ip = &zcu.intern_pool;
|
||||
switch (ip.indexToKey(ty.toIntern())) {
|
||||
|
||||
@@ -15,31 +15,24 @@ const Value = @This();
|
||||
|
||||
ip_index: InternPool.Index,
|
||||
|
||||
pub fn format(val: Value, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
|
||||
pub fn format(val: Value, writer: *std.io.Writer, comptime fmt: []const u8) !void {
|
||||
_ = val;
|
||||
_ = fmt;
|
||||
_ = options;
|
||||
_ = writer;
|
||||
_ = fmt;
|
||||
@compileError("do not use format values directly; use either fmtDebug or fmtValue");
|
||||
}
|
||||
|
||||
/// This is a debug function. In order to print values in a meaningful way
|
||||
/// we also need access to the type.
|
||||
pub fn dump(
|
||||
start_val: Value,
|
||||
comptime fmt: []const u8,
|
||||
_: std.fmt.FormatOptions,
|
||||
out_stream: anytype,
|
||||
) !void {
|
||||
comptime assert(fmt.len == 0);
|
||||
try out_stream.print("(interned: {})", .{start_val.toIntern()});
|
||||
pub fn dump(start_val: Value, w: std.io.Writer) std.io.Writer.Error!void {
|
||||
try w.print("(interned: {})", .{start_val.toIntern()});
|
||||
}
|
||||
|
||||
pub fn fmtDebug(val: Value) std.fmt.Formatter(dump) {
|
||||
pub fn fmtDebug(val: Value) std.fmt.Formatter(Value, dump) {
|
||||
return .{ .data = val };
|
||||
}
|
||||
|
||||
pub fn fmtValue(val: Value, pt: Zcu.PerThread) std.fmt.Formatter(print_value.format) {
|
||||
pub fn fmtValue(val: Value, pt: Zcu.PerThread) std.fmt.Formatter(print_value.FormatContext, print_value.format) {
|
||||
return .{ .data = .{
|
||||
.val = val,
|
||||
.pt = pt,
|
||||
@@ -48,7 +41,7 @@ pub fn fmtValue(val: Value, pt: Zcu.PerThread) std.fmt.Formatter(print_value.for
|
||||
} };
|
||||
}
|
||||
|
||||
pub fn fmtValueSema(val: Value, pt: Zcu.PerThread, sema: *Sema) std.fmt.Formatter(print_value.formatSema) {
|
||||
pub fn fmtValueSema(val: Value, pt: Zcu.PerThread, sema: *Sema) std.fmt.Formatter(print_value.FormatContext, print_value.formatSema) {
|
||||
return .{ .data = .{
|
||||
.val = val,
|
||||
.pt = pt,
|
||||
@@ -57,7 +50,7 @@ pub fn fmtValueSema(val: Value, pt: Zcu.PerThread, sema: *Sema) std.fmt.Formatte
|
||||
} };
|
||||
}
|
||||
|
||||
pub fn fmtValueSemaFull(ctx: print_value.FormatContext) std.fmt.Formatter(print_value.formatSema) {
|
||||
pub fn fmtValueSemaFull(ctx: print_value.FormatContext) std.fmt.Formatter(print_value.FormatContext, print_value.formatSema) {
|
||||
return .{ .data = ctx };
|
||||
}
|
||||
|
||||
|
||||
@@ -937,12 +937,7 @@ const FormatWipMirData = struct {
|
||||
func: *Func,
|
||||
inst: Mir.Inst.Index,
|
||||
};
|
||||
fn formatWipMir(
|
||||
data: FormatWipMirData,
|
||||
comptime _: []const u8,
|
||||
_: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) @TypeOf(writer).Error!void {
|
||||
fn formatWipMir(data: FormatWipMirData, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
const pt = data.func.pt;
|
||||
const comp = pt.zcu.comp;
|
||||
var lower: Lower = .{
|
||||
@@ -982,7 +977,7 @@ fn formatWipMir(
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
fn fmtWipMir(func: *Func, inst: Mir.Inst.Index) std.fmt.Formatter(formatWipMir) {
|
||||
fn fmtWipMir(func: *Func, inst: Mir.Inst.Index) std.fmt.Formatter(FormatWipMirData, formatWipMir) {
|
||||
return .{ .data = .{ .func = func, .inst = inst } };
|
||||
}
|
||||
|
||||
@@ -990,15 +985,10 @@ const FormatNavData = struct {
|
||||
ip: *const InternPool,
|
||||
nav_index: InternPool.Nav.Index,
|
||||
};
|
||||
fn formatNav(
|
||||
data: FormatNavData,
|
||||
comptime _: []const u8,
|
||||
_: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) @TypeOf(writer).Error!void {
|
||||
try writer.print("{}", .{data.ip.getNav(data.nav_index).fqn.fmt(data.ip)});
|
||||
fn formatNav(data: FormatNavData, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
try writer.print("{f}", .{data.ip.getNav(data.nav_index).fqn.fmt(data.ip)});
|
||||
}
|
||||
fn fmtNav(nav_index: InternPool.Nav.Index, ip: *const InternPool) std.fmt.Formatter(formatNav) {
|
||||
fn fmtNav(nav_index: InternPool.Nav.Index, ip: *const InternPool) std.fmt.Formatter(FormatNavData, formatNav) {
|
||||
return .{ .data = .{
|
||||
.ip = ip,
|
||||
.nav_index = nav_index,
|
||||
@@ -1009,31 +999,25 @@ const FormatAirData = struct {
|
||||
func: *Func,
|
||||
inst: Air.Inst.Index,
|
||||
};
|
||||
fn formatAir(
|
||||
data: FormatAirData,
|
||||
comptime _: []const u8,
|
||||
_: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) @TypeOf(writer).Error!void {
|
||||
data.func.air.dumpInst(data.inst, data.func.pt, data.func.liveness);
|
||||
fn formatAir(data: FormatAirData, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
// Not acceptable implementation because it ignores `writer`:
|
||||
//data.func.air.dumpInst(data.inst, data.func.pt, data.func.liveness);
|
||||
_ = data;
|
||||
_ = writer;
|
||||
@panic("unimplemented");
|
||||
}
|
||||
fn fmtAir(func: *Func, inst: Air.Inst.Index) std.fmt.Formatter(formatAir) {
|
||||
fn fmtAir(func: *Func, inst: Air.Inst.Index) std.fmt.Formatter(FormatAirData, formatAir) {
|
||||
return .{ .data = .{ .func = func, .inst = inst } };
|
||||
}
|
||||
|
||||
const FormatTrackingData = struct {
|
||||
func: *Func,
|
||||
};
|
||||
fn formatTracking(
|
||||
data: FormatTrackingData,
|
||||
comptime _: []const u8,
|
||||
_: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) @TypeOf(writer).Error!void {
|
||||
fn formatTracking(data: FormatTrackingData, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
var it = data.func.inst_tracking.iterator();
|
||||
while (it.next()) |entry| try writer.print("\n%{d} = {}", .{ entry.key_ptr.*, entry.value_ptr.* });
|
||||
}
|
||||
fn fmtTracking(func: *Func) std.fmt.Formatter(formatTracking) {
|
||||
fn fmtTracking(func: *Func) std.fmt.Formatter(FormatTrackingData, formatTracking) {
|
||||
return .{ .data = .{ .func = func } };
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -340,13 +340,15 @@ fn isReservedIdent(ident: []const u8) bool {
|
||||
} else return reserved_idents.has(ident);
|
||||
}
|
||||
|
||||
fn formatIdent(
|
||||
ident: []const u8,
|
||||
comptime fmt_str: []const u8,
|
||||
_: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) @TypeOf(writer).Error!void {
|
||||
const solo = fmt_str.len != 0 and fmt_str[0] == ' '; // space means solo; not part of a bigger ident.
|
||||
fn formatIdentSolo(ident: []const u8, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
return formatIdentOptions(ident, writer, true);
|
||||
}
|
||||
|
||||
fn formatIdentUnsolo(ident: []const u8, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
return formatIdentOptions(ident, writer, false);
|
||||
}
|
||||
|
||||
fn formatIdentOptions(ident: []const u8, writer: *std.io.Writer, solo: bool) std.io.Writer.Error!void {
|
||||
if (solo and isReservedIdent(ident)) {
|
||||
try writer.writeAll("zig_e_");
|
||||
}
|
||||
@@ -363,30 +365,36 @@ fn formatIdent(
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn fmtIdent(ident: []const u8) std.fmt.Formatter(formatIdent) {
|
||||
|
||||
pub fn fmtIdentSolo(ident: []const u8) std.fmt.Formatter([]const u8, formatIdentSolo) {
|
||||
return .{ .data = ident };
|
||||
}
|
||||
|
||||
pub fn fmtIdentUnsolo(ident: []const u8) std.fmt.Formatter([]const u8, formatIdentUnsolo) {
|
||||
return .{ .data = ident };
|
||||
}
|
||||
|
||||
const CTypePoolStringFormatData = struct {
|
||||
ctype_pool_string: CType.Pool.String,
|
||||
ctype_pool: *const CType.Pool,
|
||||
solo: bool,
|
||||
};
|
||||
fn formatCTypePoolString(
|
||||
data: CTypePoolStringFormatData,
|
||||
comptime fmt_str: []const u8,
|
||||
fmt_opts: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) @TypeOf(writer).Error!void {
|
||||
fn formatCTypePoolString(data: CTypePoolStringFormatData, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
if (data.ctype_pool_string.toSlice(data.ctype_pool)) |slice|
|
||||
try formatIdent(slice, fmt_str, fmt_opts, writer)
|
||||
try formatIdentOptions(slice, writer, data.solo)
|
||||
else
|
||||
try writer.print("{}", .{data.ctype_pool_string.fmt(data.ctype_pool)});
|
||||
}
|
||||
pub fn fmtCTypePoolString(
|
||||
ctype_pool_string: CType.Pool.String,
|
||||
ctype_pool: *const CType.Pool,
|
||||
) std.fmt.Formatter(formatCTypePoolString) {
|
||||
return .{ .data = .{ .ctype_pool_string = ctype_pool_string, .ctype_pool = ctype_pool } };
|
||||
solo: bool,
|
||||
) std.fmt.Formatter(CTypePoolStringFormatData, formatCTypePoolString) {
|
||||
return .{ .data = .{
|
||||
.ctype_pool_string = ctype_pool_string,
|
||||
.ctype_pool = ctype_pool,
|
||||
.solo = solo,
|
||||
} };
|
||||
}
|
||||
|
||||
// Returns true if `formatIdent` would make any edits to ident.
|
||||
@@ -596,7 +604,7 @@ pub const Function = struct {
|
||||
return f.object.dg.renderIntCast(w, dest_ty, .{ .c_value = .{ .f = f, .value = src, .v = v } }, src_ty, location);
|
||||
}
|
||||
|
||||
fn fmtIntLiteral(f: *Function, val: Value) !std.fmt.Formatter(formatIntLiteral) {
|
||||
fn fmtIntLiteral(f: *Function, val: Value) !std.fmt.Formatter(FormatIntLiteralContext, formatIntLiteral) {
|
||||
return f.object.dg.fmtIntLiteral(val, .Other);
|
||||
}
|
||||
|
||||
@@ -614,16 +622,16 @@ pub const Function = struct {
|
||||
gop.value_ptr.* = .{
|
||||
.fn_name = switch (key) {
|
||||
.tag_name,
|
||||
=> |enum_ty| try ctype_pool.fmt(gpa, "zig_{s}_{}__{d}", .{
|
||||
=> |enum_ty| try ctype_pool.fmt(gpa, "zig_{s}_{f}__{d}", .{
|
||||
@tagName(key),
|
||||
fmtIdent(ip.loadEnumType(enum_ty).name.toSlice(ip)),
|
||||
fmtIdentUnsolo(ip.loadEnumType(enum_ty).name.toSlice(ip)),
|
||||
@intFromEnum(enum_ty),
|
||||
}),
|
||||
.never_tail,
|
||||
.never_inline,
|
||||
=> |owner_nav| try ctype_pool.fmt(gpa, "zig_{s}_{}__{d}", .{
|
||||
@tagName(key),
|
||||
fmtIdent(ip.getNav(owner_nav).name.toSlice(ip)),
|
||||
fmtIdentUnsolo(ip.getNav(owner_nav).name.toSlice(ip)),
|
||||
@intFromEnum(owner_nav),
|
||||
}),
|
||||
},
|
||||
@@ -965,7 +973,7 @@ pub const DeclGen = struct {
|
||||
|
||||
fn renderErrorName(dg: *DeclGen, writer: anytype, err_name: InternPool.NullTerminatedString) !void {
|
||||
const ip = &dg.pt.zcu.intern_pool;
|
||||
try writer.print("zig_error_{}", .{fmtIdent(err_name.toSlice(ip))});
|
||||
try writer.print("zig_error_{}", .{fmtIdentUnsolo(err_name.toSlice(ip))});
|
||||
}
|
||||
|
||||
fn renderValue(
|
||||
@@ -1551,7 +1559,7 @@ pub const DeclGen = struct {
|
||||
.payload => {
|
||||
try writer.writeByte('{');
|
||||
if (field_ty.hasRuntimeBits(zcu)) {
|
||||
try writer.print(" .{ } = ", .{fmtIdent(field_name.toSlice(ip))});
|
||||
try writer.print(" .{ } = ", .{fmtIdentSolo(field_name.toSlice(ip))});
|
||||
try dg.renderValue(
|
||||
writer,
|
||||
Value.fromInterned(un.val),
|
||||
@@ -1888,7 +1896,7 @@ pub const DeclGen = struct {
|
||||
kind: CType.Kind,
|
||||
name: union(enum) {
|
||||
nav: InternPool.Nav.Index,
|
||||
fmt_ctype_pool_string: std.fmt.Formatter(formatCTypePoolString),
|
||||
fmt_ctype_pool_string: std.fmt.Formatter(CTypePoolStringFormatData, formatCTypePoolString),
|
||||
@"export": struct {
|
||||
main_name: InternPool.NullTerminatedString,
|
||||
extern_name: InternPool.NullTerminatedString,
|
||||
@@ -1933,7 +1941,7 @@ pub const DeclGen = struct {
|
||||
switch (name) {
|
||||
.nav => |nav| try dg.renderNavName(w, nav),
|
||||
.fmt_ctype_pool_string => |fmt| try w.print("{ }", .{fmt}),
|
||||
.@"export" => |@"export"| try w.print("{ }", .{fmtIdent(@"export".extern_name.toSlice(ip))}),
|
||||
.@"export" => |@"export"| try w.print("{ }", .{fmtIdentSolo(@"export".extern_name.toSlice(ip))}),
|
||||
}
|
||||
|
||||
try renderTypeSuffix(
|
||||
@@ -1961,13 +1969,13 @@ pub const DeclGen = struct {
|
||||
const is_export = @"export".extern_name != @"export".main_name;
|
||||
if (is_mangled and is_export) {
|
||||
try w.print(" zig_mangled_export({ }, {s}, {s})", .{
|
||||
fmtIdent(extern_name),
|
||||
fmtIdentSolo(extern_name),
|
||||
fmtStringLiteral(extern_name, null),
|
||||
fmtStringLiteral(@"export".main_name.toSlice(ip), null),
|
||||
});
|
||||
} else if (is_mangled) {
|
||||
try w.print(" zig_mangled({ }, {s})", .{
|
||||
fmtIdent(extern_name), fmtStringLiteral(extern_name, null),
|
||||
fmtIdentSolo(extern_name), fmtStringLiteral(extern_name, null),
|
||||
});
|
||||
} else if (is_export) {
|
||||
try w.print(" zig_export({s}, {s})", .{
|
||||
@@ -2198,7 +2206,7 @@ pub const DeclGen = struct {
|
||||
.new_local, .local => |i| try w.print("t{d}", .{i}),
|
||||
.constant => |uav| try renderUavName(w, uav),
|
||||
.nav => |nav| try dg.renderNavName(w, nav),
|
||||
.identifier => |ident| try w.print("{ }", .{fmtIdent(ident)}),
|
||||
.identifier => |ident| try w.print("{ }", .{fmtIdentSolo(ident)}),
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
@@ -2215,13 +2223,13 @@ pub const DeclGen = struct {
|
||||
try dg.renderNavName(w, nav);
|
||||
},
|
||||
.undef => |ty| try dg.renderUndefValue(w, ty, .Other),
|
||||
.identifier => |ident| try w.print("{ }", .{fmtIdent(ident)}),
|
||||
.identifier => |ident| try w.print("{ }", .{fmtIdentSolo(ident)}),
|
||||
.payload_identifier => |ident| try w.print("{ }.{ }", .{
|
||||
fmtIdent("payload"),
|
||||
fmtIdent(ident),
|
||||
fmtIdentSolo("payload"),
|
||||
fmtIdentSolo(ident),
|
||||
}),
|
||||
.ctype_pool_string => |string| try w.print("{ }", .{
|
||||
fmtCTypePoolString(string, &dg.ctype_pool),
|
||||
.ctype_pool_string => |string| try w.print("{f}", .{
|
||||
fmtCTypePoolString(string, &dg.ctype_pool, true),
|
||||
}),
|
||||
}
|
||||
}
|
||||
@@ -2245,10 +2253,10 @@ pub const DeclGen = struct {
|
||||
},
|
||||
.nav_ref => |nav| try dg.renderNavName(w, nav),
|
||||
.undef => unreachable,
|
||||
.identifier => |ident| try w.print("(*{ })", .{fmtIdent(ident)}),
|
||||
.identifier => |ident| try w.print("(*{ })", .{fmtIdentSolo(ident)}),
|
||||
.payload_identifier => |ident| try w.print("(*{ }.{ })", .{
|
||||
fmtIdent("payload"),
|
||||
fmtIdent(ident),
|
||||
fmtIdentSolo("payload"),
|
||||
fmtIdentSolo(ident),
|
||||
}),
|
||||
}
|
||||
}
|
||||
@@ -2334,14 +2342,14 @@ pub const DeclGen = struct {
|
||||
const nav = ip.getNav(nav_index);
|
||||
if (nav.getExtern(ip)) |@"extern"| {
|
||||
try writer.print("{ }", .{
|
||||
fmtIdent(ip.getNav(@"extern".owner_nav).name.toSlice(ip)),
|
||||
fmtIdentSolo(ip.getNav(@"extern".owner_nav).name.toSlice(ip)),
|
||||
});
|
||||
} else {
|
||||
// MSVC has a limit of 4095 character token length limit, and fmtIdent can (worst case),
|
||||
// expand to 3x the length of its input, but let's cut it off at a much shorter limit.
|
||||
const fqn_slice = ip.getNav(nav_index).fqn.toSlice(ip);
|
||||
try writer.print("{}__{d}", .{
|
||||
fmtIdent(fqn_slice[0..@min(fqn_slice.len, 100)]),
|
||||
fmtIdentUnsolo(fqn_slice[0..@min(fqn_slice.len, 100)]),
|
||||
@intFromEnum(nav_index),
|
||||
});
|
||||
}
|
||||
@@ -2452,7 +2460,7 @@ fn renderFwdDeclTypeName(
|
||||
switch (fwd_decl.name) {
|
||||
.anon => try w.print("anon__lazy_{d}", .{@intFromEnum(ctype.index)}),
|
||||
.index => |index| try w.print("{}__{d}", .{
|
||||
fmtIdent(Type.fromInterned(index).containerTypeName(ip).toSlice(&zcu.intern_pool)),
|
||||
fmtIdentUnsolo(Type.fromInterned(index).containerTypeName(ip).toSlice(&zcu.intern_pool)),
|
||||
@intFromEnum(index),
|
||||
}),
|
||||
}
|
||||
@@ -2666,7 +2674,7 @@ fn renderFields(
|
||||
.suffix,
|
||||
.{},
|
||||
);
|
||||
try writer.print("{}{ }", .{ trailing, fmtCTypePoolString(field_info.name, ctype_pool) });
|
||||
try writer.print("{}{f}", .{ trailing, fmtCTypePoolString(field_info.name, ctype_pool, true) });
|
||||
try renderTypeSuffix(.flush, ctype_pool, zcu, writer, field_info.ctype, .suffix, .{});
|
||||
try writer.writeAll(";\n");
|
||||
}
|
||||
@@ -2841,7 +2849,7 @@ pub fn genErrDecls(o: *Object) !void {
|
||||
const name = name_nts.toSlice(ip);
|
||||
if (val > 1) try writer.writeAll(", ");
|
||||
try writer.print("{{" ++ name_prefix ++ "{}, {}}}", .{
|
||||
fmtIdent(name),
|
||||
fmtIdentUnsolo(name),
|
||||
try o.dg.fmtIntLiteral(try pt.intValue(.usize, name.len), .StaticInitializer),
|
||||
});
|
||||
}
|
||||
@@ -2891,7 +2899,7 @@ pub fn genLazyFn(o: *Object, lazy_ctype_pool: *const CType.Pool, lazy_fn: LazyFn
|
||||
try w.writeAll(";\n return (");
|
||||
try o.dg.renderType(w, name_slice_ty);
|
||||
try w.print("){{{}, {}}};\n", .{
|
||||
fmtIdent("name"),
|
||||
fmtIdentUnsolo("name"),
|
||||
try o.dg.fmtIntLiteral(try pt.intValue(.usize, tag_name_len), .Other),
|
||||
});
|
||||
|
||||
@@ -3204,7 +3212,7 @@ pub fn genExports(dg: *DeclGen, exported: Zcu.Exported, export_indices: []const
|
||||
.uav => |uav| try DeclGen.renderUavName(fwd, Value.fromInterned(uav)),
|
||||
}
|
||||
try fwd.writeByte(' ');
|
||||
try fwd.print("{ }", .{fmtIdent(main_name.toSlice(ip))});
|
||||
try fwd.print("{ }", .{fmtIdentSolo(main_name.toSlice(ip))});
|
||||
try fwd.writeByte('\n');
|
||||
|
||||
const exported_val = exported.getValue(zcu);
|
||||
@@ -3250,13 +3258,13 @@ pub fn genExports(dg: *DeclGen, exported: Zcu.Exported, export_indices: []const
|
||||
);
|
||||
if (is_mangled and is_export) {
|
||||
try fwd.print(" zig_mangled_export({ }, {s}, {s})", .{
|
||||
fmtIdent(extern_name),
|
||||
fmtIdentSolo(extern_name),
|
||||
fmtStringLiteral(extern_name, null),
|
||||
fmtStringLiteral(main_name.toSlice(ip), null),
|
||||
});
|
||||
} else if (is_mangled) {
|
||||
try fwd.print(" zig_mangled({ }, {s})", .{
|
||||
fmtIdent(extern_name), fmtStringLiteral(extern_name, null),
|
||||
fmtIdentSolo(extern_name), fmtStringLiteral(extern_name, null),
|
||||
});
|
||||
} else if (is_export) {
|
||||
try fwd.print(" zig_export({s}, {s})", .{
|
||||
@@ -4538,7 +4546,7 @@ fn airCmpLtErrorsLen(f: *Function, inst: Air.Inst.Index) !CValue {
|
||||
try f.writeCValue(writer, local, .Other);
|
||||
try writer.writeAll(" = ");
|
||||
try f.writeCValue(writer, operand, .Other);
|
||||
try writer.print(" < sizeof({ }) / sizeof(*{0 });\n", .{fmtIdent("zig_errorName")});
|
||||
try writer.print(" < sizeof({ }) / sizeof(*{0 });\n", .{fmtIdentSolo("zig_errorName")});
|
||||
return local;
|
||||
}
|
||||
|
||||
@@ -8202,10 +8210,9 @@ fn stringLiteral(
|
||||
const FormatStringContext = struct { str: []const u8, sentinel: ?u8 };
|
||||
fn formatStringLiteral(
|
||||
data: FormatStringContext,
|
||||
comptime fmt: []const u8,
|
||||
_: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) @TypeOf(writer).Error!void {
|
||||
writer: *std.io.Writer,
|
||||
comptime fmt: []const u8, // TODO move this state to FormatStringContext
|
||||
) std.io.Writer.Error!void {
|
||||
if (fmt.len != 1 or fmt[0] != 's') @compileError("Invalid fmt: " ++ fmt);
|
||||
|
||||
var literal = stringLiteral(writer, data.str.len + @intFromBool(data.sentinel != null));
|
||||
@@ -8215,7 +8222,7 @@ fn formatStringLiteral(
|
||||
try literal.end();
|
||||
}
|
||||
|
||||
fn fmtStringLiteral(str: []const u8, sentinel: ?u8) std.fmt.Formatter(formatStringLiteral) {
|
||||
fn fmtStringLiteral(str: []const u8, sentinel: ?u8) std.fmt.Formatter(FormatStringContext, formatStringLiteral) {
|
||||
return .{ .data = .{ .str = str, .sentinel = sentinel } };
|
||||
}
|
||||
|
||||
@@ -8234,10 +8241,9 @@ const FormatIntLiteralContext = struct {
|
||||
};
|
||||
fn formatIntLiteral(
|
||||
data: FormatIntLiteralContext,
|
||||
comptime fmt: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) @TypeOf(writer).Error!void {
|
||||
writer: *std.io.Writer,
|
||||
comptime fmt: []const u8, // TODO move this state to FormatIntLiteralContext
|
||||
) std.io.Writer.Error!void {
|
||||
const pt = data.dg.pt;
|
||||
const zcu = pt.zcu;
|
||||
const target = &data.dg.mod.resolved_target.result;
|
||||
@@ -8406,7 +8412,7 @@ fn formatIntLiteral(
|
||||
.kind = data.kind,
|
||||
.ctype = c_limb_ctype,
|
||||
.val = try pt.intValue_big(.comptime_int, c_limb_mut.toConst()),
|
||||
}, fmt, options, writer);
|
||||
}, fmt, writer);
|
||||
}
|
||||
}
|
||||
try data.ctype.renderLiteralSuffix(writer, ctype_pool);
|
||||
|
||||
@@ -938,19 +938,13 @@ pub const Pool = struct {
|
||||
index: String.Index,
|
||||
|
||||
const FormatData = struct { string: String, pool: *const Pool };
|
||||
fn format(
|
||||
data: FormatData,
|
||||
comptime fmt_str: []const u8,
|
||||
_: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) @TypeOf(writer).Error!void {
|
||||
if (fmt_str.len > 0) @compileError("invalid format string '" ++ fmt_str ++ "'");
|
||||
fn format(data: FormatData, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
if (data.string.toSlice(data.pool)) |slice|
|
||||
try writer.writeAll(slice)
|
||||
else
|
||||
try writer.print("f{d}", .{@intFromEnum(data.string.index)});
|
||||
}
|
||||
pub fn fmt(str: String, pool: *const Pool) std.fmt.Formatter(format) {
|
||||
pub fn fmt(str: String, pool: *const Pool) std.fmt.Formatter(FormatData, format) {
|
||||
return .{ .data = .{ .string = str, .pool = pool } };
|
||||
}
|
||||
|
||||
|
||||
@@ -3061,40 +3061,25 @@ const ImportTable = struct {
|
||||
return base_vaddr + index * @sizeOf(u64);
|
||||
}
|
||||
|
||||
const FormatContext = struct {
|
||||
const Format = struct {
|
||||
itab: ImportTable,
|
||||
ctx: Context,
|
||||
|
||||
fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
const lib_name = f.ctx.coff.temp_strtab.getAssumeExists(f.ctx.name_off);
|
||||
const base_vaddr = getBaseAddress(f.ctx);
|
||||
try writer.print("IAT({s}.dll) @{x}:", .{ lib_name, base_vaddr });
|
||||
for (f.itab.entries.items, 0..) |entry, i| {
|
||||
try writer.print("\n {d}@{?x} => {s}", .{
|
||||
i,
|
||||
f.itab.getImportAddress(entry, f.ctx),
|
||||
f.ctx.coff.getSymbolName(entry),
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
fn format(itab: ImportTable, comptime unused_format_string: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
|
||||
_ = itab;
|
||||
_ = unused_format_string;
|
||||
_ = options;
|
||||
_ = writer;
|
||||
@compileError("do not format ImportTable directly; use itab.fmtDebug()");
|
||||
}
|
||||
|
||||
fn format2(
|
||||
fmt_ctx: FormatContext,
|
||||
comptime unused_format_string: []const u8,
|
||||
options: fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) @TypeOf(writer).Error!void {
|
||||
_ = options;
|
||||
comptime assert(unused_format_string.len == 0);
|
||||
const lib_name = fmt_ctx.ctx.coff.temp_strtab.getAssumeExists(fmt_ctx.ctx.name_off);
|
||||
const base_vaddr = getBaseAddress(fmt_ctx.ctx);
|
||||
try writer.print("IAT({s}.dll) @{x}:", .{ lib_name, base_vaddr });
|
||||
for (fmt_ctx.itab.entries.items, 0..) |entry, i| {
|
||||
try writer.print("\n {d}@{?x} => {s}", .{
|
||||
i,
|
||||
fmt_ctx.itab.getImportAddress(entry, fmt_ctx.ctx),
|
||||
fmt_ctx.ctx.coff.getSymbolName(entry),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn fmtDebug(itab: ImportTable, ctx: Context) fmt.Formatter(format2) {
|
||||
fn fmtDebug(itab: ImportTable, ctx: Context) fmt.Formatter(Format, Format.default) {
|
||||
return .{ .data = .{ .itab = itab, .ctx = ctx } };
|
||||
}
|
||||
|
||||
|
||||
@@ -3860,26 +3860,19 @@ pub fn failFile(
|
||||
return error.LinkFailure;
|
||||
}
|
||||
|
||||
const FormatShdrCtx = struct {
|
||||
const FormatShdr = struct {
|
||||
elf_file: *Elf,
|
||||
shdr: elf.Elf64_Shdr,
|
||||
};
|
||||
|
||||
fn fmtShdr(self: *Elf, shdr: elf.Elf64_Shdr) std.fmt.Formatter(formatShdr) {
|
||||
fn fmtShdr(self: *Elf, shdr: elf.Elf64_Shdr) std.fmt.Formatter(FormatShdr, formatShdr) {
|
||||
return .{ .data = .{
|
||||
.shdr = shdr,
|
||||
.elf_file = self,
|
||||
} };
|
||||
}
|
||||
|
||||
fn formatShdr(
|
||||
ctx: FormatShdrCtx,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = options;
|
||||
_ = unused_fmt_string;
|
||||
fn formatShdr(ctx: FormatShdr, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
const shdr = ctx.shdr;
|
||||
try writer.print("{s} : @{x} ({x}) : align({x}) : size({x}) : entsize({x}) : flags({})", .{
|
||||
ctx.elf_file.getShString(shdr.sh_name), shdr.sh_offset,
|
||||
@@ -3889,18 +3882,11 @@ fn formatShdr(
|
||||
});
|
||||
}
|
||||
|
||||
pub fn fmtShdrFlags(sh_flags: u64) std.fmt.Formatter(formatShdrFlags) {
|
||||
pub fn fmtShdrFlags(sh_flags: u64) std.fmt.Formatter(u64, formatShdrFlags) {
|
||||
return .{ .data = sh_flags };
|
||||
}
|
||||
|
||||
fn formatShdrFlags(
|
||||
sh_flags: u64,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
fn formatShdrFlags(sh_flags: u64, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
if (elf.SHF_WRITE & sh_flags != 0) {
|
||||
try writer.writeAll("W");
|
||||
}
|
||||
@@ -3945,26 +3931,19 @@ fn formatShdrFlags(
|
||||
}
|
||||
}
|
||||
|
||||
const FormatPhdrCtx = struct {
|
||||
const FormatPhdr = struct {
|
||||
elf_file: *Elf,
|
||||
phdr: elf.Elf64_Phdr,
|
||||
};
|
||||
|
||||
fn fmtPhdr(self: *Elf, phdr: elf.Elf64_Phdr) std.fmt.Formatter(formatPhdr) {
|
||||
fn fmtPhdr(self: *Elf, phdr: elf.Elf64_Phdr) std.fmt.Formatter(FormatPhdr, formatPhdr) {
|
||||
return .{ .data = .{
|
||||
.phdr = phdr,
|
||||
.elf_file = self,
|
||||
} };
|
||||
}
|
||||
|
||||
fn formatPhdr(
|
||||
ctx: FormatPhdrCtx,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = options;
|
||||
_ = unused_fmt_string;
|
||||
fn formatPhdr(ctx: FormatPhdr, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
const phdr = ctx.phdr;
|
||||
const write = phdr.p_flags & elf.PF_W != 0;
|
||||
const read = phdr.p_flags & elf.PF_R != 0;
|
||||
@@ -3991,19 +3970,11 @@ fn formatPhdr(
|
||||
});
|
||||
}
|
||||
|
||||
pub fn dumpState(self: *Elf) std.fmt.Formatter(fmtDumpState) {
|
||||
pub fn dumpState(self: *Elf) std.fmt.Formatter(*Elf, fmtDumpState) {
|
||||
return .{ .data = self };
|
||||
}
|
||||
|
||||
fn fmtDumpState(
|
||||
self: *Elf,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
|
||||
fn fmtDumpState(self: *Elf, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
const shared_objects = self.shared_objects.values();
|
||||
|
||||
if (self.zigObjectPtr()) |zig_object| {
|
||||
|
||||
@@ -214,35 +214,28 @@ pub const ArSymtab = struct {
|
||||
@compileError("do not format ar symtab directly; use fmt instead");
|
||||
}
|
||||
|
||||
const FormatContext = struct {
|
||||
const Format = struct {
|
||||
ar: ArSymtab,
|
||||
elf_file: *Elf,
|
||||
|
||||
fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
const ar = f.ar;
|
||||
const elf_file = f.elf_file;
|
||||
for (ar.symtab.items, 0..) |entry, i| {
|
||||
const name = ar.strtab.getAssumeExists(entry.off);
|
||||
const file = elf_file.file(entry.file_index).?;
|
||||
try writer.print(" {d}: {s} in file({d})({})\n", .{ i, name, entry.file_index, file.fmtPath() });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
pub fn fmt(ar: ArSymtab, elf_file: *Elf) std.fmt.Formatter(format2) {
|
||||
pub fn fmt(ar: ArSymtab, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
|
||||
return .{ .data = .{
|
||||
.ar = ar,
|
||||
.elf_file = elf_file,
|
||||
} };
|
||||
}
|
||||
|
||||
fn format2(
|
||||
ctx: FormatContext,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
const ar = ctx.ar;
|
||||
const elf_file = ctx.elf_file;
|
||||
for (ar.symtab.items, 0..) |entry, i| {
|
||||
const name = ar.strtab.getAssumeExists(entry.off);
|
||||
const file = elf_file.file(entry.file_index).?;
|
||||
try writer.print(" {d}: {s} in file({d})({})\n", .{ i, name, entry.file_index, file.fmtPath() });
|
||||
}
|
||||
}
|
||||
|
||||
const Entry = struct {
|
||||
/// Offset into the string table.
|
||||
off: u32,
|
||||
|
||||
@@ -904,65 +904,45 @@ pub fn setExtra(atom: Atom, extras: Extra, elf_file: *Elf) void {
|
||||
atom.file(elf_file).?.setAtomExtra(atom.extra_index, extras);
|
||||
}
|
||||
|
||||
pub fn format(
|
||||
atom: Atom,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = atom;
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
_ = writer;
|
||||
@compileError("do not format Atom directly");
|
||||
}
|
||||
|
||||
pub fn fmt(atom: Atom, elf_file: *Elf) std.fmt.Formatter(format2) {
|
||||
pub fn fmt(atom: Atom, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
|
||||
return .{ .data = .{
|
||||
.atom = atom,
|
||||
.elf_file = elf_file,
|
||||
} };
|
||||
}
|
||||
|
||||
const FormatContext = struct {
|
||||
const Format = struct {
|
||||
atom: Atom,
|
||||
elf_file: *Elf,
|
||||
};
|
||||
|
||||
fn format2(
|
||||
ctx: FormatContext,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = options;
|
||||
_ = unused_fmt_string;
|
||||
const atom = ctx.atom;
|
||||
const elf_file = ctx.elf_file;
|
||||
try writer.print("atom({d}) : {s} : @{x} : shdr({d}) : align({x}) : size({x}) : prev({}) : next({})", .{
|
||||
atom.atom_index, atom.name(elf_file), atom.address(elf_file),
|
||||
atom.output_section_index, atom.alignment.toByteUnits() orelse 0, atom.size,
|
||||
atom.prev_atom_ref, atom.next_atom_ref,
|
||||
});
|
||||
if (atom.file(elf_file)) |atom_file| switch (atom_file) {
|
||||
.object => |object| {
|
||||
if (atom.fdes(object).len > 0) {
|
||||
try writer.writeAll(" : fdes{ ");
|
||||
const extras = atom.extra(elf_file);
|
||||
for (atom.fdes(object), extras.fde_start..) |fde, i| {
|
||||
try writer.print("{d}", .{i});
|
||||
if (!fde.alive) try writer.writeAll("([*])");
|
||||
if (i - extras.fde_start < extras.fde_count - 1) try writer.writeAll(", ");
|
||||
fn default(f: Format, w: *std.io.Writer) std.io.Writer.Error!void {
|
||||
const atom = f.atom;
|
||||
const elf_file = f.elf_file;
|
||||
try w.print("atom({d}) : {s} : @{x} : shdr({d}) : align({x}) : size({x}) : prev({}) : next({})", .{
|
||||
atom.atom_index, atom.name(elf_file), atom.address(elf_file),
|
||||
atom.output_section_index, atom.alignment.toByteUnits() orelse 0, atom.size,
|
||||
atom.prev_atom_ref, atom.next_atom_ref,
|
||||
});
|
||||
if (atom.file(elf_file)) |atom_file| switch (atom_file) {
|
||||
.object => |object| {
|
||||
if (atom.fdes(object).len > 0) {
|
||||
try w.writeAll(" : fdes{ ");
|
||||
const extras = atom.extra(elf_file);
|
||||
for (atom.fdes(object), extras.fde_start..) |fde, i| {
|
||||
try w.print("{d}", .{i});
|
||||
if (!fde.alive) try w.writeAll("([*])");
|
||||
if (i - extras.fde_start < extras.fde_count - 1) try w.writeAll(", ");
|
||||
}
|
||||
try w.writeAll(" }");
|
||||
}
|
||||
try writer.writeAll(" }");
|
||||
}
|
||||
},
|
||||
else => {},
|
||||
};
|
||||
if (!atom.alive) {
|
||||
try writer.writeAll(" : [*]");
|
||||
},
|
||||
else => {},
|
||||
};
|
||||
if (!atom.alive) {
|
||||
try w.writeAll(" : [*]");
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
pub const Index = u32;
|
||||
|
||||
|
||||
@@ -167,44 +167,27 @@ pub fn lastAtom(list: AtomList, elf_file: *Elf) *Atom {
|
||||
return elf_file.atom(list.atoms.keys()[list.atoms.keys().len - 1]).?;
|
||||
}
|
||||
|
||||
pub fn format(
|
||||
list: AtomList,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = list;
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
_ = writer;
|
||||
@compileError("do not format AtomList directly");
|
||||
}
|
||||
const Format = struct {
|
||||
atom_list: AtomList,
|
||||
elf_file: *Elf,
|
||||
|
||||
const FormatCtx = struct { AtomList, *Elf };
|
||||
|
||||
pub fn fmt(list: AtomList, elf_file: *Elf) std.fmt.Formatter(format2) {
|
||||
return .{ .data = .{ list, elf_file } };
|
||||
}
|
||||
|
||||
fn format2(
|
||||
ctx: FormatCtx,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
const list, const elf_file = ctx;
|
||||
try writer.print("list : @{x} : shdr({d}) : align({x}) : size({x})", .{
|
||||
list.address(elf_file), list.output_section_index,
|
||||
list.alignment.toByteUnits() orelse 0, list.size,
|
||||
});
|
||||
try writer.writeAll(" : atoms{ ");
|
||||
for (list.atoms.keys(), 0..) |ref, i| {
|
||||
try writer.print("{}", .{ref});
|
||||
if (i < list.atoms.keys().len - 1) try writer.writeAll(", ");
|
||||
fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
const list, const elf_file = f;
|
||||
try writer.print("list : @{x} : shdr({d}) : align({x}) : size({x})", .{
|
||||
list.address(elf_file), list.output_section_index,
|
||||
list.alignment.toByteUnits() orelse 0, list.size,
|
||||
});
|
||||
try writer.writeAll(" : atoms{ ");
|
||||
for (list.atoms.keys(), 0..) |ref, i| {
|
||||
try writer.print("{}", .{ref});
|
||||
if (i < list.atoms.keys().len - 1) try writer.writeAll(", ");
|
||||
}
|
||||
try writer.writeAll(" }");
|
||||
}
|
||||
try writer.writeAll(" }");
|
||||
};
|
||||
|
||||
pub fn fmt(list: AtomList, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
|
||||
return .{ .data = .{ list, elf_file } };
|
||||
}
|
||||
|
||||
const assert = std.debug.assert;
|
||||
|
||||
@@ -437,38 +437,31 @@ pub fn setSymbolExtra(self: *LinkerDefined, index: u32, extra: Symbol.Extra) voi
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fmtSymtab(self: *LinkerDefined, elf_file: *Elf) std.fmt.Formatter(formatSymtab) {
|
||||
pub fn fmtSymtab(self: *LinkerDefined, elf_file: *Elf) std.fmt.Formatter(Format, Format.symtab) {
|
||||
return .{ .data = .{
|
||||
.self = self,
|
||||
.elf_file = elf_file,
|
||||
} };
|
||||
}
|
||||
|
||||
const FormatContext = struct {
|
||||
const Format = struct {
|
||||
self: *LinkerDefined,
|
||||
elf_file: *Elf,
|
||||
};
|
||||
|
||||
fn formatSymtab(
|
||||
ctx: FormatContext,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
const self = ctx.self;
|
||||
const elf_file = ctx.elf_file;
|
||||
try writer.writeAll(" globals\n");
|
||||
for (self.symbols.items, 0..) |sym, i| {
|
||||
const ref = self.resolveSymbol(@intCast(i), elf_file);
|
||||
if (elf_file.symbol(ref)) |ref_sym| {
|
||||
try writer.print(" {}\n", .{ref_sym.fmt(elf_file)});
|
||||
} else {
|
||||
try writer.print(" {s} : unclaimed\n", .{sym.name(elf_file)});
|
||||
fn symtab(ctx: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
const self = ctx.self;
|
||||
const elf_file = ctx.elf_file;
|
||||
try writer.writeAll(" globals\n");
|
||||
for (self.symbols.items, 0..) |sym, i| {
|
||||
const ref = self.resolveSymbol(@intCast(i), elf_file);
|
||||
if (elf_file.symbol(ref)) |ref_sym| {
|
||||
try writer.print(" {f}\n", .{ref_sym.fmt(elf_file)});
|
||||
} else {
|
||||
try writer.print(" {s} : unclaimed\n", .{sym.name(elf_file)});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const assert = std.debug.assert;
|
||||
const elf = std.elf;
|
||||
|
||||
@@ -157,54 +157,34 @@ pub const Section = struct {
|
||||
}
|
||||
};
|
||||
|
||||
pub fn format(
|
||||
msec: Section,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = msec;
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
_ = writer;
|
||||
@compileError("do not format directly");
|
||||
}
|
||||
|
||||
pub fn fmt(msec: Section, elf_file: *Elf) std.fmt.Formatter(format2) {
|
||||
pub fn fmt(msec: Section, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
|
||||
return .{ .data = .{
|
||||
.msec = msec,
|
||||
.elf_file = elf_file,
|
||||
} };
|
||||
}
|
||||
|
||||
const FormatContext = struct {
|
||||
const Format = struct {
|
||||
msec: Section,
|
||||
elf_file: *Elf,
|
||||
};
|
||||
|
||||
pub fn format2(
|
||||
ctx: FormatContext,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = options;
|
||||
_ = unused_fmt_string;
|
||||
const msec = ctx.msec;
|
||||
const elf_file = ctx.elf_file;
|
||||
try writer.print("{s} : @{x} : size({x}) : align({x}) : entsize({x}) : type({x}) : flags({x})\n", .{
|
||||
msec.name(elf_file),
|
||||
msec.address(elf_file),
|
||||
msec.size,
|
||||
msec.alignment.toByteUnits() orelse 0,
|
||||
msec.entsize,
|
||||
msec.type,
|
||||
msec.flags,
|
||||
});
|
||||
for (msec.subsections.items) |msub| {
|
||||
try writer.print(" {}\n", .{msub.fmt(elf_file)});
|
||||
pub fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
const msec = f.msec;
|
||||
const elf_file = f.elf_file;
|
||||
try writer.print("{s} : @{x} : size({x}) : align({x}) : entsize({x}) : type({x}) : flags({x})\n", .{
|
||||
msec.name(elf_file),
|
||||
msec.address(elf_file),
|
||||
msec.size,
|
||||
msec.alignment.toByteUnits() orelse 0,
|
||||
msec.entsize,
|
||||
msec.type,
|
||||
msec.flags,
|
||||
});
|
||||
for (msec.subsections.items) |msub| {
|
||||
try writer.print(" {f}\n", .{msub.fmt(elf_file)});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
pub const Index = u32;
|
||||
};
|
||||
@@ -231,48 +211,28 @@ pub const Subsection = struct {
|
||||
return msec.bytes.items[msub.string_index..][0..msub.size];
|
||||
}
|
||||
|
||||
pub fn format(
|
||||
msub: Subsection,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = msub;
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
_ = writer;
|
||||
@compileError("do not format directly");
|
||||
}
|
||||
|
||||
pub fn fmt(msub: Subsection, elf_file: *Elf) std.fmt.Formatter(format2) {
|
||||
pub fn fmt(msub: Subsection, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
|
||||
return .{ .data = .{
|
||||
.msub = msub,
|
||||
.elf_file = elf_file,
|
||||
} };
|
||||
}
|
||||
|
||||
const FormatContext = struct {
|
||||
const Format = struct {
|
||||
msub: Subsection,
|
||||
elf_file: *Elf,
|
||||
};
|
||||
|
||||
pub fn format2(
|
||||
ctx: FormatContext,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = options;
|
||||
_ = unused_fmt_string;
|
||||
const msub = ctx.msub;
|
||||
const elf_file = ctx.elf_file;
|
||||
try writer.print("@{x} : align({x}) : size({x})", .{
|
||||
msub.address(elf_file),
|
||||
msub.alignment,
|
||||
msub.size,
|
||||
});
|
||||
if (!msub.alive) try writer.writeAll(" : [*]");
|
||||
}
|
||||
pub fn default(ctx: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
const msub = ctx.msub;
|
||||
const elf_file = ctx.elf_file;
|
||||
try writer.print("@{x} : align({x}) : size({x})", .{
|
||||
msub.address(elf_file),
|
||||
msub.alignment,
|
||||
msub.size,
|
||||
});
|
||||
if (!msub.alive) try writer.writeAll(" : [*]");
|
||||
}
|
||||
};
|
||||
|
||||
pub const Index = u32;
|
||||
};
|
||||
|
||||
@@ -1432,167 +1432,112 @@ pub fn group(self: *Object, index: Elf.Group.Index) *Elf.Group {
|
||||
return &self.groups.items[index];
|
||||
}
|
||||
|
||||
pub fn format(
|
||||
self: *Object,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = self;
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
_ = writer;
|
||||
@compileError("do not format objects directly");
|
||||
}
|
||||
|
||||
pub fn fmtSymtab(self: *Object, elf_file: *Elf) std.fmt.Formatter(formatSymtab) {
|
||||
pub fn fmtSymtab(self: *Object, elf_file: *Elf) std.fmt.Formatter(Format, Format.symtab) {
|
||||
return .{ .data = .{
|
||||
.object = self,
|
||||
.elf_file = elf_file,
|
||||
} };
|
||||
}
|
||||
|
||||
const FormatContext = struct {
|
||||
const Format = struct {
|
||||
object: *Object,
|
||||
elf_file: *Elf,
|
||||
|
||||
fn symtab(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
const object = f.object;
|
||||
const elf_file = f.elf_file;
|
||||
try writer.writeAll(" locals\n");
|
||||
for (object.locals()) |sym| {
|
||||
try writer.print(" {}\n", .{sym.fmt(elf_file)});
|
||||
}
|
||||
try writer.writeAll(" globals\n");
|
||||
for (object.globals(), 0..) |sym, i| {
|
||||
const first_global = object.first_global.?;
|
||||
const ref = object.resolveSymbol(@intCast(i + first_global), elf_file);
|
||||
if (elf_file.symbol(ref)) |ref_sym| {
|
||||
try writer.print(" {}\n", .{ref_sym.fmt(elf_file)});
|
||||
} else {
|
||||
try writer.print(" {s} : unclaimed\n", .{sym.name(elf_file)});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn atoms(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
const object = f.object;
|
||||
try writer.writeAll(" atoms\n");
|
||||
for (object.atoms_indexes.items) |atom_index| {
|
||||
const atom_ptr = object.atom(atom_index) orelse continue;
|
||||
try writer.print(" {}\n", .{atom_ptr.fmt(f.elf_file)});
|
||||
}
|
||||
}
|
||||
|
||||
fn cies(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
const object = f.object;
|
||||
try writer.writeAll(" cies\n");
|
||||
for (object.cies.items, 0..) |cie, i| {
|
||||
try writer.print(" cie({d}) : {}\n", .{ i, cie.fmt(f.elf_file) });
|
||||
}
|
||||
}
|
||||
|
||||
fn fdes(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
const object = f.object;
|
||||
try writer.writeAll(" fdes\n");
|
||||
for (object.fdes.items, 0..) |fde, i| {
|
||||
try writer.print(" fde({d}) : {}\n", .{ i, fde.fmt(f.elf_file) });
|
||||
}
|
||||
}
|
||||
|
||||
fn groups(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
const object = f.object;
|
||||
const elf_file = f.elf_file;
|
||||
try writer.writeAll(" groups\n");
|
||||
for (object.groups.items, 0..) |g, g_index| {
|
||||
try writer.print(" {s}({d})", .{ if (g.is_comdat) "COMDAT" else "GROUP", g_index });
|
||||
if (!g.alive) try writer.writeAll(" : [*]");
|
||||
try writer.writeByte('\n');
|
||||
const g_members = g.members(elf_file);
|
||||
for (g_members) |shndx| {
|
||||
const atom_index = object.atoms_indexes.items[shndx];
|
||||
const atom_ptr = object.atom(atom_index) orelse continue;
|
||||
try writer.print(" atom({d}) : {s}\n", .{ atom_index, atom_ptr.name(elf_file) });
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
fn formatSymtab(
|
||||
ctx: FormatContext,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
const object = ctx.object;
|
||||
const elf_file = ctx.elf_file;
|
||||
try writer.writeAll(" locals\n");
|
||||
for (object.locals()) |sym| {
|
||||
try writer.print(" {}\n", .{sym.fmt(elf_file)});
|
||||
}
|
||||
try writer.writeAll(" globals\n");
|
||||
for (object.globals(), 0..) |sym, i| {
|
||||
const first_global = object.first_global.?;
|
||||
const ref = object.resolveSymbol(@intCast(i + first_global), elf_file);
|
||||
if (elf_file.symbol(ref)) |ref_sym| {
|
||||
try writer.print(" {}\n", .{ref_sym.fmt(elf_file)});
|
||||
} else {
|
||||
try writer.print(" {s} : unclaimed\n", .{sym.name(elf_file)});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fmtAtoms(self: *Object, elf_file: *Elf) std.fmt.Formatter(formatAtoms) {
|
||||
pub fn fmtAtoms(self: *Object, elf_file: *Elf) std.fmt.Formatter(Format, Format.atoms) {
|
||||
return .{ .data = .{
|
||||
.object = self,
|
||||
.elf_file = elf_file,
|
||||
} };
|
||||
}
|
||||
|
||||
fn formatAtoms(
|
||||
ctx: FormatContext,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
const object = ctx.object;
|
||||
try writer.writeAll(" atoms\n");
|
||||
for (object.atoms_indexes.items) |atom_index| {
|
||||
const atom_ptr = object.atom(atom_index) orelse continue;
|
||||
try writer.print(" {}\n", .{atom_ptr.fmt(ctx.elf_file)});
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fmtCies(self: *Object, elf_file: *Elf) std.fmt.Formatter(formatCies) {
|
||||
pub fn fmtCies(self: *Object, elf_file: *Elf) std.fmt.Formatter(Format, Format.cies) {
|
||||
return .{ .data = .{
|
||||
.object = self,
|
||||
.elf_file = elf_file,
|
||||
} };
|
||||
}
|
||||
|
||||
fn formatCies(
|
||||
ctx: FormatContext,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
const object = ctx.object;
|
||||
try writer.writeAll(" cies\n");
|
||||
for (object.cies.items, 0..) |cie, i| {
|
||||
try writer.print(" cie({d}) : {}\n", .{ i, cie.fmt(ctx.elf_file) });
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fmtFdes(self: *Object, elf_file: *Elf) std.fmt.Formatter(formatFdes) {
|
||||
pub fn fmtFdes(self: *Object, elf_file: *Elf) std.fmt.Formatter(Format, Format.fdes) {
|
||||
return .{ .data = .{
|
||||
.object = self,
|
||||
.elf_file = elf_file,
|
||||
} };
|
||||
}
|
||||
|
||||
fn formatFdes(
|
||||
ctx: FormatContext,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
const object = ctx.object;
|
||||
try writer.writeAll(" fdes\n");
|
||||
for (object.fdes.items, 0..) |fde, i| {
|
||||
try writer.print(" fde({d}) : {}\n", .{ i, fde.fmt(ctx.elf_file) });
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fmtGroups(self: *Object, elf_file: *Elf) std.fmt.Formatter(formatGroups) {
|
||||
pub fn fmtGroups(self: *Object, elf_file: *Elf) std.fmt.Formatter(Format, Format.groups) {
|
||||
return .{ .data = .{
|
||||
.object = self,
|
||||
.elf_file = elf_file,
|
||||
} };
|
||||
}
|
||||
|
||||
fn formatGroups(
|
||||
ctx: FormatContext,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
const object = ctx.object;
|
||||
const elf_file = ctx.elf_file;
|
||||
try writer.writeAll(" groups\n");
|
||||
for (object.groups.items, 0..) |g, g_index| {
|
||||
try writer.print(" {s}({d})", .{ if (g.is_comdat) "COMDAT" else "GROUP", g_index });
|
||||
if (!g.alive) try writer.writeAll(" : [*]");
|
||||
try writer.writeByte('\n');
|
||||
const g_members = g.members(elf_file);
|
||||
for (g_members) |shndx| {
|
||||
const atom_index = object.atoms_indexes.items[shndx];
|
||||
const atom_ptr = object.atom(atom_index) orelse continue;
|
||||
try writer.print(" atom({d}) : {s}\n", .{ atom_index, atom_ptr.name(elf_file) });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fmtPath(self: Object) std.fmt.Formatter(formatPath) {
|
||||
pub fn fmtPath(self: Object) std.fmt.Formatter(Object, formatPath) {
|
||||
return .{ .data = self };
|
||||
}
|
||||
|
||||
fn formatPath(
|
||||
object: Object,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
fn formatPath(object: Object, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
if (object.archive) |ar| {
|
||||
try writer.print("{}({})", .{ ar.path, object.path });
|
||||
} else {
|
||||
|
||||
@@ -509,41 +509,21 @@ pub fn setSymbolExtra(self: *SharedObject, index: u32, extra: Symbol.Extra) void
|
||||
}
|
||||
}
|
||||
|
||||
pub fn format(
|
||||
self: SharedObject,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = self;
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
_ = writer;
|
||||
@compileError("unreachable");
|
||||
}
|
||||
|
||||
pub fn fmtSymtab(self: SharedObject, elf_file: *Elf) std.fmt.Formatter(formatSymtab) {
|
||||
pub fn fmtSymtab(self: SharedObject, elf_file: *Elf) std.fmt.Formatter(Format, Format.symtab) {
|
||||
return .{ .data = .{
|
||||
.shared = self,
|
||||
.elf_file = elf_file,
|
||||
} };
|
||||
}
|
||||
|
||||
const FormatContext = struct {
|
||||
const Format = struct {
|
||||
shared: SharedObject,
|
||||
elf_file: *Elf,
|
||||
};
|
||||
|
||||
fn formatSymtab(
|
||||
ctx: FormatContext,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
const shared = ctx.shared;
|
||||
const elf_file = ctx.elf_file;
|
||||
fn formatSymtab(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
const shared = f.shared;
|
||||
const elf_file = f.elf_file;
|
||||
try writer.writeAll(" globals\n");
|
||||
for (shared.symbols.items, 0..) |sym, i| {
|
||||
const ref = shared.resolveSymbol(@intCast(i), elf_file);
|
||||
|
||||
@@ -316,99 +316,72 @@ pub fn setOutputSym(symbol: Symbol, elf_file: *Elf, out: *elf.Elf64_Sym) void {
|
||||
out.st_size = esym.st_size;
|
||||
}
|
||||
|
||||
pub fn format(
|
||||
symbol: Symbol,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = symbol;
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
_ = writer;
|
||||
@compileError("do not format Symbol directly");
|
||||
}
|
||||
|
||||
const FormatContext = struct {
|
||||
const Format = struct {
|
||||
symbol: Symbol,
|
||||
elf_file: *Elf,
|
||||
|
||||
fn name(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
const elf_file = f.elf_file;
|
||||
const symbol = f.symbol;
|
||||
try writer.writeAll(symbol.name(elf_file));
|
||||
switch (symbol.version_index.VERSION) {
|
||||
@intFromEnum(elf.VER_NDX.LOCAL), @intFromEnum(elf.VER_NDX.GLOBAL) => {},
|
||||
else => {
|
||||
const file_ptr = symbol.file(elf_file).?;
|
||||
assert(file_ptr == .shared_object);
|
||||
const shared_object = file_ptr.shared_object;
|
||||
try writer.print("@{s}", .{shared_object.versionString(symbol.version_index)});
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
const symbol = f.symbol;
|
||||
const elf_file = f.elf_file;
|
||||
try writer.print("%{d} : {s} : @{x}", .{
|
||||
symbol.esym_index,
|
||||
symbol.fmtName(elf_file),
|
||||
symbol.address(.{ .plt = false, .trampoline = false }, elf_file),
|
||||
});
|
||||
if (symbol.file(elf_file)) |file_ptr| {
|
||||
if (symbol.isAbs(elf_file)) {
|
||||
if (symbol.elfSym(elf_file).st_shndx == elf.SHN_UNDEF) {
|
||||
try writer.writeAll(" : undef");
|
||||
} else {
|
||||
try writer.writeAll(" : absolute");
|
||||
}
|
||||
} else if (symbol.outputShndx(elf_file)) |shndx| {
|
||||
try writer.print(" : shdr({d})", .{shndx});
|
||||
}
|
||||
if (symbol.atom(elf_file)) |atom_ptr| {
|
||||
try writer.print(" : atom({d})", .{atom_ptr.atom_index});
|
||||
}
|
||||
var buf: [2]u8 = .{'_'} ** 2;
|
||||
if (symbol.flags.@"export") buf[0] = 'E';
|
||||
if (symbol.flags.import) buf[1] = 'I';
|
||||
try writer.print(" : {s}", .{&buf});
|
||||
if (symbol.flags.weak) try writer.writeAll(" : weak");
|
||||
switch (file_ptr) {
|
||||
inline else => |x| try writer.print(" : {s}({d})", .{ @tagName(file_ptr), x.index }),
|
||||
}
|
||||
} else try writer.writeAll(" : unresolved");
|
||||
}
|
||||
};
|
||||
|
||||
pub fn fmtName(symbol: Symbol, elf_file: *Elf) std.fmt.Formatter(formatName) {
|
||||
pub fn fmtName(symbol: Symbol, elf_file: *Elf) std.fmt.Formatter(Format, Format.name) {
|
||||
return .{ .data = .{
|
||||
.symbol = symbol,
|
||||
.elf_file = elf_file,
|
||||
} };
|
||||
}
|
||||
|
||||
fn formatName(
|
||||
ctx: FormatContext,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = options;
|
||||
_ = unused_fmt_string;
|
||||
const elf_file = ctx.elf_file;
|
||||
const symbol = ctx.symbol;
|
||||
try writer.writeAll(symbol.name(elf_file));
|
||||
switch (symbol.version_index.VERSION) {
|
||||
@intFromEnum(elf.VER_NDX.LOCAL), @intFromEnum(elf.VER_NDX.GLOBAL) => {},
|
||||
else => {
|
||||
const file_ptr = symbol.file(elf_file).?;
|
||||
assert(file_ptr == .shared_object);
|
||||
const shared_object = file_ptr.shared_object;
|
||||
try writer.print("@{s}", .{shared_object.versionString(symbol.version_index)});
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fmt(symbol: Symbol, elf_file: *Elf) std.fmt.Formatter(format2) {
|
||||
pub fn fmt(symbol: Symbol, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
|
||||
return .{ .data = .{
|
||||
.symbol = symbol,
|
||||
.elf_file = elf_file,
|
||||
} };
|
||||
}
|
||||
|
||||
fn format2(
|
||||
ctx: FormatContext,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = options;
|
||||
_ = unused_fmt_string;
|
||||
const symbol = ctx.symbol;
|
||||
const elf_file = ctx.elf_file;
|
||||
try writer.print("%{d} : {s} : @{x}", .{
|
||||
symbol.esym_index,
|
||||
symbol.fmtName(elf_file),
|
||||
symbol.address(.{ .plt = false, .trampoline = false }, elf_file),
|
||||
});
|
||||
if (symbol.file(elf_file)) |file_ptr| {
|
||||
if (symbol.isAbs(elf_file)) {
|
||||
if (symbol.elfSym(elf_file).st_shndx == elf.SHN_UNDEF) {
|
||||
try writer.writeAll(" : undef");
|
||||
} else {
|
||||
try writer.writeAll(" : absolute");
|
||||
}
|
||||
} else if (symbol.outputShndx(elf_file)) |shndx| {
|
||||
try writer.print(" : shdr({d})", .{shndx});
|
||||
}
|
||||
if (symbol.atom(elf_file)) |atom_ptr| {
|
||||
try writer.print(" : atom({d})", .{atom_ptr.atom_index});
|
||||
}
|
||||
var buf: [2]u8 = .{'_'} ** 2;
|
||||
if (symbol.flags.@"export") buf[0] = 'E';
|
||||
if (symbol.flags.import) buf[1] = 'I';
|
||||
try writer.print(" : {s}", .{&buf});
|
||||
if (symbol.flags.weak) try writer.writeAll(" : weak");
|
||||
switch (file_ptr) {
|
||||
inline else => |x| try writer.print(" : {s}({d})", .{ @tagName(file_ptr), x.index }),
|
||||
}
|
||||
} else try writer.writeAll(" : unresolved");
|
||||
}
|
||||
|
||||
pub const Flags = packed struct {
|
||||
/// Whether the symbol is imported at runtime.
|
||||
import: bool = false,
|
||||
|
||||
@@ -65,47 +65,27 @@ fn trampolineSize(cpu_arch: std.Target.Cpu.Arch) usize {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn format(
|
||||
thunk: Thunk,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = thunk;
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
_ = writer;
|
||||
@compileError("do not format Thunk directly");
|
||||
}
|
||||
|
||||
pub fn fmt(thunk: Thunk, elf_file: *Elf) std.fmt.Formatter(format2) {
|
||||
pub fn fmt(thunk: Thunk, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
|
||||
return .{ .data = .{
|
||||
.thunk = thunk,
|
||||
.elf_file = elf_file,
|
||||
} };
|
||||
}
|
||||
|
||||
const FormatContext = struct {
|
||||
const Format = struct {
|
||||
thunk: Thunk,
|
||||
elf_file: *Elf,
|
||||
};
|
||||
|
||||
fn format2(
|
||||
ctx: FormatContext,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = options;
|
||||
_ = unused_fmt_string;
|
||||
const thunk = ctx.thunk;
|
||||
const elf_file = ctx.elf_file;
|
||||
try writer.print("@{x} : size({x})\n", .{ thunk.value, thunk.size(elf_file) });
|
||||
for (thunk.symbols.keys()) |ref| {
|
||||
const sym = elf_file.symbol(ref).?;
|
||||
try writer.print(" {} : {s} : @{x}\n", .{ ref, sym.name(elf_file), sym.value });
|
||||
fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
const thunk = f.thunk;
|
||||
const elf_file = f.elf_file;
|
||||
try writer.print("@{x} : size({x})\n", .{ thunk.value, thunk.size(elf_file) });
|
||||
for (thunk.symbols.keys()) |ref| {
|
||||
const sym = elf_file.symbol(ref).?;
|
||||
try writer.print(" {} : {s} : @{x}\n", .{ ref, sym.name(elf_file), sym.value });
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
pub const Index = u32;
|
||||
|
||||
|
||||
@@ -2195,60 +2195,46 @@ pub fn setSymbolExtra(self: *ZigObject, index: u32, extra: Symbol.Extra) void {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fmtSymtab(self: *ZigObject, elf_file: *Elf) std.fmt.Formatter(formatSymtab) {
|
||||
return .{ .data = .{
|
||||
.self = self,
|
||||
.elf_file = elf_file,
|
||||
} };
|
||||
}
|
||||
|
||||
const FormatContext = struct {
|
||||
const Format = struct {
|
||||
self: *ZigObject,
|
||||
elf_file: *Elf,
|
||||
|
||||
fn symtab(f: Format, writer: *std.io.Writer.Error) std.io.Writer.Error!void {
|
||||
const self = f.self;
|
||||
const elf_file = f.elf_file;
|
||||
try writer.writeAll(" locals\n");
|
||||
for (self.local_symbols.items) |index| {
|
||||
const local = self.symbols.items[index];
|
||||
try writer.print(" {f}\n", .{local.fmt(elf_file)});
|
||||
}
|
||||
try writer.writeAll(" globals\n");
|
||||
for (f.self.global_symbols.items) |index| {
|
||||
const global = self.symbols.items[index];
|
||||
try writer.print(" {f}\n", .{global.fmt(elf_file)});
|
||||
}
|
||||
}
|
||||
|
||||
fn atoms(f: Format, writer: *std.io.Writer.Error) std.io.Writer.Error!void {
|
||||
try writer.writeAll(" atoms\n");
|
||||
for (f.self.atoms_indexes.items) |atom_index| {
|
||||
const atom_ptr = f.self.atom(atom_index) orelse continue;
|
||||
try writer.print(" {f}\n", .{atom_ptr.fmt(f.elf_file)});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
fn formatSymtab(
|
||||
ctx: FormatContext,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
const self = ctx.self;
|
||||
const elf_file = ctx.elf_file;
|
||||
try writer.writeAll(" locals\n");
|
||||
for (self.local_symbols.items) |index| {
|
||||
const local = self.symbols.items[index];
|
||||
try writer.print(" {}\n", .{local.fmt(elf_file)});
|
||||
}
|
||||
try writer.writeAll(" globals\n");
|
||||
for (ctx.self.global_symbols.items) |index| {
|
||||
const global = self.symbols.items[index];
|
||||
try writer.print(" {}\n", .{global.fmt(elf_file)});
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fmtAtoms(self: *ZigObject, elf_file: *Elf) std.fmt.Formatter(formatAtoms) {
|
||||
pub fn fmtSymtab(self: *ZigObject, elf_file: *Elf) std.fmt.Formatter(Format, Format.symtab) {
|
||||
return .{ .data = .{
|
||||
.self = self,
|
||||
.elf_file = elf_file,
|
||||
} };
|
||||
}
|
||||
|
||||
fn formatAtoms(
|
||||
ctx: FormatContext,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
try writer.writeAll(" atoms\n");
|
||||
for (ctx.self.atoms_indexes.items) |atom_index| {
|
||||
const atom_ptr = ctx.self.atom(atom_index) orelse continue;
|
||||
try writer.print(" {}\n", .{atom_ptr.fmt(ctx.elf_file)});
|
||||
}
|
||||
pub fn fmtAtoms(self: *ZigObject, elf_file: *Elf) std.fmt.Formatter(Format, Format.atoms) {
|
||||
return .{ .data = .{
|
||||
.self = self,
|
||||
.elf_file = elf_file,
|
||||
} };
|
||||
}
|
||||
|
||||
const ElfSym = struct {
|
||||
|
||||
@@ -47,52 +47,32 @@ pub const Fde = struct {
|
||||
return object.relocs.items[fde.rel_index..][0..fde.rel_num];
|
||||
}
|
||||
|
||||
pub fn format(
|
||||
fde: Fde,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = fde;
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
_ = writer;
|
||||
@compileError("do not format FDEs directly");
|
||||
}
|
||||
|
||||
pub fn fmt(fde: Fde, elf_file: *Elf) std.fmt.Formatter(format2) {
|
||||
pub fn fmt(fde: Fde, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
|
||||
return .{ .data = .{
|
||||
.fde = fde,
|
||||
.elf_file = elf_file,
|
||||
} };
|
||||
}
|
||||
|
||||
const FdeFormatContext = struct {
|
||||
const Format = struct {
|
||||
fde: Fde,
|
||||
elf_file: *Elf,
|
||||
};
|
||||
|
||||
fn format2(
|
||||
ctx: FdeFormatContext,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
const fde = ctx.fde;
|
||||
const elf_file = ctx.elf_file;
|
||||
const base_addr = fde.address(elf_file);
|
||||
const object = elf_file.file(fde.file_index).?.object;
|
||||
const atom_name = fde.atom(object).name(elf_file);
|
||||
try writer.print("@{x} : size({x}) : cie({d}) : {s}", .{
|
||||
base_addr + fde.out_offset,
|
||||
fde.calcSize(),
|
||||
fde.cie_index,
|
||||
atom_name,
|
||||
});
|
||||
if (!fde.alive) try writer.writeAll(" : [*]");
|
||||
}
|
||||
fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
const fde = f.fde;
|
||||
const elf_file = f.elf_file;
|
||||
const base_addr = fde.address(elf_file);
|
||||
const object = elf_file.file(fde.file_index).?.object;
|
||||
const atom_name = fde.atom(object).name(elf_file);
|
||||
try writer.print("@{x} : size({x}) : cie({d}) : {s}", .{
|
||||
base_addr + fde.out_offset,
|
||||
fde.calcSize(),
|
||||
fde.cie_index,
|
||||
atom_name,
|
||||
});
|
||||
if (!fde.alive) try writer.writeAll(" : [*]");
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
pub const Cie = struct {
|
||||
@@ -150,48 +130,28 @@ pub const Cie = struct {
|
||||
return true;
|
||||
}
|
||||
|
||||
pub fn format(
|
||||
cie: Cie,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = cie;
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
_ = writer;
|
||||
@compileError("do not format CIEs directly");
|
||||
}
|
||||
|
||||
pub fn fmt(cie: Cie, elf_file: *Elf) std.fmt.Formatter(format2) {
|
||||
pub fn fmt(cie: Cie, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
|
||||
return .{ .data = .{
|
||||
.cie = cie,
|
||||
.elf_file = elf_file,
|
||||
} };
|
||||
}
|
||||
|
||||
const CieFormatContext = struct {
|
||||
const Format = struct {
|
||||
cie: Cie,
|
||||
elf_file: *Elf,
|
||||
};
|
||||
|
||||
fn format2(
|
||||
ctx: CieFormatContext,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
const cie = ctx.cie;
|
||||
const elf_file = ctx.elf_file;
|
||||
const base_addr = cie.address(elf_file);
|
||||
try writer.print("@{x} : size({x})", .{
|
||||
base_addr + cie.out_offset,
|
||||
cie.calcSize(),
|
||||
});
|
||||
if (!cie.alive) try writer.writeAll(" : [*]");
|
||||
}
|
||||
fn format2(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
const cie = f.cie;
|
||||
const elf_file = f.elf_file;
|
||||
const base_addr = cie.address(elf_file);
|
||||
try writer.print("@{x} : size({x})", .{
|
||||
base_addr + cie.out_offset,
|
||||
cie.calcSize(),
|
||||
});
|
||||
if (!cie.alive) try writer.writeAll(" : [*]");
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
pub const Iterator = struct {
|
||||
|
||||
@@ -10,23 +10,16 @@ pub const File = union(enum) {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn fmtPath(file: File) std.fmt.Formatter(formatPath) {
|
||||
pub fn fmtPath(file: File) std.fmt.Formatter(File, formatPath) {
|
||||
return .{ .data = file };
|
||||
}
|
||||
|
||||
fn formatPath(
|
||||
file: File,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
fn formatPath(file: File, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
switch (file) {
|
||||
.zig_object => |zo| try writer.writeAll(zo.basename),
|
||||
.linker_defined => try writer.writeAll("(linker defined)"),
|
||||
.object => |x| try writer.print("{}", .{x.fmtPath()}),
|
||||
.shared_object => |x| try writer.print("{}", .{@as(Path, x.path)}),
|
||||
.object => |x| try writer.print("{f}", .{x.fmtPath()}),
|
||||
.shared_object => |x| try writer.print("{f}", .{@as(Path, x.path)}),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -141,21 +141,14 @@ const FormatRelocTypeCtx = struct {
|
||||
cpu_arch: std.Target.Cpu.Arch,
|
||||
};
|
||||
|
||||
pub fn fmtRelocType(r_type: u32, cpu_arch: std.Target.Cpu.Arch) std.fmt.Formatter(formatRelocType) {
|
||||
pub fn fmtRelocType(r_type: u32, cpu_arch: std.Target.Cpu.Arch) std.fmt.Formatter(FormatRelocTypeCtx, formatRelocType) {
|
||||
return .{ .data = .{
|
||||
.r_type = r_type,
|
||||
.cpu_arch = cpu_arch,
|
||||
} };
|
||||
}
|
||||
|
||||
fn formatRelocType(
|
||||
ctx: FormatRelocTypeCtx,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
fn formatRelocType(ctx: FormatRelocTypeCtx, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
const r_type = ctx.r_type;
|
||||
switch (ctx.cpu_arch) {
|
||||
.x86_64 => try writer.print("R_X86_64_{s}", .{@tagName(@as(elf.R_X86_64, @enumFromInt(r_type)))}),
|
||||
|
||||
@@ -606,37 +606,30 @@ pub const GotSection = struct {
|
||||
}
|
||||
}
|
||||
|
||||
const FormatCtx = struct {
|
||||
const Format = struct {
|
||||
got: GotSection,
|
||||
elf_file: *Elf,
|
||||
|
||||
pub fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
const got = f.got;
|
||||
const elf_file = f.elf_file;
|
||||
try writer.writeAll("GOT\n");
|
||||
for (got.entries.items) |entry| {
|
||||
const symbol = elf_file.symbol(entry.ref).?;
|
||||
try writer.print(" {d}@0x{x} => {}@0x{x} ({s})\n", .{
|
||||
entry.cell_index,
|
||||
entry.address(elf_file),
|
||||
entry.ref,
|
||||
symbol.address(.{}, elf_file),
|
||||
symbol.name(elf_file),
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
pub fn fmt(got: GotSection, elf_file: *Elf) std.fmt.Formatter(format2) {
|
||||
pub fn fmt(got: GotSection, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
|
||||
return .{ .data = .{ .got = got, .elf_file = elf_file } };
|
||||
}
|
||||
|
||||
pub fn format2(
|
||||
ctx: FormatCtx,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = options;
|
||||
_ = unused_fmt_string;
|
||||
const got = ctx.got;
|
||||
const elf_file = ctx.elf_file;
|
||||
try writer.writeAll("GOT\n");
|
||||
for (got.entries.items) |entry| {
|
||||
const symbol = elf_file.symbol(entry.ref).?;
|
||||
try writer.print(" {d}@0x{x} => {}@0x{x} ({s})\n", .{
|
||||
entry.cell_index,
|
||||
entry.address(elf_file),
|
||||
entry.ref,
|
||||
symbol.address(.{}, elf_file),
|
||||
symbol.name(elf_file),
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
pub const PltSection = struct {
|
||||
@@ -749,38 +742,31 @@ pub const PltSection = struct {
|
||||
}
|
||||
}
|
||||
|
||||
const FormatCtx = struct {
|
||||
const Format = struct {
|
||||
plt: PltSection,
|
||||
elf_file: *Elf,
|
||||
|
||||
pub fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
const plt = f.plt;
|
||||
const elf_file = f.elf_file;
|
||||
try writer.writeAll("PLT\n");
|
||||
for (plt.symbols.items, 0..) |ref, i| {
|
||||
const symbol = elf_file.symbol(ref).?;
|
||||
try writer.print(" {d}@0x{x} => {}@0x{x} ({s})\n", .{
|
||||
i,
|
||||
symbol.pltAddress(elf_file),
|
||||
ref,
|
||||
symbol.address(.{}, elf_file),
|
||||
symbol.name(elf_file),
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
pub fn fmt(plt: PltSection, elf_file: *Elf) std.fmt.Formatter(format2) {
|
||||
pub fn fmt(plt: PltSection, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
|
||||
return .{ .data = .{ .plt = plt, .elf_file = elf_file } };
|
||||
}
|
||||
|
||||
pub fn format2(
|
||||
ctx: FormatCtx,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = options;
|
||||
_ = unused_fmt_string;
|
||||
const plt = ctx.plt;
|
||||
const elf_file = ctx.elf_file;
|
||||
try writer.writeAll("PLT\n");
|
||||
for (plt.symbols.items, 0..) |ref, i| {
|
||||
const symbol = elf_file.symbol(ref).?;
|
||||
try writer.print(" {d}@0x{x} => {}@0x{x} ({s})\n", .{
|
||||
i,
|
||||
symbol.pltAddress(elf_file),
|
||||
ref,
|
||||
symbol.address(.{}, elf_file),
|
||||
symbol.name(elf_file),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const x86_64 = struct {
|
||||
fn write(plt: PltSection, elf_file: *Elf, writer: anytype) !void {
|
||||
const shdrs = elf_file.sections.items(.shdr);
|
||||
|
||||
@@ -1649,7 +1649,7 @@ fn spawnLld(
|
||||
child.stderr_behavior = .Pipe;
|
||||
|
||||
child.spawn() catch |err| break :term err;
|
||||
stderr = try child.stderr.?.reader().readAllAlloc(comp.gpa, std.math.maxInt(usize));
|
||||
stderr = try child.stderr.?.deprecatedReader().readAllAlloc(comp.gpa, std.math.maxInt(usize));
|
||||
break :term child.wait();
|
||||
}) catch |first_err| term: {
|
||||
const err = switch (first_err) {
|
||||
@@ -1697,7 +1697,7 @@ fn spawnLld(
|
||||
rsp_child.stderr_behavior = .Pipe;
|
||||
|
||||
rsp_child.spawn() catch |err| break :err err;
|
||||
stderr = try rsp_child.stderr.?.reader().readAllAlloc(comp.gpa, std.math.maxInt(usize));
|
||||
stderr = try rsp_child.stderr.?.deprecatedReader().readAllAlloc(comp.gpa, std.math.maxInt(usize));
|
||||
break :term rsp_child.wait() catch |err| break :err err;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -2552,7 +2552,7 @@ const Format = struct {
|
||||
}
|
||||
}
|
||||
|
||||
fn formatSymtab(f: Format, w: *Writer) Writer.Error!void {
|
||||
fn symtab(f: Format, w: *Writer) Writer.Error!void {
|
||||
const object = f.object;
|
||||
const macho_file = f.macho_file;
|
||||
try w.writeAll(" symbols\n");
|
||||
@@ -2695,7 +2695,7 @@ const StabFile = struct {
|
||||
};
|
||||
|
||||
pub fn fmt(stab: Stab, object: Object) std.fmt.Formatter(Stab.Format, Stab.Format.default) {
|
||||
return .{ .data = .{ stab, object } };
|
||||
return .{ .data = .{ .stab = stab, .object = object } };
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -71,7 +71,7 @@ pub fn lessThan(ctx: void, lhs: Relocation, rhs: Relocation) bool {
|
||||
}
|
||||
|
||||
pub fn fmtPretty(rel: Relocation, cpu_arch: std.Target.Cpu.Arch) std.fmt.Formatter(Format, Format.pretty) {
|
||||
return .{ .data = .{ rel, cpu_arch } };
|
||||
return .{ .data = .{ .relocation = rel, .arch = cpu_arch } };
|
||||
}
|
||||
|
||||
const Format = struct {
|
||||
|
||||
@@ -211,49 +211,29 @@ pub const Fde = struct {
|
||||
return fde.getObject(macho_file).getAtom(fde.lsda);
|
||||
}
|
||||
|
||||
pub fn format(
|
||||
fde: Fde,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = fde;
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
_ = writer;
|
||||
@compileError("do not format FDEs directly");
|
||||
}
|
||||
|
||||
pub fn fmt(fde: Fde, macho_file: *MachO) std.fmt.Formatter(format2) {
|
||||
pub fn fmt(fde: Fde, macho_file: *MachO) std.fmt.Formatter(Format, Format.default) {
|
||||
return .{ .data = .{
|
||||
.fde = fde,
|
||||
.macho_file = macho_file,
|
||||
} };
|
||||
}
|
||||
|
||||
const FormatContext = struct {
|
||||
const Format = struct {
|
||||
fde: Fde,
|
||||
macho_file: *MachO,
|
||||
};
|
||||
|
||||
fn format2(
|
||||
ctx: FormatContext,
|
||||
comptime unused_fmt_string: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = unused_fmt_string;
|
||||
_ = options;
|
||||
const fde = ctx.fde;
|
||||
const macho_file = ctx.macho_file;
|
||||
try writer.print("@{x} : size({x}) : cie({d}) : {s}", .{
|
||||
fde.offset,
|
||||
fde.getSize(),
|
||||
fde.cie,
|
||||
fde.getAtom(macho_file).getName(macho_file),
|
||||
});
|
||||
if (!fde.alive) try writer.writeAll(" : [*]");
|
||||
}
|
||||
fn default(f: Format, writer: *Writer) Writer.Error!void {
|
||||
const fde = f.fde;
|
||||
const macho_file = f.macho_file;
|
||||
try writer.print("@{x} : size({x}) : cie({d}) : {s}", .{
|
||||
fde.offset,
|
||||
fde.getSize(),
|
||||
fde.cie,
|
||||
fde.getAtom(macho_file).getName(macho_file),
|
||||
});
|
||||
if (!fde.alive) try writer.writeAll(" : [*]");
|
||||
}
|
||||
};
|
||||
|
||||
pub const Index = u32;
|
||||
};
|
||||
|
||||
@@ -20,15 +20,8 @@ pub const FormatContext = struct {
|
||||
depth: u8,
|
||||
};
|
||||
|
||||
pub fn formatSema(
|
||||
ctx: FormatContext,
|
||||
comptime fmt: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = options;
|
||||
pub fn formatSema(ctx: FormatContext, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
const sema = ctx.opt_sema.?;
|
||||
comptime std.debug.assert(fmt.len == 0);
|
||||
return print(ctx.val, writer, ctx.depth, ctx.pt, sema) catch |err| switch (err) {
|
||||
error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function
|
||||
error.ComptimeBreak, error.ComptimeReturn => unreachable,
|
||||
@@ -37,15 +30,8 @@ pub fn formatSema(
|
||||
};
|
||||
}
|
||||
|
||||
pub fn format(
|
||||
ctx: FormatContext,
|
||||
comptime fmt: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
_ = options;
|
||||
pub fn format(ctx: FormatContext, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
std.debug.assert(ctx.opt_sema == null);
|
||||
comptime std.debug.assert(fmt.len == 0);
|
||||
return print(ctx.val, writer, ctx.depth, ctx.pt, null) catch |err| switch (err) {
|
||||
error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function
|
||||
error.ComptimeBreak, error.ComptimeReturn, error.AnalysisFail => unreachable,
|
||||
@@ -55,11 +41,11 @@ pub fn format(
|
||||
|
||||
pub fn print(
|
||||
val: Value,
|
||||
writer: anytype,
|
||||
writer: *std.io.Writer,
|
||||
level: u8,
|
||||
pt: Zcu.PerThread,
|
||||
opt_sema: ?*Sema,
|
||||
) (@TypeOf(writer).Error || Zcu.CompileError)!void {
|
||||
) (std.io.Writer.Error || Zcu.CompileError)!void {
|
||||
const zcu = pt.zcu;
|
||||
const ip = &zcu.intern_pool;
|
||||
switch (ip.indexToKey(val.toIntern())) {
|
||||
@@ -197,11 +183,11 @@ fn printAggregate(
|
||||
val: Value,
|
||||
aggregate: InternPool.Key.Aggregate,
|
||||
is_ref: bool,
|
||||
writer: anytype,
|
||||
writer: *std.io.Writer,
|
||||
level: u8,
|
||||
pt: Zcu.PerThread,
|
||||
opt_sema: ?*Sema,
|
||||
) (@TypeOf(writer).Error || Zcu.CompileError)!void {
|
||||
) (std.io.Writer.Error || Zcu.CompileError)!void {
|
||||
if (level == 0) {
|
||||
if (is_ref) try writer.writeByte('&');
|
||||
return writer.writeAll(".{ ... }");
|
||||
@@ -283,11 +269,11 @@ fn printPtr(
|
||||
ptr_val: Value,
|
||||
/// Whether to print `derivation` as an lvalue or rvalue. If `null`, the more concise option is chosen.
|
||||
want_kind: ?PrintPtrKind,
|
||||
writer: anytype,
|
||||
writer: *std.io.Writer,
|
||||
level: u8,
|
||||
pt: Zcu.PerThread,
|
||||
opt_sema: ?*Sema,
|
||||
) (@TypeOf(writer).Error || Zcu.CompileError)!void {
|
||||
) (std.io.Writer.Error || Zcu.CompileError)!void {
|
||||
const ptr = switch (pt.zcu.intern_pool.indexToKey(ptr_val.toIntern())) {
|
||||
.undef => return writer.writeAll("undefined"),
|
||||
.ptr => |ptr| ptr,
|
||||
@@ -329,7 +315,7 @@ const PrintPtrKind = enum { lvalue, rvalue };
|
||||
/// Returns the root derivation, which may be ignored.
|
||||
pub fn printPtrDerivation(
|
||||
derivation: Value.PointerDeriveStep,
|
||||
writer: anytype,
|
||||
writer: *std.io.Writer,
|
||||
pt: Zcu.PerThread,
|
||||
/// Whether to print `derivation` as an lvalue or rvalue. If `null`, the more concise option is chosen.
|
||||
/// If this is `.rvalue`, the result may look like `&foo`, so it's not necessarily valid to treat it as
|
||||
|
||||
Reference in New Issue
Block a user