Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions libcxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ if (NOT "${LIBCXX_HARDENING_MODE}" IN_LIST LIBCXX_SUPPORTED_HARDENING_MODES)
message(FATAL_ERROR
"Unsupported hardening mode: '${LIBCXX_HARDENING_MODE}'. Supported values are ${LIBCXX_SUPPORTED_HARDENING_MODES}.")
endif()
set(LIBCXX_SUPPORTED_PFP none untagged tagged)
set(LIBCXX_PFP none CACHE STRING
"Specify whether to build with pointer field protection.
Supported values are ${LIBCXX_SUPPORTED_PFP}.")
if (NOT "${LIBCXX_PFP}" IN_LIST LIBCXX_SUPPORTED_PFP)
message(FATAL_ERROR
"Unsupported PFP mode: '${LIBCXX_PFP}'. Supported values are ${LIBCXX_SUPPORTED_PFP}.")
endif()
set(LIBCXX_ASSERTION_HANDLER_FILE
"vendor/llvm/default_assertion_handler.in"
CACHE STRING
Expand Down Expand Up @@ -563,6 +571,17 @@ function(cxx_add_rtti_flags target)
endif()
endfunction()

function(cxx_add_pfp_flags target)
if (LIBCXX_PFP STREQUAL untagged)
target_add_compile_flags_if_supported(${target} PUBLIC
-fexperimental-pointer-field-protection)
elseif (LIBCXX_PFP STREQUAL tagged)
target_add_compile_flags_if_supported(${target} PUBLIC
-fexperimental-pointer-field-protection
-fexperimental-pointer-field-protection-tagged)
endif()
endfunction()

# Modules flags ===============================================================
# FIXME The libc++ sources are fundamentally non-modular. They need special
# versions of the headers in order to provide C++03 and legacy ABI definitions.
Expand Down Expand Up @@ -819,6 +838,7 @@ function(cxx_add_common_build_flags target)
cxx_add_windows_flags(${target})
cxx_add_exception_flags(${target})
cxx_add_rtti_flags(${target})
cxx_add_pfp_flags(${target})
cxx_add_module_flags(${target})
cxx_link_system_libraries(${target})
target_link_libraries(${target} PRIVATE cxx-sanitizer-flags)
Expand Down
1 change: 1 addition & 0 deletions libcxx/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ if (NOT LIBCXX_ENABLE_RTTI)
endif()

serialize_lit_string_param(SERIALIZED_LIT_PARAMS hardening_mode "${LIBCXX_HARDENING_MODE}")
serialize_lit_string_param(SERIALIZED_LIT_PARAMS pfp "${LIBCXX_PFP}")

if (CMAKE_CXX_COMPILER_TARGET)
serialize_lit_string_param(SERIALIZED_LIT_PARAMS target_triple "${CMAKE_CXX_COMPILER_TARGET}")
Expand Down
3 changes: 3 additions & 0 deletions libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
// This test doesn't work as such on Windows.
// UNSUPPORTED: windows

// GDB doesn't know how to read PFP fields correctly yet.
// UNSUPPORTED: pfp

// RUN: %{cxx} %{flags} %s -o %t.exe %{compile_flags} -g %{link_flags}
// Ensure locale-independence for unicode tests.
// RUN: env LANG=en_US.UTF-8 %{gdb} -nx -batch -iex "set autoload off" -ex "source %S/../../../utils/gdb/libcxx/printers.py" -ex "python register_libcxx_printer_loader()" -ex "source %S/gdb_pretty_printer_test.py" %t.exe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
//
//===----------------------------------------------------------------------===//

// With PFP we return different values for __libcpp_is_trivially_relocatable.
// UNSUPPORTED: pfp

#include <__type_traits/is_trivially_relocatable.h>
#include <array>
#include <deque>
Expand Down
36 changes: 36 additions & 0 deletions libcxx/utils/ci/run-buildbot
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,42 @@ bootstrapping-build)

ccache -s
;;
bootstrapping-build-pfp)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bootstrapping build is incredibly heavy weight. Why is this required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's required because the PFP support in the compiler is experimental, and brand new so it won't exist in compilers that are already installed on the target system. Once PFP becomes a stable feature that is supported in released compilers, we may convert this to a non-bootstrapping buid.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we should update the compiler instead. We have close-to-trunk compilers available.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I replaced this with a generic-pfp build that assumes an up to date compiler.

