Skip to content

Commit 7392bd6

Browse files
authored
Merge branch 'main' into lldb/function-name-highlighting-demangler
2 parents 8526be4 + 34598fd commit 7392bd6

File tree

945 files changed

+42632
-9748
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

945 files changed

+42632
-9748
lines changed

.ci/compute_projects.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
"clang": {"clang-tools-extra", "compiler-rt", "cross-project-tests"},
5353
"clang-tools-extra": {"libc"},
5454
"mlir": {"flang"},
55+
# Test everything if ci scripts are changed.
56+
# FIXME: Figure out what is missing and add here.
57+
".ci": {"llvm", "clang", "lld", "lldb"},
5558
}
5659

5760
DEPENDENT_RUNTIMES_TO_TEST = {"clang": {"libcxx", "libcxxabi", "libunwind"}}
@@ -130,12 +133,11 @@ def _add_dependencies(projects: Set[str]) -> Set[str]:
130133
def _compute_projects_to_test(modified_projects: Set[str], platform: str) -> Set[str]:
131134
projects_to_test = set()
132135
for modified_project in modified_projects:
133-
# Skip all projects where we cannot run tests.
134-
if modified_project not in PROJECT_CHECK_TARGETS:
135-
continue
136136
if modified_project in RUNTIMES:
137137
continue
138-
projects_to_test.add(modified_project)
138+
# Skip all projects where we cannot run tests.
139+
if modified_project in PROJECT_CHECK_TARGETS:
140+
projects_to_test.add(modified_project)
139141
if modified_project not in DEPENDENTS_TO_TEST:
140142
continue
141143
for dependent_project in DEPENDENTS_TO_TEST[modified_project]:

.ci/compute_projects_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,19 @@ def test_exclude_gn(self):
188188
self.assertEqual(env_variables["runtimes_to_build"], "")
189189
self.assertEqual(env_variables["runtimes_check_targets"], "")
190190

