@@ -432,8 +432,8 @@ bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
432
432
return true ;
433
433
}
434
434
435
- bool IsRelocatable = EvaluateAsRelocatableImpl (
436
- Value, Asm, Layout, nullptr , Addrs, InSet, /* ForceVarExpansion */ true );
435
+ bool IsRelocatable =
436
+ EvaluateAsRelocatableImpl ( Value, Asm, Layout, nullptr , Addrs, InSet);
437
437
438
438
// Record the current value.
439
439
Res = Value.getConstant ();
@@ -586,21 +586,21 @@ bool MCExpr::EvaluateAsRelocatable(MCValue &Res,
586
586
const MCFixup *Fixup) const {
587
587
MCAssembler *Assembler = Layout ? &Layout->getAssembler () : nullptr ;
588
588
return EvaluateAsRelocatableImpl (Res, Assembler, Layout, Fixup, nullptr ,
589
- false , /* ForceVarExpansion */ false );
589
+ false );
590
590
}
591
591
592
- bool MCExpr::EvaluateAsValue (MCValue &Res , const MCAsmLayout *Layout,
593
- const MCFixup *Fixup) const {
594
- MCAssembler *Assembler = Layout ? &Layout-> getAssembler () : nullptr ;
595
- return EvaluateAsRelocatableImpl (Res, Assembler, Layout, Fixup, nullptr ,
596
- false , /* ForceVarExpansion */ true );
592
+ static bool canExpand ( const MCSymbol &Sym , const MCAssembler *Asm) {
593
+ if (!Asm)
594
+ return false ;
595
+ const MCSymbolData &SD = Asm-> getSymbolData (Sym);
596
+ return !Asm-> getWriter (). isWeak (SD );
597
597
}
598
598
599
599
bool MCExpr::EvaluateAsRelocatableImpl (MCValue &Res, const MCAssembler *Asm,
600
600
const MCAsmLayout *Layout,
601
601
const MCFixup *Fixup,
602
- const SectionAddrMap *Addrs, bool InSet,
603
- bool ForceVarExpansion ) const {
602
+ const SectionAddrMap *Addrs,
603
+ bool InSet ) const {
604
604
++stats::MCExprEvaluate;
605
605
606
606
switch (getKind ()) {
@@ -617,28 +617,23 @@ bool MCExpr::EvaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
617
617
const MCSymbol &Sym = SRE->getSymbol ();
618
618
619
619
// Evaluate recursively if this is a variable.
620
- if (Sym.isVariable () && SRE->getKind () == MCSymbolRefExpr::VK_None) {
620
+ if (Sym.isVariable () && SRE->getKind () == MCSymbolRefExpr::VK_None &&
621
+ canExpand (Sym, Asm)) {
621
622
if (Sym.getVariableValue ()->EvaluateAsRelocatableImpl (
622
- Res, Asm, Layout, Fixup, Addrs, true , ForceVarExpansion)) {
623
+ Res, Asm, Layout, Fixup, Addrs, true )) {
624
+ if (!SRE->hasSubsectionsViaSymbols ())
625
+ return true ;
626
+
623
627
const MCSymbolRefExpr *A = Res.getSymA ();
624
628
const MCSymbolRefExpr *B = Res.getSymB ();
625
-
626
- if (SRE->hasSubsectionsViaSymbols ()) {
627
- // FIXME: This is small hack. Given
628
- // a = b + 4
629
- // .long a
630
- // the OS X assembler will completely drop the 4. We should probably
631
- // include it in the relocation or produce an error if that is not
632
- // possible.
633
- if (!A && !B)
634
- return true ;
635
- } else {
636
- if (ForceVarExpansion)
637
- return true ;
638
- bool IsSymbol = A && A->getSymbol ().isDefined ();
639
- if (!IsSymbol)
640
- return true ;
641
- }
629
+ // FIXME: This is small hack. Given
630
+ // a = b + 4
631
+ // .long a
632
+ // the OS X assembler will completely drop the 4. We should probably
633
+ // include it in the relocation or produce an error if that is not
634
+ // possible.
635
+ if (!A && !B)
636
+ return true ;
642
637
}
643
638
}
644
639
@@ -650,9 +645,8 @@ bool MCExpr::EvaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
650
645
const MCUnaryExpr *AUE = cast<MCUnaryExpr>(this );
651
646
MCValue Value;
652
647
653
- if (!AUE->getSubExpr ()->EvaluateAsRelocatableImpl (Value, Asm, Layout,
654
- Fixup, Addrs, InSet,
655
- ForceVarExpansion))
648
+ if (!AUE->getSubExpr ()->EvaluateAsRelocatableImpl (Value, Asm, Layout, Fixup,
649
+ Addrs, InSet))
656
650
return false ;
657
651
658
652
switch (AUE->getOpcode ()) {
@@ -685,12 +679,10 @@ bool MCExpr::EvaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
685
679
const MCBinaryExpr *ABE = cast<MCBinaryExpr>(this );
686
680
MCValue LHSValue, RHSValue;
687
681
688
- if (!ABE->getLHS ()->EvaluateAsRelocatableImpl (LHSValue, Asm, Layout,
689
- Fixup, Addrs, InSet,
690
- ForceVarExpansion) ||
691
- !ABE->getRHS ()->EvaluateAsRelocatableImpl (RHSValue, Asm, Layout,
692
- Fixup, Addrs, InSet,
693
- ForceVarExpansion))
682
+ if (!ABE->getLHS ()->EvaluateAsRelocatableImpl (LHSValue, Asm, Layout, Fixup,
683
+ Addrs, InSet) ||
684
+ !ABE->getRHS ()->EvaluateAsRelocatableImpl (RHSValue, Asm, Layout, Fixup,
685
+ Addrs, InSet))
694
686
return false ;
695
687
696
688
// We only support a few operations on non-constant expressions, handle
0 commit comments