Skip to content

Commit f3a8aab

Browse files
committed
personal change
1 parent 7e440d9 commit f3a8aab

File tree

11 files changed

+433
-3
lines changed

11 files changed

+433
-3
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ static const uint64_t ttbr1_mask = 1ULL << 55;
5555
static bool pac_supported() {
5656
register uintptr_t x30 __asm__("x30") = 1ULL << 55;
5757
__asm__ __volatile__("xpaclri" : "+r"(x30));
58+
#ifdef FORCE_NON_PAC
59+
return !(x30 & (1ULL << 54));
60+
#else
5861
return x30 & (1ULL << 54);
62+
#endif
5963
}
6064

6165
#ifdef __GCC_HAVE_DWARF2_CFI_ASM

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
@@ -495,19 +495,23 @@ bool expandProtectedFieldPtr(Function &Intr) {
495495

496496
auto CreateSign = [&](IRBuilder<> &B, Value *Val, Value *Disc,
497497
OperandBundleDef DSBundle) {
498+
#ifndef FORCE_EMUPAC
498499
Function *F = B.GetInsertBlock()->getParent();
499500
Attribute FSAttr = F->getFnAttribute("target-features");
500501
if (FSAttr.isValid() && FSAttr.getValueAsString().contains("+pauth"))
501502
return B.CreateCall(SignIntr, {Val, B.getInt32(2), Disc}, DSBundle);
503+
#endif
502504
return B.CreateCall(EmuSignIntr, {Val, Disc}, DSBundle);
503505
};
504506

505507
auto CreateAuth = [&](IRBuilder<> &B, Value *Val, Value *Disc,
506508
OperandBundleDef DSBundle) {
509+
#ifndef FORCE_EMUPAC
507510
Function *F = B.GetInsertBlock()->getParent();
508511
Attribute FSAttr = F->getFnAttribute("target-features");
509512
if (FSAttr.isValid() && FSAttr.getValueAsString().contains("+pauth"))
510513
return B.CreateCall(AuthIntr, {Val, B.getInt32(2), Disc}, DSBundle);
514+
#endif
511515
return B.CreateCall(EmuAuthIntr, {Val, Disc}, DSBundle);
512516
};
513517

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 = [
@@ -256,4 +258,7 @@ static_library("CodeGen") {
256258
"WindowsSecureHotPatching.cpp",
257259
"XRayInstrumentation.cpp",
258260
]
261+
if (emupac_force) {
262+
defines = [ "FORCE_EMUPAC" ]
263+
}
259264
}

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-bench

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
# See https://llvm.org/LICENSE.txt for license information.
5+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
#
7+
# ==------------------------------------------------------------------------==#
8+
9+
import argparse
10+
import os
11+
import random
12+
import shutil
13+
import subprocess
14+
import tempfile
15+
16+
# The purpose of this script is to measure the performance effect
17+
# of a PFP change in a statistically sound way, automating all the
18+
# tedious parts of doing so. It copies the test case (a Fleetbench binary)
19+
# into /tmp as well as running the test binaries from /tmp to reduce the influence on the test
20+
# machine's storage medium on the results. It accounts for measurement
21+
# bias caused by binary layout (using the --randomize-section-padding
22+
# flag to link the test binaries) and by environment variable size.
23+
# Runs of the base and test case are interleaved to account for environmental factors which may influence
24+
# the result due to the passage of time. The results
25+
# are collected into a results-base.csv and results-test.csv file in the output directory and may
26+
# be analyzed by the user with a tool such as ministat.
27+
#
28+
# Requirements: Linux host, /tmp is tmpfs.
29+
#
30+
# Example invocation for comparing the performance of the current commit
31+
# against the previous commit which is treated as the baseline, without
32+
# linking debug info:
33+
#
34+
# llvm/utils/pfp-bench \
35+
# --base-commit HEAD^ \
36+
# --test-commit HEAD \
37+
# --project-path /path/to/fleetbench \
38+
# --num-iterations 512 \
39+
# --num-binary-variants 16 \
40+
# --output-dir outdir
41+
#
42+
# Then this bash command will compare the real time of the base and test cases.
43+
#
44+
# ministat -A \
45+
# <(grep lld-base outdir/results.csv | cut -d, -f2) \
46+
# <(grep lld-test outdir/results.csv | cut -d, -f2)
47+
48+
# We don't want to copy stat() information when we copy the reproducer
49+
# to the temporary directory. Files in the Bazel store are read-only so this will
50+
# cause trouble when the linker writes the output file and when we want to clean
51+
# up the temporary directory. Python doesn't provide a way to disable copying
52+
# stat() information in shutil.copytree so we just monkeypatch shutil.copystat
53+
# to do nothing.
54+
shutil.copystat = lambda *args, **kwargs: 0
55+
56+
parser = argparse.ArgumentParser(prog="benchmark_change.py")
57+
parser.add_argument("--base-commit", required=True)
58+
parser.add_argument("--test-commit", required=True)
59+
parser.add_argument("--project-path", required=True)
60+
parser.add_argument("--num-iterations", type=int, required=True)
61+
parser.add_argument("--num-binary-variants", type=int, required=True)
62+
parser.add_argument("--output-dir", required=True)
63+
args = parser.parse_args()
64+
65+
test_dir = tempfile.mkdtemp()
66+
print(f"Using {test_dir} as temporary directory")
67+
68+
os.makedirs(args.output_dir)
69+
print(f"Using {args.output_dir} as output directory")
70+
71+
pfp_bazel = f"{os.path.dirname(__file__)}/pfp-bazel"
72+
bazel_flags = ["-c", "opt", "--copt=-gmlt", "--verbose_failures"]
73+
74+
def extract_link_command(target):
75+
link_command = None
76+
for line in subprocess.Popen(
77+
f"{pfp_bazel} aquery {' '.join(bazel_flags)} {target} | commandify", stdout=subprocess.PIPE, shell=True, cwd=args.project_path
78+
).stdout.readlines():
79+
commands = line.decode("utf-8").split("&&")
80+
for command in commands:
81+
if " -o " in command and "-fuse-ld=" in command:
82+
link_command = command.strip()
83+
return link_command
84+
85+
86+
def generate_binary_variants(case_name):
87+
target = "//fleetbench"
88+
subprocess.run([pfp_bazel, "clean"], cwd=args.project_path)
89+
subprocess.run([pfp_bazel, "build"] + bazel_flags + [target], cwd=args.project_path)
90+
link_command = extract_link_command(target)
91+
92+
for i in range(0, args.num_binary_variants):
93+
print(f"Generating binary variant {i} for {case_name} case")
94+
command = f"{link_command} -o {test_dir}/fleetbench-{case_name}{i} -Wl,--randomize-section-padding={i}"
95+
subprocess.run(command, check=True, shell=True, cwd=args.project_path)
96+
command2 = f"ln -sf fleetbench.runfiles {test_dir}/fleetbench-{case_name}{i}.runfiles"
97+
subprocess.run(command2, check=True, shell=True)
98+
99+
100+
# Make sure that there are no local changes.
101+
subprocess.run(["git", "diff", "--exit-code", "HEAD"], check=True)
102+
103+
# Resolve the base and test commit, since if they are relative to HEAD we will
104+
# check out the wrong commit below.
105+
resolved_base_commit = subprocess.check_output(
106+
["git", "rev-parse", args.base_commit]
107+
).strip()
108+
resolved_test_commit = subprocess.check_output(
109+
["git", "rev-parse", args.test_commit]
110+
).strip()
111+
112+
113+
subprocess.run(["git", "checkout", resolved_base_commit], check=True)
114+
generate_binary_variants("base")
115+
116+
subprocess.run(["git", "checkout", resolved_test_commit], check=True)
117+
generate_binary_variants("test")
118+
119+
shutil.copytree(f"{args.project_path}/bazel-bin/fleetbench/fleetbench.runfiles", f"{test_dir}/fleetbench.runfiles")
120+
121+
def benchmark_command(case_name, binary_variant):
122+
return [f"{test_dir}/fleetbench-{case_name}{binary_variant}", "--benchmark_format=csv"]
123+
124+
125+
results_base_csv = open(f"{args.output_dir}/results-base.csv", "w")
126+
results_test_csv = open(f"{args.output_dir}/results-test.csv", "w")
127+
128+
env = os.environ.copy()
129+
rng = random.Random(0)
130+
131+
for i in range(0, args.num_iterations):
132+
for v in range(0, args.num_binary_variants):
133+
env['PAD'] = 'a' * rng.getrandbits(12)
134+
subprocess.run(benchmark_command("base", v), stdout=results_base_csv, env=env)
135+
env['PAD'] = 'a' * rng.getrandbits(12)
136+
subprocess.run(benchmark_command("test", v), stdout=results_test_csv, env=env)
137+
138+
shutil.rmtree(test_dir)

llvm/utils/pfp-check-libcxx

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
import shlex
70+
import sys
71+
site.addsitedir(os.path.join('$tc/../libcxx', 'utils'))
72+
import libcxx.test.format
73+
74+
# Basic configuration of the test suite
75+
config.name = os.path.basename('$tc/../libcxx/test/configs/llvm-libc++-static.cfg.in')
76+
config.test_source_root = os.path.join('$tc/../libcxx', 'test')
77+
config.test_format = libcxx.test.format.CxxStandardLibraryTest()
78+
config.recursiveExpansionLimit = 10
79+
config.test_exec_root = '$tc/check-libcxx'
80+
81+
# Add substitutions for bootstrapping the test suite configuration
82+
config.substitutions.append(('%{libcxx-dir}', '$tc/../libcxx'))
83+
config.substitutions.append(('%{install-prefix}', '$tc'))
84+
config.substitutions.append(('%{include-dir}', '$tc/include/c++/v1'))
85+
config.substitutions.append(('%{target-include-dir}', '$tc/include/aarch64-unknown-linux-gnu/c++/v1'))
86+
config.substitutions.append(('%{lib-dir}', '$tc/lib'))
87+
config.substitutions.append(('%{module-dir}', '$tc/share/libc++/v1'))
88+
config.substitutions.append(('%{test-tools-dir}', '$tc/../libcxx/test/tools'))
89+
config.substitutions.append(('%{benchmark_flags}', ''))
90+
config.substitutions.append(("%{python}", shlex.quote(sys.executable)))
91+
LIT
92+
93+
$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++" "$@"

0 commit comments

Comments
 (0)