llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

CommandLine Error: Option 'enable-fs-discriminator' registered more than once

Open Qfrost911 opened this issue 3 years ago • 1 comments

Env: Ubuntu 18 LLVM 17 (last commit: 0ec4cae146e37d97f39818d89e4f2209dcde38ee)

When I use a IR plugin in Clang or opt, an error was raised.

root@qfrost:/mnt/c/pass# clang++ -fpass-plugin='build/NewModulePass.so' -o build/out.out test/default.cpp
clang (LLVM option parsing): CommandLine Error: Option 'enable-fs-discriminator' registered more than once!
fatal error: error in backend: inconsistency in registered CommandLine options
clang++: error: clang frontend command failed with exit code 70 (use -v to see invocation)
opt: CommandLine Error: Option 'enable-fs-discriminator' registered more than once!
LLVM ERROR: inconsistency in registered CommandLine options
Stack dump:
0.      Program arguments: opt --load-pass-plugin=build/NewModulePass.so --passes=NewModulePass build/1-target_before.bc -o build/2-target_after.bc

I think this code can running perfect in LLVM 16, and this error was introduced when I have updated my LLVM to 17.

struct NewModulePass : public PassInfoMixin<NewModulePass> {
    static bool isRequired() { return true; }

    PreservedAnalyses run(Module &M, llvm::AnalysisManager<llvm::Module>& PAM) {
        errs() << "[+] NewModulePass: " << M.getName() << '\n';
        return PreservedAnalyses::all();
    }
};

extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK llvmGetPassPluginInfo() {                             \
    return {LLVM_PLUGIN_API_VERSION, "NewModulePass", "v0.1", [](::llvm::PassBuilder &PB) {                            \
                PB.registerPipelineParsingCallback([](::llvm::StringRef PassName, ::llvm::ModulePassManager &MPM,  \
                                                        ::llvm::ArrayRef<::llvm::PassBuilder::PipelineElement>) {    \
                    if (PassName == "NewModulePass") {                                                                 \
                        printf("[+] addPass\n");                                        \
                        MPM.addPass(NewModulePass());                                   \
                        return true;                                                                               \
                    }                                                                                              \
                    return false;                                                                                  \
                });                                                                                                \
                PB.registerPipelineStartEPCallback(                                                                \
                    [](::llvm::ModulePassManager &MPM, ::llvm::OptimizationLevel Level) {                          \
                        printf("[+] addPass\n");                                        \
                        MPM.addPass(NewModulePass());                                   \
                    });                                                                                            \
            }};                                                                                                    \
}

Qfrost911 avatar Mar 03 '23 06:03 Qfrost911

The reason causes this problem is link LLVM libs multiple under Linux.

Qfrost911 avatar Mar 09 '23 12:03 Qfrost911