@@ -34,6 +34,14 @@ static cl::opt<bool> ULEB128Reloc(
34
34
" riscv-uleb128-reloc" , cl::init(true ), cl::Hidden,
35
35
cl::desc(" Emit R_RISCV_SET_ULEB128/E_RISCV_SUB_ULEB128 if appropriate" ));
36
36
37
+ RISCVAsmBackend::RISCVAsmBackend (const MCSubtargetInfo &STI, uint8_t OSABI,
38
+ bool Is64Bit, const MCTargetOptions &Options)
39
+ : MCAsmBackend(llvm::endianness::little,
40
+ FirstRelocationKind + ELF::R_RISCV_RELAX),
41
+ STI(STI), OSABI(OSABI), Is64Bit(Is64Bit), TargetOptions(Options) {
42
+ RISCVFeatures::validate (STI.getTargetTriple (), STI.getFeatureBits ());
43
+ }
44
+
37
45
std::optional<MCFixupKind> RISCVAsmBackend::getFixupKind (StringRef Name) const {
38
46
if (STI.getTargetTriple ().isOSBinFormatELF ()) {
39
47
unsigned Type;
@@ -71,27 +79,13 @@ RISCVAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
71
79
MCFixupKindInfo::FKF_IsPCRel | MCFixupKindInfo::FKF_IsTarget},
72
80
{" fixup_riscv_pcrel_lo12_s" , 0 , 32 ,
73
81
MCFixupKindInfo::FKF_IsPCRel | MCFixupKindInfo::FKF_IsTarget},
74
- {" fixup_riscv_got_hi20" , 12 , 20 , MCFixupKindInfo::FKF_IsPCRel},
75
- {" fixup_riscv_tprel_hi20" , 12 , 20 , 0 },
76
- {" fixup_riscv_tprel_lo12_i" , 20 , 12 , 0 },
77
- {" fixup_riscv_tprel_lo12_s" , 0 , 32 , 0 },
78
- {" fixup_riscv_tprel_add" , 0 , 0 , 0 },
79
- {" fixup_riscv_tls_got_hi20" , 12 , 20 , MCFixupKindInfo::FKF_IsPCRel},
80
- {" fixup_riscv_tls_gd_hi20" , 12 , 20 , MCFixupKindInfo::FKF_IsPCRel},
81
82
{" fixup_riscv_jal" , 12 , 20 , MCFixupKindInfo::FKF_IsPCRel},
82
83
{" fixup_riscv_branch" , 0 , 32 , MCFixupKindInfo::FKF_IsPCRel},
83
84
{" fixup_riscv_rvc_jump" , 2 , 11 , MCFixupKindInfo::FKF_IsPCRel},
84
85
{" fixup_riscv_rvc_branch" , 0 , 16 , MCFixupKindInfo::FKF_IsPCRel},
85
86
{" fixup_riscv_call" , 0 , 64 , MCFixupKindInfo::FKF_IsPCRel},
86
87
{" fixup_riscv_call_plt" , 0 , 64 , MCFixupKindInfo::FKF_IsPCRel},
87
- {" fixup_riscv_relax" , 0 , 0 , 0 },
88
- {" fixup_riscv_align" , 0 , 0 , 0 },
89
88
90
- {" fixup_riscv_tlsdesc_hi20" , 12 , 20 ,
91
- MCFixupKindInfo::FKF_IsPCRel | MCFixupKindInfo::FKF_IsTarget},
92
- {" fixup_riscv_tlsdesc_load_lo12" , 20 , 12 , 0 },
93
- {" fixup_riscv_tlsdesc_add_lo12" , 20 , 12 , 0 },
94
- {" fixup_riscv_tlsdesc_call" , 0 , 0 , 0 },
95
89
{" fixup_riscv_qc_e_branch" , 0 , 48 , MCFixupKindInfo::FKF_IsPCRel},
96
90
{" fixup_riscv_qc_e_32" , 16 , 32 , 0 },
97
91
{" fixup_riscv_qc_abs20_u" , 12 , 20 , 0 },
@@ -100,9 +94,9 @@ RISCVAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
100
94
static_assert ((std::size (Infos)) == RISCV::NumTargetFixupKinds,
101
95
" Not all fixup kinds added to Infos array" );
102
96
103
- // Fixup kinds from .reloc directive are like R_RISCV_NONE. They
104
- // do not require any extra processing.
105
- if (Kind >= FirstLiteralRelocationKind )
97
+ // Fixup kinds from raw relocation types and .reloc directive are like
98
+ // R_RISCV_NONE. They do not require any extra processing.
99
+ if (Kind >= FirstRelocationKind )
106
100
return MCAsmBackend::getFixupKindInfo (FK_NONE);
107
101
108
102
if (Kind < FirstTargetFixupKind)
@@ -131,11 +125,6 @@ bool RISCVAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
131
125
if (Target.isAbsolute ())
132
126
return false ;
133
127
break ;
134
- case RISCV::fixup_riscv_got_hi20:
135
- case RISCV::fixup_riscv_tls_got_hi20:
136
- case RISCV::fixup_riscv_tls_gd_hi20:
137
- case RISCV::fixup_riscv_tlsdesc_hi20:
138
- return true ;
139
128
}
140
129
141
130
return STI->hasFeature (RISCV::FeatureRelax) || ForceRelocs;
@@ -456,11 +445,6 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, uint64_t Value,
456
445
switch (Fixup.getTargetKind ()) {
457
446
default :
458
447
llvm_unreachable (" Unknown fixup kind!" );
459
- case RISCV::fixup_riscv_got_hi20:
460
- case RISCV::fixup_riscv_tls_got_hi20:
461
- case RISCV::fixup_riscv_tls_gd_hi20:
462
- case RISCV::fixup_riscv_tlsdesc_hi20:
463
- llvm_unreachable (" Relocation should be unconditionally forced\n " );
464
448
case FK_Data_1:
465
449
case FK_Data_2:
466
450
case FK_Data_4:
@@ -469,8 +453,6 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, uint64_t Value,
469
453
return Value;
470
454
case RISCV::fixup_riscv_lo12_i:
471
455
case RISCV::fixup_riscv_pcrel_lo12_i:
472
- case RISCV::fixup_riscv_tprel_lo12_i:
473
- case RISCV::fixup_riscv_tlsdesc_load_lo12:
474
456
return Value & 0xfff ;
475
457
case RISCV::fixup_riscv_12_i:
476
458
if (!isInt<12 >(Value)) {
@@ -480,11 +462,9 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, uint64_t Value,
480
462
return Value & 0xfff ;
481
463
case RISCV::fixup_riscv_lo12_s:
482
464
case RISCV::fixup_riscv_pcrel_lo12_s:
483
- case RISCV::fixup_riscv_tprel_lo12_s:
484
465
return (((Value >> 5 ) & 0x7f ) << 25 ) | ((Value & 0x1f ) << 7 );
485
466
case RISCV::fixup_riscv_hi20:
486
467
case RISCV::fixup_riscv_pcrel_hi20:
487
- case RISCV::fixup_riscv_tprel_hi20:
488
468
// Add 1 if bit 11 is 1, to compensate for low 12 bits being negative.
489
469
return ((Value + 0x800 ) >> 12 ) & 0xfffff ;
490
470
case RISCV::fixup_riscv_jal: {
@@ -602,7 +582,6 @@ bool RISCVAsmBackend::evaluateTargetFixup(
602
582
switch (Fixup.getTargetKind ()) {
603
583
default :
604
584
llvm_unreachable (" Unexpected fixup kind!" );
605
- case RISCV::fixup_riscv_tlsdesc_hi20:
606
585
case RISCV::fixup_riscv_pcrel_hi20:
607
586
AUIPCFixup = &Fixup;
608
587
AUIPCDF = DF;
@@ -642,7 +621,7 @@ bool RISCVAsmBackend::evaluateTargetFixup(
642
621
Value = Asm.getSymbolOffset (SA) + AUIPCTarget.getConstant ();
643
622
Value -= Asm.getFragmentOffset (*AUIPCDF) + AUIPCFixup->getOffset ();
644
623
645
- return ! shouldForceRelocation (Asm, *AUIPCFixup, AUIPCTarget, STI) ;
624
+ return AUIPCFixup-> getTargetKind () == RISCV::fixup_riscv_pcrel_hi20 ;
646
625
}
647
626
648
627
bool RISCVAsmBackend::handleAddSubRelocations (const MCAssembler &Asm,
@@ -680,12 +659,10 @@ bool RISCVAsmBackend::handleAddSubRelocations(const MCAssembler &Asm,
680
659
}
681
660
MCValue A = MCValue::get (Target.getAddSym (), nullptr , Target.getConstant ());
682
661
MCValue B = MCValue::get (Target.getSubSym ());
683
- auto FA = MCFixup::create (
684
- Fixup.getOffset (), nullptr ,
685
- static_cast <MCFixupKind>(FirstLiteralRelocationKind + TA));
686
- auto FB = MCFixup::create (
687
- Fixup.getOffset (), nullptr ,
688
- static_cast <MCFixupKind>(FirstLiteralRelocationKind + TB));
662
+ auto FA =
663
+ MCFixup::create (Fixup.getOffset (), nullptr , FirstRelocationKind + TA);
664
+ auto FB =
665
+ MCFixup::create (Fixup.getOffset (), nullptr , FirstRelocationKind + TB);
689
666
auto &Assembler = const_cast <MCAssembler &>(Asm);
690
667
Asm.getWriter ().recordRelocation (Assembler, &F, FA, A, FixedValueA);
691
668
Asm.getWriter ().recordRelocation (Assembler, &F, FB, B, FixedValueB);
@@ -699,7 +676,7 @@ void RISCVAsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
699
676
bool IsResolved,
700
677
const MCSubtargetInfo *STI) const {
701
678
MCFixupKind Kind = Fixup.getKind ();
702
- if (Kind >= FirstLiteralRelocationKind )
679
+ if (Kind >= FirstRelocationKind )
703
680
return ;
704
681
MCContext &Ctx = Asm.getContext ();
705
682
MCFixupKindInfo Info = getFixupKindInfo (Kind);
@@ -767,8 +744,8 @@ bool RISCVAsmBackend::shouldInsertFixupForCodeAlign(MCAssembler &Asm,
767
744
MCContext &Ctx = Asm.getContext ();
768
745
const MCExpr *Dummy = MCConstantExpr::create (0 , Ctx);
769
746
// Create fixup_riscv_align fixup.
770
- MCFixup Fixup =
771
- MCFixup::create ( 0 , Dummy, MCFixupKind (RISCV::fixup_riscv_align) , SMLoc ());
747
+ MCFixup Fixup = MCFixup::create (
748
+ 0 , Dummy, FirstRelocationKind + ELF::R_RISCV_ALIGN , SMLoc ());
772
749
773
750
uint64_t FixedValue = 0 ;
774
751
MCValue NopBytes = MCValue::get (Count);
0 commit comments