summaryrefslogtreecommitdiffstats
path: root/dynamic-layers/openembedded-layer/recipes-devtools/bpftrace/bpftrace/0001-bpftrace-Fix-compilation-with-LLVM-11.patch
blob: 44aac984e4794c7db2d79656e1a25f7e7d4ac475 (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
From 7c9ee9b7054413b6e5f73db6c0ca56e6a7c0504b Mon Sep 17 00:00:00 2001
From: Ovidiu Panait <ovidiu.panait@windriver.com>
Date: Thu, 6 Aug 2020 10:34:23 +0300
Subject: [PATCH] irbuilderbpf.cpp, bpforc.h: Fix compilation with LLVM 11

Fixes: #1384

Fix the following build errors when compiling with LLVM 11:

 #1
----
/llvm/include/llvm/ExecutionEngine/Orc/Legacy.h:118:35: error: no match for call to ‘(bpftrace::BpfOrc::BpfOrc(llvm::TargetMachine*)::<lambda(const string&)>) (llvm::StringRef)’
  118 |     if (JITSymbol Sym = FindSymbol(*S)) {
      |                         ~~~~~~~~~~^~~~
/llvm/include/llvm/ExecutionEngine/Orc/Legacy.h:118:35: note: candidate: ‘llvm::JITSymbol (*)(const string&)’ {aka ‘llvm::JITSymbol (*)(const std::__cxx11::basic_string<char>&)’} <conversion>
/llvm/include/llvm/ExecutionEngine/Orc/Legacy.h:118:35: note:   candidate expects 2 arguments, 2 provided
In file included from /work/src/github.com/iovisor/bpftrace/src/ast/codegen_llvm.cpp:5:
/work/src/github.com/iovisor/bpftrace/src/bpforc.h:99:13: note: candidate: ‘bpftrace::BpfOrc::BpfOrc(llvm::TargetMachine*)::<lambda(const string&)>’
   99 |             [](const std::string &Name __attribute__((unused))) -> JITSymbol {
      |             ^
/work/src/github.com/iovisor/bpftrace/src/bpforc.h:99:13: note:   no known conversion for argument 1 from ‘llvm::StringRef’ to ‘const string&’ {aka ‘const std::__cxx11::basic_string<char>&’}
In file included from /llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h:23,

 #2
----
| /src/ast/irbuilderbpf.cpp: In member function 'llvm::CallInst* bpftrace::ast::IRBuilderBPF::createMapLookup(int, llvm::AllocaInst*)':
| /src/ast/irbuilderbpf.cpp:230:65: error: no matching function for call to 'bpftrace::ast::IRBuilderBPF::CreateCall(llvm::Constant*&, <brace-enclosed initializer list>, const char [12])'
|   230 |   return CreateCall(lookup_func, { map_ptr, key }, "lookup_elem");
|       |                                                                 ^
| In file included from /src/ast/irbuilderbpf.h:9,
|                  from /src/ast/async_event_types.h:3,
|                  from /src/ast/irbuilderbpf.cpp:5:
| /usr/include/llvm/IR/IRBuilder.h:2324:13: note: candidate: 'llvm::CallInst* llvm::IRBuilderBase::CreateCall(llvm::FunctionType*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, const llvm::Twine&, llvm::MDNode*)'
|  2324 |   CallInst *CreateCall(FunctionType *FTy, Value *Callee,
|       |             ^~~~~~~~~~
| /usr/include/llvm/IR/IRBuilder.h:2324:38: note:   no known conversion for argument 1 from 'llvm::Constant*' to 'llvm::FunctionType*'
|  2324 |   CallInst *CreateCall(FunctionType *FTy, Value *Callee,
|       |                        ~~~~~~~~~~~~~~^~~


The CreateCall part is based on the llvm 11 fix from bcc:
https://github.com/iovisor/bcc/commit/45e63f2b316cdce2d8cc925f6f14a8726ade9ff6

Upstream-Status: Submitted [https://github.com/iovisor/bpftrace/pull/1456]

Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
---
 src/ast/irbuilderbpf.cpp | 49 ++++++++++++++++++++++++----------------
 src/ast/irbuilderbpf.h   |  1 +
 src/bpforc.h             |  6 +++++
 3 files changed, 37 insertions(+), 19 deletions(-)

diff --git a/src/ast/irbuilderbpf.cpp b/src/ast/irbuilderbpf.cpp
index 8ae055e6..108c80e4 100644
--- a/src/ast/irbuilderbpf.cpp
+++ b/src/ast/irbuilderbpf.cpp
@@ -201,10 +201,21 @@ llvm::Type *IRBuilderBPF::GetType(const SizedType &stype)
   return ty;
 }
 
+CallInst *IRBuilderBPF::createCall(Value *callee, ArrayRef<Value *> args, const Twine &Name)
+{
+#if LLVM_VERSION_MAJOR >= 11
+  auto *calleePtrType = cast<PointerType>(callee->getType());
+  auto *calleeType = cast<FunctionType>(calleePtrType->getElementType());
+  return CreateCall(calleeType, callee, args, Name);
+#else
+  return CreateCall(callee, args, Name);
+#endif
+}
+
 CallInst *IRBuilderBPF::CreateBpfPseudoCall(int mapfd)
 {
   Function *pseudo_func = module_.getFunction("llvm.bpf.pseudo");
-  return CreateCall(pseudo_func, {getInt64(BPF_PSEUDO_MAP_FD), getInt64(mapfd)}, "pseudo");
+  return createCall(pseudo_func, {getInt64(BPF_PSEUDO_MAP_FD), getInt64(mapfd)}, "pseudo");
 }
 
 CallInst *IRBuilderBPF::CreateBpfPseudoCall(Map &map)
@@ -227,7 +238,7 @@ CallInst *IRBuilderBPF::createMapLookup(int mapfd, AllocaInst *key)
       Instruction::IntToPtr,
       getInt64(libbpf::BPF_FUNC_map_lookup_elem),
       lookup_func_ptr_type);
-  return CreateCall(lookup_func, { map_ptr, key }, "lookup_elem");
+  return createCall(lookup_func, { map_ptr, key }, "lookup_elem");
 }
 
 CallInst *IRBuilderBPF::CreateGetJoinMap(Value *ctx, const location &loc)
@@ -325,7 +336,7 @@ void IRBuilderBPF::CreateMapUpdateElem(Value *ctx,
       Instruction::IntToPtr,
       getInt64(libbpf::BPF_FUNC_map_update_elem),
       update_func_ptr_type);
-  CallInst *call = CreateCall(update_func,
+  CallInst *call = createCall(update_func,
                               { map_ptr, key, val, flags },
                               "update_elem");
   CreateHelperErrorCond(ctx, call, libbpf::BPF_FUNC_map_update_elem, loc);
@@ -349,7 +360,7 @@ void IRBuilderBPF::CreateMapDeleteElem(Value *ctx,
       Instruction::IntToPtr,
       getInt64(libbpf::BPF_FUNC_map_delete_elem),
       delete_func_ptr_type);
-  CallInst *call = CreateCall(delete_func, { map_ptr, key }, "delete_elem");
+  CallInst *call = createCall(delete_func, { map_ptr, key }, "delete_elem");
   CreateHelperErrorCond(ctx, call, libbpf::BPF_FUNC_map_delete_elem, loc);
 }
 
@@ -378,7 +389,7 @@ void IRBuilderBPF::CreateProbeRead(Value *ctx,
       Instruction::IntToPtr,
       getInt64(libbpf::BPF_FUNC_probe_read),
       proberead_func_ptr_type);
-  CallInst *call = CreateCall(proberead_func, { dst, size, src }, "probe_read");
+  CallInst *call = createCall(proberead_func, { dst, size, src }, "probe_read");
   CreateHelperErrorCond(ctx, call, libbpf::BPF_FUNC_probe_read, loc);
 }
 
@@ -413,7 +424,7 @@ CallInst *IRBuilderBPF::CreateProbeReadStr(Value *ctx,
 {
   assert(ctx && ctx->getType() == getInt8PtrTy());
   Constant *fn = createProbeReadStrFn(dst->getType(), src->getType());
-  CallInst *call = CreateCall(fn,
+  CallInst *call = createCall(fn,
                               { dst, getInt32(size), src },
                               "probe_read_str");
   CreateHelperErrorCond(ctx, call, libbpf::BPF_FUNC_probe_read_str, loc);
@@ -434,7 +445,7 @@ CallInst *IRBuilderBPF::CreateProbeReadStr(Value *ctx,
   auto *size_i32 = CreateIntCast(size, getInt32Ty(), false);
 
   Constant *fn = createProbeReadStrFn(dst->getType(), src->getType());
-  CallInst *call = CreateCall(fn, { dst, size_i32, src }, "probe_read_str");
+  CallInst *call = createCall(fn, { dst, size_i32, src }, "probe_read_str");
   CreateHelperErrorCond(ctx, call, libbpf::BPF_FUNC_probe_read_str, loc);
   return call;
 }
@@ -717,7 +728,7 @@ CallInst *IRBuilderBPF::CreateGetNs()
       Instruction::IntToPtr,
       getInt64(libbpf::BPF_FUNC_ktime_get_ns),
       gettime_func_ptr_type);
-  return CreateCall(gettime_func, {}, "get_ns");
+  return createCall(gettime_func, {}, "get_ns");
 }
 
 CallInst *IRBuilderBPF::CreateGetPidTgid()
@@ -730,7 +741,7 @@ CallInst *IRBuilderBPF::CreateGetPidTgid()
       Instruction::IntToPtr,
       getInt64(libbpf::BPF_FUNC_get_current_pid_tgid),
       getpidtgid_func_ptr_type);
-  return CreateCall(getpidtgid_func, {}, "get_pid_tgid");
+  return createCall(getpidtgid_func, {}, "get_pid_tgid");
 }
 
 CallInst *IRBuilderBPF::CreateGetCurrentCgroupId()
@@ -744,7 +755,7 @@ CallInst *IRBuilderBPF::CreateGetCurrentCgroupId()
       Instruction::IntToPtr,
       getInt64(libbpf::BPF_FUNC_get_current_cgroup_id),
       getcgroupid_func_ptr_type);
