controllab / fmi-export-20sim

FMI export code generation template for 20-sim
GNU General Public License v3.0
3 stars 4 forks source link

Issue with global variables in dylib when compiled with the cross-compiler #38

Open lausdahl opened 7 years ago

lausdahl commented 7 years ago

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)