This is necessary for YAML based tests for D55881.
Details
Diff Detail
Event Timeline
I think a composite test (or tests) would makes sense, but check the intermediate output as well as the final output.
include/llvm/ObjectYAML/COFFYAML.h | ||
---|---|---|
67 | SymbolTableIndex -> SymbolIndex "SymbolTableIndex" to me implies the section index of the symbol table. | |
tools/obj2yaml/coff2yaml.cpp | ||
146 | SymbolOccurrances -> SymbolOccurrences | |
tools/yaml2obj/yaml2coff.cpp | ||
524–533 | It should probably be an error somewhere if both fields are set (possibly unless they indicate the same symbol). I'd also write this as a ternary, with the symbol index being the first case, to avoid the lookup if not necessary, unless the intention is to insert a default constructed symbol in the map when no symbol exists? |
include/llvm/ObjectYAML/COFFYAML.h | ||
---|---|---|
67 | Well the field in the actual relocation also is called SymbolTableIndex, so I chose that as it's an exact match of what's stored on disk. In coff, the symbol table isn't stored in a section, so there shouldn't be any confusion with that (in a pure coff environment). | |
tools/obj2yaml/coff2yaml.cpp | ||
146 | Ok, will fix. Later I though of using a StringMap<bool> SymbolUnique instead, to conserve space a little. | |
tools/yaml2obj/yaml2coff.cpp | ||
524–533 | Ok, that sounds sensible. It's not intended to insert a dummy element in the map (although I doubt that it'd be harmful either). I'll see if it making it an error here fits in. |
Added a testcase, applied @jhenderson's suggestions (erroring out if both SymbolName and SymbolTableIndex are present, avoiding touching SymbolTableIndexMap if direct index is set, changed the (misspelled) SymbolOccurrances map into a SymbolUnique map).
tools/obj2yaml/coff2yaml.cpp | ||
---|---|---|
208–211 | Doesn't this insert a new key if *SymbolNameOrErr does not exist in the map? I don't think that affects correctness of the program, but that's probably a waste of time and memory. I'd use count instead. |
tools/obj2yaml/coff2yaml.cpp | ||
---|---|---|
208–211 | Yes, but every symbol will exist in the map already. We're not interested in whether the key exists in the map or not (it will always exist), but whether the map entry actually is set to true or false. |
tools/obj2yaml/coff2yaml.cpp | ||
---|---|---|
208–211 | Ah OK, then this is fine. I'd still use count to not surprise careless readers like me though. :) |
tools/obj2yaml/coff2yaml.cpp | ||
---|---|---|
208–211 | Why count? Wouldn't that just return 1 saying that the symbol indeed is present in the map? We're not interested in whether the key is present or not (it always is), we're interested in the value of the map element, and count won't help with that. |
tools/obj2yaml/coff2yaml.cpp | ||
---|---|---|
208–211 | You're imagining a StringSet that only contains the symbols we know are unique. It's not that (building such a data structure would be tricky) but a StringMap<bool> which could be called StringIsUnique, which stores all symbols and whether they are unique or not, as a bool. |
tools/obj2yaml/coff2yaml.cpp | ||
---|---|---|
208–211 | Sorry, what I wanted to say is lookup. |
tools/obj2yaml/coff2yaml.cpp | ||
---|---|---|
208–211 | Oh, ok - I can change it to that. |
include/llvm/ObjectYAML/COFFYAML.h | ||
---|---|---|
67 | I'd probably add a comment somewhere explaining that this "duplication" (the presence of both Index and Name) are for convenience (that i.e. in YAML one can specify either the name or the index) + handling of non-unique names. P.S. if i understood the rationale for this change correctly, of course |
include/llvm/ObjectYAML/COFFYAML.h | ||
---|---|---|
67 | Sure, I can add a comment. |
LGTM with one minor nit
tools/obj2yaml/coff2yaml.cpp | ||
---|---|---|
151 | side note: double lookup (1st - find, second - operator []) can be avoided here if we switch to using the method "insert" instead (it returns the corresponding iterator). |
tools/obj2yaml/coff2yaml.cpp | ||
---|---|---|
151 | Oh, nice, will do. |
Using the insert method, to avoid double lookup. Will push next week after giving @jhenderson a chance to comment, unless there's more things to change.
I'm giving a conditional LGTM, assuming that the mentioned YAML blob is as small as reasonably possible to test the relocations. Remember, we don't need to have a fully usable object file, we just need one that has the relevant symbols and relocations.
include/llvm/ObjectYAML/COFFYAML.h | ||
---|---|---|
61 | To clarify that this comment refers to the two following variables, please put a new line before it. | |
test/tools/yaml2obj/coff-symbol-index.yaml | ||
46 | Is this YAML blob as minimal as it can get whilst still testing the required properties? It's very verbose! |
Okay, looking much better. I'm happy for this to go in, but if any of the other bits I highlighted can be removed, even better.
test/tools/yaml2obj/coff-symbol-index.yaml | ||
---|---|---|
34 | Are all these required? Same comment for the other sections. | |
59–61 | Are these fields required? Same question for further below. | |
78 | Is this necessary? | |
80 | Is this needed? |
test/tools/yaml2obj/coff-symbol-index.yaml | ||
---|---|---|
34 | Yes, Characteristics is mandatory, otherwise it fails like this: YAML:33:5: error: missing required key 'Characteristics' | |
59–61 | Yes, these fields are necessary. | |
78 | The whole SectionDefinition part can be omitted while keeping the test functioning. | |
80 | Can be omitted while keeping the test working. |
Stripped the test yaml further, with empty Characteristics and removed SectionDefinitions.
To clarify that this comment refers to the two following variables, please put a new line before it.