diff --git a/lib/MC/MCExpr.cpp b/lib/MC/MCExpr.cpp index 3eae6bdf3d3..c0ecad0361a 100644 --- a/lib/MC/MCExpr.cpp +++ b/lib/MC/MCExpr.cpp @@ -20,9 +20,20 @@ void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI) const { OS << cast(*this).getValue(); return; - case MCExpr::SymbolRef: - cast(*this).getSymbol().print(OS, MAI); + case MCExpr::SymbolRef: { + const MCSymbol &Sym = cast(*this).getSymbol(); + + // Parenthesize names that start with $ so that they don't look like + // absolute names. + if (Sym.getName()[0] == '$') { + OS << '('; + Sym.print(OS, MAI); + OS << ')'; + } else { + Sym.print(OS, MAI); + } return; + } case MCExpr::Unary: { const MCUnaryExpr &UE = cast(*this);