MIOpenGEMM icon indicating copy to clipboard operation
MIOpenGEMM copied to clipboard

Fix underlinked shared library

Open sclarkson opened this issue 7 years ago • 0 comments

libmiopengemm.so uses symbols from libpthread, but doesn't explicitly link to it

sclarkson@localhost:~/miopengemm$ nm -D /opt/rocm/miopengemm/lib/libmiopengemm.so | grep pthread
                 U pthread_create
                 w pthread_equal
                 w __pthread_key_create
                 w pthread_mutex_lock
                 w pthread_mutex_unlock
                 w pthread_once
sclarkson@localhost:~/miopengemm$ objdump -p /opt/rocm/miopengemm/lib/libmiopengemm.so | grep NEEDED
  NEEDED               libOpenCL.so.1
  NEEDED               libstdc++.so.6
  NEEDED               libm.so.6
  NEEDED               libgcc_s.so.1
  NEEDED               libc.so.6
  NEEDED               ld-linux-x86-64.so.2

This forces any user of the library to explicitly link to libpthread themselves, despite not using threads directly. For example

sclarkson@localhost:~/miopengemm$ g++ -std=c++11 examples/bench.cpp -I/opt/rocm/include -L/opt/rocm/lib -lmiopengemm
/opt/rocm/lib/libmiopengemm.so: undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status

The linking was made private and headers modified to make it clear that threading isn't needed in the public interface. (Those other libraries should also probably be private).

One of the tests explicitly uses threads, so the pthread options can't be removed from the tests CMakeLists.txt

sclarkson avatar Oct 31 '18 03:10 sclarkson