Skip to content

Commit 9a706aa

Browse files
committed
Merge remote-tracking branch 'upstream/main' into delayed_privatization_15
2 parents 130dc7a + 922ab70 commit 9a706aa

File tree

1,606 files changed

+239936
-100534
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,606 files changed

+239936
-100534
lines changed

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "bolt/Core/JumpTable.h"
2121
#include "bolt/Core/MCPlusBuilder.h"
2222
#include "bolt/RuntimeLibs/RuntimeLibrary.h"
23+
#include "llvm/ADT/AddressRanges.h"
2324
#include "llvm/ADT/ArrayRef.h"
2425
#include "llvm/ADT/StringMap.h"
2526
#include "llvm/ADT/iterator.h"
@@ -726,6 +727,9 @@ class BinaryContext {
726727
uint64_t OldTextSectionOffset{0};
727728
uint64_t OldTextSectionSize{0};
728729

730+
/// Area in the input binary reserved for BOLT.
731+
AddressRange BOLTReserved;
732+
729733
/// Address of the code/function that is executed before any other code in
730734
/// the binary.
731735
std::optional<uint64_t> StartFunctionAddress;

bolt/include/bolt/Profile/DataAggregator.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,8 @@ class DataAggregator : public DataReader {
198198
/// A trace is region of code executed between two LBR entries supplied in
199199
/// execution order.
200200
///
201-
/// Return true if the trace is valid, false otherwise.
202-
bool
203-
recordTrace(BinaryFunction &BF, const LBREntry &First, const LBREntry &Second,
204-
uint64_t Count,
205-
SmallVector<std::pair<uint64_t, uint64_t>, 16> &Branches) const;
206-
207201
/// Return a vector of offsets corresponding to a trace in a function
208-
/// (see recordTrace() above).
202+
/// if the trace is valid, std::nullopt otherwise.
209203
std::optional<SmallVector<std::pair<uint64_t, uint64_t>, 16>>
210204
getFallthroughsInTrace(BinaryFunction &BF, const LBREntry &First,
211205
const LBREntry &Second, uint64_t Count = 1) const;

bolt/include/bolt/Rewrite/RewriteInstance.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ class RewriteInstance {
9797
/// from meta data in the file.
9898
void discoverFileObjects();
9999

100+
/// Check if the input binary has a space reserved for BOLT and use it for new
101+
/// section allocations if found.
102+
void discoverBOLTReserved();
103+
100104
/// Check whether we should use DT_FINI or DT_FINI_ARRAY for instrumentation.
101105
/// DT_FINI is preferred; DT_FINI_ARRAY is only used when no DT_FINI entry was
102106
/// found.
@@ -422,6 +426,10 @@ class RewriteInstance {
422426
/// Section name used for extra BOLT code in addition to .text.
423427
static StringRef getBOLTTextSectionName() { return ".bolt.text"; }
424428

429+
/// Symbol markers for BOLT reserved area.
430+
static StringRef getBOLTReservedStart() { return "__bolt_reserved_start"; }
431+
static StringRef getBOLTReservedEnd() { return "__bolt_reserved_end"; }
432+
425433
/// Common section names.
426434
static StringRef getEHFrameSectionName() { return ".eh_frame"; }
427435
static StringRef getEHFrameHdrSectionName() { return ".eh_frame_hdr"; }
@@ -494,6 +502,9 @@ class RewriteInstance {
494502
/// Store all non-zero symbols in this map for a quick address lookup.
495503
std::map<uint64_t, llvm::object::SymbolRef> FileSymRefs;
496504

505+
/// FILE symbols used for disambiguating split function parents.
506+
std::vector<ELFSymbolRef> FileSymbols;
507+
497508
std::unique_ptr<DWARFRewriter> DebugInfoRewriter;
498509

499510
std::unique_ptr<BoltAddressTranslation> BAT;

bolt/include/bolt/Utils/NameResolver.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,23 @@ class NameResolver {
2828
static constexpr char Sep = '/';
2929

3030
public:
31-
/// Return unique version of the \p Name in the form "Name<Sep><Number>".
31+
/// Return the number of uniquified versions of a given \p Name.
32+
uint64_t getUniquifiedNameCount(StringRef Name) const {
33+
if (Counters.contains(Name))
34+
return Counters.at(Name);
35+
return 0;
36+
}
37+
38+
/// Return unique version of the \p Name in the form "Name<Sep><ID>".
39+
std::string getUniqueName(StringRef Name, const uint64_t ID) const {
40+
return (Name + Twine(Sep) + Twine(ID)).str();
41+
}
42+
43+
/// Register new version of \p Name and return unique version in the form
44+
/// "Name<Sep><Number>".
3245
std::string uniquify(StringRef Name) {
3346
const uint64_t ID = ++Counters[Name];
34-
return (Name + Twine(Sep) + Twine(ID)).str();
47+
return getUniqueName(Name, ID);
3548
}
3649

3750
/// For uniquified \p Name, return the original form (that may no longer be

bolt/lib/Passes/SplitFunctions.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,12 @@ Error SplitFunctions::runOnFunctions(BinaryContext &BC) {
715715
if (!opts::SplitFunctions)
716716
return Error::success();
717717

718+
if (BC.IsLinuxKernel && BC.BOLTReserved.empty()) {
719+
BC.errs() << "BOLT-ERROR: split functions require reserved space in the "
720+
"Linux kernel binary\n";
721+
exit(1);
722+
}
723+
718724
// If split strategy is not CDSplit, then a second run of the pass is not
719725
// needed after function reordering.
720726
if (BC.HasFinalizedFunctionOrder &&
@@ -829,6 +835,13 @@ void SplitFunctions::splitFunction(BinaryFunction &BF, SplitStrategy &S) {
829835
}
830836
}
831837
}
838+
839+
// Outlining blocks with dynamic branches is not supported yet.
840+
if (BC.IsLinuxKernel) {
841+
if (llvm::any_of(
842+
*BB, [&](MCInst &Inst) { return BC.MIB->isDynamicBranch(Inst); }))
843+
BB->setCanOutline(false);
844+
}
832845
}
833846

834847
BF.getLayout().updateLayoutIndices();

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -861,14 +861,17 @@ bool DataAggregator::doTrace(const LBREntry &First, const LBREntry &Second,
861861
return true;
862862
}
863863

864-
bool DataAggregator::recordTrace(
865-
BinaryFunction &BF, const LBREntry &FirstLBR, const LBREntry &SecondLBR,
866-
uint64_t Count,
867-
SmallVector<std::pair<uint64_t, uint64_t>, 16> &Branches) const {
864+
std::optional<SmallVector<std::pair<uint64_t, uint64_t>, 16>>
865+
DataAggregator::getFallthroughsInTrace(BinaryFunction &BF,
866+
const LBREntry &FirstLBR,
867+
const LBREntry &SecondLBR,
868+
uint64_t Count) const {
869+
SmallVector<std::pair<uint64_t, uint64_t>, 16> Branches;
870+
868871
BinaryContext &BC = BF.getBinaryContext();
869872

870873
if (!BF.isSimple())
871-
return false;
874+
return std::nullopt;
872875

873876
assert(BF.hasCFG() && "can only record traces in CFG state");
874877

@@ -877,13 +880,13 @@ bool DataAggregator::recordTrace(
877880
const uint64_t To = SecondLBR.From - BF.getAddress();
878881

879882
if (From > To)
880-
return false;
883+
return std::nullopt;
881884

882885
const BinaryBasicBlock *FromBB = BF.getBasicBlockContainingOffset(From);
883886
const BinaryBasicBlock *ToBB = BF.getBasicBlockContainingOffset(To);
884887

885888
if (!FromBB || !ToBB)
886-
return false;
889+
return std::nullopt;
887890

888891
// Adjust FromBB if the first LBR is a return from the last instruction in
889892
// the previous block (that instruction should be a call).
@@ -907,7 +910,7 @@ bool DataAggregator::recordTrace(
907910
// within the same basic block, e.g. when two call instructions are in the
908911
// same block. In this case we skip the processing.
909912
if (FromBB == ToBB)
910-
return true;
913+
return Branches;
911914

912915
// Process blocks in the original layout order.
913916
BinaryBasicBlock *BB = BF.getLayout().getBlock(FromBB->getIndex());
@@ -921,7 +924,7 @@ bool DataAggregator::recordTrace(
921924
LLVM_DEBUG(dbgs() << "no fall-through for the trace:\n"
922925
<< " " << FirstLBR << '\n'
923926
<< " " << SecondLBR << '\n');
924-
return false;
927+
return std::nullopt;
925928
}
926929

927930
const MCInst *Instr = BB->getLastNonPseudoInstr();
@@ -945,20 +948,7 @@ bool DataAggregator::recordTrace(
945948
BI.Count += Count;
946949
}
947950

948-
return true;
949-
}
950-
951-
std::optional<SmallVector<std::pair<uint64_t, uint64_t>, 16>>
952-
DataAggregator::getFallthroughsInTrace(BinaryFunction &BF,
953-
const LBREntry &FirstLBR,
954-
const LBREntry &SecondLBR,
955-
uint64_t Count) const {
956-
SmallVector<std::pair<uint64_t, uint64_t>, 16> Res;
957-
958-
if (!recordTrace(BF, FirstLBR, SecondLBR, Count, Res))
959-
return std::nullopt;
960-
961-
return Res;
951+
return Branches;
962952
}
963953

964954
bool DataAggregator::recordEntry(BinaryFunction &BF, uint64_t To, bool Mispred,

0 commit comments

Comments
 (0)