Skip to content

Commit

Permalink
fix llvm15 compilation error
Browse files Browse the repository at this point in the history
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
  llvm/llvm-project@d593cf7
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.

Signed-off-by: Yonghong Song <[email protected]>
  • Loading branch information
yonghong-song committed Feb 15, 2022
1 parent 2895551 commit d7ff054
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/cc/bcc_debug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/cc/bpf_module_rw_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit d7ff054

Please sign in to comment.