Skip to content

Commit aac1065

Browse files
committed
personal change
1 parent f968f1a commit aac1065

File tree

10 files changed

+292
-3
lines changed

10 files changed

+292
-3
lines changed

compiler-rt/lib/builtins/aarch64/emupac.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ const uint64_t kTTBR1Mask = 1ULL << 55;
4747
static bool pac_supported() {
4848
register uintptr_t x30 __asm__("x30") = 1ULL << 55;
4949
__asm__ __volatile__("xpaclri" : "+r"(x30));
50+
#ifdef FORCE_NON_PAC
51+
return !(x30 & (1ULL << 54));
52+
#else
5053
return x30 & (1ULL << 54);
54+
#endif
5155
}
5256

5357
// This asm snippet is used to force the creation of a frame record when

libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
// UNSUPPORTED: no-localization
1313
// UNSUPPORTED: c++03
1414

15-
// TODO: Investigate why this fails on the arm bots
16-
// UNSUPPORTED: target=arm{{.*}}
17-
1815
// The Android libc++ tests are run on a non-Android host, connected to an
1916
// Android device over adb. gdb needs special support to make this work (e.g.
2017
// gdbclient.py, ndk-gdb.py, gdbserver), and the Android organization doesn't

llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,19 +472,23 @@ bool expandProtectedFieldPtr(Function &Intr) {
472472

473473
auto CreateSign = [&](IRBuilder<> &B, Value *Val, Value *Disc,
474474
OperandBundleDef DSBundle) {
475+
#ifndef FORCE_EMUPAC
475476
Function *F = B.GetInsertBlock()->getParent();
476477
Attribute FSAttr = F->getFnAttribute("target-features");
477478
if (FSAttr.isValid() && FSAttr.getValueAsString().contains("+pauth"))
478479
return B.CreateCall(SignIntr, {Val, B.getInt32(2), Disc}, DSBundle);
480+
#endif
479481
return B.CreateCall(EmuSignIntr, {Val, Disc}, DSBundle);
480482
};
481483

482484
auto CreateAuth = [&](IRBuilder<> &B, Value *Val, Value *Disc,
483485
OperandBundleDef DSBundle) {
486+
#ifndef FORCE_EMUPAC
484487
Function *F = B.GetInsertBlock()->getParent();
485488
Attribute FSAttr = F->getFnAttribute("target-features");
486489
if (FSAttr.isValid() && FSAttr.getValueAsString().contains("+pauth"))
487490
return B.CreateCall(AuthIntr, {Val, B.getInt32(2), Disc}, DSBundle);
491+
#endif
488492
return B.CreateCall(EmuAuthIntr, {Val, Disc}, DSBundle);
489493
};
490494

llvm/utils/gn/build/toolchain/target_flags.gni

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ import("//llvm/triples.gni")
22
import("//llvm/utils/gn/build/mac_sdk.gni")
33
import("//llvm/utils/gn/build/toolchain/compiler.gni")
44

5+
declare_args() {
6+
stage2_pointer_field_protection = "none"
7+
emupac_force = false
8+
emupac_force_non_pac = false
9+
}
10+
511
# Flags in this file are passed both to the compiler that's building
612
# compiler-rt at build time (via normal gn cflags/ldflags), as well as to the
713
# compiler building compiler-rt test programs at test time (via
@@ -63,3 +69,20 @@ if (current_cpu == "x86") {
6369
target_flags += [ "-m32" ]
6470
}
6571
}
72+
73+
if (current_toolchain != host_toolchain && current_cpu == "arm64") {
74+
target_flags += [
75+
"-march=armv8.3a",
76+
]
77+
}
78+
if (current_toolchain != host_toolchain) {
79+
target_flags += [
80+
"-fexperimental-pointer-field-protection=$stage2_pointer_field_protection",
81+
]
82+
target_ldflags += [
83+
"--rtlib=compiler-rt",
84+
"--unwindlib=libunwind",
85+
"-static-libgcc",
86+
"-L" + rebase_path(root_build_dir) + "/lib",
87+
]
88+
}

