Skip to content

Commit f1338fd

Browse files
authored
Merge branch 'main' into code_extractor_1
2 parents 25ee0e2 + f52b01b commit f1338fd

File tree

2,130 files changed

+225697
-29674
lines changed

Some content is hidden

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

2,130 files changed

+225697
-29674
lines changed

.ci/compute_projects_test.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -188,18 +188,22 @@ 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):
191+
def test_ci(self):
192192
env_variables = compute_projects.get_env_variables(
193193
[".ci/compute_projects.py"], "Linux"
194194
)
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")
195+
self.assertEqual(env_variables["projects_to_build"], "clang;lld;llvm;lldb")
196+
self.assertEqual(
197+
env_variables["project_check_targets"],
198+
"check-clang check-lld check-llvm check-lldb",
199+
)
200+
self.assertEqual(
201+
env_variables["runtimes_to_build"], "libcxx;libcxxabi;libunwind"
202+
)
203+
self.assertEqual(
204+
env_variables["runtimes_check_targets"],
205+
"check-cxx check-cxxabi check-unwind",
206+
)
203207

204208

205209
if __name__ == "__main__":

.ci/monolithic-linux.sh

+41-17
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ 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"
2122
rm -rf "${BUILD_DIR}"
2223

2324
ccache --zero-stats
@@ -53,12 +54,10 @@ trap at-exit EXIT
5354

5455
projects="${1}"
5556
targets="${2}"
56-
runtimes="${3}"
5757

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

6060
echo "--- cmake"
61-
6261
export PIP_BREAK_SYSTEM_PACKAGES=1
6362
pip install -q -r "${MONOREPO_ROOT}"/mlir/python/requirements.txt
6463
pip install -q -r "${MONOREPO_ROOT}"/lldb/test/requirements.txt
@@ -69,7 +68,7 @@ export LLVM_SYMBOLIZER_PATH=`which llvm-symbolizer`
6968
[[ ! -f "${LLVM_SYMBOLIZER_PATH}" ]] && echo "llvm-symbolizer not found!"
7069

7170
# Set up all runtimes either way. libcxx is a dependency of LLDB.
72-
# If it ends up being unused, not much harm.
71+
# It will not be built unless it is used.
7372
cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
7473
-D LLVM_ENABLE_PROJECTS="${projects}" \
7574
-D LLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
@@ -86,44 +85,69 @@ cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
8685
-D LIBCXX_CXX_ABI=libcxxabi \
8786
-D MLIR_ENABLE_BINDINGS_PYTHON=ON \
8887
-D LLDB_ENABLE_PYTHON=ON \
89-
-D LLDB_ENFORCE_STRICT_TEST_REQUIREMENTS=ON
88+
-D LLDB_ENFORCE_STRICT_TEST_REQUIREMENTS=ON \
89+
-D CMAKE_INSTALL_PREFIX="${INSTALL_DIR}"
9090

9191
echo "--- ninja"
92-
9392
# Targets are not escaped as they are passed as separate arguments.
9493
ninja -C "${BUILD_DIR}" -k 0 ${targets}
9594

95+
runtimes="${3}"
9696
runtime_targets="${4}"
9797

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.
98+
# Compiling runtimes with just-built Clang and running their tests
99+
# as an additional testing for Clang.
104100
if [[ "${runtimes}" != "" ]]; then
105101
if [[ "${runtime_targets}" == "" ]]; then
106102
echo "Runtimes to build are specified, but targets are not."
107103
exit 1
108104
fi
109105

106+
echo "--- ninja install-clang"
107+
108+
ninja -C ${BUILD_DIR} install-clang install-clang-resource-headers
109+
110+
RUNTIMES_BUILD_DIR="${MONOREPO_ROOT}/build-runtimes"
111+
INSTALL_DIR="${BUILD_DIR}/install"
112+
mkdir -p ${RUNTIMES_BUILD_DIR}
113+
110114
echo "--- cmake runtimes C++26"
111115

