I've got a custom Skylark rule that generates some .o files, and I use those .o files as inputs to a cc_library rule:
special_library(
name = "lib_compile",
srcs = [
...
],
)
cc_library(
name = "lib",
srcs = [":lib_compile"],
hdrs = ["Lib.hpp"],
visibility = ["//visibility:public"],
)
lib_compile creates two object files: lib_compile.host.o and lib_compile.device.o. I want all of the symbols from both of these to end up in the cc_library. When compiling with -c fastbuild or -c dbg, two files are generated: liblib.a and liblib.so. Both of these contain the symbols from both of the object files (checked with nm).
When compiling with -c opt, though, I get three files: liblib.a, liblib.pic.a and liblib.so. Both liblib.pic.a and liblib.so contain the symbols I'd expect, but liblib.a contains no symbols at all. The command run to generate liblib.a is:
(cd /home/prenav/.cache/bazel/_bazel_prenav/498b20bdde769651f9658c988dcbe162/execroot/monorepo && \
exec env - \
/usr/bin/ar @bazel-out/local-opt/bin/lib/liblib.a-2.params)
And the contents of liblib.a-2.params:
$ cat bazel-out/local-opt/bin/lib/liblib.a-2.params
rcsD
bazel-out/local-opt/bin/lib/liblib.a
The contents of liblib.pic.a, for comparison, are what I would expect:
rcsD
bazel-out/local-opt/bin/lib/liblib.pic.a
bazel-out/local-opt/bin/lib/lib_compile.host.pic.o
bazel-out/local-opt/bin/lib/lib_compile.device.pic.o
Both of the objects are position-independent.
This wouldn't be a problem, except rules downstream of this rule seem to prefer the liblib.a archive. Both --force_pic and --dynamic_mode=fully cause other rules in our build to misbehave, so it's hard to know whether those would fix the problem.
Any idea what's going on? Thanks so much!
Haldean
The fact that my object files ended with .pic.o has some significance; changing them to be named lib_compile.host.o and lib_compile.device.o makes the symbols show up in both liblib.a and liblib.pic.a.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/eea5f84c-f580-42f7-b2c1-d76d6a2c88db%40googlegroups.com.--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.