Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 405487 - C client library: Exported symbols should be controlled when compiling on Linux
Summary: C client library: Exported symbols should be controlled when compiling on Linux
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Paho (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Ian Craggs CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 405486
Blocks: 405837
  Show dependency tree
 
Reported: 2013-04-11 11:59 EDT by Roger Light CLA
Modified: 2016-02-05 11:16 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Roger Light CLA 2013-04-11 11:59:25 EDT
The C client library currently controls which functions/symbols are exported on Windows using the DLLExport macro. There is no similar control on Linux, but there should be.

The "Version script" page at http://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_node/ld_25.html describes how to control which functions are exported and almost more importantly, how to version functions. I can provide more details if needed, it's quite easy really.

The gcc option to add in the linker script is "-Wl,--version-script=linker.version"
Comment 1 Ian Craggs CLA 2013-04-11 12:15:45 EDT
Agreed.  Up to now I didn't know it was possible, or how to do it.  Thanks
Comment 2 Andy Piper CLA 2013-04-11 19:18:52 EDT
Great call Roger, thank you! let's get this into the Makefile and respective source files. As we move towards a formal release these kinds of details are vital.
Comment 3 Andy Piper CLA 2013-04-15 06:43:51 EDT
Assigning to MQTT-C
Comment 4 Ian Craggs CLA 2013-04-15 08:29:28 EDT
So, as per this document:

https://www.gnu.org/software/gnulib/manual/html_node/Exported-Symbols-of-Shared-Libraries.html

the preferred method is

"The programmer specifies a “hidden” attribute for all files that make up the shared library, and an “exported” attribute for those symbols in these files that shall be exported.

This is perfect: It burdens the maintainer only for exported API, not for library-internal API. And it keeps the annotations in the source code."

implemented by adding -fvisibility=hidden to the compile options, and 

__attribute__ ((visibility ("default")))

to each definition to be exported.  This method is very similar to the Windows method already used, so we already usable tags in the source code.

I propose using this method.  The only downside is that the -fvisibility compile option is not supported in gcc earlier than v4.
Comment 5 Ian Craggs CLA 2013-04-18 11:09:57 EDT
Fixed as I suggested above.
Comment 6 Roger Light CLA 2013-04-18 16:16:43 EDT
Could I suggest the following then:

#if defined(__GNUC__) && __GNUC__ >= 4
#  define DLLExport __attribute__ ((visibility ("default")))
#else
#  define DLLExport
#endif