112-
cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
116+
rm -rf "${RUNTIMES_BUILD_DIR}"
117+
cmake -S "${MONOREPO_ROOT}/runtimes" -B "${RUNTIMES_BUILD_DIR}" -GNinja \
118+
-D CMAKE_C_COMPILER="${INSTALL_DIR}/bin/clang" \
119+
-D CMAKE_CXX_COMPILER="${INSTALL_DIR}/bin/clang++" \
120+
-D LLVM_ENABLE_RUNTIMES="${runtimes}" \
121+
-D LIBCXX_CXX_ABI=libcxxabi \
122+
-D CMAKE_BUILD_TYPE=RelWithDebInfo \
123+
-D CMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
113124
-D LIBCXX_TEST_PARAMS="std=c++26" \
114-
-D LIBCXXABI_TEST_PARAMS="std=c++26"
125+
-D LIBCXXABI_TEST_PARAMS="std=c++26" \
126+
-D LLVM_LIT_ARGS="${lit_args}"
115127

116128
echo "--- ninja runtimes C++26"
117129

118-
ninja -vC "${BUILD_DIR}" ${runtime_targets}
130+
ninja -vC "${RUNTIMES_BUILD_DIR}" ${runtime_targets}
119131

120132
echo "--- cmake runtimes clang modules"
121133

122-
cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
134+
# We don't need to do a clean build of runtimes, because LIBCXX_TEST_PARAMS
135+
# and LIBCXXABI_TEST_PARAMS only affect lit configuration, which successfully
136+
# propagates without a clean build. Other that those two variables, builds
137+
# are supposed to be the same.
138+
139+
cmake -S "${MONOREPO_ROOT}/runtimes" -B "${RUNTIMES_BUILD_DIR}" -GNinja \
140+
-D CMAKE_C_COMPILER="${INSTALL_DIR}/bin/clang" \
141+
-D CMAKE_CXX_COMPILER="${INSTALL_DIR}/bin/clang++" \
142+
-D LLVM_ENABLE_RUNTIMES="${runtimes}" \
143+
-D LIBCXX_CXX_ABI=libcxxabi \
144+
-D CMAKE_BUILD_TYPE=RelWithDebInfo \
145+
-D CMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
123146
-D LIBCXX_TEST_PARAMS="enable_modules=clang" \
124-
-D LIBCXXABI_TEST_PARAMS="enable_modules=clang"
147+
-D LIBCXXABI_TEST_PARAMS="enable_modules=clang" \
148+
-D LLVM_LIT_ARGS="${lit_args}"
125149

126150
echo "--- ninja runtimes clang modules"
127151

128-
ninja -vC "${BUILD_DIR}" ${runtime_targets}
152+
ninja -vC "${RUNTIMES_BUILD_DIR}" ${runtime_targets}
129153
fi

.clang-format-ignore

Whitespace-only changes.

.github/new-prs-labeler.yml

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ ClangIR:
77
- clang/tools/cir-*/**/*
88
- clang/test/CIR/**/*
99

10+
clang:bytecode:
11+
- clang/docs/ConstantInterpreter.rst
12+
- clang/lib/AST/ByteCode/**/*
13+
- clang/test/AST/ByteCode/**/*
14+
- clang/unittests/AST/ByteCode/**/*
15+
1016
clang:dataflow:
1117
- clang/include/clang/Analysis/FlowSensitive/**/*
1218
- clang/lib/Analysis/FlowSensitive/**/*

.github/workflows/libc-fullbuild-tests.yml

