New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLVM ERROR: inconsistency in registered CommandLine options #102

Open
Kniyl opened this Issue Jan 12, 2018 · 8 comments

Comments

Projects
None yet
4 participants
@Kniyl
Copy link

Kniyl commented Jan 12, 2018

I just built castxml and tried to run it but:

$ castxml  --help
: CommandLine Error: Option 'help-list' registered more than once!
LLVM ERROR: inconsistency in registered CommandLine options

CastXML was built using

$ cmake -DSPHINX_EXECUTABLE=/usr/bin/sphinx-build \
        -DSPHINX_HTML=1 \
        -DSPHINX_MAN=1 \
        -DCMAKE_INSTALL_PREFIX=/usr \
        -DCastXML_INSTALL_DOC_DIR=share/doc/castxml \
        -DCastXML_INSTALL_MAN_DIR=share/man
$ make
# make install

When searching about this error, I found other tools whose support for recent LLVM version was not perfect, so including it as well:

$ ldd /usr/bin/castxml 
	linux-vdso.so.1 (0x00007ffd477bf000)
	libLLVM-5.0.so => /usr/lib/libLLVM-5.0.so (0x00007f48a7255000)
	libtinfo.so.6 => /usr/lib/libtinfo.so.6 (0x00007f48a7029000)
	libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f48a6e0b000)
	libz.so.1 => /usr/lib/libz.so.1 (0x00007f48a6bf4000)
	libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f48a686d000)
	libm.so.6 => /usr/lib/libm.so.6 (0x00007f48a6521000)
	libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f48a630a000)
	libc.so.6 => /usr/lib/libc.so.6 (0x00007f48a5f53000)
	/lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007f48add2b000)
	libffi.so.6 => /usr/lib/../lib/libffi.so.6 (0x00007f48a5d4a000)
	libedit.so.0 => /usr/lib/../lib/libedit.so.0 (0x00007f48a5b12000)
	libdl.so.2 => /usr/lib/../lib/libdl.so.2 (0x00007f48a590e000)
	libncursesw.so.6 => /usr/lib/../lib/libncursesw.so.6 (0x00007f48a56d6000)
$ llvm-config --version
5.0.1
@bradking

This comment has been minimized.

Copy link
Member

bradking commented Jan 12, 2018

The --help option is covered in our test suite and known to work well in general. We've tested with LLVM 5.0 and even more recent versions from its upstream repository (see mention in the readme). It works for me locally on Debian "testing":

$ bin/castxml --version
castxml version 0.1-g90d4abc
...
clang version 5.0.1-2 (tags/RELEASE_501/final)
...
$ ldd bin/castxml 
        linux-vdso.so.1 (0x00007ffe0de65000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f7f46863000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7f4665f000)
        libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f7f46435000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f7f46217000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f7f45ffd000)
        libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f7f45c7e000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7f4596b000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f7f45754000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7f453b1000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f7f4aad0000)
$ bin/castxml --help
...works...

I wonder how you ended up linking against a shared libLLVM-5.0.so library.

@Kniyl

This comment has been minimized.

Copy link
Author

Kniyl commented Jan 12, 2018

Thing is, this is not tied to the --help option; it just appears to be the command I tried first, but:

