@@ -38,25 +38,15 @@ PPCELFObjectWriter::PPCELFObjectWriter(bool Is64Bit, uint8_t OSABI)
38
38
Is64Bit ? ELF::EM_PPC64 : ELF::EM_PPC,
39
39
/* HasRelocationAddend*/ true ) {}
40
40
41
- static PPCMCExpr::Specifier getAccessVariant (const MCValue &Target,
42
- const MCFixup &Fixup) {
43
- const MCExpr *Expr = Fixup.getValue ();
44
-
45
- if (Expr->getKind () != MCExpr::Target)
46
- return PPCMCExpr::Specifier (Target.getAccessVariant ());
47
- return cast<PPCMCExpr>(Expr)->getSpecifier ();
48
- }
49
-
50
41
unsigned PPCELFObjectWriter::getRelocType (MCContext &Ctx, const MCValue &Target,
51
42
const MCFixup &Fixup,
52
43
bool IsPCRel) const {
53
44
MCFixupKind Kind = Fixup.getKind ();
54
45
if (Kind >= FirstLiteralRelocationKind)
55
46
return Kind - FirstLiteralRelocationKind;
56
- auto RefKind = static_cast <PPCMCExpr::Specifier>(Target.getRefKind ());
57
- auto Modifier = getAccessVariant (Target, Fixup);
58
-
59
- switch (PPCMCExpr::Specifier (Modifier)) {
47
+ SMLoc Loc = Fixup.getValue ()->getLoc ();
48
+ auto Spec = static_cast <PPCMCExpr::Specifier>(Target.getSpecifier ());
49
+ switch (Spec) {
60
50
case PPCMCExpr::VK_DTPMOD:
61
51
case PPCMCExpr::VK_DTPREL:
62
52
case PPCMCExpr::VK_DTPREL_HA:
@@ -108,16 +98,18 @@ unsigned PPCELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
108
98
}
109
99
110
100
// determine the type of the relocation
111
- unsigned Type;
101
+ unsigned Type = 0 ;
112
102
if (IsPCRel) {
113
103
switch (Fixup.getTargetKind ()) {
114
104
default :
115
105
llvm_unreachable (" Unimplemented" );
116
106
case PPC::fixup_ppc_br24:
117
107
case PPC::fixup_ppc_br24abs:
118
108
case PPC::fixup_ppc_br24_notoc:
119
- switch (Modifier) {
120
- default : llvm_unreachable (" Unsupported Modifier" );
109
+ switch (Spec) {
110
+ default :
111
+ Ctx.reportError (Loc, " unsupported relocation type" );
112
+ break ;
121
113
case PPCMCExpr::VK_None:
122
114
Type = ELF::R_PPC_REL24;
123
115
break ;
@@ -137,9 +129,9 @@ unsigned PPCELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
137
129
Type = ELF::R_PPC_REL14;
138
130
break ;
139
131
case PPC::fixup_ppc_half16:
140
- switch (RefKind ) {
132
+ switch (Spec ) {
141
133
default :
142
- Ctx.reportError (Fixup. getLoc () , " invalid VariantKind " );
134
+ Ctx.reportError (Loc , " unsupported relocation type " );
143
135
return ELF::R_PPC_NONE;
144
136
case PPCMCExpr::VK_None:
145
137
return ELF::R_PPC_REL16;
@@ -157,9 +149,10 @@ unsigned PPCELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
157
149
errs () << ' \n ' ;
158
150
report_fatal_error (" Invalid PC-relative half16ds relocation" );
159
151
case PPC::fixup_ppc_pcrel34:
160
- switch (Modifier ) {
152
+ switch (Spec ) {
161
153
default :
162
- llvm_unreachable (" Unsupported Modifier for fixup_ppc_pcrel34" );
154
+ Ctx.reportError (Loc, " unsupported relocation type" );
155
+ break ;
163
156
case PPCMCExpr::VK_PCREL:
164
157
Type = ELF::R_PPC64_PCREL34;
165
158
break ;
@@ -196,9 +189,10 @@ unsigned PPCELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
196
189
Type = ELF::R_PPC_ADDR14; // XXX: or BRNTAKEN?_
197
190
break ;
198
191
case PPC::fixup_ppc_half16:
199
- switch (Modifier ) {
192
+ switch (Spec ) {
200
193
default :
201
- llvm_unreachable (" Unsupported specifier" );
194
+ Ctx.reportError (Loc, " unsupported relocation type" );
195
+ break ;
202
196
case PPCMCExpr::VK_LO:
203
197
return ELF::R_PPC_ADDR16_LO;
204
198
case PPCMCExpr::VK_HI:
@@ -371,10 +365,10 @@ unsigned PPCELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
371
365
break ;
372
366
case PPC::fixup_ppc_half16ds:
373
367
case PPC::fixup_ppc_half16dq:
374
- switch (Modifier ) {
368
+ switch (Spec ) {
375
369
default :
376
- Ctx.reportError (Fixup. getLoc () , " invalid VariantKind " );
377
- return ELF::R_PPC64_NONE ;
370
+ Ctx.reportError (Loc , " unsupported relocation type " );
371
+ break ;
378
372
case PPCMCExpr::VK_LO:
379
373
return ELF::R_PPC64_ADDR16_LO_DS;
380
374
case PPCMCExpr::VK_None:
@@ -419,8 +413,10 @@ unsigned PPCELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
419
413
}
420
414
break ;
421
415
case PPC::fixup_ppc_nofixup:
422
- switch (Modifier) {
423
- default : llvm_unreachable (" Unsupported Modifier" );
416
+ switch (Spec) {
417
+ default :
418
+ Ctx.reportError (Loc, " unsupported relocation type" );
419
+ break ;
424
420
case PPCMCExpr::VK_TLSGD:
425
421
if (is64Bit ())
426
422
Type = ELF::R_PPC64_TLSGD;
@@ -445,9 +441,10 @@ unsigned PPCELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
445
441
}
446
442
break ;
447
443
case PPC::fixup_ppc_imm34:
448
- switch (Modifier ) {
444
+ switch (Spec ) {
449
445
default :
450
- report_fatal_error (" Unsupported Modifier for fixup_ppc_imm34." );
446
+ Ctx.reportError (Loc, " unsupported relocation type" );
447
+ break ;
451
448
case PPCMCExpr::VK_DTPREL:
452
449
Type = ELF::R_PPC64_DTPREL34;
453
450
break ;
@@ -457,8 +454,10 @@ unsigned PPCELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
457
454
}
458
455
break ;
459
456
case FK_Data_8:
460
- switch (Modifier) {
461
- default : llvm_unreachable (" Unsupported Modifier" );
457
+ switch (Spec) {
458
+ default :
459
+ Ctx.reportError (Loc, " unsupported relocation type" );
460
+ break ;
462
461
case PPCMCExpr::VK_TOCBASE:
463
462
Type = ELF::R_PPC64_TOC;
464
463
break ;
@@ -477,7 +476,7 @@ unsigned PPCELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
477
476
}
478
477
break ;
479
478
case FK_Data_4:
480
- switch (Modifier ) {
479
+ switch (Spec ) {
481
480
case PPCMCExpr::VK_DTPREL:
482
481
Type = ELF::R_PPC_DTPREL32;
483
482
break ;
0 commit comments