File tree Expand file tree Collapse file tree 5 files changed +25
-7
lines changed Expand file tree Collapse file tree 5 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -150,6 +150,24 @@ struct PluginManager {
150
150
HostPtrToTableMapTy HostPtrToTableMap;
151
151
std::mutex TblMapMtx; // /< For HostPtrToTableMap
152
152
153
+ // Work around for plugins that call dlopen on shared libraries that call
154
+ // tgt_register_lib during their initialisation. Stash the pointers in a
155
+ // vector until the plugins are all initialised and then register them.
156
+ bool delayRegisterLib (__tgt_bin_desc *Desc) {
157
+ if (RTLsLoaded)
158
+ return false ;
159
+ DelayedBinDesc.push_back (Desc);
160
+ return true ;
161
+ }
162
+
163
+ void registerDelayedLibraries () {
164
+ // Only called by libomptarget constructor
165
+ RTLsLoaded = true ;
166
+ for (auto *Desc : DelayedBinDesc)
167
+ __tgt_register_lib (Desc);
168
+ DelayedBinDesc.clear ();
169
+ }
170
+
153
171
// / Return the number of usable devices.
154
172
int getNumDevices () { return getExclusiveDevicesAccessor ()->size (); }
155
173
@@ -178,6 +196,9 @@ struct PluginManager {
178
196
void addRequirements (int64_t Flags) { Requirements.addRequirements (Flags); }
179
197
180
198
private:
199
+ bool RTLsLoaded = false ;
200
+ llvm::SmallVector<__tgt_bin_desc *> DelayedBinDesc;
201
+
181
202
// List of all plugin adaptors, in use or not.
182
203
llvm::SmallVector<std::unique_ptr<PluginAdaptorTy>> PluginAdaptors;
183
204
Original file line number Diff line number Diff line change @@ -46,6 +46,9 @@ EXTERN void __tgt_register_requires(int64_t Flags) {
46
46
// / adds a target shared library to the target execution image
47
47
EXTERN void __tgt_register_lib (__tgt_bin_desc *Desc) {
48
48
TIMESCOPE ();
49
+ if (PM->delayRegisterLib (Desc))
50
+ return ;
51
+
49
52
PM->registerLib (Desc);
50
53
}
51
54
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ __attribute__((constructor(101))) void init() {
51
51
PM->init ();
52
52
53
53
Profiler::get ();
54
+ PM->registerDelayedLibraries ();
54
55
}
55
56
56
57
__attribute__ ((destructor(101 ))) void deinit() {
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments