@@ -873,69 +873,20 @@ void MCAssembler::layout() {
873
873
// Evaluate and apply the fixups, generating relocation entries as necessary.
874
874
for (MCSection &Sec : *this ) {
875
875
for (MCFragment &Frag : Sec) {
876
- MutableArrayRef<MCFixup> Fixups;
877
- MutableArrayRef<char > Contents;
878
-
879
- // Process MCAlignFragment and MCEncodedFragmentWithFixups here.
880
- switch (Frag.getKind ()) {
881
- default :
882
- continue ;
883
- case MCFragment::FT_Align: {
884
- MCAlignFragment &AF = cast<MCAlignFragment>(Frag);
885
- // Insert fixup type for code alignment if the target define
886
- // shouldInsertFixupForCodeAlign target hook.
887
- if (Sec.useCodeAlign () && AF.hasEmitNops ())
888
- getBackend ().shouldInsertFixupForCodeAlign (*this , AF);
889
- continue ;
890
- }
891
- case MCFragment::FT_Data: {
892
- MCDataFragment &DF = cast<MCDataFragment>(Frag);
893
- Fixups = DF.getFixups ();
894
- Contents = DF.getContents ();
895
- break ;
896
- }
897
- case MCFragment::FT_Relaxable: {
898
- MCRelaxableFragment &RF = cast<MCRelaxableFragment>(Frag);
899
- Fixups = RF.getFixups ();
900
- Contents = RF.getContents ();
901
- break ;
902
- }
903
- case MCFragment::FT_CVDefRange: {
904
- MCCVDefRangeFragment &CF = cast<MCCVDefRangeFragment>(Frag);
905
- Fixups = CF.getFixups ();
906
- Contents = CF.getContents ();
907
- break ;
908
- }
909
- case MCFragment::FT_Dwarf: {
910
- MCDwarfLineAddrFragment &DF = cast<MCDwarfLineAddrFragment>(Frag);
911
- Fixups = DF.getFixups ();
912
- Contents = DF.getContents ();
913
- break ;
914
- }
915
- case MCFragment::FT_DwarfFrame: {
916
- MCDwarfCallFrameFragment &DF = cast<MCDwarfCallFrameFragment>(Frag);
917
- Fixups = DF.getFixups ();
918
- Contents = DF.getContents ();
919
- break ;
920
- }
921
- case MCFragment::FT_LEB: {
922
- auto &LF = cast<MCLEBFragment>(Frag);
923
- Fixups = LF.getFixups ();
924
- Contents = LF.getContents ();
925
- break ;
926
- }
927
- case MCFragment::FT_PseudoProbe: {
928
- MCPseudoProbeAddrFragment &PF = cast<MCPseudoProbeAddrFragment>(Frag);
929
- Fixups = PF.getFixups ();
930
- Contents = PF.getContents ();
931
- break ;
932
- }
933
- }
934
- for (const MCFixup &Fixup : Fixups) {
935
- uint64_t FixedValue;
936
- MCValue Target;
937
- evaluateFixup (Frag, Fixup, Target, FixedValue,
938
- /* RecordReloc=*/ true , Contents);
876
+ // Process fragments with fixups here.
877
+ if (auto *F = dyn_cast<MCEncodedFragment>(&Frag)) {
878
+ auto Contents = F->getContents ();
879
+ for (const MCFixup &Fixup : F->getFixups ()) {
880
+ uint64_t FixedValue;
881
+ MCValue Target;
882
+ evaluateFixup (Frag, Fixup, Target, FixedValue,
883
+ /* RecordReloc=*/ true , Contents);
884
+ }
885
+ } else if (auto *AF = dyn_cast<MCAlignFragment>(&Frag)) {
886
+ // For RISC-V linker relaxation, an alignment relocation might be
887
+ // needed.
888
+ if (AF->hasEmitNops ())
889
+ getBackend ().shouldInsertFixupForCodeAlign (*this , *AF);
939
890
}
940
891
}
941
892
}
0 commit comments