Static linking fails for global mutex variable(c++ class) on embedded system
Hello,
For our projects we developed a multiplatform library which is used to create our applications. We are now porting this to Xenomai. Because we compile for embedded targets, in this case an ARM board, we use static linking as it might occur that dynamic libraries are not available.
In one of our test cases we compile a global class containing a mutex. This class gets initiated before the main function. The test compiles fine in both static and non-static linking, however when running the executable which was staticly linked, the following error occurs:pthread_mutex_init() returns an ENOSYS, indicating it is not implemented.
A gdb backtrace also indicates that this function is not called before the main function -> initiating global variables?
The particular self-test was subtracted from the library and is added as a self-contained use-case in the attachments. In addition the configuration used to for the kernel of the target is included.
The question is, why does the particular function fail when using static linking. Does this have to do with the fact that it is a global class, calling the function? What could be done in order to fix this, due to the targets being embedded systems, using non-static linking is not an option.
Below is a summary of the systems used to run and compile the particular test. -------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: kernel-configuration.txt
URL: <http://www.xenomai.org/pipermail/xenomai/attachments/20131028/e9350a87/attachment.txt>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SingletonTest.tar.bz2
Type: application/x-bzip2
Size: 9907 bytes
Desc: not available
URL: <http://www.xenomai.org/pipermail/xenomai/attachments/20131028/e9350a87/attachment.bin>
-------------- next part --------------
Build system information:
uname -a:
Linux 3.5.0-40-generic #62-Ubuntu SMP (date) x86_64 x86_64 x86_64 GNU/Linux
arm-linux-gnueabi-g++ ?version:
(Ubuntu/Linaro 4.6.3-8ubuntu1) 4.6.3 20120624 (prerelease)
Xenomai:
version: 2.6.3
.configurate settings:
$xenomai_root/configure CFLAGS="-march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp -ftree-vectorize -ftree-vectorizer-verbose=3 -fdump-tree-vect" LDFLAGS="-march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp -ftree-vectorize -ftree-vectorizer-verbose=3 -fdump-tree-vect" --build=x86_64-linux-gnu --host=arm-linux-gnueabi
Target system:
Gumstix Overo Fire (arm-cortex-a8 computer on module) Tobi baseboard and costum base board.
Software:
Linux 3.2.21
Adeos version: ipipe-core-3.2.21-arm-4.patch
Xenomai version 2.6.3
Thanks in advance.
Regards,
Jan Jaap Kempenaar
Quoted 10 lines · Jan Jaap Kempenaar
Hello,
For our projects we developed a multiplatform library which is used to create our applications. We are now porting this to Xenomai. Because we compile for embedded targets, in this case an ARM board, we use static linking as it might occur that dynamic libraries are not available.
In one of our test cases we compile a global class containing a mutex. This class gets initiated before the main function.
Whether this works depends on initialization order: the Xenomai library has to be initialized before you call pthread_mutex_init, and this is probably not true when you link the library statically. The only solution is to defer the call to pthread_mutex_init somehow.
Also note that in order to static link the Xenomai library, you have to use the "wrap-link.sh" script.
Signature · 1 line
Gilles.
How exactly is the xenomai library initialised?
Is this a kind of system function call performed by the application?
Can you check whether or not the xenomai library is initialised at a certain point in the application?
As for the wrap-link.sh, we use that in our static linking.
Regards,
Jan Jaap
Op 28 okt. 2013, om 10:53 heeft Gilles Chanteperdrix <[email protected]> het volgende geschreven:
Quoted 21 lines · Jan Jaap Kempenaar
Quoted 10 lines
Hello,
For our projects we developed a multiplatform library which is used to create our applications. We are now porting this to Xenomai. Because we compile for embedded targets, in this case an ARM board, we use static linking as it might occur that dynamic libraries are not available.
In one of our test cases we compile a global class containing a mutex. This class gets initiated before the main function.
Whether this works depends on initialization order: the Xenomai library has to be initialized before you call
pthread_mutex_init, and this is probably not true when you link the library statically. The only solution is to defer the call topthread_mutex_initsomehow.Also note that in order to static link the Xenomai library, you have to use the "
wrap-link.sh" script.Signature · 1 line
Gilles.
Quoted 1 line · Jan Jaap Kempenaar
How exactly is the xenomai library initialised?
Witch a function having the "constructor" attribute which makes it executed before main, but does not give any guarantee that it will be executed before a C++ static object constructor.
Quoted 1 line
Is this a kind of system function call performed by the application?
Yes.
Quoted 3 lines
Can you check whether or not the xenomai library is initialised at a certain point in the application?
Well, if pthread_mutex_init returns ENOSYS, it means that it is not
initialized. Also, when entering the "main" function, you are sure that the library has been initialized.
Quoted 2 lines
As for the
wrap-link.sh, we use that in our static linking.
Ok.
Signature · 1 line
Gilles.