What am I doing
When writing shared libraries for Linux, I try to pay attention to movement, visibility of characters, GOT / PLT, etc.
When applicable, I try to avoid calling PLT stubs when functions from the same library call each other. For example, suppose a shared object provides two public functions - foo() and bar() (either of which can be called by the user). However, the bar() function also calls foo() . So what I do in this case is the following:
- Define the
_foo() and _bar() functions that have confidential visibility. - Define the weak aliases
foo() and bar() for _foo() and _bar() respectively.
Thus, code in a shared object never uses weak characters. It calls directly local functions. For example, when _bar() is called, it calls _foo() directly.
But users are unaware of the _* functions and always use the corresponding weak aliases.
How i do it
On Linux, this is achieved using the following construct:
extern __typeof (_NAME) NAME __attribute__(weak, alias("_NAME"));
Problem
Unfortunately, this does not work for OS X. I do not have deep knowledge about OS X or its binary formats, so I thought a little and found some examples of weak functions (for example this one ), but this is not quite the same as you can have a weak character, but not a weak character, which is an alias for the local DSO function.
Possible Solution...
At the moment, I have disabled this feature (which is implemented using macros), so that all characters are global and have default visibility. The only way I can come now is to have all _foo functions with private visibility and have the corresponding foo functions with default visibility and call their βhiddenβ copies.
The best way?
This, however, requires a good piece of code that needs to be changed. Therefore, I would prefer not to go there if there is no other way.
So what closes the OS X alternative or the easiest way to get the same semantics / behavior?
c linux linker dynamic-linking macos
user405725 Aug 15 '13 at 19:27 2013-08-15 19:27
source share