Bazel build and dynamic linking

160 views
Skip to first unread message

Elliott Brossard

unread,
Feb 5, 2024, 5:42:43 PM2/5/24
to v8-dev
https://github.com/v8/v8/blob/main/bazel/defs.bzl sets `linkstatic` to `True` for all of the library targets, and there is no option to create shared objects for the libraries instead (as far as I can tell). If I naively patch `defs.bzl` to have `linkstatic = False`, I get the following link errors:

```
ld.lld: error: undefined reference due to --no-allow-shlib-undefined: v8_Default_embedded_blob_code_
>>> referenced by bazel-out/k8-fastbuild/bin/_solib_k8/libexternal_Sv8_Slibv8_Ulibshared_Uicu.so

ld.lld: error: undefined reference due to --no-allow-shlib-undefined: v8_Default_embedded_blob_code_size_
>>> referenced by bazel-out/k8-fastbuild/bin/_solib_k8/libexternal_Sv8_Slibv8_Ulibshared_Uicu.so

ld.lld: error: undefined reference due to --no-allow-shlib-undefined: v8_Default_embedded_blob_data_
>>> referenced by bazel-out/k8-fastbuild/bin/_solib_k8/libexternal_Sv8_Slibv8_Ulibshared_Uicu.so

ld.lld: error: undefined reference due to --no-allow-shlib-undefined: v8_Default_embedded_blob_data_size_
>>> referenced by bazel-out/k8-fastbuild/bin/_solib_k8/libexternal_Sv8_Slibv8_Ulibshared_Uicu.so
collect2: error: ld returned 1 exit status
```

I think (please correct me if I'm wrong) that the gn-based build does support generating shared objects for the various V8 libraries instead, and I see references e.g. to defines like `BUILDING_V8_SHARED` in https://github.com/v8/v8/blob/main/BUILD.gn. I'm not interested in cross-version stability, just the ability to link dynamically in order to have smaller test binaries involving V8, but I'm wondering:
* Is it true that the gn build supports dynamic linking? I'm having trouble deciphering this from the docs/sources.
* Is dynamic linking with the Bazel build on the roadmap? I don't see any related mentions on the issue tracker.

Thanks!
Elliott

Jakob Kummerow

unread,
Feb 6, 2024, 7:01:59 AM2/6/24
to v8-...@googlegroups.com
Yes, definitely. I use it all the time. 
The GN build supports everything. The Bazel build is known to support only a subset of configuration options.
 
* Is dynamic linking with the Bazel build on the roadmap? I don't see any related mentions on the issue tracker.

I don't know.

If you have time/interest to figure out how to support dynamic-linking (aka shared-library aka component) builds with the Bazel build, we would probably accept patches (as long as they're not too intrusive or add too much maintenance burden going forward).

Victor Gomes

unread,
Feb 6, 2024, 7:09:30 AM2/6/24
to v8-...@googlegroups.com
On Tue, Feb 6, 2024 at 1:02 PM Jakob Kummerow <jkum...@chromium.org> wrote:
On Mon, Feb 5, 2024 at 11:42 PM 'Elliott Brossard' via v8-dev <v8-...@googlegroups.com> wrote:
https://github.com/v8/v8/blob/main/bazel/defs.bzl sets `linkstatic` to `True` for all of the library targets, and there is no option to create shared objects for the libraries instead (as far as I can tell). If I naively patch `defs.bzl` to have `linkstatic = False`, I get the following link errors:

```
ld.lld: error: undefined reference due to --no-allow-shlib-undefined: v8_Default_embedded_blob_code_
>>> referenced by bazel-out/k8-fastbuild/bin/_solib_k8/libexternal_Sv8_Slibv8_Ulibshared_Uicu.so

ld.lld: error: undefined reference due to --no-allow-shlib-undefined: v8_Default_embedded_blob_code_size_
>>> referenced by bazel-out/k8-fastbuild/bin/_solib_k8/libexternal_Sv8_Slibv8_Ulibshared_Uicu.so

ld.lld: error: undefined reference due to --no-allow-shlib-undefined: v8_Default_embedded_blob_data_
>>> referenced by bazel-out/k8-fastbuild/bin/_solib_k8/libexternal_Sv8_Slibv8_Ulibshared_Uicu.so

ld.lld: error: undefined reference due to --no-allow-shlib-undefined: v8_Default_embedded_blob_data_size_
>>> referenced by bazel-out/k8-fastbuild/bin/_solib_k8/libexternal_Sv8_Slibv8_Ulibshared_Uicu.so
collect2: error: ld returned 1 exit status
```

I think (please correct me if I'm wrong) that the gn-based build does support generating shared objects for the various V8 libraries instead, and I see references e.g. to defines like `BUILDING_V8_SHARED` in https://github.com/v8/v8/blob/main/BUILD.gn. I'm not interested in cross-version stability, just the ability to link dynamically in order to have smaller test binaries involving V8, but I'm wondering:
* Is it true that the gn build supports dynamic linking? I'm having trouble deciphering this from the docs/sources.

Yes, definitely. I use it all the time. 
The GN build supports everything. The Bazel build is known to support only a subset of configuration options.
 
* Is dynamic linking with the Bazel build on the roadmap? I don't see any related mentions on the issue tracker.

I don't know.
No, we don't have dynamic linking on the roadmap. 

If you have time/interest to figure out how to support dynamic-linking (aka shared-library aka component) builds with the Bazel build, we would probably accept patches (as long as they're not too intrusive or add too much maintenance burden going forward).
+1 to that. 

--
--
v8-dev mailing list
v8-...@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-dev+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/v8-dev/CAKSzg3QPEzjX0sLmguPG%3DXNYby61%3Dp6w%2B4f4LR3Y1zcNDgUhDA%40mail.gmail.com.


--
Victor

Elliott Brossard

unread,
Feb 6, 2024, 12:12:37 PM2/6/24
to v8-...@googlegroups.com
Thanks! That's helpful. If I do figure out a way to make this work, what is the best way to add tests for Bazel build configurations? If you have a sample commit, that would be great.

You received this message because you are subscribed to a topic in the Google Groups "v8-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-dev/BccObkPEGm4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to v8-dev+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/v8-dev/CAGFuzY1w1Gu4hzvORTq6c%3D5ZvJMkpZ4h1UYHrGhK071BngYcTw%40mail.gmail.com.

Elliott Brossard

unread,
Feb 6, 2024, 1:28:11 PM2/6/24
to v8-...@googlegroups.com
I doubt this is the right approach, by the way, but I was able to link successfully by commenting out https://github.com/v8/v8/blob/ebd3e99c85fb93e7ddea207233e35f53742c2e05/src/snapshot/embedded/platform-embedded-file-writer-generic.cc#L60 so that the symbols aren't declared as hidden. I'm guessing that in the GN build, there's some other configuration difference that allows linking to succeed even with the hidden symbols.

Jakob Kummerow

unread,
Feb 7, 2024, 8:13:25 AM2/7/24
to v8-...@googlegroups.com, Michael Achenbach
Regarding testing, I think we generally test build systems/configurations by having builders that use them. We do have a Bazel builder; I'm not sure how many more Bazel builders for other configurations we'd want at this stage... maybe one more for the component build would be okay; if it only compiles (doesn't run tests) and runs infrequently / with low priority and without being a tree closer (unless/until we decide that we want it to be one), maybe it doesn't need too many resources. +Michael Achenbach WDYT?

Obviously we'd first need to get the Bazel+component build working before it makes sense to set up a bot for it.
Reply all
Reply to author
Forward
0 new messages