@@ -49,6 +49,10 @@ Plugin::Plugin(plugin::Plugin::Type T, std::string LibraryName,
4949 ThisModule(Module), ThisConfig(Module.getConfig()),
5050 IsDefaultPlugin(DefaultPlugin) {}
5151
52+ bool Plugin::isTraced () const {
53+ return ThisConfig.options ().tracePlugin (getPluginType ());
54+ }
55+
5256std::string Plugin::resolvePath (const LinkerConfig &PConfig) {
5357 // Library already loaded!
5458 if (PluginLibraryHandle)
@@ -79,13 +83,14 @@ std::string Plugin::resolvePath(const LinkerConfig &PConfig) {
7983
8084 if (nullptr != NS ) {
8185 PluginLibraryName = NS ->getFullPath ();
82- if (ThisModule. getPrinter ()-> tracePlugins ())
86+ if (isTraced ())
8387 ThisConfig.raise (Diag::using_plugin) << PluginLibraryName << Name;
8488 }
8589 return PluginLibraryName;
8690}
8791
88- void *Plugin::loadPlugin (std::string LibraryName, Module *Module) {
92+ void *Plugin::loadPlugin (std::string LibraryName, Module *Module,
93+ bool IsTraced) {
8994 void *LibraryHandle = DynamicLibrary::Load (LibraryName);
9095 DiagnosticEngine *DiagEngine = Module->getConfig ().getDiagEngine ();
9196 if (!LibraryHandle) {
@@ -94,7 +99,7 @@ void *Plugin::loadPlugin(std::string LibraryName, Module *Module) {
9499 return nullptr ;
95100 }
96101
97- if (Module-> getPrinter ()-> tracePlugins () )
102+ if (IsTraced )
98103 DiagEngine->raise (Diag::loaded_library) << LibraryName;
99104
100105 return LibraryHandle;
@@ -151,15 +156,15 @@ bool Plugin::setFunctions() {
151156 return false ;
152157 }
153158
154- if (ThisModule. getPrinter ()-> tracePlugins ()) {
159+ if (isTraced ()) {
155160 ThisConfig.raise (Diag::found_register_function) << Register << LibraryName;
156161 ThisConfig.raise (Diag::found_function_for_plugintype)
157162 << PluginFunc << LibraryName;
158163 }
159164
160165 std::string PluginCleanupFunc = " Cleanup" ;
161166 void *C = DynamicLibrary::GetFunction (PluginLibraryHandle, PluginCleanupFunc);
162- if (C && ThisModule. getPrinter ()-> tracePlugins ()) {
167+ if (C && isTraced ()) {
163168 ThisConfig.raise (Diag::found_cleanup_function)
164169 << PluginCleanupFunc << LibraryName;
165170 }
@@ -182,7 +187,7 @@ bool Plugin::setFunctions() {
182187bool Plugin::getUserPlugin () {
183188 std::string LibraryName = DynamicLibrary::getLibraryName (Name);
184189
185- if (ThisModule. getPrinter ()-> tracePlugins ())
190+ if (isTraced ())
186191 ThisConfig.raise (Diag::registering_all_functions);
187192
188193 UserPluginHandle = (*GetPluginFunction)(getPluginType ().c_str ());
@@ -192,7 +197,7 @@ bool Plugin::getUserPlugin() {
192197 return false ;
193198 }
194199
195- if (ThisModule. getPrinter ()-> tracePlugins ())
200+ if (isTraced ())
196201 ThisConfig.raise (Diag::found_plugin_handler)
197202 << getPluginType () << LibraryName;
198203
@@ -211,7 +216,7 @@ bool Plugin::init(eld::OutputTarWriter *OutputTar) {
211216 return false ;
212217 eld::RegisterTimer T (
213218 " Init" , ThisModule.saveString (UserPluginHandle->GetName ()), Stats);
214- if (ThisModule. getPrinter ()-> tracePlugins ())
219+ if (isTraced ())
215220 ThisConfig.raise (Diag::note_initializing_plugin)
216221 << getPluginType () << DynamicLibrary::getLibraryName (Name)
217222 << UserPluginHandle->GetName ();
@@ -235,14 +240,14 @@ bool Plugin::run(std::vector<Plugin *> &Plugins) {
235240 return false ;
236241 eld::RegisterTimer T (
237242 " Run" , ThisModule.saveString (UserPluginHandle->GetName ()), Stats);
238- if (ThisModule. getPrinter ()-> tracePlugins ())
243+ if (isTraced ())
239244 ThisConfig.raise (Diag::running_plugin)
240245 << getPluginType () << DynamicLibrary::getLibraryName (Name)
241246 << UserPluginHandle->GetName ();
242247 Plugins.push_back (this );
243248 Running R (this );
244249 plugin::Plugin *P = llvm::cast<plugin::Plugin>(UserPluginHandle);
245- plugin::Plugin::Status S = P->Run (ThisModule. getPrinter ()-> tracePlugins ());
250+ plugin::Plugin::Status S = P->Run (isTraced ());
246251 if (S == plugin::Plugin::Status::ERROR || P->GetLastError ()) {
247252 ThisConfig.raise (Diag::plugin_has_error)
248253 << getPluginType () << DynamicLibrary::getLibraryName (Name)
@@ -266,11 +271,12 @@ bool Plugin::cleanup() {
266271 return true ;
267272}
268273
269- bool Plugin::unload (std::string LibraryName, void *Handle, Module *Module) {
274+ bool Plugin::unload (std::string LibraryName, void *Handle, Module *Module,
275+ bool IsTraced) {
270276 if (Handle) {
271277 DynamicLibrary::Unload (Handle);
272278
273- if (Module-> getPrinter ()-> tracePlugins () )
279+ if (IsTraced )
274280 Module->getConfig ().raise (Diag::unloaded_library) << LibraryName;
275281 }
276282
@@ -290,7 +296,7 @@ bool Plugin::destroy() {
290296 return false ;
291297 eld::RegisterTimer T (
292298 " Destroy" , ThisModule.saveString (UserPluginHandle->GetName ()), Stats);
293- if (ThisModule. getPrinter ()-> tracePlugins ())
299+ if (isTraced ())
294300 ThisConfig.raise (Diag::plugin_destroy) << getPluginType ();
295301 plugin::Plugin *P = llvm::cast<plugin::Plugin>(UserPluginHandle);
296302 P->Destroy ();
@@ -332,7 +338,7 @@ bool Plugin::check() {
332338 return false ;
333339 }
334340
335- if (ThisModule. getPrinter ()-> tracePlugins ())
341+ if (isTraced ())
336342 ThisConfig.raise (Diag::note_plugin_version)
337343 << PluginMajor << PluginMinor << DynamicLibrary::getLibraryName (Name)
338344 << getPluginType ();
@@ -522,7 +528,7 @@ void Plugin::callInitHook() {
522528 plugin::LinkerPlugin *P = llvm::cast<plugin::LinkerPlugin>(UserPluginHandle);
523529 RegisterTimer T (" Init" , ThisModule.saveString (UserPluginHandle->GetName ()),
524530 Stats);
525- if (ThisModule. getPrinter ()-> tracePlugins ())
531+ if (isTraced ())
526532 ThisConfig.raise (Diag::trace_plugin_init) << getPluginName ();
527533 P->Init (PluginOptions);
528534}
@@ -531,15 +537,15 @@ void Plugin::callDestroyHook() {
531537 plugin::LinkerPlugin *P = llvm::cast<plugin::LinkerPlugin>(UserPluginHandle);
532538 RegisterTimer T (" Destroy" , ThisModule.saveString (UserPluginHandle->GetName ()),
533539 Stats);
534- if (ThisModule. getPrinter ()-> tracePlugins ())
540+ if (isTraced ())
535541 ThisConfig.raise (Diag::trace_plugin_destroy) << getPluginName ();
536542 P->Destroy ();
537543}
538544
539545void Plugin::registerCommandLineOption (
540546 const std::string &Option, bool HasValue,
541547 const CommandLineOptionSpec::OptionHandlerType &OptionHandler) {
542- if (ThisModule. getPrinter ()-> tracePlugins ()) {
548+ if (isTraced ()) {
543549 if (HasValue)
544550 ThisConfig.raise (Diag::trace_plugin_register_opt_with_val)
545551 << getPluginName () << Option;
@@ -568,7 +574,7 @@ void Plugin::callVisitSectionsHook(InputFile &IF) {
568574 plugin::LinkerPlugin *P = llvm::cast<plugin::LinkerPlugin>(UserPluginHandle);
569575 RegisterTimer T (" VisitSections" ,
570576 ThisModule.saveString (UserPluginHandle->GetName ()), Stats);
571- if (ThisModule. getPrinter ()-> tracePlugins ())
577+ if (isTraced ())
572578 ThisConfig.raise (Diag::trace_plugin_visit_sections)
573579 << getPluginName () << IF .getInput ()->decoratedPath ();
574580 P->VisitSections (plugin::InputFile (&IF ));
@@ -579,7 +585,7 @@ void Plugin::callVisitSymbolHook(LDSymbol *Sym, llvm::StringRef SymName,
579585 plugin::LinkerPlugin *P = llvm::cast<plugin::LinkerPlugin>(UserPluginHandle);
580586 RegisterTimer T (" VisitSymbol" ,
581587 ThisModule.saveString (UserPluginHandle->GetName ()), Stats);
582- if (ThisModule. getPrinter ()-> tracePlugins ())
588+ if (isTraced ())
583589 ThisConfig.raise (Diag::trace_plugin_visit_symbol)
584590 << getPluginName () << SymName;
585591 std::unique_ptr<SymbolInfo> UpSymInfo = std::make_unique<SymbolInfo>(SymInfo);
@@ -593,7 +599,7 @@ void Plugin::callActBeforeRuleMatchingHook() {
593599 plugin::LinkerPlugin *P = llvm::cast<plugin::LinkerPlugin>(UserPluginHandle);
594600 RegisterTimer T (HookName, ThisModule.saveString (UserPluginHandle->GetName ()),
595601 Stats);
596- if (ThisModule. getPrinter ()-> tracePlugins ())
602+ if (isTraced ())
597603 ThisConfig.raise (Diag::trace_plugin_hook) << getPluginName () << HookName;
598604 P->ActBeforeRuleMatching ();
599605}
@@ -603,7 +609,7 @@ void Plugin::callActBeforeSectionMergingHook() {
603609 plugin::LinkerPlugin *P = llvm::cast<plugin::LinkerPlugin>(UserPluginHandle);
604610 RegisterTimer T (HookName, ThisModule.saveString (UserPluginHandle->GetName ()),
605611 Stats);
606- if (ThisModule. getPrinter ()-> tracePlugins ())
612+ if (isTraced ())
607613 ThisConfig.raise (Diag::trace_plugin_hook) << getPluginName () << HookName;
608614 P->ActBeforeSectionMerging ();
609615}
@@ -613,7 +619,7 @@ void Plugin::callActBeforePerformingLayoutHook() {
613619 plugin::LinkerPlugin *P = llvm::cast<plugin::LinkerPlugin>(UserPluginHandle);
614620 RegisterTimer T (HookName, ThisModule.saveString (UserPluginHandle->GetName ()),
615621 Stats);
616- if (ThisModule. getPrinter ()-> tracePlugins ())
622+ if (isTraced ())
617623 ThisConfig.raise (Diag::trace_plugin_hook) << getPluginName () << HookName;
618624 P->ActBeforePerformingLayout ();
619625}
@@ -623,7 +629,7 @@ void Plugin::callActBeforeWritingOutputHook() {
623629 plugin::LinkerPlugin *P = llvm::cast<plugin::LinkerPlugin>(UserPluginHandle);
624630 RegisterTimer T (HookName, ThisModule.saveString (UserPluginHandle->GetName ()),
625631 Stats);
626- if (ThisModule. getPrinter ()-> tracePlugins ())
632+ if (isTraced ())
627633 ThisConfig.raise (Diag::trace_plugin_hook) << getPluginName () << HookName;
628634 P->ActBeforeWritingOutput ();
629635}
0 commit comments