diff --git a/llvm/lib/Target/AVR/AVRAsmPrinter.cpp b/llvm/lib/Target/AVR/AVRAsmPrinter.cpp --- a/llvm/lib/Target/AVR/AVRAsmPrinter.cpp +++ b/llvm/lib/Target/AVR/AVRAsmPrinter.cpp @@ -25,6 +25,7 @@ #include "llvm/CodeGen/TargetSubtargetInfo.h" #include "llvm/IR/Mangler.h" #include "llvm/MC/MCInst.h" +#include "llvm/MC/MCContext.h" #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSymbol.h" #include "llvm/Support/ErrorHandling.h" @@ -56,8 +57,11 @@ const MCExpr *lowerConstant(const Constant *CV) override; + void emitXXStructor(const DataLayout &DL, const Constant *CV) override; + private: const MCRegisterInfo &MRI; + bool EmittedStructorSymbolAttrs = false; }; void AVRAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo, @@ -193,6 +197,22 @@ return AsmPrinter::lowerConstant(CV); } +void AVRAsmPrinter::emitXXStructor(const DataLayout &DL, const Constant *CV) { + if (!EmittedStructorSymbolAttrs) { + MCSymbol *CtorsSym = OutContext.getOrCreateSymbol("__do_global_ctors"); + CtorsSym->setExternal(true); + OutStreamer->emitSymbolAttribute(CtorsSym, MCSA_Global); + + MCSymbol *DtorsSym = OutContext.getOrCreateSymbol("__do_global_dtors"); + DtorsSym->setExternal(true); + OutStreamer->emitSymbolAttribute(DtorsSym, MCSA_Global); + + EmittedStructorSymbolAttrs = true; + } + + AsmPrinter::emitXXStructor(DL, CV); +} + } // end of namespace llvm extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAVRAsmPrinter() {