This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readobj] - Teach readobj to recognize SHF_COMPRESSED flag.
ClosedPublic

Authored by grimar on May 15 2016, 4:28 AM.

Details

Summary

Main problem here was that SHF_COMPRESSED has the same value with XCORE_SHF_CP_SECTION,
which was included as standart (common) flag.
As far I understand xCore is a family of controllers and it that means it's constant should be processed separately,
only if e_machine == EM_XCORE, otherwise llvm-readobj would ouput different constants twice for compressed section:

SHF_COMPRESSED (0x800)
....
XCORE_SHF_CP_SECTION (0x800)

what probably does not make sence if you're not working with xcore file.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar updated this revision to Diff 57293.May 15 2016, 4:28 AM
grimar retitled this revision from to [llvm-readobj] - Teach readobj to recognize SHF_COMPRESSED flag..
grimar updated this object.
grimar added reviewers: davide, rafael, ruiu, echristo.
grimar added subscribers: llvm-commits, grimar.
rafael accepted this revision.May 15 2016, 8:23 AM
rafael edited edge metadata.

LGTM with a testcase.

This revision is now accepted and ready to land.May 15 2016, 8:23 AM
davide edited edge metadata.May 15 2016, 10:53 AM

Add a test case, please. With that, I'm fine.

LGTM with a testcase.

Add a test case, please. With that, I'm fine.

Thank you guys for review, I have a question then.
As far I know llvm-mc do not support currently feature to generate compressed debug sections in
zlib style (afaik, llvm-mc generates it in only zlib-gnu style, so it is not possible to emit SHF_COMPRESSED flag).

So what I want to suggest here:
what if I'll prepare patch for llvm-mc that will allow it to generate zlib style sections and after that update this one ?
I can guess that it is a good feature for llvm-mc.
If you would agree with above then my question would be - should we need to support both ways or can just switch
to zlib style and cut off gnu one ? (afaik zlib-gnu is depricated in binutils).

