Add file with Xtensa ELF relocations. Add Xtensa support to ELF.h,
ELFObject.h and ELFYAML.cpp. Add simple test of Xtensa ELF representation in YAML.
Details
Diff Detail
Event Timeline
llvm/include/llvm/BinaryFormat/ELF.h | ||
---|---|---|
778 | I took as a basis naming conventions of the e_flags from binutils (binutils/include/elf/xtensa.h). There used similar names for the architecture mask and base machine architecture with only differenece in prefix (E_ or EF_). | |
llvm/include/llvm/BinaryFormat/ELFRelocs/Xtensa.def | ||
12 | It is missing also in binutils (binutils/include/elf/xtensa.h). So I left it as is. |
LGTM, but I know very little about the LLVM backend.
Also, I see that this patch lacks one change that are included by the very similar RISC-V patch: https://github.com/lowRISC/riscv-llvm/blob/master/0003-RISCV-Add-RISC-V-ELF-defines.patch, namely the equivalent of ElfHeaderRISCVFlags in ELFDumper.cpp. I don't know whether that has a reason but mentioning it just in case.
llvm/include/llvm/BinaryFormat/ELF.h | ||
---|---|---|
778 | Looking at https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=include/elf/msp430.h for comparison, they use EF_<arch>_MACH for the mask and E_<arch>_MACH_<sub> for what seems to be the sub-architecture. I see a very similar pattern for AVR. In both cases, LLVM still uses the EF_ prefix for the subarch. |
llvm/include/llvm/BinaryFormat/ELF.h | ||
---|---|---|
775 | Use // as the rest of the file uses. | |
llvm/include/llvm/BinaryFormat/ELFRelocs/Xtensa.def | ||
2 | Add a test test/tools/llvm-readobj/reloc-types-elf-xtensa.test | |
llvm/test/Object/Xtensa/elf-flags.yaml | ||
1 ↗ | (On Diff #210194) | Delete this file. Add to test/Object/obj2yaml.test instead. You may follow the ELF-X86-64: yaml2obj+obj2yaml test. |
llvm/test/Object/Xtensa/lit.local.cfg | ||
3 ↗ | (On Diff #210194) | Delete this file. |
Patch is updated according to latest upstream version. The E_XTENSA_MACH_BASE symbol changed to EF_XTENSA_MACH_BASE.
Add Xtensa ELF relocations test. Move ELF flags test from "llvm/test/Object/Xtensa/" directory to test/Object/obj2yaml.test.
llvm/include/llvm/BinaryFormat/ELF.h | ||
---|---|---|
778 | Changed E_XTENSA_MACH to EF_XTENSA_MACH_BASE |
llvm/test/Object/obj2yaml.test | ||
---|---|---|
753 | Rather than adding a pre-canned binary, use yaml2obj to generate a file. | |
llvm/test/tools/llvm-readobj/ELF/reloc-types-elf-xtensa.test | ||
1 ↗ | (On Diff #243466) | No need for "elf" to be in the file name, since it's in the ELF subdirectory. |
183 ↗ | (On Diff #243466) | Delete extra blank line here. |
Correction of the llvm/test/tools/ llvm-readobj/ELF/reloc-types-elf-xtensa.test file (renaming to reloc-types-xtensa.test, and also delete the empty line at the end of file).
llvm/test/Object/obj2yaml.test | ||
---|---|---|
753 | You suggest to create separate obj2yaml test for Xtensa? |
llvm/test/Object/obj2yaml.test | ||
---|---|---|
753 | There is no risk in yaml2obj picking the wrong yaml block. You can use the --docnum=<index> switch to specify which one to use, where <index> indicates which doc to use (e.g. --docnum=1 for the first, --docnum=2 for the second etc). See various other examples in the llvm-readobj tests for how. |
Correction of the llvm/test/Object/obj2yaml.test, now Xtensa test uses yaml2obj instead of pre-built binary trivial-object-test.elf-xtensa.
llvm/test/Object/obj2yaml.test | ||
---|---|---|
753 | Now Xtensa test uses yaml2obj instead of pre-built binary |
There should be an llvm-readobj test for the xtensa file header (machine type + flags).
llvm/include/llvm/BinaryFormat/ELFRelocs/Xtensa.def | ||
---|---|---|
2 | (Not specific to your change, but I don't understand why .def files don't seem to have any licence information) | |
llvm/test/Object/obj2yaml.test | ||
667 | It looks weird to me seeing a difference in the inptut Flags and printed Flags. Is EF_XTENSA_MACH_BASE a marker (like SHT_LORESERVE etc) or an actual flag? If it's only a marker, we shouldn't dump it. | |
675 | This should specify all EF_XTENSA flags, to show that they all work. |
Change EF_XTENSA_MACH_BASE to EF_XTENSA_MACH_NONE, it seems this is closer to ELF flag naming style used for AMDGPU and MIPS.
llvm/include/llvm/BinaryFormat/ELFRelocs/Xtensa.def | ||
---|---|---|
2 | I also noticed that and I thought that this is some kind of coding style and decided to follow it. | |
llvm/test/Object/obj2yaml.test | ||
667 | The situation is that EF_XTENSA_MACH_NONE (EF_XTENSA_MACH_BASE) defines default architecture, this flag equals 0x00 and it printed even in case of empty input flags set. Similar situation can be observed in AMDGPU tests, for example in llvm\test\Object\AMDGPU\elf-header-flags-xnack.yaml flag EF_AMDGPU_MACH_NONE. But I added this flag for input flags in Xtensa test to avoid confusion. | |
675 | Added rest Xtensa ELF flags |
llvm/include/llvm/BinaryFormat/ELF.h | ||
---|---|---|
776 | Just trying to understand this: is this a mask for some other information? Perhaps worth saying that in the comment above if so (e.g. "Four-bit Xtensa machine type mask"). | |
llvm/include/llvm/BinaryFormat/ELFRelocs/Xtensa.def | ||
12 | Is there an xtensa specification anywhere? | |
llvm/test/Object/obj2yaml.test | ||
667 |
Is printed by what? GNU readelf? I think not having it in the input flags would be fine, if this line is accompanied by a comment saying something like "As EF_XTENSA_MACH_NONE == 0, it is always printed." |
llvm/include/llvm/BinaryFormat/ELF.h | ||
---|---|---|
776 | Comment is corrected | |
llvm/include/llvm/BinaryFormat/ELFRelocs/Xtensa.def | ||
12 | There is some description of the Xtensa relocations in GNU Binutils ( in binutils/bfd/doc/bfd.info file and source code). As I understand most of ELF relocations for other architectures in LLVM are imported from binutils, so the same approach was used for Xtensa. | |
llvm/test/Object/obj2yaml.test | ||
667 | The EF_XTENSA_MACH_NONE removed from input flags and added comment which explains why EF_XTENSA_MACH_NONE is printed by obj2yaml. |
llvm/test/Object/obj2yaml.test | ||
---|---|---|
667 | You never answered this question:
From what I piece together from the comments and flag names, EF_XTENSA_MACH_NONE is effectively saying "there are no other EF_XTENSA_MACH_* bits sets". Given that, I would expect to NOT see this flag in obj2yaml or llvm-readobj output, if any of the bits covered by the EF_XTENSA_MACH mask are set. This of course might require some extra logic. | |
llvm/test/tools/llvm-readobj/ELF/reloc-types-xtensa.test | ||
2 | for the Xtensa | |
5 | Your comment says both llvm-readobj and llvm-readelf, but you only test one of those. As the code is generic, that's fine, but probably best to remove the llvm-readelf reference from the comment. |
llvm/test/tools/llvm-readobj/ELF/reloc-types-xtensa.test | ||
---|---|---|
5 | Corrected |
llvm/test/Object/obj2yaml.test | ||
---|---|---|
667 | The EF_XTENSA_MACH_NONE is printed only by obj2yaml and it is printed only in case when ((ELF_FLAGS & EF_XTENSA_MACH) == 0 ). I checked this situation using dummy architecture flag like (EF_XTENSA_ARCH_1 = 0x1) and verified that obj2yaml prints only EF_XTENSA_ARCH_1 without EF_XTENSA_MACH_NONE. I'm not sure that we must add Xtensa ELF flags to llvm-readobj, because it seems that in ELFDumper.cpp only RISCV / AMDGPU / Mips ELF flags are processed. |
llvm/test/tools/llvm-readobj/ELF/reloc-types-xtensa.test | ||
---|---|---|
5 | Delete --expand-relocs and you will be able to use CHECK-NEXT: instead of CHECK:. |
llvm/test/Object/obj2yaml.test | ||
---|---|---|
667 |
Thanks.
This seems like a circular argument to me. Surely it only supports those other flags, because Xtensa flags haven't been implemented in it yet? FWIW, adding support should probably be a separate change, but please do implement that patch, as otherwise I consider this functionality incomplete. |
Patch is updated according to LLVM upstream version and latest Xtensa backend version.
llvm/test/Object/Xtensa/lit.local.cfg | ||
---|---|---|
3 ↗ | (On Diff #210194) | I suggest to add llvm/test/Object/Xtensa/elf-header-flags.yaml and llvm/test/Object/Xtensa/li.local.cfg to test llvm-readobj. What is your opinion on this? |
llvm/include/llvm/Object/ELFObjectFile.h | ||
---|---|---|
1088–1089 | I don't see any testing for this here? | |
llvm/test/Object/Xtensa/elf-header-flags.yaml | ||
4 ↗ | (On Diff #329497) | You can avoid having a second YAML DOC by using yaml2obj's -D option, which allows you to define a variable. See other yaml2obj examples in various tests. |
6 ↗ | (On Diff #329497) | obj2yaml testing should be done in test\tools\obj2yaml. There's no need for it here too. |
1 ↗ | (On Diff #328692) | Please add a comment to this file explaining what the test is testing. |
llvm/test/Object/Xtensa/lit.local.cfg | ||
3 ↗ | (On Diff #210194) | The ability to check the ELF flags does not require the Xtensa target to be enabled. You only need to mark such tests as unsupported if they actually do require the enabling of that target, otherwise more people won't run the tests and there's a higher chance they'll break due to somebody's change, without them noticing. |
llvm/test/tools/llvm-readobj/ELF/reloc-types-elf-xtensa.test | ||
7 ↗ | (On Diff #329497) | We normally add spaces to make the checked values line up neatly, as suggested inline. |
1 ↗ | (On Diff #243466) | "elf" is still in the file name. Please remove it. |
llvm/test/tools/llvm-readobj/ELF/reloc-types-elf-xtensa.test | ||
---|---|---|
1 ↗ | (On Diff #243466) | I changed file name to reloc-types-xtensa.test |
llvm/include/llvm/Object/ELFObjectFile.h | ||
---|---|---|
1088–1089 | I added test to llvm/unittests/Object/ELFObjectFileTest.cpp |
llvm/test/Object/Xtensa/elf-header-flags.yaml | ||
---|---|---|
6 ↗ | (On Diff #329497) | I'm agree, probably obj2yaml testing of the ELF flags is even redundant because it already implemented in llvm/test/Object/obj2yaml.test. @jhenderson I suggest to implement "llvm/test/tools/llvm-readobj/ELF/xtensa-elf-flags.test" test instead of "llvm/test/Object/Xtensa/elf-header-flags.yaml". What do you think about this? |
llvm/test/tools/llvm-readobj/ELF/xtensa-elf-flags.test | ||
---|---|---|
1 ↗ | (On Diff #333474) | Rename this to xtensa-header-flags.test. This should hopefully make it clear that these are flags for the ELF header, without the redundant elf in the filename. |
3–7 ↗ | (On Diff #333474) | Use a different filename for the files. That way, if the test breaks, you can easily compare the two files. This is generally very useful for debugging. I'd also drop ELF- from the prefixes, since they don't add any value. I've suggested a possible name inline. |
LGTM, with one test nit. You might want to give it a couple of days to see if any of the other reviewers have further comments to make.
llvm/test/tools/llvm-readobj/ELF/xtensa-header-flags.test | ||
---|---|---|
9–12 ↗ | (On Diff #333612) | No need for the extra indentation. |
llvm/include/llvm/BinaryFormat/ELFRelocs/Xtensa.def | ||
---|---|---|
6 | Don't use a space for macro calls. |
Removed spaces in macro calls in Xtensa.def. Also removed extra indentation in xtensa-header-flags.test.
llvm/test/Object/obj2yaml.test | ||
---|---|---|
527 | All other architectures put their input in a separate file to avoid this. |
llvm/test/Object/obj2yaml.test | ||
---|---|---|
527 | Are you referring to the yaml2obj line or the use of --docnum? All other files use pre-canned binaries, which are not ideal, as they are fixed and hard to inspect/understand/update. Using yaml2obj is generally preferable for creating objects at test time. |
llvm/test/Object/obj2yaml.test | ||
---|---|---|
527 | Oh you're right. Hm. --docnum=N for each architecture would start to get a bit silly though... I do wonder why we don't have one .test file for each architecture being tested, then you don't need to play --docnum or Inputs/foo.yaml games (and even for pre-canned binaries it keeps the tests nicely separated rather than having an 800-odd line file). |
Patch is updated according to LLVM upstream version and latest Xtensa backend version.
Still looks good to me, but someone with Xtensa knowledge needs to approve to confirm the flags etc are correct.
llvm/test/Object/obj2yaml.test | ||
---|---|---|
527 | That would be reasonable. I think it's a legacy of how this test was written. In fact, having an obj2yaml test inside the Object library tests is a bit weird - it should either be in ObjectYAML or more likely tools\obj2yaml. Feel free to tidy things up! (Apologies, I wrote this commenet ages ago, but forgot to submit it). |
OK with one minor change.
llvm/include/llvm/BinaryFormat/ELFRelocs/Xtensa.def | ||
---|---|---|
12 | To the best of my knowledge Xtensa does not have a formal elf specification. They definitely didn't a in the years I worked there. The binutils implementation governed. My recollection is very hazy almost twenty years later, but I believe 7 was used in some experiments during the original port and we later determined it wasn't useful. But by the time we removed it, the other assignments had already been made. I think instead of leaving it unused and blank, we should use something like: ELF_RELOC(R_XTENSA_RESERVED_7, 7) which will better show that this isn't a mistake. and probably what we should have done originally. |
llvm/include/llvm/BinaryFormat/ELFRelocs/Xtensa.def | ||
---|---|---|
12 | I disagree, such constants achieve nothing, as nothing should be using them. Just put a comment if you want to make it clear it’s deliberately not assigned a name here. |
llvm/include/llvm/BinaryFormat/ELFRelocs/Xtensa.def | ||
---|---|---|
12 | Added comment about RELOC '7' |
llvm/include/llvm/BinaryFormat/ELFRelocs/Xtensa.def | ||
---|---|---|
13 | Nit: comments should end with full stops. |
Hi everyone. Since this has been accepted for some time now, we're planning to commit this on Monday (December 16th). Please let us know if there is anything else we should address.
llvm/unittests/Object/ELFObjectFileTest.cpp | ||
---|---|---|
317 ↗ | (On Diff #484117) | This can use llvm::enumerate, but it's ok to follow other tests. |
Use // as the rest of the file uses.