This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readelf/obj] - Print section symbol names properly when dumping relocations.
ClosedPublic

Authored by grimar on Sep 14 2020, 7:35 AM.

Details

Summary

Currently --relocations ignores section symbol names and always prints
section names for them. This is inconsistent with GNU readelf and with --symbols.

We have a code in getFullSymbolName (which is used for --symbols) which can be
reused for getRelocationTarget (used for --relocations).
With that the issue described is fixed and code becomes a bit shorter.
Also with this change we start to print more relocations (in situations when we just
showed warnings instead before) and also start to report more diagnostic warnings
(see reloc-zero-name-or-value.test).

Diff Detail

Event Timeline

grimar created this revision.Sep 14 2020, 7:35 AM
grimar requested review of this revision.Sep 14 2020, 7:35 AM

There seems to be more going on in this patch than the description talks about. In particular, it looks like this patch causes relocations to be printed when they weren't before. I don't think this is necessarily a problem, but it needs explaining in the description at least, and if sensibly practical, should actually be a separate patch, to minimise behaviour changes per patch.

llvm/test/tools/llvm-readobj/ELF/relocation-errors.test
71–72
76–77

I think you need to rephrase this and the similar comment below - section symbols (like any other symbol) don't have "sh_name" fields, and therefore this comment is confusing.

81–87
llvm/tools/llvm-readobj/ELFDumper.cpp
1163–1164

If I'm following this correctly, there's an unrelated behaviour change here to do with which symbol table to use when IsDynamic is true? That sounds like a different patch (also possibly unnecessary, since I'm not sure a STT_SECTION symbol in a dynsym makes sense, but that's possibly tangential).

1174

I think you can delete this comment. It just describes what the code says.

1187

I'm concerned that not using this function is a behaviour change here too? Note that getSymbolSectionName does more than just look up the section's name - there's special behaviour for e.g. common and absolute symbols, which the new code doesn't seem to be accounting for?

grimar planned changes to this revision.Sep 15 2020, 5:06 AM
grimar updated this revision to Diff 293402.Sep 22 2020, 3:39 AM
grimar marked 6 inline comments as done.
grimar edited the summary of this revision. (Show Details)
  • Updated implementation after other changes that were landed independently.
  • Addressed review comments.
llvm/tools/llvm-readobj/ELFDumper.cpp
1163–1164

This change is gone.

1174

This change is gone.

jhenderson accepted this revision.Sep 23 2020, 12:28 AM

LGTM, with nit.

llvm/test/tools/llvm-readobj/ELF/relocation-errors.test
81–86
This revision is now accepted and ready to land.Sep 23 2020, 12:28 AM
This revision was automatically updated to reflect the committed changes.
grimar marked an inline comment as done.