Question about adding a pass in LLVM

Hi, I’ve met a problem when I am trying llvm.
I’ve added a small pass in it, and when I define or use an object of APInt class, it will get the following output while running:

$ opt -load hello.so -hello test.bc -o test.hello.bc
opt: CommandLine Error: Argument ‘disable-opt’ defined more than once!
opt: CommandLine Error: Argument ‘disable-inlining’ defined more than once!
opt: CommandLine Error: Argument ‘strip-debug’ defined more than once!
opt: CommandLine Error: Argument ‘verify-each’ defined more than once!
opt: CommandLine Error: Argument ‘disable-verify’ defined more than once!
opt: CommandLine Error: Argument ‘disable-output’ defined more than once!
opt: CommandLine Error: Argument ‘p’ defined more than once!
opt: CommandLine Error: Argument ‘f’ defined more than once!
opt: CommandLine Error: Argument ‘o’ defined more than once!
opt: CommandLine Error: Argument ‘argpromotion’ defined more than once!
… (it just repeated outputting the last line, without stop…)

Has anybody met the similiar problem with me?
Thanks :slight_smile:

Hi Fiona,

Fiona Sheen wrote:

Hi, I've met a problem when I am trying llvm.
I've added a small pass in it, and when I define or use an object of APInt class, it will get the following output while running:
$ opt -load hello.so -hello test.bc -o test.hello.bc
opt: CommandLine Error: Argument 'disable-opt' defined more than once!
opt: CommandLine Error: Argument 'disable-inlining' defined more than once!
opt: CommandLine Error: Argument 'strip-debug' defined more than once!
opt: CommandLine Error: Argument 'verify-each' defined more than once!
opt: CommandLine Error: Argument 'disable-verify' defined more than once!
opt: CommandLine Error: Argument 'disable-output' defined more than once!
opt: CommandLine Error: Argument 'p' defined more than once!
opt: CommandLine Error: Argument 'f' defined more than once!
opt: CommandLine Error: Argument 'o' defined more than once!
opt: CommandLine Error: Argument 'argpromotion' defined more than once!
..... (it just repeated outputting the last line, without stop...)
Has anybody met the similiar problem with me?

When you link the hello.so module, do not link *any* LLVM code into it. The references will get resolved at run time. This looks to me like you've linked some of the opt code itself into hello.so. I suggest you follow the pattern in lib/Transforms/Hello. In particular this means a) you build your "hello" module in a separate directory, b) the Makefile looks just like the one in lib/Transforms/Hello.

In this arrangement, it is possible (but unlikely) that you could end up with unresolved symbols (because your module references something in LLVM that is not linked into opt). If that is the case, you have two options: a) copy the code from LLLVM into your module and compile and statically link it into your module, or b) use a different mechanism (code) to achieve the same end (e.g. if you were using SmallPtrSet, just use std::set).

Hope this helps.

Reid.