Jump to content
  • Advertisement
Sign in to follow this  
Metron

Hide exported Symbols in .so

This topic is 3656 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I've ported a DLL from Win32 to Linux (.so). Basically, the DLL contains a bunch of classes which are derived from pure virtual interfaces. The DLL only exports 1 function (getFactory) which returns a pointer to one of those pure virtual interfaces. The aren't any other symbols exported. Now, when I take a look at my .so using "nm -D" almost all of my classes are visible. I don't want anyone to see my classes, function, etc. but the one I have exported in my Windows DLL (namely getFactory). Is there any way to hide those symbols? Thanks, Metron

Share this post


Link to post
Share on other sites
Advertisement
Use a configure script to see if the g++ compiler supports the visibility attribute and use macros just as you would do so for windows (import/export).


#ifdef WIN32
# ifdef EXPORT
...
# else
....
# endif
# define DLL_LOCAL
#else
# ifdef __GNU__
# if (GCC_SUPPORTS_VISABLE == 1) /*defined by configure*/
# ifdef EXPORT
# define DLL_API __attribute__ ((visibility("default")))
# else
# define DLL_API __attribute__ ((visibility("default")))
# endif
# define DLL_LOCAL __attribute__ ((visibility("hidden")))
# else
# define DLL_API
# define DLL_LOCAL
# endif
# endif
#endif

Share this post


Link to post
Share on other sites
Quote:
Original post by Metron
Is there any way to hide those symbols?

As with Windows, there are two different ways.

First, there is the GCC visibility attribute as pointed out by dmail. You use it just lke the Windows import/export declspec (it has a different meaning, but the defined symbol goes in the same place so you just need to define a macro in a header file as appropriate). Problem with this method is it only works in GCC 4.2 or later: the attribute was available in 4.1 but cuase dhorrible things to go wrong with standard library symbols.

Second, you can create a version list file and feed it to the linker (like the old Windows .def files). This is not the preferred way, but is the only way if you're using a pre-4.2 toolchain.

Finally, the end effect of using the version list or visibility attribute is that it marks some symbols as local, and others as global. It doesn't remove those symbols. For that, you will want to run the strip -x command. Most packaging systems do this automatically as they package your library.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!