Skip to content
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

clang_delta fails to link against shared LLVM-6.0.1 #165

Closed
mgorny opened this issue Jul 16, 2018 · 7 comments
Closed

clang_delta fails to link against shared LLVM-6.0.1 #165

mgorny opened this issue Jul 16, 2018 · 7 comments
Assignees
Labels

Comments

@mgorny
Copy link
Contributor

mgorny commented Jul 16, 2018

FAILED: clang_delta/clang_delta 
: && /usr/lib/ccache/bin/x86_64-pc-linux-gnu-g++-7.3.0  -march=k8-sse3 -mcx16 -msahf --param l1-cache-size=64 --param l1-cache-line-size=64 --param l2-cache-size=512 -O2 -pipe -frecord-gcc-switches -std=c++11 -fno-rtti -fno-strict-aliasing -Wall -Wextra -Wno-long-long -Wno-unused-parameter -Wno-missing-field-initializers -fvisibility-inlines-hidden  -Wl,-O1 -Wl,--as-needed -Wl,--hash-style=gnu   -rdynamic clang_delta/CMakeFiles/clang_delta.dir/AggregateToScalar.cpp.o clang_delta/CMakeFiles/clang_delta.dir/BinOpSimplification.cpp.o clang_delta/CMakeFiles/clang_delta.dir/CallExprToValue.cpp.o clang_delta/CMakeFiles/clang_delta.dir/ClangDelta.cpp.o clang_delta/CMakeFiles/clang_delta.dir/ClassTemplateToClass.cpp.o clang_delta/CMakeFiles/clang_delta.dir/CombineGlobalVarDecl.cpp.o clang_delta/CMakeFiles/clang_delta.dir/CombineLocalVarDecl.cpp.o clang_delta/CMakeFiles/clang_delta.dir/CopyPropagation.cpp.o clang_delta/CMakeFiles/clang_delta.dir/EmptyStructToInt.cpp.o clang_delta/CMakeFiles/clang_delta.dir/ExpressionDetector.cpp.o clang_delta/CMakeFiles/clang_delta.dir/InstantiateTemplateParam.cpp.o clang_delta/CMakeFiles/clang_delta.dir/InstantiateTemplateTypeParamToInt.cpp.o clang_delta/CMakeFiles/clang_delta.dir/LiftAssignmentExpr.cpp.o clang_delta/CMakeFiles/clang_delta.dir/LocalToGlobal.cpp.o clang_delta/CMakeFiles/clang_delta.dir/MoveFunctionBody.cpp.o clang_delta/CMakeFiles/clang_delta.dir/MoveGlobalVar.cpp.o clang_delta/CMakeFiles/clang_delta.dir/ParamToGlobal.cpp.o clang_delta/CMakeFiles/clang_delta.dir/ParamToLocal.cpp.o clang_delta/CMakeFiles/clang_delta.dir/ReduceArrayDim.cpp.o clang_delta/CMakeFiles/clang_delta.dir/ReduceArraySize.cpp.o clang_delta/CMakeFiles/clang_delta.dir/ReduceClassTemplateParameter.cpp.o clang_delta/CMakeFiles/clang_delta.dir/ReducePointerLevel.cpp.o clang_delta/CMakeFiles/clang_delta.dir/ReducePointerPairs.cpp.o clang_delta/CMakeFiles/clang_delta.dir/RemoveAddrTaken.cpp.o clang_delta/CMakeFiles/clang_delta.dir/RemoveArray.cpp.o clang_delta/CMakeFiles/clang_delta.dir/RemoveBaseClass.cpp.o clang_delta/CMakeFiles/clang_delta.dir/RemoveCtorInitializer.cpp.o clang_delta/CMakeFiles/clang_delta.dir/RemoveEnumMemberValue.cpp.o clang_delta/CMakeFiles/clang_delta.dir/RemoveNamespace.cpp.o clang_delta/CMakeFiles/clang_delta.dir/RemoveNestedFunction.cpp.o clang_delta/CMakeFiles/clang_delta.dir/RemovePointer.cpp.o clang_delta/CMakeFiles/clang_delta.dir/RemoveTrivialBaseTemplate.cpp.o clang_delta/CMakeFiles/clang_delta.dir/RemoveUnresolvedBase.cpp.o clang_delta/CMakeFiles/clang_delta.dir/RemoveUnusedEnumMember.cpp.o clang_delta/CMakeFiles/clang_delta.dir/RemoveUnusedFunction.cpp.o clang_delta/CMakeFiles/clang_delta.dir/RemoveUnusedOuterClass.cpp.o clang_delta/CMakeFiles/clang_delta.dir/RemoveUnusedStructField.cpp.o clang_delta/CMakeFiles/clang_delta.dir/RemoveUnusedVar.cpp.o clang_delta/CMakeFiles/clang_delta.dir/RenameCXXMethod.cpp.o clang_delta/CMakeFiles/clang_delta.dir/RenameClass.cpp.o clang_delta/CMakeFiles/clang_delta.dir/RenameFun.cpp.o clang_delta/CMakeFiles/clang_delta.dir/RenameParam.cpp.o clang_delta/CMakeFiles/clang_delta.dir/RenameVar.cpp.o clang_delta/CMakeFiles/clang_delta.dir/ReplaceArrayAccessWithIndex.cpp.o clang_delta/CMakeFiles/clang_delta.dir/ReplaceArrayIndexVar.cpp.o clang_delta/CMakeFiles/clang_delta.dir/ReplaceCallExpr.cpp.o clang_delta/CMakeFiles/clang_delta.dir/ReplaceClassWithBaseTemplateSpec.cpp.o clang_delta/CMakeFiles/clang_delta.dir/ReplaceDependentName.cpp.o clang_delta/CMakeFiles/clang_delta.dir/ReplaceDependentTypedef.cpp.o clang_delta/CMakeFiles/clang_delta.dir/ReplaceDerivedClass.cpp.o clang_delta/CMakeFiles/clang_delta.dir/ReplaceFunctionDefWithDecl.cpp.o clang_delta/CMakeFiles/clang_delta.dir/ReplaceOneLevelTypedefType.cpp.o clang_delta/CMakeFiles/clang_delta.dir/ReplaceSimpleTypedef.cpp.o clang_delta/CMakeFiles/clang_delta.dir/ReplaceUndefinedFunction.cpp.o clang_delta/CMakeFiles/clang_delta.dir/ReturnVoid.cpp.o clang_delta/CMakeFiles/clang_delta.dir/RewriteUtils.cpp.o clang_delta/CMakeFiles/clang_delta.dir/SimpleInliner.cpp.o clang_delta/CMakeFiles/clang_delta.dir/SimplifyCallExpr.cpp.o clang_delta/CMakeFiles/clang_delta.dir/SimplifyCommaExpr.cpp.o clang_delta/CMakeFiles/clang_delta.dir/SimplifyDependentTypedef.cpp.o clang_delta/CMakeFiles/clang_delta.dir/SimplifyIf.cpp.o clang_delta/CMakeFiles/clang_delta.dir/SimplifyNestedClass.cpp.o clang_delta/CMakeFiles/clang_delta.dir/SimplifyRecursiveTemplateInstantiation.cpp.o clang_delta/CMakeFiles/clang_delta.dir/SimplifyStruct.cpp.o clang_delta/CMakeFiles/clang_delta.dir/SimplifyStructUnionDecl.cpp.o clang_delta/CMakeFiles/clang_delta.dir/TemplateArgToInt.cpp.o clang_delta/CMakeFiles/clang_delta.dir/TemplateNonTypeArgToInt.cpp.o clang_delta/CMakeFiles/clang_delta.dir/Transformation.cpp.o clang_delta/CMakeFiles/clang_delta.dir/TransformationManager.cpp.o clang_delta/CMakeFiles/clang_delta.dir/UnifyFunctionDecl.cpp.o clang_delta/CMakeFiles/clang_delta.dir/UnionToStruct.cpp.o clang_delta/CMakeFiles/clang_delta.dir/VectorToArray.cpp.o clang_delta/CMakeFiles/clang_delta.dir/git_version.cpp.o  -o clang_delta/clang_delta -L/usr/lib/llvm/6/lib64 -Wl,-rpath,/usr/lib/llvm/6/lib64: /usr/lib/llvm/6/lib64/libclangStaticAnalyzerFrontend.so.6.0.1 /usr/lib/llvm/6/lib64/libclangStaticAnalyzerCheckers.so.6.0.1 /usr/lib/llvm/6/lib64/libclangStaticAnalyzerCore.so.6.0.1 /usr/lib/llvm/6/lib64/libclangFrontendTool.so.6.0.1 /usr/lib/llvm/6/lib64/libclangFrontend.so.6.0.1 /usr/lib/llvm/6/lib64/libclangDriver.so.6.0.1 /usr/lib/llvm/6/lib64/libclangSerialization.so.6.0.1 /usr/lib/llvm/6/lib64/libclangCodeGen.so.6.0.1 /usr/lib/llvm/6/lib64/libclangParse.so.6.0.1 /usr/lib/llvm/6/lib64/libclangSema.so.6.0.1 /usr/lib/llvm/6/lib64/libclangAnalysis.so.6.0.1 /usr/lib/llvm/6/lib64/libclangRewriteFrontend.so.6.0.1 /usr/lib/llvm/6/lib64/libclangRewrite.so.6.0.1 /usr/lib/llvm/6/lib64/libclangAST.so.6.0.1 /usr/lib/llvm/6/lib64/libclangBasic.so.6.0.1 /usr/lib/llvm/6/lib64/libclangEdit.so.6.0.1 /usr/lib/llvm/6/lib64/libclangLex.so.6.0.1 /usr/lib/llvm/6/lib64/libclangARCMigrate.so.6.0.1 && :
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: clang_delta/CMakeFiles/clang_delta.dir/ExpressionDetector.cpp.o: undefined reference to symbol '_ZN4llvm5APInt12initSlowCaseEmb'
/usr/lib/llvm/6/lib64/libLLVMSupport.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

