Skip to content

Commit 5b0e57f

Browse files
committed
Merge branch 'main' into ptrauth-init-fini
2 parents d955cf8 + 09fec46 commit 5b0e57f

File tree

1,979 files changed

+88770
-31701
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,979 files changed

+88770
-31701
lines changed

.git-blame-ignore-revs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,6 @@ b9079baaddfed5e604fbfaa1d81a7a1c38e78c26
8484

8585
# [libc++][NFC] Run clang-format on libcxx/include again (#95874)
8686
e2c2ffbe7a1b5d9e32a2ce64279475b50c4cba5b
87+
88+
# [lldb][nfc] Deindent ProcessGDBRemote::SetThreadStopInfo by two levels
89+
b32931c5b32eb0d2cf37d688b34f8548c9674c19

.github/CODEOWNERS

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ clang/test/AST/Interp/ @tbaederr
6767
/mlir/include/mlir/Dialect/Linalg @dcaballe @nicolasvasilache @rengolin
6868
/mlir/lib/Dialect/Linalg @dcaballe @nicolasvasilache @rengolin
6969
/mlir/lib/Dialect/Linalg/Transforms/DecomposeLinalgOps.cpp @MaheshRavishankar @nicolasvasilache
70-
/mlir/lib/Dialect/Linalg/Transforms/DropUnitDims.cpp @MaheshRavishankar @nicolasvasilache
70+
/mlir/lib/Dialect/Linalg/Transforms/DropUnitDims.cpp @dcaballe @MaheshRavishankar @nicolasvasilache
7171
/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp @MaheshRavishankar @nicolasvasilache
7272
/mlir/lib/Dialect/Linalg/Transforms/DataLayoutPropagation.cpp @hanhanW @nicolasvasilache
73-
/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp @hanhanW @nicolasvasilache
74-
/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp @hanhanW @nicolasvasilache
73+
/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp @dcaballe @hanhanW @nicolasvasilache
74+
/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp @banach-space @dcaballe @hanhanW @nicolasvasilache
7575

7676
# MemRef Dialect in MLIR.
7777
/mlir/lib/Dialect/MemRef/Transforms/EmulateNarrowType.cpp @MaheshRavishankar @nicolasvasilache
@@ -85,10 +85,10 @@ clang/test/AST/Interp/ @tbaederr
8585
/mlir/**/*VectorToSCF* @banach-space @dcaballe @matthias-springer @nicolasvasilache
8686
/mlir/**/*VectorToLLVM* @banach-space @dcaballe @nicolasvasilache
8787
/mlir/**/*X86Vector* @aartbik @dcaballe @nicolasvasilache
88-
/mlir/include/mlir/Dialect/Vector @dcaballe @nicolasvasilache
89-
/mlir/lib/Dialect/Vector @dcaballe @nicolasvasilache
90-
/mlir/lib/Dialect/Vector/Transforms/* @hanhanW @nicolasvasilache
91-
/mlir/lib/Dialect/Vector/Transforms/VectorEmulateNarrowType.cpp @MaheshRavishankar @nicolasvasilache
88+
/mlir/include/mlir/Dialect/Vector @banach-space @dcaballe @nicolasvasilache
89+
/mlir/lib/Dialect/Vector @banach-space @dcaballe @nicolasvasilache
90+
/mlir/lib/Dialect/Vector/Transforms/* @banach-space @dcaballe @hanhanW @nicolasvasilache
91+
/mlir/lib/Dialect/Vector/Transforms/VectorEmulateNarrowType.cpp @banach-space @dcaballe @MaheshRavishankar @nicolasvasilache
9292
/mlir/**/*EmulateNarrowType* @dcaballe @hanhanW
9393

9494
# Presburger library in MLIR

a-abfdec1d.o.tmp

