This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readelf/llvm-readobj] - Improved the error reporting in a few method related to versioning.
ClosedPublic

Authored by grimar on Dec 6 2019, 7:22 AM.

Details

Summary

I was investigating a change previously discussed that eliminates an excessive
empty lines from the output when we report warnings and errors
(https://reviews.llvm.org/D70826#inline-639055) and found
that we need this refactoring or alike to achieve that.

The problem is that some of our functions that finds symbol versions just
fail instead of returning errors or printing warnings. Another problem
is that they might print a warning on the same line with the regular output.
In this patch I've splitted getting of the version information and dumping of it
for GNU printVersionSymbolSection(). I had to change a few methods to return
Error or Expected<> to do that properly.

Diff Detail

Event Timeline

grimar created this revision.Dec 6 2019, 7:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 6 2019, 7:22 AM
jhenderson added inline comments.Dec 9 2019, 1:58 AM
llvm/test/tools/llvm-readobj/elf-verdef-invalid.test
266 ↗(On Diff #232558)

"we report when..."

This line is quite long. Maybe it should be split.

llvm/test/tools/llvm-readobj/elf-versym-invalid.test
222 ↗(On Diff #232558)

sections -> section

226 ↗(On Diff #232558)

I'd use --dyn-syms here instead of -dt, since there's no reason for it to be inconsistent with the line below.

256 ↗(On Diff #232558)

Would it be worth an extra 0xFF entry to show that the warning gets uniqued?

llvm/tools/llvm-readobj/ELFDumper.cpp
4126

for (size_t I = 0, S = VerTable.size(); I < S; ++I)

4136

I'm not sure it's right to say that an empty name is corrupt?

grimar marked an inline comment as done.Dec 9 2019, 2:52 AM
grimar added inline comments.
llvm/tools/llvm-readobj/ELFDumper.cpp
4136

That what original code did (the test was introduced in D59877) and I think it is
probably reasonable to assume that.
Normally we probably never want to have an empty version name for a symbol that has version?
Having such an empty version intentionally seems looks highly unlikely.

Spec says: "All other values are used to identify version strings located in one of the other Symbol
Version sections. The value itself is not the version associated with the symbol.
The string identified by the value defines the version of the symbol."
(https://refspecs.linuxfoundation.org/LSB_3.0.0/LSB-PDA/LSB-PDA.junk/symversion.html)
It says nothing about the case when the version string is empty, though
it sounds like it is assumed that a version exists, i.e is non-empty?

it is also just a bit strange to me to see the output for such case (below is what GNU readelf prints):

Symbol table '.dynsym' contains 6 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
....
     2: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __libc_start_main@ (2)
....
Version symbols section '.gnu.version' contains 6 entries:
 Addr: 000000000000043e  Offset: 0x00043e  Link: 5 (.dynsym)
  000:   0 (*local*)       0 (*local*)       2 ()              0 (*local*)    
  004:   0 (*local*)       2 ()

It looks like something is just wrong with the symbol __libc_start_main@ and version 2?

jhenderson added inline comments.Dec 9 2019, 3:59 AM
llvm/tools/llvm-readobj/ELFDumper.cpp
4136

But shouldn't we just allow it? It simplifies the code and brings us closer to GNU compatibility. Whilst I think it a bit odd, I don't see a strong motivation for handling the empty string differently to other strings. I don't feel strongly about this however.

grimar updated this revision to Diff 232856.Dec 9 2019, 7:37 AM
grimar marked 8 inline comments as done.
  • Addressed review comments.
llvm/test/tools/llvm-readobj/elf-versym-invalid.test
256 ↗(On Diff #232558)

Done.

llvm/tools/llvm-readobj/ELFDumper.cpp
4136

I do not mind to suggest a follow-up patch to change this behavior if we do not really want it.
(I'd not change this existent behavior in this patch, as it is probably unrelated).

jhenderson added inline comments.Dec 9 2019, 8:00 AM
llvm/test/tools/llvm-readobj/elf-versym-invalid.test
256 ↗(On Diff #232558)

Will you need an --implicit-check-not="warning:" or equivalent somewhere to actually detect that the warning has actually been uniqued?

llvm/tools/llvm-readobj/ELFDumper.cpp
4136

Sounds reasonable.

grimar updated this revision to Diff 233015.Dec 10 2019, 1:23 AM
grimar marked an inline comment as done.
  • Rebased.
  • Addressed review comments.
grimar added inline comments.Dec 10 2019, 1:23 AM
llvm/test/tools/llvm-readobj/elf-versym-invalid.test
256 ↗(On Diff #232558)

Oh, I missed we do not have it.
And also actually we need one more dynamic symbol to trigger a warning too..
I've updated the test.

jhenderson accepted this revision.Dec 10 2019, 1:48 AM

LGTM, with one minor comment.

llvm/test/tools/llvm-readobj/ELF/verdef-invalid.test
266–267

Actually, on re-read, I realise that this should be "Check we report a warning when..."

This revision is now accepted and ready to land.Dec 10 2019, 1:48 AM
This revision was automatically updated to reflect the committed changes.
grimar marked an inline comment as done.