Index: tools/opt/CMakeLists.txt =================================================================== --- tools/opt/CMakeLists.txt +++ tools/opt/CMakeLists.txt @@ -22,6 +22,7 @@ TransformUtils Vectorize Passes + Linker ) # Support plugins. @@ -31,6 +32,7 @@ AnalysisWrappers.cpp BreakpointPrinter.cpp Debugify.cpp + EnsurePluginSymbols.cpp GraphPrinters.cpp NewPMDriver.cpp PassPrinters.cpp Index: tools/opt/EnsurePluginSymbols.cpp =================================================================== --- /dev/null +++ tools/opt/EnsurePluginSymbols.cpp @@ -0,0 +1,27 @@ +//===- EnsurePluginSymbols.cpp - ------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Plugins via the -load mechanism may require symbols that opt itself does not +// use. This file ensures that those symbols are added to the executable by the +// static library linker. +// +//===----------------------------------------------------------------------===// + +#include "llvm/IR/Module.h" +#include "llvm/Linker/Linker.h" + +using namespace llvm; + +void ensurePluginSymbols() { + LLVMContext C; + Module M("", C); + + // Linker is e.g. required by Polly's GPGPU generator to link libdevice with + // user code. + Linker L(M); +}