pthread?

hi,

I compile a pthread program using llvmgcc, but when i run pthread.ll, it show:

Try

llvmgcc pthread.c -o pthread.ll -pthread

You have to link in the pthreads library, and I believe -pthread is all you
need on a redhat 9 box.

Kevin

Yup, in theory this should work. However, in practice it looks like it
doesn't, on redhat 8 at least. The problem is that (in RH8)
/usr/lib/libpthread.so is not actually a library, it's a linker script.

Because of this you might need to edit the script generated by gccld (the
pthread.ll file in your case) to pass '--load libpthread.so.0' into lli
before the $0.bc argument. This should give you something like this:

I try to run lli with "--load=/lib/libpthread.so", but it shows:

I try to run lli with "--load=/lib/libpthread.so", but it shows:
---------------------------------------------------
[yue@RH9 test]$ ./pthread.ll
Error opening '/lib/libpthread.so.0': /lib/libpthread.so.0: symbol
_errno, version GLIBC_2.0 not defined in file libc.so.6 with link time
reference
  -load request ignored.

This is strange, I have no idea why this is happening. Maybe you have
mixed versions of different libraries installed on your system? Maybe
your compiled version of LLI is not up-to-date?

I was able to use 'lli -load=libpthread.so.0 a.out.bc' and that worked for
me, note the lack of an absolute path.

then try to run with "--load=/usr/lib/libpthread.so", it shows:
--------------------------------------------------
[yue@RH9 test]$ ./pthread.ll
Error opening '/usr/lib/libpthread.so': /usr/lib/libpthread.so: invalid
ELF header

That's because it is trying to use the linker script as a shared object
and getting unhappy about it. It would be nice if LLVM supported linker
scripts better, precisely to make these sorts of problems disappear, but
noone has tackled that yet.

Actually, while I'm thinking about it, I should throw a disclaimer in
here. The JIT does not yet have locking in place to protect its internal
data structures from multiple threads. Because of this you might get
'recursive compilation detected' aborts when you finally get your threaded
program to load the correct libraries. As a work-around, you can compile
the program with the 'llc' utility to native code, link it with the
pthreads libraries, then execute it. Another advantage of this, is that
it lets the GCC compiler driver parse the linker script and figure out
what to do with it.

To use this, try something like this:

$ llvmgcc foo.c -o foo # or however you compile your program to .bc
$ llc foo.bc -o foo.s
$ gcc -pthread foo.s -o foo
$ ./foo

-Chris

yue wrote:

> hi,
>
> I compile a pthread program using llvmgcc, but when i run pthread.ll,
> it show:
> ------------------
> [yue@RH9 test]$ llvmgcc pthread.c -o pthread.ll
> [yue@RH9 test]$ ls
> pthread pthread.c pthread.ll pthread.ll.bc
> [yue@RH9 test]$ ./pthread.ll
> Creating thread 0
> WARNING: Cannot resolve fn 'pthread_create' using a dummy noop
> function instead!
> ERROR; return code from pthread_create() is -1073745164
> [yue@RH9 test]$
> --------------------
> how to solve the problem?
>
> yueqiang
> 2003/12/24
>

_______________________________________________
LLVM Developers mailing list
LLVMdev@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev

-Chris

ok, using
lli -load=libpthread.so.0 pthread.ll.bc

yueqiang

Chris Lattner wrote: