Skip to content

Commit f1b6862

Browse files
committed
resolved conflicts
2 parents 188200d + 2ca0526 commit f1b6862

File tree

2,257 files changed

+152751
-65054
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,257 files changed

+152751
-65054
lines changed

.ci/monolithic-linux.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
6060
-D MLIR_ENABLE_BINDINGS_PYTHON=ON \
6161
-D LLDB_ENABLE_PYTHON=ON \
6262
-D LLDB_ENFORCE_STRICT_TEST_REQUIREMENTS=ON \
63-
-D CMAKE_INSTALL_PREFIX="${INSTALL_DIR}"
63+
-D CMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
64+
-D CMAKE_EXE_LINKER_FLAGS="-no-pie"
6465

6566
start-group "ninja"
6667

bolt/docs/CommandLineArgumentReference.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@
138138
Dump function CFGs to graphviz format after each stage;enable '-print-loops'
139139
for color-coded blocks
140140

141+
- `--dump-dot-func=<func1,func2,func3...>`
142+
143+
Dump function CFGs to graphviz format for specified functions only;
144+
takes function name patterns (regex supported). Note: C++ function names
145+
must be passed using their mangled names
146+
141147
- `--dump-linux-exceptions`
142148

143149
Dump Linux kernel exception table

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/include/bolt/Utils/CommandLineOpts.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515

1616
#include "llvm/Support/CommandLine.h"
1717

