Xojo Conferences
MBSOct2019CologneDE

dylibs, function loading and getting the wrong one called (Real Studio Plugins Mailinglist archive)

Back to the thread list
Previous thread: plugin from fortran
Next thread: custom HIView in plugin


macosx and unix paths   -   GOLD
  dylibs, function loading and getting the wrong one called   -   Norman Palardy
   Re: dylibs, function loading and getting the wrong one called   -   Alfred Van Hoek
   Re: dylibs, function loading and getting the wrong one called   -   Alfred Van Hoek
   Re: dylibs, function loading and getting the wrong one called   -   Jonathan Johnson
   Re: dylibs, function loading and getting the wrong one called   -   Alfred Van Hoek
   Re: dylibs, function loading and getting the wrong one called   -   Jonathan Johnson
   Re: dylibs, function loading and getting the wrong one called   -   Norman Palardy
   Re: dylibs, function loading and getting the wrong one called   -   Jonathan Johnson
   Re: dylibs, function loading and getting the wrong one called   -   Norman Palardy
   Re: dylibs, function loading and getting the wrong one called   -   Norman Palardy
   Re: dylibs, function loading and getting the wrong one called   -   Norman Palardy
    VST plugins   -   D P

dylibs, function loading and getting the wrong one called
Date: 25.10.06 06:23 (Tue, 24 Oct 2006 23:23:39 -0600)
From: Norman Palardy
I was trying to figure out what the heck was happening with a couple
dylibs I'd been using that are not wrapped into plugins
Sometimes the wrong function seemed to get called.

Here's the simplified set up

I have a very simple dylib that has the compiled result of

long testFunction(long value)
return value + 500 ;
Call this libraryA

And in another I have

long testFunction(long value)
return value ;

Call this libraryB

Then in REALbasic I have a single method that has a deliberate use of
the Alias to enable access to the two libraries in one method as follows

soft declare function testFunction lib "libraryA.dylib" (v as
integer) as integer
soft declare function testFunction2 lib "libraryB.dylib" alias
"testFunction" (v as integer) as integer

dim i as integer
dim j as integer
dim k as integer

i = 123

j = testFunction(i)
k = testFunction2(i)

to my surprise despite trying to call different functions in two
different libraries both j and k get the same result from calling the
same function.

OK ... so I put calls to each function in their own method (still in
the same class) and see if that helps
Nope.

OK ... so take the two calls and put them in separate modules.
No luck.

After reading how dlopen and such work is this even possible using
those functions ?
And, since plugins contain dylibs how is this avoided if two plugins
have the same signature for a function ?

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: dylibs, function loading and getting the wrong one called
Date: 09.12.06 16:35 (Sat, 9 Dec 2006 10:35:48 -0500)
From: Alfred Van Hoek

On Oct 25, 2006, at 11:32 AM, Jonathan Johnson wrote:

> Well, here's the issue. It turns out this is the problem. We use
> NSAddImage and NSLookupSymbolInImage because dyld isn't available
> in anything prior to 10.3. NSAddImage has no notion of adding an
> image to a private namespace, even if two level namespaces are
> used. So, whichever library loads the symbol first will be used for
> the rest of the run.
>
> We can use dyld on 10.3 and higher though, so if possible, please
> file a report against this. One workaround might be to package the
> dylib into a bundle and declare against the bundle. This should work.

Does this still holds? I mean it is an issue that I have. If
REALbasic is adding an image to a private namespace, our code will
fail to add it's own image, and when we call a symbol, it is the
symbol owned by the rbframework that will crash our app. (Using the
current RB version in 10.4.8).

Given your workaround suggestion, is there a shell command or such
that can put the dylib in a bundle, or do we need to use Xcode for that?

Alfred
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: dylibs, function loading and getting the wrong one called
Date: 10.12.06 17:52 (Sun, 10 Dec 2006 11:52:23 -0500)
From: Alfred Van Hoek

On Dec 9, 2006, at 10:35 AM, Alfred Van Hoek wrote:

>
>> Well, here's the issue. It turns out this is the problem. We use
>> NSAddImage and NSLookupSymbolInImage because dyld isn't available
>> in anything prior to 10.3. NSAddImage has no notion of adding an
>> image to a private namespace, even if two level namespaces are
>> used. So, whichever library loads the symbol first will be used
>> for the rest of the run.
>>
>> We can use dyld on 10.3 and higher though, so if possible, please
>> file a report against this. One workaround might be to package the
>> dylib into a bundle and declare against the bundle. This should work.
>
> Does this still holds? I mean it is an issue that I have. If
> REALbasic is adding an image to a private namespace, our code will
> fail to add it's own image, and when we call a symbol, it is the
> symbol owned by the rbframework that will crash our app. (Using the
> current RB version in 10.4.8).
>
> Given your workaround suggestion, is there a shell command or such
> that can put the dylib in a bundle, or do we need to use Xcode for
> that?

