From 3c4ed02698afec021c6bca80740d1e58e3ee019e Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 25 Feb 2022 00:22:12 +0000 Subject: [PATCH] [Driver] Default CLANG_DEFAULT_PIE_ON_LINUX to ON Default the option introduced in D113372 to ON to match all(?) major Linux distros. This matches GCC and improves consistency with Android and linux-musl which always default to PIE. Note: CLANG_DEFAULT_PIE_ON_LINUX will be removed in the future. Reviewed By: thesamesam Differential Revision: https://reviews.llvm.org/D120305 --- clang/CMakeLists.txt | 2 +- clang/docs/ReleaseNotes.rst | 6 ++++++ clang/test/Driver/hip-fpie-option.hip | 7 +++---- .../utils/gn/secondary/clang/include/clang/Config/BUILD.gn | 2 +- .../clang/include/clang/Config/config.h | 2 +- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt index 937a8467df1d..813df14b7af3 100644 --- a/clang/CMakeLists.txt +++ b/clang/CMakeLists.txt @@ -245,7 +245,7 @@ set(PPC_LINUX_DEFAULT_IEEELONGDOUBLE OFF CACHE BOOL set(CLANG_SPAWN_CC1 OFF CACHE BOOL "Whether clang should use a new process for the CC1 invocation") -option(CLANG_DEFAULT_PIE_ON_LINUX "Default to -fPIE and -pie on Linux" OFF) +option(CLANG_DEFAULT_PIE_ON_LINUX "Default to -fPIE and -pie on linux-gnu" ON) # TODO: verify the values against LangStandards.def? set(CLANG_DEFAULT_STD_C "" CACHE STRING diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 4131c022f594..d1456ee4ffd6 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -183,6 +183,12 @@ Internal API Changes Build System Changes -------------------- +* CMake ``-DCLANG_DEFAULT_PIE_ON_LINUX=ON`` is now the default. This is used by + linux-gnu systems to decide whether ``-fPIE -pie`` is the default (instead of + ``-fno-pic -no-pie``). This matches GCC installations on many Linux distros. + Note: linux-android and linux-musl always default to ``-fPIE -pie``, ignoring + this variable. ``-DCLANG_DEFAULT_PIE_ON_LINUX`` will be removed in the future. + AST Matchers ------------ diff --git a/clang/test/Driver/hip-fpie-option.hip b/clang/test/Driver/hip-fpie-option.hip index 2e296a099dea..ffd639dd5a6d 100644 --- a/clang/test/Driver/hip-fpie-option.hip +++ b/clang/test/Driver/hip-fpie-option.hip @@ -1,15 +1,15 @@ -// REQUIRES: clang-driver, amdgpu-registered-target +// REQUIRES: clang-driver, amdgpu-registered-target, default-pie-on-linux // -fPIC and -fPIE only affects host relocation model. // device compilation always uses PIC. // RUN: %clang -### -target x86_64-unknown-linux-gnu \ // RUN: --offload-arch=gfx906 %s -nogpulib -nogpuinc \ -// RUN: 2>&1 | FileCheck -check-prefixes=DEV,HOST-STATIC %s +// RUN: 2>&1 | FileCheck -check-prefixes=DEV,HOST-PIE %s // RUN: %clang -### -target x86_64-unknown-linux-gnu \ // RUN: -fgpu-rdc --offload-arch=gfx906 %s -nogpulib -nogpuinc \ -// RUN: 2>&1 | FileCheck -check-prefixes=DEV,HOST-STATIC %s +// RUN: 2>&1 | FileCheck -check-prefixes=DEV,HOST-PIE %s // RUN: %clang -### -target x86_64-unknown-linux-gnu \ // RUN: --offload-arch=gfx906 %s -nogpulib -nogpuinc \ @@ -32,7 +32,6 @@ // RUN: 2>&1 | FileCheck -check-prefixes=DEV,HOST-PIE %s // DEV-DAG: {{".*clang.*".* "-triple" "amdgcn-amd-amdhsa".* "-mrelocation-model" "pic" "-pic-level" "[1|2]".* "-mframe-pointer=all"}} -// HOST-STATIC-DAG: {{".*clang.*".* "-triple" "x86_64-unknown-linux-gnu".* "-mrelocation-model" "static"}} // HOST-PIC-DAG: {{".*clang.*".* "-triple" "x86_64-unknown-linux-gnu".* "-mrelocation-model" "pic" "-pic-level" "2"}} // HOST-PIC-NOT: "-pic-is-pie" // HOST-PIE-DAG: {{".*clang.*".* "-triple" "x86_64-unknown-linux-gnu".* "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie"}} diff --git a/llvm/utils/gn/secondary/clang/include/clang/Config/BUILD.gn b/llvm/utils/gn/secondary/clang/include/clang/Config/BUILD.gn index a10e45cecac1..c1e5775db8dc 100644 --- a/llvm/utils/gn/secondary/clang/include/clang/Config/BUILD.gn +++ b/llvm/utils/gn/secondary/clang/include/clang/Config/BUILD.gn @@ -9,7 +9,7 @@ write_cmake_config("Config") { output = "$target_gen_dir/config.h" values = [ "BUG_REPORT_URL=https://github.com/llvm/llvm-project/issues/", - "CLANG_DEFAULT_PIE_ON_LINUX=", + "CLANG_DEFAULT_PIE_ON_LINUX=1", "CLANG_DEFAULT_LINKER=", "CLANG_DEFAULT_STD_C=", "CLANG_DEFAULT_STD_CXX=", diff --git a/utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h b/utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h index ccf47729f3ad..5bcded19c8c3 100644 --- a/utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h +++ b/utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h @@ -23,7 +23,7 @@ #define BUG_REPORT_URL "https://github.com/llvm/llvm-project/issues/" /* Default to -fPIE and -pie on Linux. */ -#define CLANG_DEFAULT_PIE_ON_LINUX 0 +#define CLANG_DEFAULT_PIE_ON_LINUX 1 /* Default linker to use. */ #define CLANG_DEFAULT_LINKER ""