jiangyi created this revision.
Herald added subscribers: cfe-commits, mstorsjo, aheejin, jgravelle-google,
sbc100, mgorny, dschuff, emaste.
Herald added a project: clang.
GCC 6 added the --enable-defaut-pie flag, which would provide better security
with ASLR enabled.
--enable-defaut-pie is enabled by default in many linux distros such as Alpine,
Arch, Debian, Fedora, Gentoo, OpenSUSE, Ubuntu...
Add a cmake option CLANG_ENABLE_DEFAULT_PIE to support the same functionality
for clang.
A pre-processor macro is placed at clang/Driver/ToolChain.h to conditionally
make isPIEDefault() a non-virtual function. By doing so, future subclasses of
clang::driver::ToolChain will not accidentally override isPIEDefault() while
not taking into account of CLANG_ENABLE_DEFAULT_PIE.
Repository:
rC Clang
https://reviews.llvm.org/D60186
Files:
CMakeLists.txt
include/clang/Config/config.h.cmake
include/clang/Driver/ToolChain.h
lib/Driver/Driver.cpp
lib/Driver/ToolChain.cpp
lib/Driver/ToolChains/BareMetal.h
lib/Driver/ToolChains/CloudABI.cpp
lib/Driver/ToolChains/CloudABI.h
lib/Driver/ToolChains/CommonArgs.cpp
lib/Driver/ToolChains/CrossWindows.cpp
lib/Driver/ToolChains/CrossWindows.h
lib/Driver/ToolChains/Cuda.cpp
lib/Driver/ToolChains/Cuda.h
lib/Driver/ToolChains/Darwin.cpp
lib/Driver/ToolChains/Darwin.h
lib/Driver/ToolChains/FreeBSD.cpp
lib/Driver/ToolChains/FreeBSD.h
lib/Driver/ToolChains/Fuchsia.cpp
lib/Driver/ToolChains/Fuchsia.h
lib/Driver/ToolChains/Gnu.cpp
lib/Driver/ToolChains/Gnu.h
lib/Driver/ToolChains/HIP.h
lib/Driver/ToolChains/Haiku.h
lib/Driver/ToolChains/Hurd.cpp
lib/Driver/ToolChains/Linux.cpp
lib/Driver/ToolChains/Linux.h
lib/Driver/ToolChains/MSP430.h
lib/Driver/ToolChains/MSVC.cpp
lib/Driver/ToolChains/MSVC.h
lib/Driver/ToolChains/MinGW.cpp
lib/Driver/ToolChains/MinGW.h
lib/Driver/ToolChains/OpenBSD.h
lib/Driver/ToolChains/Solaris.cpp
lib/Driver/ToolChains/TCE.cpp
lib/Driver/ToolChains/TCE.h
lib/Driver/ToolChains/WebAssembly.cpp
lib/Driver/ToolChains/WebAssembly.h
lib/Driver/ToolChains/XCore.cpp
lib/Driver/ToolChains/XCore.h
lib/Frontend/CompilerInvocation.cpp
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -25,7 +25,6 @@
#include "clang/Basic/Version.h"
#include "clang/Basic/Visibility.h"
#include "clang/Basic/XRayInstr.h"
-#include "clang/Config/config.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/DriverDiagnostic.h"
#include "clang/Driver/Options.h"
Index: lib/Driver/ToolChains/XCore.h
===
--- lib/Driver/ToolChains/XCore.h
+++ lib/Driver/ToolChains/XCore.h
@@ -58,7 +58,9 @@
public:
bool isPICDefault() const override;
- bool isPIEDefault() const override;
+#if !CLANG_ENABLE_DEFAULT_PIE
+ bool isPIEDefault() const override { return false; }
+#endif
bool isPICDefaultForced() const override;
bool SupportsProfiling() const override;
bool hasBlocksRuntime() const override;
Index: lib/Driver/ToolChains/XCore.cpp
===
--- lib/Driver/ToolChains/XCore.cpp
+++ lib/Driver/ToolChains/XCore.cpp
@@ -100,8 +100,6 @@
bool XCoreToolChain::isPICDefault() const { return false; }
-bool XCoreToolChain::isPIEDefault() const { return false; }
-
bool XCoreToolChain::isPICDefaultForced() const { return false; }
bool XCoreToolChain::SupportsProfiling() const { return false; }
Index: lib/Driver/ToolChains/WebAssembly.h
===
--- lib/Driver/ToolChains/WebAssembly.h
+++ lib/Driver/ToolChains/WebAssembly.h
@@ -45,7 +45,9 @@
bool IsObjCNonFragileABIDefault() const override;
bool UseObjCMixedDispatch() const override;
bool isPICDefault() const override;
- bool isPIEDefault() const override;
+#if !CLANG_ENABLE_DEFAULT_PIE
+ bool isPIEDefault() const override { return false; }
+#endif
bool isPICDefaultForced() const override;
bool IsIntegratedAssemblerDefault() const override;
bool hasBlocksRuntime() const override;
Index: lib/Driver/ToolChains/WebAssembly.cpp
===
--- lib/Driver/ToolChains/WebAssembly.cpp
+++ lib/Driver/ToolChains/WebAssembly.cpp
@@ -127,8 +127,6 @@
bool WebAssembly::isPICDefault() const { return false; }
-bool WebAssembly::isPIEDefault() const { return false; }
-
bool WebAssembly::isPICDefaultForced() const { return false; }
bool WebAssembly::IsIntegratedAssemblerDefault() const { return true; }
Index: lib/Driver/ToolChains/TCE.h
===
--- lib/Driver/ToolChains/TCE.h
+++ lib/Driver/ToolChains/TCE.h
@@ -27,7 +27,9 @@
bool IsMathErrnoDefault() const override;
bool isPICDefault() const override;
-