Path: blob/main/contrib/llvm-project/llvm/lib/Passes/PassPlugin.cpp
35262 views
//===- lib/Passes/PassPluginLoader.cpp - Load Plugins for New PM Passes ---===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "llvm/Passes/PassPlugin.h"9#include "llvm/Support/raw_ostream.h"1011#include <cstdint>1213using namespace llvm;1415Expected<PassPlugin> PassPlugin::Load(const std::string &Filename) {16std::string Error;17auto Library =18sys::DynamicLibrary::getPermanentLibrary(Filename.c_str(), &Error);19if (!Library.isValid())20return make_error<StringError>(Twine("Could not load library '") +21Filename + "': " + Error,22inconvertibleErrorCode());2324PassPlugin P{Filename, Library};2526// llvmGetPassPluginInfo should be resolved to the definition from the plugin27// we are currently loading.28intptr_t getDetailsFn =29(intptr_t)Library.getAddressOfSymbol("llvmGetPassPluginInfo");3031if (!getDetailsFn)32// If the symbol isn't found, this is probably a legacy plugin, which is an33// error34return make_error<StringError>(Twine("Plugin entry point not found in '") +35Filename + "'. Is this a legacy plugin?",36inconvertibleErrorCode());3738P.Info = reinterpret_cast<decltype(llvmGetPassPluginInfo) *>(getDetailsFn)();3940if (P.Info.APIVersion != LLVM_PLUGIN_API_VERSION)41return make_error<StringError>(42Twine("Wrong API version on plugin '") + Filename + "'. Got version " +43Twine(P.Info.APIVersion) + ", supported version is " +44Twine(LLVM_PLUGIN_API_VERSION) + ".",45inconvertibleErrorCode());4647if (!P.Info.RegisterPassBuilderCallbacks)48return make_error<StringError>(Twine("Empty entry callback in plugin '") +49Filename + "'.'",50inconvertibleErrorCode());5152return P;53}545556