Guest User

Problems with C++ constructors and RTEMS

a guest
Sep 16th, 2011
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. Hi,
  2.  
  3. I managed to compile and link all the dependencies libraries together
  4. with RTEMS 4.10.1 and Newlib, producing a final binary of about 32Mb.
  5. I run it with QEMU but a problem in runtime arose:
  6.  
  7. The problem happens inside a c++ constructor, called from
  8. __do_global_ctors_aux (which if I understand it correctly, basically
  9. call all the constructors from the table of pointers to constructor
  10. defined in the .ctors section (i386-rtems-objdump -s -j .ctors
  11. message_producer_test | vim -)).
  12.  
  13. __do_global_ctors_aux is called from RTEMS (_Thread_Handler
  14. ->INIT_NAME -> _init).
  15.  
  16. The constructor is part of omniORB, omni_mutex::omni_mutex
  17. (http://pastebin.com/Pcd50Bni). Inside this constructor, a call to
  18. pthread_mutex_init is produced.
  19.  
  20. From the gdb log (http://pastebin.com/QrRxWxse) I fear that the
  21. problem is allocating resources inside pthread_mutex_init, actually in
  22. objectallocate.c -> chainget.c -> chain.inl.
  23.  
  24. At first, I though the problem was related to RTEMS running out of
  25. memory (and even tried to increase QEMU memory), but after taking a
  26. look to chain.inl, I think that the problem may be the omni_mutex
  27. constructor calling pthread_mutex_init and therefore allocating
  28. resources before RTEMS is completly ready. Although, RTEMS is the one
  29. calling __do_global_ctors_aux.
  30.  
  31. I hope any of you can spread some light. In the meantime, what I have
  32. in mind is modify omniORB and delay the pthread_mutex_init call in
  33. omni_mutex.
  34.  
  35. Kind regards,
  36. Ana
  37.  
  38. P.S. In order to simplify the understanding of the problem, I attach
  39. the code from mutexinit.c (http://pastebin.com/cC6G2UjF), and since
  40. _Thread_Disable_dispatch(), _POSIX_Mutex_Allocate() and
  41. _Thread_Enable_dispatch() are inline functions, I also attached the
  42. unrolled version (http://pastebin.com/MxwXCCj5).
Advertisement
Add Comment
Please, Sign In to add comment