<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/57996>57996</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang 15] Impossible to disable the new default PIE mode on Linux with -fno-pic -fno-PIC -fno-pie -fno-PIE
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Romain-Geissler-1A
</td>
</tr>
</table>
<pre>
Hi,
It seems clang 15 enabled `CLANG_DEFAULT_PIE_ON_LINUX=ON` by default, and I have no problem with that. However it seems it's much more than a default, it's also not reversible at all once clang has been compiled.
Just try to compile this snippet:
```
#include <iostream>
int main()
{
std::cout << "some text" << std::endl;
}
```
with the following options: `-fno-pic -fno-PIC -fno-pie -fno-PIE -fuse-ld=lld` and you will end up with errors like:
```
ld.lld: error: relocation R_X86_64_64 cannot be used against local symbol; recompile with -fPIC
>>> defined in /tmp/example-a1ec20.o
>>> referenced by example.cpp:5
>>> /tmp/example-a1ec20.o:(main)
ld.lld: error: relocation R_X86_64_64 cannot be used against local symbol; recompile with -fPIC
>>> defined in /tmp/example-a1ec20.o
>>> referenced by iostream:74 (/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/iostream:74)
>>> /tmp/example-a1ec20.o:(__cxx_global_var_init)
ld.lld: error: relocation R_X86_64_64 cannot be used against local symbol; recompile with -fPIC
>>> defined in /tmp/example-a1ec20.o
>>> referenced by example.cpp:0
>>> /tmp/example-a1ec20.o:(__cxx_global_var_init)
ld.lld: error: cannot preempt symbol: __dso_handle
>>> defined in /opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/crtbeginS.o
>>> referenced by example.cpp:0
>>> /tmp/example-a1ec20.o:(__cxx_global_var_init)
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
ASM generation compiler returned: 1
ld.lld: error: relocation R_X86_64_64 cannot be used against local symbol; recompile with -fPIC
>>> defined in /tmp/example-653928.o
>>> referenced by example.cpp:5
>>> /tmp/example-653928.o:(main)
ld.lld: error: relocation R_X86_64_64 cannot be used against local symbol; recompile with -fPIC
>>> defined in /tmp/example-653928.o
>>> referenced by iostream:74 (/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/iostream:74)
>>> /tmp/example-653928.o:(__cxx_global_var_init)
ld.lld: error: relocation R_X86_64_64 cannot be used against local symbol; recompile with -fPIC
>>> defined in /tmp/example-653928.o
>>> referenced by example.cpp:0
>>> /tmp/example-653928.o:(__cxx_global_var_init)
ld.lld: error: cannot preempt symbol: __dso_handle
>>> defined in /opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/crtbeginS.o
>>> referenced by example.cpp:0
>>> /tmp/example-653928.o:(__cxx_global_var_init)
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
Execution build compiler returned: 1
```
Note: the above example was taken from this godbolt example: https://godbolt.org/z/aT6xGah4e
I don't understand why this default PIE mode is not something you can control from the commande line.
Cheers,
Romain
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzlV1lv2zgQ_jXyy0CCJfl88IMTJ6kX2bToAfRNoKSRzS1FCiTlY3_9DnU4dtrNbosW23QNmqao4RzfDGc8qcqPi1fci6694cobLtt5bcEglgYyweQGwjGgZKnAHLzJ8Pp--XCXrG5ulx_u3ydv1jfJ64fkfv3w4aMXr14_EAWkR8ixYLWwxBiYzGENW7ZDkAoqrYhTCXtut2C3zAbwSu1xhxp4L5bTuamBss62UCqNjk4CO2fakTBhFHG1oB0Hw4k1MEvbApTMsDNgywykiBIyVVac7AjOrf2tNhasPoJVPQEJ5AaM5FWF1ouX5-RkYDfaxyjmMhN1juDF11wZq5GVXnxzfoZLCyXj0otmXjTv3kyv2gXQx9jciYmXmaqtY0QDvCgyq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