Open gruszczy opened 7 years ago
C++ so marcel to look at it.
Hello @gruszczy,
The source of confusion is that Bazel by default links binaries statically, but tests dynamically. This makes the test-code-refactor loop faster, because changes to the test code only trigger the rebuild of the test, not the whole application. It can be disabled by setting linkstatic = 1
on codegen_test
target.
As to why the symbols are not present in codegen_test
when built as a shared library, that's much harder question and would need more project-specific information. But a possible solution might be to mark targets producing VMRuntimeDyld.a
and VMMCJit.a
as alwayslink = 1
.
I'll close this issue now, feel free to reopen if you think this is a Bazel issue. If you have further questions feel free to continue on your StackOverflow question.
Hi Marcel,
Thanks for the tip, it's good to know the difference (and rationale) about the linking. linkstatic indeed fixes the issues an allows me to avoid listing files, so it's an acceptable solution.
However, I did try to use alwayslink = 1 on the target that is producing the VMRuntimeDyld.a and VMMCJit.a, it's in the snippet I included above:
cc_library( name = "main", srcs = glob(["lib/*.a"]), hdrs = glob(["include/*/.*"]), visibility = ["//visibility:public"], copts = ["-Iexternal/llvm/include"], alwayslink=1 )
That's why I think this is a bug, because I would expect the alwayslink to propagate to the cc_test, no matter what is the difference in linking between these two.
I guess this is really a bug. The issue here is that Bazel treats .a files in srcs as dependencies, not a real sources. And alwayslink only affects the .a library made from sources (in your last snippet that would be libmain.a, but since there are no real sources there, it's not built). Alwayslink is not transitive, so dependencies are not enclosed in --whole-archive
block.
I've shared a really ugly unsupported hack on StackOverflow if you need a fix quickly. As the answer says, it can break any time without warning, but we have plans for more disciplined solution.
Hi there! We're doing a clean up of old issues and will be closing this one. Please reopen if you’d like to discuss anything further. We’ll respond as soon as we have the bandwidth/resources to do so.
@sgowroji this still happens, please reopen
Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs. If you think this issue is still relevant and should stay open, please post any comment here and the issue will no longer be marked as stale.
Description of the problem / feature request / question:
WORKSPACE:
llvm.BUILD:
Usage:
cc_binary works no matter what. For cc_test, if I remove the linkopts, it will stop working, complaining during execution of the test about:
It doesn't complain about this in the compiler binary, even though it depends on ":jit" target.
If possible, provide a minimal example to reproduce the problem:
Environment info
Operating System: Mac OS
Bazel version (output of
bazel info release
): release 0.4.5-jdk7Have you found anything relevant by searching the web?
My own question: http://stackoverflow.com/questions/43786877/llvm-dyld-symbol-not-found-zn4llvm11runtimedyld13memorymanager6anchorev
Anything else, information or logs or outputs that would be helpful?
(If they are large, please upload as attachment or provide link).