Even if we wrap our dylib into a bundle, providing an Info.plist, it
does not matter, declaring leads to the same problem: there is no
private namespace. Another idea, short of filing a report against it?

Alfred
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: dylibs, function loading and getting the wrong one called
Date: 10.12.06 22:08 (Sun, 10 Dec 2006 15:08:13 -0600)
From: Jonathan Johnson

On Dec 9, 2006, at 9:35 AM, Alfred Van Hoek wrote:

>
> On Oct 25, 2006, at 11:32 AM, Jonathan Johnson wrote:
>
>> Well, here's the issue. It turns out this is the problem. We use
>> NSAddImage and NSLookupSymbolInImage because dyld isn't available
>> in anything prior to 10.3. NSAddImage has no notion of adding an
>> image to a private namespace, even if two level namespaces are
>> used. So, whichever library loads the symbol first will be used
>> for the rest of the run.
>>
>> We can use dyld on 10.3 and higher though, so if possible, please
>> file a report against this. One workaround might be to package the
>> dylib into a bundle and declare against the bundle. This should work.
>
> Does this still holds? I mean it is an issue that I have. If
> REALbasic is adding an image to a private namespace, our code will
> fail to add it's own image, and when we call a symbol, it is the
> symbol owned by the rbframework that will crash our app. (Using the
> current RB version in 10.4.8).

Yes and no. For soft declares, it still does matter. For plugins, you
can build your plugin as a Bundle instead of a Dylib (not an actual
folder bundle, just a Mach-O bundle). As of 2006r4 we support these
library types, and back to 10.1 they have a private namespace.

HTH,
Jon

Re: dylibs, function loading and getting the wrong one called
Date: 11.12.06 01:11 (Sun, 10 Dec 2006 19:11:06 -0500)
From: Alfred Van Hoek

On Dec 10, 2006, at 4:08 PM, Jonathan Johnson wrote:

> Yes and no. For soft declares, it still does matter. For plugins,
> you can build your plugin as a Bundle instead of a Dylib (not an
> actual folder bundle, just a Mach-O bundle). As of 2006r4 we
> support these library types, and back to 10.1 they have a private
> namespace.

thanks, this works as it should,

Alfred
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: dylibs, function loading and getting the wrong one called
Date: 25.10.06 11:56 (Wed, 25 Oct 2006 05:56:39 -0500)
From: Jonathan Johnson

On Oct 25, 2006, at 12:23 AM, Norman Palardy wrote:
> OK ... so I put calls to each function in their own method (still in
> the same class) and see if that helps
> Nope.
>
> OK ... so take the two calls and put them in separate modules.
> No luck.
>
> After reading how dlopen and such work is this even possible using
> those functions ?
> And, since plugins contain dylibs how is this avoided if two plugins
> have the same signature for a function ?

Depending on how you created your dylibs, you may not have two-level
namespaces enabled. This would be the first thing to look at.

The second thing I can't really think would apply here, so if you do
already have two-level namespaces enabled, let me know.

HTH,
Jon
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: dylibs, function loading and getting the wrong one called
Date: 25.10.06 15:58 (Wed, 25 Oct 2006 08:58:05 -0600)
From: Norman Palardy

On Oct 25, 2006, at 4:56 AM, Jonathan Johnson wrote:

>
> On Oct 25, 2006, at 12:23 AM, Norman Palardy wrote:
>> OK ... so I put calls to each function in their own method (still
>> in the same class) and see if that helps
>> Nope.
>>
>> OK ... so take the two calls and put them in separate modules.
>> No luck.
>>
>> After reading how dlopen and such work is this even possible using
>> those functions ?
>> And, since plugins contain dylibs how is this avoided if two
>> plugins have the same signature for a function ?
>
> Depending on how you created your dylibs, you may not have two-
> level namespaces enabled. This would be the first thing to look at.

Where in XCode is that setting ?
I can't seem to find it.
I did find lots of message between you and Chris Espinosa about this
but darned if I could find the setting :)

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: dylibs, function loading and getting the wrong one called
Date: 25.10.06 16:32 (Wed, 25 Oct 2006 10:32:42 -0500)
From: Jonathan Johnson

On Oct 25, 2006, at 9:58 AM, Norman Palardy wrote:

