[llvm-dev] custom LLVM Pass with options fails to load

Viktor Was via llvm-dev llvm-dev at lists.llvm.org
Tue Jul 10 06:26:45 PDT 2018


Hi,
I'm working on an LLVM Pass plugin and I'm running into a problem when  
loading it into opt.
I want to have a custom option for my pass and added an llvm::cl::opt  
#include'ing "llvm/Support/CommandLine.h"

linking the dependant libs causes the following error when loading it  
with opt:
opt: CommandLine Error: Option 'debug-pass' registered more than once!

I narrowed it down to the Core lib but without it I get this

opt:  
/home/qwert/projects/ext/repos/llvm/6.0.0/lib/Support/CommandLine.cpp:281:  
void (anonymous  
namespace)::CommandLineParser::registerCategory(llvm::cl::OptionCategory *):  
Assertion `count_if(RegisteredOptionCategories, [cat](const  
OptionCategory *Category) { return cat->getName() ==  
Category->getName(); }) == 0 && "Duplicate option categories"' failed.
LLVMSymbolizer: error reading file: No such file or directory
#0 0x0000000001d8eea4 (opt+0x1d8eea4)
#1 0x0000000001d8f206 (opt+0x1d8f206)
#2 0x00007fb283220390 __restore_rt  
(/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
#3 0x00007fb2821cd428 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x35428)
#4 0x00007fb2821cf02a abort (/lib/x86_64-linux-gnu/libc.so.6+0x3702a)
#5 0x00007fb2821c5bd7 (/lib/x86_64-linux-gnu/libc.so.6+0x2dbd7)
#6 0x00007fb2821c5c82 (/lib/x86_64-linux-gnu/libc.so.6+0x2dc82)
#7 0x0000000001d2b2a9 (opt+0x1d2b2a9)
#8 0x00007fb281efebc2 _GLOBAL__sub_I_CommandLine.cpp  
(/home/qwert/projects/ext/projects/cmake/llvm/6.0.0/lib/TestPass.so+0x28bc2)
#9 0x00007fb28343c6ba (/lib64/ld-linux-x86-64.so.2+0x106ba)
#10 0x00007fb28343c7cb (/lib64/ld-linux-x86-64.so.2+0x107cb)
#11 0x00007fb2834418e2 (/lib64/ld-linux-x86-64.so.2+0x158e2)
#12 0x00007fb28343c564 (/lib64/ld-linux-x86-64.so.2+0x10564)
#13 0x00007fb283440da9 (/lib64/ld-linux-x86-64.so.2+0x14da9)
#14 0x00007fb282e03f09 __asprintf (/lib/x86_64-linux-gnu/libdl.so.2+0xf09)
#15 0x00007fb28343c564 (/lib64/ld-linux-x86-64.so.2+0x10564)
#16 0x00007fb282e04571 (/lib/x86_64-linux-gnu/libdl.so.2+0x1571)
#17 0x00007fb282e03fa1 dlopen (/lib/x86_64-linux-gnu/libdl.so.2+0xfa1)
#18 0x0000000001d7b88b (opt+0x1d7b88b)
#19 0x0000000001d44de9 (opt+0x1d44de9)
#20 0x000000000069f0b4 (opt+0x69f0b4)
#21 0x0000000001d35a91 (opt+0x1d35a91)
#22 0x0000000001d2e3b9 (opt+0x1d2e3b9)
#23 0x00000000006958b4 (opt+0x6958b4)
#24 0x00007fb2821b8830 __libc_start_main  
(/lib/x86_64-linux-gnu/libc.so.6+0x20830)
#25 0x0000000000686be9 (opt+0x686be9)
Stack dump:
0.	Program arguments: opt -load  
/home/maliusarth/projects/ext/projects/cmake/llvm/6.0.0/lib/TestPass.so  
-testPass test.cpp
Aborted


in my cmakelists.txt I have the following:

set(CMAKE_BUILD_TYPE Debug)

set(LLVM_LINK_COMPONENTS
	Core # narrowed it down to this
	BinaryFormat
	Support
	Demangle
)

add_llvm_loadable_module( TestPass
	TestPass.cpp

	DEPENDS
	intrinsics_gen
	PLUGIN_TOOL
	opt
)

in my cpp I have this:

#include "llvm/IR/Constants.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/CommandLine.h"

#include <string>

namespace
{
// Apply a custom category to all command-line options so that they are the
// only ones displayed.
static llvm::cl::OptionCategory testCategory("testPass Options");

static llvm::cl::opt<std::string>
	testOpt("testOpt", llvm::cl::desc("testOpt"),
		   llvm::cl::value_desc("test pass opt"), llvm::cl::cat(testCategory));
}

namespace test
{
char TestPass::ID = 0;

static ::llvm::RegisterPass<test::TestPass>
	X("testPass", "test pass", false /* Only looks at CFG */,
	  false /* Analysis Pass */);
}

the rest of the file is more or less straight out of the Hello example.

I'm working with this llvm version  
http://llvm.org/svn/llvm-project/llvm/tags/RELEASE_600/final

I'd appreciate any help on this issue.

Viktor



More information about the llvm-dev mailing list