+7-4
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ jobs:
1919
include:
2020
- os: ubuntu-24.04
2121
ccache-variant: sccache
22-
c_compiler: clang
23-
cpp_compiler: clang++
22+
c_compiler: clang-20
23+
cpp_compiler: clang++-20
2424
# TODO: remove ccache logic when https://github.com/hendrikmuhs/ccache-action/issues/279 is resolved.
2525
- os: ubuntu-24.04-arm
2626
ccache-variant: ccache
27-
c_compiler: clang
28-
cpp_compiler: clang++
27+
c_compiler: clang-20
28+
cpp_compiler: clang++-20
2929
# TODO: add back gcc build when it is fixed
3030
# - c_compiler: gcc
3131
# cpp_compiler: g++
@@ -51,6 +51,9 @@ jobs:
5151
# For more information, see https://wiki.debian.org/Multiarch/LibraryPathOverview
5252
- name: Prepare dependencies (Ubuntu)
5353
run: |
54+
wget https://apt.llvm.org/llvm.sh
55+
chmod +x llvm.sh
56+
sudo ./llvm.sh 20
5457
sudo apt-get update
5558
sudo apt-get install -y libmpfr-dev libgmp-dev libmpc-dev ninja-build linux-libc-dev
5659
sudo ln -sf /usr/include/$(uname -p)-linux-gnu/asm /usr/include/asm

bolt/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ endforeach()
8282

8383
set(BOLT_ENABLE_RUNTIME_default OFF)
8484
if ((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64"
85-
OR CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)$")
85+
OR CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)$"
86+
OR CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
8687
AND (CMAKE_SYSTEM_NAME STREQUAL "Linux"
8788
OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
8889
AND (NOT CMAKE_CROSSCOMPILING))

bolt/lib/Core/BinaryBasicBlock.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,7 @@ void BinaryBasicBlock::updateJumpTableSuccessors() {
372372
[](const BinaryBasicBlock *BB1, const BinaryBasicBlock *BB2) {
373373
return BB1->getInputOffset() < BB2->getInputOffset();
374374
});
375-
SuccessorBBs.erase(std::unique(SuccessorBBs.begin(), SuccessorBBs.end()),
376-
SuccessorBBs.end());
375+
SuccessorBBs.erase(llvm::unique(SuccessorBBs), SuccessorBBs.end());
377376

378377
for (BinaryBasicBlock *BB : SuccessorBBs)
379378
addSuccessor(BB);

bolt/lib/Core/BinaryEmitter.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,10 @@ bool BinaryEmitter::emitFunction(BinaryFunction &Function,
373373
Streamer.emitLabel(StartSymbol);
374374
}
375375

