flang-compiler / flang

Flang is a Fortran language front-end designed for integration with LLVM.
Other
808 stars 137 forks source link

undefined reference to `__mth_i_dceil' on Ubuntu 18.04 #838

Open naromero77 opened 5 years ago

naromero77 commented 5 years ago

I followed the instructions here for building Flang: https://github.com/flang-compiler/flang/wiki/Building-Flang

particular the OpenMP 4.5 version with the NVidia backend. However, if compile a trivial OpenMP 4.5 program, I receive the following link-time error for a trivial program:

(base) [naromero@naromero-desktop gcc-bugs]$ flang -v -O3 -fopenmp -Mpreprocess --cuda-path=/scratch/naromero/opt/spack/linux-ubuntu18.04-westmere/gcc-7.4.0/cuda-9.2.88-pvhoreulmghihlbm3yc5rygpgx3vn2ni -o foo.x test_openacc_attach_v4.F90  
clang version 7.1.0 (https://github.com/flang-compiler/flang-driver.git 984936abdd04b40140c98ba5e273a3c006780612) (https://github.com/flang-compiler/llvm.git 939ad19087ec3c18718b2b6bb7ae40d7945f54d8)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /scratch/naromero/opt/spack/linux-ubuntu18.04-westmere/gcc-7.4.0/llvm-flang-develop-dkyv5x7m4wuskctqlzhii2plzodz6bo6/bin
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.4.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
Found CUDA installation: /scratch/naromero/opt/spack/linux-ubuntu18.04-westmere/gcc-7.4.0/cuda-9.2.88-pvhoreulmghihlbm3yc5rygpgx3vn2ni, version 9.2
 "/scratch/naromero/opt/spack/linux-ubuntu18.04-westmere/gcc-7.4.0/flang-develop-5gydx7iiqiag5e2mxxuogz46ggfwy3vi/bin/flang1" test_openacc_attach_v4.F90 -x 69 0x1000 -opt 3 -terse 1 -inform warn -nohpf -nostatic -cmdline '+flang -v -O3 -fopenmp -Mpreprocess --cuda-path=/scratch/naromero/opt/spack/linux-ubuntu18.04-westmere/gcc-7.4.0/cuda-9.2.88-pvhoreulmghihlbm3yc5rygpgx3vn2ni -o foo.x test_openacc_attach_v4.F90' -inform warn -mp -x 69 0x200 -x 69 0x400 -ieee 0 -x 19 0x400000 -quad -x 68 0x1 -x 59 4 -x 15 2 -x 49 0x400004 -x 51 0x20 -x 57 0x4c -x 58 0x10000 -x 124 0x1000 -tp px -x 57 0xfb0000 -x 58 0x78031040 -x 47 0x08 -x 48 4608 -x 49 0x100 -x 70 0x6c00 -x 119 0x10000000 -x 129 2 -x 47 0x400000 -x 52 2 -stdinc /scratch/naromero/opt/spack/linux-ubuntu18.04-westmere/gcc-7.4.0/llvm-flang-develop-dkyv5x7m4wuskctqlzhii2plzodz6bo6/bin/../include:/usr/local/include:/scratch/naromero/opt/spack/linux-ubuntu18.04-westmere/gcc-7.4.0/llvm-flang-develop-dkyv5x7m4wuskctqlzhii2plzodz6bo6/lib/clang/7.1.0/include:/usr/include/x86_64-linux-gnu:/include:/usr/include -def __amd64__=1 -def __amd64=1 -def __x86_64=1 -def __x86_64__=1 -def __REGISTER_PREFIX__= -def __NO_MATH_INLINES=1 -def __SSE2__=1 -def __SSE2_MATH__=1 -def __SSE__=1 -def __SSE_MATH__=1 -def __MMX__=1 -def __SIZEOF_FLOAT128__=16 -def unix=1 -def __unix=1 -def __unix__=1 -def linux=1 -def __linux=1 -def __linux__=1 -def __gnu_linux__=1 -def __ELF__=1 -def __FLOAT128__=1 -def __SIZE_TYPE__=long unsigned int -def __PTRDIFF_TYPE__=long int -def _LP64=1 -def __LP64__=1 -def __LONG_MAX__=9223372036854775807L -def __amd_64__amd64__ -def __k8 -def __k8__ -def __THROW= -def __extension__= -def __PGLLVM__ -preprocess -freeform -vect 48 -x 54 1 -x 70 0x40000000 -y 163 0xc0000000 -x 189 0x10 -stbfile test_openacc_attach_v4-da48e8.stb -modexport test_openacc_attach_v4-da48e8.cmod -modindex test_openacc_attach_v4-da48e8.cmdx -output test_openacc_attach_v4-da48e8.ilm
 "/scratch/naromero/opt/spack/linux-ubuntu18.04-westmere/gcc-7.4.0/flang-develop-5gydx7iiqiag5e2mxxuogz46ggfwy3vi/bin/flang2" test_openacc_attach_v4-da48e8.ilm -y 129 2 -fn test_openacc_attach_v4.F90 -opt 3 -terse 1 -inform warn -cmdline '+flang -v -O3 -fopenmp -Mpreprocess --cuda-path=/scratch/naromero/opt/spack/linux-ubuntu18.04-westmere/gcc-7.4.0/cuda-9.2.88-pvhoreulmghihlbm3yc5rygpgx3vn2ni -o foo.x test_openacc_attach_v4.F90' -inform warn -mp -x 69 0x200 -x 69 0x400 -ieee 0 -x 68 0x1 -x 51 0x20 -x 119 0xa10000 -x 122 0x40 -x 123 0x1000 -x 127 4 -x 127 17 -x 19 0x400000 -x 28 0x40000 -x 120 0x10000000 -x 70 0x8000 -x 122 1 -x 125 0x20000 -x 164 0x800000 -quad -x 59 4 -tp px -x 120 0x1000 -x 124 0x1400 -y 15 2 -x 57 0x3b0000 -x 58 0x48000000 -x 49 0x100 -astype 0 -x 183 4 -x 121 0x800 -x 54 0x10 -x 70 0x40000000 -x 249 70 -x 124 1 -y 163 0xc0000000 -x 189 0x10 -y 189 0x4000000 -x 183 0x10 -stbfile test_openacc_attach_v4-da48e8.stb -asm /tmp/test_openacc_attach_v4-da48e8.ll
 "/scratch/naromero/opt/spack/linux-ubuntu18.04-westmere/gcc-7.4.0/llvm-flang-develop-dkyv5x7m4wuskctqlzhii2plzodz6bo6/bin/clang-7" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test_openacc_attach_v4.F90 -mrelocation-model static -mthread-model posix -mllvm -pass-remarks= -mllvm -pass-remarks-missed= -mllvm -pass-remarks-analysis= -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -v -resource-dir /scratch/naromero/opt/spack/linux-ubuntu18.04-westmere/gcc-7.4.0/llvm-flang-develop-dkyv5x7m4wuskctqlzhii2plzodz6bo6/lib/clang/7.1.0 -O3 -fdebug-compilation-dir /home/naromero/gcc-bugs -ferror-limit 19 -fmessage-length 238 -fopenmp -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o /tmp/test_openacc_attach_v4-4ce6e7.o -x ir /tmp/test_openacc_attach_v4-da48e8.ll -faddrsig
clang -cc1 version 7.1.0 based upon LLVM 7.1.0 default target x86_64-unknown-linux-gnu
 "/usr/bin/ld" -z relro --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o foo.x /usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/7.4.0/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/7.4.0 -L/usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../../x86_64-linux-gnu -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../.. -L/scratch/naromero/opt/spack/linux-ubuntu18.04-westmere/gcc-7.4.0/llvm-flang-develop-dkyv5x7m4wuskctqlzhii2plzodz6bo6/bin/../lib -L/lib -L/usr/lib /tmp/test_openacc_attach_v4-4ce6e7.o -lflangmain -L/scratch/naromero/opt/spack/linux-ubuntu18.04-westmere/gcc-7.4.0/llvm-flang-develop-dkyv5x7m4wuskctqlzhii2plzodz6bo6/lib -L/scratch/naromero/opt/spack/linux-ubuntu18.04-westmere/gcc-7.4.0/pgmath-master-rofaowqkrd436lcosccvfgaisotn2xpz/lib -L/scratch/naromero/opt/spack/linux-ubuntu18.04-westmere/gcc-7.4.0/flang-develop-5gydx7iiqiag5e2mxxuogz46ggfwy3vi/lib -L/scratch/naromero/opt/spack/linux-ubuntu18.04-westmere/gcc-7.4.0/llvm-flang-develop-rh6m3ksy54lv3ixdua2evw5qh45oijkj/lib -L/scratch/naromero/opt/spack/linux-ubuntu18.04-westmere/gcc-7.4.0/cuda-9.2.88-pvhoreulmghihlbm3yc5rygpgx3vn2ni/lib64 -L/scratch/naromero/opt/spack/linux-ubuntu18.04-westmere/gcc-7.4.0/cuda-10.1.243-rmln3knnhqdkc4r2wbrnjdvtdmyd3e6x/lib64 -lflang -lflangrti -lpgmath -lomp -lm -lrt -lpthread -lomp -lgcc --as-needed -lgcc_s --no-as-needed -lpthread -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-linux-gnu/7.4.0/crtend.o /usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../../x86_64-linux-gnu/crtn.o
/scratch/naromero/opt/spack/linux-ubuntu18.04-westmere/gcc-7.4.0/pgmath-master-rofaowqkrd436lcosccvfgaisotn2xpz/lib/libpgmath.so: undefined reference to `__mth_i_dceil'
/scratch/naromero/opt/spack/linux-ubuntu18.04-westmere/gcc-7.4.0/pgmath-master-rofaowqkrd436lcosccvfgaisotn2xpz/lib/libpgmath.so: undefined reference to `__mth_i_floor'
/scratch/naromero/opt/spack/linux-ubuntu18.04-westmere/gcc-7.4.0/pgmath-master-rofaowqkrd436lcosccvfgaisotn2xpz/lib/libpgmath.so: undefined reference to `__mth_i_dfloor'

