Skip to content

Commit ff2d84f

Browse files
Merge branch 'llvm:main' into gh-101657
2 parents 90f4db2 + 26d4e56 commit ff2d84f

File tree

1,585 files changed

+79363
-49091
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,585 files changed

+79363
-49091
lines changed

.ci/compute_projects.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@
4949
"flang",
5050
},
5151
"lld": {"bolt", "cross-project-tests"},
52-
# TODO(issues/132795): LLDB should be enabled on clang changes.
53-
"clang": {"clang-tools-extra", "cross-project-tests"},
52+
"clang": {"clang-tools-extra", "cross-project-tests", "lldb"},
5453
"mlir": {"flang"},
5554
# Test everything if ci scripts are changed.
5655
".ci": {

.ci/compute_projects_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ def test_clang(self):
8383
)
8484
self.assertEqual(
8585
env_variables["projects_to_build"],
86-
"clang;clang-tools-extra;lld;llvm",
86+
"clang;clang-tools-extra;lld;lldb;llvm",
8787
)
8888
self.assertEqual(
8989
env_variables["project_check_targets"],
90-
"check-clang check-clang-tools",
90+
"check-clang check-clang-tools check-lldb",
9191
)
9292
self.assertEqual(
9393
env_variables["runtimes_to_build"], "compiler-rt;libcxx;libcxxabi;libunwind"
@@ -158,11 +158,11 @@ def test_cir(self):
158158
)
159159
self.assertEqual(
160160
env_variables["projects_to_build"],
161-
"clang;clang-tools-extra;lld;llvm;mlir",
161+
"clang;clang-tools-extra;lld;lldb;llvm;mlir",
162162
)
163163
self.assertEqual(
164164
env_variables["project_check_targets"],
165-
"check-clang check-clang-cir check-clang-tools",
165+
"check-clang check-clang-cir check-clang-tools check-lldb",
166166
)
167167
self.assertEqual(
168168
env_variables["runtimes_to_build"], "compiler-rt;libcxx;libcxxabi;libunwind"

.github/workflows/pr-code-format.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ jobs:
7171
- name: Run code formatter
7272
env:
7373
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
74-
START_REV: ${{ github.event.pull_request.base.sha }}
75-
END_REV: ${{ github.event.pull_request.head.sha }}
7674
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
7775
# Create an empty comments file so the pr-write job doesn't fail.
7876
run: |

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,11 +1196,6 @@ class BinaryFunction {
11961196
return getSecondaryEntryPointSymbol(BB.getLabel());
11971197
}
11981198

1199-
/// Remove a label from the secondary entry point map.
1200-
void removeSymbolFromSecondaryEntryPointMap(const MCSymbol *Label) {
1201-
SecondaryEntryPoints.erase(Label);
1202-
}
1203-
12041199
/// Return true if the basic block is an entry point into the function
12051200
/// (either primary or secondary).
12061201
bool isEntryPoint(const BinaryBasicBlock &BB) const {

bolt/include/bolt/Rewrite/RewriteInstance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ class RewriteInstance {
241241

242242
/// Adjust function sizes and set proper maximum size values after the whole
243243
/// symbol table has been processed.
244-
void adjustFunctionBoundaries();
244+
void adjustFunctionBoundaries(DenseMap<uint64_t, MarkerSymType> &MarkerSyms);
245245

246246
/// Make .eh_frame section relocatable.
247247
void relocateEHFrameSection();

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,13 +1915,9 @@ void BinaryFunction::postProcessEntryPoints() {
19151915
continue;
19161916

19171917
// If we have grabbed a wrong code label which actually points to some
1918-
// constant island inside the function, ignore this label and remove it
1919-
// from the secondary entry point map.
1920-
if (isStartOfConstantIsland(Offset)) {
1921-
BC.SymbolToFunctionMap.erase(Label);
1922-
removeSymbolFromSecondaryEntryPointMap(Label);
1918+
// constant island inside the function, ignore this label.
1919+
if (isStartOfConstantIsland(Offset))
19231920
continue;
1924-
}
19251921

19261922
BC.errs() << "BOLT-WARNING: reference in the middle of instruction "
19271923
"detected in function "

bolt/lib/Core/MCPlusBuilder.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ using namespace bolt;
3030
using namespace MCPlus;
3131

3232
namespace opts {
33+
cl::opt<bool>
34+
TerminalHLT("terminal-x86-hlt",
35+
cl::desc("Assume that execution stops at x86 HLT instruction"),
36+
cl::init(true), cl::Hidden, cl::cat(BoltCategory));
37+
3338
cl::opt<bool>
3439
TerminalTrap("terminal-trap",
3540
cl::desc("Assume that execution stops at trap instruction"),
@@ -132,10 +137,13 @@ bool MCPlusBuilder::equals(const MCSpecifierExpr &A, const MCSpecifierExpr &B,
132137
}
133138

134139
bool MCPlusBuilder::isTerminator(const MCInst &Inst) const {
135-
return (opts::TerminalTrap && Info->get(Inst.getOpcode()).isTrap()) ||
136-
Analysis->isTerminator(Inst)
137-
? !isX86HLT(Inst)
138-
: false;
140+
if (isX86HLT(Inst))
141+
return opts::TerminalHLT;
142+
143+
if (Info->get(Inst.getOpcode()).isTrap())
144+
return opts::TerminalTrap;
145+
146+
return Analysis->isTerminator(Inst);
139147
}
140148

141149
void MCPlusBuilder::setTailCall(MCInst &Inst) const {

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ extern cl::opt<bool> KeepNops;
8484
extern cl::opt<bool> Lite;
8585
extern cl::list<std::string> ReorderData;
8686
extern cl::opt<bolt::ReorderFunctions::ReorderType> ReorderFunctions;
87+
extern cl::opt<bool> TerminalHLT;
8788
extern cl::opt<bool> TerminalTrap;
8889
extern cl::opt<bool> TimeBuild;
8990
extern cl::opt<bool> TimeRewrite;
@@ -880,14 +881,9 @@ void RewriteInstance::discoverFileObjects() {
880881
// code section (see IHI0056B). $d identifies data contents.
881882
// Compilers usually merge multiple data objects in a single $d-$x interval,
882883
// but we need every data object to be marked with $d. Because of that we
883-
// create a vector of MarkerSyms with all locations of data objects.
884+
// keep track of marker symbols with all locations of data objects.
884885

885-
struct MarkerSym {
886-
uint64_t Address;
887-
MarkerSymType Type;
888-
};
889-
890-
std::vector<MarkerSym> SortedMarkerSymbols;
886+
DenseMap<uint64_t, MarkerSymType> MarkerSymbols;
891887
auto addExtraDataMarkerPerSymbol = [&]() {
892888
bool IsData = false;
893889
uint64_t LastAddr = 0;
@@ -911,14 +907,14 @@ void RewriteInstance::discoverFileObjects() {
911907
}
912908

913909
if (MarkerType != MarkerSymType::NONE) {
914-
SortedMarkerSymbols.push_back(MarkerSym{SymInfo.Address, MarkerType});
910+
MarkerSymbols[SymInfo.Address] = MarkerType;
915911
LastAddr = SymInfo.Address;
916912
IsData = MarkerType == MarkerSymType::DATA;
917913
continue;
918914
}
919915

920916
if (IsData) {
921-
SortedMarkerSymbols.push_back({SymInfo.Address, MarkerSymType::DATA});
917+
MarkerSymbols[SymInfo.Address] = MarkerSymType::DATA;
922918
LastAddr = SymInfo.Address;
923919
}
924920
}
@@ -1283,27 +1279,24 @@ void RewriteInstance::discoverFileObjects() {
12831279
BC->setHasSymbolsWithFileName(FileSymbols.size());
12841280

12851281
// Now that all the functions were created - adjust their boundaries.
1286-
adjustFunctionBoundaries();
1282+
adjustFunctionBoundaries(MarkerSymbols);
12871283

12881284
// Annotate functions with code/data markers in AArch64
1289-
for (auto ISym = SortedMarkerSymbols.begin();
1290-
ISym != SortedMarkerSymbols.end(); ++ISym) {
1291-
1292-
auto *BF =
1293-
BC->getBinaryFunctionContainingAddress(ISym->Address, true, true);
1285+
for (auto &[Address, Type] : MarkerSymbols) {
1286+
auto *BF = BC->getBinaryFunctionContainingAddress(Address, true, true);
12941287

12951288
if (!BF) {
12961289
// Stray marker
12971290
continue;
12981291
}
1299-
const auto EntryOffset = ISym->Address - BF->getAddress();
1300-
if (ISym->Type == MarkerSymType::CODE) {
1292+
const auto EntryOffset = Address - BF->getAddress();
1293+
if (Type == MarkerSymType::CODE) {
13011294
BF->markCodeAtOffset(EntryOffset);
13021295
continue;
13031296
}
1304-
if (ISym->Type == MarkerSymType::DATA) {
1297+
if (Type == MarkerSymType::DATA) {
13051298
BF->markDataAtOffset(EntryOffset);
1306-
BC->AddressToConstantIslandMap[ISym->Address] = BF;
1299+
BC->AddressToConstantIslandMap[Address] = BF;
13071300
continue;
13081301
}
13091302
llvm_unreachable("Unknown marker");
@@ -1832,7 +1825,8 @@ void RewriteInstance::disassemblePLT() {
18321825
}
18331826
}
18341827

1835-
void RewriteInstance::adjustFunctionBoundaries() {
1828+
void RewriteInstance::adjustFunctionBoundaries(
1829+
DenseMap<uint64_t, MarkerSymType> &MarkerSyms) {
18361830
for (auto BFI = BC->getBinaryFunctions().begin(),
18371831
BFE = BC->getBinaryFunctions().end();
18381832
BFI != BFE; ++BFI) {
@@ -1870,12 +1864,15 @@ void RewriteInstance::adjustFunctionBoundaries() {
18701864
continue;
18711865
}
18721866

1873-
// This is potentially another entry point into the function.
1874-
uint64_t EntryOffset = NextSymRefI->first - Function.getAddress();
1875-
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: adding entry point to function "
1876-
<< Function << " at offset 0x"
1877-
<< Twine::utohexstr(EntryOffset) << '\n');
1878-
Function.addEntryPointAtOffset(EntryOffset);
1867+
auto It = MarkerSyms.find(NextSymRefI->first);
1868+
if (It == MarkerSyms.end() || It->second != MarkerSymType::DATA) {
1869+
// This is potentially another entry point into the function.
1870+
uint64_t EntryOffset = NextSymRefI->first - Function.getAddress();
1871+
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: adding entry point to function "
1872+
<< Function << " at offset 0x"
1873+
<< Twine::utohexstr(EntryOffset) << '\n');
1874+
Function.addEntryPointAtOffset(EntryOffset);
1875+
}
18791876

18801877
++NextSymRefI;
18811878
}
@@ -2177,7 +2174,9 @@ void RewriteInstance::adjustCommandLineOptions() {
21772174
if (!opts::KeepNops.getNumOccurrences())
21782175
opts::KeepNops = true;
21792176

2180-
// Linux kernel may resume execution after a trap instruction in some cases.
2177+
// Linux kernel may resume execution after a trap or x86 HLT instruction.
2178+
if (!opts::TerminalHLT.getNumOccurrences())
2179+
opts::TerminalHLT = false;
21812180
if (!opts::TerminalTrap.getNumOccurrences())
21822181
opts::TerminalTrap = false;
21832182
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# This test is to ensure that we query data marker symbols to avoid
2+
# misidentifying constant data island symbol as extra entry point.
3+
4+
# RUN: %clang %cflags %s -o %t.so -Wl,-q -Wl,--init=_bar -Wl,--fini=_bar
5+
# RUN: llvm-bolt %t.so -o %t.instr.so
6+
7+
.text
8+
.global _start
9+
.type _start, %function
10+
_start:
11+
ret
12+
13+
.text
14+
.global _foo
15+
.type _foo, %function
16+
_foo:
17+
cbz x1, _foo_2
18+
_foo_1:
19+
add x1, x2, x0
20+
b _foo
21+
_foo_2:
22+
ret
23+
24+
# None of these constant island symbols should be identified as extra entry
25+
# point for function `_foo'.
26+
.align 4
27+
_const1: .short 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80
28+
_const2: .short 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0xa0
29+
_const3: .short 0x04, 0x08, 0x0c, 0x20, 0x60, 0x80, 0xa0, 0xc0
30+
31+
.text
32+
.global _bar
33+
.type _bar, %function
34+
_bar:
35+
ret
36+
37+
# Dummy relocation to force relocation mode
38+
.reloc 0, R_AARCH64_NONE

bolt/test/X86/cfg_build_hlt.s

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)