-  return CreateCall(getcgroupid_func, {}, "get_cgroup_id");
+  return createCall(getcgroupid_func, {}, "get_cgroup_id");
 }
 
 CallInst *IRBuilderBPF::CreateGetUidGid()
@@ -757,7 +768,7 @@ CallInst *IRBuilderBPF::CreateGetUidGid()
       Instruction::IntToPtr,
       getInt64(libbpf::BPF_FUNC_get_current_uid_gid),
       getuidgid_func_ptr_type);
-  return CreateCall(getuidgid_func, {}, "get_uid_gid");
+  return createCall(getuidgid_func, {}, "get_uid_gid");
 }
 
 CallInst *IRBuilderBPF::CreateGetCpuId()
@@ -770,7 +781,7 @@ CallInst *IRBuilderBPF::CreateGetCpuId()
       Instruction::IntToPtr,
       getInt64(libbpf::BPF_FUNC_get_smp_processor_id),
       getcpuid_func_ptr_type);
-  return CreateCall(getcpuid_func, {}, "get_cpu_id");
+  return createCall(getcpuid_func, {}, "get_cpu_id");
 }
 
 CallInst *IRBuilderBPF::CreateGetCurrentTask()
@@ -783,7 +794,7 @@ CallInst *IRBuilderBPF::CreateGetCurrentTask()
       Instruction::IntToPtr,
       getInt64(libbpf::BPF_FUNC_get_current_task),
       getcurtask_func_ptr_type);
