Skip to content

Commit 0999cbd

Browse files
committed
MC: add a RefKind field to MCValue
This is principally to allow neater mapping of fixups to relocations in ARM64 ELF. Without this, there isn't enough information available to GetRelocType, leading to many more fixup_arm64_... enumerators. llvm-svn: 205085
1 parent 53d3251 commit 0999cbd

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

llvm/include/llvm/MC/MCValue.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,16 @@ class MCSymbol;
2424
class MCSymbolRefExpr;
2525
class raw_ostream;
2626

27-
/// MCValue - This represents an "assembler immediate". In its most general
28-
/// form, this can hold "SymbolA - SymbolB + imm64". Not all targets supports
29-
/// relocations of this general form, but we need to represent this anyway.
27+
/// MCValue - This represents an "assembler immediate". In its most
28+
/// general form, this can hold ":Kind:(SymbolA - SymbolB + imm64)".
29+
/// Not all targets supports relocations of this general form, but we
30+
/// need to represent this anyway.
31+
///
32+
/// In general both SymbolA and SymbolB will also have a modifier
33+
/// analogous to the top-level Kind. Current targets are not expected
34+
/// to make use of both though. The choice comes down to whether
35+
/// relocation modifiers apply to the closest symbol or the whole
36+
/// expression.
3037
///
3138
/// In the general form, SymbolB can only be defined if SymbolA is, and both
3239
/// must be in the same (non-external) section. The latter constraint is not
@@ -37,11 +44,13 @@ class raw_ostream;
3744
class MCValue {
3845
const MCSymbolRefExpr *SymA, *SymB;
3946
int64_t Cst;
47+
uint32_t RefKind;
4048
public:
4149

4250
int64_t getConstant() const { return Cst; }
4351
const MCSymbolRefExpr *getSymA() const { return SymA; }
4452
const MCSymbolRefExpr *getSymB() const { return SymB; }
53+
uint32_t getRefKind() const { return RefKind; }
4554

4655
/// isAbsolute - Is this an absolute (as opposed to relocatable) value.
4756
bool isAbsolute() const { return !SymA && !SymB; }
@@ -53,12 +62,13 @@ class MCValue {
5362
void dump() const;
5463

5564
static MCValue get(const MCSymbolRefExpr *SymA, const MCSymbolRefExpr *SymB=0,
56-
int64_t Val = 0) {
65+
int64_t Val = 0, uint32_t RefKind = 0) {
5766
MCValue R;
5867
assert((!SymB || SymA) && "Invalid relocatable MCValue!");
5968
R.Cst = Val;
6069
R.SymA = SymA;
6170
R.SymB = SymB;
71+
R.RefKind = RefKind;
6272
return R;
6373
}
6474

@@ -67,6 +77,7 @@ class MCValue {
6777
R.Cst = Val;
6878
R.SymA = 0;
6979
R.SymB = 0;
80+
R.RefKind = 0;
7081
return R;
7182
}
7283

llvm/lib/MC/MCValue.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ void MCValue::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
2020
return;
2121
}
2222

23+
// FIXME: prints as a number, which isn't ideal. But the meaning will be
24+
// target-specific anyway.
25+
if (getRefKind())
26+
OS << ':' << getRefKind() << ':';
27+
2328
getSymA()->print(OS);
2429

2530
if (getSymB()) {

0 commit comments

Comments
 (0)