Skip to content

Commit 122784f

Browse files
Merge branch 'main' into users/boomanaiden154/build-metrics-container
2 parents 0522707 + 77c2b00 commit 122784f

File tree

2,032 files changed

+99444
-31651
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,032 files changed

+99444
-31651
lines changed

.ci/generate_test_report.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def junit_from_xml(xml):
1818

1919
class TestReports(unittest.TestCase):
2020
def test_title_only(self):
21-
self.assertEqual(_generate_report("Foo", []), ("", None))
21+
self.assertEqual(_generate_report("Foo", []), ("", "success"))
2222

2323
def test_no_tests_in_testsuite(self):
2424
self.assertEqual(
@@ -336,7 +336,7 @@ def _generate_report(title, junit_objects, size_limit=1024 * 1024, list_failures
336336
)
337337

338338
if not tests_run:
339-
return ("", style)
339+
return ("", None)
340340

341341
style = "error" if tests_failed else "success"
342342
report = [f"# {title}", ""]

.ci/metrics/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
<<<<<<< HEAD
12
FROM python:3.12
3+
=======
4+
FROM docker.io/python:3.12
5+
>>>>>>> main
26

37
COPY requirements.lock.txt ./
48
RUN pip3 install --no-cache-dir -r requirements.lock.txt

.ci/metrics/metrics.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import time
33
import os
44
from dataclasses import dataclass
5+
import sys
56

7+
import github
68
from github import Github
79
from github import Auth
810

@@ -11,6 +13,7 @@
1113
)
1214
GITHUB_PROJECT = "llvm/llvm-project"
1315
WORKFLOWS_TO_TRACK = ["Check code formatting"]
16+
SCRAPE_INTERVAL_SECONDS = 5 * 60
1417

1518

1619
@dataclass
@@ -23,7 +26,7 @@ class JobMetrics:
2326
workflow_id: int
2427

2528

