@@ -195,8 +195,8 @@ static bool isAbsoluteValue(const Symbol &sym) {
195
195
196
196
// Returns true if Expr refers a PLT entry.
197
197
static bool needsPlt (RelExpr expr) {
198
- return oneof<R_PLT, R_PLT_PC, R_PLT_GOTPLT, R_PPC32_PLTREL, R_PPC64_CALL_PLT>(
199
- expr);
198
+ return oneof<R_PLT, R_PLT_PC, R_PLT_GOTPLT, R_LOONGARCH_PLT_PAGE_PC,
199
+ R_PPC32_PLTREL, R_PPC64_CALL_PLT>( expr);
200
200
}
201
201
202
202
// Returns true if Expr refers a GOT entry. Note that this function
@@ -205,20 +205,23 @@ static bool needsPlt(RelExpr expr) {
205
205
static bool needsGot (RelExpr expr) {
206
206
return oneof<R_GOT, R_GOT_OFF, R_MIPS_GOT_LOCAL_PAGE, R_MIPS_GOT_OFF,
207
207
R_MIPS_GOT_OFF32, R_AARCH64_GOT_PAGE_PC, R_GOT_PC, R_GOTPLT,
208
- R_AARCH64_GOT_PAGE>(expr);
208
+ R_AARCH64_GOT_PAGE, R_LOONGARCH_GOT, R_LOONGARCH_GOT_PAGE_PC>(
209
+ expr);
209
210
}
210
211
211
212
// True if this expression is of the form Sym - X, where X is a position in the
212
213
// file (PC, or GOT for example).
213
214
static bool isRelExpr (RelExpr expr) {
214
215
return oneof<R_PC, R_GOTREL, R_GOTPLTREL, R_MIPS_GOTREL, R_PPC64_CALL,
215
216
R_PPC64_RELAX_TOC, R_AARCH64_PAGE_PC, R_RELAX_GOT_PC,
216
- R_RISCV_PC_INDIRECT, R_PPC64_RELAX_GOT_PC>(expr);
217
+ R_RISCV_PC_INDIRECT, R_PPC64_RELAX_GOT_PC, R_LOONGARCH_PAGE_PC>(
218
+ expr);
217
219
}
218
220
219
-
220
221
static RelExpr toPlt (RelExpr expr) {
221
222
switch (expr) {
223
+ case R_LOONGARCH_PAGE_PC:
224
+ return R_LOONGARCH_PLT_PAGE_PC;
222
225
case R_PPC64_CALL:
223
226
return R_PPC64_CALL_PLT;
224
227
case R_PC:
@@ -237,6 +240,8 @@ static RelExpr fromPlt(RelExpr expr) {
237
240
case R_PLT_PC:
238
241
case R_PPC32_PLTREL:
239
242
return R_PC;
243
+ case R_LOONGARCH_PLT_PAGE_PC:
244
+ return R_LOONGARCH_PAGE_PC;
240
245
case R_PPC64_CALL_PLT:
241
246
return R_PPC64_CALL;
242
247
case R_PLT:
@@ -951,7 +956,9 @@ bool RelocationScanner::isStaticLinkTimeConstant(RelExpr e, RelType type,
951
956
R_MIPS_GOTREL, R_MIPS_GOT_OFF, R_MIPS_GOT_OFF32, R_MIPS_GOT_GP_PC,
952
957
R_AARCH64_GOT_PAGE_PC, R_GOT_PC, R_GOTONLY_PC, R_GOTPLTONLY_PC,
953
958
R_PLT_PC, R_PLT_GOTPLT, R_PPC32_PLTREL, R_PPC64_CALL_PLT,
954
- R_PPC64_RELAX_TOC, R_RISCV_ADD, R_AARCH64_GOT_PAGE>(e))
959
+ R_PPC64_RELAX_TOC, R_RISCV_ADD, R_AARCH64_GOT_PAGE,
960
+ R_LOONGARCH_PLT_PAGE_PC, R_LOONGARCH_GOT, R_LOONGARCH_GOT_PAGE_PC>(
961
+ e))
955
962
return true ;
956
963
957
964
// These never do, except if the entire file is position dependent or if
@@ -1055,7 +1062,9 @@ void RelocationScanner::processAux(RelExpr expr, RelType type, uint64_t offset,
1055
1062
// for detailed description:
1056
1063
// ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
1057
1064
in.mipsGot ->addEntry (*sec->file , sym, addend, expr);
1058
- } else {
1065
+ } else if (!sym.isTls () || config->emachine != EM_LOONGARCH) {
1066
+ // Many LoongArch TLS relocs reuse the R_LOONGARCH_GOT type, in which
1067
+ // case the NEEDS_GOT flag shouldn't get set.
1059
1068
sym.setFlags (NEEDS_GOT);
1060
1069
}
1061
1070
} else if (needsPlt (expr)) {
@@ -1095,7 +1104,8 @@ void RelocationScanner::processAux(RelExpr expr, RelType type, uint64_t offset,
1095
1104
(isa<EhInputSection>(sec) && config->emachine != EM_MIPS));
1096
1105
if (canWrite) {
1097
1106
RelType rel = target->getDynRel (type);
1098
- if (expr == R_GOT || (rel == target->symbolicRel && !sym.isPreemptible )) {
1107
+ if (oneof<R_GOT, R_LOONGARCH_GOT>(expr) ||
1108
+ (rel == target->symbolicRel && !sym.isPreemptible )) {
1099
1109
addRelativeReloc<true >(*sec, offset, sym, addend, expr, type);
1100
1110
return ;
1101
1111
} else if (rel != 0 ) {
@@ -1247,11 +1257,13 @@ static unsigned handleTlsRelocation(RelType type, Symbol &sym,
1247
1257
return 1 ;
1248
1258
}
1249
1259
1250
- // ARM, Hexagon and RISC-V do not support GD/LD to IE/LE relaxation. For
1251
- // PPC64, if the file has missing R_PPC64_TLSGD/R_PPC64_TLSLD, disable
1260
+ // ARM, Hexagon, LoongArch and RISC-V do not support GD/LD to IE/LE
1261
+ // relaxation.
1262
+ // For PPC64, if the file has missing R_PPC64_TLSGD/R_PPC64_TLSLD, disable
1252
1263
// relaxation as well.
1253
1264
bool toExecRelax = !config->shared && config->emachine != EM_ARM &&
1254
1265
config->emachine != EM_HEXAGON &&
1266
+ config->emachine != EM_LOONGARCH &&
1255
1267
config->emachine != EM_RISCV &&
1256
1268
!c.file ->ppc64DisableTLSRelax ;
1257
1269
@@ -1268,8 +1280,7 @@ static unsigned handleTlsRelocation(RelType type, Symbol &sym,
1268
1280
// being suitable for being dynamically loaded via dlopen. GOT[e0] is the
1269
1281
// module index, with a special value of 0 for the current module. GOT[e1] is
1270
1282
// unused. There only needs to be one module index entry.
1271
- if (oneof<R_TLSLD_GOT, R_TLSLD_GOTPLT, R_TLSLD_PC, R_TLSLD_HINT>(
1272
- expr)) {
1283
+ if (oneof<R_TLSLD_GOT, R_TLSLD_GOTPLT, R_TLSLD_PC, R_TLSLD_HINT>(expr)) {
1273
1284
// Local-Dynamic relocs can be relaxed to Local-Exec.
1274
1285
if (toExecRelax) {
1275
1286
c.addReloc ({target->adjustTlsExpr (type, R_RELAX_TLS_LD_TO_LE), type,
@@ -1300,7 +1311,8 @@ static unsigned handleTlsRelocation(RelType type, Symbol &sym,
1300
1311
}
1301
1312
1302
1313
if (oneof<R_AARCH64_TLSDESC_PAGE, R_TLSDESC, R_TLSDESC_CALL, R_TLSDESC_PC,
1303
- R_TLSDESC_GOTPLT, R_TLSGD_GOT, R_TLSGD_GOTPLT, R_TLSGD_PC>(expr)) {
1314
+ R_TLSDESC_GOTPLT, R_TLSGD_GOT, R_TLSGD_GOTPLT, R_TLSGD_PC,
1315
+ R_LOONGARCH_TLSGD_PAGE_PC>(expr)) {
1304
1316
if (!toExecRelax) {
1305
1317
sym.setFlags (NEEDS_TLSGD);
1306
1318
c.addReloc ({expr, type, offset, addend, &sym});
@@ -1320,8 +1332,8 @@ static unsigned handleTlsRelocation(RelType type, Symbol &sym,
1320
1332
return target->getTlsGdRelaxSkip (type);
1321
1333
}
1322
1334
1323
- if (oneof<R_GOT, R_GOTPLT, R_GOT_PC, R_AARCH64_GOT_PAGE_PC, R_GOT_OFF,
1324
- R_TLSIE_HINT>(expr)) {
1335
+ if (oneof<R_GOT, R_GOTPLT, R_GOT_PC, R_AARCH64_GOT_PAGE_PC,
1336
+ R_LOONGARCH_GOT_PAGE_PC, R_GOT_OFF, R_TLSIE_HINT>(expr)) {
1325
1337
ctx.hasTlsIe .store (true , std::memory_order_relaxed);
1326
1338
// Initial-Exec relocs can be relaxed to Local-Exec if the symbol is locally
1327
1339
// defined.
0 commit comments