Skip to content

Mixing clang++ with gfortran: relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object

When mixing clang++ 15 with gfortran one gets the following linking error:

Scanning dependencies of target hello
Consolidate compiler generated dependencies of target hello
[ 33%] Linking CXX executable hello
/usr/bin/ld: CMakeFiles/hello.dir/hello.f90.o: relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: failed to set dynamic section sizes: bad value
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [CMakeFiles/hello.dir/build.make:112: hello] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/hello.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

To reproduce this on a fedora:rawhide container, use the following CMakeLists.txt:

cmake_minimum_required(VERSION 3.24)
project(dummy LANGUAGES CXX Fortran)
add_executable(hello hello.f90 tools.cpp)

with hello.f90 being

program hello
  print *, 'Hello, World!'
end program hello

and tools.cpp being:

int yes() {
  return 0;
}

and running CXX=clang++ FC=gfortran cmake .. .

See https://github.com/kokkos/ci-containers/pull/28 for details.

Edited by Christoph Junghans
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information