Skip to content

Commit 4e5c743

Browse files
committed
Merge remote-tracking branch 'origin/main' into vplan-runtime-checks
2 parents 1b89761 + 4fb953a commit 4e5c743

File tree

3,303 files changed

+102437
-49865
lines changed

Some content is hidden

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

3,303 files changed

+102437
-49865
lines changed

.github/workflows/libcxx-build-and-test.yaml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ env:
4949
jobs:
5050
stage1:
5151
if: github.repository_owner == 'llvm'
52-
runs-on: libcxx-runners-8-set
52+
runs-on: libcxx-runners-set
53+
container: ghcr.io/libcxx/actions-builder:testing-2024-09-21
5354
continue-on-error: false
5455
strategy:
5556
fail-fast: false
@@ -85,7 +86,8 @@ jobs:
8586
**/crash_diagnostics/*
8687
stage2:
8788
if: github.repository_owner == 'llvm'
88-
runs-on: libcxx-runners-8-set
89+
runs-on: libcxx-runners-set
90+
container: ghcr.io/libcxx/actions-builder:testing-2024-09-21
8991
needs: [ stage1 ]
9092
continue-on-error: false
9193
strategy:
@@ -162,20 +164,21 @@ jobs:
162164
'benchmarks',
163165
'bootstrapping-build'
164166
]
165-
machine: [ 'libcxx-runners-8-set' ]
167+
machine: [ 'libcxx-runners-set' ]
166168
include:
167169
- config: 'generic-cxx26'
168-
machine: libcxx-runners-8-set
170+
machine: libcxx-runners-set
169171
- config: 'generic-asan'
170-
machine: libcxx-runners-8-set
172+
machine: libcxx-runners-set
171173
- config: 'generic-tsan'
172-
machine: libcxx-runners-8-set
174+
machine: libcxx-runners-set
173175
- config: 'generic-ubsan'
174-
machine: libcxx-runners-8-set
176+
machine: libcxx-runners-set
175177
# Use a larger machine for MSAN to avoid timeout and memory allocation issues.
176178
- config: 'generic-msan'
177-
machine: libcxx-runners-8-set
179+
machine: libcxx-runners-set
178180
runs-on: ${{ matrix.machine }}
181+
container: ghcr.io/libcxx/actions-builder:testing-2024-09-21
179182
steps:
180183
- uses: actions/checkout@v4
181184
- name: ${{ matrix.config }}

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,9 +789,44 @@ void RewriteInstance::discoverFileObjects() {
789789
BinarySection Section(*BC, *cantFail(Sym.getSection()));
790790
return Section.isAllocatable();
791791
};
792+
auto checkSymbolInSection = [this](const SymbolInfo &S) {
793+
// Sometimes, we encounter symbols with addresses outside their section. If
794+
// such symbols happen to fall into another section, they can interfere with
795+
// disassembly. Notably, this occurs with AArch64 marker symbols ($d and $t)
796+
// that belong to .eh_frame, but end up pointing into .text.
797+
// As a workaround, we ignore all symbols that lie outside their sections.
798+
auto Section = cantFail(S.Symbol.getSection());
799+
800+
// Accept all absolute symbols.
801+
if (Section == InputFile->section_end())
802+
return true;
803+
804+
uint64_t SecStart = Section->getAddress();
805+
uint64_t SecEnd = SecStart + Section->getSize();
806+
uint64_t SymEnd = S.Address + ELFSymbolRef(S.Symbol).getSize();
807+
if (S.Address >= SecStart && SymEnd <= SecEnd)
808+
return true;
809+
810+
auto SymType = cantFail(S.Symbol.getType());
811+
// Skip warnings for common benign cases.
812+
if (opts::Verbosity < 1 && SymType == SymbolRef::ST_Other)
813+
return false; // E.g. ELF::STT_TLS.
814+
815+
auto SymName = S.Symbol.getName();
816+
auto SecName = cantFail(S.Symbol.getSection())->getName();
817+
BC->errs() << "BOLT-WARNING: ignoring symbol "
818+
<< (SymName ? *SymName : "[unnamed]") << " at 0x"
819+
<< Twine::utohexstr(S.Address) << ", which lies outside "
820+
<< (SecName ? *SecName : "[unnamed]") << "\n";
821+
822+
return false;
823+
};
792824
for (const SymbolRef &Symbol : InputFile->symbols())
793-
if (isSymbolInMemory(Symbol))
794-
SortedSymbols.push_back({cantFail(Symbol.getAddress()), Symbol});
825+
if (isSymbolInMemory(Symbol)) {
826+
SymbolInfo SymInfo{cantFail(Symbol.getAddress()), Symbol};
827+
if (checkSymbolInSection(SymInfo))
828+
SortedSymbols.push_back(SymInfo);
829+
}
795830

796831
auto CompareSymbols = [this](const SymbolInfo &A, const SymbolInfo &B) {
797832
if (A.Address != B.Address)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
--- !ELF
2+
FileHeader:
3+
Class: ELFCLASS64
4+
Data: ELFDATA2LSB
5+
Type: ET_EXEC
6+
Machine: EM_AARCH64
7+
Entry: 0x2a0000
8+
ProgramHeaders:
9+
- Type: PT_PHDR
10+
Flags: [ PF_R ]
11+
VAddr: 0x40
12+
Align: 0x8
13+
FileSize: 0xa8
14+
MemSize: 0xa8
15+
Offset: 0x40
16+
- Type: PT_LOAD
17+
Flags: [ PF_R ]
18+
VAddr: 0x0
19+
Align: 0x10000
20+
FileSize: 0xf8
21+
MemSize: 0xf8
22+
Offset: 0x0
23+
- Type: PT_LOAD
24+
Flags: [ PF_X, PF_R ]
25+
VAddr: 0x2a0000
26+
Align: 0x10000
27+
FirstSec: .text
28+
LastSec: .ignored
29+
Sections:
30+
- Name: .text
31+
Type: SHT_PROGBITS
32+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
33+
Address: 0x2a0000
34+
AddressAlign: 0x4
35+
Content: 400580d2c0035fd6
36+
- Name: .ignored
37+
Type: SHT_PROGBITS
38+
Flags: [ SHF_ALLOC ]
39+
Address: 0x2a0008
40+
AddressAlign: 0x8
41+
Size: 0x8
42+
- Name: .eh_frame
43+
Type: SHT_PROGBITS
44+
Flags: [ SHF_ALLOC ]
45+
Address: 0x2a0010
46+
AddressAlign: 0x8
47+
Content: 1000000000000000017a520004781e010b0c1f00140000001800000000002a0008000000000e01410e010000
48+
Symbols:
49+
- Name: func
50+
Section: .text
51+
Value: 0x2a0000
52+
Size: 0x8
53+
- Name: '$d.42'
54+
Section: .ignored
55+
Value: 0x2a0004
56+
...
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Check that marker symbols ($d, $x) denoting data embedded in code are ignored
2+
// if they fall outside their respective sections.
3+
4+
// RUN: yaml2obj %S/Inputs/spurious-marker-symbol.yaml -o %t.exe
5+
// RUN: llvm-bolt %t.exe -o %t.bolt 2>&1 | FileCheck %s
6+
// CHECK: 1 out of 1 functions were overwritten
7+
// RUN: llvm-objdump -j .text -d %t.bolt | FileCheck %s -check-prefix=CHECK-DISASM
8+
// CHECK-DISASM: func
9+
// CHECK-DISASM: 2a0000: d2800540 mov
10+
// CHECK-DISASM: 2a0004: d65f03c0 ret
11+
12+
// The YAML encodes the following assembly and debug information:
13+
14+
.text
15+
.globl func
16+
.type func, %function
17+
func:
18+
mov x0, #42
19+
// $d.42: (symbol in .ignored, with an address in .text)
20+
ret
21+
22+
// .eh_frame contains minimal DWARF with a CFA operation on the `ret`. BOLT
23+
// should ignore the spurious `$d.42`. If it doesn't, then it will stop
24+
// disassembling after the `mov` and will fail to process the second
25+
// DW_CFA_def_cfa_offset.
26+
//
27+
// CIE
28+
// length: 00000010
29+
// CIE_id: 00000000
30+
// version: 01
31+
// augmentation:
32+
// "zR" 7a 52 00
33+
// - read augmentation data
34+
// - read FDE pointer encoding
35+
// code_alignment_factor: 04
36+
// data_alignment_factor: 78 (-8)
37+
// return_address_register: 1e (r30 / lr)
38+
//
39+
// augmentation data:
40+
// length: 01
41+
// FDE pointers are absptr+sdata4 0b
42+
//
43+
// initial_instructions:
44+
// DW_CFA_def_cfa (31, 0): 0c 1f 00
45+
//
46+
// Encoding: 10000000'00000000'01'7a5200'04'78'1e'10'0b'0c1f00
47+
//
48+
// FDE
49+
// length: 00000014
50+
// CIE_pointer: 00000018 (backwards offset from here to CIE)
51+
// initial_location: 002a0000 (`func` as absptr+sdata4)
52+
// address_range: 00000008
53+
// augmentation data:
54+
// length: 00
55+
// instructions:
56+
// DW_CFA_def_cfa_offset (1) 0e 01
57+
// DW_CFA_advance_loc (1) 41 (`ret` at 0x2a0004)
58+
// DW_CFA_def_cfa_offset (1) 0e 01 Fails unless $d.42 is ignored.
59+
// DW_CFA_nop 00 00
60+
//
61+
// Encoding: 14000000'18000000'00002a00'08000000'000e0141'0e010000

clang-tools-extra/clang-include-fixer/InMemorySymbolIndex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ InMemorySymbolIndex::InMemorySymbolIndex(
2121

2222
std::vector<SymbolAndSignals>
2323
InMemorySymbolIndex::search(llvm::StringRef Identifier) {
24-
auto I = LookupTable.find(std::string(Identifier));
24+
auto I = LookupTable.find(Identifier);
2525
if (I != LookupTable.end())
2626
return I->second;
2727
return {};

clang-tools-extra/clang-include-fixer/InMemorySymbolIndex.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class InMemorySymbolIndex : public SymbolIndex {
2727
search(llvm::StringRef Identifier) override;
2828

2929
private:
30-
std::map<std::string, std::vector<find_all_symbols::SymbolAndSignals>>
30+
std::map<std::string, std::vector<find_all_symbols::SymbolAndSignals>,
31+
std::less<>>
3132
LookupTable;
3233
};
3334

clang-tools-extra/clang-query/Query.cpp

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ bool HelpQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
4444
" set bind-root (true|false) "
4545
"Set whether to bind the root matcher to \"root\".\n"
4646
" set print-matcher (true|false) "
47-
"Set whether to print the current matcher,\n"
47+
"Set whether to print the current matcher.\n"
48+
" set enable-profile (true|false) "
49+
"Set whether to enable matcher profiling.\n"
4850
" set traversal <kind> "
4951
"Set traversal kind of clang-query session. Available kinds are:\n"
5052
" AsIs "
@@ -82,27 +84,53 @@ namespace {
8284

8385
struct CollectBoundNodes : MatchFinder::MatchCallback {
8486
std::vector<BoundNodes> &Bindings;
85-
CollectBoundNodes(std::vector<BoundNodes> &Bindings) : Bindings(Bindings) {}
87+
StringRef Unit;
88+
CollectBoundNodes(std::vector<BoundNodes> &Bindings, StringRef Unit)
89+
: Bindings(Bindings), Unit(Unit) {}
8690
void run(const MatchFinder::MatchResult &Result) override {
8791
Bindings.push_back(Result.Nodes);
8892
}
93+
StringRef getID() const override { return Unit; }
94+
};
95+
96+
struct QueryProfiler {
97+
llvm::StringMap<llvm::TimeRecord> Records;
98+
99+
~QueryProfiler() {
100+
llvm::TimerGroup TG("clang-query", "clang-query matcher profiling",
101+
Records);
102+
TG.print(llvm::errs());
103+
llvm::errs().flush();
104+
}
89105
};
90106

91107
} // namespace
92108

93109
bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
94110
unsigned MatchCount = 0;
95111

112+
std::optional<QueryProfiler> Profiler;
113+
if (QS.EnableProfile)
114+
Profiler.emplace();
115+
96116
for (auto &AST : QS.ASTs) {
97-
MatchFinder Finder;
117+
ast_matchers::MatchFinder::MatchFinderOptions FinderOptions;
118+
std::optional<llvm::StringMap<llvm::TimeRecord>> Records;
119+
if (QS.EnableProfile) {
120+
Records.emplace();
121+
FinderOptions.CheckProfiling.emplace(*Records);
122+
}
123+
124+
MatchFinder Finder(FinderOptions);
98125
std::vector<BoundNodes> Matches;
99126
DynTypedMatcher MaybeBoundMatcher = Matcher;
100127
if (QS.BindRoot) {
101128
std::optional<DynTypedMatcher> M = Matcher.tryBind("root");
102129
if (M)
103130
MaybeBoundMatcher = *M;
104131
}
105-
CollectBoundNodes Collect(Matches);
132+
StringRef OrigSrcName = AST->getOriginalSourceFileName();
133+
CollectBoundNodes Collect(Matches, OrigSrcName);
106134
if (!Finder.addDynamicMatcher(MaybeBoundMatcher, &Collect)) {
107135
OS << "Not a valid top-level matcher.\n";
108136
return false;
@@ -111,6 +139,8 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
111139
ASTContext &Ctx = AST->getASTContext();
112140
Ctx.getParentMapContext().setTraversalKind(QS.TK);
113141
Finder.matchAST(Ctx);
142+
if (QS.EnableProfile)
143+
Profiler->Records[OrigSrcName] += (*Records)[OrigSrcName];
114144

115145
if (QS.PrintMatcher) {
116146
SmallVector<StringRef, 4> Lines;

clang-tools-extra/clang-query/QueryParser.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ enum ParsedQueryVariable {
182182
PQV_Output,
183183
PQV_BindRoot,
184184
PQV_PrintMatcher,
185+
PQV_EnableProfile,
185186
PQV_Traversal
186187
};
187188

@@ -285,6 +286,7 @@ QueryRef QueryParser::doParse() {
285286
.Case("output", PQV_Output)
286287
.Case("bind-root", PQV_BindRoot)
287288
.Case("print-matcher", PQV_PrintMatcher)
289+
.Case("enable-profile", PQV_EnableProfile)
288290
.Case("traversal", PQV_Traversal)
289291
.Default(PQV_Invalid);
290292
if (VarStr.empty())
@@ -303,6 +305,9 @@ QueryRef QueryParser::doParse() {
303305
case PQV_PrintMatcher:
304306
Q = parseSetBool(&QuerySession::PrintMatcher);
305307
break;
308+
case PQV_EnableProfile:
309+
Q = parseSetBool(&QuerySession::EnableProfile);
310+
break;
306311
case PQV_Traversal:
307312
Q = parseSetTraversalKind(&QuerySession::TK);
308313
break;

clang-tools-extra/clang-query/QuerySession.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class QuerySession {
2626
QuerySession(llvm::ArrayRef<std::unique_ptr<ASTUnit>> ASTs)
2727
: ASTs(ASTs), PrintOutput(false), DiagOutput(true),
2828
DetailedASTOutput(false), BindRoot(true), PrintMatcher(false),
29-
Terminate(false), TK(TK_AsIs) {}
29+
EnableProfile(false), Terminate(false), TK(TK_AsIs) {}
3030

3131
llvm::ArrayRef<std::unique_ptr<ASTUnit>> ASTs;
3232

@@ -36,6 +36,7 @@ class QuerySession {
3636

3737
bool BindRoot;
3838
bool PrintMatcher;
39+
bool EnableProfile;
3940
bool Terminate;
4041

4142
TraversalKind TK;

clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ std::optional<DurationScale> getScaleForDurationInverse(llvm::StringRef Name) {
244244
{"ToDoubleNanoseconds", DurationScale::Nanoseconds},
245245
{"ToInt64Nanoseconds", DurationScale::Nanoseconds}});
246246

247-
auto ScaleIter = ScaleMap.find(std::string(Name));
247+
auto ScaleIter = ScaleMap.find(Name);
248248
if (ScaleIter == ScaleMap.end())
249249
return std::nullopt;
250250

@@ -260,7 +260,7 @@ std::optional<DurationScale> getScaleForTimeInverse(llvm::StringRef Name) {
260260
{"ToUnixMicros", DurationScale::Microseconds},
261261
{"ToUnixNanos", DurationScale::Nanoseconds}});
262262

263-
auto ScaleIter = ScaleMap.find(std::string(Name));
263+
auto ScaleIter = ScaleMap.find(Name);
264264
if (ScaleIter == ScaleMap.end())
265265
return std::nullopt;
266266

0 commit comments

Comments
 (0)