[BOLT][merge-fdata] Initialize YAML profile header (#109613)
While merging profiles, some fields in the input header, e.g. HashFunction, could be uninitialized leading to a UMR. Initialize merged header with the first input header. Fixes #109592
This commit is contained in:
parent
924b3904b7
commit
6fb39ac77b
45
bolt/test/merge-fdata-uninitialized-header.test
Normal file
45
bolt/test/merge-fdata-uninitialized-header.test
Normal file
@ -0,0 +1,45 @@
|
||||
## Test that merge-fdata correctly handles YAML header with an uninitialized
|
||||
## fields. a.yaml does not have hash-func set and it used to crash merge-fdata.
|
||||
|
||||
# REQUIRES: system-linux
|
||||
|
||||
# RUN: split-file %s %t
|
||||
# RUN: not merge-fdata %t/a.yaml %t/b.yaml 2>&1 | FileCheck %s
|
||||
|
||||
# CHECK: cannot merge profiles with different hash functions
|
||||
|
||||
#--- a.yaml
|
||||
---
|
||||
header:
|
||||
profile-version: 1
|
||||
binary-name: 'a.out'
|
||||
binary-build-id: '<unknown>'
|
||||
profile-flags: [ lbr ]
|
||||
profile-origin: branch profile reader
|
||||
profile-events: ''
|
||||
dfs-order: false
|
||||
functions:
|
||||
- name: 'main'
|
||||
fid: 1
|
||||
hash: 0x50BBA3441D436491
|
||||
exec: 1
|
||||
nblocks: 0
|
||||
...
|
||||
#--- b.yaml
|
||||
---
|
||||
header:
|
||||
profile-version: 1
|
||||
binary-name: 'a.out'
|
||||
binary-build-id: '<unknown>'
|
||||
profile-flags: [ lbr ]
|
||||
profile-origin: branch profile reader
|
||||
profile-events: ''
|
||||
dfs-order: false
|
||||
hash-func: xxh3
|
||||
functions:
|
||||
- name: 'main'
|
||||
fid: 1
|
||||
hash: 0x50BBA3441D436491
|
||||
exec: 1
|
||||
nblocks: 0
|
||||
...
|
@ -145,6 +145,10 @@ void mergeProfileHeaders(BinaryProfileHeader &MergedHeader,
|
||||
errs() << "WARNING: merging profiles with different sampling events\n";
|
||||
MergedHeader.EventNames += "," + Header.EventNames;
|
||||
}
|
||||
|
||||
if (MergedHeader.HashFunction != Header.HashFunction)
|
||||
report_error("merge conflict",
|
||||
"cannot merge profiles with different hash functions");
|
||||
}
|
||||
|
||||
void mergeBasicBlockProfile(BinaryBasicBlockProfile &MergedBB,
|
||||
@ -386,6 +390,7 @@ int main(int argc, char **argv) {
|
||||
// Merged information for all functions.
|
||||
StringMap<BinaryFunctionProfile> MergedBFs;
|
||||
|
||||
bool FirstHeader = true;
|
||||
for (std::string &InputDataFilename : Inputs) {
|
||||
ErrorOr<std::unique_ptr<MemoryBuffer>> MB =
|
||||
MemoryBuffer::getFileOrSTDIN(InputDataFilename);
|
||||
@ -409,7 +414,12 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
// Merge the header.
|
||||
if (FirstHeader) {
|
||||
MergedHeader = BP.Header;
|
||||
FirstHeader = false;
|
||||
} else {
|
||||
mergeProfileHeaders(MergedHeader, BP.Header);
|
||||
}
|
||||
|
||||
// Do the function merge.
|
||||
for (BinaryFunctionProfile &BF : BP.Functions) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user