My first though was that linkage to LLVM libraries is missing. Apparently, it is by design:

# ENE, LLVM 6.0: LLVM_LIBS end up in the link command line anyway.  I'm not
# quite sure why!  But if you list LLVM_LIBS here, the `clang_delta' binary
# can end up with dynamic link errors when it runs (multiply defined symbols).
#
target_link_libraries(clang_delta ${CLANG_LIBS})

However, LLVM libraries don't get pulled implicitly for me, so it looks like the workaround for 'weird' systems is breaking normal systems.

Full log: dev-util:creduce-9999:20180716-080437.log

That's LLVM 6.0.1 on Gentoo. Let me know if you need extra data.

@eeide eeide self-assigned this Jul 16, 2018
@eeide eeide added the bug label Jul 16, 2018
@eeide
Copy link
Member

eeide commented Jul 16, 2018

Hmm. I expect that sorting this out will take some thought.

As you can see from the comment that you quoted, I'm not good at navigating LLVM's current linking practices! If you have a CMake recipe that works with all the ways that LLVM/Clang might be packaged into libs, please let me know.

I will say that the current CMake file "worked for me" on all the systems I tested, with both pre-packaged and self-compiled LLVM trees. That included Ubuntu 14/16/18, CentOS 7, FreeBSD 10/11, and macOS 10.12. I did not try Gentoo.

