Infinite loop parsing opt command line options

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:

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.



cl_problem.tar.gz (3.82 KB)

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 -load -stats -debug foo.bc -o /dev/null