llvm-gfortran gives errors on AMD64-Ubuntu

Hi,

I have installed llvm and llvm-gfortran on Pentium4 machine using 32-bit
Ubuntu, it works fine. I recently installed them on AMD64-Ubuntu 8.04,
llvm-gfortran gave me following errors

$ llvm-gfortran -Wall hello.f95 -o hellof

/home/jli127/LLVM/llvm-gcc/install/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.1/../../../../lib64/libgfortran.a(error.o):
In function `_gfortrani_gfc_itoa':
(.text+0x76): undefined reference to `__umoddi3'
/home/jli127/LLVM/llvm-gcc/install/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.1/../../../../lib64/libgfortran.a(error.o):
In function `_gfortrani_gfc_itoa':
(.text+0x8a): undefined reference to `__udivdi3'
/home/jli127/LLVM/llvm-gcc/install/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.1/../../../../lib64/libgfortran.a(list_read.o):
In function `convert_integer':
(.text+0xd7c): undefined reference to `__divdi3'
/home/jli127/LLVM/llvm-gcc/install/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.1/../../../../lib64/libgfortran.a(read.o):
In function `_gfortrani_read_radix':
(.text+0x366): undefined reference to `__udivdi3'
/home/jli127/LLVM/llvm-gcc/install/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.1/../../../../lib64/libgfortran.a(read.o):
In function `_gfortrani_read_decimal':
(.text+0x603): undefined reference to `__udivdi3'
collect2: ld returned 1 exit status

The program is very simple:
PROGRAM hello
  IMPLICIT NONE
  WRITE (*,*) "Hello World!"
END PROGRAM hello

(2) Can I get LLVM bitcode file and run it as llvm-gcc does?
It give following errors on both 32bit and 64bit Ubuntu.
$ llvm-gfortran -O3 -emit-llvm hello.f95 -c -o hellof.bc
$ lli hellof.bc
  ERROR : 'main' function not found in module.
$ llc hellof.bc -o hellof.s
$ gcc hellof.s -o hellof.native
ERROR:
/usr/lib/gcc/i486-linux-gnu/4.1.3/../../../../lib/crt1.o: In function
`_start':
(.text+0x18): undefined reference to `main'
/tmp/cc4i3wD7.o: In function `MAIN__':
(.text+0x1f): undefined reference to `_gfortran_set_std'
/tmp/cc4i3wD7.o: In function `MAIN__':
(.text+0x4b): undefined reference to `_gfortran_st_write'
/tmp/cc4i3wD7.o: In function `MAIN__':
(.text+0x63): undefined reference to `_gfortran_transfer_character'
/tmp/cc4i3wD7.o: In function `MAIN__':
(.text+0x6b): undefined reference to `_gfortran_st_write_done'
collect2: ld returned 1 exit status

(3) Where can I get the SPEC/polyhedron testsuites?

Thanks
Jun

Hi,

I have installed llvm and llvm-gfortran on Pentium4 machine using 32-bit
Ubuntu, it works fine. I recently installed them on AMD64-Ubuntu 8.04,
llvm-gfortran gave me following errors

$ llvm-gfortran -Wall hello.f95 -o hellof

this works here on x86-64 ubuntu 8.10. I took a look in my libgfortran.a
and it doesn't reference any of the symbols you mention.

/home/jli127/LLVM/llvm-gcc/install/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.1/../../../../lib64/libgfortran.a(error.o):
In function `_gfortrani_gfc_itoa':
(.text+0x76): undefined reference to `__umoddi3'

This is a library function for doing 64 bit unsigned rem.
On a 64 bit machine you shouldn't need to call a library
function for this! Are you sure you didn't mix up 64 bit
and 32 bit somewhere?

(2) Can I get LLVM bitcode file and run it as llvm-gcc does?
It give following errors on both 32bit and 64bit Ubuntu.
$ llvm-gfortran -O3 -emit-llvm hello.f95 -c -o hellof.bc
$ lli hellof.bc
  ERROR : 'main' function not found in module.

