Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang/flang-new compilation issues on Linux on loongarch64 #4907

Closed
azuresky01 opened this issue Sep 29, 2024 · 7 comments · Fixed by #4915
Closed

clang/flang-new compilation issues on Linux on loongarch64 #4907

azuresky01 opened this issue Sep 29, 2024 · 7 comments · Fixed by #4915

Comments

@azuresky01
Copy link

Hello,

@XiWeiGu When I try to build OpenBLAS with clang/flang-new on Debian sid, I found compilation failed with both gmake and cmake. See below.

System details: Loongson 3A6000 CPU, Debian sid, kernel 6.11.0, clang 18.1.8, flang-new 18.1.8 (or clang 19.1.0 and flang-new 19.1.0), cmake 3.30.3.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

gmake:

building command: CC=clang-18 FC=flang-new-18 make

result:

...
make[1]: Entering directory '/home/loongson/test/build_OpenBLAS/kernel'
make[1]: warning: -j8 forced in makefile: resetting jobserver mode.
clang-18 -c -O2 -DSMALL_MATRIX_OPT -DMAX_STACK_ALLOC=2048 -Wall -march=loongarch64 -mabi=lp64d -DF_INTERFACE_GFORT -fPIC -DSMP_SERVER -DNO_WARMUP -DMAX_CPU_NUMBER=8 -DMAX_PARALLEL_NUMBER=1 -DBUILD_SINGLE=1 -DBUILD_DOUBLE=1 -DBUILD_COMPLEX=1 -DBUILD_COMPLEX16=1 -DVERSION=\"0.3.28.dev\" -UASMNAME -UASMFNAME -UNAME -UCNAME -UCHAR_NAME -UCHAR_CNAME -DASMNAME=samax_k -DASMFNAME=samax_k_ -DNAME=samax_k_ -DCNAME=samax_k -DCHAR_NAME=\"samax_k_\" -DCHAR_CNAME=\"samax_k\" -DNO_AFFINITY -I.. -UDOUBLE  -UCOMPLEX -UCOMPLEX -UDOUBLE  -DUSE_ABS -UUSE_MIN ../kernel/loongarch64/amax_lasx.S -o samax_k.o
../kernel/loongarch64/amax_lasx.S:232:10: error: expected newline
    .end samax_k ; .section .note.GNU-stack,"",@progbits
         ^
make[1]: *** [Makefile.L1:556: samax_k.o] Error 1
make[1]: Leaving directory '/home/loongson/test/build_OpenBLAS/kernel'
make: *** [Makefile:199: libs] Error 1

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

cmake:

building commands: CC=clang-18 FC=flang-new-18 cmake -B build and then cmake --build build

result:

