This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objdump] Add testing for --print-imm-hex, --headers, --section-headers and --private-headers
ClosedPublic

Authored by gbreynoo on Jun 9 2021, 10:11 AM.

Details

Summary

llvm-objdump had some missing coverage that is fixed by this change:

  • A test specifically for --print-imm-hex, and coverage of --no-print-imm-hex
  • section-headers.test checks the aliases --headers or --section-headers
  • A test for the use of --private-headers for ELF that checks the output

Diff Detail

Event Timeline

gbreynoo created this revision.Jun 9 2021, 10:11 AM
gbreynoo requested review of this revision.Jun 9 2021, 10:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 9 2021, 10:11 AM
gbreynoo added inline comments.Jun 9 2021, 10:14 AM
llvm/test/tools/llvm-objdump/ELF/private-headers.test
17

I'm new to yaml2obj so there may well be a simpler way to do this.

llvm/test/tools/llvm-objdump/X86/print-imm-hex.s
7

The assembly here was taken from another test, I'm happy to change it if a better sample can be suggested.

jhenderson added inline comments.Jun 10 2021, 12:24 AM
llvm/test/tools/llvm-objdump/ELF/private-headers.test
2

Add a comment to the start of the test briefly outlining the test purpose.

A quick skim suggests this is essentially the only testing for dumping this information for llvm-objdump for ELF. I'm guessing the code path is completely unrelated to the Mach-O equivalent behaviour, so it looks like it needs far more thorough testing, showing that all the various properties can be dumped correctly (e.g. all the different flags). Take a look at the equivalent llvm-readobj testing for an idea of what would be best.

Assuming more widespread testing is added, I'd split this up into separate testing for each of the different things (program header/version info/dynamic section) and then have a very minimal test that shows that --private-headers dumps all three.

10

Nit: here and below, add additional spaces between CHECK: and "Dynamic Section"/"Version definitions" to make things nicely line up.

27–28

If memory serves me correctly, the combination of a size and content will tail-pad the content with null bytes to make the appropriate size. I'm guessing this isn't what you wanted?

It would be helpful to have a comment spelling out what this content represents.

31

This looks awfully suspicious. Your previous section starts at address 0x1000 but is more than 0x10 bytes in size, so this address couldn't possibly be correct. You don't actually need to explicitly specify the address - yaml2obj will automatically increment it as necessary (but you'll need to add the SHF_ALLOC section flag, which you want anyway, since these are sections with addresses).

32

I might be wrong, but I believe yaml2obj automatically assigns the Link value for .dynamic to .dynstr. Even if it doesn't, you should be able to specify the section name rather than the index.

40–41

I think you probably don't need these fields?

llvm/test/tools/llvm-objdump/X86/print-imm-hex.s
7

Which other test was this taken from and why did you pick it?

MaskRay added inline comments.Jun 13 2021, 11:17 AM
llvm/test/tools/llvm-objdump/ELF/private-headers.test
2

{,llvm-|objdump -p / --private-headers dumps program headers, the dynamic section, and GNU symbol versioning sections.

dynamic-section.test tests -p but there is no test in this directory testing --private-headers.

12

For versions. llvm-readobj/ELF/ has some llvm-readelf -V tests which may be used as a reference.

MaskRay requested changes to this revision.Jun 16 2021, 1:31 PM

Ping:)

This revision now requires changes to proceed.Jun 16 2021, 1:31 PM
gbreynoo updated this revision to Diff 353594.Jun 22 2021, 3:56 AM
gbreynoo marked 9 inline comments as done.

I followed jhendersons suggestions regarding whitespace, the YAML in private-headers.test and adding a test program-headers.test based off the equivalent llvm-readobj test. With this last point I found the following:

  • Unlike llvm-readobj, ARM and MIPs specific program header type's are not printed.
  • Unlike llvm-readobj, there is no warning when a program interpreter name is non-null-terminated or when PT_INTERP has an offset that goes past the end of the file.
  • llvm-objdump has test cases here when a warning and error with effectively the same message are output together. This is due to the call to printELFFileHeader returning early in these cases with a warning, but the following call to printELFDynamicSection ending with an error for the same issue.

Regarding the three points above, I presume they are not expected behaviour and so will create bugzilla tickets for them.

Thanks for your patience Maskray.

llvm/test/tools/llvm-objdump/ELF/private-headers.test
2

As MaskRay says there is already dynamic-section.test for the ELF dynamic section. There is verdef.test for version definitions and I’ve added program-headers.test for program header output. I saw there was no ELF specific test for use of –private-headers (rather than -p) except for invalid-phdr.test so a test to ensure output was as expected would be useful even if the output was partially covered in other tests. Although I originally was only going to check for the strings Program Header, Dynamic Section and Version definitions, similar to how –headers is tested in llvm-readobj, I thought extra coverage like this wouldn’t hurt?

12

Is this coverage sufficient considering we already have verdef.test? I am happy to make changes here if not.

llvm/test/tools/llvm-objdump/X86/print-imm-hex.s
7

I took this from disassemble-align.s as it was an existing example of disassembled output that had values that can be converted to hex.

gbreynoo added inline comments.Jun 22 2021, 3:59 AM
llvm/test/tools/llvm-objdump/ELF/private-headers.test
40–41

To test the symbol version info output I wanted something here.

MaskRay accepted this revision.Jun 23 2021, 12:02 PM
MaskRay added inline comments.
llvm/test/tools/llvm-objdump/X86/print-imm-hex.s
2

-triple=x86_64-unknown-linux => -triple=x86_64 this tests generic ELF behavior.

This revision is now accepted and ready to land.Jun 23 2021, 12:02 PM