Issue 1486: cgo: fix C++ dynamic initialization of static variables when using alwayslink = True#4438
Conversation
fmeum
left a comment
There was a problem hiding this comment.
Thanks for working on this, let me know if you need help with the tests.
|
Hi, @fmeum! Yes, I would need help with tests. I tried to fix them, but didn't succeed. Plus, I don't have debian and windows machines to debug tests locally I've got 2 tests failing:
Obviously, something is wrong with the configuration. Maybe
Strangely, my So, the problem is not in rules_go, actually. But something is wrong with the C++ part only The test produced 0 instead of 42. My theory was that it happened because the upd Let's see if my next commit fixes this error |
|
Finally, I got everything fixed, as you can see |
|
Thanks and sorry for the late reply! Avoiding the manual deduplication would require a very different approach to the entire cgo code. Since your change fixes the bug with minimal additional complexity, I think that it's fine as is. |
701f560 to
55a9c90
Compare
…uplicate symbol errors introduced by rules_go v0.58.1 (#2311) Summary: Consolidate `all_scripts_test.go` to use a single CGO target to fix duplicate symbol errors introduced by rules_go v0.58.1 bazel-contrib/rules_go#4438, included in `rules_go` v0.58.1, causes certain statically linked CGO binaries to fail with duplicate symbol errors. This occurs when a binary depends on more than one CGO library that transitively depends on a common set of object files. `all_scripts_test.go` previously depended on two CGO targets: - `//src/carnot/planner` - `//src/e2e_test/vizier/planner/dump_schemas/godumpschemas` This PR solves this issue by removing the src/e2e_test/vizier/planner/dump_schemas/godumpschemas CGO library and instead generate the protobuf export directly in C++, loading it in the main application. This approach mirrors the existing pattern used in [src/vizier/funcs](https://github.com/pixie-io/pixie/blob/a6349a90b1e4b30f0bb13872ad03dff83a53f363/src/vizier/funcs/BUILD.bazel#L50-L66). **Why not fix `rules_go`?** The `rules_go` change that causes the issue explains that it doesn't include the necessary deduplication logic to avoid these duplicate symbol errors (bazel-contrib/rules_go#4438 (comment)). This tradeoff was [deemed acceptable](bazel-contrib/rules_go#4438 (comment)) since it solved the c++ initialization problem with minimal complexity. Relevant Issues: N/A Type of change: /kind cleanup Test Plan: Build should pass Signed-off-by: Dom Del Nano <ddelnano@gmail.com>
…uplicate symbol errors introduced by rules_go v0.58.1 (#2311) Summary: Consolidate `all_scripts_test.go` to use a single CGO target to fix duplicate symbol errors introduced by rules_go v0.58.1 bazel-contrib/rules_go#4438, included in `rules_go` v0.58.1, causes certain statically linked CGO binaries to fail with duplicate symbol errors. This occurs when a binary depends on more than one CGO library that transitively depends on a common set of object files. `all_scripts_test.go` previously depended on two CGO targets: - `//src/carnot/planner` - `//src/e2e_test/vizier/planner/dump_schemas/godumpschemas` This PR solves this issue by removing the src/e2e_test/vizier/planner/dump_schemas/godumpschemas CGO library and instead generate the protobuf export directly in C++, loading it in the main application. This approach mirrors the existing pattern used in [src/vizier/funcs](https://github.com/pixie-io/pixie/blob/a6349a90b1e4b30f0bb13872ad03dff83a53f363/src/vizier/funcs/BUILD.bazel#L50-L66). **Why not fix `rules_go`?** The `rules_go` change that causes the issue explains that it doesn't include the necessary deduplication logic to avoid these duplicate symbol errors (bazel-contrib/rules_go#4438 (comment)). This tradeoff was [deemed acceptable](bazel-contrib/rules_go#4438 (comment)) since it solved the c++ initialization problem with minimal complexity. Relevant Issues: N/A Type of change: /kind cleanup Test Plan: Build should pass Signed-off-by: Dom Del Nano <ddelnano@gmail.com> GitOrigin-RevId: bc01887bc88ba9860de93fc03764176837825982
…uplicate symbol errors introduced by rules_go v0.58.1 (#2311) Summary: Consolidate `all_scripts_test.go` to use a single CGO target to fix duplicate symbol errors introduced by rules_go v0.58.1 bazel-contrib/rules_go#4438, included in `rules_go` v0.58.1, causes certain statically linked CGO binaries to fail with duplicate symbol errors. This occurs when a binary depends on more than one CGO library that transitively depends on a common set of object files. `all_scripts_test.go` previously depended on two CGO targets: - `//src/carnot/planner` - `//src/e2e_test/vizier/planner/dump_schemas/godumpschemas` This PR solves this issue by removing the src/e2e_test/vizier/planner/dump_schemas/godumpschemas CGO library and instead generate the protobuf export directly in C++, loading it in the main application. This approach mirrors the existing pattern used in [src/vizier/funcs](https://github.com/pixie-io/pixie/blob/a6349a90b1e4b30f0bb13872ad03dff83a53f363/src/vizier/funcs/BUILD.bazel#L50-L66). **Why not fix `rules_go`?** The `rules_go` change that causes the issue explains that it doesn't include the necessary deduplication logic to avoid these duplicate symbol errors (bazel-contrib/rules_go#4438 (comment)). This tradeoff was [deemed acceptable](bazel-contrib/rules_go#4438 (comment)) since it solved the c++ initialization problem with minimal complexity. Relevant Issues: N/A Type of change: /kind cleanup Test Plan: Build should pass Signed-off-by: Dom Del Nano <ddelnano@gmail.com> GitOrigin-RevId: bc01887bc88ba9860de93fc03764176837825982
…uplicate symbol errors introduced by rules_go v0.58.1 (#2311) Summary: Consolidate `all_scripts_test.go` to use a single CGO target to fix duplicate symbol errors introduced by rules_go v0.58.1 bazel-contrib/rules_go#4438, included in `rules_go` v0.58.1, causes certain statically linked CGO binaries to fail with duplicate symbol errors. This occurs when a binary depends on more than one CGO library that transitively depends on a common set of object files. `all_scripts_test.go` previously depended on two CGO targets: - `//src/carnot/planner` - `//src/e2e_test/vizier/planner/dump_schemas/godumpschemas` This PR solves this issue by removing the src/e2e_test/vizier/planner/dump_schemas/godumpschemas CGO library and instead generate the protobuf export directly in C++, loading it in the main application. This approach mirrors the existing pattern used in [src/vizier/funcs](https://github.com/pixie-io/pixie/blob/a6349a90b1e4b30f0bb13872ad03dff83a53f363/src/vizier/funcs/BUILD.bazel#L50-L66). **Why not fix `rules_go`?** The `rules_go` change that causes the issue explains that it doesn't include the necessary deduplication logic to avoid these duplicate symbol errors (bazel-contrib/rules_go#4438 (comment)). This tradeoff was [deemed acceptable](bazel-contrib/rules_go#4438 (comment)) since it solved the c++ initialization problem with minimal complexity. Relevant Issues: N/A Type of change: /kind cleanup Test Plan: Build should pass Signed-off-by: Dom Del Nano <ddelnano@gmail.com> GitOrigin-RevId: bc01887bc88ba9860de93fc03764176837825982
…uplicate symbol errors introduced by rules_go v0.58.1 (#2311) Summary: Consolidate `all_scripts_test.go` to use a single CGO target to fix duplicate symbol errors introduced by rules_go v0.58.1 bazel-contrib/rules_go#4438, included in `rules_go` v0.58.1, causes certain statically linked CGO binaries to fail with duplicate symbol errors. This occurs when a binary depends on more than one CGO library that transitively depends on a common set of object files. `all_scripts_test.go` previously depended on two CGO targets: - `//src/carnot/planner` - `//src/e2e_test/vizier/planner/dump_schemas/godumpschemas` This PR solves this issue by removing the src/e2e_test/vizier/planner/dump_schemas/godumpschemas CGO library and instead generate the protobuf export directly in C++, loading it in the main application. This approach mirrors the existing pattern used in [src/vizier/funcs](https://github.com/pixie-io/pixie/blob/a6349a90b1e4b30f0bb13872ad03dff83a53f363/src/vizier/funcs/BUILD.bazel#L50-L66). **Why not fix `rules_go`?** The `rules_go` change that causes the issue explains that it doesn't include the necessary deduplication logic to avoid these duplicate symbol errors (bazel-contrib/rules_go#4438 (comment)). This tradeoff was [deemed acceptable](bazel-contrib/rules_go#4438 (comment)) since it solved the c++ initialization problem with minimal complexity. Relevant Issues: N/A Type of change: /kind cleanup Test Plan: Build should pass Signed-off-by: Dom Del Nano <ddelnano@gmail.com> GitOrigin-RevId: bc01887bc88ba9860de93fc03764176837825982
…uplicate symbol errors introduced by rules_go v0.58.1 (#2311) Summary: Consolidate `all_scripts_test.go` to use a single CGO target to fix duplicate symbol errors introduced by rules_go v0.58.1 bazel-contrib/rules_go#4438, included in `rules_go` v0.58.1, causes certain statically linked CGO binaries to fail with duplicate symbol errors. This occurs when a binary depends on more than one CGO library that transitively depends on a common set of object files. `all_scripts_test.go` previously depended on two CGO targets: - `//src/carnot/planner` - `//src/e2e_test/vizier/planner/dump_schemas/godumpschemas` This PR solves this issue by removing the src/e2e_test/vizier/planner/dump_schemas/godumpschemas CGO library and instead generate the protobuf export directly in C++, loading it in the main application. This approach mirrors the existing pattern used in [src/vizier/funcs](https://github.com/pixie-io/pixie/blob/a6349a90b1e4b30f0bb13872ad03dff83a53f363/src/vizier/funcs/BUILD.bazel#L50-L66). **Why not fix `rules_go`?** The `rules_go` change that causes the issue explains that it doesn't include the necessary deduplication logic to avoid these duplicate symbol errors (bazel-contrib/rules_go#4438 (comment)). This tradeoff was [deemed acceptable](bazel-contrib/rules_go#4438 (comment)) since it solved the c++ initialization problem with minimal complexity. Relevant Issues: N/A Type of change: /kind cleanup Test Plan: Build should pass Signed-off-by: Dom Del Nano <ddelnano@gmail.com> GitOrigin-RevId: bc01887bc88ba9860de93fc03764176837825982
…uplicate symbol errors introduced by rules_go v0.58.1 (pixie-io#2311) Summary: Consolidate `all_scripts_test.go` to use a single CGO target to fix duplicate symbol errors introduced by rules_go v0.58.1 bazel-contrib/rules_go#4438, included in `rules_go` v0.58.1, causes certain statically linked CGO binaries to fail with duplicate symbol errors. This occurs when a binary depends on more than one CGO library that transitively depends on a common set of object files. `all_scripts_test.go` previously depended on two CGO targets: - `//src/carnot/planner` - `//src/e2e_test/vizier/planner/dump_schemas/godumpschemas` This PR solves this issue by removing the src/e2e_test/vizier/planner/dump_schemas/godumpschemas CGO library and instead generate the protobuf export directly in C++, loading it in the main application. This approach mirrors the existing pattern used in [src/vizier/funcs](https://github.com/pixie-io/pixie/blob/a6349a90b1e4b30f0bb13872ad03dff83a53f363/src/vizier/funcs/BUILD.bazel#L50-L66). **Why not fix `rules_go`?** The `rules_go` change that causes the issue explains that it doesn't include the necessary deduplication logic to avoid these duplicate symbol errors (bazel-contrib/rules_go#4438 (comment)). This tradeoff was [deemed acceptable](bazel-contrib/rules_go#4438 (comment)) since it solved the c++ initialization problem with minimal complexity. Relevant Issues: N/A Type of change: /kind cleanup Test Plan: Build should pass Signed-off-by: Dom Del Nano <ddelnano@gmail.com>
…uplicate symbol errors introduced by rules_go v0.58.1 (pixie-io#2311) Summary: Consolidate `all_scripts_test.go` to use a single CGO target to fix duplicate symbol errors introduced by rules_go v0.58.1 bazel-contrib/rules_go#4438, included in `rules_go` v0.58.1, causes certain statically linked CGO binaries to fail with duplicate symbol errors. This occurs when a binary depends on more than one CGO library that transitively depends on a common set of object files. `all_scripts_test.go` previously depended on two CGO targets: - `//src/carnot/planner` - `//src/e2e_test/vizier/planner/dump_schemas/godumpschemas` This PR solves this issue by removing the src/e2e_test/vizier/planner/dump_schemas/godumpschemas CGO library and instead generate the protobuf export directly in C++, loading it in the main application. This approach mirrors the existing pattern used in [src/vizier/funcs](https://github.com/pixie-io/pixie/blob/a6349a90b1e4b30f0bb13872ad03dff83a53f363/src/vizier/funcs/BUILD.bazel#L50-L66). **Why not fix `rules_go`?** The `rules_go` change that causes the issue explains that it doesn't include the necessary deduplication logic to avoid these duplicate symbol errors (bazel-contrib/rules_go#4438 (comment)). This tradeoff was [deemed acceptable](bazel-contrib/rules_go#4438 (comment)) since it solved the c++ initialization problem with minimal complexity. Relevant Issues: N/A Type of change: /kind cleanup Test Plan: Build should pass Signed-off-by: Dom Del Nano <ddelnano@gmail.com>
What type of PR is this?
Bug fix
What does this PR do? Why is it needed?
Fixes static linking against libraries that have
alwayslink = Truespecified. Fixes C++'s dynamic initialization of static variables when using cgoWhich issues(s) does this PR fix?
Fixes #1486
Related to #2584 and #2294