-static const MCSymbol *getBaseSymbol(const MCAsmLayout &Layout,
- const MCSymbol &Symbol) {
- if (!Symbol.isVariable())
- return &Symbol;
-
- const MCExpr *Expr = Symbol.getVariableValue();
- MCValue Value;
- if (!Expr->EvaluateAsValue(Value, &Layout))
- llvm_unreachable("Invalid Expression");
-
- const MCSymbolRefExpr *RefB = Value.getSymB();
- if (RefB)
- Layout.getAssembler().getContext().FatalError(
- SMLoc(), Twine("symbol '") + RefB->getSymbol().getName() +
- "' could not be evaluated in a subtraction expression");
-
- const MCSymbolRefExpr *A = Value.getSymA();
- if (!A)
- return nullptr;
-
- return &A->getSymbol();
-}
-