This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readobj][test] - Add a test for testing regular section flags and cleanup flags testing.
ClosedPublic

Authored by grimar on Dec 11 2019, 2:41 AM.

Details

Summary

This:

  1. Adds a test for testing all section flags (section-flags.test).
  2. Renames sec-flags.test->section-arch-flags.test and performs a clean up.
  3. Removes compression.zlib.style.elf-x86-64 binary and a test case for SHF_COMPRESSED flag, because them are now excessive.
  4. Adds missing MIPS flags and a test for SHF_ARM_PURECODE.

Diff Detail

Event Timeline

grimar created this revision.Dec 11 2019, 2:41 AM
jhenderson added inline comments.Dec 11 2019, 3:39 AM
llvm/test/tools/llvm-readobj/ELF/section-arch-flags.test
2

Probably this should be deferred to a later change, but I think this test should be extended to

  1. cover the remaining arch-specific flags defined in BinaryFormat/ELF.h.
  2. show that arch-specific flags not known for the current file format (e.g. SHF_MIPS_MERGE for an X86_64 ELF) are handled appropriately.
4

Maybe '>' -> '-o'?

4–6

Here and elsewhere in this test whilst you're moving it, could you change single dash long-options to double-dash ones please (--docnum, --check-prefix etc).

21

I believe this line can be deleted?

26

You could delete the Size parameter to slightly simplify ever test case here, I think.

77

Nit: unnecessary ...

llvm/test/tools/llvm-readobj/ELF/section-flags.test
4

-o?

5–6

--check-prefix

22

Don't know if this should be in this or another test, but we should also test:

  1. Unknown flags outside any reserved range.
  2. Flags in the OS-specific range.
grimar updated this revision to Diff 233359.Dec 11 2019, 6:47 AM
grimar marked 13 inline comments as done.
  • Addressed review comments.
llvm/test/tools/llvm-readobj/ELF/section-arch-flags.test
2

cover the remaining arch-specific flags defined in BinaryFormat/ELF.h.

This test case originally covered EM_HEXAGON, EM_MIPS and EM_X86_64. It did not cover EM_ARM and EM_XCORE.
I've added a case for EM_ARM. I had to skip EM_XCORE for now because yaml2obj does not seem to support this machine type yet.
(I'll add a case for EM_XCORE in a follow-up change after teaching the yaml2obj tool if you do not mind).

I've also added missing MIPS flags.

show that arch-specific flags not known for the current file format (e.g. SHF_MIPS_MERGE for an X86_64 ELF) are handled appropriately.

I think it is not possible atm, because yaml2obj handles flags as a bit set and report when sees an unknown used bit:
YAML:117:14: error: unknown bit value
I.e. I can't just use 0x20000000 (which is a SHF_ARM_PURECODE/SHF_MIPS_MERGE) inside`Flags []`, for example.

Seems we might want to implement a ShFlags property, similar to other Sh* stuff we have.
What about I do this in a follow-up too?

4–6

I'll try to pay more attention to such things during test cases moving next time.

21

Done.

26

Done.

llvm/test/tools/llvm-readobj/ELF/section-flags.test
22

This also needs something like a ShFlags property to write a test. Follow-up?

jhenderson added inline comments.Dec 11 2019, 7:12 AM
llvm/test/tools/llvm-readobj/ELF/section-arch-flags.test
2

Sounds good. I wasn't expecting you to extend this test right now!

34–35

Where have these two flags come from?

SHF_MASKPROC in particular is concerning, since it's a range delimiter, not an actual value... That's probably a bug.

55–56

Spacing here isn't quite consistent at the start and end of the list.

llvm/test/tools/llvm-readobj/ELF/section-flags.test
22

Yup, sounds good.

grimar updated this revision to Diff 233547.Dec 12 2019, 2:43 AM
grimar marked 3 inline comments as done.
  • Addressed review comments.
grimar edited the summary of this revision. (Show Details)Dec 12 2019, 2:44 AM
grimar added inline comments.Dec 12 2019, 2:45 AM
llvm/test/tools/llvm-readobj/ELF/section-arch-flags.test
34–35

The code related is:
https://github.com/llvm-mirror/llvm/blob/master/tools/llvm-readobj/ELFDumper.cpp#L1131
https://github.com/llvm-mirror/llvm/blob/master/tools/llvm-readobj/ELFDumper.cpp#L5358

I.e. for LLVM style it pushes all the SHF_*, including masks to array and prints all of them.

GNU style is a bit different, it drops the bits during proccessing:
https://github.com/llvm-mirror/llvm/blob/master/tools/llvm-readobj/ELFDumper.cpp#L1176

But note that 'SHF_EXCLUDE' has the same value as 'SHF_MIPS_STRING`:

// This section is excluded from the final executable or shared library.
SHF_EXCLUDE = 0x80000000U,
// Section data is string data by default.
SHF_MIPS_STRING = 0x80000000,

So we probably should not attemp to drop them in LLVM style. That is why
we print both SHF_EXCLUDE and SHF_MIPS_STRING flags.

The situation with the SHF_MASKPROC is similar. It has value of 0xf0000000,
and the value of SHF_MIPS_GPREL + SHF_MIPS_MERGE + SHF_MIPS_ADDR + SHF_MIPS_STRING
also gives us 0xf0000000. Though in this SHF_MASKPROC it is a mask value and I agree
that we should not print SHF_MASKPROC (and SHF_MASKOS).
So I think we should add a test showing that them are not printed, for example
when the flag value is 0xffffffff. For that we need a yam2obj change discussed to
be done first.

I've added a FIXME comment here and do that in the follow-up too.
(If you think we should do a change for yaml2obj first, please say.)

FTR, I've also tried to use both mips-linux-gnu-readelf and regular x86 readelf and got:

  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .mips             PROGBITS        00000000 000034 000000 00 Dop  0   0  0
...
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  p (processor specific)

I.e. it prints "D" instead of "E", but doesn't give an explanation about what it is.

jhenderson accepted this revision.Dec 12 2019, 2:46 AM

LGTM. One comment, for a possible follow-up.

llvm/test/tools/llvm-readobj/ELF/section-arch-flags.test
34

Do you think we should avoid printing SHF_EXCLUDE for MIPS, since it clashes?

This revision is now accepted and ready to land.Dec 12 2019, 2:46 AM
jhenderson added inline comments.Dec 12 2019, 2:47 AM
llvm/test/tools/llvm-readobj/ELF/section-arch-flags.test
34

Never mind, you posted your comments as I was writing mine. It probably should be up to a MIPS developer to discuss this point.

grimar marked 3 inline comments as done.Dec 12 2019, 2:52 AM
grimar added inline comments.
llvm/test/tools/llvm-readobj/ELF/section-arch-flags.test
34

Yeah, sorry, I've pushed it a minute later that the patch itself.

Answering this question I actually kind of confused why they used the similar
value. It's indeed up to them what to do with it.. Perhaps leaving it alone is not so
bad for the code.

This revision was automatically updated to reflect the committed changes.
grimar marked an inline comment as done.