clean

triple="$(${CXX} --print-target-triple)"

step "Generating CMake"
${CMAKE} \
-S "${MONOREPO_ROOT}/llvm" \
-B "${BUILD_DIR}" \
-GNinja -DCMAKE_MAKE_PROGRAM="${NINJA}" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
-DLLVM_ENABLE_PROJECTS="clang;lld" \
-DLLVM_ENABLE_RUNTIMES="compiler-rt;libcxx;libcxxabi;libunwind" \
-DLLVM_RUNTIME_TARGETS="$triple" \
-DLLVM_HOST_TRIPLE="$triple" \
-DLLVM_TARGETS_TO_BUILD="host" \
-DRUNTIMES_BUILD_ALLOW_DARWIN=ON \
-DLLVM_ENABLE_ASSERTIONS=ON \
"-DRUNTIMES_${triple}_LIBCXXABI_ENABLE_SHARED=OFF" \
"-DRUNTIMES_${triple}_LIBCXX_USE_COMPILER_RT=ON" \
"-DRUNTIMES_${triple}_LIBCXX_PFP=tagged" \
"-DRUNTIMES_${triple}_LIBCXX_ENABLE_SHARED=OFF" \
"-DRUNTIMES_${triple}_LIBCXX_TEST_CONFIG=llvm-libc++-static.cfg.in" \
"-DRUNTIMES_${triple}_LIBUNWIND_ENABLE_SHARED=OFF" \
-DLLVM_LIT_ARGS="-sv --xunit-xml-output test-results.xml --timeout=1500 --time-tests"

# FIXME: Currently this also runs the sanitizer tests due to compiler-rt
# being in LLVM_ENABLE_RUNTIMES for the emulated PAC runtime. Ideally this
# would only run the libc++ and libc++abi tests.
step "Running the libc++ and libc++abi tests"
${NINJA} -vC "${BUILD_DIR}" check-runtimes

# FIXME: Debugging support for PFP is incomplete so don't run the LLDB tests
# as above for now.
;;
generic-static)
clean
generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-static.cmake"
Expand Down
18 changes: 18 additions & 0 deletions libcxx/utils/libcxx/test/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,24 @@ def getSuitableClangTidy(cfg):
]
)
),
Parameter(
name="pfp",
choices=["none", "untagged", "tagged"],
type=str,
default="none",
help="Whether to build with pointer field protection.",
actions=lambda pfp: [] if pfp == "none" else [
AddCompileFlag("-fexperimental-pointer-field-protection"),
AddCompileFlag("-fexperimental-pointer-field-protection-tagged") if pfp == "tagged" else None,
# Requires support for new relocations which are only implemented in lld for now.
AddLinkFlag("-fuse-ld=lld"),
# Requires emulated PAC support in compiler-rt.
AddCompileFlag("--rtlib=compiler-rt"),
AddLinkFlag("--rtlib=compiler-rt"),
AddLinkFlag("--unwindlib=libunwind"),
AddFeature("pfp"),
],
),
Parameter(
name="enable_experimental",
choices=[True, False],
Expand Down
4 changes: 4 additions & 0 deletions libcxxabi/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ if (LLVM_USE_SANITIZER)
serialize_lit_string_param(SERIALIZED_LIT_PARAMS use_sanitizer "${LLVM_USE_SANITIZER}")
endif()

if (DEFINED LIBCXX_PFP)
serialize_lit_string_param(SERIALIZED_LIT_PARAMS pfp "${LIBCXX_PFP}")
endif()

if (CMAKE_CXX_COMPILER_TARGET)
serialize_lit_string_param(SERIALIZED_LIT_PARAMS target_triple "${CMAKE_CXX_COMPILER_TARGET}")
else()
Expand Down
Loading