This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readobj] - Add a validation of the GNU hash table to printGnuHashHistogram().
ClosedPublic

Authored by grimar on Jun 17 2020, 5:56 AM.

Details

Summary

Similar to D81937, we might crash when printing a histogram for a GNU hash table
with a 'symndx' index that is larger than the number of dynamic symbols.

This patch adopts and reuses the getGnuHashTableChains() helper which performs
a validation of the table. As a side effect the warning reported for
the --gnu-hash-table was improved.

Also with this change we start to report a warning when the histogram is requested for
the GNU hash table, but the dynamic symbols table is empty (size == 0).

Diff Detail

Event Timeline

grimar created this revision.Jun 17 2020, 5:56 AM
Herald added a project: Restricted Project. · View Herald Transcript

If I'm following things right, the behaviour for an empty dynsym is changing with this patch. Is the new behaviour compatible with GNU?

llvm/test/tools/llvm-readobj/ELF/gnuhash.test
130

Hmm... This message is clearly not quite right even before your change: 2 is obviously not larger than 2...

Anyway, that's a separate issue.

llvm/test/tools/llvm-readobj/ELF/hash-histogram.test
335

Perhaps this should be non-zero rather than non-null? Similar null -> zero below.

342

No need for the comma here or in Case C.

386

It might also locate it by name, but I hope it wouldn't :-)

Perhaps this should say "The code locates the..."

grimar marked an inline comment as done.EditedJun 18 2020, 2:33 AM

If I'm following things right, the behaviour for an empty dynsym is changing with this patch. Is the new behaviour compatible with GNU?

Right. It it what I mentioned in the description:
"Also with this change we start to report a warning when the histogram is requested for
the GNU hash table, but the dynamic symbols table is empty (size == 0)."

GNU readelf doesn't warn about that. But isn't it a bug? When we have a zero sized dynamic table it is already incorrect, because it should have a zero symbol at least.
And it is wierd to have a hash table in this case too.

llvm/test/tools/llvm-readobj/ELF/hash-histogram.test
386

There is also an option currently where it uses the DT_SYMTAB tag.
In this test cases we have no such tag, so I think your suggestion is ok, I'll apply it.

grimar updated this revision to Diff 271643.Jun 18 2020, 3:24 AM
grimar marked 5 inline comments as done.
  • Addressed review comments.
grimar added inline comments.Jun 18 2020, 3:27 AM
llvm/test/tools/llvm-readobj/ELF/gnuhash.test
130

I'll fix, thanks for spotting.

jhenderson accepted this revision.Jun 18 2020, 5:57 AM

If I'm following things right, the behaviour for an empty dynsym is changing with this patch. Is the new behaviour compatible with GNU?

Right. It it what I mentioned in the description:
"Also with this change we start to report a warning when the histogram is requested for
the GNU hash table, but the dynamic symbols table is empty (size == 0)."

GNU readelf doesn't warn about that. But isn't it a bug? When we have a zero sized dynamic table it is already incorrect, because it should have a zero symbol at least.
And it is wierd to have a hash table in this case too.

You're probably right that it's a bug. I think I'm okay with this. LGTM.

This revision is now accepted and ready to land.Jun 18 2020, 5:57 AM
This revision was automatically updated to reflect the committed changes.