File tree Expand file tree Collapse file tree 3 files changed +27
-33
lines changed Expand file tree Collapse file tree 3 files changed +27
-33
lines changed Original file line number Diff line number Diff line change @@ -164,4 +164,28 @@ typedef void *PluginCleanupFuncT();
164164// LinkerPluginConfig
165165typedef LinkerPluginConfig * PluginConfigFuncT (PluginType T);
166166}
167+
168+ // / A helper macro for registering a plugin.
169+ // / It simply provides good defaults for RegisterAll, getPlugin
170+ // / and Cleanup functions.
171+ // / \note It can be only be used once in a source file.
172+ # define ELD_REGISTER_PLUGIN(PluginType) \
173+ PluginType * ThisPlugin = nullptr; \
174+ \
175+ extern " C" { \
176+ bool DLL_A_EXPORT RegisterAll () { \
177+ ThisPlugin = new PluginType (); \
178+ return true ; \
179+ } \
180+ \
181+ eld ::plugin ::PluginBase DLL_A_EXPORT * getPlugin (const char * T) { \
182+ return ThisPlugin; \
183+ } \
184+ \
185+ void DLL_A_EXPORT Cleanup () { \
186+ if (ThisPlugin) \
187+ delete ThisPlugin; \
188+ ThisPlugin = nullptr; \
189+ } \
190+ }
167191# endif
Original file line number Diff line number Diff line change @@ -44,20 +44,4 @@ class DLL_A_EXPORT AddedSectionOverrides
4444};
4545
4646
47- std::unordered_map<std::string, Plugin *> Plugins;
48-
49- extern " C" {
50- bool DLL_A_EXPORT RegisterAll () {
51- Plugins[" AddedSectionOverrides" ] = new AddedSectionOverrides ();
52- return true ;
53- }
54-
55- PluginBase DLL_A_EXPORT *getPlugin (const char *T) { return Plugins[T]; }
56- void DLL_A_EXPORT Cleanup () {
57- for (auto &item : Plugins) {
58- if (item.second )
59- delete item.second ;
60- }
61- Plugins.clear ();
62- }
63- }
47+ ELD_REGISTER_PLUGIN (AddedSectionOverrides)
Original file line number Diff line number Diff line change 33#include " LinkerWrapper.h"
44#include " OutputSectionIteratorPlugin.h"
55#include " PluginADT.h"
6+ #include " PluginBase.h"
67#include " PluginVersion.h"
78#include < cassert>
89
@@ -63,19 +64,4 @@ class DLL_A_EXPORT BasicChunkMover : public eld::plugin::OutputSectionIteratorPl
6364 eld::plugin::OutputSection m_Bar{nullptr };
6465};
6566
66- BasicChunkMover *ThisPlugin = nullptr ;
67-
68- extern " C" {
69- bool DLL_A_EXPORT RegisterAll () {
70- ThisPlugin = new BasicChunkMover ();
71- return true ;
72- }
73-
74- eld::plugin::PluginBase DLL_A_EXPORT *getPlugin (const char *T) { return ThisPlugin; }
75-
76- void DLL_A_EXPORT Cleanup () {
77- if (ThisPlugin)
78- delete ThisPlugin;
79- ThisPlugin = nullptr ;
80- }
81- }
67+ ELD_REGISTER_PLUGIN (BasicChunkMover)
You can’t perform that action at this time.
0 commit comments