summaryrefslogtreecommitdiffstats
path: root/dynamic-layers/openembedded-layer/recipes-devtools/bpftrace/bpftrace/0002-ast-Repace-getInt8PtrTy-with-getPtrTy.patch
blob: 91679631b426354db33d31a2baca406eb5ba5a7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
From 441f38a0fa9711a08ca8d904b542559593bffb16 Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Fri, 16 Feb 2024 10:32:27 -0800
Subject: [PATCH 2/4] ast: Repace getInt8PtrTy with getPtrTy

getPtrTy is added in LLVM-15 and is to be used instead of getInt8PtrTy
which is gone in LLVM-18 onwards

https://github.com/llvm/llvm-project/commit/7e0802aeb5b90

Upstream-Status: Submitted [https://github.com/bpftrace/bpftrace/pull/3009]
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 src/ast/irbuilderbpf.cpp        | 58 ++++++++++++++++-----------------
 src/ast/passes/codegen_llvm.cpp | 22 ++++++-------
 2 files changed, 40 insertions(+), 40 deletions(-)

diff --git a/src/ast/irbuilderbpf.cpp b/src/ast/irbuilderbpf.cpp
index 670a9e98..2ff3c0ce 100644
--- a/src/ast/irbuilderbpf.cpp
+++ b/src/ast/irbuilderbpf.cpp
@@ -301,7 +301,7 @@ CallInst *IRBuilderBPF::createMapLookup(const std::string &map_name,
                                         Value *key,
                                         const std::string &name)
 {
-  return createMapLookup(map_name, key, getInt8PtrTy(), name);
+  return createMapLookup(map_name, key, getPtrTy(), name);
 }
 
 CallInst *IRBuilderBPF::createMapLookup(const std::string &map_name,
@@ -329,7 +329,7 @@ CallInst *IRBuilderBPF::CreateGetJoinMap(BasicBlock *failure_callback,
 {
   return createGetScratchMap(to_string(MapManager::Type::Join),
                              "join",
-                             getInt8PtrTy(),
+                             getPtrTy(),
                              loc,
                              failure_callback);
 }
@@ -358,8 +358,8 @@ CallInst *IRBuilderBPF::createGetScratchMap(const std::string &map_name,
   BasicBlock *lookup_merge_block = BasicBlock::Create(
       module_.getContext(), "lookup_" + name + "_merge", parent);
   Value *condition = CreateICmpNE(
-      CreateIntCast(call, getInt8PtrTy(), true),
-      ConstantExpr::getCast(Instruction::IntToPtr, getInt64(0), getInt8PtrTy()),
+      CreateIntCast(call, getPtrTy(), true),
+      ConstantExpr::getCast(Instruction::IntToPtr, getInt64(0), getPtrTy()),
       "lookup_" + name + "_cond");
   CreateCondBr(condition, lookup_merge_block, lookup_failure_block);
 
@@ -379,7 +379,7 @@ Value *IRBuilderBPF::CreateMapLookupElem(Value *ctx,
                                          Value *key,
                                          const location &loc)
 {
-  assert(ctx && ctx->getType() == getInt8PtrTy());
+  assert(ctx && ctx->getType() == getPtrTy());
   return CreateMapLookupElem(ctx, map.ident, key, map.type, loc);
 }
 
@@ -389,7 +389,7 @@ Value *IRBuilderBPF::CreateMapLookupElem(Value *ctx,
                                          SizedType &type,
                                          const location &loc)
 {
-  assert(ctx && ctx->getType() == getInt8PtrTy());
+  assert(ctx && ctx->getType() == getPtrTy());
   CallInst *call = createMapLookup(map_name, key);
 
   // Check if result == 0
@@ -406,8 +406,8 @@ Value *IRBuilderBPF::CreateMapLookupElem(Value *ctx,
 
   AllocaInst *value = CreateAllocaBPF(type, "lookup_elem_val");
   Value *condition = CreateICmpNE(
-      CreateIntCast(call, getInt8PtrTy(), true),
-      ConstantExpr::getCast(Instruction::IntToPtr, getInt64(0), getInt8PtrTy()),
+      CreateIntCast(call, getPtrTy(), true),
+      ConstantExpr::getCast(Instruction::IntToPtr, getInt64(0), getPtrTy()),
       "map_lookup_cond");
   CreateCondBr(condition, lookup_success_block, lookup_failure_block);
 
@@ -449,7 +449,7 @@ void IRBuilderBPF::CreateMapUpdateElem(Value *ctx,
 {
   Value *map_ptr = GetMapVar(map.ident);
 
-  assert(ctx && ctx->getType() == getInt8PtrTy());
+  assert(ctx && ctx->getType() == getPtrTy());
   assert(key->getType()->isPointerTy());
   assert(val->getType()->isPointerTy());
 
@@ -478,7 +478,7 @@ void IRBuilderBPF::CreateMapDeleteElem(Value *ctx,
                                        Value *key,
                                        const location &loc)
 {
-  assert(ctx && ctx->getType() == getInt8PtrTy());
+  assert(ctx && ctx->getType() == getPtrTy());
   assert(key->getType()->isPointerTy());
   Value *map_ptr = GetMapVar(map.ident);
 
@@ -541,7 +541,7 @@ void IRBuilderBPF::CreateProbeRead(Value *ctx,
                                    AddrSpace as,
                                    const location &loc)
 {
-  assert(ctx && ctx->getType() == getInt8PtrTy());
+  assert(ctx && ctx->getType() == getPtrTy());
   assert(size && size->getType()->getIntegerBitWidth() <= 32);
   size = CreateIntCast(size, getInt32Ty(), false);
 
@@ -581,7 +581,7 @@ CallInst *IRBuilderBPF::CreateProbeReadStr(Value *ctx,
                                            AddrSpace as,
                                            const location &loc)
 {
-  assert(ctx && ctx->getType() == getInt8PtrTy());
+  assert(ctx && ctx->getType() == getPtrTy());
   assert(size && size->getType()->isIntegerTy());
   if ([[maybe_unused]] auto *dst_alloca = dyn_cast<AllocaInst>(dst)) {
     assert(dst_alloca->getAllocatedType()->isArrayTy() &&
@@ -615,7 +615,7 @@ Value *IRBuilderBPF::CreateUSDTReadArgument(Value *ctx,
                                             AddrSpace as,
                                             const location &loc)
 {
-  assert(ctx && ctx->getType() == getInt8PtrTy());
+  assert(ctx && ctx->getType() == getPtrTy());
   // Argument size must be 1, 2, 4, or 8. See
   // https://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation
   int abs_size = std::abs(argument->size);
@@ -711,7 +711,7 @@ Value *IRBuilderBPF::CreateUSDTReadArgument(Value *ctx,
                                             AddrSpace as,
                                             const location &loc)
 {
-  assert(ctx && ctx->getType() == getInt8PtrTy());
+  assert(ctx && ctx->getType() == getPtrTy());
   struct bcc_usdt_argument argument;
 
   void *usdt;
@@ -1337,7 +1337,7 @@ CallInst *IRBuilderBPF::CreateGetStackId(Value *ctx,
                                          StackType stack_type,
                                          const location &loc)
 {
-  assert(ctx && ctx->getType() == getInt8PtrTy());
+  assert(ctx && ctx->getType() == getPtrTy());
 
   Value *map_ptr = GetMapVar(stack_type.name());
 
@@ -1350,7 +1350,7 @@ CallInst *IRBuilderBPF::CreateGetStackId(Value *ctx,
   // Return: >= 0 stackid on success or negative error
   FunctionType *getstackid_func_type = FunctionType::get(
       getInt64Ty(),
-      { getInt8PtrTy(), map_ptr->getType(), getInt64Ty() },
+      { getPtrTy(), map_ptr->getType(), getInt64Ty() },
       false);
   CallInst *call = CreateHelperCall(libbpf::BPF_FUNC_get_stackid,
                                     getstackid_func_type,
@@ -1399,7 +1399,7 @@ void IRBuilderBPF::CreateOutput(Value *ctx,
                                 size_t size,
                                 const location *loc)
 {
-  assert(ctx && ctx->getType() == getInt8PtrTy());
+  assert(ctx && ctx->getType() == getPtrTy());
   assert(data && data->getType()->isPointerTy());
 
   if (bpftrace_.feature_->has_map_ringbuf()) {
@@ -1464,8 +1464,8 @@ void IRBuilderBPF::CreateAtomicIncCounter(const std::string &map_name,
                                                       parent);
 
   Value *condition = CreateICmpNE(
-      CreateIntCast(call, getInt8PtrTy(), true),
-      ConstantExpr::getCast(Instruction::IntToPtr, getInt64(0), getInt8PtrTy()),
+      CreateIntCast(call, getPtrTy(), true),
+      ConstantExpr::getCast(Instruction::IntToPtr, getInt64(0), getPtrTy()),
       "map_lookup_cond");
   CreateCondBr(condition, lookup_success_block, lookup_failure_block);
 
@@ -1521,8 +1521,8 @@ void IRBuilderBPF::CreateMapElemAdd(Value *ctx,
 
   AllocaInst *value = CreateAllocaBPF(type, "lookup_elem_val");
   Value *condition = CreateICmpNE(
-      CreateIntCast(call, getInt8PtrTy(), true),
-      ConstantExpr::getCast(Instruction::IntToPtr, getInt64(0), getInt8PtrTy()),
+      CreateIntCast(call, getPtrTy(), true),
+      ConstantExpr::getCast(Instruction::IntToPtr, getInt64(0), getPtrTy()),
       "map_lookup_cond");
   CreateCondBr(condition, lookup_success_block, lookup_failure_block);
 
@@ -1557,7 +1557,7 @@ void IRBuilderBPF::CreatePerfEventOutput(Value *ctx,
   // long bpf_perf_event_output(struct pt_regs *ctx, struct bpf_map *map,
   //                            u64 flags, void *data, u64 size)
   FunctionType *perfoutput_func_type = FunctionType::get(getInt64Ty(),
-                                                         { getInt8PtrTy(),
+                                                         { getPtrTy(),
                                                            map_ptr->getType(),
                                                            getInt64Ty(),
                                                            data->getType(),
@@ -1600,7 +1600,7 @@ void IRBuilderBPF::CreateTracePrintk(Value *fmt_ptr,
 
   // long bpf_trace_printk(const char *fmt, u32 fmt_size, ...)
   FunctionType *traceprintk_func_type = FunctionType::get(
-      getInt64Ty(), { getInt8PtrTy(), getInt32Ty() }, true);
+      getInt64Ty(), { getPtrTy(), getInt32Ty() }, true);
 
   CreateHelperCall(libbpf::BPF_FUNC_trace_printk,
                    traceprintk_func_type,
@@ -1630,7 +1630,7 @@ void IRBuilderBPF::CreateOverrideReturn(Value *ctx, Value *rc)
   // long bpf_override_return(struct pt_regs *regs, u64 rc)
   // Return: 0
   FunctionType *override_func_type = FunctionType::get(
-      getInt64Ty(), { getInt8PtrTy(), getInt64Ty() }, false);
+      getInt64Ty(), { getPtrTy(), getInt64Ty() }, false);
   PointerType *override_func_ptr_type = PointerType::get(override_func_type, 0);
   Constant *override_func = ConstantExpr::getCast(
       Instruction::IntToPtr,
@@ -1807,7 +1807,7 @@ void IRBuilderBPF::CreateHelperError(Value *ctx,
                                      libbpf::bpf_func_id func_id,
                                      const location &loc)
 {
-  assert(ctx && ctx->getType() == getInt8PtrTy());
+  assert(ctx && ctx->getType() == getPtrTy());
   assert(return_value && return_value->getType() == getInt32Ty());
 
   if (bpftrace_.helper_check_level_ == 0 ||
@@ -1847,7 +1847,7 @@ void IRBuilderBPF::CreateHelperErrorCond(Value *ctx,
                                          const location &loc,
                                          bool compare_zero)
 {
-  assert(ctx && ctx->getType() == getInt8PtrTy());
+  assert(ctx && ctx->getType() == getPtrTy());
   if (bpftrace_.helper_check_level_ == 0 ||
       (bpftrace_.helper_check_level_ == 1 && return_zero_if_err(func_id)))
     return;
@@ -1883,7 +1883,7 @@ void IRBuilderBPF::CreatePath(Value *ctx,
   // int bpf_d_path(struct path *path, char *buf, u32 sz)
   // Return: 0 or error
   FunctionType *d_path_func_type = FunctionType::get(
-      getInt64Ty(), { getInt8PtrTy(), buf->getType(), getInt32Ty() }, false);
+      getInt64Ty(), { getPtrTy(), buf->getType(), getInt32Ty() }, false);
   CallInst *call = CreateHelperCall(
       libbpf::bpf_func_id::BPF_FUNC_d_path,
       d_path_func_type,
@@ -1905,9 +1905,9 @@ void IRBuilderBPF::CreateSeqPrintf(Value *ctx,
   // Return: 0 or error
   FunctionType *seq_printf_func_type = FunctionType::get(getInt64Ty(),
                                                          { getInt64Ty(),
-                                                           getInt8PtrTy(),
+                                                           getPtrTy(),
                                                            getInt32Ty(),
-                                                           getInt8PtrTy(),
+                                                           getPtrTy(),
                                                            getInt32Ty() },
                                                          false);
   PointerType *seq_printf_func_ptr_type = PointerType::get(seq_printf_func_type,
diff --git a/src/ast/passes/codegen_llvm.cpp b/src/ast/passes/codegen_llvm.cpp
index 073d48ae..258b0b0b 100644
--- a/src/ast/passes/codegen_llvm.cpp
+++ b/src/ast/passes/codegen_llvm.cpp
@@ -380,10 +380,10 @@ void CodegenLLVM::visit(Call &call)
 
     AllocaInst *value = b_.CreateAllocaBPF(type, "lookup_elem_val");
     Value *condition = b_.CreateICmpNE(
-        b_.CreateIntCast(lookup, b_.getInt8PtrTy(), true),
+        b_.CreateIntCast(lookup, b_.getPtrTy(), true),
         ConstantExpr::getCast(Instruction::IntToPtr,
                               b_.getInt64(0),
-                              b_.getInt8PtrTy()),
+                              b_.getPtrTy()),
         "map_lookup_cond");
     b_.CreateCondBr(condition, lookup_success_block, lookup_failure_block);
 
@@ -437,10 +437,10 @@ void CodegenLLVM::visit(Call &call)
 
     AllocaInst *value = b_.CreateAllocaBPF(type, "lookup_elem_val");
     Value *condition = b_.CreateICmpNE(
-        b_.CreateIntCast(lookup, b_.getInt8PtrTy(), true),
+        b_.CreateIntCast(lookup, b_.getPtrTy(), true),
         ConstantExpr::getCast(Instruction::IntToPtr,
                               b_.getInt64(0),
-                              b_.getInt8PtrTy()),
+                              b_.getPtrTy()),
         "map_lookup_cond");
     b_.CreateCondBr(condition, lookup_success_block, lookup_failure_block);
 
@@ -687,7 +687,7 @@ void CodegenLLVM::visit(Call &call)
                                     ? Instruction::BitCast
                                     : Instruction::IntToPtr,
                                 expr_,
-                                b_.getInt8PtrTy()),
+                                b_.getPtrTy()),
                   call.loc);
     expr_ = buf;
     expr_deleter_ = [this, buf]() { b_.CreateLifetimeEnd(buf); };
@@ -919,9 +919,9 @@ void CodegenLLVM::visit(Call &call)
 
       // and finally the seq_printf call
       b_.CreateSeqPrintf(ctx_,
-                         b_.CreateIntToPtr(fmt, b_.getInt8PtrTy()),
+                         b_.CreateIntToPtr(fmt, b_.getPtrTy()),
                          b_.getInt32(size),
-                         b_.CreatePointerCast(data, b_.getInt8PtrTy()),
+                         b_.CreatePointerCast(data, b_.getPtrTy()),
                          b_.getInt32(data_size),
                          call.loc);
 
@@ -950,7 +950,7 @@ void CodegenLLVM::visit(Call &call)
       values.push_back(expr_);
     }
 
-    b_.CreateTracePrintk(b_.CreateIntToPtr(fmt, b_.getInt8PtrTy()),
+    b_.CreateTracePrintk(b_.CreateIntToPtr(fmt, b_.getPtrTy()),
                          b_.getInt32(size),
                          values,
                          call.loc);
@@ -1878,7 +1878,7 @@ void CodegenLLVM::visit(FieldAccess &acc)
         // `is_data_loc` should only be set if field access is on `args` which
         // has to be a ctx access
         assert(type.IsCtxAccess());
-        assert(ctx_->getType() == b_.getInt8PtrTy());
+        assert(ctx_->getType() == b_.getPtrTy());
         // Parser needs to have rewritten field to be a u64
         assert(field.type.IsIntTy());
         assert(field.type.GetIntBitWidth() == 64);
@@ -2416,7 +2416,7 @@ void CodegenLLVM::createRet(Value *value)
 void CodegenLLVM::visit(Probe &probe)
 {
   FunctionType *func_type = FunctionType::get(b_.getInt64Ty(),
-                                              { b_.getInt8PtrTy() }, // struct
+                                              { b_.getPtrTy() }, // struct
                                                                      // pt_regs
                                                                      // *ctx
                                               false);
@@ -3773,7 +3773,7 @@ Function *CodegenLLVM::createMapLenCallback()
   auto saved_ip = b_.saveIP();
 
   std::array<llvm::Type *, 4> args = {
-    b_.getInt8PtrTy(), b_.getInt8PtrTy(), b_.getInt8PtrTy(), b_.getInt8PtrTy()
+    b_.getPtrTy(), b_.getPtrTy(), b_.getPtrTy(), b_.getPtrTy()
   };
 
   FunctionType *callback_type = FunctionType::get(b_.getInt64Ty(), args, false);
-- 
2.43.2