Skip to content

Commit baee006

Browse files
committed
Delete the wrong flag NEEDS_TLSGD_TO_IE in the extreme code model.
1 parent 99c1a4e commit baee006

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Diff for: lld/ELF/Relocations.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,17 @@ unsigned RelocationScanner::handleTlsRelocation(RelExpr expr, RelType type,
14591459
// label, so TLSDESC=>IE will be categorized as R_RELAX_TLS_GD_TO_LE. We fix
14601460
// the categorization in RISCV::relocateAllosec->
14611461
if (sym.isPreemptible) {
1462-
sym.setFlags(NEEDS_TLSGD_TO_IE);
1462+
// In LoongArch, TLSDESC code sequences share relocations
1463+
// R_LARCH_TLS_DESC_PC_HI20 and R_LARCH_TLS_DESC_PC_LO12 in
1464+
// normal/medium/extreme code model. Since the extreme code model cannot
1465+
// be optimized to IE/LE, the flag NEEDS_TLSGD_TO_IE added previously
1466+
// needs to be cleared.
1467+
// In extreme code model, R_LARCH_TLS_DESC64_LO20 and
1468+
// R_LARCH_TLS_DESC64_HI12 will set NEEDS_TLSDESC flag.
1469+
if (ctx.arg.emachine == EM_LOONGARCH && sym.hasFlag(NEEDS_TLSDESC))
1470+
sym.clearFlags(NEEDS_TLSGD_TO_IE);
1471+
else
1472+
sym.setFlags(NEEDS_TLSGD_TO_IE);
14631473
sec->addReloc({ctx.target->adjustTlsExpr(type, R_RELAX_TLS_GD_TO_IE),
14641474
type, offset, addend, &sym});
14651475
} else {

Diff for: lld/ELF/Symbols.h

+3
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ class Symbol {
342342
void setFlags(uint16_t bits) {
343343
flags.fetch_or(bits, std::memory_order_relaxed);
344344
}
345+
void clearFlags(uint16_t bits) {
346+
flags.fetch_and(~bits, std::memory_order_relaxed);
347+
}
345348
bool hasFlag(uint16_t bit) const {
346349
assert(bit && (bit & (bit - 1)) == 0 && "bit must be a power of 2");
347350
return flags.load(std::memory_order_relaxed) & bit;

0 commit comments

Comments
 (0)