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

Philip Pfaffe via llvm-dev llvm-dev at lists.llvm.org
Thu Jul 12 01:02:54 PDT 2018


No quite, that's the _vtable_ for cl::opt<...>. Are you loading a library
that's built with RTTI in an LLVM linked without?

Philip

On Thu, Jul 12, 2018 at 2:20 AM Viktor Was <gs15m015 at technikum-wien.at>
wrote:

> Hi Philip,
>
> thanks for the quick answer.
> That makes sense, but when leaving the set LLVM_LINK_COMPONENTS out
> I get an undefined symbol when loading the plugin:
>
> _ZTVN4llvm2cl3optINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEELb0ENS0_6parserIS7_EEEE
>
> which boils down to
>
> llvm::cl::opt<std::__cxx11::basic_string<char, std::char_traits<char>,
> std::allocator<char>>, false,
> llvm::cl::parser<std::__cxx11::basic_string<char,
> std::char_traits<char>, std::allocator<char>>>>
>
> aka
>
> llvm::cl::opt<std::string, false, llvm::cl::parser<std::string>>
>
> I guess...
>
> any ideas?
>
> Viktor
>
> Quoting Philip Pfaffe <philip.pfaffe at gmail.com>:
>
> > Hi Viktor,
> >
> > I believe you shouldn't set LLVM_LINK_COMPONENTS.
> >
> > You don't need to link your TestPass against anything since opt is
> expected
> > to have everything loaded already. If you're linking against a statically
> > built LLVM, then this way you'll pull in other definitions of
> cl::opt'ions,
> > which'll then clash with the ones that are in opt.
> >
> > Cheers,
> > Philip
> >
> > On Tue, Jul 10, 2018 at 3:26 PM Viktor Was via llvm-dev <
> > llvm-dev at lists.llvm.org> wrote:
> >
> >> 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
> >>
> >> _______________________________________________
> >> LLVM Developers mailing list
> >> llvm-dev at lists.llvm.org
> >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
> >>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180712/4aead6cf/attachment.html>


More information about the llvm-dev mailing list