Skip to content

[Flang] .mod files built into include/flang/ do not support multiple target architectures #158790

@s-watanabe314

Description

@s-watanabe314

When Flang is built with multiple target architectures specified for -DLLVM_TARGETS_TO_BUILD, .mod files are created only for the default target architecture and not for other architectures.

This becomes a problem, for example, when building on an X86_64 machine targeting both X86_64 and AArch64.

  • CMake configuration:
cmake \
  -G Ninja \
  -DCMAKE_INSTALL_PREFIX=/<install_dir> \
  -DCMAKE_BUILD_TYPE=Release \
  -DLLVM_ENABLE_PROJECTS="clang;mlir;flang" \
  -DLLVM_TARGETS_TO_BUILD="AArch64;X86" \
  -DLLVM_DEFAULT_TARGET_TRIPLE="x86_64-unknown-linux-gnu" \
  /<llvm_dir>/llvm-project/llvm

In this case, .mod files are likely built by this command, but since no target architecture is specified, they seem to be built only for the default X86_64. This leads to cross-compilation failures like the following:

  • foo.f90:
program main
  use, intrinsic :: IEEE_ARITHMETIC
  implicit none
end program
  • Compilation error:
$ flang --target=aarch64-unknown-linux-gnu --sysroot=<GCC_TOOLCHAIN_DIR>/libc --gcc-toolchain=<GCC_TOOLCHAIN_DIR> foo.f90 -c -o x86_to_aarch.o

error: Semantic errors in foo.f90
/<install_dir>/bin/../include/flang/ieee_arithmetic.mod:143:1: error: REAL(KIND=10) is not an enabled type for this target
  real(10),intent(in)::x
  ^^^^^^^^^^^^^^^^^^^^^^
/<install_dir>/bin/../include/flang/ieee_arithmetic.mod:183:1: error: REAL(KIND=10) is not an enabled type for this target
  real(10),intent(in)::y
  ^^^^^^^^^^^^^^^^^^^^^^
/<install_dir>/bin/../include/flang/ieee_arithmetic.mod:223:1: error: REAL(KIND=10) is not an enabled type for this target
  real(10),intent(in)::y
  ^^^^^^^^^^^^^^^^^^^^^^
...

This error seems to occur because ieee_arithmetic.mod is built for X86_64 with REAL(KIND=10) included, and then compiled for AArch64. A similar issue was also reported in #146876.

Other modules also contain values that differ from the target architecture because they are built for X86_64. We have confirmed the following:

  • iso_c_binding.mod
    • Built natively for AArch64
      • integer(4),parameter::c_long_double=16_4
    • Built on X86_64 with -DLLVM_TARGETS_TO_BUILD="AArch64;X86"
      • integer(4),parameter::c_long_double=10_4
  • iso_fortran_env_impl.mod
    • Built natively for AArch64
      • integer(4),parameter::__builtin_real_kinds(1_8:*)=[INTEGER(4)::2_4,3_4,4_4,8_4,16_4]
    • Built on X86_64 with -DLLVM_TARGETS_TO_BUILD="AArch64;X86"
      • integer(4),parameter::__builtin_real_kinds(1_8:*)=[INTEGER(4)::2_4,3_4,4_4,8_4,10_4]

To resolve this, it might be necessary to change the build process to create all .mod files for each target architecture and then select the appropriate .mod file during compilation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    build-problemflangFlang issues not falling into any other category

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions