-1

We try to port our virtual machine on Net Bsd 7.0 (amd64). Already ported from Linux to Free BSD and Open BSD, among others, with success. We have several issues on a fresh and standard install of Net BSD.

  1. Code is compiled with gcc and the following flags : CC_OPTIONS=-pedantic -Wall -Wno-trigraphs -Wno-long-long -Wno-variadic-macros -fshort-wchar -x c++ -fPIC -pipe -fno-omit-frame-pointer -g -I"/usr/local"/include -I"$(UAS_SRC)"
    LD_OPTIONS=-shared-libgcc -L"/usr/lib" -L"/usr/local/lib" -L"$(UAS_HOME)vtm/lib"

  2. When attempting to create a thread with pthread_create(), the process receives SIGABRT from libc run-time : gdb backtrace :

    • in _lwp_kill() from /usr/lib/libc.so.12
    • in __lwd_thr_create_stub() from /usr/lib/libc.so.12
    • in _pthread_create() from /usr/libpthread.so.1
    • in CreerThread2() in /home/../syspsx_nt.cpp
  3. When attempting to use spin locks, we receive a segment violation. Here is the test case :

    typedef struct typmttsysnatsynchronisationdirect
    {
    union

      {
      pthread_spinlock_t HandleSpinLock;
      } Selection;
    } *TypMttSysNatSynchronisationDirect;

    TypMttSysNatSynchronisationDirect SynchronisationCourant;
    int Reponse;

    SynchronisationCourant=(TypMttSysNatSynchronisationDirect)malloc(sizeof(struct typmttsysnatsynchronisationdirect));
    if (SynchronisationCourant==NULL)
      return(0);
    memset(SynchronisationCourant, 0x0, sizeof(struct typmttsysnatsynchronisationdirect));
    Reponse=pthread_spin_init(&(SynchronisationCourant->Selection.HandleSpinLock), PTHREAD_PROCESS_SHARED);
    if (Reponse!=0)
      return(0);
    Reponse=pthread_spin_lock(&(SynchronisationCourant->Selection.HandleSpinLock));
    if (Reponse!=0)
      return(0);

When disassemblying code of pthread_spin_init() and pthread_spin_lock(), it seems that there is a function pointer inside pthread_spinlock that is set to NULL in pthread_spin_init() and that is indirectly called into pthread_spintrylock() called by pthread_spinlock().

Thank your for your help.

1 Answers1

0

It seems that each module is tagged by the compiler (gcc) to be compatible with multi-thread or not, and code generated is slighty changed accordignly. And you can't mixed the two kinds of module into one executable. Especially if you use dlopen() to dynamically load some shared objects.

As there is the /Mt option for msvc, threre is -pthread for gcc, but it is unavailable for Net BSD. And it is useless on other platforms.

The workaround is to link systematically libpthread.so to each module. Each module is then tagged has compatible multi-thread. And the two issues are over.