[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
Fri Jul 30 23:05:26 PDT 2021
mhjacobson updated this revision to Diff 363267.
mhjacobson added a comment.
Add assembly comment.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D107133/new/
https://reviews.llvm.org/D107133
Files:
llvm/lib/Target/AVR/AVRAsmPrinter.cpp
llvm/test/CodeGen/AVR/ctors.ll
Index: llvm/test/CodeGen/AVR/ctors.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AVR/ctors.ll
@@ -0,0 +1,15 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -march=avr | FileCheck %s
+
+define void @do_nothing() addrspace(1) #0 {
+; CHECK-LABEL: do_nothing:
+; CHECK: ; %bb.0:
+; CHECK-NEXT: ret
+ ret void
+}
+
+; CHECK: .globl __do_global_ctors
+ at llvm.global_ctors = appending global [1 x { i32, void () addrspace(1)*, i8* }] [{ i32, void () addrspace(1)*, i8* } { i32 65535, void () addrspace(1)* @do_nothing, i8* null }]
+
+; CHECK: .globl __do_global_dtors
+ at llvm.global_dtors = appending global [1 x { i32, void () addrspace(1)*, i8* }] [{ i32, void () addrspace(1)*, i8* } { i32 65535, void () addrspace(1)* @do_nothing, i8* null }]
Index: llvm/lib/Target/AVR/AVRAsmPrinter.cpp
===================================================================
--- llvm/lib/Target/AVR/AVRAsmPrinter.cpp
+++ llvm/lib/Target/AVR/AVRAsmPrinter.cpp
@@ -24,6 +24,7 @@
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/IR/Mangler.h"
+#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSymbol.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,25 @@
return AsmPrinter::lowerConstant(CV);
}
+void AVRAsmPrinter::emitXXStructor(const DataLayout &DL, const Constant *CV) {
+ if (!EmittedStructorSymbolAttrs) {
+ OutStreamer->emitRawComment(" Emitting these symbol references causes us "
+ "to link the libgcc code that runs our constructors/destructors.");
+
+ 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.363267.patch
Type: text/x-patch
Size: 2535 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210731/4a136f6c/attachment.bin>
More information about the llvm-commits
mailing list