[PATCH] D21478: [build] Link main executable with libpthread

Chris Bieneman via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 21 11:25:33 PDT 2016


beanz added inline comments.

================
Comment at: cmake/config-ix.cmake:115
@@ +114,3 @@
+  find_package(Threads REQUIRED)
+  # Strip -l prefix, because we expect unprefixed name in PTHREAD_LIB
+  string(REGEX REPLACE "^-l" "" PTHREAD_LIB ${CMAKE_THREAD_LIBS_INIT})
----------------
tra wrote:
> beanz wrote:
> > Rather than this, try setting `THREADS_PREFER_PTHREAD_FLAG`. That will prefer the -pthreds flag if the compiler supports it.
> > 
> > Even with that you can't actually assume that the flag returned here will be `-pthread` instead of `-lpthread` because I'm pretty sure we support using pthreads library with compilers that don't support `-pthread`.
> That would need more changes. Currently we add PTHREAD_LIB to system_libs, which eventually ends up in LLVM_SYSTEM_LIBS property which is in turn used by llvm-config for figuring out what to print for --system-libs. The way it currently does that by prepending everything in LLVM_SYSTEM_LIBS with '-l' and that breaks with both -lpthread and -pthread.
> 
> I guess we need to check for prefixed names there and only append -l to items without leading dash. Stay tuned for updated patch.
I didn't think about the extra complication, if we want to force `-lpthread` to be the return here to be consistent you can set `THREADS_HAVE_PTHREAD_ARG=Off`. That should make this safer, and you can save the added complexity of supporting `-pthread` for another time.

Thoughts?


http://reviews.llvm.org/D21478





More information about the llvm-commits mailing list