@@ -39,8 +39,8 @@ class LLVMSymbolLinkerInterface
39
39
if (auto found = append.find (" llvm.global_ctors" ); found != append.end ())
40
40
toLink = append.find (" llvm.global_ctors" )->second ;
41
41
} else if constexpr (std::is_same<LLVM::GlobalDtorsOp, structor_t >()) {
42
- if (auto found = append.find (" llvm.global_ctors " ); found != append.end ())
43
- toLink = append.find (" llvm.global_ctors " )->second ;
42
+ if (auto found = append.find (" llvm.global_dtors " ); found != append.end ())
43
+ toLink = append.find (" llvm.global_dtors " )->second ;
44
44
}
45
45
46
46
std::vector<Attribute> newStructorList;
@@ -82,12 +82,19 @@ class LLVMSymbolLinkerInterface
82
82
}
83
83
}
84
84
85
- auto cloned = state.clone (toLink. back () );
85
+ auto ctx = state.getDestinationOp ()-> getContext ( );
86
86
auto newStructorsAttr =
87
- mlir::ArrayAttr::get (cloned-> getContext () , newStructorList);
87
+ mlir::ArrayAttr::get (ctx , newStructorList);
88
88
auto newPrioritiesAttr =
89
- mlir::ArrayAttr::get (cloned->getContext (), newPriorities);
90
- auto newDataAttr = mlir::ArrayAttr::get (cloned->getContext (), newData);
89
+ mlir::ArrayAttr::get (ctx, newPriorities);
90
+ auto newDataAttr = mlir::ArrayAttr::get (ctx, newData);
91
+
92
+ Operation *cloned;
93
+ if (toLink.empty ()) {
94
+ cloned = state.create <structor_t >(UnknownLoc::get (ctx), newStructorsAttr, newPrioritiesAttr, newDataAttr);
95
+ } else {
96
+ cloned = state.clone (toLink.back ());
97
+ }
91
98
92
99
if constexpr (std::is_same<LLVM::GlobalCtorsOp, structor_t >()) {
93
100
auto ctor = cast<LLVM::GlobalCtorsOp>(cloned);
0 commit comments