>
> On Oct 25, 2006, at 4:56 AM, Jonathan Johnson wrote:
>
>>
>> On Oct 25, 2006, at 12:23 AM, Norman Palardy wrote:
>>> OK ... so I put calls to each function in their own method (still
>>> in the same class) and see if that helps
>>> Nope.
>>>
>>> OK ... so take the two calls and put them in separate modules.
>>> No luck.
>>>
>>> After reading how dlopen and such work is this even possible
>>> using those functions ?
>>> And, since plugins contain dylibs how is this avoided if two
>>> plugins have the same signature for a function ?
>>
>> Depending on how you created your dylibs, you may not have two-
>> level namespaces enabled. This would be the first thing to look at.
>
> Where in XCode is that setting ?
> I can't seem to find it.

In Xcode 2.4... actually, nevermind. It appears that it's no longer
obvious how to turn this feature off, so you probably have it on
(which it is by default).

> I did find lots of message between you and Chris Espinosa about
> this but darned if I could find the setting :)

Well, here's the issue. It turns out this is the problem. We use
NSAddImage and NSLookupSymbolInImage because dyld isn't available in
anything prior to 10.3. NSAddImage has no notion of adding an image
to a private namespace, even if two level namespaces are used. So,
whichever library loads the symbol first will be used for the rest of
the run.

We can use dyld on 10.3 and higher though, so if possible, please
file a report against this. One workaround might be to package the
dylib into a bundle and declare against the bundle. This should work.

HTH,
Jon

Re: dylibs, function loading and getting the wrong one called
Date: 25.10.06 17:14 (Wed, 25 Oct 2006 10:14:42 -0600)
From: Norman Palardy

On Oct 25, 2006, at 8:58 AM, Norman Palardy wrote:

>
> On Oct 25, 2006, at 4:56 AM, Jonathan Johnson wrote:
>
>>
>> On Oct 25, 2006, at 12:23 AM, Norman Palardy wrote:
>>> OK ... so I put calls to each function in their own method (still
>>> in the same class) and see if that helps
>>> Nope.
>>>
>>> OK ... so take the two calls and put them in separate modules.
>>> No luck.
>>>
>>> After reading how dlopen and such work is this even possible
>>> using those functions ?
>>> And, since plugins contain dylibs how is this avoided if two
>>> plugins have the same signature for a function ?
>>
>> Depending on how you created your dylibs, you may not have two-
>> level namespaces enabled. This would be the first thing to look at.
>
> Where in XCode is that setting ?
> I can't seem to find it.
> I did find lots of message between you and Chris Espinosa about
> this but darned if I could find the setting :)

I've added -twolevel_namespace to my setting for other linker flags
in the linker section of build settings (despite it supposedly being
the default)
This is XCode 2.3

While this sounds like the right ay to resolve this it makes no
difference to the results I get :(
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: dylibs, function loading and getting the wrong one called
Date: 25.10.06 17:28 (Wed, 25 Oct 2006 10:28:55 -0600)
From: Norman Palardy

On Oct 25, 2006, at 10:14 AM, Norman Palardy wrote:

>
> I've added -twolevel_namespace to my setting for other linker flags
> in the linker section of build settings (despite it supposedly
> being the default)
> This is XCode 2.3
>
> While this sounds like the right ay to resolve this it makes no
> difference to the results I get :(

More mucking about and I have this working so I can have multiple
libraries with the same entry points and call each one independantly

I had to add the -towlevel_namespace AND also make sure the product
name was part of the build and NOT just rename the library as I had
been doing :)

It has to be built with the right name

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: dylibs, function loading and getting the wrong one called
Date: 25.10.06 17:46 (Wed, 25 Oct 2006 10:46:10 -0600)
From: Norman Palardy

On Oct 25, 2006, at 9:32 AM, Jonathan Johnson wrote:

>
> In Xcode 2.4... actually, nevermind. It appears that it's no longer
> obvious how to turn this feature off, so you probably have it on
> (which it is by default).
I'm only using 2.3
Guess I should update :)

It looks like the man page for ld says
-flat_namespace or -force_flat_namespace
in the Other Linker Flags will force a flat name space

>> I did find lots of message between you and Chris Espinosa about
>> this but darned if I could find the setting :)
>
> Well, here's the issue. It turns out this is the problem. We use
> NSAddImage and NSLookupSymbolInImage because dyld isn't available
> in anything prior to 10.3. NSAddImage has no notion of adding an
> image to a private namespace, even if two level namespaces are
> used. So, whichever library loads the symbol first will be used for
> the rest of the run.
> We can use dyld on 10.3 and higher though, so if possible, please
> file a report against this. One workaround might be to package the
> dylib into a bundle and declare against the bundle. This should work.

Not sure exactly what the wording of such a bug report might be though ?

"Can't properly call functions loaded from different dylibs on OS X <
10.3 " or something like that ?

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>