[PATCH] D107133: [AVR] emit `MCSA_Global` references to `__do_global_ctors` and `__do_global_dtors`
Matt Jacobson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 29 23:50:33 PDT 2021
mhjacobson created this revision.
mhjacobson added reviewers: benshi001, dylanmckay.
Herald added subscribers: Jim, hiraditya.
mhjacobson requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Emit references to `__do_global_ctors` and `__do_global_dtors` to allow constructor/destructor routines to run.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D107133
Files:
llvm/lib/Target/AVR/AVRAsmPrinter.cpp
Index: llvm/lib/Target/AVR/AVRAsmPrinter.cpp
===================================================================
--- llvm/lib/Target/AVR/AVRAsmPrinter.cpp
+++ 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() {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107133.362975.patch
Type: text/x-patch
Size: 1512 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210730/f1e4cff7/attachment.bin>
More information about the llvm-commits
mailing list