cortex
aien-dev/cortex
Brought by drakestapleton
cortex / tests / fts / gen_flog_table.py
| 1 | #!/usr/bin/env python3 |
| 2 | """Generator (not product code) for the data table in om/flog.om. |
| 3 | |
| 4 | Reads the 274 doubles of glibc 2.39's __log_data (ln2hi, ln2lo, poly[5], poly1[11], |
| 5 | tab[128]{invc,logc}) out of the exact libm.so.6 the Rust cortex-rs binary links on this |
| 6 | machine, at the address its `log` code loads them from (vaddr 0x78880, see disassembly of |
| 7 | log@@GLIBC_2.29 in evidence/fts/glibc-log.dis), and prints them as one Omega text literal |
| 8 | of decimal u64 bit patterns. |
| 9 | |
| 10 | Usage: python3 tests/fts/gen_flog_table.py [/usr/lib/aarch64-linux-gnu/libm.so.6] |
| 11 | """ |
| 12 | import hashlib, struct, sys |
| 13 | |
| 14 | path = sys.argv[1] if len(sys.argv) > 1 else '/usr/lib/aarch64-linux-gnu/libm.so.6' |
| 15 | blob = open(path, 'rb').read() |
| 16 | VA = 0x78880 |
| 17 | phoff = struct.unpack_from('<Q', blob, 0x20)[0] |
| 18 | phentsize, phnum = struct.unpack_from('<HH', blob, 0x36) |
| 19 | for i in range(phnum): |
| 20 | p_type, _f, p_off, p_va, _pa, p_fsz, _msz, _al = struct.unpack_from('<IIQQQQQQ', blob, phoff + i * phentsize) |
| 21 | if p_type == 1 and p_va <= VA < p_va + p_fsz: |
| 22 | vals = struct.unpack_from('<274Q', blob, p_off + VA - p_va) |
| 23 | break |
| 24 | else: |
| 25 | sys.exit('address not mapped') |
| 26 | assert vals[0] == 0x3fe62e42fefa3800 and vals[7] == 0xbfe0000000000000, 'unexpected __log_data layout' |
| 27 | print('note generated by tests/fts/gen_flog_table.py from %s sha256 %s' % (path, hashlib.sha256(blob).hexdigest())) |
| 28 | print('text qlgx "' + ' '.join(str(v) for v in vals) + '"') |