This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG1042de90589c: [Driver] Add CLANG_DEFAULT_PIE_ON_LINUX to emulate GCC --enable-default-pie (authored by MaskRay).
Changed prior to commit: https://reviews.llvm.org/D113372?vs=394015&id=394301#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D113372/new/ https://reviews.llvm.org/D113372 Files: clang/CMakeLists.txt clang/docs/ReleaseNotes.rst clang/include/clang/Config/config.h.cmake clang/lib/Driver/ToolChains/Linux.cpp clang/test/Driver/fsanitize.c clang/test/Driver/linux-default-pie.c clang/test/Driver/linux-ld.c clang/test/lit.cfg.py clang/test/lit.site.cfg.py.in llvm/utils/gn/secondary/clang/include/clang/Config/BUILD.gn utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h
Index: utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h =================================================================== --- utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h +++ utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h @@ -22,6 +22,9 @@ /* Bug report URL. */ #define BUG_REPORT_URL "https://bugs.llvm.org/" +/* Default to -fPIE and -pie on Linux. */ +#define CLANG_DEFAULT_PIE_ON_LINUX 0 + /* Default linker to use. */ #define CLANG_DEFAULT_LINKER "" Index: llvm/utils/gn/secondary/clang/include/clang/Config/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/clang/include/clang/Config/BUILD.gn +++ llvm/utils/gn/secondary/clang/include/clang/Config/BUILD.gn @@ -9,6 +9,7 @@ output = "$target_gen_dir/config.h" values = [ "BUG_REPORT_URL=https://bugs.llvm.org/", + "CLANG_DEFAULT_PIE_ON_LINUX=0", "CLANG_DEFAULT_LINKER=", "CLANG_DEFAULT_STD_C=", "CLANG_DEFAULT_STD_CXX=", Index: clang/test/lit.site.cfg.py.in =================================================================== --- clang/test/lit.site.cfg.py.in +++ clang/test/lit.site.cfg.py.in @@ -22,6 +22,7 @@ config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@" config.have_zlib = @LLVM_ENABLE_ZLIB@ config.clang_arcmt = @CLANG_ENABLE_ARCMT@ +config.clang_default_pie_on_linux = "@CLANG_DEFAULT_PIE_ON_LINUX@" config.clang_default_cxx_stdlib = "@CLANG_DEFAULT_CXX_STDLIB@" config.clang_staticanalyzer = @CLANG_ENABLE_STATIC_ANALYZER@ config.clang_staticanalyzer_z3 = "@LLVM_WITH_Z3@" Index: clang/test/lit.cfg.py =================================================================== --- clang/test/lit.cfg.py +++ clang/test/lit.cfg.py @@ -121,6 +121,9 @@ if config.has_plugins and config.llvm_plugin_ext: config.available_features.add('plugins') +if config.clang_default_pie_on_linux == '1': + config.available_features.add('default-pie-on-linux') + # Set available features we allow tests to conditionalize on. # if config.clang_default_cxx_stdlib != '': Index: clang/test/Driver/linux-ld.c =================================================================== --- clang/test/Driver/linux-ld.c +++ clang/test/Driver/linux-ld.c @@ -1,4 +1,4 @@ -// UNSUPPORTED: system-windows +// UNSUPPORTED: system-windows, default-pie-on-linux // General tests that ld invocations on Linux targets sane. Note that we use // sysroot to make these tests independent of the host system. // Index: clang/test/Driver/linux-default-pie.c =================================================================== --- /dev/null +++ clang/test/Driver/linux-default-pie.c @@ -0,0 +1,7 @@ +// REQUIRES: default-pie-on-linux +/// Test -DCLANG_DEFAULT_PIE_ON_LINUX=on. + +// RUN: %clang -### --target=aarch64-linux-gnu %s 2>&1 | FileCheck %s --check-prefix=PIE2 + +// PIE2: "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" +// PIE2: "-pie" Index: clang/test/Driver/fsanitize.c =================================================================== --- clang/test/Driver/fsanitize.c +++ clang/test/Driver/fsanitize.c @@ -1,3 +1,4 @@ +// UNSUPPORTED: default-pie-on-linux // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined -fsanitize-trap=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined -fsanitize-trap=undefined -fno-sanitize-trap=signed-integer-overflow %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP2 // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined -fsanitize-undefined-trap-on-error %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP Index: clang/lib/Driver/ToolChains/Linux.cpp =================================================================== --- clang/lib/Driver/ToolChains/Linux.cpp +++ clang/lib/Driver/ToolChains/Linux.cpp @@ -663,8 +663,8 @@ } bool Linux::isPIEDefault(const llvm::opt::ArgList &Args) const { - return getTriple().isAndroid() || getTriple().isMusl() || - getSanitizerArgs(Args).requiresPIE(); + return CLANG_DEFAULT_PIE_ON_LINUX || getTriple().isAndroid() || + getTriple().isMusl() || getSanitizerArgs(Args).requiresPIE(); } bool Linux::IsAArch64OutlineAtomicsDefault(const ArgList &Args) const { Index: clang/include/clang/Config/config.h.cmake =================================================================== --- clang/include/clang/Config/config.h.cmake +++ clang/include/clang/Config/config.h.cmake @@ -8,6 +8,9 @@ /* Bug report URL. */ #define BUG_REPORT_URL "${BUG_REPORT_URL}" +/* Default to -fPIE and -pie on Linux. */ +#cmakedefine01 CLANG_DEFAULT_PIE_ON_LINUX + /* Default linker to use. */ #define CLANG_DEFAULT_LINKER "${CLANG_DEFAULT_LINKER}" Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -249,7 +249,10 @@ Build System Changes -------------------- -- ... +- Linux distros can specify ``-DCLANG_DEFAULT_PIE_ON_LINUX=On`` to use ``-fPIE`` and + ``-pie`` by default. This matches GCC installations on many Linux distros + (configured with ``--enable-default-pie``). + (`D113372 <https://reviews.llvm.org/D113372>`_) AST Matchers ------------ Index: clang/CMakeLists.txt =================================================================== --- clang/CMakeLists.txt +++ clang/CMakeLists.txt @@ -227,6 +227,11 @@ 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) +if(CLANG_DEFAULT_PIE_ON_LINUX) + set(CLANG_DEFAULT_PIE_ON_LINUX 1) +endif() + # TODO: verify the values against LangStandards.def? set(CLANG_DEFAULT_STD_C "" CACHE STRING "Default standard to use for C/ObjC code (IDENT from LangStandards.def, empty for platform default)")
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits