Skip to content

Commit b20891a

Browse files
committed
rebase
Created using spr 1.3.7
2 parents 1966b6c + a8a0ffb commit b20891a

File tree

186 files changed

+10267
-777
lines changed

Some content is hidden

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

186 files changed

+10267
-777
lines changed

.github/workflows/build-ci-container-windows.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
- build-ci-container-windows
5757
permissions:
5858
packages: write
59-
runs-on: windows-2022
59+
runs-on: ubuntu-24.04
6060
env:
6161
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6262
steps:
@@ -66,8 +66,12 @@ jobs:
6666
name: container
6767
- name: Push Container
6868
run: |
69-
docker load -i ${{ needs.build-ci-container-windows.outputs.container-filename }}
70-
docker tag ${{ needs.build-ci-container-windows.outputs.container-name-tag }} ${{ needs.build-ci-container-windows.outputs.container-name }}:latest
71-
docker login -u ${{ github.actor }} -p $env:GITHUB_TOKEN ghcr.io
72-
docker push ${{ needs.build-ci-container-windows.outputs.container-name-tag }}
73-
docker push ${{ needs.build-ci-container-windows.outputs.container-name }}:latest
69+
sudo apt-get update
70+
sudo apt-get install -y skopeo
71+
skopeo login -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} ghcr.io
72+
skopeo copy docker-archive:${{ needs.build-ci-container-windows.outputs.container-filename }} \
73+
--dest-compress-format zstd \
74+
docker://${{ needs.build-ci-container-windows.outputs.container-name-tag }}
75+
skopeo copy docker-archive:${{ needs.build-ci-container-windows.outputs.container-filename }} \
76+
--dest-compress-format zstd \
77+
docker://${{ needs.build-ci-container-windows.outputs.container-name }}:latest

bolt/include/bolt/Rewrite/MetadataRewriters.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ class BinaryContext;
1919

2020
// The list of rewriter build functions.
2121

22-
std::unique_ptr<MetadataRewriter> createLinuxKernelRewriter(BinaryContext &);
23-
2422
std::unique_ptr<MetadataRewriter> createBuildIDRewriter(BinaryContext &);
2523

24+
std::unique_ptr<MetadataRewriter> createLinuxKernelRewriter(BinaryContext &);
25+
2626
std::unique_ptr<MetadataRewriter> createPseudoProbeRewriter(BinaryContext &);
2727

28+
std::unique_ptr<MetadataRewriter> createRSeqRewriter(BinaryContext &);
29+
2830
std::unique_ptr<MetadataRewriter> createSDTRewriter(BinaryContext &);
2931

3032
std::unique_ptr<MetadataRewriter> createGNUPropertyRewriter(BinaryContext &);

