POSIX thread library support

Hello all,

I caught a problem related to pthread library. I built llvm and llvm-gcc then compiling a multithreaded benchmark written in POSIX thread library. The command “llvm-gcc –o bench bench.c –lpthread” ran well while “llvm-gcc –c bench; llvm-ld –o bench bench.o –lpthread” crashed. It told that “llvm-ld: error: Cannot find library ‘pthread’”.

I could not find libpthread.a as well as libpthread.so** in my llvm installation path directory. Did llvm not support pthread? Any suggestions?

Best regards,

Hanfeng

I could not find libpthread.a as well as libpthread.so** in my llvm
installation path directory. Did llvm not support pthread? Any suggestions?

  I believe it uses your system pthread library.

Regards,
chenwj

Hi chenwj,
If it use system pthread library, then it should find it in the stand search path. I also added the option "-L/usr/lib -L/usr/lib64" but it still failed.

  Don't know if the link below helps or not,
  http://lists.cs.uiuc.edu/pipermail/llvmdev/2009-November/027274.html

Regards,
chenwj

Hi chenwj,
According to the link, I found that during the compiling process, the option "-emit-llvm" must be added to generate immediate object *.o.
[hanfeng@os-wstation02 fft]llvm-gcc -c fft.c -emit-llvm
Then using llvm-ld will generate two files - a shell excutable and a llvm bytecode data both of which would run perfect.
[hanfeng@os-wstation02 fft]llvm-ld -o FFT fft.o
[hanfeng@os-wstation02 fft]$ ls
FFT FFT.bc fft.c fft.C fft.o Makefile README.fft
[hanfeng@os-wstation02 fft]$ lli FFT.bc
...
<omit some outputs here, it worked well>
...
I guess llvm-ld may not support to generate native executable. However, I am not sure that.

Best regards,
Hanfeng

According to the link, I found that during the compiling process, the option "-emit-llvm" must be added to generate immediate object *.o.
[hanfeng@os-wstation02 fft]llvm-gcc -c fft.c -emit-llvm

  "-emit-llvm" emits object file which contains LLVM bitcode (IR).
Default file name suffix is .o, but you might want to use "-o fft.bc"
to make the suffix self-explained.

Then using llvm-ld will generate two files - a shell excutable and a llvm bytecode data both of which would run perfect.
[hanfeng@os-wstation02 fft]llvm-ld -o FFT fft.o

                                        ^^^
  Is it not a native excutable?

Regards,
chenwj

Hi chenwj,
For the first question, even if I did not specify "-o fft.bc", it still generated fft.o which is also a llvm bitcode file.
For the second question, I intended to generate a native executable "FFT". However, it only generate a llvm bitcode file fft.bc and a native POSIX shell excuatable named fft. Howerver, the contents of the shell executable fft is a wrapper to call "lli fft".

I also asked some other people. They told me that pthread came along with the native system and was not distributed by llvm. Libpthread.so and libpthread_nonshared.so were located in /usr/lib. "llvm-ld -native -o th th.o" failed even I told it that "-L/usr/lib".

Best regards,
Hanfeng

According to the link, I found that during the compiling process, the option "-emit-llvm" must be added to generate immediate object *.o.
[hanfeng@os-wstation02 fft]llvm-gcc -c fft.c -emit-llvm

  "-emit-llvm" emits object file which contains LLVM bitcode (IR).
Default file name suffix is .o, but you might want to use "-o fft.bc"
to make the suffix self-explained.

Then using llvm-ld will generate two files - a shell excutable and a llvm bytecode data both of which would run perfect.
[hanfeng@os-wstation02 fft]llvm-ld -o FFT fft.o

                                        ^^^
  Is it not a native excutable?

Regards,
chenwj

... "llvm-ld -native -o th th.o" failed even I told it that "-L/usr/lib".

But did you also tell it -lpthread ?

Ciao, Duncan.