From f8d9726ce5127ecba790fbbfde47920da37f4054 Mon Sep 17 00:00:00 2001 From: Milad Fa Date: Mon, 14 Sep 2026 12:49:56 +0000 Subject: [PATCH 1/8] Big-endian support --- gn/standalone/android.gni | 8 ++++++-- include/perfetto/protozero/message.h | 3 ++- include/perfetto/protozero/proto_utils.h | 24 ++++++++++++++++++++++++ src/protozero/field.cc | 12 ++++-------- src/protozero/message.cc | 6 ------ src/protozero/proto_decoder.cc | 9 ++++----- 6 files changed, 40 insertions(+), 22 deletions(-) diff --git a/gn/standalone/android.gni b/gn/standalone/android.gni index 3b82104369d..00e73c0ea22 100644 --- a/gn/standalone/android.gni +++ b/gn/standalone/android.gni @@ -44,7 +44,10 @@ declare_args() { android_abi_target = "aarch64-linux-android" android_llvm_arch = "aarch64" } else { - assert(false, "Need android libgcc support for this arch.") + assert(target_os != "android", + "Need android libgcc support for this arch.") + android_abi_target = "" + android_llvm_arch = "" } if (current_cpu == "x86") { @@ -56,6 +59,7 @@ declare_args() { } else if (current_cpu == "arm64") { android_app_abi = "arm64-v8a" } else { - assert(false, "Unknown ABI: " + current_cpu) + assert(target_os != "android", "Unknown ABI: " + current_cpu) + android_app_abi = "" } } diff --git a/include/perfetto/protozero/message.h b/include/perfetto/protozero/message.h index 1bcadaf688b..0cf24796e8b 100644 --- a/include/perfetto/protozero/message.h +++ b/include/perfetto/protozero/message.h @@ -135,7 +135,8 @@ class PERFETTO_EXPORT_COMPONENT Message { uint8_t* pos = buffer; pos = proto_utils::WriteVarInt(proto_utils::MakeTagFixed(field_id), pos); - memcpy(pos, &value, sizeof(T)); + T le_value = proto_utils::FixedToFromLittleEndian(value); + memcpy(pos, &le_value, sizeof(T)); pos += sizeof(T); // TODO: Optimize memcpy performance, see http://crbug.com/624311 . WriteToStream(buffer, pos); diff --git a/include/perfetto/protozero/proto_utils.h b/include/perfetto/protozero/proto_utils.h index ce8b24e279c..2444c195141 100644 --- a/include/perfetto/protozero/proto_utils.h +++ b/include/perfetto/protozero/proto_utils.h @@ -18,10 +18,12 @@ #define INCLUDE_PERFETTO_PROTOZERO_PROTO_UTILS_H_ #include +#include #include #include +#include "perfetto/base/compiler.h" #include "perfetto/base/logging.h" #include "perfetto/public/compiler.h" #include "perfetto/public/pb_utils.h" @@ -38,6 +40,28 @@ namespace protozero { namespace proto_utils { +// Reorders the bytes of a fixed32/fixed64/float/double so that the in memory +// representation matches the little endian proto wire format. +template +inline T FixedToFromLittleEndian(T value) { + static_assert(std::is_trivially_copyable::value, + "FixedToFromLittleEndian requires a trivially copyable type"); +#if PERFETTO_IS_LITTLE_ENDIAN() + return value; +#else + uint8_t bytes[sizeof(T)]; + memcpy(bytes, &value, sizeof(T)); + for (size_t i = 0; i < sizeof(T) / 2; ++i) { + uint8_t tmp = bytes[i]; + bytes[i] = bytes[sizeof(T) - 1 - i]; + bytes[sizeof(T) - 1 - i] = tmp; + } + T result; + memcpy(&result, bytes, sizeof(T)); + return result; +#endif +} + // See https://developers.google.com/protocol-buffers/docs/encoding wire types. // This is a type encoded into the proto that provides just enough info to // find the length of the following value. diff --git a/src/protozero/field.cc b/src/protozero/field.cc index 881ee4a1d9f..24428934c89 100644 --- a/src/protozero/field.cc +++ b/src/protozero/field.cc @@ -19,12 +19,6 @@ #include "perfetto/base/compiler.h" #include "perfetto/base/logging.h" -#if !PERFETTO_IS_LITTLE_ENDIAN() -// The memcpy() for fixed32/64 below needs to be adjusted if we want to -// support big endian CPUs. There doesn't seem to be a compelling need today. -#error Unimplemented for big endian archs. -#endif - namespace protozero { template @@ -42,14 +36,16 @@ void Field::SerializeAndAppendToInternal(Container* dst) const { } case static_cast(pu::ProtoWireType::kFixed32): { wptr = pu::WriteVarInt(pu::MakeTagFixed(id_), wptr); - uint32_t value32 = static_cast(int_value_); + uint32_t value32 = + pu::FixedToFromLittleEndian(static_cast(int_value_)); memcpy(wptr, &value32, sizeof(value32)); wptr += sizeof(uint32_t); break; } case static_cast(pu::ProtoWireType::kFixed64): { wptr = pu::WriteVarInt(pu::MakeTagFixed(id_), wptr); - memcpy(wptr, &int_value_, sizeof(int_value_)); + uint64_t value64 = pu::FixedToFromLittleEndian(int_value_); + memcpy(wptr, &value64, sizeof(value64)); wptr += sizeof(uint64_t); break; } diff --git a/src/protozero/message.cc b/src/protozero/message.cc index 562438b0fa0..a4278c4e493 100644 --- a/src/protozero/message.cc +++ b/src/protozero/message.cc @@ -24,12 +24,6 @@ #include "perfetto/protozero/message_arena.h" #include "perfetto/protozero/message_handle.h" -#if !PERFETTO_IS_LITTLE_ENDIAN() -// The memcpy() for float and double below needs to be adjusted if we want to -// support big endian CPUs. There doesn't seem to be a compelling need today. -#error Unimplemented for big endian archs. -#endif - namespace protozero { namespace { diff --git a/src/protozero/proto_decoder.cc b/src/protozero/proto_decoder.cc index 496209c7c82..112ee805298 100644 --- a/src/protozero/proto_decoder.cc +++ b/src/protozero/proto_decoder.cc @@ -32,10 +32,6 @@ namespace protozero { using namespace proto_utils; -#if !PERFETTO_IS_LITTLE_ENDIAN() -#error Unimplemented for big endian archs. -#endif - const Field TypedProtoDecoderBase::kInvalidField{}; namespace { @@ -115,11 +111,14 @@ ParseOneField(const uint8_t* const buffer, const uint8_t* const end) { if (PERFETTO_UNLIKELY(new_pos > end)) return res; memcpy(&int_value, pos, sizeof(uint64_t)); + int_value = proto_utils::FixedToFromLittleEndian(int_value); } else if (field_type == static_cast(ProtoWireType::kFixed32)) { new_pos = pos + sizeof(uint32_t); if (PERFETTO_UNLIKELY(new_pos > end)) return res; - memcpy(&int_value, pos, sizeof(uint32_t)); + uint32_t value32; + memcpy(&value32, pos, sizeof(uint32_t)); + int_value = proto_utils::FixedToFromLittleEndian(value32); } else { PERFETTO_DLOG("Invalid proto field type: %u", field_type); return res; From a542af31fa2f78273fb62e7ad05c67e969252038 Mon Sep 17 00:00:00 2001 From: Milad Fa Date: Fri, 18 Sep 2026 17:21:38 +0000 Subject: [PATCH 2/8] update --- include/perfetto/base/compiler.h | 2 +- include/perfetto/ext/base/endian.h | 86 +++++++++++++++---- include/perfetto/ext/base/uuid.h | 19 ++-- include/perfetto/protozero/BUILD.gn | 1 + include/perfetto/protozero/message.h | 2 +- .../protozero/packed_repeated_fields.h | 3 +- include/perfetto/protozero/proto_decoder.h | 1 + include/perfetto/protozero/proto_utils.h | 53 ++++++++---- src/protozero/field.cc | 4 +- .../filtering/filter_bytecode_generator.cc | 5 +- .../filtering/filter_bytecode_parser.cc | 2 +- .../filter_bytecode_parser_unittest.cc | 7 +- src/protozero/filtering/message_filter.cc | 3 +- src/protozero/proto_decoder.cc | 4 +- 14 files changed, 140 insertions(+), 52 deletions(-) diff --git a/include/perfetto/base/compiler.h b/include/perfetto/base/compiler.h index d0406c8dbab..8ffa94a0507 100644 --- a/include/perfetto/base/compiler.h +++ b/include/perfetto/base/compiler.h @@ -113,7 +113,7 @@ extern "C" void __msan_unpoison(void const volatile*, size_t); #endif // __clang__ #if defined(__GNUC__) || defined(__clang__) -#define PERFETTO_IS_LITTLE_ENDIAN() __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#define PERFETTO_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) #else // Assume all MSVC targets are little endian. #define PERFETTO_IS_LITTLE_ENDIAN() 1 diff --git a/include/perfetto/ext/base/endian.h b/include/perfetto/ext/base/endian.h index d4bac901881..7c81ca241ec 100644 --- a/include/perfetto/ext/base/endian.h +++ b/include/perfetto/ext/base/endian.h @@ -23,50 +23,104 @@ #include "perfetto/base/build_config.h" #include "perfetto/base/compiler.h" -#if !PERFETTO_IS_LITTLE_ENDIAN() -#error "endian.h supports only little-endian archs" -#endif - namespace perfetto { namespace base { #if PERFETTO_BUILDFLAG(PERFETTO_COMPILER_MSVC) -inline uint16_t HostToBE16(uint16_t x) { +inline uint16_t ByteSwap16(uint16_t x) { return _byteswap_ushort(x); } -inline uint32_t HostToBE32(uint32_t x) { +inline uint32_t ByteSwap32(uint32_t x) { return _byteswap_ulong(x); } -inline uint64_t HostToBE64(uint64_t x) { +inline uint64_t ByteSwap64(uint64_t x) { return _byteswap_uint64(x); } +#else +inline uint16_t ByteSwap16(uint16_t x) { + return __builtin_bswap16(x); +} +inline uint32_t ByteSwap32(uint32_t x) { + return __builtin_bswap32(x); +} +inline uint64_t ByteSwap64(uint64_t x) { + return __builtin_bswap64(x); +} +#endif + +#if PERFETTO_IS_LITTLE_ENDIAN() +inline uint16_t HostToLE16(uint16_t x) { + return x; +} +inline uint32_t HostToLE32(uint32_t x) { + return x; +} +inline uint64_t HostToLE64(uint64_t x) { + return x; +} +inline uint16_t LE16ToHost(uint16_t x) { + return x; +} +inline uint32_t LE32ToHost(uint32_t x) { + return x; +} +inline uint64_t LE64ToHost(uint64_t x) { + return x; +} +inline uint16_t HostToBE16(uint16_t x) { + return ByteSwap16(x); +} +inline uint32_t HostToBE32(uint32_t x) { + return ByteSwap32(x); +} +inline uint64_t HostToBE64(uint64_t x) { + return ByteSwap64(x); +} inline uint16_t BE16ToHost(uint16_t x) { - return _byteswap_ushort(x); + return ByteSwap16(x); } inline uint32_t BE32ToHost(uint32_t x) { - return _byteswap_ulong(x); + return ByteSwap32(x); } inline uint64_t BE64ToHost(uint64_t x) { - return _byteswap_uint64(x); + return ByteSwap64(x); } #else +inline uint16_t HostToLE16(uint16_t x) { + return ByteSwap16(x); +} +inline uint32_t HostToLE32(uint32_t x) { + return ByteSwap32(x); +} +inline uint64_t HostToLE64(uint64_t x) { + return ByteSwap64(x); +} +inline uint16_t LE16ToHost(uint16_t x) { + return ByteSwap16(x); +} +inline uint32_t LE32ToHost(uint32_t x) { + return ByteSwap32(x); +} +inline uint64_t LE64ToHost(uint64_t x) { + return ByteSwap64(x); +} inline uint16_t HostToBE16(uint16_t x) { - return __builtin_bswap16(x); + return x; } inline uint32_t HostToBE32(uint32_t x) { - return __builtin_bswap32(x); + return x; } inline uint64_t HostToBE64(uint64_t x) { - return __builtin_bswap64(x); + return x; } inline uint16_t BE16ToHost(uint16_t x) { - return __builtin_bswap16(x); + return x; } inline uint32_t BE32ToHost(uint32_t x) { - return __builtin_bswap32(x); + return x; } inline uint64_t BE64ToHost(uint64_t x) { - return __builtin_bswap64(x); + return x; } #endif diff --git a/include/perfetto/ext/base/uuid.h b/include/perfetto/ext/base/uuid.h index 4dd2a788600..5b3d1a8e7d8 100644 --- a/include/perfetto/ext/base/uuid.h +++ b/include/perfetto/ext/base/uuid.h @@ -23,6 +23,7 @@ #include #include "perfetto/base/export.h" +#include "perfetto/ext/base/endian.h" namespace perfetto { namespace base { @@ -43,23 +44,29 @@ class PERFETTO_EXPORT_COMPONENT Uuid { explicit operator bool() const { return *this != Uuid(); } int64_t msb() const { - int64_t result; + uint64_t result; memcpy(&result, data_.data() + 8, 8); - return result; + return static_cast(LE64ToHost(result)); } int64_t lsb() const { - int64_t result; + uint64_t result; memcpy(&result, data_.data(), 8); - return result; + return static_cast(LE64ToHost(result)); } void set_lsb_msb(int64_t lsb, int64_t msb) { set_lsb(lsb); set_msb(msb); } - void set_msb(int64_t msb) { memcpy(data_.data() + 8, &msb, 8); } - void set_lsb(int64_t lsb) { memcpy(data_.data(), &lsb, 8); } + void set_msb(int64_t msb) { + uint64_t le = HostToLE64(static_cast(msb)); + memcpy(data_.data() + 8, &le, 8); + } + void set_lsb(int64_t lsb) { + uint64_t le = HostToLE64(static_cast(lsb)); + memcpy(data_.data(), &le, 8); + } std::string ToString() const; std::string ToPrettyString() const; diff --git a/include/perfetto/protozero/BUILD.gn b/include/perfetto/protozero/BUILD.gn index 60d6b1ae50f..3a1f9ef0c4f 100644 --- a/include/perfetto/protozero/BUILD.gn +++ b/include/perfetto/protozero/BUILD.gn @@ -15,6 +15,7 @@ source_set("protozero") { public_deps = [ "../base", + "../ext/base", "../public:protozero", ] sources = [ diff --git a/include/perfetto/protozero/message.h b/include/perfetto/protozero/message.h index 0cf24796e8b..47313edd722 100644 --- a/include/perfetto/protozero/message.h +++ b/include/perfetto/protozero/message.h @@ -135,7 +135,7 @@ class PERFETTO_EXPORT_COMPONENT Message { uint8_t* pos = buffer; pos = proto_utils::WriteVarInt(proto_utils::MakeTagFixed(field_id), pos); - T le_value = proto_utils::FixedToFromLittleEndian(value); + T le_value = proto_utils::HostToLEFixed(value); memcpy(pos, &le_value, sizeof(T)); pos += sizeof(T); // TODO: Optimize memcpy performance, see http://crbug.com/624311 . diff --git a/include/perfetto/protozero/packed_repeated_fields.h b/include/perfetto/protozero/packed_repeated_fields.h index dff45e7cb89..424972f648b 100644 --- a/include/perfetto/protozero/packed_repeated_fields.h +++ b/include/perfetto/protozero/packed_repeated_fields.h @@ -105,7 +105,8 @@ class PackedFixedSizeInt : public PackedBufferBase { "kMaxElementSize needs to be updated"); GrowIfNeeded(); PERFETTO_DCHECK(reinterpret_cast(write_ptr_) % alignof(T) == 0); - memcpy(reinterpret_cast(write_ptr_), &value, sizeof(T)); + T le_value = proto_utils::HostToLEFixed(value); + memcpy(reinterpret_cast(write_ptr_), &le_value, sizeof(T)); write_ptr_ += sizeof(T); } }; diff --git a/include/perfetto/protozero/proto_decoder.h b/include/perfetto/protozero/proto_decoder.h index 6cb299b3136..e6dd5ecf90e 100644 --- a/include/perfetto/protozero/proto_decoder.h +++ b/include/perfetto/protozero/proto_decoder.h @@ -243,6 +243,7 @@ class PackedRepeatedFieldIterator { // NB: the raw buffer is not guaranteed to be aligned, so neither are // these copies. memcpy(&curr_value_, read_ptr_, sizeof(CppType)); + curr_value_ = proto_utils::LEFixedToHost(curr_value_); read_ptr_ += kStep; } diff --git a/include/perfetto/protozero/proto_utils.h b/include/perfetto/protozero/proto_utils.h index 2444c195141..ec48b62389b 100644 --- a/include/perfetto/protozero/proto_utils.h +++ b/include/perfetto/protozero/proto_utils.h @@ -25,6 +25,7 @@ #include "perfetto/base/compiler.h" #include "perfetto/base/logging.h" +#include "perfetto/ext/base/endian.h" #include "perfetto/public/compiler.h" #include "perfetto/public/pb_utils.h" @@ -40,26 +41,46 @@ namespace protozero { namespace proto_utils { -// Reorders the bytes of a fixed32/fixed64/float/double so that the in memory -// representation matches the little endian proto wire format. +// Converts a fixed32/fixed64/sfixed/float/double between host byte order and +// the little-endian proto wire representation. template -inline T FixedToFromLittleEndian(T value) { +inline T HostToLEFixed(T value) { static_assert(std::is_trivially_copyable::value, - "FixedToFromLittleEndian requires a trivially copyable type"); -#if PERFETTO_IS_LITTLE_ENDIAN() + "HostToLEFixed requires a trivially copyable type"); + static_assert(sizeof(T) == 4 || sizeof(T) == 8, + "HostToLEFixed supports only 32/64-bit fixed types"); + if (sizeof(T) == 4) { + uint32_t u; + memcpy(&u, &value, sizeof(u)); + u = perfetto::base::HostToLE32(u); + memcpy(&value, &u, sizeof(u)); + } else { + uint64_t u; + memcpy(&u, &value, sizeof(u)); + u = perfetto::base::HostToLE64(u); + memcpy(&value, &u, sizeof(u)); + } return value; -#else - uint8_t bytes[sizeof(T)]; - memcpy(bytes, &value, sizeof(T)); - for (size_t i = 0; i < sizeof(T) / 2; ++i) { - uint8_t tmp = bytes[i]; - bytes[i] = bytes[sizeof(T) - 1 - i]; - bytes[sizeof(T) - 1 - i] = tmp; +} + +template +inline T LEFixedToHost(T value) { + static_assert(std::is_trivially_copyable::value, + "LEFixedToHost requires a trivially copyable type"); + static_assert(sizeof(T) == 4 || sizeof(T) == 8, + "LEFixedToHost supports only 32/64-bit fixed types"); + if (sizeof(T) == 4) { + uint32_t u; + memcpy(&u, &value, sizeof(u)); + u = perfetto::base::LE32ToHost(u); + memcpy(&value, &u, sizeof(u)); + } else { + uint64_t u; + memcpy(&u, &value, sizeof(u)); + u = perfetto::base::LE64ToHost(u); + memcpy(&value, &u, sizeof(u)); } - T result; - memcpy(&result, bytes, sizeof(T)); - return result; -#endif + return value; } // See https://developers.google.com/protocol-buffers/docs/encoding wire types. diff --git a/src/protozero/field.cc b/src/protozero/field.cc index 24428934c89..7d30d3f8c11 100644 --- a/src/protozero/field.cc +++ b/src/protozero/field.cc @@ -37,14 +37,14 @@ void Field::SerializeAndAppendToInternal(Container* dst) const { case static_cast(pu::ProtoWireType::kFixed32): { wptr = pu::WriteVarInt(pu::MakeTagFixed(id_), wptr); uint32_t value32 = - pu::FixedToFromLittleEndian(static_cast(int_value_)); + pu::HostToLEFixed(static_cast(int_value_)); memcpy(wptr, &value32, sizeof(value32)); wptr += sizeof(uint32_t); break; } case static_cast(pu::ProtoWireType::kFixed64): { wptr = pu::WriteVarInt(pu::MakeTagFixed(id_), wptr); - uint64_t value64 = pu::FixedToFromLittleEndian(int_value_); + uint64_t value64 = pu::HostToLEFixed(int_value_); memcpy(wptr, &value64, sizeof(value64)); wptr += sizeof(uint64_t); break; diff --git a/src/protozero/filtering/filter_bytecode_generator.cc b/src/protozero/filtering/filter_bytecode_generator.cc index d52b5bf0d0c..aece6810acc 100644 --- a/src/protozero/filtering/filter_bytecode_generator.cc +++ b/src/protozero/filtering/filter_bytecode_generator.cc @@ -23,6 +23,7 @@ #include "perfetto/base/logging.h" #include "perfetto/ext/base/fnv_hash.h" #include "perfetto/protozero/packed_repeated_fields.h" +#include "perfetto/protozero/proto_utils.h" #include "src/protozero/filtering/filter_bytecode_common.h" namespace protozero { @@ -144,7 +145,7 @@ FilterBytecodeGenerator::SerializeResult FilterBytecodeGenerator::Serialize() { perfetto::base::FnvHasher hasher; for (uint32_t word : bytecode_) { words.Append(word); - hasher.Update(word); + hasher.Update(proto_utils::HostToLEFixed(word)); } words.Append(static_cast(hasher.digest())); result.bytecode = @@ -157,7 +158,7 @@ FilterBytecodeGenerator::SerializeResult FilterBytecodeGenerator::Serialize() { perfetto::base::FnvHasher hasher; for (uint32_t word : v54_overlay_) { words.Append(word); - hasher.Update(word); + hasher.Update(proto_utils::HostToLEFixed(word)); } words.Append(static_cast(hasher.digest())); result.v54_overlay = diff --git a/src/protozero/filtering/filter_bytecode_parser.cc b/src/protozero/filtering/filter_bytecode_parser.cc index c199f155807..9c1b71817d7 100644 --- a/src/protozero/filtering/filter_bytecode_parser.cc +++ b/src/protozero/filtering/filter_bytecode_parser.cc @@ -62,7 +62,7 @@ bool ParseAndVerifyChecksum(const uint8_t* data, break; } words->emplace_back(word); - hasher.Update(word); + hasher.Update(proto_utils::HostToLEFixed(word)); } if (packed_parse_err || !has_checksum) { words->clear(); diff --git a/src/protozero/filtering/filter_bytecode_parser_unittest.cc b/src/protozero/filtering/filter_bytecode_parser_unittest.cc index 98b2ecf4b2f..b6a97f214f9 100644 --- a/src/protozero/filtering/filter_bytecode_parser_unittest.cc +++ b/src/protozero/filtering/filter_bytecode_parser_unittest.cc @@ -22,6 +22,7 @@ #include "perfetto/ext/base/fnv_hash.h" #include "perfetto/protozero/packed_repeated_fields.h" +#include "perfetto/protozero/proto_utils.h" #include "src/protozero/filtering/filter_bytecode_common.h" #include "test/gtest_and_gmock.h" @@ -35,7 +36,7 @@ bool LoadBytecode(FilterBytecodeParser* parser, protozero::PackedVarInt words; for (uint32_t w : bytecode) { words.Append(w); - hasher.Update(w); + hasher.Update(proto_utils::HostToLEFixed(w)); } words.Append(static_cast(hasher.digest())); return parser->Load(words.data(), words.size()); @@ -46,7 +47,7 @@ std::vector MakeOverlay(std::initializer_list words) { protozero::PackedVarInt packed; for (uint32_t w : words) { packed.Append(w); - hasher.Update(w); + hasher.Update(proto_utils::HostToLEFixed(w)); } packed.Append(static_cast(hasher.digest())); return {packed.data(), packed.data() + packed.size()}; @@ -59,7 +60,7 @@ bool LoadBytecodeWithOverlay(FilterBytecodeParser* parser, protozero::PackedVarInt words; for (uint32_t w : bytecode) { words.Append(w); - hasher.Update(w); + hasher.Update(proto_utils::HostToLEFixed(w)); } words.Append(static_cast(hasher.digest())); diff --git a/src/protozero/filtering/message_filter.cc b/src/protozero/filtering/message_filter.cc index 36fd2b0b768..0c44ac8ca6b 100644 --- a/src/protozero/filtering/message_filter.cc +++ b/src/protozero/filtering/message_filter.cc @@ -42,7 +42,8 @@ template inline void AppendFixed(uint32_t field_id, INT_T value, uint8_t** out) { *out = proto_utils::WriteVarInt(proto_utils::MakeTagFixed(field_id), *out); - memcpy(*out, &value, sizeof(value)); + INT_T le_value = proto_utils::HostToLEFixed(value); + memcpy(*out, &le_value, sizeof(value)); *out += sizeof(value); } diff --git a/src/protozero/proto_decoder.cc b/src/protozero/proto_decoder.cc index 112ee805298..ba14fd55694 100644 --- a/src/protozero/proto_decoder.cc +++ b/src/protozero/proto_decoder.cc @@ -111,14 +111,14 @@ ParseOneField(const uint8_t* const buffer, const uint8_t* const end) { if (PERFETTO_UNLIKELY(new_pos > end)) return res; memcpy(&int_value, pos, sizeof(uint64_t)); - int_value = proto_utils::FixedToFromLittleEndian(int_value); + int_value = perfetto::base::LE64ToHost(int_value); } else if (field_type == static_cast(ProtoWireType::kFixed32)) { new_pos = pos + sizeof(uint32_t); if (PERFETTO_UNLIKELY(new_pos > end)) return res; uint32_t value32; memcpy(&value32, pos, sizeof(uint32_t)); - int_value = proto_utils::FixedToFromLittleEndian(value32); + int_value = perfetto::base::LE32ToHost(value32); } else { PERFETTO_DLOG("Invalid proto field type: %u", field_type); return res; From 2b0cc9bef013bac4f60b0e76217a6431d3e09076 Mon Sep 17 00:00:00 2001 From: Milad Fa Date: Tue, 22 Sep 2026 14:59:33 +0000 Subject: [PATCH 3/8] update --- include/perfetto/ext/base/endian.h | 51 +++++++++++++++++++ include/perfetto/protozero/message.h | 2 +- .../protozero/packed_repeated_fields.h | 2 +- include/perfetto/protozero/proto_decoder.h | 2 +- include/perfetto/protozero/proto_utils.h | 42 --------------- src/protozero/field.cc | 4 +- .../filtering/filter_bytecode_generator.cc | 4 +- .../filtering/filter_bytecode_parser.cc | 2 +- .../filter_bytecode_parser_unittest.cc | 6 +-- src/protozero/filtering/message_filter.cc | 2 +- 10 files changed, 63 insertions(+), 54 deletions(-) diff --git a/include/perfetto/ext/base/endian.h b/include/perfetto/ext/base/endian.h index 7c81ca241ec..501efe9fd25 100644 --- a/include/perfetto/ext/base/endian.h +++ b/include/perfetto/ext/base/endian.h @@ -19,6 +19,9 @@ #include #include // For MSVC +#include + +#include #include "perfetto/base/build_config.h" #include "perfetto/base/compiler.h" @@ -124,6 +127,54 @@ inline uint64_t BE64ToHost(uint64_t x) { } #endif +template +inline T HostToLE(T x) { + static_assert(sizeof(T) == 4 || sizeof(T) == 8); + if constexpr (std::is_integral::value) { + if constexpr (sizeof(T) == 4) + return static_cast(HostToLE32(static_cast(x))); + else + return static_cast(HostToLE64(static_cast(x))); + } else { + if constexpr (sizeof(T) == 4) { + uint32_t u; + memcpy(&u, &x, sizeof(u)); + u = HostToLE32(u); + memcpy(&x, &u, sizeof(u)); + } else { + uint64_t u; + memcpy(&u, &x, sizeof(u)); + u = HostToLE64(u); + memcpy(&x, &u, sizeof(u)); + } + return x; + } +} + +template +inline T LEToHost(T x) { + static_assert(sizeof(T) == 4 || sizeof(T) == 8); + if constexpr (std::is_integral::value) { + if constexpr (sizeof(T) == 4) + return static_cast(LE32ToHost(static_cast(x))); + else + return static_cast(LE64ToHost(static_cast(x))); + } else { + if constexpr (sizeof(T) == 4) { + uint32_t u; + memcpy(&u, &x, sizeof(u)); + u = LE32ToHost(u); + memcpy(&x, &u, sizeof(u)); + } else { + uint64_t u; + memcpy(&u, &x, sizeof(u)); + u = LE64ToHost(u); + memcpy(&x, &u, sizeof(u)); + } + return x; + } +} + } // namespace base } // namespace perfetto diff --git a/include/perfetto/protozero/message.h b/include/perfetto/protozero/message.h index 47313edd722..c2a014156fe 100644 --- a/include/perfetto/protozero/message.h +++ b/include/perfetto/protozero/message.h @@ -135,7 +135,7 @@ class PERFETTO_EXPORT_COMPONENT Message { uint8_t* pos = buffer; pos = proto_utils::WriteVarInt(proto_utils::MakeTagFixed(field_id), pos); - T le_value = proto_utils::HostToLEFixed(value); + T le_value = perfetto::base::HostToLE(value); memcpy(pos, &le_value, sizeof(T)); pos += sizeof(T); // TODO: Optimize memcpy performance, see http://crbug.com/624311 . diff --git a/include/perfetto/protozero/packed_repeated_fields.h b/include/perfetto/protozero/packed_repeated_fields.h index 424972f648b..b6e23910e47 100644 --- a/include/perfetto/protozero/packed_repeated_fields.h +++ b/include/perfetto/protozero/packed_repeated_fields.h @@ -105,7 +105,7 @@ class PackedFixedSizeInt : public PackedBufferBase { "kMaxElementSize needs to be updated"); GrowIfNeeded(); PERFETTO_DCHECK(reinterpret_cast(write_ptr_) % alignof(T) == 0); - T le_value = proto_utils::HostToLEFixed(value); + T le_value = perfetto::base::HostToLE(value); memcpy(reinterpret_cast(write_ptr_), &le_value, sizeof(T)); write_ptr_ += sizeof(T); } diff --git a/include/perfetto/protozero/proto_decoder.h b/include/perfetto/protozero/proto_decoder.h index e6dd5ecf90e..347bacf9ed3 100644 --- a/include/perfetto/protozero/proto_decoder.h +++ b/include/perfetto/protozero/proto_decoder.h @@ -243,7 +243,7 @@ class PackedRepeatedFieldIterator { // NB: the raw buffer is not guaranteed to be aligned, so neither are // these copies. memcpy(&curr_value_, read_ptr_, sizeof(CppType)); - curr_value_ = proto_utils::LEFixedToHost(curr_value_); + curr_value_ = perfetto::base::LEToHost(curr_value_); read_ptr_ += kStep; } diff --git a/include/perfetto/protozero/proto_utils.h b/include/perfetto/protozero/proto_utils.h index ec48b62389b..60a5dd738bf 100644 --- a/include/perfetto/protozero/proto_utils.h +++ b/include/perfetto/protozero/proto_utils.h @@ -41,48 +41,6 @@ namespace protozero { namespace proto_utils { -// Converts a fixed32/fixed64/sfixed/float/double between host byte order and -// the little-endian proto wire representation. -template -inline T HostToLEFixed(T value) { - static_assert(std::is_trivially_copyable::value, - "HostToLEFixed requires a trivially copyable type"); - static_assert(sizeof(T) == 4 || sizeof(T) == 8, - "HostToLEFixed supports only 32/64-bit fixed types"); - if (sizeof(T) == 4) { - uint32_t u; - memcpy(&u, &value, sizeof(u)); - u = perfetto::base::HostToLE32(u); - memcpy(&value, &u, sizeof(u)); - } else { - uint64_t u; - memcpy(&u, &value, sizeof(u)); - u = perfetto::base::HostToLE64(u); - memcpy(&value, &u, sizeof(u)); - } - return value; -} - -template -inline T LEFixedToHost(T value) { - static_assert(std::is_trivially_copyable::value, - "LEFixedToHost requires a trivially copyable type"); - static_assert(sizeof(T) == 4 || sizeof(T) == 8, - "LEFixedToHost supports only 32/64-bit fixed types"); - if (sizeof(T) == 4) { - uint32_t u; - memcpy(&u, &value, sizeof(u)); - u = perfetto::base::LE32ToHost(u); - memcpy(&value, &u, sizeof(u)); - } else { - uint64_t u; - memcpy(&u, &value, sizeof(u)); - u = perfetto::base::LE64ToHost(u); - memcpy(&value, &u, sizeof(u)); - } - return value; -} - // See https://developers.google.com/protocol-buffers/docs/encoding wire types. // This is a type encoded into the proto that provides just enough info to // find the length of the following value. diff --git a/src/protozero/field.cc b/src/protozero/field.cc index 7d30d3f8c11..add8cf0b6fc 100644 --- a/src/protozero/field.cc +++ b/src/protozero/field.cc @@ -37,14 +37,14 @@ void Field::SerializeAndAppendToInternal(Container* dst) const { case static_cast(pu::ProtoWireType::kFixed32): { wptr = pu::WriteVarInt(pu::MakeTagFixed(id_), wptr); uint32_t value32 = - pu::HostToLEFixed(static_cast(int_value_)); + perfetto::base::HostToLE(static_cast(int_value_)); memcpy(wptr, &value32, sizeof(value32)); wptr += sizeof(uint32_t); break; } case static_cast(pu::ProtoWireType::kFixed64): { wptr = pu::WriteVarInt(pu::MakeTagFixed(id_), wptr); - uint64_t value64 = pu::HostToLEFixed(int_value_); + uint64_t value64 = perfetto::base::HostToLE(int_value_); memcpy(wptr, &value64, sizeof(value64)); wptr += sizeof(uint64_t); break; diff --git a/src/protozero/filtering/filter_bytecode_generator.cc b/src/protozero/filtering/filter_bytecode_generator.cc index aece6810acc..42b697e2445 100644 --- a/src/protozero/filtering/filter_bytecode_generator.cc +++ b/src/protozero/filtering/filter_bytecode_generator.cc @@ -145,7 +145,7 @@ FilterBytecodeGenerator::SerializeResult FilterBytecodeGenerator::Serialize() { perfetto::base::FnvHasher hasher; for (uint32_t word : bytecode_) { words.Append(word); - hasher.Update(proto_utils::HostToLEFixed(word)); + hasher.Update(perfetto::base::HostToLE(word)); } words.Append(static_cast(hasher.digest())); result.bytecode = @@ -158,7 +158,7 @@ FilterBytecodeGenerator::SerializeResult FilterBytecodeGenerator::Serialize() { perfetto::base::FnvHasher hasher; for (uint32_t word : v54_overlay_) { words.Append(word); - hasher.Update(proto_utils::HostToLEFixed(word)); + hasher.Update(perfetto::base::HostToLE(word)); } words.Append(static_cast(hasher.digest())); result.v54_overlay = diff --git a/src/protozero/filtering/filter_bytecode_parser.cc b/src/protozero/filtering/filter_bytecode_parser.cc index 9c1b71817d7..b229b846033 100644 --- a/src/protozero/filtering/filter_bytecode_parser.cc +++ b/src/protozero/filtering/filter_bytecode_parser.cc @@ -62,7 +62,7 @@ bool ParseAndVerifyChecksum(const uint8_t* data, break; } words->emplace_back(word); - hasher.Update(proto_utils::HostToLEFixed(word)); + hasher.Update(perfetto::base::HostToLE(word)); } if (packed_parse_err || !has_checksum) { words->clear(); diff --git a/src/protozero/filtering/filter_bytecode_parser_unittest.cc b/src/protozero/filtering/filter_bytecode_parser_unittest.cc index b6a97f214f9..a44cfd66a8c 100644 --- a/src/protozero/filtering/filter_bytecode_parser_unittest.cc +++ b/src/protozero/filtering/filter_bytecode_parser_unittest.cc @@ -36,7 +36,7 @@ bool LoadBytecode(FilterBytecodeParser* parser, protozero::PackedVarInt words; for (uint32_t w : bytecode) { words.Append(w); - hasher.Update(proto_utils::HostToLEFixed(w)); + hasher.Update(perfetto::base::HostToLE(w)); } words.Append(static_cast(hasher.digest())); return parser->Load(words.data(), words.size()); @@ -47,7 +47,7 @@ std::vector MakeOverlay(std::initializer_list words) { protozero::PackedVarInt packed; for (uint32_t w : words) { packed.Append(w); - hasher.Update(proto_utils::HostToLEFixed(w)); + hasher.Update(perfetto::base::HostToLE(w)); } packed.Append(static_cast(hasher.digest())); return {packed.data(), packed.data() + packed.size()}; @@ -60,7 +60,7 @@ bool LoadBytecodeWithOverlay(FilterBytecodeParser* parser, protozero::PackedVarInt words; for (uint32_t w : bytecode) { words.Append(w); - hasher.Update(proto_utils::HostToLEFixed(w)); + hasher.Update(perfetto::base::HostToLE(w)); } words.Append(static_cast(hasher.digest())); diff --git a/src/protozero/filtering/message_filter.cc b/src/protozero/filtering/message_filter.cc index 0c44ac8ca6b..f54035f2bb2 100644 --- a/src/protozero/filtering/message_filter.cc +++ b/src/protozero/filtering/message_filter.cc @@ -42,7 +42,7 @@ template inline void AppendFixed(uint32_t field_id, INT_T value, uint8_t** out) { *out = proto_utils::WriteVarInt(proto_utils::MakeTagFixed(field_id), *out); - INT_T le_value = proto_utils::HostToLEFixed(value); + INT_T le_value = perfetto::base::HostToLE(value); memcpy(*out, &le_value, sizeof(value)); *out += sizeof(value); } From 34b4cd100b4bc192e72775848dea068d45dce815 Mon Sep 17 00:00:00 2001 From: Milad Fa Date: Tue, 22 Sep 2026 18:27:13 +0000 Subject: [PATCH 4/8] update --- include/perfetto/ext/base/endian.h | 137 ++++++++++++++------- include/perfetto/protozero/proto_decoder.h | 2 +- 2 files changed, 92 insertions(+), 47 deletions(-) diff --git a/include/perfetto/ext/base/endian.h b/include/perfetto/ext/base/endian.h index 501efe9fd25..c5b96c9697c 100644 --- a/include/perfetto/ext/base/endian.h +++ b/include/perfetto/ext/base/endian.h @@ -21,8 +21,6 @@ #include // For MSVC #include -#include - #include "perfetto/base/build_config.h" #include "perfetto/base/compiler.h" @@ -127,52 +125,99 @@ inline uint64_t BE64ToHost(uint64_t x) { } #endif -template -inline T HostToLE(T x) { - static_assert(sizeof(T) == 4 || sizeof(T) == 8); - if constexpr (std::is_integral::value) { - if constexpr (sizeof(T) == 4) - return static_cast(HostToLE32(static_cast(x))); - else - return static_cast(HostToLE64(static_cast(x))); - } else { - if constexpr (sizeof(T) == 4) { - uint32_t u; - memcpy(&u, &x, sizeof(u)); - u = HostToLE32(u); - memcpy(&x, &u, sizeof(u)); - } else { - uint64_t u; - memcpy(&u, &x, sizeof(u)); - u = HostToLE64(u); - memcpy(&x, &u, sizeof(u)); - } - return x; - } +inline float HostToLEFloat(float x) { + uint32_t u; + memcpy(&u, &x, sizeof(u)); + u = HostToLE32(u); + memcpy(&x, &u, sizeof(u)); + return x; +} +inline double HostToLEDouble(double x) { + uint64_t u; + memcpy(&u, &x, sizeof(u)); + u = HostToLE64(u); + memcpy(&x, &u, sizeof(u)); + return x; +} +inline float HostToBEFloat(float x) { + uint32_t u; + memcpy(&u, &x, sizeof(u)); + u = HostToBE32(u); + memcpy(&x, &u, sizeof(u)); + return x; +} +inline double HostToBEDouble(double x) { + uint64_t u; + memcpy(&u, &x, sizeof(u)); + u = HostToBE64(u); + memcpy(&x, &u, sizeof(u)); + return x; +} +inline float LEFloatToHost(float x) { + uint32_t u; + memcpy(&u, &x, sizeof(u)); + u = LE32ToHost(u); + memcpy(&x, &u, sizeof(u)); + return x; +} +inline double LEDoubleToHost(double x) { + uint64_t u; + memcpy(&u, &x, sizeof(u)); + u = LE64ToHost(u); + memcpy(&x, &u, sizeof(u)); + return x; +} +inline float BEFloatToHost(float x) { + uint32_t u; + memcpy(&u, &x, sizeof(u)); + u = BE32ToHost(u); + memcpy(&x, &u, sizeof(u)); + return x; +} +inline double BEDoubleToHost(double x) { + uint64_t u; + memcpy(&u, &x, sizeof(u)); + u = BE64ToHost(u); + memcpy(&x, &u, sizeof(u)); + return x; +} + +inline uint32_t HostToLE(uint32_t x) { + return HostToLE32(x); +} +inline int32_t HostToLE(int32_t x) { + return static_cast(HostToLE32(static_cast(x))); +} +inline uint64_t HostToLE(uint64_t x) { + return HostToLE64(x); +} +inline int64_t HostToLE(int64_t x) { + return static_cast(HostToLE64(static_cast(x))); +} +inline float HostToLE(float x) { + return HostToLEFloat(x); +} +inline double HostToLE(double x) { + return HostToLEDouble(x); } -template -inline T LEToHost(T x) { - static_assert(sizeof(T) == 4 || sizeof(T) == 8); - if constexpr (std::is_integral::value) { - if constexpr (sizeof(T) == 4) - return static_cast(LE32ToHost(static_cast(x))); - else - return static_cast(LE64ToHost(static_cast(x))); - } else { - if constexpr (sizeof(T) == 4) { - uint32_t u; - memcpy(&u, &x, sizeof(u)); - u = LE32ToHost(u); - memcpy(&x, &u, sizeof(u)); - } else { - uint64_t u; - memcpy(&u, &x, sizeof(u)); - u = LE64ToHost(u); - memcpy(&x, &u, sizeof(u)); - } - return x; - } +inline uint32_t LEToHost(uint32_t x) { + return LE32ToHost(x); +} +inline int32_t LEToHost(int32_t x) { + return static_cast(LE32ToHost(static_cast(x))); +} +inline uint64_t LEToHost(uint64_t x) { + return LE64ToHost(x); +} +inline int64_t LEToHost(int64_t x) { + return static_cast(LE64ToHost(static_cast(x))); +} +inline float LEToHost(float x) { + return LEFloatToHost(x); +} +inline double LEToHost(double x) { + return LEDoubleToHost(x); } } // namespace base diff --git a/include/perfetto/protozero/proto_decoder.h b/include/perfetto/protozero/proto_decoder.h index 347bacf9ed3..ee8a33c50fb 100644 --- a/include/perfetto/protozero/proto_decoder.h +++ b/include/perfetto/protozero/proto_decoder.h @@ -224,7 +224,7 @@ class PackedRepeatedFieldIterator { return *this; } - if (wire_type == ProtoWireType::kVarInt) { + if constexpr (wire_type == ProtoWireType::kVarInt) { uint64_t new_value = 0; const uint8_t* new_pos = proto_utils::ParseVarInt(read_ptr_, data_end_, &new_value); From 7e788925ac3f017994fedb436de3983278b8332f Mon Sep 17 00:00:00 2001 From: Milad Fa Date: Thu, 24 Sep 2026 12:48:58 +0000 Subject: [PATCH 5/8] update --- include/perfetto/ext/base/endian.h | 75 +++++++++++++++++++----------- 1 file changed, 49 insertions(+), 26 deletions(-) diff --git a/include/perfetto/ext/base/endian.h b/include/perfetto/ext/base/endian.h index c5b96c9697c..6bf1724dafe 100644 --- a/include/perfetto/ext/base/endian.h +++ b/include/perfetto/ext/base/endian.h @@ -86,6 +86,46 @@ inline uint32_t BE32ToHost(uint32_t x) { inline uint64_t BE64ToHost(uint64_t x) { return ByteSwap64(x); } +inline float HostToLEFloat(float x) { + return x; +} +inline double HostToLEDouble(double x) { + return x; +} +inline float LEFloatToHost(float x) { + return x; +} +inline double LEDoubleToHost(double x) { + return x; +} +inline float HostToBEFloat(float x) { + uint32_t u; + memcpy(&u, &x, sizeof(u)); + u = ByteSwap32(u); + memcpy(&x, &u, sizeof(u)); + return x; +} +inline double HostToBEDouble(double x) { + uint64_t u; + memcpy(&u, &x, sizeof(u)); + u = ByteSwap64(u); + memcpy(&x, &u, sizeof(u)); + return x; +} +inline float BEFloatToHost(float x) { + uint32_t u; + memcpy(&u, &x, sizeof(u)); + u = ByteSwap32(u); + memcpy(&x, &u, sizeof(u)); + return x; +} +inline double BEDoubleToHost(double x) { + uint64_t u; + memcpy(&u, &x, sizeof(u)); + u = ByteSwap64(u); + memcpy(&x, &u, sizeof(u)); + return x; +} #else inline uint16_t HostToLE16(uint16_t x) { return ByteSwap16(x); @@ -123,64 +163,47 @@ inline uint32_t BE32ToHost(uint32_t x) { inline uint64_t BE64ToHost(uint64_t x) { return x; } -#endif - inline float HostToLEFloat(float x) { uint32_t u; memcpy(&u, &x, sizeof(u)); - u = HostToLE32(u); + u = ByteSwap32(u); memcpy(&x, &u, sizeof(u)); return x; } inline double HostToLEDouble(double x) { uint64_t u; memcpy(&u, &x, sizeof(u)); - u = HostToLE64(u); + u = ByteSwap64(u); memcpy(&x, &u, sizeof(u)); return x; } -inline float HostToBEFloat(float x) { +inline float LEFloatToHost(float x) { uint32_t u; memcpy(&u, &x, sizeof(u)); - u = HostToBE32(u); + u = ByteSwap32(u); memcpy(&x, &u, sizeof(u)); return x; } -inline double HostToBEDouble(double x) { +inline double LEDoubleToHost(double x) { uint64_t u; memcpy(&u, &x, sizeof(u)); - u = HostToBE64(u); + u = ByteSwap64(u); memcpy(&x, &u, sizeof(u)); return x; } -inline float LEFloatToHost(float x) { - uint32_t u; - memcpy(&u, &x, sizeof(u)); - u = LE32ToHost(u); - memcpy(&x, &u, sizeof(u)); +inline float HostToBEFloat(float x) { return x; } -inline double LEDoubleToHost(double x) { - uint64_t u; - memcpy(&u, &x, sizeof(u)); - u = LE64ToHost(u); - memcpy(&x, &u, sizeof(u)); +inline double HostToBEDouble(double x) { return x; } inline float BEFloatToHost(float x) { - uint32_t u; - memcpy(&u, &x, sizeof(u)); - u = BE32ToHost(u); - memcpy(&x, &u, sizeof(u)); return x; } inline double BEDoubleToHost(double x) { - uint64_t u; - memcpy(&u, &x, sizeof(u)); - u = BE64ToHost(u); - memcpy(&x, &u, sizeof(u)); return x; } +#endif inline uint32_t HostToLE(uint32_t x) { return HostToLE32(x); From 5bff205742d0c5d7038e89c75906c4f2a22c326b Mon Sep 17 00:00:00 2001 From: Milad Fa Date: Fri, 25 Sep 2026 15:48:46 +0000 Subject: [PATCH 6/8] update --- BUILD | 3 +++ gn/standalone/android.gni | 3 +-- include/perfetto/protozero/message.h | 1 + include/perfetto/protozero/packed_repeated_fields.h | 1 + include/perfetto/protozero/proto_decoder.h | 1 + include/perfetto/protozero/proto_utils.h | 2 -- src/protozero/field.cc | 1 + src/protozero/filtering/filter_bytecode_generator.cc | 1 + src/protozero/filtering/filter_bytecode_parser.cc | 1 + src/protozero/filtering/filter_bytecode_parser_unittest.cc | 1 + src/protozero/filtering/message_filter.cc | 1 + 11 files changed, 12 insertions(+), 4 deletions(-) diff --git a/BUILD b/BUILD index b62e93fb3e2..9653a0310c9 100644 --- a/BUILD +++ b/BUILD @@ -147,6 +147,7 @@ perfetto_cc_library( ], hdrs = [ ":include_perfetto_base_base", + ":include_perfetto_ext_base_base", ":include_perfetto_protozero_protozero", ":include_perfetto_public_abi_base", ":include_perfetto_public_base", @@ -1141,6 +1142,7 @@ perfetto_cc_binary( name = "client_api_example", srcs = [ ":include_perfetto_base_base", + ":include_perfetto_ext_base_base", ":include_perfetto_protozero_protozero", ":include_perfetto_public_abi_base", ":include_perfetto_public_base", @@ -2482,6 +2484,7 @@ perfetto_cc_library( ], hdrs = [ ":include_perfetto_base_base", + ":include_perfetto_ext_base_base", ":include_perfetto_protozero_protozero", ":include_perfetto_public_abi_base", ":include_perfetto_public_base", diff --git a/gn/standalone/android.gni b/gn/standalone/android.gni index 00e73c0ea22..c9972f1fad7 100644 --- a/gn/standalone/android.gni +++ b/gn/standalone/android.gni @@ -44,8 +44,7 @@ declare_args() { android_abi_target = "aarch64-linux-android" android_llvm_arch = "aarch64" } else { - assert(target_os != "android", - "Need android libgcc support for this arch.") + assert(target_os != "android", "Need android libgcc support for this arch.") android_abi_target = "" android_llvm_arch = "" } diff --git a/include/perfetto/protozero/message.h b/include/perfetto/protozero/message.h index c2a014156fe..faf9680ad8a 100644 --- a/include/perfetto/protozero/message.h +++ b/include/perfetto/protozero/message.h @@ -26,6 +26,7 @@ #include "perfetto/base/export.h" #include "perfetto/base/logging.h" +#include "perfetto/ext/base/endian.h" // no-include-violation-check #include "perfetto/protozero/contiguous_memory_range.h" #include "perfetto/protozero/proto_utils.h" #include "perfetto/protozero/scattered_stream_writer.h" diff --git a/include/perfetto/protozero/packed_repeated_fields.h b/include/perfetto/protozero/packed_repeated_fields.h index b6e23910e47..001522f1348 100644 --- a/include/perfetto/protozero/packed_repeated_fields.h +++ b/include/perfetto/protozero/packed_repeated_fields.h @@ -24,6 +24,7 @@ #include #include "perfetto/base/logging.h" +#include "perfetto/ext/base/endian.h" // no-include-violation-check #include "perfetto/protozero/proto_utils.h" namespace protozero { diff --git a/include/perfetto/protozero/proto_decoder.h b/include/perfetto/protozero/proto_decoder.h index ee8a33c50fb..1f8bae398af 100644 --- a/include/perfetto/protozero/proto_decoder.h +++ b/include/perfetto/protozero/proto_decoder.h @@ -29,6 +29,7 @@ #include "perfetto/base/export.h" #include "perfetto/base/logging.h" +#include "perfetto/ext/base/endian.h" // no-include-violation-check #include "perfetto/protozero/field.h" #include "perfetto/protozero/proto_utils.h" #include "perfetto/public/compiler.h" diff --git a/include/perfetto/protozero/proto_utils.h b/include/perfetto/protozero/proto_utils.h index 60a5dd738bf..defbaf57a3c 100644 --- a/include/perfetto/protozero/proto_utils.h +++ b/include/perfetto/protozero/proto_utils.h @@ -18,14 +18,12 @@ #define INCLUDE_PERFETTO_PROTOZERO_PROTO_UTILS_H_ #include -#include #include #include #include "perfetto/base/compiler.h" #include "perfetto/base/logging.h" -#include "perfetto/ext/base/endian.h" #include "perfetto/public/compiler.h" #include "perfetto/public/pb_utils.h" diff --git a/src/protozero/field.cc b/src/protozero/field.cc index add8cf0b6fc..3ce22341afe 100644 --- a/src/protozero/field.cc +++ b/src/protozero/field.cc @@ -18,6 +18,7 @@ #include "perfetto/base/compiler.h" #include "perfetto/base/logging.h" +#include "perfetto/ext/base/endian.h" namespace protozero { diff --git a/src/protozero/filtering/filter_bytecode_generator.cc b/src/protozero/filtering/filter_bytecode_generator.cc index 42b697e2445..6936bed242b 100644 --- a/src/protozero/filtering/filter_bytecode_generator.cc +++ b/src/protozero/filtering/filter_bytecode_generator.cc @@ -21,6 +21,7 @@ #include #include "perfetto/base/logging.h" +#include "perfetto/ext/base/endian.h" #include "perfetto/ext/base/fnv_hash.h" #include "perfetto/protozero/packed_repeated_fields.h" #include "perfetto/protozero/proto_utils.h" diff --git a/src/protozero/filtering/filter_bytecode_parser.cc b/src/protozero/filtering/filter_bytecode_parser.cc index b229b846033..37bbe2e5a13 100644 --- a/src/protozero/filtering/filter_bytecode_parser.cc +++ b/src/protozero/filtering/filter_bytecode_parser.cc @@ -23,6 +23,7 @@ #include #include "perfetto/base/logging.h" +#include "perfetto/ext/base/endian.h" #include "perfetto/ext/base/fnv_hash.h" #include "perfetto/protozero/proto_decoder.h" #include "perfetto/protozero/proto_utils.h" diff --git a/src/protozero/filtering/filter_bytecode_parser_unittest.cc b/src/protozero/filtering/filter_bytecode_parser_unittest.cc index a44cfd66a8c..f645840cf11 100644 --- a/src/protozero/filtering/filter_bytecode_parser_unittest.cc +++ b/src/protozero/filtering/filter_bytecode_parser_unittest.cc @@ -20,6 +20,7 @@ #include #include +#include "perfetto/ext/base/endian.h" #include "perfetto/ext/base/fnv_hash.h" #include "perfetto/protozero/packed_repeated_fields.h" #include "perfetto/protozero/proto_utils.h" diff --git a/src/protozero/filtering/message_filter.cc b/src/protozero/filtering/message_filter.cc index f54035f2bb2..17d781c6814 100644 --- a/src/protozero/filtering/message_filter.cc +++ b/src/protozero/filtering/message_filter.cc @@ -17,6 +17,7 @@ #include "src/protozero/filtering/message_filter.h" #include "perfetto/base/logging.h" +#include "perfetto/ext/base/endian.h" #include "perfetto/protozero/proto_utils.h" #include "src/protozero/filtering/string_filter.h" From cfa0c8b142095f0d95b34f641f3da13c0baf7e9b Mon Sep 17 00:00:00 2001 From: Milad Fa Date: Fri, 25 Sep 2026 19:27:06 +0000 Subject: [PATCH 7/8] update --- BUILD | 2 +- include/perfetto/base/BUILD.gn | 1 + include/perfetto/{ext => }/base/endian.h | 6 +++--- include/perfetto/ext/base/BUILD.gn | 1 - include/perfetto/ext/base/uuid.h | 2 +- include/perfetto/protozero/message.h | 2 +- include/perfetto/protozero/packed_repeated_fields.h | 2 +- include/perfetto/protozero/proto_decoder.h | 2 +- src/base/http/http_server.cc | 2 +- src/protozero/field.cc | 2 +- src/protozero/filtering/filter_bytecode_generator.cc | 2 +- src/protozero/filtering/filter_bytecode_parser.cc | 2 +- src/protozero/filtering/filter_bytecode_parser_unittest.cc | 2 +- src/protozero/filtering/message_filter.cc | 2 +- .../core/interpreter/bytecode_interpreter_impl.h | 2 +- src/trace_processor/core/util/sort.h | 2 +- src/trace_processor/core/util/sort_unittest.cc | 2 +- .../importers/art_hprof/art_heap_graph_builder.cc | 2 +- .../importers/art_hprof/art_heap_graph_builder.h | 2 +- src/trace_processor/importers/art_hprof/art_hprof_parser.cc | 2 +- src/trace_processor/plugins/flamegraph/flamegraph.cc | 2 +- 21 files changed, 22 insertions(+), 22 deletions(-) rename include/perfetto/{ext => }/base/endian.h (97%) diff --git a/BUILD b/BUILD index 9653a0310c9..5b544a0471e 100644 --- a/BUILD +++ b/BUILD @@ -1379,6 +1379,7 @@ perfetto_filegroup( srcs = [ "include/perfetto/base/build_config.h", "include/perfetto/base/compiler.h", + "include/perfetto/base/endian.h", "include/perfetto/base/export.h", "include/perfetto/base/flat_set.h", "include/perfetto/base/logging.h", @@ -1417,7 +1418,6 @@ perfetto_filegroup( "include/perfetto/ext/base/crash_keys.h", "include/perfetto/ext/base/ctrl_c_handler.h", "include/perfetto/ext/base/dynamic_string_writer.h", - "include/perfetto/ext/base/endian.h", "include/perfetto/ext/base/event_fd.h", "include/perfetto/ext/base/file_utils.h", "include/perfetto/ext/base/flags.h", diff --git a/include/perfetto/base/BUILD.gn b/include/perfetto/base/BUILD.gn index 1fa5c9d536f..79c438c0721 100644 --- a/include/perfetto/base/BUILD.gn +++ b/include/perfetto/base/BUILD.gn @@ -18,6 +18,7 @@ source_set("base") { sources = [ "build_config.h", "compiler.h", + "endian.h", "export.h", "flat_set.h", "logging.h", diff --git a/include/perfetto/ext/base/endian.h b/include/perfetto/base/endian.h similarity index 97% rename from include/perfetto/ext/base/endian.h rename to include/perfetto/base/endian.h index 6bf1724dafe..269e9971dd0 100644 --- a/include/perfetto/ext/base/endian.h +++ b/include/perfetto/base/endian.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef INCLUDE_PERFETTO_EXT_BASE_ENDIAN_H_ -#define INCLUDE_PERFETTO_EXT_BASE_ENDIAN_H_ +#ifndef INCLUDE_PERFETTO_BASE_ENDIAN_H_ +#define INCLUDE_PERFETTO_BASE_ENDIAN_H_ #include #include // For MSVC @@ -246,4 +246,4 @@ inline double LEToHost(double x) { } // namespace base } // namespace perfetto -#endif // INCLUDE_PERFETTO_EXT_BASE_ENDIAN_H_ +#endif // INCLUDE_PERFETTO_BASE_ENDIAN_H_ diff --git a/include/perfetto/ext/base/BUILD.gn b/include/perfetto/ext/base/BUILD.gn index 653908960ab..b543f0784f8 100644 --- a/include/perfetto/ext/base/BUILD.gn +++ b/include/perfetto/ext/base/BUILD.gn @@ -27,7 +27,6 @@ source_set("base") { "crash_keys.h", "ctrl_c_handler.h", "dynamic_string_writer.h", - "endian.h", "event_fd.h", "file_utils.h", "flags.h", diff --git a/include/perfetto/ext/base/uuid.h b/include/perfetto/ext/base/uuid.h index 5b3d1a8e7d8..dd5b6f81d24 100644 --- a/include/perfetto/ext/base/uuid.h +++ b/include/perfetto/ext/base/uuid.h @@ -22,8 +22,8 @@ #include #include +#include "perfetto/base/endian.h" #include "perfetto/base/export.h" -#include "perfetto/ext/base/endian.h" namespace perfetto { namespace base { diff --git a/include/perfetto/protozero/message.h b/include/perfetto/protozero/message.h index faf9680ad8a..55ed0531f2f 100644 --- a/include/perfetto/protozero/message.h +++ b/include/perfetto/protozero/message.h @@ -24,9 +24,9 @@ #include #include +#include "perfetto/base/endian.h" #include "perfetto/base/export.h" #include "perfetto/base/logging.h" -#include "perfetto/ext/base/endian.h" // no-include-violation-check #include "perfetto/protozero/contiguous_memory_range.h" #include "perfetto/protozero/proto_utils.h" #include "perfetto/protozero/scattered_stream_writer.h" diff --git a/include/perfetto/protozero/packed_repeated_fields.h b/include/perfetto/protozero/packed_repeated_fields.h index 001522f1348..ed5ada6e867 100644 --- a/include/perfetto/protozero/packed_repeated_fields.h +++ b/include/perfetto/protozero/packed_repeated_fields.h @@ -23,8 +23,8 @@ #include #include +#include "perfetto/base/endian.h" #include "perfetto/base/logging.h" -#include "perfetto/ext/base/endian.h" // no-include-violation-check #include "perfetto/protozero/proto_utils.h" namespace protozero { diff --git a/include/perfetto/protozero/proto_decoder.h b/include/perfetto/protozero/proto_decoder.h index 1f8bae398af..dd57983eb55 100644 --- a/include/perfetto/protozero/proto_decoder.h +++ b/include/perfetto/protozero/proto_decoder.h @@ -27,9 +27,9 @@ #include #include +#include "perfetto/base/endian.h" #include "perfetto/base/export.h" #include "perfetto/base/logging.h" -#include "perfetto/ext/base/endian.h" // no-include-violation-check #include "perfetto/protozero/field.h" #include "perfetto/protozero/proto_utils.h" #include "perfetto/public/compiler.h" diff --git a/src/base/http/http_server.cc b/src/base/http/http_server.cc index f6c8c398f49..2ab9707a217 100644 --- a/src/base/http/http_server.cc +++ b/src/base/http/http_server.cc @@ -30,9 +30,9 @@ #include #include +#include "perfetto/base/endian.h" #include "perfetto/base/logging.h" #include "perfetto/ext/base/base64.h" -#include "perfetto/ext/base/endian.h" #include "perfetto/ext/base/http/sha1.h" #include "perfetto/ext/base/paged_memory.h" #include "perfetto/ext/base/string_utils.h" diff --git a/src/protozero/field.cc b/src/protozero/field.cc index 3ce22341afe..d6189e35338 100644 --- a/src/protozero/field.cc +++ b/src/protozero/field.cc @@ -17,8 +17,8 @@ #include "perfetto/protozero/field.h" #include "perfetto/base/compiler.h" +#include "perfetto/base/endian.h" #include "perfetto/base/logging.h" -#include "perfetto/ext/base/endian.h" namespace protozero { diff --git a/src/protozero/filtering/filter_bytecode_generator.cc b/src/protozero/filtering/filter_bytecode_generator.cc index 6936bed242b..59583b0f0ee 100644 --- a/src/protozero/filtering/filter_bytecode_generator.cc +++ b/src/protozero/filtering/filter_bytecode_generator.cc @@ -20,8 +20,8 @@ #include #include +#include "perfetto/base/endian.h" #include "perfetto/base/logging.h" -#include "perfetto/ext/base/endian.h" #include "perfetto/ext/base/fnv_hash.h" #include "perfetto/protozero/packed_repeated_fields.h" #include "perfetto/protozero/proto_utils.h" diff --git a/src/protozero/filtering/filter_bytecode_parser.cc b/src/protozero/filtering/filter_bytecode_parser.cc index 37bbe2e5a13..ec11410a62b 100644 --- a/src/protozero/filtering/filter_bytecode_parser.cc +++ b/src/protozero/filtering/filter_bytecode_parser.cc @@ -22,8 +22,8 @@ #include #include +#include "perfetto/base/endian.h" #include "perfetto/base/logging.h" -#include "perfetto/ext/base/endian.h" #include "perfetto/ext/base/fnv_hash.h" #include "perfetto/protozero/proto_decoder.h" #include "perfetto/protozero/proto_utils.h" diff --git a/src/protozero/filtering/filter_bytecode_parser_unittest.cc b/src/protozero/filtering/filter_bytecode_parser_unittest.cc index f645840cf11..a166bd88b10 100644 --- a/src/protozero/filtering/filter_bytecode_parser_unittest.cc +++ b/src/protozero/filtering/filter_bytecode_parser_unittest.cc @@ -20,7 +20,7 @@ #include #include -#include "perfetto/ext/base/endian.h" +#include "perfetto/base/endian.h" #include "perfetto/ext/base/fnv_hash.h" #include "perfetto/protozero/packed_repeated_fields.h" #include "perfetto/protozero/proto_utils.h" diff --git a/src/protozero/filtering/message_filter.cc b/src/protozero/filtering/message_filter.cc index 17d781c6814..910a889c337 100644 --- a/src/protozero/filtering/message_filter.cc +++ b/src/protozero/filtering/message_filter.cc @@ -16,8 +16,8 @@ #include "src/protozero/filtering/message_filter.h" +#include "perfetto/base/endian.h" #include "perfetto/base/logging.h" -#include "perfetto/ext/base/endian.h" #include "perfetto/protozero/proto_utils.h" #include "src/protozero/filtering/string_filter.h" diff --git a/src/trace_processor/core/interpreter/bytecode_interpreter_impl.h b/src/trace_processor/core/interpreter/bytecode_interpreter_impl.h index 6de62ddd344..2734b5e7eae 100644 --- a/src/trace_processor/core/interpreter/bytecode_interpreter_impl.h +++ b/src/trace_processor/core/interpreter/bytecode_interpreter_impl.h @@ -30,8 +30,8 @@ #include #include "perfetto/base/compiler.h" +#include "perfetto/base/endian.h" #include "perfetto/base/logging.h" -#include "perfetto/ext/base/endian.h" #include "perfetto/ext/base/flat_hash_map.h" #include "perfetto/ext/base/string_view.h" #include "perfetto/ext/base/variant.h" diff --git a/src/trace_processor/core/util/sort.h b/src/trace_processor/core/util/sort.h index 76676bb618f..2641f0381b2 100644 --- a/src/trace_processor/core/util/sort.h +++ b/src/trace_processor/core/util/sort.h @@ -25,7 +25,7 @@ #include #include -#include "perfetto/ext/base/endian.h" +#include "perfetto/base/endian.h" namespace perfetto::trace_processor::core { namespace internal { diff --git a/src/trace_processor/core/util/sort_unittest.cc b/src/trace_processor/core/util/sort_unittest.cc index da73ae83e44..254446dc124 100644 --- a/src/trace_processor/core/util/sort_unittest.cc +++ b/src/trace_processor/core/util/sort_unittest.cc @@ -21,7 +21,7 @@ #include #include -#include "perfetto/ext/base/endian.h" +#include "perfetto/base/endian.h" #include "perfetto/ext/base/string_utils.h" #include "test/gtest_and_gmock.h" diff --git a/src/trace_processor/importers/art_hprof/art_heap_graph_builder.cc b/src/trace_processor/importers/art_hprof/art_heap_graph_builder.cc index baca8eed531..082272acd41 100644 --- a/src/trace_processor/importers/art_hprof/art_heap_graph_builder.cc +++ b/src/trace_processor/importers/art_hprof/art_heap_graph_builder.cc @@ -17,7 +17,7 @@ #include "src/trace_processor/importers/art_hprof/art_heap_graph_builder.h" #include #include -#include "perfetto/ext/base/endian.h" +#include "perfetto/base/endian.h" #include "perfetto/trace_processor/trace_blob.h" #include "src/trace_processor/importers/common/stats_tracker.h" diff --git a/src/trace_processor/importers/art_hprof/art_heap_graph_builder.h b/src/trace_processor/importers/art_hprof/art_heap_graph_builder.h index 27cc8267a3f..fe4064357c7 100644 --- a/src/trace_processor/importers/art_hprof/art_heap_graph_builder.h +++ b/src/trace_processor/importers/art_hprof/art_heap_graph_builder.h @@ -17,7 +17,7 @@ #ifndef SRC_TRACE_PROCESSOR_IMPORTERS_ART_HPROF_ART_HEAP_GRAPH_BUILDER_H_ #define SRC_TRACE_PROCESSOR_IMPORTERS_ART_HPROF_ART_HEAP_GRAPH_BUILDER_H_ -#include "perfetto/ext/base/endian.h" +#include "perfetto/base/endian.h" #include "perfetto/ext/base/flat_hash_map.h" #include "perfetto/trace_processor/trace_blob_view.h" #include "src/trace_processor/importers/art_hprof/art_heap_graph.h" diff --git a/src/trace_processor/importers/art_hprof/art_hprof_parser.cc b/src/trace_processor/importers/art_hprof/art_hprof_parser.cc index 042b044c914..7eac976e651 100644 --- a/src/trace_processor/importers/art_hprof/art_hprof_parser.cc +++ b/src/trace_processor/importers/art_hprof/art_hprof_parser.cc @@ -27,8 +27,8 @@ #include #include +#include "perfetto/base/endian.h" #include "perfetto/base/status.h" -#include "perfetto/ext/base/endian.h" #include "perfetto/ext/base/flat_hash_map.h" #include "perfetto/ext/base/murmur_hash.h" #include "perfetto/ext/base/string_view.h" diff --git a/src/trace_processor/plugins/flamegraph/flamegraph.cc b/src/trace_processor/plugins/flamegraph/flamegraph.cc index f6bb89b79f6..936577b3ed6 100644 --- a/src/trace_processor/plugins/flamegraph/flamegraph.cc +++ b/src/trace_processor/plugins/flamegraph/flamegraph.cc @@ -27,9 +27,9 @@ #include #include +#include "perfetto/base/endian.h" #include "perfetto/base/logging.h" #include "perfetto/base/status.h" -#include "perfetto/ext/base/endian.h" #include "perfetto/ext/base/flat_hash_map.h" #include "perfetto/ext/base/hash.h" #include "perfetto/ext/base/murmur_hash.h" From 81239d9a150752aade48c96cdbfa21b59e9a66b0 Mon Sep 17 00:00:00 2001 From: Milad Fa Date: Fri, 25 Sep 2026 19:53:51 +0000 Subject: [PATCH 8/8] update --- BUILD | 3 --- include/perfetto/protozero/BUILD.gn | 1 - 2 files changed, 4 deletions(-) diff --git a/BUILD b/BUILD index 5b544a0471e..7b2a3966d86 100644 --- a/BUILD +++ b/BUILD @@ -147,7 +147,6 @@ perfetto_cc_library( ], hdrs = [ ":include_perfetto_base_base", - ":include_perfetto_ext_base_base", ":include_perfetto_protozero_protozero", ":include_perfetto_public_abi_base", ":include_perfetto_public_base", @@ -1142,7 +1141,6 @@ perfetto_cc_binary( name = "client_api_example", srcs = [ ":include_perfetto_base_base", - ":include_perfetto_ext_base_base", ":include_perfetto_protozero_protozero", ":include_perfetto_public_abi_base", ":include_perfetto_public_base", @@ -2484,7 +2482,6 @@ perfetto_cc_library( ], hdrs = [ ":include_perfetto_base_base", - ":include_perfetto_ext_base_base", ":include_perfetto_protozero_protozero", ":include_perfetto_public_abi_base", ":include_perfetto_public_base", diff --git a/include/perfetto/protozero/BUILD.gn b/include/perfetto/protozero/BUILD.gn index 3a1f9ef0c4f..60d6b1ae50f 100644 --- a/include/perfetto/protozero/BUILD.gn +++ b/include/perfetto/protozero/BUILD.gn @@ -15,7 +15,6 @@ source_set("protozero") { public_deps = [ "../base", - "../ext/base", "../public:protozero", ] sources = [