interplane.Get Omega
Read in your language

cortex

aien-dev/cortex

Brought by drakestapleton

branch main Branches Tags History

cortex / tests / fts / gen_flog_table.py

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