flang-compiler / flang

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

Compilation fails on macOS #678

Open trifud opened 5 years ago

trifud commented 5 years ago

I am trying to build flang (and more specifically libpgmath) on macOS 10.13 but I get a build error:

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/llvm-6.0 -DCMAKE_CXX_COMPILER=/usr/local/gcc-8.3.0/bin/g++ -DCMAKE_C_COMPILER=/usr/local/gcc-8.3.0/bin/gcc -DCMAKE_ASM_COMPILER=/usr/local/yasm-1.3.0/bin/yasm ..

make

[  0%] Building ASM object lib/x86_64/relaxed/CMakeFiles/x86_64_relaxed.dir/relaxedmath.S.o
yasm: FATAL: unrecognized object format `omit-frame-pointer'
make[2]: *** [lib/x86_64/relaxed/CMakeFiles/x86_64_relaxed.dir/relaxedmath.S.o] Error 1
make[1]: *** [lib/x86_64/relaxed/CMakeFiles/x86_64_relaxed.dir/all] Error 2
make: *** [all] Error 2

Is the issue with the assembler or with the build environment? What assembler is recommended for building flang? How can I workaround this issue?

d-parks commented 5 years ago

As far as I know, we have never tried building libpgmath with yasm. Could you use either the gnu or clang assembler?

trifud commented 5 years ago

I tried the GNU assembler from binutils-2.32: as: unrecognized option -PG_PIC

When using the LLVM assembler, I get a different error:

llvm-as: Unknown command line argument '-DOSX86'.  Try: '/usr/local/llvm-6.0/bin/llvm-as -help'
llvm-as: Did you mean '-debug'?
llvm-as: Unknown command line argument '-DPG_PIC'.  Try: '/usr/local/llvm-6.0/bin/llvm-as -help'
llvm-as: Did you mean '-debug'?
...

Then I figured out that Xcode ships with an assembler and it worked (the build errors from above were treated as warnings). But it seems that AVX-512 stuff doesn't work on macOS even with GCC 8.3.0:

[  7%] Building C object lib/common/CMakeFiles/common_mth_cmplx.dir/cdabs.c.o
/var/folders/w2/62r_94rj2m31sfbps28z0tgm0001gp/T//ccQeWacg.s:28:2: error: instruction requires: AVX-512 ISA
        vmovaps %zmm0, -176(%rbp)
        ^

Is my GCC build incomplete? Is it possible to build flang on macOS at all?

d-parks commented 5 years ago

I don't know the official status of FLANG on OSX - Steve S or Gary K will have to chime in here. I have been able to build libpgmath (in house) on OSX - but that has been a few months. Let me try building that again and give you and update.

gklimowicz commented 5 years ago

We would like to have Flang build on macOS, but it's not been a high priority.

jwhowarth commented 5 years ago

It really merits a higher priority since, as of macOS Catalina and Xcode 11, macOS users won't be able to build FSF gcc (due to the absence of support for the availability attribute).

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90835

So flang could become the de facto fortran compiler on macOS 10.15 if it would only build.

d-parks commented 5 years ago

With your build environment, would you be able to enumerate all the libpgmath failures? Maybe make -k?

Thanks

jwhowarth commented 5 years ago

The build doesn't get as far as libpgmath. Using either Xcode 10.2's clang, llvm 7.0's clang or llvm 6.0's clang, I get the 20 errors of the form...

[ 36%] Building CXX object lib/CrossTU/CMakeFiles/clangCrossTU.dir/CrossTranslationUnit.cpp.o In file included from /Users/howarth/flang_dir/flang-driver/lib/CrossTU/CrossTranslationUnit.cpp:19: In file included from /Users/howarth/flang_dir/flang-driver/include/clang/Frontend/CompilerInstance.h:18: /Users/howarth/flang_dir/flang-driver/include/clang/Frontend/Utils.h:63:1: error: declaration conflicts with target of using declaration already in scope class StringRef; ^ /Users/howarth/flang_dir/flang-driver/include/clang/Basic/LLVM.h:29:9: note: target of using declaration class StringRef; ^ /Users/howarth/flang_dir/flang-driver/include/clang/Basic/LLVM.h:73:15: note: using declaration using llvm::StringRef; ^ Are any folks on linux actually building with the clang compilers and its libc++?

isuruf commented 5 years ago

FWIW, I built the flang-driver a few months ago using clang 4.0.1 on macOS and it built fine.

jwhowarth commented 5 years ago

Is that clang 4.0.1, the Apple Clang from Xcode 9? IMHO, it is rather embarrassing that Flang is claimed to be based on the llvm 7.0 release yet it is unbuildable by that very compiler. I get that it needs its own patched llvm but it at least should be coded to match the compiler syntax restrictions of the same llvm release.

isuruf commented 5 years ago

Is that clang 4.0.1, the Apple Clang from Xcode 9?

No, vanilla clang.

jwhowarth commented 5 years ago

As I said, it really should be coded to be compatible with the clang from the llvm it claims to be based on, otherwise it will never get merged into the main llvm repos.

jwhowarth commented 5 years ago

I see the same failure with llvm 5.0.2 clang compiler. I can't test llvm 4.0 on Mojave because MacPorts reports that as an unsupported for that macOS release.

isuruf commented 5 years ago

@jwhowarth, can you build clang on your system? flang-driver is basically clang with a few changes.

jwhowarth commented 5 years ago

FYI, I can reproduce the same exact failure under Ubuntu Disco when using the Ubuntu clang-7 and clang++-7 compilers in the build-flang-driver.sh script rather than gcc and g++. So this is generic breakage when the flang-driver is built against recent clang.

jwhowarth commented 5 years ago

Okay, with the patch proposed in https://github.com/flang-compiler/flang/issues/779 flang-driver builds on macOS but the resulting build of flang fails at...

Scanning dependencies of target pgmath [100%] Linking CXX shared library libpgmath.dylib Undefined symbols for architecture x86_64: "_mth_i_dceil", referenced from: _mth_intrins_defs in dispatch.c.o fptr2name in dispatch.c.o (maybe you meant: mth_i_dceil_sse) "_mth_i_dfloor", referenced from: _mth_intrins_defs in dispatch.c.o fptr2name in dispatch.c.o (maybe you meant: mth_i_dfloor_sse) "_mth_i_floor", referenced from: _mth_intrins_defs in dispatch.c.o fptr2name in dispatch.c.o (maybe you meant: mth_i_floor_sse) ld: symbol(s) not found for architecture x86_64 clang-7: error: linker command failed with exit code 1 (use -v to see invocation)