Issue with global variables in dylib when compiled with the cross-compiler #38
+655
−640
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I tried to make an implementation fo the 2dtable which does not rely on having unique global variables. Since the implementation already uses malloc it does not seem to be a too big deal to use it for the global data table pointer array.
The issue is that which linux, windows, and mac (when compiled with clang on a mac) all seem to be able to load the global variables into an isolated space per loaded library. This is not the case for dylibs compiled with the cross-compiler. No matter what attributes or C tricks I try it always loads the library such that all globals are shared resulting in a runtime crash.
We discovered this for the linefollower after a slide change which meant that multiple FMUs had a 2dtable inside.
I tried to merge the changes into the template here. It would be good if we could change to implementation to avoid the issue. I simply have no idea on how to fix it otherwise.
The implementation relies on the fact that COE always unloads the FMUs in order. (it does not step at the same time that it calls terminate on different FMUs)