Skip to content

Fortran+C configure test fails when LTO LDFLAGS are specified #12674

Closed
@eli-schwartz

Description

@eli-schwartz

Background information

What version of Open MPI are you using? (e.g., v4.1.6, v5.0.1, git branch name and hash, etc.)

5.0.3 tarball

Describe how Open MPI was installed (e.g., from a source/distribution tarball, from a git clone, from an operating system distribution package, etc.)

Using Gentoo Portage (I am currently working to upgrade Gentoo from openmpi 4.1.6 to 5.0.3).


Details of the problem

I tried to build with the following *FLAGS to optimize the build: -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing

Note the -Werror=* flags are used to help detect cases where the compiler tries to optimize by assuming UB cannot exist in the source code -- if it does exist, ordinarily the code would be miscompiled, and this says to make the miscompilation a fatal error.

I wasn't able to successfully finish ./configure

I got this error:

*** Fortran compiler
checking for x86_64-pc-linux-gnu-gfortran... x86_64-pc-linux-gnu-gfortran
checking whether the compiler supports GNU Fortran... yes
checking whether x86_64-pc-linux-gnu-gfortran accepts -g... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/x86_64-pc-linux-gnu-nm -B
checking the name lister (/usr/bin/x86_64-pc-linux-gnu-nm -B) interface... BSD nm
configure: WARNING: Open MPI now ignores the F77 and FFLAGS environment variables; only the FC and FCFLAGS environment variables are used.
checking whether ln -s works... yes
checking if Fortran compiler works... yes
checking for extra arguments to build a shared library... none needed
checking for x86_64-pc-linux-gnu-gfortran warnings flags... none
checking for Fortran flag to compile .f files... none
checking for Fortran flag to compile .f90 files... none
checking if Fortran compilers preprocess .F90 files without additional flag... yes
checking to see if Fortran compilers need additional linker flags... none
checking  external symbol convention... single underscore
checking if C and Fortran are link compatible... no
**********************************************************************
It appears that your Fortran compiler is unable to link against
object files created by your C compiler.  This typically indicates
one of a few possibilities:

  - A conflict between CFLAGS and FCFLAGS
  - A problem with your compiler installation(s)
  - Different default build options between compilers (e.g., C
    building for 32 bit and Fortran building for 64 bit)
  - Incompatible compilers

Such problems can usually be solved by picking compatible compilers
and/or CFLAGS and FCFLAGS.  More information (including exactly what
command was given to the compilers and what error resulted when the
commands were executed) is available in the config.log file in this
directory.
**********************************************************************
configure: error: C and Fortran compilers are not link compatible.  Can not continue.

Here is the relevant snippet from config.log:

configure:30053: checking if C and Fortran are link compatible
configure:30099: x86_64-pc-linux-gnu-gcc -c -DNDEBUG -pipe -march=native -fstack-protector-all -O2 -fdiagnostics-color=always -frecord-gcc-switches -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-al
iasing  -Wformat -Werror=format-security -Werror=implicit-function-declaration -Werror=implicit-int -Werror=int-conversion -Werror=incompatible-pointer-types -finline-functions  conftest_c.c
configure:30102: $? = 0
configure:30120: x86_64-pc-linux-gnu-gfortran -o conftest -pipe -march=native -fstack-protector-all -O2 -fdiagnostics-color=always -frecord-gcc-switches -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=stri
ct-aliasing -Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wl,--defsym=__gentoo_check_ldflags__=0  conftest.f90 conftest_c.o  >&5
conftest.f90:4:23: error: type of 'testfunc' does not match original declaration [-Werror=lto-type-mismatch]
    4 |        call testfunc(1)
      |                       ^
conftest_c.c:2:5: note: return value type mismatch
    2 | int testfunc_(int a) { return a; }
      |     ^
conftest_c.c:2:5: note: type 'int' should match type 'void'
conftest_c.c:2:5: note: 'testfunc_' was previously declared here
lto1: some warnings being treated as errors
lto-wrapper: fatal error: x86_64-pc-linux-gnu-gfortran returned 1 exit status
compilation terminated.
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
configure:30120: $? = 1
configure: failed program was:
|       program main
| 
|        external testfunc
|        call testfunc(1)
| 
|       end
configure:30147: result: no
configure:30173: error: C and Fortran compilers are not link compatible.  Can not continue.

Full build log: openmpi-5.0.3:20240711-181726.log
Contents of autotools' config.log: config.log

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions