BOOST_DLL_ALIAS_SECTIONED missing specified BOOST_DLL_SECTION after performing a strip

Viewed 26

I created a shared library using BOOST using the following to specify the factory method:

BOOST_DLL_ALIAS_SECTIONED(
MyPlugin::create, // Plugin's factory method being exported
create_plugin,    // Alias for factory method.

MySectionName)  // The section name that all factory methods are grouped in.

The create() method returns a shared pointer to the MyPlugin object.

I then load the shared library and try to fetch the particular section using:

boost::dll::library_info inf(shared_library_path);

And then locate the above section with:

std::vector<std::string> sections = inf.sections();

if (std::find(sections.begin(), sections.end(), "MySectionName") == sections.end()) {
    // Do something
} else
{
    // Error out
}

If the shared library was not stripped, the above allows me to find MySectionName within its contents and perform actions within the bracket. If I however strip the shared library (default: strip library_name.so), the above library info no longer lists the defined section and I hit the error out condition.

I can protect the particular factory method during strip by specifying "-Kcreate" flag, but while that works with this simple shared library, more complex libraries end up with more missing symbols and it almost feels counterproductive to keep expanding the "-K" flag.

Is here an easier way of using BOOST for plugin creation using the above method and still allow stripping out debug information without having to expand with "-K" flag?

Thank you

1 Answers

I couldn't reproduce this with shorter section names:

  • File test.cpp

     #include <boost/dll.hpp>
     #include <boost/dll/alias.hpp>
    
     namespace MyPlugin {
         struct X{};
         static auto create() {
             return std::make_shared<X>();
         }
     }
    
     BOOST_DLL_ALIAS_SECTIONED(
             MyPlugin::create, 
             Factory, 
             MySect)
    
  • File test1.cpp

     #include <boost/dll.hpp>
     #include <iostream>
    
     int main() {
         boost::dll::library_info inf("libsotest.so");
         std::vector<std::string> s = inf.sections();
    
         auto found = (std::find(s.begin(), s.end(), "MySect") != s.end());
         std::cout << "Found: " << std::boolalpha << found << "\n";
     }
    

Prints:

enter image description here

In fact, I cannot compile it at all when the section name exceeds 9 characters:

test.cpp|11 col 1| error: static assertion failed: Some platforms require section names to be at most 8 bytes
||    11 | BOOST_DLL_ALIAS_SECTIONED(

Perhaps your problem is related to such restrictions?

Related