Repository navigation
Code Metadata - #1840
Code Metadata#1840
Conversation
Added parsing from binary and general callbacks for generic code metadata sections. Basic logging and info in objdump.
The annotations are shown in the line before the referenced instruction, as a C-style line comment.
|
|
||
| Result BinaryReaderIR::BeginFunctionBody(Index index, Offset size) { | ||
| current_func_ = module_->funcs[index]; | ||
| current_func_->loc = GetLocation(); |
There was a problem hiding this comment.
Seems odd that this was not needed before.. do you know why this is needed now?
There was a problem hiding this comment.
I am not sure why it wasn't used before, and maybe I am using it as a hack?
Anyway, It is now needed by CodeMetadataExprQueue: the offsets are always absolute but code metadata need relative offsets from the beginning of the function. So it seemed natural to fill this existing field here and use it to get relative offsets later
There was a problem hiding this comment.
Oh, actually you are adding this new loc field to struct Func. I guess that makes sense for this use case and we already track this for other things such as expressions, and I guess the location a function is different from the location of its first expression due to param declaration?
There was a problem hiding this comment.
Sorry, I made this change some time ago and I didn't remember that I added the field!
But yes, it felt natural, since like you say it is there for similar things.
And also yes, the difference with the location of the first expression is that there are the locals in between.
| CHECK_RESULT(ReadCount(&function_index, "function index")); | ||
| ERROR_UNLESS(function_index >= num_func_imports_, | ||
| "function import can't have metadata (got %" PRIindex ")", | ||
| function_index); |
There was a problem hiding this comment.
Since this is a custom section I guess we should not completely fail if its malformed?
(Update: I see tests below where it looks like there are just warnings... I guess that downgrade from error to warning ins somewhere in the custom section handling code?)
There was a problem hiding this comment.
Yes, the PrintError method automatically converts to warning if it is invoked when parsing a custom section.
| } else if (section_name == WABT_BINARY_SECTION_LINKING) { | ||
| CHECK_RESULT(ReadLinkingSection(section_size)); | ||
| } else if (options_.features.code_metadata_enabled() && | ||
| section_name.find(WABT_BINARY_SECTION_CODE_METADATA) == 0) { |
There was a problem hiding this comment.
Is there no startswith for C++ strings?
There was a problem hiding this comment.
it seems that they added it in c++20. But wabt uses c++17 currently.
This PR adds support for Code Metadata.
See https://github.com/WebAssembly/tool-conventions/blob/main/CodeMetadata.md for the specification.
In particular this pr implements the following:
All the features have corresponding tests.
Support for code metadata is gated through the --enable-code-metadata feature. For reading/writing in the text format, --enable-annotations is also required.
Missing features: