From 245f6553e6840b2221141f3e7724ae6a73294387 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Thu, 20 Jul 2023 20:00:44 +0200 Subject: [PATCH] check-object: format known OS-specific types before doing generic format --- lib/std/Build/Step/CheckObject.zig | 83 ++++++++++++++---------------- 1 file changed, 40 insertions(+), 43 deletions(-) diff --git a/lib/std/Build/Step/CheckObject.zig b/lib/std/Build/Step/CheckObject.zig index 6466708080..3fe84658a2 100644 --- a/lib/std/Build/Step/CheckObject.zig +++ b/lib/std/Build/Step/CheckObject.zig @@ -1237,49 +1237,6 @@ const ElfDumper = struct { for (symtab.symbols, 0..) |sym, index| { try writer.print("{x} {x}", .{ sym.st_value, sym.st_size }); - { - const tt = sym.st_type(); - if (elf.STT_LOPROC <= tt and tt < elf.STT_HIPROC) { - try writer.print(" LOPROC+{d}", .{tt - elf.STT_LOPROC}); - } else if (elf.STT_LOOS <= tt and tt < elf.STT_HIOS) { - try writer.print(" LOOS+{d}", .{tt - elf.STT_LOOS}); - } else { - const sym_type = switch (tt) { - elf.STT_NOTYPE => "NOTYPE", - elf.STT_OBJECT => "OBJECT", - elf.STT_FUNC => "FUNC", - elf.STT_SECTION => "SECTION", - elf.STT_FILE => "FILE", - elf.STT_COMMON => "COMMON", - elf.STT_TLS => "TLS", - elf.STT_NUM => "NUM", - else => "UNK", - }; - try writer.print(" {s}", .{sym_type}); - } - } - - { - const bind = sym.st_bind(); - if (elf.STB_LOPROC <= bind and bind < elf.STB_HIPROC) { - try writer.print(" LOPROC+{d}", .{bind - elf.STB_LOPROC}); - } else if (elf.STB_LOOS <= bind and bind < elf.STB_HIOS) { - try writer.print(" LOOS+{d}", .{bind - elf.STB_LOOS}); - } else { - const sym_bind = switch (bind) { - elf.STB_LOCAL => "LOCAL", - elf.STB_GLOBAL => "GLOBAL", - elf.STB_WEAK => "WEAK", - elf.STB_NUM => "NUM", - else => "UNKNOWN", - }; - try writer.print(" {s}", .{sym_bind}); - } - } - - const sym_vis = @as(elf.STV, @enumFromInt(sym.st_other)); - try writer.print(" {s}", .{@tagName(sym_vis)}); - { if (elf.SHN_LORESERVE <= sym.st_shndx and sym.st_shndx < elf.SHN_HIRESERVE) { if (elf.SHN_LOPROC <= sym.st_shndx and sym.st_shndx < elf.SHN_HIPROC) { @@ -1300,6 +1257,46 @@ const ElfDumper = struct { } } + blk: { + const tt = sym.st_type(); + const sym_type = switch (tt) { + elf.STT_NOTYPE => "NOTYPE", + elf.STT_OBJECT => "OBJECT", + elf.STT_FUNC => "FUNC", + elf.STT_SECTION => "SECTION", + elf.STT_FILE => "FILE", + elf.STT_COMMON => "COMMON", + elf.STT_TLS => "TLS", + elf.STT_NUM => "NUM", + elf.STT_GNU_IFUNC => "IFUNC", + else => if (elf.STT_LOPROC <= tt and tt < elf.STT_HIPROC) { + break :blk try writer.print(" LOPROC+{d}", .{tt - elf.STT_LOPROC}); + } else if (elf.STT_LOOS <= tt and tt < elf.STT_HIOS) { + break :blk try writer.print(" LOOS+{d}", .{tt - elf.STT_LOOS}); + } else "UNK", + }; + try writer.print(" {s}", .{sym_type}); + } + + blk: { + const bind = sym.st_bind(); + const sym_bind = switch (bind) { + elf.STB_LOCAL => "LOCAL", + elf.STB_GLOBAL => "GLOBAL", + elf.STB_WEAK => "WEAK", + elf.STB_NUM => "NUM", + else => if (elf.STB_LOPROC <= bind and bind < elf.STB_HIPROC) { + break :blk try writer.print(" LOPROC+{d}", .{bind - elf.STB_LOPROC}); + } else if (elf.STB_LOOS <= bind and bind < elf.STB_HIOS) { + break :blk try writer.print(" LOOS+{d}", .{bind - elf.STB_LOOS}); + } else "UNKNOWN", + }; + try writer.print(" {s}", .{sym_bind}); + } + + const sym_vis = @as(elf.STV, @enumFromInt(sym.st_other)); + try writer.print(" {s}", .{@tagName(sym_vis)}); + const sym_name = switch (sym.st_type()) { elf.STT_SECTION => getSectionName(ctx, sym.st_shndx), else => symtab.getName(index).?,