This is lld-side change of D57939
echristo dblaikie ruiu espindola
- rLLD356730: [DWARF] Refactor RelocVisitor and fix computation of SHT_RELA-typed relocation…
rL356730: [DWARF] Refactor RelocVisitor and fix computation of SHT_RELA-typed relocation…
rGdc6c0cf94dfb: [DWARF] Refactor RelocVisitor and fix computation of SHT_RELA-typed relocation…
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.
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?
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.
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.
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.
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.