From 69a1888fd587410cc6a4d857d2ad7815e5aad93e Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Mon, 24 Jun 2024 13:19:25 -0700 Subject: [PATCH] Bugfix: do not tree shake map entry messages. Since maps have a different in-memory representation than repeated messages, it is not safe to tree shake map entry messages. Specifically, map fields use `kUpb_FieldMode_Map` instead of `kUpb_FieldMode_Array`, and there is no easy way to get the linker to rewrite this when the map entry is dropped. However it is safe to tree shake message typed map values, since these use `kUpb_FieldMode_Scalar`, which remains valid even after the type is tree shaken. PiperOrigin-RevId: 646199050 --- upb_generator/protoc-gen-upb_minitable.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/upb_generator/protoc-gen-upb_minitable.cc b/upb_generator/protoc-gen-upb_minitable.cc index dbc959f82f..c5fffaed5c 100644 --- a/upb_generator/protoc-gen-upb_minitable.cc +++ b/upb_generator/protoc-gen-upb_minitable.cc @@ -364,7 +364,7 @@ void WriteMessage(upb::MessageDefPtr message, const DefPoolPair& pools, auto pair = subs.emplace(index, GetSub(field, false)); ABSL_CHECK(pair.second); if (options.one_output_per_message && field.IsSubMessage() && - IsCrossFile(field)) { + IsCrossFile(field) && !upb_MiniTableField_IsMap(f)) { if (seen.insert(pools.GetMiniTable64(field.message_type())).second) { output( "__attribute__((weak)) const upb_MiniTable* $0 ="