-  return CreateCall(getcurtask_func, {}, "get_cur_task");
+  return createCall(getcurtask_func, {}, "get_cur_task");
 }
 
 CallInst *IRBuilderBPF::CreateGetRandom()
@@ -796,7 +807,7 @@ CallInst *IRBuilderBPF::CreateGetRandom()
       Instruction::IntToPtr,
       getInt64(libbpf::BPF_FUNC_get_prandom_u32),
       getrandom_func_ptr_type);
-  return CreateCall(getrandom_func, {}, "get_random");
+  return createCall(getrandom_func, {}, "get_random");
 }
 
 CallInst *IRBuilderBPF::CreateGetStackId(Value *ctx,
@@ -826,7 +837,7 @@ CallInst *IRBuilderBPF::CreateGetStackId(Value *ctx,
       Instruction::IntToPtr,
       getInt64(libbpf::BPF_FUNC_get_stackid),
       getstackid_func_ptr_type);
-  CallInst *call = CreateCall(getstackid_func,
+  CallInst *call = createCall(getstackid_func,
                               { ctx, map_ptr, flags_val },
                               "get_stackid");
   CreateHelperErrorCond(ctx, call, libbpf::BPF_FUNC_get_stackid, loc);
@@ -852,7 +863,7 @@ void IRBuilderBPF::CreateGetCurrentComm(Value *ctx,
       Instruction::IntToPtr,
       getInt64(libbpf::BPF_FUNC_get_current_comm),
       getcomm_func_ptr_type);
-  CallInst *call = CreateCall(getcomm_func,
+  CallInst *call = createCall(getcomm_func,
                               { buf, getInt64(size) },
                               "get_comm");
   CreateHelperErrorCond(ctx, call, libbpf::BPF_FUNC_get_current_comm, loc);
@@ -883,7 +894,7 @@ void IRBuilderBPF::CreatePerfEventOutput(Value *ctx, Value *data, size_t size)
       Instruction::IntToPtr,
       getInt64(libbpf::BPF_FUNC_perf_event_output),
       perfoutput_func_ptr_type);
-  CreateCall(perfoutput_func, {ctx, map_ptr, flags_val, data, size_val}, "perf_event_output");
+  createCall(perfoutput_func, {ctx, map_ptr, flags_val, data, size_val}, "perf_event_output");
 }
 
 void IRBuilderBPF::CreateSignal(Value *ctx, Value *sig, const location &loc)
@@ -899,7 +910,7 @@ void IRBuilderBPF::CreateSignal(Value *ctx, Value *sig, const location &loc)
       Instruction::IntToPtr,
       getInt64(libbpf::BPF_FUNC_send_signal),
       signal_func_ptr_type);