llvm/utils/gn/secondary/compiler-rt/lib/builtins/BUILD.gn

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import("//compiler-rt/lib/builtins/sources.gni")
22
import("//compiler-rt/target.gni")
33
import("//llvm/utils/gn/build/buildflags.gni")
4+
import("//llvm/utils/gn/build/toolchain/target_flags.gni")
45

56
lse_targets = []
67

@@ -84,6 +85,10 @@ static_library("builtins") {
8485
defines = builtins_defines
8586
sources = builtins_sources
8687

88+
if (emupac_force_non_pac) {
89+
defines += [ "FORCE_NON_PAC" ]
90+
}
91+
8792
deps = lse_targets
8893
include_dirs = [ "//third-party/siphash/include" ]
8994
}

llvm/utils/gn/secondary/llvm/lib/CodeGen/BUILD.gn

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import("//llvm/utils/gn/build/toolchain/target_flags.gni")
2+
13
static_library("CodeGen") {
24
output_name = "LLVMCodeGen"
35
public_deps = [
@@ -255,4 +257,7 @@ static_library("CodeGen") {
255257
"WindowScheduler.cpp",
256258
"XRayInstrumentation.cpp",
257259
]
260+
if (emupac_force) {
261+
defines = [ "FORCE_EMUPAC" ]
262+
}
258263
}

llvm/utils/pfp-bazel

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh -xe
2+
3+
shopt -s globstar
4+
5+
tc="$(dirname $0)/../../ra"
6+
7+
mtime_before="$(stat -c %Y $tc/bin/clang || true)"
8+
ninja -C $tc clang
9+
mtime_after="$(stat -c %Y $tc/bin/clang)"
10+
if [ "$mtime_before" != "$mtime_after" ] ; then
11+
rm -f $tc/stage2_*/**/*.o
12+
fi
13+
ninja -C $tc libcxx
14+
15+
cflags=$(grep COMPILER_RT_TEST_COMPILER_CFLAGS= $tc/stage2_unix/toolchain.ninja | sed -e 's/\\\$ /:/g' | grep -o COMPILER_RT_TEST_COMPILER_CFLAGS='[^ ]*' | cut -d= -f2-)
16+
cflags="$cflags:-Wno-unused-command-line-argument"
17+
BAZEL_CXXOPTS=$cflags:-stdlib=libc++ BAZEL_LINKLIBS=$cflags:-Wl,-Bstatic:-lc++:-lc++abi:-Wl,-Bdynamic:-lm CC=clang PATH=$tc/bin:$PATH bazel "$@"

llvm/utils/pfp-check-libcxx

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/sh -xe
2+
3+
shopt -s globstar
4+
5+
tc="$(cd $(dirname $0)/../../ra && pwd)"
6+
7+
mtime_before="$(stat -c %Y $tc/bin/clang || true)"
8+
ninja -C $tc clang
9+
mtime_after="$(stat -c %Y $tc/bin/clang)"
10+
if [ "$mtime_before" != "$mtime_after" ] ; then
11+
rm -f $tc/stage2_*/**/*.o
12+
fi
13+
ninja -C $tc libcxx
14+
15+
cflags=$(grep COMPILER_RT_TEST_COMPILER_CFLAGS= $tc/stage2_unix/toolchain.ninja | sed -e 's/\\\$ /:/g' | grep -o COMPILER_RT_TEST_COMPILER_CFLAGS='[^ ]*' | sed -e 's/:/ /g' | cut -d= -f2-)
16+
cflags="$cflags -Wno-unused-command-line-argument"
17+
18+
mkdir -p $tc/check-libcxx
19+
cat > $tc/check-libcxx/lit.site.cfg <<LIT
20+
# This testing configuration handles running the test suite against LLVM's libc++
21+
# using a static library.
22+
23+
lit_config.load_config(config, '$tc/check-libcxx/cmake-bridge.cfg')
24+
25+
config.substitutions.append(('%{flags}',
26+
'-pthread'
27+
))
28+
config.substitutions.append(('%{compile_flags}',
29+
'-nostdinc++ -I %{include-dir} -I %{target-include-dir} -I %{libcxx-dir}/test/support $cflags'
30+
))
31+
config.substitutions.append(('%{link_flags}',
32+
'-nostdlib++ -L %{lib-dir} -Wl,-Bstatic -lc++ -lc++abi -Wl,-Bdynamic --rtlib=compiler-rt --unwindlib=libunwind -static-libgcc -static-libstdc++ -stdlib=libc++ -fuse-ld=lld'
33+
))
34+
config.substitutions.append(('%{exec}',
35+
'%{executor} --execdir %T -- '
36+
))
37+
38+
import os, site
39+
site.addsitedir(os.path.join('@LIBCXX_SOURCE_DIR@', 'utils'))
40+
import libcxx.test.params, libcxx.test.config
41+
libcxx.test.config.configure(
42+
libcxx.test.params.DEFAULT_PARAMETERS,
43+
libcxx.test.features.DEFAULT_FEATURES,
44+
config,
45+
lit_config
46+
)
47+
LIT
48+
49+
cat > $tc/check-libcxx/cmake-bridge.cfg <<LIT
50+
## Autogenerated by libcxx configuration.
51+
# Do not edit!
52+
53+
# Lit parameters serialized here for llvm-lit to pick them up
54+
config.compiler = "$tc/bin/clang++"
55+
config.hardening_mode = "none"
56+
config.target_triple = "aarch64-unknown-linux-gnu"
57+
58+
59+
#
60+
# This file performs the bridge between the CMake configuration and the Lit
61+
# configuration files by setting up the LitConfig object and various Lit
62+
# substitutions from CMake variables.
63+
#
64+
# Individual configuration files can take advantage of this bridge by
65+
# loading the file and then setting up the remaining Lit substitutions.
66+
#
67+
68+
import os, site
69+
site.addsitedir(os.path.join('$tc/../libcxx', 'utils'))
70+
import libcxx.test.format
71+
72+
# Basic configuration of the test suite
73+
config.name = os.path.basename('$tc/../libcxx/test/configs/llvm-libc++-static.cfg.in')
74+
config.test_source_root = os.path.join('$tc/../libcxx', 'test')
75+
config.test_format = libcxx.test.format.CxxStandardLibraryTest()
76+
config.recursiveExpansionLimit = 10
77+
config.test_exec_root = '$tc/check-libcxx'
78+
79+
# Add substitutions for bootstrapping the test suite configuration
80+
config.substitutions.append(('%{libcxx-dir}', '$tc/../libcxx'))
81+
config.substitutions.append(('%{install-prefix}', '$tc'))
82+
config.substitutions.append(('%{include-dir}', '$tc/include/c++/v1'))
83+
config.substitutions.append(('%{target-include-dir}', '$tc/include/aarch64-unknown-linux-gnu/c++/v1'))
84+
config.substitutions.append(('%{lib-dir}', '$tc/lib'))
85+
config.substitutions.append(('%{module-dir}', '$tc/share/libc++/v1'))
86+
config.substitutions.append(('%{test-tools-dir}', '$tc/../libcxx/test/tools'))
87+
config.substitutions.append(('%{benchmark_flags}', ''))
88+
LIT
89+
90+
$tc/bin/llvm-lit -sv $tc/check-libcxx --param enable_benchmarks=no --filter-out /modules/ "$@"

llvm/utils/pfp-cmake

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh -xe
2+
3+
shopt -s globstar
4+
5+
tc="$(dirname $0)/../../ra"
6+
7+
mtime_before="$(stat -c %Y $tc/bin/clang || true)"
8+
ninja -C $tc clang
9+
mtime_after="$(stat -c %Y $tc/bin/clang)"
10+
if [ "$mtime_before" != "$mtime_after" ] ; then
11+
rm -f $tc/stage2_*/**/*.o
12+
fi
13+
ninja -C $tc libcxx
14+
15+
cflags=$(grep COMPILER_RT_TEST_COMPILER_CFLAGS= $tc/stage2_unix/toolchain.ninja | sed -e 's/\\\$ /:/g' | grep -o COMPILER_RT_TEST_COMPILER_CFLAGS='[^ ]*' | sed -e 's/:/ /g' | cut -d= -f2-)
16+
cflags="$cflags -Wno-unused-command-line-argument"
17+
CC=$tc/bin/clang CXX=$tc/bin/clang++ cmake -G Ninja -DCMAKE_C_FLAGS="$cflags" -DCMAKE_CXX_FLAGS="$cflags -stdlib=libc++" -DCMAKE_{EXE,SHARED,MODULE}_LINKER_FLAGS="$cflags -Wl,-Bstatic -lc++ -lc++abi -Wl,-Bdynamic -lm -fuse-ld=lld -static-libstdc++" "$@"

llvm/utils/pfp-patches/dart.patch

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
From 47e6d11cc8b6db025c43451ad68afd42c2892071 Mon Sep 17 00:00:00 2001
2+
From: Peter Collingbourne <pcc@google.com>
3+
Date: Mon, 3 Mar 2025 20:07:20 -0800
4+
Subject: [PATCH] PFP fixes
5+
6+
---
7+
runtime/platform/allocation.h | 4 ++++
8+
runtime/vm/dart.cc | 5 ++---
9+
runtime/vm/isolate.cc | 5 ++++-
10+
runtime/vm/isolate.h | 4 ++--
11+
runtime/vm/timeline.cc | 4 ++++
12+
5 files changed, 16 insertions(+), 6 deletions(-)
13+
14+
diff --git a/runtime/platform/allocation.h b/runtime/platform/allocation.h
15+
index 26001ac54f2..5bc2a10960b 100644
16+
--- a/runtime/platform/allocation.h
17+
+++ b/runtime/platform/allocation.h
18+
@@ -40,6 +40,10 @@ class MallocAllocated {
19+
public:
20+
MallocAllocated() {}
21+
22+
+ // Placement new.
23+
+ void* operator new(size_t size, void *p) { return p; }
24+
+ void* operator new[](size_t size, void *p) { return p; }
25+
+
26+
// Intercept operator new to produce clearer error messages when we run out
27+
// of memory. Don't do this when running under ASAN so it can continue to
28+
// check malloc/new/new[] are paired with free/delete/delete[] respectively.
29+
diff --git a/runtime/vm/dart.cc b/runtime/vm/dart.cc
30+
index 490549316ef..d78779a511a 100644
31+
--- a/runtime/vm/dart.cc
32+
+++ b/runtime/vm/dart.cc
33+
@@ -165,12 +165,12 @@ class DartInitializationState : public AllStatic {
34+
std::atomic<uint8_t> DartInitializationState::state_ = {kUnInitialized};
35+
std::atomic<uint64_t> DartInitializationState::in_use_count_ = {0};
36+
37+
-#if defined(DART_PRECOMPILER) || defined(DART_PRECOMPILED_RUNTIME)
38+
static void CheckOffsets() {
39+
#if !defined(IS_SIMARM_HOST64)
40+
// These offsets are embedded in precompiled instructions. We need the
41+
// compiler and the runtime to agree.
42+
bool ok = true;
43+
+ (void)ok;
44+
#define CHECK_OFFSET(expr, offset) \
45+
if ((expr) != (offset)) { \
46+
OS::PrintErr("%s got %" Pd ", %s expected %" Pd "\n", #expr, \
47+
@@ -226,7 +226,6 @@ static void CheckOffsets() {
48+
} \
49+
}
50+
#define CHECK_CONSTANT(Class, Name) CHECK_OFFSET(Class::Name, Class##_##Name);
51+
-#endif // defined(DART_PRECOMPILED_RUNTIME)
52+
53+
COMMON_OFFSETS_LIST(CHECK_FIELD, CHECK_ARRAY, CHECK_SIZEOF,
54+
CHECK_ARRAY_SIZEOF, CHECK_PAYLOAD_SIZEOF, CHECK_RANGE,
55+
@@ -258,8 +257,8 @@ static void CheckOffsets() {
56+
#endif // defined(DART_PRECOMPILER) || defined(DART_PRECOMPILED_RUNTIME)
57+
58+
char* Dart::DartInit(const Dart_InitializeParams* params) {
59+
-#if defined(DART_PRECOMPILER) || defined(DART_PRECOMPILED_RUNTIME)
60+
CheckOffsets();
61+
+#if defined(DART_PRECOMPILER) || defined(DART_PRECOMPILED_RUNTIME)
62+
#elif defined(ARCH_IS_64_BIT) != defined(TARGET_ARCH_IS_64_BIT)
63+
return Utils::StrDup(
64+
"JIT cannot simulate target architecture with different word size than "
65+
diff --git a/runtime/vm/isolate.cc b/runtime/vm/isolate.cc
66+
index 11cb004f448..c48623b8907 100644
67+
--- a/runtime/vm/isolate.cc
68+
+++ b/runtime/vm/isolate.cc
69+
@@ -448,6 +448,8 @@ IsolateGroup::~IsolateGroup() {
70+
delete debugger_;
71+
debugger_ = nullptr;
72+
#endif
73+
+
74+
+ delete object_store_;
75+
}
76+
77+
void IsolateGroup::RegisterIsolate(Isolate* isolate) {
78+
@@ -1112,7 +1114,8 @@ bool Isolate::SendInternalLibMessage(Dart_Port main_port,
79+
}
80+
81+
void IsolateGroup::set_object_store(ObjectStore* object_store) {
82+
- object_store_.reset(object_store);
83+
+ delete object_store_;
84+
+ object_store_ = object_store;
85+
}
86+
87+
class IsolateMessageHandler : public MessageHandler {
88+
diff --git a/runtime/vm/isolate.h b/runtime/vm/isolate.h
89+
index 9f5d27fb404..5b501b3fc4f 100644
90+
--- a/runtime/vm/isolate.h
91+
+++ b/runtime/vm/isolate.h
92+
@@ -506,7 +506,7 @@ class IsolateGroup : public IntrusiveDListEntry<IsolateGroup> {
93+
void DropOriginalClassTable();
94+
95+
StoreBuffer* store_buffer() const { return store_buffer_.get(); }
96+
- ObjectStore* object_store() const { return object_store_.get(); }
97+
+ ObjectStore* object_store() const { return object_store_; }
98+
Mutex* symbols_mutex() { return &symbols_mutex_; }
99+
Mutex* type_canonicalization_mutex() { return &type_canonicalization_mutex_; }
100+
Mutex* type_arguments_canonicalization_mutex() {
101+
@@ -819,7 +819,7 @@ class IsolateGroup : public IntrusiveDListEntry<IsolateGroup> {
102+
// Accessed from generated code.
103+
ClassTable* class_table_;
104+
AcqRelAtomic<ClassPtr*> cached_class_table_table_;
105+
- std::unique_ptr<ObjectStore> object_store_;
106+
+ ObjectStore* object_store_;
107+
// End accessed from generated code.
108+
109+
ClassTableAllocator class_table_allocator_;
110+
diff --git a/runtime/vm/timeline.cc b/runtime/vm/timeline.cc
111+
index 211f0e28741..ba07afac27c 100644
112+
--- a/runtime/vm/timeline.cc
113+
+++ b/runtime/vm/timeline.cc
114+
@@ -1595,6 +1595,10 @@ TimelineEventFixedBufferRecorder::TimelineEventFixedBufferRecorder(
115+
if (memory_ == nullptr) {
116+
OUT_OF_MEMORY();
117+
}
118+
+ for (intptr_t i = 0; i != num_blocks_; ++i) {
119+
+ new (reinterpret_cast<char*>(memory_->address()) +
120+
+ i * sizeof(TimelineEventBlock)) TimelineEventBlock(i);
121+
+ }
122+
blocks_ = reinterpret_cast<TimelineEventBlock*>(memory_->address());
123+
}
124+
125+
--
126+
2.48.1
127+

0 commit comments

Comments
 (0)