bolt/lib/Rewrite/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ add_llvm_library(LLVMBOLTRewrite
2424
BuildIDRewriter.cpp
2525
PseudoProbeRewriter.cpp
2626
RewriteInstance.cpp
27+
RSeqRewriter.cpp
2728
SDTRewriter.cpp
2829
GNUPropertyRewriter.cpp
2930

bolt/lib/Rewrite/RSeqRewriter.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//===- bolt/Rewrite/RSeqRewriter.cpp --------------------------------------===//
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+
// Basic support for restartable sequences used by tcmalloc. Prevent critical
10+
// section overrides by ignoring optimizations in containing functions.
11+
//
12+
// References:
13+
// * https://google.github.io/tcmalloc/rseq.html
14+
// * tcmalloc/internal/percpu_rseq_x86_64.S
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
#include "bolt/Core/BinaryFunction.h"
19+
#include "bolt/Rewrite/MetadataRewriter.h"
20+
#include "bolt/Rewrite/MetadataRewriters.h"
21+
#include "llvm/Support/Errc.h"
22+
23+
using namespace llvm;
24+
using namespace bolt;
25+
26+
namespace {
27+
28+
class RSeqRewriter final : public MetadataRewriter {
29+
public:
30+
RSeqRewriter(StringRef Name, BinaryContext &BC)
31+
: MetadataRewriter(Name, BC) {}
32+
33+
Error preCFGInitializer() override {
34+
for (const BinarySection &Section : BC.allocatableSections()) {
35+
if (Section.getName() != "__rseq_cs")
36+
continue;
37+
38+
auto handleRelocation = [&](const Relocation &Rel, bool IsDynamic) {
39+
BinaryFunction *BF = nullptr;
40+
if (Rel.Symbol)
41+
BF = BC.getFunctionForSymbol(Rel.Symbol);
42+
else if (Relocation::isRelative(Rel.Type))
43+
BF = BC.getBinaryFunctionContainingAddress(Rel.Addend);
44+
45+
if (!BF) {
46+
BC.errs() << "BOLT-WARNING: no function found matching "
47+
<< (IsDynamic ? "dynamic " : "")
48+
<< "relocation in __rseq_cs\n";
49+
} else if (!BF->isIgnored()) {
50+
BC.outs() << "BOLT-INFO: restartable sequence reference detected in "
51+
<< *BF << ". Function will not be optimized\n";
52+
BF->setIgnored();
53+
}
54+
};
55+
56+
for (const Relocation &Rel : Section.dynamicRelocations())
57+
handleRelocation(Rel, /*IsDynamic*/ true);
58+
59+
for (const Relocation &Rel : Section.relocations())
60+
handleRelocation(Rel, /*IsDynamic*/ false);
61+
}
62+
63+
return Error::success();
64+
}
65+
};
66+
67+
} // namespace
68+
69+
std::unique_ptr<MetadataRewriter>
70+
llvm::bolt::createRSeqRewriter(BinaryContext &BC) {
71+
return std::make_unique<RSeqRewriter>("rseq-cs-rewriter", BC);
72+
}

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3346,6 +3346,8 @@ void RewriteInstance::initializeMetadataManager() {
33463346

33473347
MetadataManager.registerRewriter(createPseudoProbeRewriter(*BC));
33483348

3349+
MetadataManager.registerRewriter(createRSeqRewriter(*BC));
3350+
33493351
MetadataManager.registerRewriter(createSDTRewriter(*BC));
33503352

33513353
MetadataManager.registerRewriter(createGNUPropertyRewriter(*BC));

bolt/test/X86/rseq.s

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## Check that llvm-bolt avoids optimization of functions referenced from
2+
## __rseq_cs section, i.e. containing critical sections and abort handlers used
3+
## by restartable sequences in tcmalloc.
4+
5+
# RUN: %clang %cflags %s -o %t -nostdlib -no-pie -Wl,-q
6+
# RUN: llvm-bolt %t -o %t.bolt --print-cfg 2>&1 | FileCheck %s
7+
# RUN: %clang %cflags %s -o %t.pie -nostdlib -pie -Wl,-q
8+
# RUN: llvm-bolt %t.pie -o %t.pie.bolt 2>&1 | FileCheck %s
9+
10+
# CHECK: restartable sequence reference detected in _start
11+
# CHECK: restartable sequence reference detected in __rseq_abort
12+
13+
## Force relocations against .text
14+
.text
15+
.reloc 0, R_X86_64_NONE
16+
17+
.global _start
18+
.type _start, %function
19+
_start:
20+
pushq %rbp
21+
mov %rsp, %rbp
22+
.L1:
23+
pop %rbp
24+
.L2:
25+
retq
26+
.size _start, .-_start
27+
28+
.section __rseq_abort, "ax"
29+
## Signature for rseq abort IP. Unmarked in the symbol table.
30+
.byte 0x0f, 0x1f, 0x05
31+
.long 0x42424242
32+
.L3:
33+
jmp .L2
34+
35+
.section __rseq_cs, "aw"
36+
.balign 32
37+
.quad .L1
38+
.quad .L3

clang-tools-extra/clang-tidy/.clang-tidy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Checks: >
1515
performance-*,
1616
-performance-enum-size,
1717
-performance-no-int-to-ptr,
18-
-performance-unnecessary-value-param,
1918
readability-*,
2019
-readability-avoid-nested-conditional-operator,
2120
-readability-braces-around-statements,

clang-tools-extra/clang-tidy/ClangTidy.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@ ClangTidyASTConsumerFactory::createASTConsumer(
455455

456456
if (Context.canEnableModuleHeadersParsing() &&
457457
Context.getLangOpts().Modules && OverlayFS != nullptr) {
458-
auto ModuleExpander =
459-
std::make_unique<ExpandModularHeadersPPCallbacks>(&Compiler, OverlayFS);
458+
auto ModuleExpander = std::make_unique<ExpandModularHeadersPPCallbacks>(
459+
&Compiler, *OverlayFS);
460460
ModuleExpanderPP = ModuleExpander->getPreprocessor();
461461
PP->addPPCallbacks(std::move(ModuleExpander));
462462
}

clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ class ExpandModularHeadersPPCallbacks::FileRecorder {
6565
};
6666

6767
ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
68-
CompilerInstance *CI,
69-
IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFS)
68+
CompilerInstance *CI, llvm::vfs::OverlayFileSystem &OverlayFS)
7069
: Recorder(std::make_unique<FileRecorder>()), Compiler(*CI),
7170
InMemoryFs(new llvm::vfs::InMemoryFileSystem),
7271
Sources(Compiler.getSourceManager()),
@@ -76,7 +75,7 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
7675
LangOpts(Compiler.getLangOpts()), HSOpts(Compiler.getHeaderSearchOpts()) {
7776
// Add a FileSystem containing the extra files needed in place of modular
7877
// headers.
79-
OverlayFS->pushOverlay(InMemoryFs);
78+
OverlayFS.pushOverlay(InMemoryFs);
8079

8180
Diags.setSourceManager(&Sources);
8281
// FIXME: Investigate whatever is there better way to initialize DiagEngine

clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ namespace tooling {
4141
/// non-modular way.
4242
class ExpandModularHeadersPPCallbacks : public PPCallbacks {
4343
public:
44-
ExpandModularHeadersPPCallbacks(
45-
CompilerInstance *CI,
46-
IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFS);
44+
ExpandModularHeadersPPCallbacks(CompilerInstance *CI,
45+
llvm::vfs::OverlayFileSystem &OverlayFS);
4746
~ExpandModularHeadersPPCallbacks() override;
4847

4948
/// Returns the preprocessor that provides callbacks for the whole

0 commit comments

Comments
 (0)