0

I found if I add -shared, It will solve the make problem, but, I don't know where to modify the Makefile. I've tried LDFLAGS,CXXFLAGS in Makefile https://gist.github.com/anonymous/5453234 , it can not work.

[dlin@h perf]$ make V=1
/bin/sh ../libtool  --tag=CXX   --mode=link g++  -O2 -pipe -shared  -shared  -o local_lat local_lat.o ../src/libzmq.la -lrt -lpthread -shared
libtool: link: g++ -O2 -pipe -o .libs/local_lat local_lat.o  ../src/.libs/libzmq.so -lrt -lpthread
/usr/bin/ld: .libs/local_lat: hidden symbol `__sync_fetch_and_add_2' in /usr/lib/gcc/sh4-linux/4.2.4/libgcc.a(linux-atomic.o) is referenced by DSO
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status
make: *** [local_lat] Error 1
[dlin@h perf]$ g++ -O2 -pipe -o .libs/local_lat local_lat.o  ../src/.libs/libzmq.so -lrt -lpthread
/usr/bin/ld: .libs/local_lat: hidden symbol `__sync_fetch_and_add_2' in /usr/lib/gcc/sh4-linux/4.2.4/libgcc.a(linux-atomic.o) is referenced by DSO
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status
[dlin@h perf]$ g++ -O2 -pipe -o .libs/local_lat local_lat.o  ../src/.libs/libzmq.so -lrt -lpthread -shared

The -shared option workable on manual write at the last command, but how to put in Makefile?

Daniel YC Lin
  • 15,050
  • 18
  • 63
  • 96

1 Answers1

1

It is likely a -shared delays the error till runtime, it would appear GCC for SuperH does not have full atomic support. The options are thus to encode the required atomics or use the mutex fallback.

You can force use of a mutex by patching configure.ac with the following:

sh-* | sh[34]*-*)
    AC_DEFINE(ZMQ_FORCE_MUTEXES, 1, [Force to use mutexes])
    ;;

Which is not going to be significantly worse than native support as SuperH hardware only offers test-and-set on a byte via the tas.b op. A mutex op could be replaced with the following compare-and-swap:

static unsigned char sh_critical_section = 0;

inline static void sh_enter_critical_section (void)
{
  unsigned int oldval;   
  do
    __asm__ __volatile__ ("tas.b @%1; movt %0"
              : "=r" (oldval)
              : "r" (&sh_critical_section)
              : "t", "memory");
  while (oldval == 0);
}

inline static void sh_leave_critical_section (void)
{
  __asm__ __volatile__ (" " ::: "memory");
  sh_critical_section= 0;
}

Thus the following modifications could be made:

#elif defined ZMQ_ATOMIC_COUNTER_SH
            sh_enter_critical_section ();
            old_value = value;
            value += increment_;
            sh_leave_critical_section ();    
#elif defined ZMQ_ATOMIC_COUNTER_MUTEX
            sync.lock ();
            old_value = value;
            value += increment_;
            sync.unlock ();
#else

Which is redundant as the functionality is the same as the mutex implementation, so one could move the tas.b op to the mutex_t implementation but would need to introduce a global variable for the lock, you would gain hardly anything over the pthread implementation of a mutex.

Run a performance test to see if there is any measurable performance improvement or even degradation and submit a pull request upstream for others to enjoy!

Steve-o
  • 12,678
  • 2
  • 41
  • 60
  • You are so power, how to detect the problem is caused by gcc without sh4 support. Why not `unsigned int oldval` defined as `unsigned char`? – Daniel YC Lin Apr 25 '13 at 00:04
  • To quick check just try to use mutex, I've made a patch, https://gist.github.com/5458192, but it can not work, still show the same error message. I'm not familiar with automake. – Daniel YC Lin Apr 25 '13 at 07:58
  • @DanielYCLin you need to run `autogen.sh` to recreate the `configure` file from `configure.ac`. You can always `grep sh- configure` to confirm it applied. – Steve-o Apr 25 '13 at 14:40
  • my build script[PKGBUILD](https://gist.github.com/5469088),[configure.in](https://gist.github.com/5469047) ,and the [error log](http://paste.ubuntu.com/5605493) and ./configure contains the sh- patch – Daniel YC Lin Apr 26 '13 at 17:59