[llvm] 3c191d6 - [ObjectYAML] Fix yaml2obj crash when BBAddrMap entry has invalid feature (#201729)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 9 23:18:21 PDT 2026
Author: Haohai Wen
Date: 2026-06-10T14:18:16+08:00
New Revision: 3c191d65110b5f54faf68d8438a9d989a1ef133d
URL: https://github.com/llvm/llvm-project/commit/3c191d65110b5f54faf68d8438a9d989a1ef133d
DIFF: https://github.com/llvm/llvm-project/commit/3c191d65110b5f54faf68d8438a9d989a1ef133d.diff
LOG: [ObjectYAML] Fix yaml2obj crash when BBAddrMap entry has invalid feature (#201729)
Warn and skip the entry instead of dereferencing the Error-holding
Expected returned by Features::decode.
Added:
Modified:
llvm/lib/ObjectYAML/ELFEmitter.cpp
llvm/test/tools/yaml2obj/ELF/bb-addr-map-pgo-analysis-map.yaml
Removed:
################################################################################
diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp
index b60b27ff6f082..f4552f0a8f49b 100644
--- a/llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -1480,11 +1480,12 @@ void ELFState<ELFT>::writeSectionContent(
}
}
auto FeatureOrErr = llvm::object::BBAddrMap::Features::decode(E.Feature);
- bool MultiBBRangeFeatureEnabled = false;
- if (!FeatureOrErr)
+ if (!FeatureOrErr) {
+ // Invalid feature: warn and skip the entry.
WithColor::warning() << toString(FeatureOrErr.takeError());
- else
- MultiBBRangeFeatureEnabled = FeatureOrErr->MultiBBRange;
+ continue;
+ }
+ bool MultiBBRangeFeatureEnabled = FeatureOrErr->MultiBBRange;
bool MultiBBRange =
MultiBBRangeFeatureEnabled ||
(E.NumBBRanges.has_value() && E.NumBBRanges.value() != 1) ||
diff --git a/llvm/test/tools/yaml2obj/ELF/bb-addr-map-pgo-analysis-map.yaml b/llvm/test/tools/yaml2obj/ELF/bb-addr-map-pgo-analysis-map.yaml
index ac9c8d402b0a6..0fe707c15ab32 100644
--- a/llvm/test/tools/yaml2obj/ELF/bb-addr-map-pgo-analysis-map.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/bb-addr-map-pgo-analysis-map.yaml
@@ -67,9 +67,16 @@ Sections:
Size: 0x00000002
Metadata: 0x00000003
-## Check that yaml2obj generates a warning when we use unsupported feature.
-# RUN: yaml2obj --docnum=2 %s 2>&1 | FileCheck %s --check-prefix=INVALID-FEATURE
+## An invalid feature warns and skips the entry: only the version and feature
+## bytes are emitted, even when BBRanges/PGOAnalyses follow.
+# RUN: yaml2obj --docnum=2 %s -o %t2 2>&1 | FileCheck %s --check-prefix=INVALID-FEATURE
+# RUN: llvm-readobj --sections --section-data %t2 | FileCheck %s --check-prefix=INVALID-FEATURE-DATA
# INVALID-FEATURE: warning: invalid encoding for BBAddrMap::Features: 0x100
+# INVALID-FEATURE-DATA: Name: .llvm_bb_addr_map
+# INVALID-FEATURE-DATA: Size: 3
+# INVALID-FEATURE-DATA: SectionData (
+# INVALID-FEATURE-DATA-NEXT: 0000: 050001 {{ *}}|
+# INVALID-FEATURE-DATA-NEXT: )
--- !ELF
FileHeader:
@@ -80,6 +87,17 @@ Sections:
- Name: '.llvm_bb_addr_map'
Type: SHT_LLVM_BB_ADDR_MAP
Entries:
- - Version: 2
+ - Version: 5
## Specify unsupported feature
Feature: 0x100
+ BBRanges:
+ - BaseAddress: 0x0000000000000020
+ BBEntries:
+ - ID: 1
+ AddressOffset: 0x00000001
+ Size: 0x00000002
+ Metadata: 0x00000003
+ PGOAnalyses:
+ - FuncEntryCount: 100
+ PGOBBEntries:
+ - BBFreq: 100
More information about the llvm-commits
mailing list