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


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.


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/ 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' into lli
before the $0.bc argument. This should give you something like this:

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

I try to run lli with "--load=/lib/", but it shows:
[yue@RH9 test]$ ./pthread.ll
Error opening '/lib/': /lib/ symbol
_errno, version GLIBC_2.0 not defined in file with link time
  -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 a.out.bc' and that worked for
me, note the lack of an absolute path.

then try to run with "--load=/usr/lib/", it shows:
[yue@RH9 test]$ ./pthread.ll
Error opening '/usr/lib/': /usr/lib/ 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


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


ok, using
lli pthread.ll.bc


Chris Lattner wrote: