@@ -138,7 +138,7 @@ bool MCAssembler::isThumbFunc(const MCSymbol *Symbol) const {
138138
139139bool MCAssembler::evaluateFixup (const MCFixup &Fixup, const MCFragment *DF,
140140 MCValue &Target, const MCSubtargetInfo *STI,
141- uint64_t &Value, bool &WasForced ) const {
141+ uint64_t &Value, bool RecordReloc ) const {
142142 ++stats::evaluateFixup;
143143
144144 // FIXME: This code has some duplication with recordRelocation. We should
@@ -150,47 +150,51 @@ bool MCAssembler::evaluateFixup(const MCFixup &Fixup, const MCFragment *DF,
150150 const MCExpr *Expr = Fixup.getValue ();
151151 MCContext &Ctx = getContext ();
152152 Value = 0 ;
153- WasForced = false ;
154153 if (!Expr->evaluateAsRelocatable (Target, this )) {
155154 Ctx.reportError (Fixup.getLoc (), " expected relocatable expression" );
156155 return true ;
157156 }
158157
159- unsigned FixupFlags = getBackend ().getFixupKindInfo (Fixup.getKind ()).Flags ;
160- if (FixupFlags & MCFixupKindInfo::FKF_IsTarget)
161- return getBackend ().evaluateTargetFixup (*this , Fixup, DF, Target, STI,
162- Value, WasForced);
163-
164- const MCSymbol *Add = Target.getAddSym ();
165- const MCSymbol *Sub = Target.getSubSym ();
166- bool IsPCRel = FixupFlags & MCFixupKindInfo::FKF_IsPCRel;
167158 bool IsResolved = false ;
168- if (!IsPCRel) {
169- IsResolved = Target.isAbsolute ();
170- } else if (Add && !Sub && !Add->isUndefined () && !Add->isAbsolute ()) {
171- IsResolved = (FixupFlags & MCFixupKindInfo::FKF_Constant) ||
172- getWriter ().isSymbolRefDifferenceFullyResolvedImpl (
173- *this , *Add, *DF, false , true );
159+ unsigned FixupFlags = getBackend ().getFixupKindInfo (Fixup.getKind ()).Flags ;
160+ if (FixupFlags & MCFixupKindInfo::FKF_IsTarget) {
161+ IsResolved =
162+ getBackend ().evaluateTargetFixup (*this , Fixup, DF, Target, STI, Value);
163+ } else {
164+ const MCSymbol *Add = Target.getAddSym ();
165+ const MCSymbol *Sub = Target.getSubSym ();
166+ Value = Target.getConstant ();
167+ if (Add && Add->isDefined ())
168+ Value += getSymbolOffset (*Add);
169+ if (Sub && Sub->isDefined ())
170+ Value -= getSymbolOffset (*Sub);
171+
172+ bool IsPCRel = FixupFlags & MCFixupKindInfo::FKF_IsPCRel;
173+ bool ShouldAlignPC =
174+ FixupFlags & MCFixupKindInfo::FKF_IsAlignedDownTo32Bits;
175+ if (IsPCRel) {
176+ uint64_t Offset = getFragmentOffset (*DF) + Fixup.getOffset ();
177+
178+ // A number of ARM fixups in Thumb mode require that the effective PC
179+ // address be determined as the 32-bit aligned version of the actual
180+ // offset.
181+ if (ShouldAlignPC)
182+ Offset &= ~0x3 ;
183+ Value -= Offset;
184+
185+ if (Add && !Sub && !Add->isUndefined () && !Add->isAbsolute ()) {
186+ IsResolved = (FixupFlags & MCFixupKindInfo::FKF_Constant) ||
187+ getWriter ().isSymbolRefDifferenceFullyResolvedImpl (
188+ *this , *Add, *DF, false , true );
189+ }
190+ } else {
191+ IsResolved = Target.isAbsolute ();
192+ assert (!ShouldAlignPC && " FKF_IsAlignedDownTo32Bits must be PC-relative" );
193+ }
174194 }
175195
176- Value = Target.getConstant ();
177- if (Add && Add->isDefined ())
178- Value += getSymbolOffset (*Add);
179- if (Sub && Sub->isDefined ())
180- Value -= getSymbolOffset (*Sub);
181-
182- bool ShouldAlignPC = FixupFlags & MCFixupKindInfo::FKF_IsAlignedDownTo32Bits;
183- assert ((ShouldAlignPC ? IsPCRel : true ) &&
184- " FKF_IsAlignedDownTo32Bits is only allowed on PC-relative fixups!" );
185-
186- if (IsPCRel) {
187- uint64_t Offset = getFragmentOffset (*DF) + Fixup.getOffset ();
188-
189- // A number of ARM fixups in Thumb mode require that the effective PC
190- // address be determined as the 32-bit aligned version of the actual offset.
191- if (ShouldAlignPC) Offset &= ~0x3 ;
192- Value -= Offset;
193- }
196+ if (!RecordReloc)
197+ return IsResolved;
194198
195199 // .reloc directive and the backend might force the relocation.
196200 // Backends that customize shouldForceRelocation generally just need the fixup
@@ -200,12 +204,12 @@ bool MCAssembler::evaluateFixup(const MCFixup &Fixup, const MCFragment *DF,
200204 auto TargetVal = Target;
201205 TargetVal.Cst = Value;
202206 if (Fixup.getKind () >= FirstLiteralRelocationKind ||
203- getBackend ().shouldForceRelocation (*this , Fixup, TargetVal, STI)) {
207+ getBackend ().shouldForceRelocation (*this , Fixup, TargetVal, STI))
204208 IsResolved = false ;
205- WasForced = true ;
206- }
207209 }
208-
210+ if (!IsResolved)
211+ getWriter ().recordRelocation (const_cast <MCAssembler &>(*this ), DF, Fixup,
212+ Target, Value);
209213 return IsResolved;
210214}
211215
@@ -844,24 +848,6 @@ void MCAssembler::writeSectionData(raw_ostream &OS,
844848 OS.tell () - Start == getSectionAddressSize (*Sec));
845849}
846850
847- std::tuple<MCValue, uint64_t , bool >
848- MCAssembler::handleFixup (MCFragment &F, const MCFixup &Fixup,
849- const MCSubtargetInfo *STI) {
850- // Evaluate the fixup.
851- MCValue Target;
852- uint64_t FixedValue;
853- bool WasForced;
854- bool IsResolved =
855- evaluateFixup (Fixup, &F, Target, STI, FixedValue, WasForced);
856- if (!IsResolved) {
857- // The fixup was unresolved, we need a relocation. Inform the object
858- // writer of the relocation, and give it an opportunity to adjust the
859- // fixup value if need be.
860- getWriter ().recordRelocation (*this , &F, Fixup, Target, FixedValue);
861- }
862- return std::make_tuple (Target, FixedValue, IsResolved);
863- }
864-
865851void MCAssembler::layout () {
866852 assert (getBackendPtr () && " Expected assembler backend" );
867853 DEBUG_WITH_TYPE (" mc-dump" , {
@@ -987,10 +973,9 @@ void MCAssembler::layout() {
987973 }
988974 for (const MCFixup &Fixup : Fixups) {
989975 uint64_t FixedValue;
990- bool IsResolved;
991976 MCValue Target;
992- std::tie (Target, FixedValue, IsResolved) =
993- handleFixup (Frag, Fixup, STI );
977+ bool IsResolved = evaluateFixup (Fixup, &Frag, Target, STI, FixedValue,
978+ /* RecordReloc= */ true );
994979 getBackend ().applyFixup (*this , Fixup, Target, Contents, FixedValue,
995980 IsResolved, STI);
996981 }
@@ -1012,11 +997,10 @@ bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup,
1012997 assert (getBackendPtr () && " Expected assembler backend" );
1013998 MCValue Target;
1014999 uint64_t Value;
1015- bool WasForced;
10161000 bool Resolved = evaluateFixup (Fixup, DF, Target, DF->getSubtargetInfo (),
1017- Value, WasForced );
1001+ Value, /* RecordReloc= */ false );
10181002 return getBackend ().fixupNeedsRelaxationAdvanced (*this , *DF, Fixup, Target,
1019- Value, Resolved, WasForced );
1003+ Value, Resolved);
10201004}
10211005
10221006bool MCAssembler::fragmentNeedsRelaxation (const MCRelaxableFragment *F) const {
0 commit comments