18+
namespace llvm {
19+
namespace bolt {
20+
class BinaryFunction;
21+
}
22+
} // namespace llvm
23+
1824
namespace opts {
1925

2026
enum HeatmapModeKind {
@@ -100,6 +106,9 @@ extern llvm::cl::opt<unsigned> Verbosity;
100106
/// Return true if we should process all functions in the binary.
101107
bool processAllFunctions();
102108

109+
/// Return true if we should dump dot graphs for the given function.
110+
bool shouldDumpDot(const llvm::bolt::BinaryFunction &Function);
111+
103112
enum GadgetScannerKind { GS_PACRET, GS_PAUTH, GS_ALL };
104113

105114
extern llvm::cl::bits<GadgetScannerKind> GadgetScannersToRun;

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/BinaryPassManager.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ namespace opts {
5252
extern cl::opt<bool> PrintAll;
5353
extern cl::opt<bool> PrintDynoStats;
5454
extern cl::opt<bool> DumpDotAll;
55+
extern bool shouldDumpDot(const bolt::BinaryFunction &Function);
5556
extern cl::opt<std::string> AsmDump;
5657
extern cl::opt<bolt::PLTCall::OptType> PLT;
5758
extern cl::opt<bolt::IdenticalCodeFolding::ICFLevel, false,
@@ -340,7 +341,7 @@ Error BinaryFunctionPassManager::runPasses() {
340341

341342
Function.print(BC.outs(), Message);
342343

343-
if (opts::DumpDotAll)
344+
if (opts::shouldDumpDot(Function))
344345
Function.dumpGraphForPass(PassIdName);
345346
}
346347
}

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 56 additions & 28 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;
@@ -114,6 +115,35 @@ cl::opt<bool> DumpDotAll(
114115
"enable '-print-loops' for color-coded blocks"),
115116
cl::Hidden, cl::cat(BoltCategory));
116117

118+
cl::list<std::string> DumpDotFunc(
119+
"dump-dot-func", cl::CommaSeparated,
120+
cl::desc(
121+
"dump function CFGs to graphviz format for specified functions only;"
122+
"takes function name patterns (regex supported)"),
123+
cl::value_desc("func1,func2,func3,..."), cl::Hidden, cl::cat(BoltCategory));
124+
125+
bool shouldDumpDot(const bolt::BinaryFunction &Function) {
126+
// If dump-dot-all is enabled, dump all functions
127+
if (DumpDotAll)
128+
return !Function.isIgnored();
129+
130+
// If no specific functions specified in dump-dot-func, don't dump any
131+
if (DumpDotFunc.empty())
132+
return false;
133+
134+
if (Function.isIgnored())
135+
return false;
136+
137+
// Check if function matches any of the specified patterns
138+
for (const std::string &Name : DumpDotFunc) {
139+
if (Function.hasNameRegex(Name)) {
140+
return true;
141+
}
142+
}
143+
144+
return false;
145+
}
146+
117147
static cl::list<std::string>
118148
ForceFunctionNames("funcs",
119149
cl::CommaSeparated,
@@ -880,14 +910,9 @@ void RewriteInstance::discoverFileObjects() {
880910
// code section (see IHI0056B). $d identifies data contents.
881911
// Compilers usually merge multiple data objects in a single $d-$x interval,
882912
// 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.
913+
// keep track of marker symbols with all locations of data objects.
884914

885-
struct MarkerSym {
886-
uint64_t Address;
887-
MarkerSymType Type;
888-
};
889-
890-
std::vector<MarkerSym> SortedMarkerSymbols;
915+
DenseMap<uint64_t, MarkerSymType> MarkerSymbols;
891916
auto addExtraDataMarkerPerSymbol = [&]() {
892917
bool IsData = false;
893918
uint64_t LastAddr = 0;
@@ -911,14 +936,14 @@ void RewriteInstance::discoverFileObjects() {
911936
}
912937

913938
if (MarkerType != MarkerSymType::NONE) {
914-
SortedMarkerSymbols.push_back(MarkerSym{SymInfo.Address, MarkerType});
939+
MarkerSymbols[SymInfo.Address] = MarkerType;
915940
LastAddr = SymInfo.Address;
916941
IsData = MarkerType == MarkerSymType::DATA;
917942
continue;
918943
}
919944

920945
if (IsData) {
921-
SortedMarkerSymbols.push_back({SymInfo.Address, MarkerSymType::DATA});
946+
MarkerSymbols[SymInfo.Address] = MarkerSymType::DATA;
922947
LastAddr = SymInfo.Address;
923948
}
924949
}
@@ -1283,27 +1308,24 @@ void RewriteInstance::discoverFileObjects() {
12831308
BC->setHasSymbolsWithFileName(FileSymbols.size());
12841309

12851310
// Now that all the functions were created - adjust their boundaries.
1286-
adjustFunctionBoundaries();
1311+
adjustFunctionBoundaries(MarkerSymbols);
12871312

12881313
// 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);
1314+
for (auto &[Address, Type] : MarkerSymbols) {
1315+
auto *BF = BC->getBinaryFunctionContainingAddress(Address, true, true);
12941316

12951317
if (!BF) {
12961318
// Stray marker
12971319
continue;
12981320
}
1299-
const auto EntryOffset = ISym->Address - BF->getAddress();
1300-
if (ISym->Type == MarkerSymType::CODE) {
1321+
const auto EntryOffset = Address - BF->getAddress();
1322+
if (Type == MarkerSymType::CODE) {
13011323
BF->markCodeAtOffset(EntryOffset);
13021324
continue;
13031325
}
1304-
if (ISym->Type == MarkerSymType::DATA) {
1326+
if (Type == MarkerSymType::DATA) {
13051327
BF->markDataAtOffset(EntryOffset);
1306-
BC->AddressToConstantIslandMap[ISym->Address] = BF;
1328+
BC->AddressToConstantIslandMap[Address] = BF;
13071329
continue;
13081330
}
13091331
llvm_unreachable("Unknown marker");
@@ -1832,7 +1854,8 @@ void RewriteInstance::disassemblePLT() {
18321854
}
18331855
}
18341856

1835-
void RewriteInstance::adjustFunctionBoundaries() {
1857+
void RewriteInstance::adjustFunctionBoundaries(
1858+
DenseMap<uint64_t, MarkerSymType> &MarkerSyms) {
18361859
for (auto BFI = BC->getBinaryFunctions().begin(),
18371860
BFE = BC->getBinaryFunctions().end();
18381861
BFI != BFE; ++BFI) {
@@ -1870,12 +1893,15 @@ void RewriteInstance::adjustFunctionBoundaries() {
18701893
continue;
18711894
}
18721895

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);
1896+
auto It = MarkerSyms.find(NextSymRefI->first);
1897+
if (It == MarkerSyms.end() || It->second != MarkerSymType::DATA) {
1898+
// This is potentially another entry point into the function.
1899+
uint64_t EntryOffset = NextSymRefI->first - Function.getAddress();
1900+
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: adding entry point to function "
1901+
<< Function << " at offset 0x"
1902+
<< Twine::utohexstr(EntryOffset) << '\n');
1903+
Function.addEntryPointAtOffset(EntryOffset);
1904+
}
18791905

18801906
++NextSymRefI;
18811907
}
@@ -2177,7 +2203,9 @@ void RewriteInstance::adjustCommandLineOptions() {
21772203
if (!opts::KeepNops.getNumOccurrences())
21782204
opts::KeepNops = true;
21792205

2180-
// Linux kernel may resume execution after a trap instruction in some cases.
2206+
// Linux kernel may resume execution after a trap or x86 HLT instruction.
2207+
if (!opts::TerminalHLT.getNumOccurrences())
2208+
opts::TerminalHLT = false;
21812209
if (!opts::TerminalTrap.getNumOccurrences())
21822210
opts::TerminalTrap = false;
21832211
}
@@ -3570,7 +3598,7 @@ void RewriteInstance::postProcessFunctions() {
35703598
if (opts::PrintAll || opts::PrintCFG)
35713599
Function.print(BC->outs(), "after building cfg");
35723600

3573-
if (opts::DumpDotAll)
3601+
if (opts::shouldDumpDot(Function))
35743602
Function.dumpGraphForPass("00_build-cfg");
35753603

35763604
if (opts::PrintLoopInfo) {
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

0 commit comments

Comments
 (0)