[LLVMdev] Infinite loop parsing opt command line options

Mingliang LIU liuml07 at gmail.com
Sun Sep 1 02:06:40 PDT 2013

Hi Alberto,

I know nothing about the infinite loop and its root cause. However, I think
the order of loading the shared objects (i.e. the two different .so
libraries) matters. I once defined a command line option in the firstly
loaded shared object, and "extern" it in another shared object file which
was loaded afterwards. And it works.

In your case,
1. Define the cl::opt in the AnalysisPass
2. Extern the cl::opt in the TransformPass
3. opt -load libanalysis.so -load libtransform.so -stats -debug foo.bc -o


On Sat, May 25, 2013 at 12:38 AM, Alberto Magni
<alberto.magni86 at gmail.com>wrote:

> Hi all,
> I am experiencing a problem managing the command line option of a set of
> passes in my LLVM project.
> Attached you find a toy project the triggers the problem.
> The project is made up of two passes: "AnalysisPass" and "TransformPass".
> "TransformPass" requires "AnalysisPass" and they both share a common
> integer command line option called "-command-line-option"
> According to:
> http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-January/037722.html
> the proper way of sharing a cl::opt variable among multiple passes is to
> define the variable once and declare it as "explicit" in all the
> files of the passes that need it.
> To keep the project tidy the two "AnalysisPass" and "TransformPass" are
> compiled into two different .so libraries.
> The only way I can think of to share the cl::opt variable is to define is
> to define it in a separate "Support" static library which is then
> linked by both "AnalysisPass" and "TransformPass".
> When running "AnalysisPass" loading it with opt all works fine, while
> running "TransformPass" opt never returns stuck in an infinite loop.
> GDB tells me that opt is trapped somewhere into
> llvm::cl::ParseCommandLineOptions, but I am not confident with command line
> option management.
> Notice that if the cl::opt variable is not used at all in "TransformPass"
> everithing runs fine.
> Does anybody have an idea on what is going on here ?
> Is there a better way of sharing command line options among passes
> belonging to different libraries ?
> Thank you in advance.
> Cheers,
> Alberto
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

Mingliang LIU (刘明亮 in Chinese)

PACMAN Group,  Dept. of Computer Science & Technology
Tsinghua University, Beijing 100084, China
Email: liuml07 at mails.tsinghua.edu.cn
Homepage: http://pacman.cs.tsinghua.edu.cn/~liuml07/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130901/c9d64756/attachment.html>

More information about the llvm-dev mailing list