Bug 2428 - strip -s failing when linker behavior is not "Don't Link" and I use P/Invoke to call C functions
Summary: strip -s failing when linker behavior is not "Don't Link" and I use P/Invoke ...
Status: RESOLVED INVALID
Alias: None
Product: iOS
Classification: Xamarin
Component: Tools ()
Version: 5.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-12-08 15:30 UTC by Adam Kemp
Modified: 2011-12-08 18:48 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description Adam Kemp 2011-12-08 15:30:53 UTC
I have an assembly which is generated using btouch. It contains both ObjectiveC bindings as well as P/Invoke wrappers for some C functions. I then reference the resulting assembly in my main app. If I build for the simulator it works fine, but if I build for the simulator it produces this error:

/Developer/usr/bin/strip: symbols names listed in: /var/folders/9n/30_lyqjj28z3k7ds6_j8z0km0000gn/T/tmp1441f10a.tmp/symbol-file not in: /Users/akemp/Projects/nextgen/R2/Tablets/Dev/Tablets/DataDashboard/bin/iPhone/Release/DataDashboard.app/DataDashboard
_VariableManager_Init
_VariableManager_Subscribe
_VariableManager_Uninit
_VariableManager_Unsubscribe

Those are the C functions which I wrap with P/Invoke. The difference between the simulator and device builds are the linker behavior settings, which are set to "Don't Link" on the simulator and "SDK only" on the device. If I switch to "Don't Link"for the device it works. I would rather not do that unless I have to, though.

It seems that the linker is having trouble knowing that those particular symbols are called dynamically. Is there a way I can make it recognize C symbols which are called dynamically? Ideally it should recognize the [DllImport] attribute and mark those symbols as reachable.

FYI, I am using -force_load for the static library, so I believe that the native linker is behaving properly, but if there is something else I need to do let me know.
Comment 1 Sebastien Pouliot 2011-12-08 15:50:55 UTC
> but if I build for the simulator it produces this error:

but if I build for the *device* it produces this error:
^ right ?

There are two linkers
1. the managed one: which you can control with "Don't link", "Link SDK assemblies only" and "Link all" options
2. the unmanaged (native) one

For the managed linker if there is no (managed) code calls into _VariableManager_[Init|Subscribe|Uninit|Unsubscribe] then the (managed) linker will eliminate them (remove the [DllImport] from the assemblies). In turn it means the symbols won't be "protected" from being stripped out later.

I'm not totally sure what you mean by "called dynamically" but this might confuse the (managed) linker - a bit like reflection can do. In such case you need to add the [Preserve] attribute on each definition. That will instruct the linker to preserve the methods even if it cannot find the code that requires them.

Once the [Preserve] attribute are present you can re-enable the default (for devices) "Link SDK assemblies only".

Please let me know if this solves your issue (or just close the bug if it's ok :-)
Comment 2 Adam Kemp 2011-12-08 18:18:37 UTC
It turns out that this was just some misleading errors. I found the right combination of changes to make this work, and it has nothing to do with the Linker Behavior settings.

I changed two things:
1. Use armv7 as the architecture in the app's build. My static lib uses armv7, but the app was using armv6, and so it was ignoring the static lib. Oddly, it didn't tell me it was ignoring it until I tried (out of desperation) adding "-u _VariableManager_Init" to the build line. Then it spit out some warnings that it was ignoring things. Now I get to figure out how to make this work in a debug build (that's another issue).
2. Add a bunch of frameworks that were needed by the static lib.

I could create a bug report for the fact that the linker warnings about ignored static libs were being filtered out unless there were linker errors if you want me to, but I will close this particular "bug" because it's not really a bug.
Comment 3 Sebastien Pouliot 2011-12-08 18:48:45 UTC
Thanks for the info. Please fill a bug report about the linking not warning you about the lack of a matching architecture in the static library. That's definitively not something easy to find!