YAML support allows us to better test the feature in the subsequent patches. The implementation is quite similar to the .stack_sizes section.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Generally looks fine to me, I've put a few comments inline and also:
- This needs a rebasing (D89039 was landed, it added support of "Size"/"Content" for all sections).
- This needs yaml2obj tests. I think following are reasonable for initial support:
- a) Check values of section fields produced by default (sh_link, sh_info, etc).
- b) Check you can specify none of "Content", "Size" or "Entries" to produce an empty section.
- c) Check you can specify only "Size", only "Content" or only "Entries" (see tests in D89039 and others).
- d) Check you can't specify "Entries" with "Content"/"Size" (you need to add the code to validate(), see D89391).
llvm/lib/ObjectYAML/ELFEmitter.cpp | ||
---|---|---|
1310 | ||
1316 | You don't need to have curly braces here. | |
llvm/lib/ObjectYAML/ELFYAML.cpp | ||
1667 | This needs a yaml2obj test to show that we can omit "Address" and it will accept it and produce "0" as address. | |
1669 | I think you don't need NumBlock YAML key. It matches the number of items in "BBEntries", right? - Name: .note.foo Type: SHT_NOTE Flags: [ SHF_ALLOC ] Notes: - Name: AB Desc: '' Type: 0xFF - Name: ABC Desc: '123456' Type: 254 | |
llvm/test/tools/obj2yaml/ELF/bb-addr-map.yaml | ||
148 | Missing empty line before "--- !ELF" | |
157 | I'd change 0x0000000000000010 to 0x0000000000000000 and demonstrate that | |
llvm/tools/obj2yaml/elf2yaml.cpp | ||
511 | Excessive empty line. |
llvm/lib/ObjectYAML/ELFYAML.cpp | ||
---|---|---|
1669 | Presumably if the NumBlock field corresponds to part of the data structure, we want it to be an Optional member, so that users can override it independently of the number of entries - that way tests can be crafted that show what happens if the value is invalid. |
Thanks for your helpful comments @grimar.
llvm/lib/ObjectYAML/ELFEmitter.cpp | ||
---|---|---|
1310 | Adopted in the line above. | |
llvm/lib/ObjectYAML/ELFYAML.cpp | ||
1667 | Please look at the added test. | |
1669 | Great suggestion. Thanks. Removed the NumBlocks YAML key, even though the field still shows up in the section data. | |
llvm/test/tools/obj2yaml/ELF/bb-addr-map.yaml | ||
157 | Thanks. It works as expected. |
llvm/test/tools/obj2yaml/ELF/bb-addr-map.yaml | ||
---|---|---|
19 | You don't need this line, since you are always using -NEXT and dump all output. | |
llvm/test/tools/yaml2obj/ELF/bb-addr-map.yaml | ||
3 ↗ | (On Diff #300821) | I'd move these 1-5 comments to YAML description though: Sections: ## 1) We can produce a .llvm_bb_addr_map section from a description with section ## content. - Name: '.llvm_bb_addr_map (1)' Type: SHT_LLVM_BB_ADDR_MAP Content: "000000000000000001010203" ## 2) We can produce an empty .llvm_bb_addr_map section from a description ## swith empty section content. - Name: '.llvm_bb_addr_map (2)' Type: SHT_LLVM_BB_ADDR_MAP ... |
112 ↗ | (On Diff #300821) | You don't need (1) for this test. |
114 ↗ | (On Diff #300821) | I think you should be able to write just Entries: []. No need to provide more input data than needed. |
139 ↗ | (On Diff #300821) | I'd merge last two YAMLs into one with the use of macros. I think something like the --- !ELF FileHeader: Class: ELFCLASS64 Data: ELFDATA2LSB Type: ET_EXEC Sections: ## Specify Content and Entries - Name: '.llvm_bb_addr_map' Type: SHT_LLVM_BB_ADDR_MAP Entries: [] Content: [[CONTENT=<none>]] Size: [[SIZE=<none>]] And then you can: not yaml2obj --docnum=2 -DCONTENT="00"... not yaml2obj --docnum=2 -DSIZE=0... |
llvm/test/tools/yaml2obj/ELF/bb-addr-map.yaml | ||
---|---|---|
114 ↗ | (On Diff #300821) | Or even: Content: "" |
llvm/test/tools/obj2yaml/ELF/bb-addr-map.yaml | ||
---|---|---|
129 | Same as above - the -NOT check is unnecessary due to the use of the -NEXT pattern throughout. | |
llvm/test/tools/yaml2obj/ELF/bb-addr-map.yaml | ||
7 ↗ | (On Diff #300821) | |
40 ↗ | (On Diff #300821) | Watch out - this will also match Size: 10. You need extra regex patterns to make sure there are no preceding characters, e.g: # CHECK: Size:{{ }} # CHECK-SAME: {{^}}0 (in this context the ^ character represents the end of the previous match). |
llvm/tools/obj2yaml/elf2yaml.cpp | ||
799 | In the empty() case, I think it would be great to not specify Content or Entries, so that you end up with a section like this: Name: .llvm_bb_addr_map Type: SHT_LLVM_BB_ADDR_MAP |
llvm/tools/obj2yaml/elf2yaml.cpp | ||
---|---|---|
799 | Checked for Content.empty() before jumping into the while loop. |
LGTM, with a couple of nits.
llvm/test/tools/yaml2obj/ELF/bb-addr-map.yaml | ||
---|---|---|
59 ↗ | (On Diff #302670) | Trivial nit: to me, the '.' is silent when I say this out loud, so it sounds like "an .llvm_bb_addr_map" would be better than "a .llvm_bb_addr_map". Same applies for point 4). Feel free to ignore. |
99 ↗ | (On Diff #302670) | Reads more cleanly to me. |
Thank you @grimar and @jhenderson for the thorough feedback. I will start on llvm-readobj support once I submit this patch.
llvm/test/tools/yaml2obj/ELF/bb-addr-map.yaml | ||
---|---|---|
59 ↗ | (On Diff #302670) | Fixed here and elsewhere. |
llvm/lib/ObjectYAML/ELFYAML.cpp | ||
---|---|---|
1570 | Oh. This piece is actually not needed anymore, we have a general mechanism for validating fields. |
llvm/lib/ObjectYAML/ELFYAML.cpp | ||
---|---|---|
1570 | Thanks for submitting the fix. |