-  CallInst *call = CreateCall(signal_func, { sig }, "signal");
+  CallInst *call = createCall(signal_func, { sig }, "signal");
   CreateHelperErrorCond(ctx, call, libbpf::BPF_FUNC_send_signal, loc);
 }
 
@@ -913,7 +924,7 @@ void IRBuilderBPF::CreateOverrideReturn(Value *ctx, Value *rc)
   Constant *override_func = ConstantExpr::getCast(Instruction::IntToPtr,
       getInt64(libbpf::BPF_FUNC_override_return),
       override_func_ptr_type);
-  CreateCall(override_func, { ctx, rc }, "override");
+  createCall(override_func, { ctx, rc }, "override");
 }
 
 Value *IRBuilderBPF::CreatKFuncArg(Value *ctx,
diff --git a/src/ast/irbuilderbpf.h b/src/ast/irbuilderbpf.h
index d4361a8f..31115079 100644
--- a/src/ast/irbuilderbpf.h
+++ b/src/ast/irbuilderbpf.h
@@ -80,6 +80,7 @@ public:
   CallInst   *CreateGetRandom();
   CallInst   *CreateGetStackId(Value *ctx, bool ustack, StackType stack_type, const location& loc);
   CallInst   *CreateGetJoinMap(Value *ctx, const location& loc);
+  CallInst   *createCall(Value *callee, ArrayRef<Value *> args, const Twine &Name);
   void        CreateGetCurrentComm(Value *ctx, AllocaInst *buf, size_t size, const location& loc);
   void        CreatePerfEventOutput(Value *ctx, Value *data, size_t size);
   void        CreateSignal(Value *ctx, Value *sig, const location &loc);
diff --git a/src/bpforc.h b/src/bpforc.h
index a42e031a..d75f984f 100644
--- a/src/bpforc.h
+++ b/src/bpforc.h
@@ -96,9 +96,15 @@ public:
       : TM(TM_),
         Resolver(createLegacyLookupResolver(
             ES,
+#if LLVM_VERSION_MAJOR >= 11
+            [](llvm::StringRef Name __attribute__((unused))) -> JITSymbol {
+              return nullptr;
+            },
+#else
             [](const std::string &Name __attribute__((unused))) -> JITSymbol {
               return nullptr;
             },
+#endif
             [](Error Err) { cantFail(std::move(Err), "lookup failed"); })),
 #if LLVM_VERSION_MAJOR > 8
         ObjectLayer(AcknowledgeORCv1Deprecation,
-- 
2.17.1