Page MenuHomePhabricator

[Xtensa 2/10] Add Xtensa ELF definitions.
Needs ReviewPublic

Authored by andreisfr on Jul 16 2019, 3:18 PM.

Details

Summary

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.

Diff Detail

Event Timeline

andreisfr created this revision.Jul 16 2019, 3:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 16 2019, 3:18 PM
appcs added a reviewer: appcs.Jul 16 2019, 3:55 PM
appcs added inline comments.Jul 16 2019, 3:59 PM
llvm/include/llvm/BinaryFormat/ELF.h
778

Typo? (Just making sure it isn't).

llvm/include/llvm/BinaryFormat/ELFRelocs/Xtensa.def
12

Just making sure a '7' RELOC is not missing.

andreisfr marked 2 inline comments as done.Jul 17 2019, 3:09 PM
andreisfr added inline comments.
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.

aykevl added a subscriber: aykevl.Aug 17 2019, 5:07 PM

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.
For consistency with the other architectures in LLVM, it might be better to use something like EF_XTENSA_MACH_BASE. However, I have no idea why these constants are given these names in LLVM or binutils.

MaskRay added inline comments.
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.

andreisfr updated this revision to Diff 242200.Feb 3 2020, 3:01 PM
andreisfr marked an inline comment as done.

Patch is updated according to latest upstream version. The E_XTENSA_MACH_BASE symbol changed to EF_XTENSA_MACH_BASE.

andreisfr updated this revision to Diff 243466.Feb 9 2020, 4:46 PM

Add Xtensa ELF relocations test. Move ELF flags test from "llvm/test/Object/Xtensa/" directory to test/Object/obj2yaml.test.

andreisfr marked 3 inline comments as done and 2 inline comments as done.Feb 9 2020, 4:51 PM
andreisfr added inline comments.
llvm/include/llvm/BinaryFormat/ELF.h
778

Changed E_XTENSA_MACH to EF_XTENSA_MACH_BASE

andreisfr marked 5 inline comments as done.Feb 9 2020, 4:52 PM
jhenderson added inline comments.Feb 10 2020, 2:18 AM
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.

andreisfr updated this revision to Diff 244128.Feb 12 2020, 4:09 AM

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).

andreisfr added inline comments.Feb 12 2020, 4:26 AM
llvm/test/Object/obj2yaml.test
753

You suggest to create separate obj2yaml test for Xtensa?
Or add Xtensa ELF header yaml description in current file? I'm bother that there is already X86 ELF yaml description in this file, so yaml2obj could produce wrong result while processing obj2yaml.test. As I'm understand that is a reason why tests foir all other architectures in this file use pre-canned binaries.

jhenderson added inline comments.Feb 12 2020, 4:31 AM
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.

andreisfr marked an inline comment as done.Feb 12 2020, 12:49 PM
andreisfr added inline comments.
llvm/test/Object/obj2yaml.test
753

Now Xtensa test uses yaml2obj instead of pre-built binary

andreisfr marked an inline comment as not done.Feb 12 2020, 1:04 PM

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.

andreisfr updated this revision to Diff 244900.Feb 16 2020, 3:05 PM

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.

andreisfr updated this revision to Diff 244903.Feb 16 2020, 3:50 PM

Correct Xtensa ELF flag test

andreisfr added inline comments.Feb 16 2020, 4:12 PM
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

jhenderson added inline comments.Feb 18 2020, 2:39 AM
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

it printed even in case of empty input flags set.

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."

andreisfr updated this revision to Diff 245366.Feb 19 2020, 3:20 AM

Correction of comments and Xtensa ELF flags test.

andreisfr added inline comments.Feb 19 2020, 3:44 AM
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.

jhenderson added inline comments.Feb 24 2020, 7:58 AM
llvm/test/Object/obj2yaml.test
667

You never answered this question:

Is printed by what? GNU readelf?

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
3

for the Xtensa

6

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.

andreisfr updated this revision to Diff 247387.Feb 28 2020, 4:04 PM

Correct relocations test for the Xtensa target

andreisfr marked 3 inline comments as done.Feb 28 2020, 4:04 PM
andreisfr added inline comments.
llvm/test/tools/llvm-readobj/ELF/reloc-types-xtensa.test
6

Corrected

andreisfr marked an inline comment as done.Feb 28 2020, 4:25 PM
andreisfr added inline comments.
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.

MaskRay added inline comments.Feb 28 2020, 6:01 PM
llvm/test/tools/llvm-readobj/ELF/reloc-types-xtensa.test
6

Delete --expand-relocs and you will be able to use CHECK-NEXT: instead of CHECK:.

jhenderson added inline comments.Mar 2 2020, 12:54 AM
llvm/test/Object/obj2yaml.test
667

... and verified that obj2yaml prints only EF_XTENSA_ARCH_1 without EF_XTENSA_MACH_NONE.

Thanks.

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.

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.