From 169ec2d6b006ea31114a7d6ddc3f002d3cb4acb3 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 8 Jul 2020 10:27:31 -0700 Subject: [PATCH] [ELF] Rename canRelax to toExecRelax. NFC In the absence of TLS relaxation (rewrite of code sequences), there is still an applicable optimization: [gd]: General Dynamic: resolve DTPMOD to 1 and/or resolve DTPOFF statically All the other relaxations are only performed when transiting to executable (`!config->shared`). Since [gd] is handled differently, we can fold `!config->shared` into canRelax and simplify its use sites. Rename the variable to reflect to new semantics. Reviewed By: grimar, psmith Differential Revision: https://reviews.llvm.org/D83243 --- lld/ELF/Relocations.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index 42341f67afee5..751ded3977684 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -197,9 +197,9 @@ handleTlsRelocation(RelType type, Symbol &sym, InputSectionBase &c, return 1; } - bool canRelax = config->emachine != EM_ARM && - config->emachine != EM_HEXAGON && - config->emachine != EM_RISCV; + bool toExecRelax = !config->shared && config->emachine != EM_ARM && + config->emachine != EM_HEXAGON && + config->emachine != EM_RISCV; // If we are producing an executable and the symbol is non-preemptable, it // must be defined and the code sequence can be relaxed to use Local-Exec. @@ -217,7 +217,7 @@ handleTlsRelocation(RelType type, Symbol &sym, InputSectionBase &c, if (oneof( expr)) { // Local-Dynamic relocs can be relaxed to Local-Exec. - if (canRelax && !config->shared) { + if (toExecRelax) { c.relocations.push_back( {target->adjustRelaxExpr(type, nullptr, R_RELAX_TLS_LD_TO_LE), type, offset, addend, &sym}); @@ -238,7 +238,7 @@ handleTlsRelocation(RelType type, Symbol &sym, InputSectionBase &c, } // Local-Dynamic relocs can be relaxed to Local-Exec. - if (expr == R_DTPREL && canRelax && !config->shared) { + if (expr == R_DTPREL && toExecRelax) { c.relocations.push_back( {target->adjustRelaxExpr(type, nullptr, R_RELAX_TLS_LD_TO_LE), type, offset, addend, &sym}); @@ -260,7 +260,7 @@ handleTlsRelocation(RelType type, Symbol &sym, InputSectionBase &c, if (oneof(expr)) { - if (!canRelax || config->shared) { + if (!toExecRelax) { if (in.got->addDynTlsEntry(sym)) { uint64_t off = in.got->getGlobalDynOffset(sym); @@ -308,7 +308,7 @@ handleTlsRelocation(RelType type, Symbol &sym, InputSectionBase &c, // defined. if (oneof(expr) && - canRelax && isLocalInExecutable) { + toExecRelax && isLocalInExecutable) { c.relocations.push_back({R_RELAX_TLS_IE_TO_LE, type, offset, addend, &sym}); return 1; }