@@ -120,6 +120,28 @@ MCCodeEmitter *llvm::createRISCVMCCodeEmitter(const MCInstrInfo &MCII,
120
120
return new RISCVMCCodeEmitter (Ctx, MCII);
121
121
}
122
122
123
+ static void addFixup (SmallVectorImpl<MCFixup> &Fixups, uint32_t Offset,
124
+ const MCExpr *Value, uint16_t Kind) {
125
+ bool PCRel = false ;
126
+ switch (Kind) {
127
+ case ELF::R_RISCV_CALL_PLT:
128
+ case RISCV::fixup_riscv_pcrel_hi20:
129
+ case RISCV::fixup_riscv_pcrel_lo12_i:
130
+ case RISCV::fixup_riscv_pcrel_lo12_s:
131
+ case RISCV::fixup_riscv_jal:
132
+ case RISCV::fixup_riscv_branch:
133
+ case RISCV::fixup_riscv_rvc_jump:
134
+ case RISCV::fixup_riscv_rvc_branch:
135
+ case RISCV::fixup_riscv_call:
136
+ case RISCV::fixup_riscv_call_plt:
137
+ case RISCV::fixup_riscv_qc_e_branch:
138
+ case RISCV::fixup_riscv_qc_e_call_plt:
139
+ case RISCV::fixup_riscv_nds_branch_10:
140
+ PCRel = true ;
141
+ }
142
+ Fixups.push_back (MCFixup::create (Offset, Value, Kind, PCRel));
143
+ }
144
+
123
145
// Expand PseudoCALL(Reg), PseudoTAIL and PseudoJump to AUIPC and JALR with
124
146
// relocation types. We expand those pseudo-instructions while encoding them,
125
147
// meaning AUIPC and JALR won't go through RISC-V MC to MC compressed
@@ -181,7 +203,7 @@ void RISCVMCCodeEmitter::expandTLSDESCCall(const MCInst &MI,
181
203
MCRegister Link = MI.getOperand (0 ).getReg ();
182
204
MCRegister Dest = MI.getOperand (1 ).getReg ();
183
205
int64_t Imm = MI.getOperand (2 ).getImm ();
184
- Fixups. push_back ( MCFixup::create ( 0 , Expr, ELF::R_RISCV_TLSDESC_CALL) );
206
+ addFixup (Fixups, 0 , Expr, ELF::R_RISCV_TLSDESC_CALL);
185
207
MCInst Call =
186
208
MCInstBuilder (RISCV::JALR).addReg (Link).addReg (Dest).addImm (Imm);
187
209
@@ -208,7 +230,7 @@ void RISCVMCCodeEmitter::expandAddTPRel(const MCInst &MI,
208
230
assert (Expr && Expr->getSpecifier () == ELF::R_RISCV_TPREL_ADD &&
209
231
" Expected tprel_add relocation on TP-relative symbol" );
210
232
211
- Fixups. push_back ( MCFixup::create ( 0 , Expr, ELF::R_RISCV_TPREL_ADD) );
233
+ addFixup (Fixups, 0 , Expr, ELF::R_RISCV_TPREL_ADD);
212
234
if (STI.hasFeature (RISCV::FeatureRelax))
213
235
Fixups.back ().setLinkerRelaxable ();
214
236
@@ -318,10 +340,8 @@ void RISCVMCCodeEmitter::expandLongCondBr(const MCInst &MI,
318
340
// Drop any fixup added so we can add the correct one.
319
341
Fixups.resize (FixupStartIndex);
320
342
321
- if (SrcSymbol.isExpr ()) {
322
- Fixups.push_back (
323
- MCFixup::create (Offset, SrcSymbol.getExpr (), RISCV::fixup_riscv_jal));
324
- }
343
+ if (SrcSymbol.isExpr ())
344
+ addFixup (Fixups, Offset, SrcSymbol.getExpr (), RISCV::fixup_riscv_jal);
325
345
}
326
346
327
347
// Expand PseudoLongQC_(E_)Bxxx to an inverted conditional branch and an
@@ -368,10 +388,8 @@ void RISCVMCCodeEmitter::expandQCLongCondBrImm(const MCInst &MI,
368
388
support::endian::write (CB, JBinary, llvm::endianness::little);
369
389
// Drop any fixup added so we can add the correct one.
370
390
Fixups.resize (FixupStartIndex);
371
- if (SrcSymbol.isExpr ()) {
372
- Fixups.push_back (
373
- MCFixup::create (Offset, SrcSymbol.getExpr (), RISCV::fixup_riscv_jal));
374
- }
391
+ if (SrcSymbol.isExpr ())
392
+ addFixup (Fixups, Offset, SrcSymbol.getExpr (), RISCV::fixup_riscv_jal);
375
393
}
376
394
377
395
void RISCVMCCodeEmitter::encodeInstruction (const MCInst &MI,
@@ -649,7 +667,7 @@ uint64_t RISCVMCCodeEmitter::getImmOpValue(const MCInst &MI, unsigned OpNo,
649
667
650
668
assert (FixupKind != RISCV::fixup_riscv_invalid && " Unhandled expression!" );
651
669
652
- Fixups. push_back ( MCFixup::create ( 0 , Expr, FixupKind) );
670
+ addFixup (Fixups, 0 , Expr, FixupKind);
653
671
// If linker relaxation is enabled and supported by this relocation, set
654
672
// a bit so that if fixup is unresolved, a R_RISCV_RELAX relocation will be
655
673
// appended.
0 commit comments