Skip to content

Commit 83fbd86

Browse files
committed
SPARCMCCodeEmitter: Set PCRel at fixup creation
1 parent d337e09 commit 83fbd86

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

llvm/lib/Target/Sparc/MCTargetDesc/SparcMCCodeEmitter.cpp

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ class SparcMCCodeEmitter : public MCCodeEmitter {
9191

9292
} // end anonymous namespace
9393

94+
static void addFixup(SmallVectorImpl<MCFixup> &Fixups, uint32_t Offset,
95+
const MCExpr *Value, uint16_t Kind) {
96+
bool PCRel = false;
97+
switch (Kind) {
98+
case ELF::R_SPARC_PC10:
99+
case ELF::R_SPARC_PC22:
100+
case ELF::R_SPARC_WDISP10:
101+
case ELF::R_SPARC_WDISP16:
102+
case ELF::R_SPARC_WDISP19:
103+
case ELF::R_SPARC_WDISP22:
104+
PCRel = true;
105+
}
106+
Fixups.push_back(MCFixup::create(Offset, Value, Kind, PCRel));
107+
}
108+
94109
void SparcMCCodeEmitter::encodeInstruction(const MCInst &MI,
95110
SmallVectorImpl<char> &CB,
96111
SmallVectorImpl<MCFixup> &Fixups,
@@ -135,7 +150,7 @@ getMachineOpValue(const MCInst &MI, const MCOperand &MO,
135150
assert(MO.isExpr());
136151
const MCExpr *Expr = MO.getExpr();
137152
if (auto *SExpr = dyn_cast<MCSpecifierExpr>(Expr)) {
138-
Fixups.push_back(MCFixup::create(0, Expr, SExpr->getSpecifier()));
153+
addFixup(Fixups, 0, Expr, SExpr->getSpecifier());
139154
return 0;
140155
}
141156

@@ -165,10 +180,10 @@ unsigned SparcMCCodeEmitter::getSImm5OpValue(const MCInst &MI, unsigned OpNo,
165180
return CE->getValue();
166181

167182
if (auto *SExpr = dyn_cast<MCSpecifierExpr>(Expr)) {
168-
Fixups.push_back(MCFixup::create(0, Expr, SExpr->getSpecifier()));
183+
addFixup(Fixups, 0, Expr, SExpr->getSpecifier());
169184
return 0;
170185
}
171-
Fixups.push_back(MCFixup::create(0, Expr, ELF::R_SPARC_5));
186+
addFixup(Fixups, 0, Expr, ELF::R_SPARC_5);
172187
return 0;
173188
}
174189

@@ -191,10 +206,10 @@ SparcMCCodeEmitter::getSImm13OpValue(const MCInst &MI, unsigned OpNo,
191206
return CE->getValue();
192207

193208
if (auto *SExpr = dyn_cast<MCSpecifierExpr>(Expr)) {
194-
Fixups.push_back(MCFixup::create(0, Expr, SExpr->getSpecifier()));
209+
addFixup(Fixups, 0, Expr, SExpr->getSpecifier());
195210
return 0;
196211
}
197-
Fixups.push_back(MCFixup::create(0, Expr, Sparc::fixup_sparc_13));
212+
addFixup(Fixups, 0, Expr, Sparc::fixup_sparc_13);
198213
return 0;
199214
}
200215

@@ -209,7 +224,7 @@ getCallTargetOpValue(const MCInst &MI, unsigned OpNo,
209224
}
210225

211226
const MCOperand &MO = MI.getOperand(OpNo);
212-
Fixups.push_back(MCFixup::create(0, MO.getExpr(), Sparc::fixup_sparc_call30));
227+
addFixup(Fixups, 0, MO.getExpr(), Sparc::fixup_sparc_call30);
213228
return 0;
214229
}
215230

@@ -221,7 +236,7 @@ getBranchTargetOpValue(const MCInst &MI, unsigned OpNo,
221236
if (MO.isReg() || MO.isImm())
222237
return getMachineOpValue(MI, MO, Fixups, STI);
223238

224-
Fixups.push_back(MCFixup::create(0, MO.getExpr(), ELF::R_SPARC_WDISP22));
239+
addFixup(Fixups, 0, MO.getExpr(), ELF::R_SPARC_WDISP22);
225240
return 0;
226241
}
227242

@@ -232,7 +247,7 @@ unsigned SparcMCCodeEmitter::getBranchPredTargetOpValue(
232247
if (MO.isReg() || MO.isImm())
233248
return getMachineOpValue(MI, MO, Fixups, STI);
234249

235-
Fixups.push_back(MCFixup::create(0, MO.getExpr(), ELF::R_SPARC_WDISP19));
250+
addFixup(Fixups, 0, MO.getExpr(), ELF::R_SPARC_WDISP19);
236251
return 0;
237252
}
238253

@@ -243,8 +258,7 @@ unsigned SparcMCCodeEmitter::getBranchOnRegTargetOpValue(
243258
if (MO.isReg() || MO.isImm())
244259
return getMachineOpValue(MI, MO, Fixups, STI);
245260

246-
Fixups.push_back(MCFixup::create(0, MO.getExpr(), ELF::R_SPARC_WDISP16));
247-
261+
addFixup(Fixups, 0, MO.getExpr(), ELF::R_SPARC_WDISP16);
248262
return 0;
249263
}
250264

@@ -255,8 +269,7 @@ unsigned SparcMCCodeEmitter::getCompareAndBranchTargetOpValue(
255269
if (MO.isImm())
256270
return getMachineOpValue(MI, MO, Fixups, STI);
257271

258-
Fixups.push_back(MCFixup::create(0, MO.getExpr(), ELF::R_SPARC_WDISP10));
259-
272+
addFixup(Fixups, 0, MO.getExpr(), ELF::R_SPARC_WDISP10);
260273
return 0;
261274
}
262275

0 commit comments

Comments
 (0)