Skip to content

Commit 0c6ba1d

Browse files
committed
Delete the wrong flag NEEDS_TLSGD_TO_IE in the extreme code model.
1 parent 2a30b6c commit 0c6ba1d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Diff for: lld/ELF/Relocations.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -1427,7 +1427,15 @@ unsigned RelocationScanner::handleTlsRelocation(RelExpr expr, RelType type,
14271427
// label, so TLSDESC=>IE will be categorized as R_RELAX_TLS_GD_TO_LE. We fix
14281428
// the categorization in RISCV::relocateAllosec->
14291429
if (sym.isPreemptible) {
1430-
sym.setFlags(NEEDS_TLSGD_TO_IE);
1430+
// In LoongArch, TLSDESC code sequences share relocations
1431+
// R_LARCH_TLS_DESC_PC_HI20 and R_LARCH_TLS_DESC_PC_LO12 in
1432+
// normal/medium/extreme code model. Since the extreme code model cannot
1433+
// be optimized to IE/LE, the flag NEEDS_TLSGD_TO_IE added previously
1434+
// needs to be cleared.
1435+
if (ctx.arg.emachine == EM_LOONGARCH && sym.hasFlag(NEEDS_TLSDESC))
1436+
sym.clearFlags(NEEDS_TLSGD_TO_IE);
1437+
else
1438+
sym.setFlags(NEEDS_TLSGD_TO_IE);
14311439
sec->addReloc({ctx.target->adjustTlsExpr(type, R_RELAX_TLS_GD_TO_IE),
14321440
type, offset, addend, &sym});
14331441
} else {

Diff for: lld/ELF/Symbols.h

+3
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ class Symbol {
345345
void setFlags(uint16_t bits) {
346346
flags.fetch_or(bits, std::memory_order_relaxed);
347347
}
348+
void clearFlags(uint16_t bits) {
349+
flags.fetch_and(~bits, std::memory_order_relaxed);
350+
}
348351
bool hasFlag(uint16_t bit) const {
349352
assert(bit && (bit & (bit - 1)) == 0 && "bit must be a power of 2");
350353
return flags.load(std::memory_order_relaxed) & bit;

0 commit comments

Comments
 (0)