Recently @MaskRay committed a patch (⚙ D120305 [Driver] Default CLANG_DEFAULT_PIE_ON_LINUX to ON) to change the default value for CLANG_DEFAULT_PIE_ON_LINUX to “ON”. This caused some test failures in a couple of downstream projects I work on. While it’s easy enough for these projects to explicitly keep the old default value (for now, at least), it seems like a change of this nature requires more discussion than just what happens in a typical code review.
This was previous brought up here (PIE/PIC Clang Defaults on Linux x86-64), but it doesn’t seem like a consensus was reached.
The change caused a number of buildbot failures, and while I believe these have all since been sorted out, I suspect they are indicative of the kinds of problems that users are going to encounter when this change reaches them. For anyone who was building clang without explicitly setting CLANG_DEFAULT_PIE_ON_LINUX, this change introduces potential compatibility issues with previously compiled object files and static libraries.
The motivation for the change seems to hinge on two points:
- Compatibility with GCC default behavior
- Consistency with major distribution of Linux
With regard to the first point, this is a bit ambiguous. GCC, like clang, controls its default through a configuration option used when building the compiler. If the option is not explicitly specified, it does not enable PIE by default. A change was proposed, but it seems not to have been accepted (103398 – configure: Enable --enable-default-pie by default for Linux).
However, the second point is strongly connected to the first. The claim (I haven’t investigated this extensively) is that many, perhaps most, major distributions do explicitly use the option to make PIE the default in the build of GCC that is part of the distribution. I’d like to see more data. I know there are distributions that are not using this default. I’d also like input from someone affiliated with any of the distributions that don’t use the new default.
I’m sympathetic to Fangrui’s argument that the mere existence of this option in GCC and clang leads to unnecessary confusion and inconsistency, but I’m not sure that the recent change does much to help eliminate that problem and may, in fact, make it worse.
Finally, I’m concerned by this statement in the description of the change: “Note: CLANG_DEFAULT_PIE_ON_LINUX will be removed in the future.” That would make it more difficult for my downstream projects to maintain their current behavior.