Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong linking between binaries #22163

Open
steffenroeber opened this issue Apr 27, 2024 · 0 comments
Open

Wrong linking between binaries #22163

steffenroeber opened this issue Apr 27, 2024 · 0 comments
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)

Comments

@steffenroeber
Copy link

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 returns development 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

@github-actions github-actions bot added the team-Rules-CPP Issues for C++ rules label Apr 27, 2024
@comius comius added type: support / not a bug (process) P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) and removed untriaged type: bug labels May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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)
Projects
None yet
Development

No branches or pull requests

5 participants