Hide Forgot
Have a file 'hello.f90': program hello print *, 'Hello, World!' end program hello and a file 'tools.cpp': int yes() { return 0; } Building them into one executable leads to a linking error: $ clang++ -c tools.cpp -o tools.o $ gfortran -c hello.f90 -o hello.o $ clang++ -o hello tools.o hello.o -lgfortran /usr/bin/ld: hello.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 Originally I found this in https://github.com/kokkos/ci-containers/pull/28 and filed a CMake issue here: https://gitlab.kitware.com/cmake/cmake/-/issues/24051 but CMake's Brad King found that the underlying issue is that gfortran wasn't compiled with "--enable-default-pie". In F36 the above example works with errors.
This is a user error. If you want to make a PIE, you should request it explicitly (so link with -pie).
No, this is an inconsistency between GCC and Clang that needs to be fixed. Either both should default to PIE, nor neither should.
I agree with Florian, we should make this consistent. Or patch CMake to take care of it.
GCC is intentionally not configured with --enable-default-pie or similar significant behavior changing options by default, because then users simply have no idea what the compiler will do, they can't rely on anything and so if they care, they need to disable or enable all these options explicitly. While if the default isn't changing, they can rely on it, it isn't a moving target. It is like all of sudden changing the default to be -O2 instead of -O0... So not a GCC bug.
Why did it work on F36? Did the clang default change?
Most likely. Note, not having -fpie for compiling and -pie for linking by default doesn't mean Fedora isn't built with PIE, the options are added explicitly in %{optflags} etc.
Yes, clang's default changed to ON: https://releases.llvm.org/15.0.0/tools/clang/docs/ReleaseNotes.html#build-system-changes and we don't set that option in the spec file.
> Note, not having -fpie for compiling and -pie for linking by default doesn't mean Fedora isn't built with PIE, the options are added explicitly in %{optflags} etc. This is true for GCC, but for clang only -fPIE gets added to CFLAGS, but not -pie to LDFLAGS (https://bugzilla.redhat.com/show_bug.cgi?id=2084460). I'm not really clear on why this is the case though. The situation here is somewhat ugly because gcc and clang now have different upstream defaults (the bug for changing gcc defaults is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103398, which makes the incorrect claim that Fedora already enables this by default -- I guess there is confusion there between enabling something for RPM packages, and enabling it for end users). But anyway, given that GCC is the primary toolchain for Fedora, we should follow whatever it does, so I've put up https://src.fedoraproject.org/rpms/clang/pull-request/183.
FEDORA-2022-7011f92b71 has been submitted as an update to Fedora 38. https://bodhi.fedoraproject.org/updates/FEDORA-2022-7011f92b71
FEDORA-2022-7011f92b71 has been pushed to the Fedora 38 stable repository. If problem still persists, please make note of it in this bug report.
Update for f37: https://bodhi.fedoraproject.org/updates/FEDORA-2022-9dcdd39f09