@@ -34,6 +34,14 @@ static cl::opt<bool> ULEB128Reloc(
3434 " riscv-uleb128-reloc" , cl::init(true ), cl::Hidden,
3535 cl::desc(" Emit R_RISCV_SET_ULEB128/E_RISCV_SUB_ULEB128 if appropriate" ));
3636
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+
3745std::optional<MCFixupKind> RISCVAsmBackend::getFixupKind (StringRef Name) const {
3846 if (STI.getTargetTriple ().isOSBinFormatELF ()) {
3947 unsigned Type;
@@ -71,27 +79,13 @@ RISCVAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
7179 MCFixupKindInfo::FKF_IsPCRel | MCFixupKindInfo::FKF_IsTarget},
7280 {" fixup_riscv_pcrel_lo12_s" , 0 , 32 ,
7381 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},
8182 {" fixup_riscv_jal" , 12 , 20 , MCFixupKindInfo::FKF_IsPCRel},
8283 {" fixup_riscv_branch" , 0 , 32 , MCFixupKindInfo::FKF_IsPCRel},
8384 {" fixup_riscv_rvc_jump" , 2 , 11 , MCFixupKindInfo::FKF_IsPCRel},
8485 {" fixup_riscv_rvc_branch" , 0 , 16 , MCFixupKindInfo::FKF_IsPCRel},
8586 {" fixup_riscv_call" , 0 , 64 , MCFixupKindInfo::FKF_IsPCRel},
8687 {" fixup_riscv_call_plt" , 0 , 64 , MCFixupKindInfo::FKF_IsPCRel},
87- {" fixup_riscv_relax" , 0 , 0 , 0 },
88- {" fixup_riscv_align" , 0 , 0 , 0 },
8988
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 },
9589 {" fixup_riscv_qc_e_branch" , 0 , 48 , MCFixupKindInfo::FKF_IsPCRel},
9690 {" fixup_riscv_qc_e_32" , 16 , 32 , 0 },
9791 {" fixup_riscv_qc_abs20_u" , 12 , 20 , 0 },
@@ -100,9 +94,9 @@ RISCVAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
10094 static_assert ((std::size (Infos)) == RISCV::NumTargetFixupKinds,
10195 " Not all fixup kinds added to Infos array" );
10296
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 )
106100 return MCAsmBackend::getFixupKindInfo (FK_NONE);
107101
108102 if (Kind < FirstTargetFixupKind)
@@ -131,11 +125,6 @@ bool RISCVAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
131125 if (Target.isAbsolute ())
132126 return false ;
133127 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 ;
139128 }
140129
141130 return STI->hasFeature (RISCV::FeatureRelax) || ForceRelocs;
@@ -456,11 +445,6 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, uint64_t Value,
456445 switch (Fixup.getTargetKind ()) {
457446 default :
458447 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 " );
464448 case FK_Data_1:
465449 case FK_Data_2:
466450 case FK_Data_4:
@@ -469,8 +453,6 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, uint64_t Value,
469453 return Value;
470454 case RISCV::fixup_riscv_lo12_i:
471455 case RISCV::fixup_riscv_pcrel_lo12_i:
472- case RISCV::fixup_riscv_tprel_lo12_i:
473- case RISCV::fixup_riscv_tlsdesc_load_lo12:
474456 return Value & 0xfff ;
475457 case RISCV::fixup_riscv_12_i:
476458 if (!isInt<12 >(Value)) {
@@ -480,11 +462,9 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, uint64_t Value,
480462 return Value & 0xfff ;
481463 case RISCV::fixup_riscv_lo12_s:
482464 case RISCV::fixup_riscv_pcrel_lo12_s:
483- case RISCV::fixup_riscv_tprel_lo12_s:
484465 return (((Value >> 5 ) & 0x7f ) << 25 ) | ((Value & 0x1f ) << 7 );
485466 case RISCV::fixup_riscv_hi20:
486467 case RISCV::fixup_riscv_pcrel_hi20:
487- case RISCV::fixup_riscv_tprel_hi20:
488468 // Add 1 if bit 11 is 1, to compensate for low 12 bits being negative.
489469 return ((Value + 0x800 ) >> 12 ) & 0xfffff ;
490470 case RISCV::fixup_riscv_jal: {
@@ -602,7 +582,6 @@ bool RISCVAsmBackend::evaluateTargetFixup(
602582 switch (Fixup.getTargetKind ()) {
603583 default :
604584 llvm_unreachable (" Unexpected fixup kind!" );
605- case RISCV::fixup_riscv_tlsdesc_hi20:
606585 case RISCV::fixup_riscv_pcrel_hi20:
607586 AUIPCFixup = &Fixup;
608587 AUIPCDF = DF;
@@ -642,7 +621,7 @@ bool RISCVAsmBackend::evaluateTargetFixup(
642621 Value = Asm.getSymbolOffset (SA) + AUIPCTarget.getConstant ();
643622 Value -= Asm.getFragmentOffset (*AUIPCDF) + AUIPCFixup->getOffset ();
644623
645- return ! shouldForceRelocation (Asm, *AUIPCFixup, AUIPCTarget, STI) ;
624+ return AUIPCFixup-> getTargetKind () == RISCV::fixup_riscv_pcrel_hi20 ;
646625}
647626
648627bool RISCVAsmBackend::handleAddSubRelocations (const MCAssembler &Asm,
@@ -680,12 +659,10 @@ bool RISCVAsmBackend::handleAddSubRelocations(const MCAssembler &Asm,
680659 }
681660 MCValue A = MCValue::get (Target.getAddSym (), nullptr , Target.getConstant ());
682661 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);
689666 auto &Assembler = const_cast <MCAssembler &>(Asm);
690667 Asm.getWriter ().recordRelocation (Assembler, &F, FA, A, FixedValueA);
691668 Asm.getWriter ().recordRelocation (Assembler, &F, FB, B, FixedValueB);
@@ -699,7 +676,7 @@ void RISCVAsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
699676 bool IsResolved,
700677 const MCSubtargetInfo *STI) const {
701678 MCFixupKind Kind = Fixup.getKind ();
702- if (Kind >= FirstLiteralRelocationKind )
679+ if (Kind >= FirstRelocationKind )
703680 return ;
704681 MCContext &Ctx = Asm.getContext ();
705682 MCFixupKindInfo Info = getFixupKindInfo (Kind);
@@ -767,8 +744,8 @@ bool RISCVAsmBackend::shouldInsertFixupForCodeAlign(MCAssembler &Asm,
767744 MCContext &Ctx = Asm.getContext ();
768745 const MCExpr *Dummy = MCConstantExpr::create (0 , Ctx);
769746 // 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 ());
772749
773750 uint64_t FixedValue = 0 ;
774751 MCValue NopBytes = MCValue::get (Count);
0 commit comments