[clang][flang] Disable defaulting to `-fpie` for LLVM Flang
authorAndrzej Warzynski <andrzej.warzynski@arm.com>
Wed, 22 Jun 2022 10:29:57 +0000 (10:29 +0000)
committerAndrzej Warzynski <andrzej.warzynski@arm.com>
Wed, 29 Jun 2022 07:53:06 +0000 (07:53 +0000)
commitb405407a489902c0acfcf936bfda9821a1deb170
treedcd0c43e30f2e6675909fefbfe5263468fa936c1
parent3d9ce9e43d07bbd3ab5c25ee36f417e3d372b94b
[clang][flang] Disable defaulting to `-fpie` for LLVM Flang

In, https://reviews.llvm.org/D120305, CLANG_DEFAULT_PIE_ON_LINUX was set
to `On` by default. However, neither `-fpie` nor `-fpic` are currently
supported in LLVM Flang. Hence, in this patch the behaviour controlled
with CLANG_DEFAULT_PIE_ON_LINUX is refined not to apply to Flang.

Another way to look at this is that CLANG_DEFAULT_PIE_ON_LINUX is
currently affecting both Clang and Flang. IIUC, the intention for this
CMake variable has always been to only affect Clang. This patch makes
sure that that's the case.

Without this change, you might see errors like this on X86_64:
```
/usr/bin/ld: main.o: relocation R_X86_64_32 against `.bss' can not be used when making a PIE object; recompile with -fPIC
```
I've not experienced any issues on AArch64. That's probably because on
AArch64 some object files happen to be position independent without
needing -fpie or -fpic.

Differential Revision: https://reviews.llvm.org/D128333
clang/lib/Driver/ToolChains/Linux.cpp
flang/docs/ReleaseNotes.md
flang/test/Driver/pic-flags.f90 [new file with mode: 0644]