The current version of perf detects whether or not the perf.data file iswritten in a different endianness using the attr_size field in theheader of the file. This field represents sizeof(struct perf_event_attr)as known to perf record. If the sizes do not match, then perf tries thebyte-swapped version. If they match, then the tool assumes a differentendianness.

The issue with the approach is that it assumes the size ofperf_event_attr always has to match between perf record and perf report.However, the kernel perf_event ABI is extensible. New fields can beadded to struct perf_event_attr. Consequently, it is not possible to useattr_size to detect endianness.

This patch takes another approach by using the magic number written atthe beginning of the perf.data file to detect endianness. The magicnumber is an eight-byte signature. It's primary purpose is to identify(signature) a perf.data file. But it could also be used to encode theendianness.

The patch introduces a new value for this signature. The key differenceis that the signature is written differently in the file depending onthe endianness. Thus, by comparing the signature from the file with thetool's own signature it is possible to detect endianness. The newsignature is "PERFILE2".