The reason for this is that Fortran outputs the entry point
into your program as MAIN__ not main. Instead "main" is
defined in libgfortranbegin; it does some initialization
(exception handling, command line arguments, others?) then
calls MAIN__. I don't know much about lli, so hopefully
someone else can explain how to handle this situation.

$ llc hellof.bc -o hellof.s
$ gcc hellof.s -o hellof.native
ERROR:
/usr/lib/gcc/i486-linux-gnu/4.1.3/../../../../lib/crt1.o: In function
`_start':
(.text+0x18): undefined reference to `main'

You need to link with -lgfortranbegin.

(3) Where can I get the SPEC/polyhedron testsuites?

I don't know, sorry.

Best wishes,

Duncan.

Hi Duncan,

Thanks for your answers. Compiling .s file is OK after adding the -lgfortran
-lgfortranbegin.

I replace my Ubuntu 8.04 and by Ubuntu 8.10. And I checked all new packages
installed by 'apt-get' are amd64 version. However after compiling the
llvm-gfortran, I got the same error.

Here is my configure arguments
$ ../llvm-gcc4.2-2.3.source/configure --prefix=`pwd`/../install
--program-prefix=llvm- \
  --disable-shared --disable-multilib \
  --enable-llvm=/llvm/llvm-obj --enable-languages=c,c++,fortran
$ make LLVM_VERSION_INFO=2.3

Without any one of --disable-shared, --disable-multilib, the make will fail.

Could you give me the arguments you used for the 'configure', and the output
of the 'configure'? I want to check whether my OS misses some packages that
needed by llvm-gcc. I feel the libgfortran built in my OS may incorrect, due
to different configure settings.

BTW, I check the libgfortran.a in my system:
After make, the new generated libgfortran.a:
-rw-r--r-- 1 jli127 jli127 1513500 2008-11-06 19:17
/llvm/llvm-gcc/install/lib64/libgfortran.a
-rw-r--r-- 1 jli127 jli127 1513500 2008-11-06 19:16
/llvm/llvm-gcc/obj/x86_64-unknown-linux-gnu/libgfortran/.libs/libgfortran.a

It's different to the system original libgfortran.a:
-rw-r--r-- 1 root root 1854562 2008-10-25 01:40
/usr/lib/gcc/x86_64-linux-gnu/4.3/libgfortran.a

If replace it by system 'libgfortran.a', the error became:
hello.o: In function `MAIN__':
(.text+0x1e): undefined reference to `_gfortran_set_std'
collect2: ld returned 1 exit status

Thanks,
Jun

Hi Jun,

Without any one of --disable-shared, --disable-multilib, the make will fail.

This is correct. I fixed multilib & PIC codegen for x86-64 only
recently, so this will go to 2.4 release. Please carefully read
README.LLVM file

It's different to the system original libgfortran.a:

Yes, surely, because they were compiled from different sources with
different compilers!

Hi,

Here is my configure arguments
$ ../llvm-gcc4.2-2.3.source/configure --prefix=`pwd`/../install
--program-prefix=llvm- \
  --disable-shared --disable-multilib \
  --enable-llvm=/llvm/llvm-obj --enable-languages=c,c++,fortran

this looks ok to me. It's essentially the same as what I use.
Try with 2.4 (about to be released). I'm not sure I ever tried
to build the 2.3 version of llvm-gfortran on x86-64.

If replace it by system 'libgfortran.a', the error became:
hello.o: In function `MAIN__':
(.text+0x1e): undefined reference to `_gfortran_set_std'
collect2: ld returned 1 exit status

Probably your system gcc version is different to 4.2. Like gcc 4.2,
llvm-gcc generates a call to gfortran_set_std in MAIN__. This function
is defined in the gcc 4.2 version of libgfortran, but apparently not in
other gcc versions. [I think ubuntu 8.10 uses gcc 4.3].

Ciao,

Duncan.

Hi Duncan,

I tried the llvm-2.4 and llvm-gcc-4.2-2.4, but I got same error. :frowning:
It seems is the GCC's problem. Ubuntu 8.10 does use gcc 4.3. Could you tell
me what version of gcc you are using? Could you send me your configure
result for llvm and llvm-gcc? I suspect some packages may be missing since I
have a new installed OS. Thanks.

Jun