How LLVM is built without default PIE? I tried CLANG_DEFAULT_PIE_ON_LINUX=OFF but it builds them again as shared libraries no binaries to distinguishe them from libraries. There is no option for no PIE for LLVM tools. New PIE build may stop the build for old versions of libraries and tools which are incompatibel with PIE.How can be built LLVM and clang and the other LLVM project as PIE but keep them as binaries.
CLANG_DEFAULT_PIE_ON_LINUX is about whether the Clang binary that you build will default to itself creating PIEs when using a Linux target triple, it has nothing to do with whether or not the Clang (or other LLVM binaries) will themselves be PIEs. If you want to change that, mess with CMAKE_C(XX)_FLAGS, CMAKE_EXE_LINKER_FLAGS and similar as desired just like any other CMake project.
Clang 14 defaults to PIE OFF, when clang 15 changes it to PIE ON. And if it is optional, it is not included in the build instructions at Building LLVM with CMake — LLVM 16.0.0git documentation. One has to rebuild it to find out what is going on. And how do you distinguish visually executables from shared libraries. With PIE ON, everything appears as shared libraries.
The change was introduced here:
https://reviews.llvm.org/D120305
PIE is a cmake option and not LLVM specific:
https://cmake.org/cmake/help/latest/variable/CMAKE_POSITION_INDEPENDENT_CODE.html
And it is in the official release notes for LLVM 15:
https://releases.llvm.org/15.0.0/tools/clang/docs/ReleaseNotes.html#build-system-changes
Yes, it is in the release of Clang only but not in the build instructions of whole LLVM project. And it is a significant change in the build of LLVM too not only clang. PIE was off and then on and no change in the build page. It affects not only clang but also LLVM tools utils and the project. tschuett I tried dynamic with PIC and it crashes in a real mess. Static with PIC is good but the build size becomes huge around 3 GB. As to PIE, it is good as far as it wont change the look of the executables. Or better, it is up to user’s preference to build it with pie or no as jrtc27 has mentioned in the flags is good and one may use the compiler. So this build configuration of LLVM with CLANG_DEFAULT_PIE_ON_LINUX is good and one can simply disable it and then for LLVM may be suggested either. E.g. LLVM_DEFAULT_PIE_ON_LINUX or something like that and the user will build it with ON or NO.
You still seem confused. Are you talking about whether Clang itself is PIE, or whether when you use Clang to compile other third-party software it produces PIEs? CLANG_DEFAULT_PIE_ON_LINUX affects the latter, it has absolutely nothing to do with the former, which, by default, is, and has been for a long time, decided by your existing compiler, not the Clang you’re building.
CLANG_DEFAULT_PIE_ON_LINUX
is a decision/policy of the LLVM community. As I noted above there is a CMake and not LLVM specific option to choose position independent code or not. Thus it does not belong into the LLVM build instructions.
You can build LLVM and Clang with clang or with gcc as you know.well. Well, both ways I disable PIE since it makes shared libraries and not exetubales. There are more than 100 binaries in LLVM not only clang and they ara marked as shared libraries. I dont mind PIE as far as this issue is cleared and they become again binaries as before since i cannot distingush them from the shared libraries in the lib folder for instance.
I mean, they can be distinguished, they’ll have a .interp section / PT_INTERP segment and, if built with a recent toolchain, will have DF_1_PIE set in DT_FLAGS_1. Not sure at this point what you want from us, we’ve answered the question.
No thats not truth. jrtc27 then why is kept PIE off until LLVM 15? I need to be kept in the future so I have the choice of selecting PIE OFF or PIE ON and I can build sources which can run without PIE too and are compatible with no pie. I am not familiar with whole LLVM source so that I can look for it where I should turn it off or on. If I need PIE ON in building sources I will simply select in the flags, But LLVM is huge and I just need the working compiler without default PIE. If somebode else need it, then will build it enabled.
Your question is still unclear to me. If you want to build llvm-project executables as position-dependent executables (aka not PIE), use -DLLVM_ENABLE_PIC=off -DCMAKE_{C,CXX}_FLAGS=-fno-pic -DCMAKE_EXE_LINKER_FLAGS=-no-pie
.
AIUI most Linux distrbituions have changed their GCC to default to -fPIE/-pie
, so you’ll need explicit options to turn off that.
llvm-project enables -DLLVM_ENABLE_PIC=on
(it should migrate to CMAKE_POSITION_INDEPENDENT_CODE
) so -DLLVM_ENABLE_PIC=off
is needed to turn off that.
But I don’t think many people use -DLLVM_ENABLE_PIC=off
, so there may be some strange things in the build system.
Most *NIX OSes have migrated to position-independent code by default.
On Linux there remains some customization, hence the existence of the CMake variable CLANG_DEFAULT_PIE_ON_LINUX
.
If you want to build a Clang which doesn’t defaults to -fPIE/-pie
for *-linux-gnu
triples, specify -DCLANG_DEFAULT_PIE_ON_LINUX=off
.
The variable will remain for a long time and it is not much overhead to support it. Some groups are still using it.
MaskRay I built LLVM 14 with -DLLVM_ENABLE_PIC=on
-DCLANG_DEFAULT_PIE_ON_LINUX=OFF (default) and no problem. I havent even known that is off. Everything builds right. Now with LLVM 15 I havent changed it -DLLVM_ENABLE_PIC=on but
-DCLANG_DEFAULT_PIE_ON_LINUX=ON (default) and surprise the bin folder has shared libraries. Im pessimistic about PIE since I tried it with PIE-default GCC and it builds the binutils with a lot of errors in tests. Hope you understand this point. My request is to be kept the PIE choice in the future so we can easily enable or disable it. No-default is better since I can change it to PIE when building other sources. It is a new feature and when default is not switched off it may crash and waste time finding what is on. What do you mean about CMAKE_POSITION_INDEPENDENT_CODE? I tried it ON and -DLLVM_ENABLE_PIC=on and -DCLANG_DEFAULT_PIE_ON_LINUX=off but the build needs system libraries lc, lm and crashes at the beginning.
No problem if I enter only -DLLVM_ENABLE_PIC=on.
So please do not make these changes. It is wonderful as it was in 14.
Again, CLANG_DEFAULT_PIE_ON_LINUX does not affect whether bin/clang is a PIE or not. It affects whether bin/clang produces PIEs or not by default. So I do not know what you’re doing and what you’re seeing but what you’re saying is not correct, so there’s at least some crucial piece of information is missing. I suggest you post the exact commands you are running to build Clang, the exact files you are seeing change between PDE and PIE, and the exact commands you are using to determine that. Otherwise we’re just going to keep repeating the same things at you, eventually get frustrated and stop trying to help you.
jrtc27 I upgrade Clang 14 by building Clang 15. All the binaries become shared libraries.
In 16 If I try to configure a standalone libc++ with -fpic, cmake warns thar -fpic is not supported. If I configure it with building llvm and libc++ and -DLLVM_ENABLE_PIC=on, the cmake warning disappears