26-
def get_metrics(github_repo, workflows_to_track):
29+
def get_metrics(github_repo: github.Repository, workflows_to_track: dict[str, int]):
2730
"""Gets the metrics for specified Github workflows.
2831
2932
This function takes in a list of workflows to track, and optionally the
@@ -44,25 +47,24 @@ def get_metrics(github_repo, workflows_to_track):
4447

4548
workflow_metrics = []
4649

47-
workflows_to_include = {}
48-
for workflow_to_track in workflows_to_track:
49-
workflows_to_include[workflow_to_track] = True
50-
workflows_left_to_include = len(workflows_to_track)
50+
workflows_to_include = set(workflows_to_track.keys())
5151

52-
while True:
52+
while len(workflows_to_include) > 0:
5353
workflow_run = next(workflow_runs)
5454
if workflow_run.status != "completed":
5555
continue
5656

57-
interesting_workflow = False
58-
for workflow_name in workflows_to_track:
59-
if workflow_run.name == workflow_name:
60-
interesting_workflow = True
61-
break
62-
if not interesting_workflow:
57+
# This workflow was already sampled for this run, or is not tracked at
58+
# all. Ignoring.
59+
if workflow_run.name not in workflows_to_include:
6360
continue
6461

65-
if not workflows_to_include[workflow_run.name]:
62+
# There were no new workflow invocations since the previous scrape.
63+
# The API returns a sorted list with the most recent invocations first,
64+
# so we can stop looking for this particular workflow. Continue to grab
65+
# information on the other workflows of interest, if present.
66+
if workflows_to_track[workflow_run.name] == workflow_run.id:
67+
workflows_to_include.remove(workflow_run.name)
6668
continue
6769

6870
workflow_jobs = workflow_run.jobs()
@@ -89,14 +91,15 @@ def get_metrics(github_repo, workflows_to_track):
8991
workflows_to_track[workflow_run.name] is None
9092
or workflows_to_track[workflow_run.name] == workflow_run.id
9193
):
92-
workflows_left_to_include -= 1
93-
workflows_to_include[workflow_run.name] = False
94+
workflows_to_include.remove(workflow_run.name)
9495
if (
9596
workflows_to_track[workflow_run.name] is not None
96-
and workflows_left_to_include == 0
97+
and len(workflows_to_include) == 0
9798
):
9899
break
99100

101+
# The timestamp associated with the event is expected by Grafana to be
102+
# in nanoseconds.
100103
created_at_ns = int(created_at.timestamp()) * 10**9
101104

102105
workflow_metrics.append(
@@ -110,9 +113,6 @@ def get_metrics(github_repo, workflows_to_track):
110113
)
111114
)
112115

113-
if workflows_left_to_include == 0:
114-
break
115-
116116
return workflow_metrics
117117

118118

@@ -143,7 +143,9 @@ def upload_metrics(workflow_metrics, metrics_userid, api_key):
143143
)
144144

145145
if response.status_code < 200 or response.status_code >= 300:
146-
print(f"Failed to submit data to Grafana: {response.status_code}")
146+
print(
147+
f"Failed to submit data to Grafana: {response.status_code}", file=sys.stderr
148+
)
147149

148150

149151
def main():
@@ -164,16 +166,16 @@ def main():
164166
while True:
165167
current_metrics = get_metrics(github_repo, workflows_to_track)
166168
if len(current_metrics) == 0:
167-
print("No metrics found to upload.")
169+
print("No metrics found to upload.", file=sys.stderr)
168170
continue
169171

170172
upload_metrics(current_metrics, grafana_metrics_userid, grafana_api_key)
171-
print(f"Uploaded {len(current_metrics)} metrics")
173+
print(f"Uploaded {len(current_metrics)} metrics", file=sys.stderr)
172174

173175
for workflow_metric in reversed(current_metrics):
174176
workflows_to_track[workflow_metric.job_name] = workflow_metric.workflow_id
175177

176-
time.sleep(5 * 60)
178+
time.sleep(SCRAPE_INTERVAL_SECONDS)
177179

178180

179181
if __name__ == "__main__":

.github/new-issues-labeler.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,9 @@
3030

3131
'infra:commit-access-request':
3232
- '/Request Commit Access/'
33+
34+
'false-positive':
35+
- '\bfalse[- ]positive\b'
36+
37+
'false-negative':
38+
- '\bfalse[- ]negative\b'

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,6 +2407,19 @@ inline raw_ostream &operator<<(raw_ostream &OS,
24072407
return OS;
24082408
}
24092409

2410+
/// Compare function by index if it is valid, fall back to the original address
2411+
/// otherwise.
2412+
inline bool compareBinaryFunctionByIndex(const BinaryFunction *A,
2413+
const BinaryFunction *B) {
2414+
if (A->hasValidIndex() && B->hasValidIndex())
2415+
return A->getIndex() < B->getIndex();
2416+
if (A->hasValidIndex() && !B->hasValidIndex())
2417+
return true;
2418+
if (!A->hasValidIndex() && B->hasValidIndex())
2419+
return false;
2420+
return A->getAddress() < B->getAddress();
2421+
}
2422+
24102423
} // namespace bolt
24112424

24122425
// GraphTraits specializations for function basic block graphs (CFGs)

bolt/lib/Core/BinaryContext.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,13 +1607,7 @@ std::vector<BinaryFunction *> BinaryContext::getSortedFunctions() {
16071607
SortedFunctions.begin(),
16081608
[](BinaryFunction &BF) { return &BF; });
16091609

1610-
llvm::stable_sort(SortedFunctions,
1611-
[](const BinaryFunction *A, const BinaryFunction *B) {
1612-
if (A->hasValidIndex() && B->hasValidIndex()) {
1613-
return A->getIndex() < B->getIndex();
1614-
}
1615-
return A->hasValidIndex();
1616-
});
1610+
llvm::stable_sort(SortedFunctions, compareBinaryFunctionByIndex);
16171611
return SortedFunctions;
16181612
}
16191613

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -385,16 +385,7 @@ bool BinaryFunction::isForwardCall(const MCSymbol *CalleeSymbol) const {
385385
if (CalleeBF) {
386386
if (CalleeBF->isInjected())
387387
return true;
388-
389-
if (hasValidIndex() && CalleeBF->hasValidIndex()) {
390-
return getIndex() < CalleeBF->getIndex();
391-
} else if (hasValidIndex() && !CalleeBF->hasValidIndex()) {
392-
return true;
393-
} else if (!hasValidIndex() && CalleeBF->hasValidIndex()) {
394-
return false;
395-
} else {
396-
return getAddress() < CalleeBF->getAddress();
397-
}
388+
return compareBinaryFunctionByIndex(this, CalleeBF);
398389
} else {
399390
// Absolute symbol.
400391
ErrorOr<uint64_t> CalleeAddressOrError = BC.getSymbolValue(*CalleeSymbol);

bolt/lib/Passes/ReorderFunctions.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -473,16 +473,7 @@ Error ReorderFunctions::runOnFunctions(BinaryContext &BC) {
473473
[](BinaryFunction &BF) { return &BF; });
474474

475475
// Sort functions by index.
476-
llvm::stable_sort(SortedFunctions,
477-
[](const BinaryFunction *A, const BinaryFunction *B) {
478-
if (A->hasValidIndex() && B->hasValidIndex())
479-
return A->getIndex() < B->getIndex();
480-
if (A->hasValidIndex() && !B->hasValidIndex())
481-
return true;
482-
if (!A->hasValidIndex() && B->hasValidIndex())
483-
return false;
484-
return A->getAddress() < B->getAddress();
485-
});
476+
llvm::stable_sort(SortedFunctions, compareBinaryFunctionByIndex);
486477

487478
for (const BinaryFunction *Func : SortedFunctions) {
488479
if (!Func->hasValidIndex())

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2927,6 +2927,23 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
29272927
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: ignoring relocation from data to data\n");
29282928
}
29292929

2930+
static BinaryFunction *getInitFunctionIfStaticBinary(BinaryContext &BC) {
2931+
// Workaround for https://github.com/llvm/llvm-project/issues/100096
2932+
// ("[BOLT] GOT array pointer incorrectly rewritten"). In aarch64
2933+
// static glibc binaries, the .init section's _init function pointer can
2934+
// alias with a data pointer for the end of an array. GOT rewriting
2935+
// currently can't detect this and updates the data pointer to the
2936+
// moved _init, causing a runtime crash. Skipping _init on the other
2937+
// hand should be harmless.
2938+
if (!BC.IsStaticExecutable)
2939+
return nullptr;
2940+
const BinaryData *BD = BC.getBinaryDataByName("_init");
2941+
if (!BD || BD->getSectionName() != ".init")
2942+
return nullptr;
2943+
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: skip _init in for GOT workaround.\n");
2944+
return BC.getBinaryFunctionAtAddress(BD->getAddress());
2945+
}
2946+
29302947
void RewriteInstance::selectFunctionsToProcess() {
29312948
// Extend the list of functions to process or skip from a file.
29322949
auto populateFunctionNames = [](cl::opt<std::string> &FunctionNamesFile,
@@ -3047,6 +3064,9 @@ void RewriteInstance::selectFunctionsToProcess() {
30473064
return true;
30483065
};
30493066

3067+
if (BinaryFunction *Init = getInitFunctionIfStaticBinary(*BC))
3068+
Init->setIgnored();
3069+
30503070
for (auto &BFI : BC->getBinaryFunctions()) {
30513071
BinaryFunction &Function = BFI.second;
30523072

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Regression test for https://github.com/llvm/llvm-project/issues/100096
2+
# static glibc binaries crash on startup because _init is moved and
3+
# shares its address with an array end pointer. The GOT rewriting can't
4+
# tell the two pointers apart and incorrectly updates the _array_end
5+
# address. Test checks that _init is not moved.
6+
7+
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
8+
# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q -static -Wl,--section-start=.data=0x1000 -Wl,--section-start=.init=0x1004
9+
# RUN: llvm-bolt %t.exe -o %t.bolt
10+
# RUN: llvm-nm %t.exe | FileCheck --check-prefix=CHECK-ORIGINAL %s
11+
# RUN: llvm-nm %t.bolt | FileCheck --check-prefix=CHECK-BOLTED %s
12+
13+
.section .data
14+
.globl _array_end
15+
_array_start:
16+
.word 0x0
17+
18+
_array_end:
19+
.section .init,"ax",@progbits
20+
.globl _init
21+
22+
# Check that bolt doesn't move _init.
23+
#
24+
# CHECK-ORIGINAL: 0000000000001004 T _init
25+
# CHECK-BOLTED: 0000000000001004 T _init
26+
_init:
27+
ret
28+
29+
.section .text,"ax",@progbits
30+
.globl _start
31+
32+
# Check that bolt is moving some other functions.
33+
#
34+
# CHECK-ORIGINAL: 0000000000001008 T _start
35+
# CHECK-BOLTED-NOT: 0000000000001008 T _start
36+
_start:
37+
bl _init
38+
adrp x0, #:got:_array_end
39+
ldr x0, [x0, #:gotpage_lo15:_array_end]
40+
adrp x0, #:got:_init
41+
ldr x0, [x0, #:gotpage_lo15:_init]
42+
ret
43+

0 commit comments

Comments
 (0)