[  0%] Building Fortran object CMakeFiles/LAPACK_OVERRIDES.dir/lapack-netlib/SRC/la_constants.f90.o
flang-new: error: unknown argument: '-mabi=lp64d'
flang-new: error: unknown argument: '-mabi=lp64d'
gmake[2]: *** [CMakeFiles/LAPACK_OVERRIDES.dir/build.make:5548: CMakeFiles/LAPACK_OVERRIDES.dir/lapack-netlib/SRC/la_constants.f90.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:378: CMakeFiles/LAPACK_OVERRIDES.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2

if replace flang-new-18 with gfortran, the result is:

...
[ 77%] Building C object driver/others/CMakeFiles/driver_others.dir/parameter.c.o
[ 77%] Built target driver_others
[ 77%] Building C object kernel/CMakeFiles/kernel.dir/CMakeFiles/lsame.c.o
[ 77%] Building C object kernel/CMakeFiles/kernel.dir/CMakeFiles/scabs1.c.o
[ 77%] Building C object kernel/CMakeFiles/kernel.dir/CMakeFiles/dcabs1.c.o
[ 77%] Building ASM object kernel/CMakeFiles/kernel.dir/CMakeFiles/samax_k.S.o
/home/loongson/test/build_OpenBLAS/kernel/loongarch64/amax_lasx.S:232:10: error: expected newline
    .end samax_k ; .section .note.GNU-stack,"",@progbits
         ^
gmake[2]: *** [kernel/CMakeFiles/kernel.dir/build.make:117: kernel/CMakeFiles/kernel.dir/CMakeFiles/samax_k.S.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:594: kernel/CMakeFiles/kernel.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2
@XiWeiGu
Copy link
Contributor

XiWeiGu commented Sep 30, 2024

Thank you for your testing. I will set up the environment promptly to reproduce the issue.

@azuresky01
Copy link
Author

azuresky01 commented Oct 2, 2024

Update with correction:

According to the reference here: https://flang.llvm.org/docs/FlangCommandLineReference.html, there is no "-mabi=%" flag for flang-new.

Following a recent PR #4899, I tried to add " -mabi=% " flag to the filter-out list at lines 1723-1724 in the file Makefile.system:

OpenBLAS/Makefile.system

Lines 1722 to 1724 in f10d47c

ifeq ($(F_COMPILER),FLANGNEW)
LAPACK_FFLAGS := $(filter-out -m32 -m64 -msse3 -mssse3 -msse4.1 -mavx -mavx2 -mskylake-avx512 -mtune=% ,$(FFLAGS))
override FFLAGS := $(filter-out -m32 -m64 -msse3 -mssse3 -msse4.1 -mavx -mavx2 -mskylake-avx512 -mtune=% ,$(FFLAGS))

This fixes " flang-new: error: unknown argument: '-mabi=lp64d' " issue for gmake.

However, now I observe two FORTRAN programs slacon.f and slacn2.f fail and the compilation stops:

...
flang-new-18 -O2 -march=loongarch64 -fPIC -c -o slabrd.o slabrd.f
flang-new-18 -O2 -march=loongarch64 -fPIC -c -o slacon.o slacon.f
flang-new-18 -O2 -march=loongarch64 -fPIC -c -o slacn2.o slacn2.f
flang-new-18 -O2 -march=loongarch64 -fPIC -c -o slaein.o slaein.f
flang-new-18 -O2 -march=loongarch64 -fPIC -c -o slaexc.o slaexc.f
LLVM ERROR: Do not know how to promote this operator!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /usr/lib/llvm-18/bin/flang-new -fc1 -triple loongarch64-unknown-linux-gnu -emit-obj -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -target-cpu loongarch64 -mframe-pointer=none -O2 -o slacon.o -x f95-cpp-input slacon.f
1.	Running pass 'Function Pass Manager' on module 'FIRModule'.
2.	Running pass 'LoongArch DAG->DAG Pattern Instruction Selection' on function '@slacon_'
LLVM ERROR: Do not know how to promote this operator!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /usr/lib/llvm-18/bin/flang-new -fc1 -triple loongarch64-unknown-linux-gnu -emit-obj -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -target-cpu loongarch64 -mframe-pointer=none -O2 -o slacn2.o -x f95-cpp-input slacn2.f
1.	Running pass 'Function Pass Manager' on module 'FIRModule'.
2.	Running pass 'LoongArch DAG->DAG Pattern Instruction Selection' on function '@slacn2_'
flang-new-18 -O2 -march=loongarch64 -fPIC -c -o slag2.o slag2.f
flang-new-18 -O2 -march=loongarch64 -fPIC -c -o slags2.o slags2.f
 #0 0x00007fffe6df3980 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0xdf3980)
 #1 0x00007fffe6df1854 llvm::sys::RunSignalHandlers() (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0xdf1854)
 #2 0x00007fffe6df41e0 (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0xdf41e0)
 #3 0x00007ffffe5c4910 (linux-vdso.so.1+0x910)
 #4 0x00007ffff2ddb700 __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007ffff2d87d3c raise ./signal/../sysdeps/posix/raise.c:27:6
 #6 0x00007ffff2d7123c abort ./stdlib/abort.c:81:7
 #7 0x00007fffe6d373dc llvm::report_fatal_error(llvm::Twine const&, bool) (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0xd373dc)
 #8 0x00007fffe6d3720c (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0xd3720c)
 #9 0x00007fffe755b2c8 (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0x155b2c8)
#10 0x00007fffe7581768 (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0x1581768)
#11 0x00007fffe7586570 llvm::SelectionDAG::LegalizeTypes() (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0x1586570)
#12 0x00007fffe7676f88 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0x1676f88)
#13 0x00007fffe76767c4 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0x16767c4)
#14 0x00007fffe767490c llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0x167490c)
#15 0x00007fffe71ee0b8 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0x11ee0b8)
#16 0x00007fffe6f6164c llvm::FPPassManager::runOnFunction(llvm::Function&) (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0xf6164c)
#17 0x00007fffe6f67864 llvm::FPPassManager::runOnModule(llvm::Module&) (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0xf67864)
#18 0x00007fffe6f61cac llvm::legacy::PassManagerImpl::run(llvm::Module&) (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0xf61cac)
#19 0x0000555557a8b1e0 Fortran::frontend::CodeGenAction::executeAction() (/usr/lib/llvm-18/bin/flang-new+0xc071e0)
#20 0x0000555557a7e6c0 Fortran::frontend::FrontendAction::execute() (/usr/lib/llvm-18/bin/flang-new+0xbfa6c0)
#21 0x0000555557a6d0f0 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/usr/lib/llvm-18/bin/flang-new+0xbe90f0)
#22 0x0000555557a82610 Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/usr/lib/llvm-18/bin/flang-new+0xbfe610)
#23 0x0000555557a6bb40 fc1_main(llvm::ArrayRef<char const*>, char const*) (/usr/lib/llvm-18/bin/flang-new+0xbe7b40)
#24 0x0000555557a6a718 main (/usr/lib/llvm-18/bin/flang-new+0xbe6718)
#25 0x00007ffff2d718b0 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#26 0x00007ffff2d71998 call_init ./csu/../csu/libc-start.c:128:20
#27 0x00007ffff2d71998 __libc_start_main ./csu/../csu/libc-start.c:347:5
#28 0x0000555557a6a0e8 _start (/usr/lib/llvm-18/bin/flang-new+0xbe60e8)
flang-new-18 -O2 -march=loongarch64 -fPIC -c -o slagtm.o slagtm.f
 #0 0x00007fffe6df3980 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0xdf3980)
 #1 0x00007fffe6df1854 llvm::sys::RunSignalHandlers() (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0xdf1854)
 #2 0x00007fffe6df41e0 (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0xdf41e0)
 #3 0x00007ffffd774910 (linux-vdso.so.1+0x910)
 #4 0x00007ffff375f700 __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007ffff370bd3c raise ./signal/../sysdeps/posix/raise.c:27:6
 #6 0x00007ffff36f523c abort ./stdlib/abort.c:81:7
 #7 0x00007fffe6d373dc llvm::report_fatal_error(llvm::Twine const&, bool) (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0xd373dc)
 #8 0x00007fffe6d3720c (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0xd3720c)
 #9 0x00007fffe755b2c8 (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0x155b2c8)
#10 0x00007fffe7581768 (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0x1581768)
#11 0x00007fffe7586570 llvm::SelectionDAG::LegalizeTypes() (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0x1586570)
#12 0x00007fffe7676f88 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0x1676f88)
#13 0x00007fffe76767c4 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0x16767c4)
#14 0x00007fffe767490c llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0x167490c)
#15 0x00007fffe71ee0b8 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0x11ee0b8)
#16 0x00007fffe6f6164c llvm::FPPassManager::runOnFunction(llvm::Function&) (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0xf6164c)
#17 0x00007fffe6f67864 llvm::FPPassManager::runOnModule(llvm::Module&) (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0xf67864)
#18 0x00007fffe6f61cac llvm::legacy::PassManagerImpl::run(llvm::Module&) (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0xf61cac)
#19 0x000055555810f1e0 Fortran::frontend::CodeGenAction::executeAction() (/usr/lib/llvm-18/bin/flang-new+0xc071e0)
#20 0x00005555581026c0 Fortran::frontend::FrontendAction::execute() (/usr/lib/llvm-18/bin/flang-new+0xbfa6c0)
#21 0x00005555580f10f0 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/usr/lib/llvm-18/bin/flang-new+0xbe90f0)
#22 0x0000555558106610 Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/usr/lib/llvm-18/bin/flang-new+0xbfe610)
#23 0x00005555580efb40 fc1_main(llvm::ArrayRef<char const*>, char const*) (/usr/lib/llvm-18/bin/flang-new+0xbe7b40)
#24 0x00005555580ee718 main (/usr/lib/llvm-18/bin/flang-new+0xbe6718)
#25 0x00007ffff36f58b0 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#26 0x00007ffff36f5998 call_init ./csu/../csu/libc-start.c:128:20
#27 0x00007ffff36f5998 __libc_start_main ./csu/../csu/libc-start.c:347:5
#28 0x00005555580ee0e8 _start (/usr/lib/llvm-18/bin/flang-new+0xbe60e8)
flang-new-18 -O2 -march=loongarch64 -fPIC -c -o slagv2.o slagv2.f
flang-new: error: unable to execute command: Aborted (core dumped)
flang-new: error: flang frontend command failed due to signal (use -v to see invocation)
Debian flang-new version 18.1.8 (11)
Target: loongarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-18/bin
flang-new: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
flang-new: note: diagnostic msg: /tmp/slacon-dda0eb
flang-new: note: diagnostic msg: /tmp/slacon-dda0eb.sh
flang-new: note: diagnostic msg: 

********************
make[2]: *** [Makefile:66: slacon.o] Error 254
make[2]: *** Waiting for unfinished jobs....
flang-new: error: unable to execute command: Aborted (core dumped)
flang-new: error: flang frontend command failed due to signal (use -v to see invocation)
Debian flang-new version 18.1.8 (11)
Target: loongarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-18/bin
flang-new: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
flang-new: note: diagnostic msg: /tmp/slacn2-0db7ef
flang-new: note: diagnostic msg: /tmp/slacn2-0db7ef.sh
flang-new: note: diagnostic msg: 

********************
make[2]: *** [Makefile:66: slacn2.o] Error 254
make[2]: Leaving directory '/home/loongson/test/ttt/lapack-netlib/SRC'
make[1]: *** [Makefile:27: lapacklib] Error 2
make[1]: Leaving directory '/home/loongson/test/ttt/lapack-netlib'
make: *** [Makefile:291: netlib] Error 2

Check the attachment for the msg files.

#########################################################

For cmake, following PR #4569, I tried to add some lines in the file cmake/fc.cmake to avoid adding "-mabi=%" flag when the compiler is llvm.

The original related part is here:

OpenBLAS/cmake/fc.cmake

Lines 62 to 80 in edaf593

if (LOONGARCH64)
if (BINARY64)
CHECK_C_COMPILER_FLAG("-mabi=lp64d" COMPILER_SUPPORT_LP64D_ABI)
if(COMPILER_SUPPORT_LP64D_ABI)
set(FCOMMON_OPT "${FCOMMON_OPT} -mabi=lp64d")
else()
set(FCOMMON_OPT "${FCOMMON_OPT} -mabi=lp64")
endif ()
if (INTERFACE64)
set(FCOMMON_OPT "${FCOMMON_OPT} -fdefault-integer-8")
endif ()
else ()
CHECK_C_COMPILER_FLAG("-mabi=ilp32d" COMPILER_SUPPORT_ILP32D_ABI)
if(COMPILER_SUPPORT_ILP32D_ABI)
set(FCOMMON_OPT "${FCOMMON_OPT} -mabi=ilp32d")
else()
set(FCOMMON_OPT "${FCOMMON_OPT} -mabi=lp32")
endif ()
endif ()

The fix:

add one line before lines 64 and 74:

if (NOT CMAKE_Fortran_COMPILER_ID MATCHES "LLVMFlang.*")

and one line after lines 69 and 79:

endif ()

The above fixes " flang-new: error: unknown argument: '-mabi=lp64d' " issue for cmake. However, similarly I observe the FORTRAN program slacon.f fails and the compilation stops:

[  1%] Building Fortran object CMakeFiles/LAPACK_OVERRIDES.dir/lapack-netlib/SRC/shseqr.f.o
[  1%] Building Fortran object CMakeFiles/LAPACK_OVERRIDES.dir/lapack-netlib/SRC/slabrd.f.o
[  1%] Building Fortran object CMakeFiles/LAPACK_OVERRIDES.dir/lapack-netlib/SRC/slacon.f.o
LLVM ERROR: Do not know how to promote this operator!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /usr/lib/llvm-18/bin/flang-new -fc1 -triple loongarch64-unknown-linux-gnu -emit-obj -I /home/loongson/test/build-OpenBLAS-test-cmake/lapack-netlib/LAPACKE/include -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -target-cpu loongarch64 -mframe-pointer=all -o CMakeFiles/LAPACK_OVERRIDES.dir/lapack-netlib/SRC/slacon.f.o -x f95-cpp-input /home/loongson/test/build-OpenBLAS-test-cmake/lapack-netlib/SRC/slacon.f
1.	Running pass 'Function Pass Manager' on module 'FIRModule'.
2.	Running pass 'LoongArch DAG->DAG Pattern Instruction Selection' on function '@slacon_'
 #0 0x00007fffe6df3980 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0xdf3980)
 #1 0x00007fffe6df1854 llvm::sys::RunSignalHandlers() (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0xdf1854)
 #2 0x00007fffe6df41e0 (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0xdf41e0)
 #3 0x00007fffff814910 (linux-vdso.so.1+0x910)
 #4 0x00007ffff386f700 __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007ffff381bd3c raise ./signal/../sysdeps/posix/raise.c:27:6
 #6 0x00007ffff380523c abort ./stdlib/abort.c:81:7
 #7 0x00007fffe6d373dc llvm::report_fatal_error(llvm::Twine const&, bool) (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0xd373dc)
 #8 0x00007fffe6d3720c (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0xd3720c)
 #9 0x00007fffe755b2c8 (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0x155b2c8)
#10 0x00007fffe7581768 (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0x1581768)
#11 0x00007fffe7586570 llvm::SelectionDAG::LegalizeTypes() (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0x1586570)
#12 0x00007fffe7676f88 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0x1676f88)
#13 0x00007fffe76767c4 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0x16767c4)
#14 0x00007fffe767490c llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0x167490c)
#15 0x00007fffe71ee0b8 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0x11ee0b8)
#16 0x00007fffe6f6164c llvm::FPPassManager::runOnFunction(llvm::Function&) (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0xf6164c)
#17 0x00007fffe6f67864 llvm::FPPassManager::runOnModule(llvm::Module&) (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0xf67864)
#18 0x00007fffe6f61cac llvm::legacy::PassManagerImpl::run(llvm::Module&) (/lib/loongarch64-linux-gnu/libLLVM-18.so.18.1+0xf61cac)
#19 0x0000555559f431e0 Fortran::frontend::CodeGenAction::executeAction() (/usr/lib/llvm-18/bin/flang-new+0xc071e0)
#20 0x0000555559f366c0 Fortran::frontend::FrontendAction::execute() (/usr/lib/llvm-18/bin/flang-new+0xbfa6c0)
#21 0x0000555559f250f0 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/usr/lib/llvm-18/bin/flang-new+0xbe90f0)
#22 0x0000555559f3a610 Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/usr/lib/llvm-18/bin/flang-new+0xbfe610)
#23 0x0000555559f23b40 fc1_main(llvm::ArrayRef<char const*>, char const*) (/usr/lib/llvm-18/bin/flang-new+0xbe7b40)
#24 0x0000555559f22718 main (/usr/lib/llvm-18/bin/flang-new+0xbe6718)
#25 0x00007ffff38058b0 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#26 0x00007ffff3805998 call_init ./csu/../csu/libc-start.c:128:20
#27 0x00007ffff3805998 __libc_start_main ./csu/../csu/libc-start.c:347:5
#28 0x0000555559f220e8 _start (/usr/lib/llvm-18/bin/flang-new+0xbe60e8)
flang-new: error: unable to execute command: Aborted (core dumped)
flang-new: error: flang frontend command failed due to signal (use -v to see invocation)
Debian flang-new version 18.1.8 (11)
Target: loongarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-18/bin
flang-new: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
flang-new: note: diagnostic msg: /tmp/slacon-931c2e
flang-new: note: diagnostic msg: /tmp/slacon-931c2e.sh
flang-new: note: diagnostic msg: 

********************
gmake[2]: *** [CMakeFiles/LAPACK_OVERRIDES.dir/build.make:1024: CMakeFiles/LAPACK_OVERRIDES.dir/lapack-netlib/SRC/slacon.f.o] Error 254
gmake[1]: *** [CMakeFiles/Makefile2:378: CMakeFiles/LAPACK_OVERRIDES.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2

Check the attachment for the msg files.
slacon-dda0eb.zip

@martin-frbg
Copy link
Collaborator

Right, seems earlier versions of flang-new used to ignore any -m arguments without complaining, and now those generate an error. I have no idea however if/how flang-new is expected to react to the presence of multiple ABIs for a given target...

Regarding the other problem with clang, could you try changing the toplevel common_loongarch64.h
around line 280 where it currently has an unconditional

#define EPILOGUE      \
    .end    REALNAME ;\
    GNUSTACK

and make it read

#ifdef __clang__
#define EPILOGUE .end
#else
#define EPILOGUE      \
    .end    REALNAME ;\
    GNUSTACK
#endif

(assuming one does not need to use the GNUSTACK identifier to mark the stack as non-executable with clang - although maybe it would be necessary when expressly using GNU ld for linking)

@azuresky01
Copy link
Author

Right, seems earlier versions of flang-new used to ignore any -m arguments without complaining, and now those generate an error. I have no idea however if/how flang-new is expected to react to the presence of multiple ABIs for a given target...

Regarding the other problem with clang, could you try changing the toplevel common_loongarch64.h around line 280 where it currently has an unconditional

#define EPILOGUE      \
    .end    REALNAME ;\
    GNUSTACK

and make it read

#ifdef __clang__
#define EPILOGUE .end
#else
#define EPILOGUE      \
    .end    REALNAME ;\
    GNUSTACK
#endif

(assuming one does not need to use the GNUSTACK identifier to mark the stack as non-executable with clang - although maybe it would be necessary when expressly using GNU ld for linking)

Thanks for your kind help. I confirm that your modification fixes clang errors.

@martin-frbg
Copy link
Collaborator

Great, thanks for the feedback. That leaves the compilation error in slacon.f, which appears to be an internal error in LLVM18. Maybe this is already fixed in the recently released 19.1 ?

@azuresky01
Copy link
Author

Great, thanks for the feedback. That leaves the compilation error in slacon.f, which appears to be an internal error in LLVM18. Maybe this is already fixed in the recently released 19.1 ?

No. Current flang-new 19.1.1 still fails.

@martin-frbg
Copy link
Collaborator

Thanks, reported to llvm/llvm-project now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants