[llvm-dev] writing a pass, questions (original) (raw)

Preston Briggs via llvm-dev llvm-dev at lists.llvm.org
Mon Apr 10 20:57:47 PDT 2017


I'm moving a couple of dynamically loaded passes from an older version of LLVM to a newer one. I fixed various small compilation errors, and things compile now, but the resulting .so won't load without error.

So I re-read the manual (Writing an LLVM Pass) and tried the first example, Hello.cpp which produces LLVMHello.cpp The code's already there in the source tree and it builds and loads correctly. So I tried copying the directory and doing a little editing. It builds but again fails to load.

Here's what I type

opt -load LLVMZap.so -help

and here's what I see

Error opening 'LLVMZap.so': /home/briggs/llvm-cilk/new_install/bin/../lib/LLVMZap.so: undefined symbol: _ZNK4llvm12FunctionPass17createPrinterPassERNS_11raw_ostreamERKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEE -load request ignored.

The error message is quite similar to what I see when I'm experimenting with my old pass.

Any ideas?

Here's the contents of CMake.txt

If we don't need RTTI or EH, there's no reason to export anything

from the hello plugin.

if( NOT LLVM_REQUIRES_RTTI ) if( NOT LLVM_REQUIRES_EH ) set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/Zap.exports) endif() endif()

add_llvm_loadable_module( LLVMZap Zap.cpp

DEPENDS intrinsics_gen PLUGIN_TOOL opt )

And the contents of Zap.cpp

#include "llvm/IR/Function.h" #include "llvm/Pass.h" #include "llvm/Support/raw_ostream.h" using namespace llvm;

namespace { struct Zap : public FunctionPass { static char ID; // Pass identification, replacement for typeid Zap() : FunctionPass(ID) {}

bool runOnFunction(Function &F) override {
  errs() << "Zap! ";
  errs().write_escaped(F.getName()) << '\n';
  return false;
}

}; }

char Zap::ID = 0; static RegisterPass X("zap", "Zap Pass");

Thanks, Preston -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170410/897de228/attachment.html>



More information about the llvm-dev mailing list