authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-10-23 19:20:18+02:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-10-25 20:48:08+02:00
logb14f605dd7b808d1e6d3ee1f8d545135ebe296ee
treebf68c851b27ed42b98d689ae29a44b0d2b1d6cd9
parent777bcbf96871a0250664b9cabdea5dbf51e0e64d
signaturelock-open Commit is signed but in an unrecognized format.

CheckObjectStep: parse and dump `target_features`

When an object file or binary contains the target_features section we can now parse and then dump its contents in string format so we can use them in our linker tests to verify the features section.

1 files changed, 17 insertions(+), 0 deletions(-)

lib/std/build/CheckObjectStep.zig+17
...@@ -649,6 +649,8 @@ const WasmDumper = struct {...@@ -649,6 +649,8 @@ const WasmDumper = struct {
649 try parseDumpNames(reader, writer, data);649 try parseDumpNames(reader, writer, data);
650 } else if (mem.eql(u8, name, "producers")) {650 } else if (mem.eql(u8, name, "producers")) {
651 try parseDumpProducers(reader, writer, data);651 try parseDumpProducers(reader, writer, data);
652 } else if (mem.eql(u8, name, "target_features")) {
653 try parseDumpFeatures(reader, writer, data);
652 }654 }
653 // TODO: Implement parsing and dumping other custom sections (such as relocations)655 // TODO: Implement parsing and dumping other custom sections (such as relocations)
654 },656 },
...@@ -902,4 +904,19 @@ const WasmDumper = struct {...@@ -902,4 +904,19 @@ const WasmDumper = struct {
902 }904 }
903 }905 }
904 }906 }
907
908 fn parseDumpFeatures(reader: anytype, writer: anytype, data: []const u8) !void {
909 const feature_count = try std.leb.readULEB128(u32, reader);
910 try writer.print("features {d}\n", .{feature_count});
911
912 var index: u32 = 0;
913 while (index < feature_count) : (index += 1) {
914 const prefix_byte = try std.leb.readULEB128(u8, reader);
915 const name_length = try std.leb.readULEB128(u32, reader);
916 const feature_name = data[reader.context.pos..][0..name_length];
917 reader.context.pos += name_length;
918
919 try writer.print("{c} {s}\n", .{ prefix_byte, feature_name });
920 }
921 }
905};922};