This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Is it possible to use a linker script to preserve unreferenced static C++ class instances defined in a static library?

On Sat, May 18, 2013 at 1:19 AM, Richard Sandiford
<> wrote:
> Is the initialisation trick you mention something along the lines of:
>   struct S { S() { ...magic initialisation...; } }
>   static S dummyS;
> ?

Probably off topic, but:
Another pattern that bit me recently was

static Mappish <PLUGIN_MAP_TYPE> *_all_plugins;

PluginBase::PluginBase() {
   _all_plugins -> Put (this);

PluginBase::LookUpPlugin(const char *document) {
  ... find plugin that can handle document in _all_plugins ...

Real plugin objects inherit from PluginBase and live in various shared
libraries referenced solely by -lFooPlugin -lBarPlugin in the shared
library that holds PluginBase.
The app then just links -lPluginBase and calls LookUpPlugin to
find those scattered plugins.  This worked until binutils-2.22
and the guys who used the clever trick had to add explicit references
in the source, grumbling at the darn OS for breaking their trick.

I'm starting to hate all static object tricks as much as I hate singletons...
- Dan

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]