Whitespace-only changes.

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "llvm/MC/MCContext.h"
3333
#include "llvm/MC/MCObjectFileInfo.h"
3434
#include "llvm/MC/MCObjectWriter.h"
35+
#include "llvm/MC/MCPseudoProbe.h"
3536
#include "llvm/MC/MCSectionELF.h"
3637
#include "llvm/MC/MCSectionMachO.h"
3738
#include "llvm/MC/MCStreamer.h"
@@ -246,6 +247,9 @@ class BinaryContext {
246247
/// DWP Context.
247248
std::shared_ptr<DWARFContext> DWPContext;
248249

250+
/// Decoded pseudo probes.
251+
std::shared_ptr<MCPseudoProbeDecoder> PseudoProbeDecoder;
252+
249253
/// A map of DWO Ids to CUs.
250254
using DWOIdToCUMapType = std::unordered_map<uint64_t, DWARFUnit *>;
251255
DWOIdToCUMapType DWOCUs;
@@ -377,6 +381,15 @@ class BinaryContext {
377381
RtLibrary = std::move(Lib);
378382
}
379383

384+
const MCPseudoProbeDecoder *getPseudoProbeDecoder() const {
385+
return PseudoProbeDecoder.get();
386+
}
387+
388+
void setPseudoProbeDecoder(std::shared_ptr<MCPseudoProbeDecoder> Decoder) {
389+
assert(!PseudoProbeDecoder && "Cannot set pseudo probe decoder twice.");
390+
PseudoProbeDecoder = Decoder;
391+
}
392+
380393
/// Return BinaryFunction containing a given \p Address or nullptr if
381394
/// no registered function contains the \p Address.
382395
///
@@ -431,6 +444,9 @@ class BinaryContext {
431444
return nullptr;
432445
}
433446

447+
/// Deregister JumpTable registered at a given \p Address and delete it.
448+
void deleteJumpTable(uint64_t Address);
449+
434450
unsigned getDWARFEncodingSize(unsigned Encoding) {
435451
if (Encoding == dwarf::DW_EH_PE_omit)
436452
return 0;

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,9 @@ class BinaryFunction {
416416
/// different parameters by every pass.
417417
mutable uint64_t Hash{0};
418418

419+
/// Function GUID assigned externally.
420+
uint64_t GUID{0};
421+
419422
/// For PLT functions it contains a symbol associated with a function
420423
/// reference. It is nullptr for non-PLT functions.
421424
const MCSymbol *PLTSymbol{nullptr};
@@ -2256,6 +2259,11 @@ class BinaryFunction {
22562259
/// Returns the last computed hash value of the function.
22572260
size_t getHash() const { return Hash; }
22582261

2262+
/// Returns the function GUID.
2263+
uint64_t getGUID() const { return GUID; }
2264+
2265+
void setGUID(uint64_t Id) { GUID = Id; }
2266+
22592267
using OperandHashFuncTy =
22602268
function_ref<typename std::string(const MCOperand &)>;
22612269

bolt/include/bolt/Core/DIEBuilder.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,6 @@ class DIEBuilder {
135135

136136
/// Returns current state of the DIEBuilder
137137
State &getState() { return *BuilderState.get(); }
138-
/// Resolve the reference in DIE, if target is not loaded into IR,
139-
/// pre-allocate it. \p RefCU will be updated to the Unit specific by \p
140-
/// RefValue.
141-
DWARFDie resolveDIEReference(
142-
const DWARFFormValue &RefValue,
143-
const DWARFAbbreviationDeclaration::AttributeSpec AttrSpec,
144-
DWARFUnit *&RefCU, DWARFDebugInfoEntry &DwarfDebugInfoEntry);
145138

146139
/// Resolve the reference in DIE, if target is not loaded into IR,
147140
/// pre-allocate it. \p RefCU will be updated to the Unit specific by \p
@@ -165,10 +158,9 @@ class DIEBuilder {
165158
const DWARFFormValue &Val);
166159

167160
/// Clone an attribute in reference format.
168-
void cloneDieReferenceAttribute(
161+
void cloneDieOffsetReferenceAttribute(
169162
DIE &Die, const DWARFUnit &U, const DWARFDie &InputDIE,
170-
const DWARFAbbreviationDeclaration::AttributeSpec AttrSpec,
171-
const DWARFFormValue &Val);
163+
const DWARFAbbreviationDeclaration::AttributeSpec AttrSpec, uint64_t Ref);
172164

173165
/// Clone an attribute in block format.
174166
void cloneBlockAttribute(

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ enum class IndirectBranchType : char {
5858
POSSIBLE_PIC_JUMP_TABLE, /// Possibly a jump table for PIC.
5959
POSSIBLE_GOTO, /// Possibly a gcc's computed goto.
6060
POSSIBLE_FIXED_BRANCH, /// Possibly an indirect branch to a fixed location.
61+
POSSIBLE_PIC_FIXED_BRANCH, /// Possibly an indirect jump to a fixed entry in a
62+
/// PIC jump table.
6163
};
6264

6365
class MCPlusBuilder {
@@ -1474,12 +1476,11 @@ class MCPlusBuilder {
14741476
/// will be set to the different components of the branch. \p MemLocInstr
14751477
/// is the instruction that loads up the indirect function pointer. It may
14761478
/// or may not be same as \p Instruction.
1477-
virtual IndirectBranchType
1478-
analyzeIndirectBranch(MCInst &Instruction, InstructionIterator Begin,
1479-
InstructionIterator End, const unsigned PtrSize,
1480-
MCInst *&MemLocInstr, unsigned &BaseRegNum,
1481-
unsigned &IndexRegNum, int64_t &DispValue,
1482-
const MCExpr *&DispExpr, MCInst *&PCRelBaseOut) const {
1479+
virtual IndirectBranchType analyzeIndirectBranch(
1480+
MCInst &Instruction, InstructionIterator Begin, InstructionIterator End,
1481+
const unsigned PtrSize, MCInst *&MemLocInstr, unsigned &BaseRegNum,
1482+
unsigned &IndexRegNum, int64_t &DispValue, const MCExpr *&DispExpr,
1483+
MCInst *&PCRelBaseOut, MCInst *&FixedEntryLoadInst) const {
14831484
llvm_unreachable("not implemented");
14841485
return IndirectBranchType::UNKNOWN;
14851486
}

bolt/include/bolt/Profile/ProfileYAMLMapping.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,36 @@ template <> struct MappingTraits<bolt::SuccessorInfo> {
9393
static const bool flow = true;
9494
};
9595

96+
namespace bolt {
97+
struct PseudoProbeInfo {
98+
llvm::yaml::Hex64 GUID;
99+
uint64_t Index;
100+
uint8_t Type;
101+
102+
bool operator==(const PseudoProbeInfo &Other) const {
103+
return GUID == Other.GUID && Index == Other.Index;
104+
}
105+
bool operator!=(const PseudoProbeInfo &Other) const {
106+
return !(*this == Other);
107+
}
108+
};
109+
} // end namespace bolt
110+
111+
template <> struct MappingTraits<bolt::PseudoProbeInfo> {
112+
static void mapping(IO &YamlIO, bolt::PseudoProbeInfo &PI) {
113+
YamlIO.mapRequired("guid", PI.GUID);
114+
YamlIO.mapRequired("id", PI.Index);
115+
YamlIO.mapRequired("type", PI.Type);
116+
}
117+
118+
static const bool flow = true;
119+
};
96120
} // end namespace yaml
97121
} // end namespace llvm
98122

99123
LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(llvm::yaml::bolt::CallSiteInfo)
100124
LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(llvm::yaml::bolt::SuccessorInfo)
125+
LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(llvm::yaml::bolt::PseudoProbeInfo)
101126

102127
namespace llvm {
103128
namespace yaml {
@@ -111,6 +136,7 @@ struct BinaryBasicBlockProfile {
111136
uint64_t EventCount{0};
112137
std::vector<CallSiteInfo> CallSites;
113138
std::vector<SuccessorInfo> Successors;
139+
std::vector<PseudoProbeInfo> PseudoProbes;
114140

115141
bool operator==(const BinaryBasicBlockProfile &Other) const {
116142
return Index == Other.Index;
@@ -132,6 +158,8 @@ template <> struct MappingTraits<bolt::BinaryBasicBlockProfile> {
132158
std::vector<bolt::CallSiteInfo>());
133159
YamlIO.mapOptional("succ", BBP.Successors,
134160
std::vector<bolt::SuccessorInfo>());
161+
YamlIO.mapOptional("pseudo_probes", BBP.PseudoProbes,
162+
std::vector<bolt::PseudoProbeInfo>());
135163
}
136164
};
137165

@@ -151,6 +179,8 @@ struct BinaryFunctionProfile {
151179
llvm::yaml::Hex64 Hash{0};
152180
uint64_t ExecCount{0};
153181
std::vector<BinaryBasicBlockProfile> Blocks;
182+
llvm::yaml::Hex64 GUID{0};
183+
llvm::yaml::Hex64 PseudoProbeDescHash{0};
154184
bool Used{false};
155185
};
156186
} // end namespace bolt
@@ -164,6 +194,9 @@ template <> struct MappingTraits<bolt::BinaryFunctionProfile> {
164194
YamlIO.mapRequired("nblocks", BFP.NumBasicBlocks);
165195
YamlIO.mapOptional("blocks", BFP.Blocks,
166196
std::vector<bolt::BinaryBasicBlockProfile>());
197+
YamlIO.mapOptional("guid", BFP.GUID, (uint64_t)0);
198+
YamlIO.mapOptional("pseudo_probe_desc_hash", BFP.PseudoProbeDescHash,
199+
(uint64_t)0);
167200
}
168201
};
169202

bolt/include/bolt/Rewrite/DWARFRewriter.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,6 @@ class DWARFRewriter {
9595

9696
std::mutex LocListDebugInfoPatchesMutex;
9797

98-
/// Dwo id specific its RangesBase.
99-
std::unordered_map<uint64_t, uint64_t> DwoRangesBase;
100-
10198
std::unordered_map<DWARFUnit *, uint64_t> LineTablePatchMap;
10299
std::unordered_map<const DWARFUnit *, uint64_t> TypeUnitRelocMap;
103100

@@ -191,12 +188,6 @@ class DWARFRewriter {
191188
/// Update stmt_list for CUs based on the new .debug_line \p Layout.
192189
void updateLineTableOffsets(const MCAssembler &Asm);
193190

194-
uint64_t getDwoRangesBase(uint64_t DWOId) { return DwoRangesBase[DWOId]; }
195-
196-
void setDwoRangesBase(uint64_t DWOId, uint64_t RangesBase) {
197-
DwoRangesBase[DWOId] = RangesBase;
198-
}
199-
200191
using OverriddenSectionsMap = std::unordered_map<DWARFSectionKind, StringRef>;
201192
/// Output .dwo files.
202193
void writeDWOFiles(DWARFUnit &, const OverriddenSectionsMap &,

bolt/include/bolt/Rewrite/RewriteInstance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ class RewriteInstance {
490490
std::unordered_map<const MCSymbol *, uint32_t> SymbolIndex;
491491

492492
/// Store all non-zero symbols in this map for a quick address lookup.
493-
std::map<uint64_t, llvm::object::SymbolRef> FileSymRefs;
493+
std::multimap<uint64_t, llvm::object::SymbolRef> FileSymRefs;
494494

495495
/// FILE symbols used for disambiguating split function parents.
496496
std::vector<ELFSymbolRef> FileSymbols;

bolt/lib/Core/BinaryContext.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,6 +2523,16 @@ BinaryFunction *BinaryContext::getBinaryFunctionAtAddress(uint64_t Address) {
25232523
return nullptr;
25242524
}
25252525

2526+
/// Deregister JumpTable registered at a given \p Address and delete it.
2527+
void BinaryContext::deleteJumpTable(uint64_t Address) {
2528+
assert(JumpTables.count(Address) && "Must have a jump table at address");
2529+
JumpTable *JT = JumpTables.at(Address);
2530+
for (BinaryFunction *Parent : JT->Parents)
2531+
Parent->JumpTables.erase(Address);
2532+
JumpTables.erase(Address);
2533+
delete JT;
2534+
}
2535+
25262536
DebugAddressRangesVector BinaryContext::translateModuleAddressRanges(
25272537
const DWARFAddressRangesVector &InputRanges) const {
25282538
DebugAddressRangesVector OutputRanges;

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,9 @@ BinaryFunction::processIndirectBranch(MCInst &Instruction, unsigned Size,
780780
// setting the value of the register used by the branch.
781781
MCInst *MemLocInstr;
782782

783+
// The instruction loading the fixed PIC jump table entry value.
784+
MCInst *FixedEntryLoadInstr;
785+
783786
// Address of the table referenced by MemLocInstr. Could be either an
784787
// array of function pointers, or a jump table.
785788
uint64_t ArrayStart = 0;
@@ -811,7 +814,7 @@ BinaryFunction::processIndirectBranch(MCInst &Instruction, unsigned Size,
811814

812815
IndirectBranchType BranchType = BC.MIB->analyzeIndirectBranch(
813816
Instruction, Begin, Instructions.end(), PtrSize, MemLocInstr, BaseRegNum,
814-
IndexRegNum, DispValue, DispExpr, PCRelBaseInstr);
817+
IndexRegNum, DispValue, DispExpr, PCRelBaseInstr, FixedEntryLoadInstr);
815818

816819
if (BranchType == IndirectBranchType::UNKNOWN && !MemLocInstr)
817820
return BranchType;
@@ -877,6 +880,43 @@ BinaryFunction::processIndirectBranch(MCInst &Instruction, unsigned Size,
877880
if (BaseRegNum == BC.MRI->getProgramCounter())
878881
ArrayStart += getAddress() + Offset + Size;
879882

883+
if (FixedEntryLoadInstr) {
884+
assert(BranchType == IndirectBranchType::POSSIBLE_PIC_FIXED_BRANCH &&
885+
"Invalid IndirectBranch type");
886+
MCInst::iterator FixedEntryDispOperand =
887+
BC.MIB->getMemOperandDisp(*FixedEntryLoadInstr);
888+
assert(FixedEntryDispOperand != FixedEntryLoadInstr->end() &&
889+
"Invalid memory instruction");
890+
const MCExpr *FixedEntryDispExpr = FixedEntryDispOperand->getExpr();
891+
const uint64_t EntryAddress = getExprValue(FixedEntryDispExpr);
892+
uint64_t EntrySize = BC.getJumpTableEntrySize(JumpTable::JTT_PIC);
893+
ErrorOr<int64_t> Value =
894+
BC.getSignedValueAtAddress(EntryAddress, EntrySize);
895+
if (!Value)
896+
return IndirectBranchType::UNKNOWN;
897+
898+
BC.outs() << "BOLT-INFO: fixed PIC indirect branch detected in " << *this
899+
<< " at 0x" << Twine::utohexstr(getAddress() + Offset)
900+
<< " referencing data at 0x" << Twine::utohexstr(EntryAddress)
901+
<< " the destination value is 0x"
902+
<< Twine::utohexstr(ArrayStart + *Value) << '\n';
903+
904+
TargetAddress = ArrayStart + *Value;
905+
906+
// Remove spurious JumpTable at EntryAddress caused by PIC reference from
907+
// the load instruction.
908+
BC.deleteJumpTable(EntryAddress);
909+
910+
// Replace FixedEntryDispExpr used in target address calculation with outer
911+
// jump table reference.
912+
JumpTable *JT = BC.getJumpTableContainingAddress(ArrayStart);
913+
assert(JT && "Must have a containing jump table for PIC fixed branch");
914+
BC.MIB->replaceMemOperandDisp(*FixedEntryLoadInstr, JT->getFirstLabel(),
915+
EntryAddress - ArrayStart, &*BC.Ctx);
916+
917+
return BranchType;
918+
}
919+
880920
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: addressed memory is 0x"
881921
<< Twine::utohexstr(ArrayStart) << '\n');
882922

@@ -1126,6 +1166,7 @@ void BinaryFunction::handleIndirectBranch(MCInst &Instruction, uint64_t Size,
11261166
}
11271167
case IndirectBranchType::POSSIBLE_JUMP_TABLE:
11281168
case IndirectBranchType::POSSIBLE_PIC_JUMP_TABLE:
1169+
case IndirectBranchType::POSSIBLE_PIC_FIXED_BRANCH:
11291170
if (opts::JumpTables == JTS_NONE)
11301171
IsSimple = false;
11311172
break;
@@ -1878,9 +1919,11 @@ bool BinaryFunction::postProcessIndirectBranches(
18781919
int64_t DispValue;
18791920
const MCExpr *DispExpr;
18801921
MCInst *PCRelBaseInstr;
1922+
MCInst *FixedEntryLoadInstr;
18811923
IndirectBranchType Type = BC.MIB->analyzeIndirectBranch(
18821924
Instr, BB.begin(), II, PtrSize, MemLocInstr, BaseRegNum,
1883-
IndexRegNum, DispValue, DispExpr, PCRelBaseInstr);
1925+
IndexRegNum, DispValue, DispExpr, PCRelBaseInstr,
1926+
FixedEntryLoadInstr);
18841927
if (Type != IndirectBranchType::UNKNOWN || MemLocInstr != nullptr)
18851928
continue;
18861929

0 commit comments

Comments
 (0)