$ castxml --version
: CommandLine Error: Option 'help-list' registered more than once!
LLVM ERROR: inconsistency in registered CommandLine options
$ castxml
: CommandLine Error: Option 'help-list' registered more than once!
LLVM ERROR: inconsistency in registered CommandLine options
$ clang --version
clang version 5.0.1 (tags/RELEASE_501/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

As regard to the linked LLVM library, I’m building CastXML on an Archlinux using the following PKGBUILD so it really boils down to the cmake and makes calls I described in my initial post.

The only thing I added is a dependency on clang-tools-extra as cmake was complaining about a missing usr/lib/libclangApplyReplacements.a

@bradking

This comment has been minimized.

Copy link
Member

bradking commented Jan 12, 2018

I've never tried linking to LLVM/Clang using anything but the static libraries. Maybe use of the single libLLVM shared library causes the problem. See discussion of a similar problem here.

@Kniyl

This comment has been minimized.

Copy link
Author

Kniyl commented Jan 12, 2018

I will try to recompile my llvm-libs as the official package only provide dynamic ones. Will keep you updated if I succeed.

@Kniyl

This comment has been minimized.

Copy link
Author

Kniyl commented Jan 18, 2018

Ok, after trying to understand how to get LLVM static libraries on my system, I figured out they are already provided by the llvm package.

So I checked how CastXML was built by adding status messages in src/CMakeList.txt. This yielded:

-- llvm_libs=LLVMOption;LLVMBitReader;LLVMSupport;LLVMAArch64CodeGen;LLVMAArch64AsmPrinter;LLVMAArch64AsmParser;LLVMAArch64Desc;LLVMAArch64Info;LLVMAArch64Disassembler;LLVMAArch64Info;LLVMAArch64Utils;LLVMAMDGPUCodeGen;LLVMAMDGPUAsmPrinter;LLVMAMDGPUAsmParser;LLVMAMDGPUDesc;LLVMAMDGPUInfo;LLVMAMDGPUDisassembler;LLVMAMDGPUInfo;LLVMAMDGPUUtils;LLVMARMCodeGen;LLVMARMAsmPrinter;LLVMARMAsmParser;LLVMARMDesc;LLVMARMInfo;LLVMARMDisassembler;LLVMARMInfo;LLVMBPFCodeGen;LLVMBPFAsmPrinter;LLVMBPFDesc;LLVMBPFInfo;LLVMBPFDisassembler;LLVMBPFInfo;LLVMHexagonCodeGen;LLVMHexagonAsmParser;LLVMHexagonDesc;LLVMHexagonInfo;LLVMHexagonDisassembler;LLVMHexagonInfo;LLVMLanaiCodeGen;LLVMLanaiAsmPrinter;LLVMLanaiAsmParser;LLVMLanaiDesc;LLVMLanaiInfo;LLVMLanaiDisassembler;LLVMLanaiInfo;LLVMMipsCodeGen;LLVMMipsAsmPrinter;LLVMMipsAsmParser;LLVMMipsDesc;LLVMMipsInfo;LLVMMipsDisassembler;LLVMMipsInfo;LLVMMSP430CodeGen;LLVMMSP430AsmPrinter;LLVMMSP430Desc;LLVMMSP430Info;LLVMMSP430Info;LLVMNVPTXCodeGen;LLVMNVPTXAsmPrinter;LLVMNVPTXDesc;LLVMNVPTXInfo;LLVMNVPTXInfo;LLVMPowerPCCodeGen;LLVMPowerPCAsmPrinter;LLVMPowerPCAsmParser;LLVMPowerPCDesc;LLVMPowerPCInfo;LLVMPowerPCDisassembler;LLVMPowerPCInfo;LLVMSparcCodeGen;LLVMSparcAsmPrinter;LLVMSparcAsmParser;LLVMSparcDesc;LLVMSparcInfo;LLVMSparcDisassembler;LLVMSparcInfo;LLVMSystemZCodeGen;LLVMSystemZAsmPrinter;LLVMSystemZAsmParser;LLVMSystemZDesc;LLVMSystemZInfo;LLVMSystemZDisassembler;LLVMSystemZInfo;LLVMX86CodeGen;LLVMX86AsmPrinter;LLVMX86AsmParser;LLVMX86Desc;LLVMX86Info;LLVMX86Disassembler;LLVMX86Info;LLVMX86Utils;LLVMXCoreCodeGen;LLVMXCoreAsmPrinter;LLVMXCoreDesc;LLVMXCoreInfo;LLVMXCoreDisassembler;LLVMXCoreInfo;LLVMX86CodeGen;LLVMX86AsmPrinter;LLVMX86AsmParser;LLVMX86Desc;LLVMX86Info;LLVMX86Disassembler;LLVMX86Info;LLVMX86Utils
-- clang_libs=clangFrontend;clangDriver;clangSerialization;clangParse;clangSema;clangAnalysis;clangEdit;clangAST;clangLex;clangBasic

Which seems to list all required static libraries (and only the static ones).

However, the linking process involves the following command:

/usr/bin/c++  -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-exceptions -fno-rtti -std=c++11  -Wl,-O1,--sort-common,--as-needed,-z,relro -rdynamic CMakeFiles/castxml.dir/castxml.cxx.o CMakeFiles/castxml.dir/Detect.cxx.o CMakeFiles/castxml.dir/Output.cxx.o CMakeFiles/castxml.dir/RunClang.cxx.o CMakeFiles/castxml.dir/Utils.cxx.o  -o ../bin/castxml /usr/lib/libclangFrontend.a /usr/lib/libclangDriver.a /usr/lib/libclangSerialization.a /usr/lib/libclangParse.a /usr/lib/libclangSema.a /usr/lib/libclangAnalysis.a /usr/lib/libclangEdit.a /usr/lib/libclangAST.a /usr/lib/libclangLex.a /usr/lib/libclangBasic.a /usr/lib/libLLVMOption.a /usr/lib/libLLVMBitReader.a /usr/lib/libLLVMSupport.a /usr/lib/libLLVMAArch64CodeGen.a /usr/lib/libLLVMAArch64AsmPrinter.a /usr/lib/libLLVMAArch64AsmParser.a /usr/lib/libLLVMAArch64Desc.a /usr/lib/libLLVMAArch64Info.a /usr/lib/libLLVMAArch64Disassembler.a /usr/lib/libLLVMAArch64Info.a /usr/lib/libLLVMAArch64Utils.a /usr/lib/libLLVMAMDGPUCodeGen.a /usr/lib/libLLVMAMDGPUAsmPrinter.a /usr/lib/libLLVMAMDGPUAsmParser.a /usr/lib/libLLVMAMDGPUDesc.a /usr/lib/libLLVMAMDGPUInfo.a /usr/lib/libLLVMAMDGPUDisassembler.a /usr/lib/libLLVMAMDGPUInfo.a /usr/lib/libLLVMAMDGPUUtils.a /usr/lib/libLLVMARMCodeGen.a /usr/lib/libLLVMARMAsmPrinter.a /usr/lib/libLLVMARMAsmParser.a /usr/lib/libLLVMARMDesc.a /usr/lib/libLLVMARMInfo.a /usr/lib/libLLVMARMDisassembler.a /usr/lib/libLLVMARMInfo.a /usr/lib/libLLVMBPFCodeGen.a /usr/lib/libLLVMBPFAsmPrinter.a /usr/lib/libLLVMBPFDesc.a /usr/lib/libLLVMBPFInfo.a /usr/lib/libLLVMBPFDisassembler.a /usr/lib/libLLVMBPFInfo.a /usr/lib/libLLVMHexagonCodeGen.a /usr/lib/libLLVMHexagonAsmParser.a /usr/lib/libLLVMHexagonDesc.a /usr/lib/libLLVMHexagonInfo.a /usr/lib/libLLVMHexagonDisassembler.a /usr/lib/libLLVMHexagonInfo.a /usr/lib/libLLVMLanaiCodeGen.a /usr/lib/libLLVMLanaiAsmPrinter.a /usr/lib/libLLVMLanaiAsmParser.a /usr/lib/libLLVMLanaiDesc.a /usr/lib/libLLVMLanaiInfo.a /usr/lib/libLLVMLanaiDisassembler.a /usr/lib/libLLVMLanaiInfo.a /usr/lib/libLLVMMipsCodeGen.a /usr/lib/libLLVMMipsAsmPrinter.a /usr/lib/libLLVMMipsAsmParser.a /usr/lib/libLLVMMipsDesc.a /usr/lib/libLLVMMipsInfo.a /usr/lib/libLLVMMipsDisassembler.a /usr/lib/libLLVMMipsInfo.a /usr/lib/libLLVMMSP430CodeGen.a /usr/lib/libLLVMMSP430AsmPrinter.a /usr/lib/libLLVMMSP430Desc.a /usr/lib/libLLVMMSP430Info.a /usr/lib/libLLVMMSP430Info.a /usr/lib/libLLVMNVPTXCodeGen.a /usr/lib/libLLVMNVPTXAsmPrinter.a /usr/lib/libLLVMNVPTXDesc.a /usr/lib/libLLVMNVPTXInfo.a /usr/lib/libLLVMNVPTXInfo.a /usr/lib/libLLVMPowerPCCodeGen.a /usr/lib/libLLVMPowerPCAsmPrinter.a /usr/lib/libLLVMPowerPCAsmParser.a /usr/lib/libLLVMPowerPCDesc.a /usr/lib/libLLVMPowerPCInfo.a /usr/lib/libLLVMPowerPCDisassembler.a /usr/lib/libLLVMPowerPCInfo.a /usr/lib/libLLVMSparcCodeGen.a /usr/lib/libLLVMSparcAsmPrinter.a /usr/lib/libLLVMSparcAsmParser.a /usr/lib/libLLVMSparcDesc.a /usr/lib/libLLVMSparcInfo.a /usr/lib/libLLVMSparcDisassembler.a /usr/lib/libLLVMSparcInfo.a /usr/lib/libLLVMSystemZCodeGen.a /usr/lib/libLLVMSystemZAsmPrinter.a /usr/lib/libLLVMSystemZAsmParser.a /usr/lib/libLLVMSystemZDesc.a /usr/lib/libLLVMSystemZInfo.a /usr/lib/libLLVMSystemZDisassembler.a /usr/lib/libLLVMSystemZInfo.a /usr/lib/libLLVMX86CodeGen.a /usr/lib/libLLVMX86AsmPrinter.a /usr/lib/libLLVMX86AsmParser.a /usr/lib/libLLVMX86Desc.a /usr/lib/libLLVMX86Info.a /usr/lib/libLLVMX86Disassembler.a /usr/lib/libLLVMX86Info.a /usr/lib/libLLVMX86Utils.a /usr/lib/libLLVMXCoreCodeGen.a /usr/lib/libLLVMXCoreAsmPrinter.a /usr/lib/libLLVMXCoreDesc.a /usr/lib/libLLVMXCoreInfo.a /usr/lib/libLLVMXCoreDisassembler.a /usr/lib/libLLVMXCoreInfo.a /usr/lib/libLLVMX86CodeGen.a /usr/lib/libLLVMX86AsmPrinter.a /usr/lib/libLLVMX86AsmParser.a /usr/lib/libLLVMX86Desc.a /usr/lib/libLLVMX86Info.a /usr/lib/libLLVMX86Disassembler.a /usr/lib/libLLVMX86Info.a /usr/lib/libLLVMX86Utils.a /usr/lib/libLLVM-5.0.so /usr/lib/libLLVMAArch64Desc.a /usr/lib/libLLVMAArch64AsmPrinter.a /usr/lib/libLLVMAArch64Info.a /usr/lib/libLLVMAArch64Utils.a /usr/lib/libLLVMAMDGPUDesc.a /usr/lib/libLLVMAMDGPUAsmPrinter.a /usr/lib/libLLVMAMDGPUInfo.a /usr/lib/libLLVMAMDGPUUtils.a /usr/lib/libLLVMARMDesc.a /usr/lib/libLLVMARMAsmPrinter.a /usr/lib/libLLVMARMInfo.a /usr/lib/libLLVMBPFAsmPrinter.a /usr/lib/libLLVMHexagonDesc.a /usr/lib/libLLVMHexagonInfo.a /usr/lib/libLLVMLanaiDesc.a /usr/lib/libLLVMLanaiAsmPrinter.a /usr/lib/libLLVMLanaiInfo.a /usr/lib/libLLVMMipsAsmPrinter.a /usr/lib/libLLVMMSP430AsmPrinter.a /usr/lib/libLLVMNVPTXAsmPrinter.a /usr/lib/libLLVMipo.a /usr/lib/libLLVMVectorize.a /usr/lib/libLLVMIRReader.a /usr/lib/libLLVMAsmParser.a /usr/lib/libLLVMInstrumentation.a /usr/lib/libLLVMLinker.a /usr/lib/libLLVMPowerPCAsmPrinter.a /usr/lib/libLLVMSparcAsmPrinter.a /usr/lib/libLLVMSystemZDesc.a /usr/lib/libLLVMSystemZAsmPrinter.a /usr/lib/libLLVMSystemZInfo.a /usr/lib/libLLVMGlobalISel.a /usr/lib/libLLVMX86AsmPrinter.a /usr/lib/libLLVMX86Utils.a /usr/lib/libLLVMXCoreAsmPrinter.a /usr/lib/libLLVMAsmPrinter.a /usr/lib/libLLVMDebugInfoCodeView.a /usr/lib/libLLVMDebugInfoMSF.a /usr/lib/libLLVMSelectionDAG.a /usr/lib/libLLVMCodeGen.a /usr/lib/libLLVMScalarOpts.a /usr/lib/libLLVMInstCombine.a /usr/lib/libLLVMBitWriter.a /usr/lib/libLLVMTarget.a /usr/lib/libLLVMTransformUtils.a /usr/lib/libLLVMAnalysis.a /usr/lib/libLLVMObject.a /usr/lib/libLLVMBitReader.a /usr/lib/libLLVMMCParser.a /usr/lib/libLLVMProfileData.a /usr/lib/libLLVMCore.a /usr/lib/libLLVMBinaryFormat.a /usr/lib/libLLVMMCDisassembler.a /usr/lib/libLLVMMC.a /usr/lib/libLLVMSupport.a -lrt -ldl -ltinfo -lpthread -lz -lm /usr/lib/libLLVMDemangle.a 

Which, for an unknown reason, also add /usr/lib/libLLVM-5.0.so into the mix. This could explain an option registered twice: once by a static lib and once by the dynamic one.

However I have no clue as how to get rid of this library from the linker command. I tried to remove the lines relevant to this library from /usr/lib/cmake/llvm/LLVMExports-release.cmake (lines 1644 to 1652) but to no avail as the compilation fails before the link phase.

Any idea as what to try next?

@Kniyl

This comment has been minimized.

Copy link
Author

Kniyl commented Jan 18, 2018

Just went the other way around and removed linking against the static llvm libs by removing a line in a CMakeList.txt. CastXML compiled and linked fine; and seems to be working (I produced an XML file from some testing code).

Still not sure as to why (and when) the libLLVM-5.0.so got added to the linker command.

@foutrelis

This comment has been minimized.

Copy link

foutrelis commented Mar 12, 2018

libLLVM-5.0.so was pulled in by the static clang libraries (it's the LLVM target in ClangTargets.cmake).

According to a post on the llvm-dev mailing list, the llvm_config macro is the preferred way to link to LLVM libraries. Note, however, that it won't work correctly before D44391 is committed to LLVM (and released in version 7 and possibly 6.0.1).

@Kniyl: When the LLVM/Clang 6 packages are released in Arch, you will need to replace ${llvm_libs} with LLVM (instead of removing it completely). This is needed because the Clang libraries are now dynamic as well, and their CMake targets no longer pull in libLLVM-*.so.

@praetorian20

This comment has been minimized.

Copy link

praetorian20 commented Jun 10, 2018

I ran into the same error above when building tip with LLVM/clang 6.0.1 (release candidate 2). As @foutrelis (thank you so much for leaving that comment!) commented above, the fix is to modify src/CMakeLists.txt. I'm not submitting a PR because I don't understand cmake enough to make this conditional on clang version, but here's the patch I used

 src/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b1acad3..1064c41 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -67,7 +67,7 @@ add_executable(castxml
   )
 target_link_libraries(castxml
   ${clang_libs}
-  ${llvm_libs}
+  LLVM
   )
 set_property(SOURCE Utils.cxx APPEND PROPERTY COMPILE_DEFINITIONS
   "CASTXML_INSTALL_DATA_DIR=\"${CastXML_INSTALL_DATA_DIR}\"")

grwlf added a commit to grwlf/tvm that referenced this issue Jul 20, 2018

[BUILD] Fix LLVM>=5.0 libraries cmake symbol
This patch fixes "registered more than once" issue when importing tvm.so
built with LLVM>=5.0

Original issue discussion:
https://discuss.tvm.ai/t/llvm-error-option-registered-more-than-once-while-loading-libtvm-so/269/3

Reference:
CastXML/CastXML#102 (comment)

@bradking bradking referenced this issue Nov 26, 2018

Closed

All tests fail #130

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment