This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readobj/readelf] - Refactor how the code dumps relocations.
ClosedPublic

Authored by grimar on Jul 15 2020, 7:00 AM.

Details

Summary

There is a strange "feature" of the code: it handles all relocations as Elf_Rela.
For handling Elf_Rel it converts them to Elf_Rela and passes bool IsRela to
specify the real type everywhere.

A related issue is that the
decode_relrs helper in lib/Object has to return Expected<std::vector<Elf_Rela>>
because of that, though it could return a vector of Elf_Rel.

I think we should just start using templates for relocation types, it makes the code
cleaner and shorter. This patch does it.

Diff Detail

Event Timeline

grimar created this revision.Jul 15 2020, 7:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 15 2020, 7:00 AM

LLD uses template RelTy so there is prior art... For llvm-readobj, this seems to fix a misnomer. This is a +1 to me.

Have you considered https://bugs.llvm.org/show_bug.cgi?id=44257 Does this change make that easier or more difficult to fix?

LLD uses template RelTy so there is prior art... For llvm-readobj, this seems to fix a misnomer. This is a +1 to me.

Have you considered https://bugs.llvm.org/show_bug.cgi?id=44257 Does this change make that easier or more difficult to fix?

+1 from me in principle. I actually think this will make that fix easier thanks to the overloaded getAddend function now existing. That function might need to be a member function to fix the original issue, or its signature changed, but it provides an obvious spot to implement the required functionality, at least in my mind.

llvm/lib/Object/ELF.cpp
312–313

Probably best not to call an Elf_Rel object Rela...!

LLD uses template RelTy so there is prior art... For llvm-readobj, this seems to fix a misnomer. This is a +1 to me.

Have you considered https://bugs.llvm.org/show_bug.cgi?id=44257 Does this change make that easier or more difficult to fix?

+1 from me in principle. I actually think this will make that fix easier thanks to the overloaded getAddend function now existing.

Yeah, I'd say the it should make the fix slightly easier probably. Definitely should not be more difficult.

grimar updated this revision to Diff 278684.Jul 17 2020, 2:26 AM
grimar marked 2 inline comments as done.
  • Addressed review comment.
llvm/lib/Object/ELF.cpp
312–313

Right, fixed.

MaskRay accepted this revision.Jul 17 2020, 10:41 AM

LGTM.

This revision is now accepted and ready to land.Jul 17 2020, 10:41 AM
This revision was automatically updated to reflect the committed changes.