Enable llvm-readobj to handle RISC-V ELF attribute section.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/test/tools/llvm-readobj/ELF/RISCV/unknown-arch-attr.test | ||
---|---|---|
44 ↗ | (On Diff #249023) | unittests/Support/RISCVAttributeParser.cpp is more suitable for such tests. See unittests/Support/ARMAttributeParser.cpp for examples. |
llvm/test/tools/llvm-readobj/ELF/RISCV/unknown-arch-attr.test | ||
---|---|---|
44 ↗ | (On Diff #249023) | In current implementation, it will ignore unrecognized extensions. It intends to skip 'x1p0' and recognizes 'm2p0' and decodes mul instruction correctly. So, I think it is appropriate to create this test case. |
llvm/test/tools/llvm-readobj/ELF/RISCV/attribute.s | ||
---|---|---|
2 | to decode -> can decode I think the canoncial name is "RISC-V", so you should use that in comments instead of "RISCV". | |
llvm/test/tools/llvm-readobj/ELF/RISCV/unknown-arch-attr.test | ||
7 ↗ | (On Diff #249023) | Is this test an llvm-objdump or llvm-readobj test? It looks to me like this test is testing llvm-objdump primarily, in which case it should be in the llvm-objdump directory, and maybe belongs in a separate change? |
38–39 ↗ | (On Diff #249023) | '##' Same below. |
llvm/tools/llvm-readobj/ELFDumper.cpp | ||
2670 | Is there a test case for this line? | |
2676 | Is there a test case for this line? | |
2703 | This is an existing mistake in the ARM version, but we shouldn't replicate it (and perhaps you could fix it separately). Unless E is going to be a duplicate of an already-reported error, this should report the error, probably as a warning, as there's no particular reason to terminate the program. |
llvm/tools/llvm-readobj/ELFDumper.cpp | ||
---|---|---|
2670 | No, it is not related to this patch. Originally, printAttributes() is only implemented for ELFDumper<ELF32LE>. So, I check Obj->isLE() to keep original logic. In this way, it does not change the functionality of original version. So, I did not add a test case for it. | |
2676 | No, it is not related to this patch. | |
2703 | We could fix it separately. |
llvm/test/MC/RISCV/attribute-with-option.s | ||
---|---|---|
1 | When a user specifies an architecture extension which conflicts with an arhitecture attribute, we use the architecture attribute instead of the command line option. | |
4 | specify the "e" extension | |
5 | arch -> architecture | |
12 | RV32E. x16 -> RV32E, because x16 | |
13 | assemble. So, it -> assemble, since it | |
16 | Check that the architecture attribute is not overridden by the command line option. | |
llvm/tools/llvm-readobj/ELFDumper.cpp | ||
2670 | The !Obj->isLE() line is new, so I think we need a test case that exercises this line as part of this change. You may be adding it to preserve existing behaviour, in which case, consider adding a test for it that in a prerequisite patch, to show that there is no behaviour change. | |
2676 | Yes it is. The behaviour has gone from "not EM_ARM" to "not EM_ARM and not EM_RISCV", which means the code here is now exercised differently. Again, you could add a prerequisite test that shows that non-ARM architectures hit this. Then, in this patch, you would remove the EM_RISCV case. | |
2703 | If you want to fix the ARM case separately, that's fine, but we shouldn't introduce the same mistake with new code for RISC-V. |
- Print out error messages if parsing attribute section error.
- Add more tests for invalid values in attribute section.
- Refine comments.
llvm/tools/llvm-readobj/ELFDumper.cpp | ||
---|---|---|
2676 | I found printAttributes only called under EM_ARM and EM_RISCV. I add an assertion in printAttributes to ensure it. |
llvm/test/MC/RISCV/attribute-with-option.s | ||
---|---|---|
7 | Sorry, missed one bit in my last comment: "to specifying" -> "to specify". | |
18 | overrided -> overridden | |
llvm/test/tools/llvm-readobj/ELF/RISCV/invalid-attr-size.test | ||
6 ↗ | (On Diff #251292) | Here and in the other tests, I'd add the full context for this message, i.e. something like {{.*}}.o: error: invalid subsection length (or whatever it is). |
llvm/test/tools/llvm-readobj/ELF/RISCV/invalid-attr-subsection-size.test | ||
1 ↗ | (On Diff #251292) | It's entirely up to you, but you might want to fold all these "invalid-attr" tests into a single test file, with lots of yaml docs. I'm happy either way. I am a bit confused by "invalid-attr-size.test" and "invalid-attr-subsection-size.test" given that the former appears to emit an error to do with the subsection size, whilst the latter is an error to do with the attribute size itself. Did you switch them around by accident? |
llvm/test/tools/llvm-readobj/ELF/RISCV/invalid-attr-vendor.test | ||
6 ↗ | (On Diff #251292) | Probably should be "vendor name" without the hyphen (unless it is called "vendor-name" in the section specification). |
llvm/test/tools/llvm-readobj/ELF/RISCV/validate-attr-section.test | ||
1 ↗ | (On Diff #251292) | "attribute section printing" |
llvm/tools/llvm-readobj/ELFDumper.cpp | ||
2697–2698 | Can we remove this TODO (or at least part of it)? |
Latest veresion basically looks fine. One suggestion and one question remaining from me.
llvm/test/tools/llvm-readobj/ELF/RISCV/invalid-attr-section-size.test | ||
---|---|---|
6 ↗ | (On Diff #252563) | If you want to be more precise with your check (I don't think it matters too much, but it might be good), you can use something like FileCheck -DFILE=%t and change the pattern here to error: '[[FILE]].{{64|32]}.o':. Same would apply in other tests. |
18 ↗ | (On Diff #252563) | Is the size 32-bits even for ELF64? |
llvm/test/tools/llvm-readobj/ELF/RISCV/invalid-attr-section-size.test | ||
---|---|---|
18 ↗ | (On Diff #252563) | Yes, it is a 4-byte unsigned integer according to https://developer.arm.com/docs/ihi0044/h/elf-for-the-arm-architecture-abi-2019q1-documentation. |
LGTM. Please wait for @MaskRay to approve too, since I don't know very much about the details here.
llvm/lib/Support/ELFAttributeParser.cpp | ||
---|---|---|
132 ↗ | (On Diff #252800) | I use vendor-name because <format-version> [ <section-length> "vendor-name" [ <file-tag> <size> <attribute>* | <section-tag> <size> <section-number>* 0 <attribute>* | <symbol-tag> <size> <symbol-number>* 0 <attribute>* ]+ ]* I hope this change can be dropped. |
150 ↗ | (On Diff #252800) | subsection is not very appropriate. The original attribute seems to capture the collection (file/section/symbol) better. |
220 ↗ | (On Diff #252800) | subsection->section is fine, but length->size is not appropriate. |
Consider grouping some llvm-readobj/ELF/RISCV/invalid-*.test tests together. We can make Content a template.
--- !ELF FileHeader: Class: ELFCLASS[[BITS]] Data: ELFDATA2LSB Type: ET_REL Machine: EM_RISCV Sections: - Name: .riscv.attributes Type: SHT_RISCV_ATTRIBUTES Content: [[CONTENT]]
Actually, if we decide to use llvm/unittests a canonical place to test attributes, we should delete most duplicate tests in test/llvm-readobj/ELF/RISCV. The minimum test that ensures llvm-redobj forwards RISCVAttributeParser errors is sufficient.
llvm/test/tools/llvm-readobj/ELF/RISCV/invalid-attr-version.test | ||
---|---|---|
6 ↗ | (On Diff #252800) | These diagnostics should start with error: or warning: |
llvm/test/tools/llvm-readobj/ELF/RISCV/attribute.s | ||
---|---|---|
2 | This should probably go to test/MC/RISCV or test/MC/ELF/RISCV. This is more about a test for assembly. | |
llvm/test/tools/llvm-readobj/ELF/RISCV/invalid-attr-section-size.test | ||
1 ↗ | (On Diff #253582) | We can have one single invalid-*.text. You can find plent of --docnum= examples in llvm-readobj/ELF/ As I mentioned, we don't need many tests testing invalid section contents. We just need to show llvm-readobj forwards RISCVAttributeParser diagnostics, which are already tested by llvm/unittests/ |
llvm/test/tools/llvm-readobj/ELF/RISCV/validate-attr-section.test | ||
1 ↗ | (On Diff #253582) | This can be merged into section-types.test, I think. |
llvm/test/tools/llvm-readobj/ELF/RISCV/attribute.s | ||
---|---|---|
2 | It is not used to test assembly. It is used to test readelf/readelf to decode attribute section correctly. | |
llvm/test/tools/llvm-readobj/ELF/RISCV/invalid-attr-section-size.test | ||
1 ↗ | (On Diff #253582) | That's why I removed other invalid-attr*.test. invalid-attr-section-size.test is used to test the error messages are handled by llvm-readobj. As I mentioned in the test case comments. They are two different test cases. |
llvm/test/tools/llvm-readobj/ELF/RISCV/validate-attr-section.test | ||
1 ↗ | (On Diff #253582) | These two test cases are used for different purpose. I prefer to keep these two test cases. |
Sorry, I spotted the error handling is not using llvm-readobj's style. Please fix it.
llvm/test/tools/llvm-readobj/ELF/RISCV/invalid-attr-version.test | ||
---|---|---|
1 ↗ | (On Diff #253582) | Let's add a top-level comment to this file explaining why this error exists. |
llvm/tools/llvm-readobj/ELFDumper.cpp | ||
2689–2691 | Please use llvm-readobj's reportError function rather than hand-rolling your own error handling. |
llvm/test/tools/llvm-readobj/ELF/RISCV/invalid-attr-version.test | ||
---|---|---|
1 ↗ | (On Diff #254096) | Delete "ELF" - the test is in the ELF directory, so it's obvious that this is testing ELF. |
2 ↗ | (On Diff #254096) | section -> sections |
llvm/tools/llvm-readobj/ELFDumper.cpp | ||
2690 | Thinking about this, this should probably be reportWarning. In general, we don't want the tool to stop processing other options as soon as it sees something bad, as it might well be able to perform those options without any problems. |
When a user specifies an architecture extension which conflicts with an arhitecture attribute, we use the architecture attribute instead of the command line option.