[Lldb-commits] [lldb] [lldb] Handle ConstantExpr constants in InjectPointerSigningFixupCode (PR #194476)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Mon Apr 27 15:52:26 PDT 2026
================
@@ -38,38 +38,58 @@
#include "llvm/IR/Constants.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Instructions.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TargetParser/Triple.h"
using namespace llvm;
namespace {
+struct ExprStep {
+ ConstantExpr *CE;
+ unsigned OperandIdx;
+};
+
struct PtrAuthFixup {
GlobalVariable *GV;
ConstantPtrAuth *CPA;
- SmallVector<unsigned> Indices;
+ SmallVector<unsigned> GEPPath;
+ SmallVector<ExprStep> ExprPath;
PtrAuthFixup(GlobalVariable *GV, ConstantPtrAuth *CPA,
- const SmallVectorImpl<unsigned> &Indices)
- : GV(GV), CPA(CPA), Indices(Indices.begin(), Indices.end()) {}
+ const SmallVectorImpl<unsigned> &GEPPath,
+ const SmallVectorImpl<ExprStep> &ExprPath)
+ : GV(GV), CPA(CPA), GEPPath(GEPPath.begin(), GEPPath.end()),
+ ExprPath(ExprPath.begin(), ExprPath.end()) {}
};
} // namespace
/// Recursively walk a constant looking for ConstantPtrAuth expressions.
-/// When found, record the global variable containing the ConstantPtrAuth and
-/// the index path to reach it within the initializer.
+/// Aggregate types are walked via GEP indices. ContantExpr types are
+/// traversed via ExprStep (ConstantExpr + Operand index).
static void findPtrAuth(Constant *C, GlobalVariable &GV,
- SmallVectorImpl<unsigned> &Indices,
+ SmallVectorImpl<unsigned> &GEPPath,
+ SmallVectorImpl<ExprStep> &ExprPath,
SmallVectorImpl<PtrAuthFixup> &Fixups) {
if (auto *CPA = dyn_cast<ConstantPtrAuth>(C)) {
- Fixups.emplace_back(&GV, CPA, Indices);
+ Fixups.emplace_back(&GV, CPA, GEPPath, ExprPath);
return;
}
- for (unsigned I = 0, E = C->getNumOperands(); I != E; ++I) {
- if (auto *COp = dyn_cast<Constant>(C->getOperand(I))) {
- Indices.push_back(I);
- findPtrAuth(COp, GV, Indices, Fixups);
- Indices.pop_back();
+ if (isa<ConstantAggregate>(C)) {
+ for (unsigned I = 0, E = C->getNumOperands(); I != E; ++I) {
+ if (auto *COp = dyn_cast<Constant>(C->getOperand(I))) {
+ GEPPath.push_back(I);
+ findPtrAuth(COp, GV, GEPPath, ExprPath, Fixups);
+ GEPPath.pop_back();
+ }
+ }
+ } else if (auto *CE = dyn_cast<ConstantExpr>(C)) {
+ for (unsigned I = 0, E = C->getNumOperands(); I != E; ++I) {
+ if (auto *COp = dyn_cast<Constant>(C->getOperand(I))) {
+ ExprPath.push_back({CE, I});
+ findPtrAuth(COp, GV, GEPPath, ExprPath, Fixups);
+ ExprPath.pop_back();
+ }
}
}
----------------
JDevlieghere wrote:
```suggestion
if (isa<ConstantAggregate>(C)) {
for (unsigned I = 0, E = C->getNumOperands(); I != E; ++I) {
if (auto *COp = dyn_cast<Constant>(C->getOperand(I))) {
GEPPath.push_back(I);
findPtrAuth(COp, GV, GEPPath, ExprPath, Fixups);
GEPPath.pop_back();
}
}
return;
}
if (auto *CE = dyn_cast<ConstantExpr>(C)) {
for (unsigned I = 0, E = C->getNumOperands(); I != E; ++I) {
if (auto *COp = dyn_cast<Constant>(C->getOperand(I))) {
ExprPath.push_back({CE, I});
findPtrAuth(COp, GV, GEPPath, ExprPath, Fixups);
ExprPath.pop_back();
}
}
}
```
https://github.com/llvm/llvm-project/pull/194476
More information about the lldb-commits
mailing list