Page MenuHomePhabricator

Refactor RelocVisitor and fix computation of SHT_RELA-typed relocation entries
ClosedPublic

Authored by MaskRay on Feb 8 2019, 12:04 AM.

Diff Detail

Repository
rLLD LLVM Linker

Event Timeline

MaskRay created this revision.Feb 8 2019, 12:04 AM
MaskRay updated this revision to Diff 185918.Feb 8 2019, 12:31 AM

wrap with unnamed namespace

ruiu added inline comments.Feb 15 2019, 4:22 PM
ELF/DWARF.cpp
114–115

I found this interface a bit awkward. Passing a DataRefImpl instance just to pass a single integer value seems odd to me.

I think my question is, is it that hard to read debug info? We don't necessarily have to use the library to read debug info, and if we can just read debug info with a small amount of code, that could be a better way. I don't know if that's the case, but that's something I want to investigate.

dblaikie added inline comments.Feb 18 2019, 3:59 PM
ELF/DWARF.cpp
114–115

If there's something awkward about LLVM's DWARF reading APIs, I'd love to see them improved (open to suggestions/requests/design discussions/patches) rather than forked/partially reimplemented in LLD, if at all reasonable/possible, for what it's worth.

DataRefImpl is a union of the integer and some other alternatives, by the looks of it - so I'm not sure I see this as being especially odd/awkward. I guess it's because some clients want to describe the parameter in one way, and some in another. If it's particularly hard to read here, there could be a convenience wrapper function that packs the parameter into a DataRefImpl/RelocationRef/etc?

MaskRay marked an inline comment as done.Feb 20 2019, 7:00 AM
MaskRay added inline comments.
ELF/DWARF.cpp
114–115

The slight weird thing here is that RelocationResolver<typename ELFT::Rela>::Resolve is the constant for every relocation involved. Putting it to every RelocAddrEntry is wasteful. I'll try improving this but for now I just want to get the SHT_RELA bug fixed.. D57939

echristo added inline comments.Mar 14 2019, 1:09 AM
ELF/DWARF.cpp
114–115

Seems reasonable. Do you have an idea of how you want to change things?

MaskRay marked an inline comment as done.Mar 14 2019, 7:58 AM
MaskRay added inline comments.
ELF/DWARF.cpp
114–115
  1. Define another set of functions listing supported relocation types for each architecture. The function for x86_64 may look like: switch (R) { case R_X86_64_64: case R_X86_64_PC32: return true; default: return false; }. That would cause duplication but I cannot think of a better way if we also care about the performance (@dblaikie 's comment on D57949 made me think so)
  2. Make heavier refactoring to the RelocAddrEntry call sites. Make RelocationResolver<typename ELFT::Rela>::Resolve a member of the class where RelocAddrEntry is used to resolve the relocation.

The two steps require some efforts but we probably should do that to make the code cleaner. Note, I believe the lld side DWARF code is simple enough and the amount of code added by this patch is also reasonable.

echristo added inline comments.Mar 18 2019, 2:51 PM
ELF/DWARF.cpp
58–71

This could probably use some explanatory comments here. I know what you mean by S and S+A but let's just have it explicitly called out. :)

114–115

This works for me.

MaskRay updated this revision to Diff 191239.Mar 18 2019, 9:23 PM

Comment S and A

MaskRay marked 3 inline comments as done.Mar 18 2019, 9:25 PM
echristo accepted this revision.Mar 19 2019, 10:30 AM

This is fine with me, Rui?

This revision is now accepted and ready to land.Mar 19 2019, 10:30 AM
ruiu added a comment.Mar 20 2019, 5:18 PM

I thought that I sent it before, but it's gone somewhere...

I wonder why you had to use template. Looks like you could just pass a plain function pointer. Is there any reason you didn't do that?

I thought that I sent it before, but it's gone somewhere...

I wonder why you had to use template. Looks like you could just pass a plain function pointer. Is there any reason you didn't do that?

The reason I use template <class RelTy> struct RelocationResolver and make its partial specialization template <class ELFT> struct RelocationResolver<Elf_Rel_Impl<ELFT, false>> is because there are 4 ELFT types and each has the Rel variant and the Rela variant. If I de-template the struct, I'll have to define 8 functions.

ruiu added a comment.Mar 21 2019, 11:16 AM

Not sure if I follow. Looks like you always instantiate the template using ELFT::Rela, so effectively you are assuming that all targets are using RELA (which is a wrong assumption by the way)? I think you need to dispatch using Config->IsRela.

MaskRay updated this revision to Diff 191805.Mar 21 2019, 5:07 PM

dispatch using Config->IsRela

ruiu accepted this revision.Mar 21 2019, 5:18 PM

LGTM

MaskRay updated this revision to Diff 191807.Mar 21 2019, 5:18 PM

Dispatch on RelTy

Not sure if I follow. Looks like you always instantiate the template using ELFT::Rela, so effectively you are assuming that all targets are using RELA (which is a wrong assumption by the way)? I think you need to dispatch using Config->IsRela.

Config->IsRela is the target default but the object file may have both SHT_REL and SHT_RELA (may not be realistic but then intention of AreRelocsRela is probably for this purpose). I've changed that.

dispatch using Config->IsRela

The value of getAddend<ELFT>(Rel); now only seems to be in Ref.getRawDataRefImpl().p now. Shouldn't the rel case also be adding the implicit addend? I'm not sure I'm reading the code currently but it looks to me like REL no longer gets the addend added.

dispatch using Config->IsRela

The value of getAddend<ELFT>(Rel); now only seems to be in Ref.getRawDataRefImpl().p now. Shouldn't the rel case also be adding the implicit addend? I'm not sure I'm reading the code currently but it looks to me like REL no longer gets the addend added.

For the REL case, the addend is supplied by the caller as the parameter A. A is supplied by llvm/lib/DebugInfo/DWARF/DWARFDataExtractor.cpp:getRelocatedValue.

This revision was automatically updated to reflect the committed changes.