191+
def test_ci(self):
192+
env_variables = compute_projects.get_env_variables(
193+
[".ci/compute_projects.py"], "Linux"
194+
)
195+
self.assertEqual(env_variables["projects_to_build"],
196+
"clang;lld;llvm;lldb")
197+
self.assertEqual(env_variables["project_check_targets"], "check-clang
198+
check-lld check-llvm check-lldb")
199+
self.assertEqual(env_variables["runtimes_to_build"],
200+
"libcxx;libcxxabi;libunwind")
201+
self.assertEqual(env_variables["runtimes_check_targets"], "check-cxx
202+
check-cxxabi check-unwind")
203+
191204

192205
if __name__ == "__main__":
193206
unittest.main()

.ci/monolithic-linux.sh

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ set -o pipefail
1818

1919
MONOREPO_ROOT="${MONOREPO_ROOT:="$(git rev-parse --show-toplevel)"}"
2020
BUILD_DIR="${BUILD_DIR:=${MONOREPO_ROOT}/build}"
21-
INSTALL_DIR="${BUILD_DIR}/install"
2221
rm -rf "${BUILD_DIR}"
2322

2423
ccache --zero-stats
@@ -28,10 +27,14 @@ if [[ -n "${CLEAR_CACHE:-}" ]]; then
2827
ccache --clear
2928
fi
3029

30+
mkdir -p artifacts/reproducers
31+
32+
# Make sure any clang reproducers will end up as artifacts.
33+
export CLANG_CRASH_DIAGNOSTICS_DIR=`realpath artifacts/reproducers`
34+
3135
function at-exit {
3236
retcode=$?
3337

34-
mkdir -p artifacts
3538
ccache --print-stats > artifacts/ccache_stats.txt
3639
cp "${BUILD_DIR}"/.ninja_log artifacts/.ninja_log
3740

@@ -50,17 +53,28 @@ trap at-exit EXIT
5053

5154
projects="${1}"
5255
targets="${2}"
56+
runtimes="${3}"
5357

5458
lit_args="-v --xunit-xml-output ${BUILD_DIR}/test-results.xml --use-unique-output-file-name --timeout=1200 --time-tests"
5559

5660
echo "--- cmake"
61+
5762
export PIP_BREAK_SYSTEM_PACKAGES=1
5863
pip install -q -r "${MONOREPO_ROOT}"/mlir/python/requirements.txt
5964
pip install -q -r "${MONOREPO_ROOT}"/lldb/test/requirements.txt
6065
pip install -q -r "${MONOREPO_ROOT}"/.ci/requirements.txt
66+
67+
# Set the system llvm-symbolizer as preferred.
68+
export LLVM_SYMBOLIZER_PATH=`which llvm-symbolizer`
69+
[[ ! -f "${LLVM_SYMBOLIZER_PATH}" ]] && echo "llvm-symbolizer not found!"
70+
71+
# Set up all runtimes either way. libcxx is a dependency of LLDB.
72+
# If it ends up being unused, not much harm.
6173
cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
6274
-D LLVM_ENABLE_PROJECTS="${projects}" \
75+
-D LLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
6376
-G Ninja \
77+
-D CMAKE_PREFIX_PATH="${HOME}/.local" \
6478
-D CMAKE_BUILD_TYPE=Release \
6579
-D LLVM_ENABLE_ASSERTIONS=ON \
6680
-D LLVM_BUILD_EXAMPLES=ON \
@@ -69,69 +83,47 @@ cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
6983
-D LLVM_ENABLE_LLD=ON \
7084
-D CMAKE_CXX_FLAGS=-gmlt \
7185
-D LLVM_CCACHE_BUILD=ON \
86+
-D LIBCXX_CXX_ABI=libcxxabi \
7287
-D MLIR_ENABLE_BINDINGS_PYTHON=ON \
73-
-D CMAKE_INSTALL_PREFIX="${INSTALL_DIR}"
88+
-D LLDB_ENABLE_PYTHON=ON \
89+
-D LLDB_ENFORCE_STRICT_TEST_REQUIREMENTS=ON
7490

7591
echo "--- ninja"
92+
7693
# Targets are not escaped as they are passed as separate arguments.
7794
ninja -C "${BUILD_DIR}" -k 0 ${targets}
7895

79-
runtimes="${3}"
8096
runtime_targets="${4}"
8197

82-
# Compiling runtimes with just-built Clang and running their tests
83-
# as an additional testing for Clang.
98+
# Run runtimes tests.
99+
# We don't need to do a clean separate build of runtimes, because runtimes
100+
# will be built against just built clang, and because LIBCXX_TEST_PARAMS
101+
# and LIBCXXABI_TEST_PARAMS only affect lit configuration, which successfully
102+
# propagates without a clean build. Other that those two variables, builds
103+
# are supposed to be the same.
84104
if [[ "${runtimes}" != "" ]]; then
85105
if [[ "${runtime_targets}" == "" ]]; then
86106
echo "Runtimes to build are specified, but targets are not."
87107
exit 1
88108
fi
89109

90-
echo "--- ninja install-clang"
91-
92-
ninja -C ${BUILD_DIR} install-clang install-clang-resource-headers
93-
94-
RUNTIMES_BUILD_DIR="${MONOREPO_ROOT}/build-runtimes"
95-
INSTALL_DIR="${BUILD_DIR}/install"
96-
mkdir -p ${RUNTIMES_BUILD_DIR}
97-
98110
echo "--- cmake runtimes C++26"
99111

100-
rm -rf "${RUNTIMES_BUILD_DIR}"
101-
cmake -S "${MONOREPO_ROOT}/runtimes" -B "${RUNTIMES_BUILD_DIR}" -GNinja \
102-
-D CMAKE_C_COMPILER="${INSTALL_DIR}/bin/clang" \
103-
-D CMAKE_CXX_COMPILER="${INSTALL_DIR}/bin/clang++" \
104-
-D LLVM_ENABLE_RUNTIMES="${runtimes}" \
105-
-D LIBCXX_CXX_ABI=libcxxabi \
106-
-D CMAKE_BUILD_TYPE=RelWithDebInfo \
107-
-D CMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
112+
cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
108113
-D LIBCXX_TEST_PARAMS="std=c++26" \
109-
-D LIBCXXABI_TEST_PARAMS="std=c++26" \
110-
-D LLVM_LIT_ARGS="${lit_args}"
114+
-D LIBCXXABI_TEST_PARAMS="std=c++26"
111115

112116
echo "--- ninja runtimes C++26"
113117

114-
ninja -vC "${RUNTIMES_BUILD_DIR}" ${runtime_targets}
118+
ninja -vC "${BUILD_DIR}" ${runtime_targets}
115119

116120
echo "--- cmake runtimes clang modules"
117121

118-
# We don't need to do a clean build of runtimes, because LIBCXX_TEST_PARAMS
119-
# and LIBCXXABI_TEST_PARAMS only affect lit configuration, which successfully
120-
# propagates without a clean build. Other that those two variables, builds
121-
# are supposed to be the same.
122-
123-
cmake -S "${MONOREPO_ROOT}/runtimes" -B "${RUNTIMES_BUILD_DIR}" -GNinja \
124-
-D CMAKE_C_COMPILER="${INSTALL_DIR}/bin/clang" \
125-
-D CMAKE_CXX_COMPILER="${INSTALL_DIR}/bin/clang++" \
126-
-D LLVM_ENABLE_RUNTIMES="${runtimes}" \
127-
-D LIBCXX_CXX_ABI=libcxxabi \
128-
-D CMAKE_BUILD_TYPE=RelWithDebInfo \
129-
-D CMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
122+
cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
130123
-D LIBCXX_TEST_PARAMS="enable_modules=clang" \
131-
-D LIBCXXABI_TEST_PARAMS="enable_modules=clang" \
132-
-D LLVM_LIT_ARGS="${lit_args}"
124+
-D LIBCXXABI_TEST_PARAMS="enable_modules=clang"
133125

134126
echo "--- ninja runtimes clang modules"
135127

136-
ninja -vC "${RUNTIMES_BUILD_DIR}" ${runtime_targets}
128+
ninja -vC "${BUILD_DIR}" ${runtime_targets}
137129
fi

.github/workflows/premerge.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
- name: Upload Artifacts
7070
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
7171
with:
72-
name: Premerge Artifacts
72+
name: Premerge Artifacts (Linux)
7373
path: artifacts/
7474
retention-days: 5
7575
include-hidden-files: 'true'
@@ -124,7 +124,7 @@ jobs:
124124
- name: Upload Artifacts
125125
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
126126
with:
127-
name: Premerge Artifacts
127+
name: Premerge Artifacts (Windows)
128128
path: artifacts/
129129
retention-days: 5
130130
include-hidden-files: 'true'

bolt/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ if (LLVM_INCLUDE_TESTS)
136136
endif()
137137

138138
if (BOLT_ENABLE_RUNTIME)
139-
message(STATUS "Building BOLT runtime libraries for X86")
139+
message(STATUS "Building BOLT runtime libraries for ${CMAKE_SYSTEM_PROCESSOR}")
140140
set(extra_args "")
141141
if(CMAKE_SYSROOT)
142142
list(APPEND extra_args -DCMAKE_SYSROOT=${CMAKE_SYSROOT})

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,11 @@ class BinaryFunction {
11741174
return getSecondaryEntryPointSymbol(BB.getLabel());
11751175
}
11761176

1177+
/// Remove a label from the secondary entry point map.
1178+
void removeSymbolFromSecondaryEntryPointMap(const MCSymbol *Label) {
1179+
SecondaryEntryPoints.erase(Label);
1180+
}
1181+
11771182
/// Return true if the basic block is an entry point into the function
11781183
/// (either primary or secondary).
11791184
bool isEntryPoint(const BinaryBasicBlock &BB) const {
@@ -2126,6 +2131,10 @@ class BinaryFunction {
21262131
return Islands && !Islands->DataOffsets.empty();
21272132
}
21282133

2134+
bool isStartOfConstantIsland(uint64_t Offset) const {
2135+
return hasConstantIsland() && Islands->DataOffsets.count(Offset);
2136+
}
2137+
21292138
/// Return true iff the symbol could be seen inside this function otherwise
21302139
/// it is probably another function.
21312140
bool isSymbolValidInScope(const SymbolRef &Symbol, uint64_t SymbolSize) const;

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,6 +1896,15 @@ void BinaryFunction::postProcessEntryPoints() {
18961896
if (BC.isAArch64() && Offset == getSize())
18971897
continue;
18981898

1899+
// If we have grabbed a wrong code label which actually points to some
1900+
// constant island inside the function, ignore this label and remove it
1901+
// from the secondary entry point map.
1902+
if (isStartOfConstantIsland(Offset)) {
1903+
BC.SymbolToFunctionMap.erase(Label);
1904+
removeSymbolFromSecondaryEntryPointMap(Label);
1905+
continue;
1906+
}
1907+
18991908
BC.errs() << "BOLT-WARNING: reference in the middle of instruction "
19001909
"detected in function "
19011910
<< *this << " at offset 0x" << Twine::utohexstr(Offset) << '\n';

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,9 @@ Error RewriteInstance::discoverStorage() {
597597

598598
// Hugify: Additional huge page from left side due to
599599
// weird ASLR mapping addresses (4KB aligned)
600-
if (opts::Hugify && !BC->HasFixedLoadAddress)
600+
if (opts::Hugify && !BC->HasFixedLoadAddress) {
601601
NextAvailableAddress += BC->PageAlign;
602+
}
602603

603604
if (!opts::UseGnuStack && !BC->IsLinuxKernel) {
604605
// This is where the black magic happens. Creating PHDR table in a segment
@@ -5885,17 +5886,28 @@ void RewriteInstance::rewriteFile() {
58855886

58865887
// Write all allocatable sections - reloc-mode text is written here as well
58875888
for (BinarySection &Section : BC->allocatableSections()) {
5888-
if (!Section.isFinalized() || !Section.getOutputData())
5889+
if (!Section.isFinalized() || !Section.getOutputData()) {
5890+
LLVM_DEBUG(if (opts::Verbosity > 1) {
5891+
dbgs() << "BOLT-INFO: new section is finalized or !getOutputData, skip "
5892+
<< Section.getName() << '\n';
5893+
});
58895894
continue;
5890-
if (Section.isLinkOnly())
5895+
}
5896+
if (Section.isLinkOnly()) {
5897+
LLVM_DEBUG(if (opts::Verbosity > 1) {
5898+
dbgs() << "BOLT-INFO: new section is link only, skip "
5899+
<< Section.getName() << '\n';
5900+
});
58915901
continue;
5902+
}
58925903

58935904
if (opts::Verbosity >= 1)
58945905
BC->outs() << "BOLT: writing new section " << Section.getName()
58955906
<< "\n data at 0x"
58965907
<< Twine::utohexstr(Section.getAllocAddress()) << "\n of size "
58975908
<< Section.getOutputSize() << "\n at offset "
5898-
<< Section.getOutputFileOffset() << '\n';
5909+
<< Section.getOutputFileOffset() << " with content size "
5910+
<< Section.getOutputContents().size() << '\n';
58995911
OS.seek(Section.getOutputFileOffset());
59005912
Section.write(OS);
59015913
}

bolt/runtime/common.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,12 @@ struct timespec {
151151
uint64_t tv_nsec; /* nanoseconds */
152152
};
153153

154-
#if defined(__aarch64__)
154+
#if defined(__aarch64__) || defined(__arm64__)
155155
#include "sys_aarch64.h"
156-
#else
156+
#elif defined(__x86_64__)
157157
#include "sys_x86_64.h"
158+
#else
159+
#error "For AArch64/ARM64 and X86_64 only."
158160
#endif
159161

160162
constexpr uint32_t BufSize = 10240;

bolt/runtime/hugify.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
//
77
//===---------------------------------------------------------------------===//
88

9-
#if defined (__x86_64__) && !defined(__APPLE__)
9+
#if (defined(__x86_64__) || defined(__aarch64__) || defined(__arm64__)) && \
10+
!defined(__APPLE__)
1011

1112
#include "common.h"
1213

@@ -73,8 +74,10 @@ static bool hasPagecacheTHPSupport() {
7374
if (Res < 0)
7475
return false;
7576

76-
if (!strStr(Buf, "[always]") && !strStr(Buf, "[madvise]"))
77+
if (!strStr(Buf, "[always]") && !strStr(Buf, "[madvise]")) {
78+
DEBUG(report("[hugify] THP support is not enabled.\n");)
7779
return false;
80+
}
7881

7982
struct KernelVersionTy {
8083
uint32_t major;
@@ -167,12 +170,20 @@ extern "C" void __bolt_hugify_self_impl() {
167170

168171
/// This is hooking ELF's entry, it needs to save all machine state.
169172
extern "C" __attribute((naked)) void __bolt_hugify_self() {
173+
// clang-format off
170174
#if defined(__x86_64__)
171175
__asm__ __volatile__(SAVE_ALL "call __bolt_hugify_self_impl\n" RESTORE_ALL
172-
"jmp __bolt_hugify_start_program\n" ::
173-
:);
176+
"jmp __bolt_hugify_start_program\n"
177+
:::);
178+
#elif defined(__aarch64__) || defined(__arm64__)
179+
__asm__ __volatile__(SAVE_ALL "bl __bolt_hugify_self_impl\n" RESTORE_ALL
180+
"adrp x16, __bolt_hugify_start_program\n"
181+
"add x16, x16, #:lo12:__bolt_hugify_start_program\n"
182+
"br x16\n"
183+
:::);
174184
#else
175-
exit(1);
185+
__exit(1);
176186
#endif
187+
// clang-format on
177188
}
178189
#endif
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This test is to verify that BOLT won't take a label pointing to constant
2+
# island as a secondary entry point (function `_start` doesn't have ELF size
3+
# set originally) and the function won't otherwise be mistaken as non-simple.
4+
5+
# RUN: %clang %cflags -pie %s -o %t.so -Wl,-q -Wl,--init=_foo -Wl,--fini=_foo
6+
# RUN: llvm-bolt %t.so -o %t.bolt.so --print-cfg 2>&1 | FileCheck %s
7+
# CHECK-NOT: BOLT-WARNING: reference in the middle of instruction detected \
8+
# CHECK-NOT: function _start at offset 0x{{[0-9a-f]+}}
9+
# CHECK: Binary Function "_start" after building cfg
10+
11+
.text
12+
13+
.global _foo
14+
.type _foo, %function
15+
_foo:
16+
ret
17+
18+
.global _start
19+
.type _start, %function
20+
_start:
21+
b _foo
22+
23+
.balign 16
24+
_random_consts:
25+
.long 0x12345678
26+
.long 0x90abcdef
27+
28+
.global _bar
29+
.type _bar, %function
30+
_bar:
31+
ret
32+
33+
# Dummy relocation to force relocation mode
34+
.reloc 0, R_AARCH64_NONE

0 commit comments

Comments
 (0)