fix llvm15 compilation error 28/294728/1
authorYonghong Song <yhs@fb.com>
Tue, 15 Feb 2022 05:20:06 +0000 (21:20 -0800)
committerŁukasz Stelmach <l.stelmach@samsung.com>
Fri, 23 Jun 2023 20:06:04 +0000 (22:06 +0200)
With latest upstream llvm15, we have the following compilation
error:
  <...>/src/cc/bpf_module_rw_engine.cc: In member function ‘int ebpf::BPFModule::annotate()’:
  <...>/src/cc/bpf_module_rw_engine.cc:404:53: error: ‘class llvm::PointerType’ has no member named
  ‘getElementType’; did you mean ‘getArrayElementType’?
       if (StructType *st = dyn_cast<StructType>(pt->getElementType())) {
                                                     ^~~~~~~~~~~~~~
                                                     getArrayElementType

  In file included from /usr/include/c++/8/memory:80,
                   from /<...>/llvm-project/llvm/build/install/include/llvm/ADT/SmallVector.h:28,
                   from /<...>/llvm-project/llvm/build/install/include/llvm/ADT/MapVector.h:21,
                   from /<...>/llvm-project/llvm/build/install/include/llvm/DebugInfo/DWARF/DWARFContext.h:12,
                   from /<...>/src/cc/bcc_debug.cc:22:
  /usr/include/c++/8/bits/unique_ptr.h: In instantiation of ‘void std::default_delete<_Tp>::operator()(_Tp*) const [with _Tp = llvm::MCSubtargetInfo]’:
  /usr/include/c++/8/bits/unique_ptr.h:277:17:   required from ‘std::unique_ptr<_Tp, _Dp>::~unique_ptr() [with _Tp = llvm::MCSubtargetInfo; _Dp = std::default_delete<llvm::MCSubtargetInfo>]’
  /<...>/src/cc/bcc_debug.cc:136:50:   required from here
  /usr/include/c++/8/bits/unique_ptr.h:79:16: error: invalid application of ‘sizeof’ to incomplete type ‘llvm::MCSubtargetInfo’
  static_assert(sizeof(_Tp)>0,
                ^~~~~~~~~~~

There are two problems here. The first compilation error is due to
  https://github.com/llvm/llvm-project/commit/d593cf79458a59d37e75c886a4fc3ac6a02b484d
where PointerType->getElementType() is removed.
The second error is due to https://reviews.llvm.org/D119244 which reshuffles
header files which removes MCSubtargetInfo.h from some header files used in bcc_debug.cc.

Change-Id: If655d4743765130504c73fea804b967468ed7d3e
Origin: upstream, https://github.com/iovisor/bcc/commit/d7ff054cdabd881c247079c046531a5913217624
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
src/cc/bcc_debug.cc
src/cc/bpf_module_rw_engine.cc

index 52b6571ed6c319d6d237df29fbfb6002f28f1c60..77d681ac3de205274af4b2bc5efd4ed46a9dc3de 100644 (file)
@@ -29,6 +29,9 @@
 #include <llvm/MC/MCInstrInfo.h>
 #include <llvm/MC/MCObjectFileInfo.h>
 #include <llvm/MC/MCRegisterInfo.h>
+#if LLVM_MAJOR_VERSION >= 15
+#include <llvm/MC/MCSubtargetInfo.h>
+#endif
 #if LLVM_MAJOR_VERSION >= 14
 #include <llvm/MC/TargetRegistry.h>
 #else
index 533d8a1322bcba5d6f227bd02b7abefb2353525f..f1649880cb29a10e637d3a64687bc6a3117b6811 100644 (file)
@@ -401,7 +401,12 @@ int BPFModule::annotate() {
     GlobalValue *gvar = mod_->getNamedValue(table.name);
     if (!gvar) continue;
     if (PointerType *pt = dyn_cast<PointerType>(gvar->getType())) {
-      if (StructType *st = dyn_cast<StructType>(pt->getElementType())) {
+#if LLVM_MAJOR_VERSION >= 15
+      StructType *st = dyn_cast<StructType>(pt->getPointerElementType());
+#else
+      StructType *st = dyn_cast<StructType>(pt->getElementType());
+#endif
+      if (st) {
         if (st->getNumElements() < 2) continue;
         Type *key_type = st->elements()[0];
         Type *leaf_type = st->elements()[1];