[llvm] [ObjectYAML][NFC] Make BBAddrMap encoder diagnostics format-neutral (PR #202524)

Haohai Wen via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 9 23:18:56 PDT 2026


https://github.com/HaohaiWen updated https://github.com/llvm/llvm-project/pull/202524

>From bca4d3951712610d424e869bb9a1cd2da9b29084 Mon Sep 17 00:00:00 2001
From: Haohai Wen <haohai.wen at intel.com>
Date: Tue, 9 Jun 2026 15:02:44 +0800
Subject: [PATCH] [ObjectYAML][NFC] Make BBAddrMap encoder diagnostics
 format-neutral

In preparation for sharing the yaml2obj BBAddrMap encoder with COFF.
1. Drop the now-dead `Section.Type == SHT_LLVM_BB_ADDR_MAP` guards.
2. Reword the two warnings that will move into the shared helper.
3. Fix a "PBOBBEntries" -> "PGOBBEntries" typo.
---
 llvm/lib/ObjectYAML/ELFEmitter.cpp            | 30 +++++++++----------
 llvm/test/tools/yaml2obj/ELF/bb-addr-map.yaml |  2 +-
 2 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp
index b60b27ff6f082..0825bbe7a98af 100644
--- a/llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -1464,20 +1464,18 @@ void ELFState<ELFT>::writeSectionContent(
 
   for (const auto &[Idx, E] : llvm::enumerate(*Section.Entries)) {
     // Write version and feature values.
-    if (Section.Type == llvm::ELF::SHT_LLVM_BB_ADDR_MAP) {
-      if (E.Version > 5)
-        WithColor::warning() << "unsupported SHT_LLVM_BB_ADDR_MAP version: "
-                             << static_cast<int>(E.Version)
-                             << "; encoding using the most recent version";
-      CBA.write(E.Version);
+    if (E.Version > 5)
+      WithColor::warning() << "unsupported BB address map version: "
+                           << static_cast<int>(E.Version)
+                           << "; encoding using the most recent version";
+    CBA.write(E.Version);
+    SHeader.sh_size += 1;
+    if (E.Version < 5) {
+      CBA.write(static_cast<uint8_t>(E.Feature));
       SHeader.sh_size += 1;
-      if (E.Version < 5) {
-        CBA.write(static_cast<uint8_t>(E.Feature));
-        SHeader.sh_size += 1;
-      } else {
-        CBA.write<uint16_t>(E.Feature, ELFT::Endianness);
-        SHeader.sh_size += 2;
-      }
+    } else {
+      CBA.write<uint16_t>(E.Feature, ELFT::Endianness);
+      SHeader.sh_size += 2;
     }
     auto FeatureOrErr = llvm::object::BBAddrMap::Features::decode(E.Feature);
     bool MultiBBRangeFeatureEnabled = false;
@@ -1518,7 +1516,7 @@ void ELFState<ELFT>::writeSectionContent(
         continue;
       for (const BBAddrMapYAML::BBAddrMapEntry::BBEntry &BBE : *BBR.BBEntries) {
         ++TotalNumBlocks;
-        if (Section.Type == llvm::ELF::SHT_LLVM_BB_ADDR_MAP && E.Version > 1)
+        if (E.Version > 1)
           SHeader.sh_size += CBA.writeULEB128(BBE.ID);
         SHeader.sh_size += CBA.writeULEB128(BBE.AddressOffset);
         if (EmitCallsiteEndOffsets) {
@@ -1552,8 +1550,8 @@ void ELFState<ELFT>::writeSectionContent(
 
     const auto &PGOBBEntries = PGOEntry.PGOBBEntries.value();
     if (TotalNumBlocks != PGOBBEntries.size()) {
-      WithColor::warning() << "PBOBBEntries must be the same length as "
-                              "BBEntries in SHT_LLVM_BB_ADDR_MAP.\n"
+      WithColor::warning() << "PGOBBEntries must be the same length as "
+                              "BBEntries in the BB address map.\n"
                            << "Mismatch on function with address: "
                            << E.getFunctionAddress();
       continue;
diff --git a/llvm/test/tools/yaml2obj/ELF/bb-addr-map.yaml b/llvm/test/tools/yaml2obj/ELF/bb-addr-map.yaml
index 05d77d67e4468..2b2fd43b243d9 100644
--- a/llvm/test/tools/yaml2obj/ELF/bb-addr-map.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/bb-addr-map.yaml
@@ -220,7 +220,7 @@ Sections:
 
 ## Check that yaml2obj generates a warning when we use unsupported versions.
 # RUN: yaml2obj --docnum=3  %s 2>&1 | FileCheck %s --check-prefix=INVALID-VERSION
-# INVALID-VERSION: warning: unsupported SHT_LLVM_BB_ADDR_MAP version: 6; encoding using the most recent version
+# INVALID-VERSION: warning: unsupported BB address map version: 6; encoding using the most recent version
 
 --- !ELF
 FileHeader:



More information about the llvm-commits mailing list