Commit 522b861
committed
[BPF] fix print_btf.py test script on bigendian machines
Make print_btf.py correctly detect endianness of the BTF input.
Input endianness is inferred from BTF magic word [2], which is a
2-byte integer at offset 0 of the input:
- sequence `EB 9F` signals big-endian input;
- sequence `9F EB` signals little-endian input.
Before this commit the magic sequence was read using "H" format for
`unpack` method of python's `struct` module:
- if magic is `0xEB9F` assume little-endian;
- if magic is `0x9FEB` assume big-endian.
However, format `H` reads data in native endianness.
Thus the above logic would only be correct on little endian hosts:
- byte sequence `9F EB` read as `0xEB9F` -> little-endian input;
- byte sequence `EB 9F` read as `0x9FEB` -> big-endian input.
On the big-endian host the relation should be inverse.
Fix this by always reading magic in big-endian (format `>H`).
This fixes CI error reported for a BPF test using print_btf.py script
in [1]. The error happens on a s390 host, which is big-endian.
[1] https://lab.llvm.org/buildbot/#/builders/42/builds/1192
[2] https://www.kernel.org/doc/html/latest/bpf/btf.html#btf-type-and-string-encoding1 parent 7883b02 commit 522b861
1 file changed
+4
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | | - | |
| 107 | + | |
108 | 108 | | |
109 | | - | |
| 109 | + | |
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
| |||
290 | 290 | | |
291 | 291 | | |
292 | 292 | | |
293 | | - | |
| 293 | + | |
294 | 294 | | |
295 | 295 | | |
0 commit comments