-// This is a hack. To be able to implement weakrefs the writer has to be able
-// to distinguish
-// .weakref foo, bar
-// .long foo
-// from
-// .weakref foo, bar
-// .long bar
-// since the first case should produce a weak undefined reference and the second
-// one a strong one.
-// If we created foo as a regular alias pointing to bar (foo = bar), then
-// MCExpr::EvaluateAsRelocatable would recurse on foo and the writer would
-// never see it used in a relocation.
-// What we do is create a MCTargetExpr that when evaluated produces a symbol
-// ref to a temporary symbol. This temporary symbol in turn is a variable
-// that equals the original symbol (tmp = bar). With this hack the writer
-// gets a relocation with tmp and can correctly implement weak references.
-
-namespace {
-class WeakRefExpr : public MCTargetExpr {
-private:
- const MCSymbolRefExpr *Alias;
-
- explicit WeakRefExpr(const MCSymbolRefExpr *Alias_)
- : MCTargetExpr(), Alias(Alias_) {}
-
-public:
- virtual void PrintImpl(raw_ostream &OS) const {
- llvm_unreachable("Unimplemented");
- }
-
- virtual bool EvaluateAsRelocatableImpl(MCValue &Res,
- const MCAsmLayout *Layout) const {
- Res = MCValue::get(Alias, 0, 0);
- return true;
- }
-
- static const WeakRefExpr *Create(const MCSymbol *Alias, MCContext &Ctx) {
- const MCSymbolRefExpr *A = MCSymbolRefExpr::Create(Alias, Ctx);
- return new (Ctx) WeakRefExpr(A);
- }
-};
-} // end anonymous namespace
-