376+
const bool NeedsFDE =
377+
Function.hasCFI() && !(Function.isPatch() && Function.isAnonymous());
376378
// Emit CFI start
377-
if (Function.hasCFI()) {
379+
if (NeedsFDE) {
378380
Streamer.emitCFIStartProc(/*IsSimple=*/false);
379381
if (Function.getPersonalityFunction() != nullptr)
380382
Streamer.emitCFIPersonality(Function.getPersonalityFunction(),
@@ -421,7 +423,7 @@ bool BinaryEmitter::emitFunction(BinaryFunction &Function,
421423
Streamer.emitBytes(BC.MIB->getTrapFillValue());
422424

423425
// Emit CFI end
424-
if (Function.hasCFI())
426+
if (NeedsFDE)
425427
Streamer.emitCFIEndProc();
426428

427429
MCSymbol *EndSymbol = Function.getFunctionEndLabel(FF.getFragmentNum());

bolt/lib/Core/BinaryFunction.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2376,7 +2376,7 @@ Error BinaryFunction::buildCFG(MCPlusBuilder::AllocatorIdTy AllocatorId) {
23762376
// Without doing jump table value profiling we don't have a use for extra
23772377
// (duplicate) branches.
23782378
llvm::sort(TakenBranches);
2379-
auto NewEnd = std::unique(TakenBranches.begin(), TakenBranches.end());
2379+
auto NewEnd = llvm::unique(TakenBranches);
23802380
TakenBranches.erase(NewEnd, TakenBranches.end());
23812381

23822382
for (std::pair<uint32_t, uint32_t> &Branch : TakenBranches) {

bolt/lib/Core/DebugNames.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,7 @@ void DWARF5AcceleratorTable::computeBucketCount() {
440440
for (const auto &E : Entries)
441441
Uniques.push_back(E.second.HashValue);
442442
array_pod_sort(Uniques.begin(), Uniques.end());
443-
std::vector<uint32_t>::iterator P =
444-
std::unique(Uniques.begin(), Uniques.end());
443+
std::vector<uint32_t>::iterator P = llvm::unique(Uniques);
445444

446445
UniqueHashCount = std::distance(Uniques.begin(), P);
447446

bolt/lib/Core/Relocation.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ static bool isSupportedRISCV(uint32_t Type) {
123123
case ELF::R_RISCV_LO12_S:
124124
case ELF::R_RISCV_64:
125125
case ELF::R_RISCV_TLS_GOT_HI20:
126+
case ELF::R_RISCV_TLS_GD_HI20:
126127
case ELF::R_RISCV_TPREL_HI20:
127128
case ELF::R_RISCV_TPREL_ADD:
128129
case ELF::R_RISCV_TPREL_LO12_I:
@@ -236,6 +237,7 @@ static size_t getSizeForTypeRISCV(uint32_t Type) {
236237
case ELF::R_RISCV_64:
237238
case ELF::R_RISCV_GOT_HI20:
238239
case ELF::R_RISCV_TLS_GOT_HI20:
240+
case ELF::R_RISCV_TLS_GD_HI20:
239241
// See extractValueRISCV for why this is necessary.
240242
return 8;
241243
}
@@ -491,6 +493,7 @@ static uint64_t extractValueRISCV(uint32_t Type, uint64_t Contents,
491493
return extractBImmRISCV(Contents);
492494
case ELF::R_RISCV_GOT_HI20:
493495
case ELF::R_RISCV_TLS_GOT_HI20:
496+
case ELF::R_RISCV_TLS_GD_HI20:
494497
// We need to know the exact address of the GOT entry so we extract the
495498
// value from both the AUIPC and L[D|W]. We cannot rely on the symbol in the
496499
// relocation for this since it simply refers to the object that is stored
@@ -707,6 +710,7 @@ static bool isPCRelativeRISCV(uint32_t Type) {
707710
case ELF::R_RISCV_RVC_BRANCH:
708711
case ELF::R_RISCV_32_PCREL:
709712
case ELF::R_RISCV_TLS_GOT_HI20:
713+
case ELF::R_RISCV_TLS_GD_HI20:
710714
return true;
711715
}
712716
}

bolt/lib/Profile/YAMLProfileWriter.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,9 @@ std::vector<yaml::bolt::PseudoProbeInfo>
133133
YAMLProfileWriter::convertNodeProbes(NodeIdToProbes &NodeProbes) {
134134
struct BlockProbeInfoHasher {
135135
size_t operator()(const yaml::bolt::PseudoProbeInfo &BPI) const {
136-
auto HashCombine = [](auto &Range) {
137-
return llvm::hash_combine_range(Range.begin(), Range.end());
138-
};
139-
return llvm::hash_combine(HashCombine(BPI.BlockProbes),
140-
HashCombine(BPI.CallProbes),
141-
HashCombine(BPI.IndCallProbes));
136+
return llvm::hash_combine(llvm::hash_combine_range(BPI.BlockProbes),
137+
llvm::hash_combine_range(BPI.CallProbes),
138+
llvm::hash_combine_range(BPI.IndCallProbes));
142139
}
143140
};
144141

bolt/lib/Rewrite/RewriteInstance.cpp

+33-7
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ UseGnuStack("use-gnu-stack",
237237
cl::ZeroOrMore,
238238
cl::cat(BoltCategory));
239239

240+
static cl::opt<uint64_t> CustomAllocationVMA(
241+
"custom-allocation-vma",
242+
cl::desc("use a custom address at which new code will be put, "
243+
"bypassing BOLT's logic to detect where to put code"),
244+
cl::Hidden, cl::cat(BoltCategory));
245+
240246
static cl::opt<bool>
241247
SequentialDisassembly("sequential-disassembly",
242248
cl::desc("performs disassembly sequentially"),
@@ -592,6 +598,25 @@ Error RewriteInstance::discoverStorage() {
592598

593599
FirstNonAllocatableOffset = NextAvailableOffset;
594600

601+
if (opts::CustomAllocationVMA) {
602+
// If user specified a custom address where we should start writing new
603+
// data, honor that.
604+
NextAvailableAddress = opts::CustomAllocationVMA;
605+
// Sanity check the user-supplied address and emit warnings if something
606+
// seems off.
607+
for (const ELF64LE::Phdr &Phdr : PHs) {
608+
switch (Phdr.p_type) {
609+
case ELF::PT_LOAD:
610+
if (NextAvailableAddress >= Phdr.p_vaddr &&
611+
NextAvailableAddress < Phdr.p_vaddr + Phdr.p_memsz) {
612+
BC->errs() << "BOLT-WARNING: user-supplied allocation vma 0x"
613+
<< Twine::utohexstr(NextAvailableAddress)
614+
<< " conflicts with ELF segment at 0x"
615+
<< Twine::utohexstr(Phdr.p_vaddr) << "\n";
616+
}
617+
}
618+
}
619+
}
595620
NextAvailableAddress = alignTo(NextAvailableAddress, BC->PageAlign);
596621
NextAvailableOffset = alignTo(NextAvailableOffset, BC->PageAlign);
597622

@@ -1055,10 +1080,11 @@ void RewriteInstance::discoverFileObjects() {
10551080
continue;
10561081
}
10571082

1058-
if (!Section->isText()) {
1083+
if (!Section->isText() || Section->isVirtual()) {
10591084
assert(SymbolType != SymbolRef::ST_Function &&
10601085
"unexpected function inside non-code section");
1061-
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: rejecting as symbol is not in code\n");
1086+
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: rejecting as symbol is not in code or "
1087+
"is in nobits section\n");
10621088
registerName(SymbolSize);
10631089
continue;
10641090
}
@@ -2926,12 +2952,12 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
29262952

29272953
if (BinaryData *BD = BC->getBinaryDataContainingAddress(SymbolAddress)) {
29282954
// Note: this assertion is trying to check sanity of BinaryData objects
2929-
// but AArch64 has inferred and incomplete object locations coming from
2930-
// GOT/TLS or any other non-trivial relocation (that requires creation
2931-
// of sections and whose symbol address is not really what should be
2932-
// encoded in the instruction). So we essentially disabled this check
2955+
// but AArch64 and RISCV has inferred and incomplete object locations
2956+
// coming from GOT/TLS or any other non-trivial relocation (that requires
2957+
// creation of sections and whose symbol address is not really what should
2958+
// be encoded in the instruction). So we essentially disabled this check
29332959
// for AArch64 and live with bogus names for objects.
2934-
assert((IsAArch64 || IsSectionRelocation ||
2960+
assert((IsAArch64 || BC->isRISCV() || IsSectionRelocation ||
29352961
BD->nameStartsWith(SymbolName) ||
29362962
BD->nameStartsWith("PG" + SymbolName) ||
29372963
(BD->nameStartsWith("ANONYMOUS") &&

bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2336,7 +2336,7 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
23362336
std::optional<Relocation>
23372337
createRelocation(const MCFixup &Fixup,
23382338
const MCAsmBackend &MAB) const override {
2339-
const MCFixupKindInfo &FKI = MAB.getFixupKindInfo(Fixup.getKind());
2339+
MCFixupKindInfo FKI = MAB.getFixupKindInfo(Fixup.getKind());
23402340

23412341
assert(FKI.TargetOffset == 0 && "0-bit relocation offset expected");
23422342
const uint64_t RelOffset = Fixup.getOffset();

0 commit comments

Comments
 (0)