After implementing change for llvm-mc I`ll be able to prepare testcase for this. Or I can commit this one and prepare
and commit a testcase after changes to llvm-mc, please tell me what is a acceptable way.
(one more way would be to use pre-compiled object file for testcase right now).

I like the idea of switching llvm-mc first. I think you can just
switch to the new style.

Cheers,
Rafael

I think it'd be handy to have both formats supported for reading/dumping - at least I personally still deal with compilers generating the old format (indeed, that's why I implemented the old format - it's what I saw in the version of GCC I was trying to be compatible with).

In any case, pretty sure I implemented this the first time by adding libObject support first, checking in a binary with compressed debug info generated by GCC. If you break libObject's ability to read the old style .zdebug format, you /should/ find some test cases that fail.

I think it'd be handy to have both formats supported for reading/dumping - at least I personally still deal with compilers generating the old format (indeed, that's why I implemented the old format - it's what I saw in the version of GCC I was trying to be compatible with).

In any case, pretty sure I implemented this the first time by adding libObject support first, checking in a binary with compressed debug info generated by GCC. If you break libObject's ability to read the old style .zdebug format, you /should/ find some test cases that fail.

I added support for dumping new zlib style in llvm-dwarfdump in D20470. I don't think any of my patches breaking ability to read/dump the old style anywhere, D20331 changes only llvm-mc output style.

This revision was automatically updated to reflect the committed changes.

I committed this using precompiled binary for testcase.
The reasons why I did not use llvm-mc were:
I found that testcases for llvm-readobj mostly uses precompiled objects. I didn't find llvm-mc
usings. Also, generating of compressed sections from llvm-mc depends on zlib. It is disabled
for windows atm and may be also disabled on unix. We probably do not want to have so many
excessive dependencies like asm->llvm-mc->zlib, for tools like readobj just to check the flags.

I'm still convinced (for many reasons) that checking in a binary isn't a great option when we can use MC.
I don't think "excessive dependencies like asm->llvm-mc->zlib" is a strong argument as we have them anyway.
OTOH, using our tools instead of a binary allows:

  1. dogfooding (which might catch regression)
  2. easier changes in case something breaks in the toolchain (we don't need to generate the binary again, we can just change the test)
  3. readability (you can read the ASM instead of a description). Maybe it's not the case but from time to time precompiled binaries lack a comment which describes how they've been generated, and comments and binary can get out of sync quickly.

In other words, I'm always for using llvm-mc instead of a binary (unless there's a strong reason not to). I'd rather bit the bullet and implement the missing feature in the assembler instead of going through the binary route which may lead to bigger pain later (I had to generate again ~10 binaries in DebugInfo tests in order to fix a bug in the verifier recently).

I found that testcases for llvm-readobj mostly uses precompiled objects.

If they do, and they can use MC instead, I think the llvm-readobj tests should be converted and not the other way around.

I'm still convinced (for many reasons) that checking in a binary isn't a great option when we can use MC.
I don't think "excessive dependencies like asm->llvm-mc->zlib" is a strong argument as we have them anyway.
OTOH, using our tools instead of a binary allows:

  1. dogfooding (which might catch regression)

I think in this patch we do not want to test llvm-mc, we want to check that proper flag is dumped from valid object. Since object is one time commited and
therefore always is valid, regression might be only because of changes in readobj code. If we would want to check that llvm-mc
generates proper flags, it should be test for llvm-mc, but not readobj.

  1. easier changes in case something breaks in the toolchain (we don't need to generate the binary again, we can just change the test)

We probably never need to gererate binary again except if it was incorrect initially.

  1. readability (you can read the ASM instead of a description). Maybe it's not the case but from time to time precompiled binaries lack a comment which describes how they've been generated, and comments and binary can get out of sync quickly.

Sometimes yes, we can read, but speaking of this patch you not only would not find anything about SHF_COMPRESSED flag in asm, but also would need to read llvm-mc command line
to find was compression set or not and also know what style of compression was used, was it zlib (which sets the flag) or zlib-gnu, which don't. So it would be a huge pain here.

In other words, I'm always for using llvm-mc instead of a binary (unless there's a strong reason not to). I'd rather bit the bullet and implement the missing feature in the assembler instead of going through the binary route which may lead to bigger pain later (I had to generate again ~10 binaries in DebugInfo tests in order to fix a bug in the verifier recently).

So my opinion that sometimes it is profitably to use llvm-mc, but sometimes - not.
(Just in case, are you aware that zlib on windows is broken >= 2 years ? https://llvm.org/bugs/show_bug.cgi?id=19403, so use of llvm-mc for this test would just skip
running testcases on whole windows world). That is what I thinkg a good example of excessive dependency on llvm-mc.

So my opinion that sometimes it is profitably to use llvm-mc, but sometimes - not.
(Just in case, are you aware that zlib on windows is broken >= 2 years ? https://llvm.org/bugs/show_bug.cgi?id=19403, so use of llvm-mc for this test would just skip
running testcases on whole windows world). That is what I thinkg a good example of excessive dependency on llvm-mc.

I respectfully disagree. There's no correlation between zlib broken on windows and llvm-mc.
If zlib is broken on windows, we should spend time fixing it, not silently ignoring the problem.

So my opinion that sometimes it is profitably to use llvm-mc, but sometimes - not.
(Just in case, are you aware that zlib on windows is broken >= 2 years ? https://llvm.org/bugs/show_bug.cgi?id=19403, so use of llvm-mc for this test would just skip
running testcases on whole windows world). That is what I thinkg a good example of excessive dependency on llvm-mc.

I respectfully disagree. There's no correlation between zlib broken on windows and llvm-mc.
If zlib is broken on windows, we should spend time fixing it, not silently ignoring the problem.

So my opinion that sometimes it is profitably to use llvm-mc, but sometimes - not.
(Just in case, are you aware that zlib on windows is broken >= 2 years ? https://llvm.org/bugs/show_bug.cgi?id=19403, so use of llvm-mc for this test would just skip
running testcases on whole windows world). That is what I thinkg a good example of excessive dependency on llvm-mc.

I respectfully disagree. There's no correlation between zlib broken on windows and llvm-mc.
If zlib is broken on windows, we should spend time fixing it, not silently ignoring the problem.

I went ahead and reassigned PR19403 to myself.

I went ahead and reassigned PR19403 to myself.

Thank you ! I am not good familar with CMake and llvm build system and was
not sure I can fix that by myself.