This is an archive of the discontinued LLVM Phabricator instance.

[Xtensa 2/10] Add Xtensa ELF definitions.
ClosedPublic

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
863

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
863

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
863

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
860

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
863

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
787

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
787

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
787

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
787

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
689

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.

697

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
689

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.

697

Added rest Xtensa ELF flags

jhenderson added inline comments.Feb 18 2020, 2:39 AM
llvm/include/llvm/BinaryFormat/ELF.h
861

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
689

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
861

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
689

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
689

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
689

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
689

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

andreisfr updated this revision to Diff 328692.Mar 5 2021, 4:39 PM

Patch is updated according to latest upstream version. Added llvm-readobj test.

andreisfr marked an inline comment as done.Mar 5 2021, 4:45 PM
andreisfr added inline comments.
llvm/test/Object/obj2yaml.test
689

Added Xtensa ELF flags to llvm-readobj, also implemented test

llvm/test/tools/llvm-readobj/ELF/reloc-types-elf-xtensa.test
183 ↗(On Diff #243466)

Corrected

andreisfr updated this revision to Diff 329497.Mar 9 2021, 4:48 PM

Patch is updated according to LLVM upstream version and latest Xtensa backend version.

andreisfr marked 2 inline comments as done.Mar 9 2021, 4:57 PM
andreisfr added inline comments.Mar 9 2021, 5:01 PM
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?

jhenderson added inline comments.Mar 19 2021, 2:54 AM
llvm/include/llvm/Object/ELFObjectFile.h
1204–1205

I don't see any testing for this here?

llvm/test/Object/Xtensa/elf-header-flags.yaml
1 ↗(On Diff #328692)

Please add a comment to this file explaining what the test is testing.

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.

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.

andreisfr updated this revision to Diff 333474.Mar 25 2021, 5:34 PM

Corrected according to review comments

andreisfr marked 2 inline comments as done.Mar 25 2021, 5:40 PM
andreisfr added inline comments.
llvm/test/tools/llvm-readobj/ELF/reloc-types-elf-xtensa.test
1 ↗(On Diff #243466)

I changed file name to reloc-types-xtensa.test

andreisfr marked an inline comment as done.Mar 25 2021, 5:41 PM
andreisfr added inline comments.
llvm/include/llvm/Object/ELFObjectFile.h
1204–1205

I added test to llvm/unittests/Object/ELFObjectFileTest.cpp

andreisfr added inline comments.Mar 25 2021, 5:47 PM
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?

jhenderson added inline comments.Mar 26 2021, 1:35 AM
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.

andreisfr updated this revision to Diff 333612.Mar 26 2021, 1:06 PM

Corrected llvm-readobj test

andreisfr added inline comments.Mar 26 2021, 1:12 PM
llvm/test/tools/llvm-readobj/ELF/xtensa-elf-flags.test
1 ↗(On Diff #333474)

File name is renamed to xtensa-header-flags.test.

3–7 ↗(On Diff #333474)

Thank you for suggestions, I corrected this code in xtensa-header-flags.test

jhenderson accepted this revision.Mar 29 2021, 12:10 AM

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
10–13

No need for the extra indentation.

This revision is now accepted and ready to land.Mar 29 2021, 12:10 AM
MaskRay accepted this revision.Mar 29 2021, 12:15 AM
MaskRay added inline comments.
llvm/include/llvm/BinaryFormat/ELFRelocs/Xtensa.def
6

Don't use a space for macro calls.

andreisfr updated this revision to Diff 334835.Apr 1 2021, 3:15 PM

Removed spaces in macro calls in Xtensa.def. Also removed extra indentation in xtensa-header-flags.test.

andreisfr added inline comments.Apr 1 2021, 3:16 PM
llvm/include/llvm/BinaryFormat/ELFRelocs/Xtensa.def
6

Corrected, also aligned right parentheses

llvm/test/tools/llvm-readobj/ELF/xtensa-header-flags.test
10–13

Corrected

jrtc27 added a subscriber: jrtc27.Jun 8 2021, 5:39 AM
jrtc27 added inline comments.
llvm/test/Object/obj2yaml.test
550

All other architectures put their input in a separate file to avoid this.

jhenderson added inline comments.Jun 8 2021, 5:53 AM
llvm/test/Object/obj2yaml.test
550

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.

jrtc27 added inline comments.Jun 8 2021, 5:56 AM
llvm/test/Object/obj2yaml.test
550

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
550

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

andreisfr updated this revision to Diff 425064.Apr 25 2022, 5:13 PM

Patch is updated according to LLVM upstream version

Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2022, 5:13 PM
Herald added a subscriber: StephenFan. · View Herald Transcript
saugustine accepted this revision.Aug 19 2022, 11:34 AM
saugustine added a subscriber: saugustine.

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.

jrtc27 added inline comments.Aug 19 2022, 11:38 AM
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.

andreisfr updated this revision to Diff 455439.Aug 24 2022, 5:52 PM

Minor changes, added a comment to the Xtensa ELF relocations file.

andreisfr added inline comments.Aug 24 2022, 6:12 PM
llvm/include/llvm/BinaryFormat/ELFRelocs/Xtensa.def
12

Added comment about RELOC '7'

jhenderson added inline comments.Aug 25 2022, 2:16 AM
llvm/include/llvm/BinaryFormat/ELFRelocs/Xtensa.def
13

Nit: comments should end with full stops.

phosek added a subscriber: phosek.Sep 1 2022, 11:42 AM
andreisfr updated this revision to Diff 461112.Sep 18 2022, 6:16 PM

Corrected comment

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

Corrected

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.

andreisfr updated this revision to Diff 484117.Dec 19 2022, 3:38 PM

Updated according to latest changes in upstream source code

MaskRay accepted this revision.Dec 19 2022, 4:00 PM
MaskRay added inline comments.
llvm/unittests/Object/ELFObjectFileTest.cpp
304

This can use llvm::enumerate, but it's ok to follow other tests.

andreisfr updated this revision to Diff 485247.Dec 25 2022, 4:20 PM

Updated according to latest changes in upstream source code

This revision was landed with ongoing or failed builds.Dec 26 2022, 4:39 AM
This revision was automatically updated to reflect the committed changes.