Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ module(
compatibility_level = 1,
)

bazel_dep(name = "rules_cc", version = "0.1.5")
bazel_dep(name = "rules_cc", version = "0.2.14")

# GoogleTest/GoogleMock framework. Used by most unit-tests.
bazel_dep(
name = "googletest",
version = "1.11.0",
version = "1.17.0.bcr.2",
repo_name = "com_google_googletest",
)

# zlib, used by proto builders.
bazel_dep(
name = "zlib",
version = "1.3.1",
version = "1.3.1.bcr.5",
)

# Proto rules for Bazel and Protobuf
bazel_dep(
name = "protobuf",
version = "31.1",
version = "33.4",
repo_name = "com_google_protobuf",
)
bazel_dep(
Expand All @@ -31,10 +31,10 @@ bazel_dep(
)
bazel_dep(
name = "gflags",
version = "2.2.2",
version = "2.2.2.bcr.1",
repo_name = "com_github_gflags_gflags",
)
bazel_dep(
name = "abseil-cpp",
version = "20250512.0",
version = "20250814.1",
)
11 changes: 7 additions & 4 deletions ci/linux_clang-latest_libcxx_bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,26 @@ set -euox pipefail

if [ -z "${PDC_ROOT:-}" ]; then
PDC_ROOT="$(realpath $(dirname ${0})/..)"
PDC_ROOT_DIR_NAME=$(basename "${PDC_ROOT}")
PDC_HOST_ROOT="${KOKORO_HOST_ROOT_DIR}/src/git/${PDC_ROOT_DIR_NAME}"
fi

# This container is a reasonable start but is missing some prerequisite libs and
# an installation of linux_perf. We'll manually add them below.
readonly DOCKER_CONTAINER="gcr.io/google.com/absl-177019/linux_hybrid-latest:20231218"
readonly DOCKER_CONTAINER="gcr.io/google.com/absl-177019/linux_hybrid-latest:20260131"

time docker run \
--volume="${PDC_ROOT}:/perf_data_converter:ro" \
--mount "type=bind,src=${PDC_HOST_ROOT},target=/perf_data_converter" \
--workdir=/perf_data_converter \
--cap-add=SYS_PTRACE \
--rm \
-i \
-e CC="/opt/llvm/clang/bin/clang" \
-e CC="/opt/llvm/bin/clang" \
-e BAZEL_CXXOPTS="-nostdinc++" \
-e BAZEL_LINKOPTS="-L/opt/llvm/libcxx/lib:-lc++:-lc++abi:-lm:-Wl,-rpath=/opt/llvm/libcxx/lib" \
-e CPLUS_INCLUDE_PATH="/opt/llvm/libcxx/include/c++/v1" \
-e BAZEL_LINKOPTS="-L/opt/llvm/lib/x86_64-unknown-linux-gnu:-lc++:-lc++abi:-lm:-Wl,-rpath=/opt/llvm/lib/x86_64-unknown-linux-gnu" \
-e CPLUS_INCLUDE_PATH="/opt/llvm/include/c++/v1:/opt/llvm/include/x86_64-unknown-linux-gnu/c++/v1/" \
${DOCKER_EXTRA_ARGS:-} \
${DOCKER_CONTAINER} \
bash <<EOF
Expand All @@ -40,7 +44,6 @@ time docker run \
/usr/local/bin/bazel test ... \
--compilation_mode=fastbuild \
--copt=-fexceptions \
--copt=-Werror \
--distdir="/bazel-distdir" \
--keep_going \
--show_timestamps \
Expand Down
3 changes: 3 additions & 0 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
load("@rules_cc//cc:cc_library.bzl", "cc_library")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your patch as is fails to link in my cloudtop machine (using a public bazel build). Can you reproduce this?

ERROR: /usr/local/google/home/victorvianna/repos/perf_data_converter/src/BUILD:149:10: Linking src/perf_to_profile failed: (Exit 1): gcc failed: error executing CppLink command (from cc_binary rule target //src:perf_to_profile) /usr/bin/gcc @bazel-out/k8-fastbuild/bin/src/perf_to_profile-0.params

Gemini-cli suggested this fix and now it works.

$ git diff
diff --git a/src/BUILD b/src/BUILD
index b12658e..dff870c 100644
--- a/src/BUILD
+++ b/src/BUILD
@@ -139,6 +139,7 @@ cc_library(
     name = "perf_to_profile_lib",
     srcs = ["perf_to_profile_lib.cc"],
     hdrs = ["perf_to_profile_lib.h"],
+    alwayslink = 1,
     deps = [
         ":perf_data_converter",
         "//src/quipper:base",
@@ -149,6 +150,8 @@ cc_library(
 cc_binary(
     name = "perf_to_profile",
     srcs = ["perf_to_profile.cc"],
+    copts = ["-fPIC"],
+    linkopts = ["-Wl,--gc-sections"],
     deps = [
         ":perf_data_converter",
         ":perf_to_profile_lib",

Copy link
Contributor Author

@s-kanev s-kanev Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reproduced some linker issues, but definitely not something that should be solved with alwayslink, which tends to be a pretty big bandaid.

Basically, Ubuntu (and internal gLiunux as a result) have picked up a broken version of GCC -- the details are here llvm/llvm-project#156667 (comment)

The bazel team recommends this in your bazelrc as a workaround until the toolchain gets into a proper state:

common --copt=-Wa,--gsframe=no
common --host_copt=-Wa,--gsframe=no

That worked on my gLinux machine.

Feel free to comment on b/483020832 internally with the full exact errors you're seeing, if this doesn't work.

(bugs like this are exactly why we shouldn't be using the system toolchain, but unfortunately bazel backtracked on the initial hermetic builds design)

load("@rules_cc//cc:cc_test.bzl", "cc_test")

load("@com_google_protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")

package(
default_visibility = [
"//src:__subpackages__",
Expand Down
7 changes: 7 additions & 0 deletions src/quipper/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@

load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@rules_cc//cc:cc_test.bzl", "cc_test")

load("@com_google_protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")

licenses(["notice"])

perf_test_data = glob([
Expand Down
4 changes: 3 additions & 1 deletion src/quipper/perf_data_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ const PerfDataProto_SampleInfo* GetSampleInfoForEvent(
return &event.cgroup_event().sample_info();
case PERF_RECORD_KSYMBOL:
return &event.ksymbol_event().sample_info();
case PERF_RECORD_BPF_METADATA:
return &event.bpf_metadata_event().sample_info();
}
return nullptr;
}
Expand Down Expand Up @@ -555,7 +557,7 @@ bool GetEventDataVariablePayloadSize(const event_t& event,
<< remaining_event_size;
return false;
}
*size = remaining_event_size;
*size = actual_entries * sizeof(struct bpf_metadata_entry);
break;
}
// The below events changed size between kernel versions,
Expand Down
3 changes: 2 additions & 1 deletion src/quipper/perf_parser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1904,7 +1904,8 @@ TEST(PerfParserTest, BpfMetadataEvents) {
{
{.key = "my_key", .value = "my_value"},
{.key = "longer_key", .value = "slightly_different_value"},
});
},
testing::SampleInfo().Tid(2010));

size_t data_size = event.GetSize();

Expand Down
5 changes: 4 additions & 1 deletion src/quipper/perf_serializer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ uint64_t GetSampleTimestampFromEventProto(
return event.context_switch_event().sample_info().sample_time_ns();
} else if (event.has_namespaces_event()) {
return event.namespaces_event().sample_info().sample_time_ns();
} else if (event.has_bpf_metadata_event()) {
return event.bpf_metadata_event().sample_info().sample_time_ns();
}
return 0;
}
Expand Down Expand Up @@ -1868,7 +1870,8 @@ TEST(PerfSerializerTest, SerializesAndDeserializesBpfEvents) {
{
{.key = "my_key", .value = "my_value"},
{.key = "longer_key", .value = "slightly_different_value"},
})
},
testing::SampleInfo().Tid(2010))
.WriteTo(&input);

// Serialize.
Expand Down
2 changes: 2 additions & 0 deletions src/quipper/sample_info_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,7 @@ bool SampleInfoReader::IsSupportedEventType(uint32_t type) {
case PERF_RECORD_MMAP:
case PERF_RECORD_MMAP2:
case PERF_RECORD_KSYMBOL:
case PERF_RECORD_BPF_METADATA:
case PERF_RECORD_FORK:
case PERF_RECORD_EXIT:
case PERF_RECORD_COMM:
Expand Down Expand Up @@ -922,6 +923,7 @@ uint64_t SampleInfoReader::GetSampleFieldsForEventType(uint32_t event_type,
case PERF_RECORD_FORK:
case PERF_RECORD_MMAP2:
case PERF_RECORD_KSYMBOL:
case PERF_RECORD_BPF_METADATA:
case PERF_RECORD_AUX:
case PERF_RECORD_ITRACE_START:
case PERF_RECORD_LOST_SAMPLES:
Expand Down
7 changes: 5 additions & 2 deletions src/quipper/test_perf_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,8 @@ void ExampleKsymbolEvent::WriteTo(std::ostream* out) const {

size_t ExampleBpfMetadataEvent::GetSize() const {
return offsetof(struct bpf_metadata_event, entries) +
entries_.size() * sizeof(struct bpf_metadata_entry);
entries_.size() * sizeof(struct bpf_metadata_entry) +
sample_id_.size(); // sample_id_all
}

void ExampleBpfMetadataEvent::WriteTo(std::ostream* out) const {
Expand All @@ -960,7 +961,9 @@ void ExampleBpfMetadataEvent::WriteTo(std::ostream* out) const {
}

const size_t previous_offset = out->tellp();
out->write(reinterpret_cast<const char*>(event.get()), event_size);
out->write(reinterpret_cast<const char*>(event.get()),
event_size - sample_id_.size());
out->write(sample_id_.data(), sample_id_.size());
const size_t written_event_size =
static_cast<size_t>(out->tellp()) - previous_offset;
CHECK_EQ(event_size, static_cast<u64>(written_event_size));
Expand Down
8 changes: 6 additions & 2 deletions src/quipper/test_perf_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -958,14 +958,18 @@ class ExampleKsymbolEvent : public StreamWriteable {
class ExampleBpfMetadataEvent : public StreamWriteable {
public:
ExampleBpfMetadataEvent(std::string prog_name,
std::vector<struct bpf_metadata_entry> entries)
: prog_name_(prog_name), entries_(std::move(entries)) {}
std::vector<struct bpf_metadata_entry> entries,
const SampleInfo& sample_id)
: prog_name_(prog_name),
entries_(std::move(entries)),
sample_id_(sample_id) {}
size_t GetSize() const;
void WriteTo(std::ostream* out) const override;

private:
const std::string prog_name_;
const std::vector<struct bpf_metadata_entry> entries_;
const SampleInfo sample_id_;
};

} // namespace testing
Expand Down
Loading