Skip to content

Commit 6c3c0d1

Browse files
authored
Merge branch 'main' into sdag/arm-glue
2 parents 486d07f + 2b3266c commit 6c3c0d1

File tree

1,575 files changed

+69339
-17582
lines changed

Some content is hidden

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

1,575 files changed

+69339
-17582
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}", ""]

.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/include/bolt/Profile/DataAggregator.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,6 @@ class DataAggregator : public DataReader {
170170
std::string BuildIDBinaryName;
171171

172172
/// Memory map info for a single file as recorded in perf.data
173-
/// When a binary has multiple text segments, the Size is computed as the
174-
/// difference of the last address of these segments from the BaseAddress.
175-
/// The base addresses of all text segments must be the same.
176173
struct MMapInfo {
177174
uint64_t BaseAddress{0}; /// Base address of the mapped binary.
178175
uint64_t MMapAddress{0}; /// Address of the executable segment.
@@ -496,11 +493,6 @@ class DataAggregator : public DataReader {
496493
/// and return a file name matching a given \p FileBuildID.
497494
std::optional<StringRef> getFileNameForBuildID(StringRef FileBuildID);
498495

499-
/// Get a constant reference to the parsed binary mmap entries.
500-
const std::unordered_map<uint64_t, MMapInfo> &getBinaryMMapInfo() {
501-
return BinaryMMapInfo;
502-
}
503-
504496
friend class YAMLProfileWriter;
505497
};
506498
} // namespace bolt

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/Profile/DataAggregator.cpp

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,6 @@ cl::opt<bool> ReadPreAggregated(
9595
"pa", cl::desc("skip perf and read data from a pre-aggregated file format"),
9696
cl::cat(AggregatorCategory));
9797

98-
cl::opt<std::string>
99-
ReadPerfEvents("perf-script-events",
100-
cl::desc("skip perf event collection by supplying a "
101-
"perf-script output in a textual format"),
102-
cl::ReallyHidden, cl::init(""), cl::cat(AggregatorCategory));
103-
10498
static cl::opt<bool>
10599
TimeAggregator("time-aggr",
106100
cl::desc("time BOLT aggregator"),
@@ -173,9 +167,8 @@ void DataAggregator::findPerfExecutable() {
173167
void DataAggregator::start() {
174168
outs() << "PERF2BOLT: Starting data aggregation job for " << Filename << "\n";
175169

176-
// Don't launch perf for pre-aggregated files or when perf input is specified
177-
// by the user.
178-
if (opts::ReadPreAggregated || !opts::ReadPerfEvents.empty())
170+
// Don't launch perf for pre-aggregated files
171+
if (opts::ReadPreAggregated)
179172
return;
180173

181174
findPerfExecutable();
@@ -471,13 +464,6 @@ void DataAggregator::filterBinaryMMapInfo() {
471464

472465
int DataAggregator::prepareToParse(StringRef Name, PerfProcessInfo &Process,
473466
PerfProcessErrorCallbackTy Callback) {
474-
if (!opts::ReadPerfEvents.empty()) {
475-
outs() << "PERF2BOLT: using pre-processed perf events for '" << Name
476-
<< "' (perf-script-events)\n";
477-
ParsingBuf = opts::ReadPerfEvents;
478-
return 0;
479-
}
480-
481467
std::string Error;
482468
outs() << "PERF2BOLT: waiting for perf " << Name
483469
<< " collection to finish...\n";
@@ -2070,6 +2056,15 @@ std::error_code DataAggregator::parseMMapEvents() {
20702056
if (FileMMapInfo.first == "(deleted)")
20712057
continue;
20722058

2059+
// Consider only the first mapping of the file for any given PID
2060+
auto Range = GlobalMMapInfo.equal_range(FileMMapInfo.first);
2061+
bool PIDExists = llvm::any_of(make_range(Range), [&](const auto &MI) {
2062+
return MI.second.PID == FileMMapInfo.second.PID;
2063+
});
2064+
2065+
if (PIDExists)
2066+
continue;
2067+
20732068
GlobalMMapInfo.insert(FileMMapInfo);
20742069
}
20752070

@@ -2121,22 +2116,12 @@ std::error_code DataAggregator::parseMMapEvents() {
21212116
<< " using file offset 0x" << Twine::utohexstr(MMapInfo.Offset)
21222117
<< ". Ignoring profile data for this mapping\n";
21232118
continue;
2119+
} else {
2120+
MMapInfo.BaseAddress = *BaseAddress;
21242121
}
2125-
MMapInfo.BaseAddress = *BaseAddress;
21262122
}
21272123

2128-
// Try to add MMapInfo to the map and update its size. Large binaries may
2129-
// span to multiple text segments, so the mapping is inserted only on the
2130-
// first occurrence.
2131-
if (!BinaryMMapInfo.insert(std::make_pair(MMapInfo.PID, MMapInfo)).second)
2132-
assert(MMapInfo.BaseAddress == BinaryMMapInfo[MMapInfo.PID].BaseAddress &&
2133-
"Base address on multiple segment mappings should match");
2134-
2135-
// Update mapping size.
2136-
const uint64_t EndAddress = MMapInfo.MMapAddress + MMapInfo.Size;
2137-
const uint64_t Size = EndAddress - BinaryMMapInfo[MMapInfo.PID].BaseAddress;
2138-
if (Size > BinaryMMapInfo[MMapInfo.PID].Size)
2139-
BinaryMMapInfo[MMapInfo.PID].Size = Size;
2124+
BinaryMMapInfo.insert(std::make_pair(MMapInfo.PID, MMapInfo));
21402125
}
21412126

21422127
if (BinaryMMapInfo.empty()) {

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)