Our code in handleTlsRelocation is hard to read.
It is possible to rewrite it and reduce a bit.
That is what this patch does. It should be NFC.
Details
- Reviewers
ruiu syzaara • espindola
Diff Detail
Event Timeline
If I calculate it right, your code has the same cyclomatic complexity as the original one. At the same time, it is one level deeper, taking into account the number of conditions for the particular lines.
ELF/Relocations.cpp | ||
---|---|---|
189–191 | I like the new code because it's shorter, but this part looks odd to me, because only R_ABS is not a TLSLD type, though other relocations are all TLSLD. So it is hard to judge. |
- Addressed review comment.
ELF/Relocations.cpp | ||
---|---|---|
189–191 | What if I keep logic about R_ABS outside? Like in the updated version. |
Rui, what do you think about this one?
I think the new code is better because it groups handling of the R_TLSLD_* relocations at one place.
- Rebased.
ELF/Arch/PPC64.cpp | ||
---|---|---|
742–743 | The old code doesn't say anything about these relocations, but your new code contains code for these relocations. Where did they come from? What is special about them? |
ELF/Arch/PPC64.cpp | ||
---|---|---|
742–743 | The original code did that: if (Expr == R_TLSLD_GOT_OFF) { // Local-Dynamic relocs can be relaxed to local-exec if (!Config->Shared) { C.Relocations.push_back({R_RELAX_TLS_LD_TO_LE, Type, Offset, Addend, &Sym}); The new code does: if (isRelExprOneOf<R_TLSLD_* ..., R_TLSLD_GOT_OFF>(Expr)) { // Local-Dynamic relocs can be relaxed to Local-Exec. if (!Config->Shared) { C.Relocations.push_back( {Target->adjustRelaxExpr(Type, nullptr, R_RELAX_TLS_LD_TO_LE), Type, Offset, Addend, &Sym}); See, the new code calls Target->adjustRelaxExpr before pushing the relocations (Note, such an approach is not new, for example, we are doing the same on AArch64 I think: |
I'd like to see more drastic refactoring of this code. Honestly we should completely rewrite this code because the current code is really hard to read. As to this patch, I'm not sure if this is an improvement from readability perspective, as both the current code and the new code are hard to understand to me.
The old code doesn't say anything about these relocations, but your new code contains code for these relocations. Where did they come from? What is special about them?