If your immediate goal is just to build C-Reduce, you might try the Autoconf-based build system.

Also, FWIW, I generally test only with CC and CXX set to use compilers from the LLVM tree that I'm linking against. That's probably not relevant in this case, but I thought I'd mention it.

@eeide
Copy link
Member

eeide commented Jul 16, 2018

Also, one might experiment with the following patch, suggested by @ismail in the comments for issue #147. If you apply this patch, I presume that you would also need to re-add LLVM_LIBS to the target_link_libraries.

diff --git a/clang_delta/CMakeLists.txt b/clang_delta/CMakeLists.txt
index ab1dc42..ab67dfc 100644
--- a/clang_delta/CMakeLists.txt
+++ b/clang_delta/CMakeLists.txt
@@ -57,6 +57,7 @@ include_directories(${CLANG_INCLUDE_DIRS}) # only works for LLVM post-4.0
 
 link_directories(${LLVM_LIBRARY_DIRS})
 
+if (${BUILD_SHARED_LIBS})
 llvm_map_components_to_libnames(LLVM_LIBS
   coverage
   irreader
@@ -67,6 +68,9 @@ llvm_map_components_to_libnames(LLVM_LIBS
   profiledata
   support
 )
+else()
+  set(LLVM_LIBS LLVM)
+endif()
 
 set(CLANG_LIBS
   clangStaticAnalyzerFrontend

@mgorny
Copy link
Contributor Author

mgorny commented Jul 17, 2018

This patch doesn't work. My guess would be it's because BUILD_SHARED_LIBS is unset — it's not really exported out of LLVM. That said, I think all current versions of LLVM have some clean way of linking that selects correct targets independently of the way LLVM was built.

@marxin
Copy link
Contributor

marxin commented Aug 23, 2018

I see one maybe similar issue for current creduce trunk:

$ make
[  1%] Linking CXX executable clang_delta
/usr/lib64/gcc/x86_64-suse-linux/8/../../../../x86_64-suse-linux/bin/ld: CMakeFiles/clang_delta.dir/ReplaceArrayIndexVar.cpp.o: undefined reference to symbol '_ZN4llvm19SmallPtrSetImplBaseC2EPPKvRKS0_@@LLVM_6.0'
/usr/lib64/gcc/x86_64-suse-linux/8/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/../lib64/libLLVM.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [clang_delta/CMakeFiles/clang_delta.dir/build.make:1182: clang_delta/clang_delta] Error 1
make[1]: *** [CMakeFiles/Makefile2:156: clang_delta/CMakeFiles/clang_delta.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

@marxin
Copy link
Contributor

marxin commented Oct 1, 2018

Please any progress on this?

@eeide
Copy link
Member

eeide commented Oct 1, 2018

No, we have not made progress on this.

I am hopeful that this will be resolved as part of preparing the C-Reduce release for LLVM 7.0. I vaguely recall that there was some discussion about improving the LLVM infrastructure that third-party tools can use for linking against LLVM libraries—but perhaps I am misremembering.

@eeide
Copy link
Member

eeide commented Apr 22, 2019

I'm going to close this issue, without resolution, because we're moving on to LLVM 7.0 and 8.0.

It is still an issue with LLVM 7.0; see #189.

@eeide eeide closed this as completed Apr 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants