Wrong linking between binaries #22163
Labels
P4
This is either out of scope or we don't have bandwidth to review a PR. (No assignee)
team-Rules-CPP
Issues for C++ rules
type: support / not a bug (process)
Description of the bug:
Hi, after recent update to bazel 7.1 I got follwing issue..
I have two shared libs (using cc_binary) and one executable. If I run main, I'd expect to show same values in printvs independednfrom where I call it. But I get, a 0 when calling from main. I don't understand why, because the vs() symbols should be located in lib1.so, wich sould be shared to every consumer. Has this changed in bazel and how to do correctly again?
Which category does this issue belong to?
C++ Rules
What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
lib1.h
#pragma once
#include
struct Services
{
static std::vector &vs();
static void printvs();
};
lib1.cc
#include "lib1.h"
#include
std::vector& Services::vs()
{
static std::vector v;
return v;
}
void Services::printvs()
{
std::cout << Services::vs().size() << std::endl;
}
lib2.cc
#include "lib1.h"
static bool init()
{
Services::vs().push_back(1);
Services::vs().push_back(2);
Services::printvs();
return true;
}
[[maybe_unused]] bool i = init();
main.cc #include "lib1.h"
int main()
{
Services::printvs();
}
BUILD.bazel
cc_library(
name = "lib1_lib",
srcs = ["lib1.cc"],
hdrs = ["lib1.h"],
visibility = ["//visibility:public"],
)
cc_binary(
name = "lib1",
srcs = ["lib1_lib"],
visibility = ["//visibility:public"],
linkshared = 1,
)
cc_library(
name = "lib2_lib",
srcs = ["lib2.cc"],
deps = ["lib1_lib"],
visibility = ["//visibility:public"],
)
cc_binary(
name = "lib2",
srcs = ["lib2_lib"],
visibility = ["//visibility:public"],
linkshared = 1,
)
cc_binary(
name = "main",
srcs = ["main.cc", ":lib2", ":lib1"],
deps = [":lib1_lib"],
)
Which operating system are you running Bazel on?
linux
What is the output of
bazel info release
?Invocation ID: 434bb820-3b50-468f-97f7-237571c04586 release 7.1.0
If
bazel info release
returnsdevelopment version
or(@non-git)
, tell us how you built Bazel.No response
What's the output of
git remote get-url origin; git rev-parse HEAD
?No response
Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.
No response
Have you found anything relevant by searching the web?
No response
Any other information, logs, or outputs that you want to share?
No response
The text was updated successfully, but these errors were encountered: