Commit 72bb0d56 authored by yonghong-song's avatar yonghong-song Committed by GitHub

fix compilation error with latest llvm 8.0 trunk (#1976)

In llvm/clang 8 trunk, the following commits
  https://reviews.llvm.org/rL339384
  https://reviews.llvm.org/rL339385
  https://reviews.llvm.org/rL339386
renames getLocStart to getBeginLoc, and getLocEnd to getEndLoc.
This caused bcc compilation error with llvm/clang 8.
To avoid proliferation of #define's based on LLVM version numbers
and similar logic for many different types,
this patch fixed the issues by define macros in common
frontend_action_common.h where macro definition is multi-versioned
based on llvm version. The macro itself is used in
{b,tp}_frontend_action.cc.

clang 8 also introduced a new library dependency
  libclangAnalysis.a depends on libclangASTMatchers.a
This patch fixed this issue as well.
Signed-off-by: default avatarYonghong Song <yhs@fb.com>
parent 61484e17
...@@ -45,6 +45,7 @@ find_library(libclangParse NAMES clangParse HINTS ${CLANG_SEARCH}) ...@@ -45,6 +45,7 @@ find_library(libclangParse NAMES clangParse HINTS ${CLANG_SEARCH})
find_library(libclangRewrite NAMES clangRewrite HINTS ${CLANG_SEARCH}) find_library(libclangRewrite NAMES clangRewrite HINTS ${CLANG_SEARCH})
find_library(libclangSema NAMES clangSema HINTS ${CLANG_SEARCH}) find_library(libclangSema NAMES clangSema HINTS ${CLANG_SEARCH})
find_library(libclangSerialization NAMES clangSerialization HINTS ${CLANG_SEARCH}) find_library(libclangSerialization NAMES clangSerialization HINTS ${CLANG_SEARCH})
find_library(libclangASTMatchers NAMES clangASTMatchers HINTS ${CLANG_SEARCH})
if(libclangBasic STREQUAL "libclangBasic-NOTFOUND") if(libclangBasic STREQUAL "libclangBasic-NOTFOUND")
message(FATAL_ERROR "Unable to find clang libraries") message(FATAL_ERROR "Unable to find clang libraries")
endif() endif()
......
...@@ -23,7 +23,13 @@ endif() ...@@ -23,7 +23,13 @@ endif()
set(clang_libs set(clang_libs
${libclangFrontend} ${libclangFrontend}
${libclangSerialization} ${libclangSerialization}
${libclangDriver} ${libclangDriver})
if (${LLVM_PACKAGE_VERSION} VERSION_EQUAL 8 OR ${LLVM_PACKAGE_VERSION} VERSION_GREATER 8)
list(APPEND clang_libs ${libclangASTMatchers})
endif()
list(APPEND clang_libs
${libclangParse} ${libclangParse}
${libclangSema} ${libclangSema}
${libclangCodeGen} ${libclangCodeGen}
......
This diff is collapsed.
/*
* Copyright (c) 2018 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if LLVM_MAJOR_VERSION >= 8
#define GET_BEGINLOC(E) ((E)->getBeginLoc())
#define GET_ENDLOC(E) ((E)->getEndLoc())
#else
#define GET_BEGINLOC(E) ((E)->getLocStart())
#define GET_ENDLOC(E) ((E)->getLocEnd())
#endif
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <clang/Frontend/MultiplexConsumer.h> #include <clang/Frontend/MultiplexConsumer.h>
#include <clang/Rewrite/Core/Rewriter.h> #include <clang/Rewrite/Core/Rewriter.h>
#include "frontend_action_common.h"
#include "tp_frontend_action.h" #include "tp_frontend_action.h"
namespace ebpf { namespace ebpf {
...@@ -209,11 +210,11 @@ bool TracepointTypeVisitor::VisitFunctionDecl(FunctionDecl *D) { ...@@ -209,11 +210,11 @@ bool TracepointTypeVisitor::VisitFunctionDecl(FunctionDecl *D) {
string tp_cat, tp_evt; string tp_cat, tp_evt;
if (_is_tracepoint_struct_type(type_name, tp_cat, tp_evt)) { if (_is_tracepoint_struct_type(type_name, tp_cat, tp_evt)) {
string tp_struct = GenerateTracepointStruct( string tp_struct = GenerateTracepointStruct(
D->getLocStart(), tp_cat, tp_evt); GET_BEGINLOC(D), tp_cat, tp_evt);
// Get the actual function declaration point (the macro instantiation // Get the actual function declaration point (the macro instantiation
// point if using the TRACEPOINT_PROBE macro instead of the macro // point if using the TRACEPOINT_PROBE macro instead of the macro
// declaration point in bpf_helpers.h). // declaration point in bpf_helpers.h).
auto insert_loc = D->getLocStart(); auto insert_loc = GET_BEGINLOC(D);
insert_loc = rewriter_.getSourceMgr().getFileLoc(insert_loc); insert_loc = rewriter_.getSourceMgr().getFileLoc(insert_loc);
rewriter_.InsertText(insert_loc, tp_struct); rewriter_.InsertText(insert_loc, tp_struct);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment