authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-07-20 20:00:44+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-07-20 20:01:06+02:00
log245f6553e6840b2221141f3e7724ae6a73294387
treecc5412a93c1e428d10e018217c145a01b9b64faa
parent3b6200db41f201839a7238c95ddc2e1323d8acbd

check-object: format known OS-specific types before doing generic format


1 files changed, 40 insertions(+), 43 deletions(-)

lib/std/Build/Step/CheckObject.zig+40-43
...@@ -1237,49 +1237,6 @@ const ElfDumper = struct {...@@ -1237,49 +1237,6 @@ const ElfDumper = struct {
1237 for (symtab.symbols, 0..) |sym, index| {1237 for (symtab.symbols, 0..) |sym, index| {
1238 try writer.print("{x} {x}", .{ sym.st_value, sym.st_size });1238 try writer.print("{x} {x}", .{ sym.st_value, sym.st_size });
12391239
1240 {
1241 const tt = sym.st_type();
1242 if (elf.STT_LOPROC <= tt and tt < elf.STT_HIPROC) {
1243 try writer.print(" LOPROC+{d}", .{tt - elf.STT_LOPROC});
1244 } else if (elf.STT_LOOS <= tt and tt < elf.STT_HIOS) {
1245 try writer.print(" LOOS+{d}", .{tt - elf.STT_LOOS});
1246 } else {
1247 const sym_type = switch (tt) {
1248 elf.STT_NOTYPE => "NOTYPE",
1249 elf.STT_OBJECT => "OBJECT",
1250 elf.STT_FUNC => "FUNC",
1251 elf.STT_SECTION => "SECTION",
1252 elf.STT_FILE => "FILE",
1253 elf.STT_COMMON => "COMMON",
1254 elf.STT_TLS => "TLS",
1255 elf.STT_NUM => "NUM",
1256 else => "UNK",
1257 };
1258 try writer.print(" {s}", .{sym_type});
1259 }
1260 }
1261
1262 {
1263 const bind = sym.st_bind();
1264 if (elf.STB_LOPROC <= bind and bind < elf.STB_HIPROC) {
1265 try writer.print(" LOPROC+{d}", .{bind - elf.STB_LOPROC});
1266 } else if (elf.STB_LOOS <= bind and bind < elf.STB_HIOS) {
1267 try writer.print(" LOOS+{d}", .{bind - elf.STB_LOOS});
1268 } else {
1269 const sym_bind = switch (bind) {
1270 elf.STB_LOCAL => "LOCAL",
1271 elf.STB_GLOBAL => "GLOBAL",
1272 elf.STB_WEAK => "WEAK",
1273 elf.STB_NUM => "NUM",
1274 else => "UNKNOWN",
1275 };
1276 try writer.print(" {s}", .{sym_bind});
1277 }
1278 }
1279
1280 const sym_vis = @as(elf.STV, @enumFromInt(sym.st_other));
1281 try writer.print(" {s}", .{@tagName(sym_vis)});
1282
1283 {1240 {
1284 if (elf.SHN_LORESERVE <= sym.st_shndx and sym.st_shndx < elf.SHN_HIRESERVE) {1241 if (elf.SHN_LORESERVE <= sym.st_shndx and sym.st_shndx < elf.SHN_HIRESERVE) {
1285 if (elf.SHN_LOPROC <= sym.st_shndx and sym.st_shndx < elf.SHN_HIPROC) {1242 if (elf.SHN_LOPROC <= sym.st_shndx and sym.st_shndx < elf.SHN_HIPROC) {
...@@ -1300,6 +1257,46 @@ const ElfDumper = struct {...@@ -1300,6 +1257,46 @@ const ElfDumper = struct {
1300 }1257 }
1301 }1258 }
13021259
1260 blk: {
1261 const tt = sym.st_type();
1262 const sym_type = switch (tt) {
1263 elf.STT_NOTYPE => "NOTYPE",
1264 elf.STT_OBJECT => "OBJECT",
1265 elf.STT_FUNC => "FUNC",
1266 elf.STT_SECTION => "SECTION",
1267 elf.STT_FILE => "FILE",
1268 elf.STT_COMMON => "COMMON",
1269 elf.STT_TLS => "TLS",
1270 elf.STT_NUM => "NUM",
1271 elf.STT_GNU_IFUNC => "IFUNC",
1272 else => if (elf.STT_LOPROC <= tt and tt < elf.STT_HIPROC) {
1273 break :blk try writer.print(" LOPROC+{d}", .{tt - elf.STT_LOPROC});
1274 } else if (elf.STT_LOOS <= tt and tt < elf.STT_HIOS) {
1275 break :blk try writer.print(" LOOS+{d}", .{tt - elf.STT_LOOS});
1276 } else "UNK",
1277 };
1278 try writer.print(" {s}", .{sym_type});
1279 }
1280
1281 blk: {
1282 const bind = sym.st_bind();
1283 const sym_bind = switch (bind) {
1284 elf.STB_LOCAL => "LOCAL",
1285 elf.STB_GLOBAL => "GLOBAL",
1286 elf.STB_WEAK => "WEAK",
1287 elf.STB_NUM => "NUM",
1288 else => if (elf.STB_LOPROC <= bind and bind < elf.STB_HIPROC) {
1289 break :blk try writer.print(" LOPROC+{d}", .{bind - elf.STB_LOPROC});
1290 } else if (elf.STB_LOOS <= bind and bind < elf.STB_HIOS) {
1291 break :blk try writer.print(" LOOS+{d}", .{bind - elf.STB_LOOS});
1292 } else "UNKNOWN",
1293 };
1294 try writer.print(" {s}", .{sym_bind});
1295 }
1296
1297 const sym_vis = @as(elf.STV, @enumFromInt(sym.st_other));
1298 try writer.print(" {s}", .{@tagName(sym_vis)});
1299
1303 const sym_name = switch (sym.st_type()) {1300 const sym_name = switch (sym.st_type()) {
1304 elf.STT_SECTION => getSectionName(ctx, sym.st_shndx),1301 elf.STT_SECTION => getSectionName(ctx, sym.st_shndx),
1305 else => symtab.getName(index).?,1302 else => symtab.getName(index).?,