It is very similar to this issue https://github.com/flang-compiler/flang/issues/780

It looks like libpgmath.so needs the -lm from GCC 7.4.0 (default system lib), but adding the appropriate link line -L/lib/x86_64-linux-gnu/ does not resolve the issue.

sscalpone commented 5 years ago

Maybe @d-parks or @gklimowicz have some ideas?

isuruf commented 5 years ago

It looks like the same issue. On macOS this is a build time issue as unresolved symbols results in a build error, but on Linux, this is a runtime issue.

naromero77 commented 5 years ago

Yes, I would agree that it appears to be the same issues. There is a work around which involves commenting out the preprocessor logic. I am not sure what the correct long term solution is.

d-parks commented 5 years ago

Yes, this is a known problem with what different compilers predefine as CPP object macros with regards to Intel ISA extensions. I suspect that your compiler is either defining AVX or SSE4_1. The fastest workaround is to disable all the `#ifdef AVXand#ifdef SSE4_1logic (like prefix the object macros with XXX in theifdefs) inruntime/libpgmath/common/{ceil,dceil,dfloor,floor}.c`

In the meantime, I'll try to find a general solution.

naromero77 commented 4 years ago

@d-parks @sscalpone Thanks, that was the trick. I will make sure to patch this when I do a PR for the flang Spack package.