interplane.Get Omega
Read in your language

aien-architecture-mv

Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.

Brought by drakestapleton

branch main Branches Tags History

aien-architecture-mv / tools / zero-legacy / fixtures / elfgen.om

328 lines · 5843 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note elfgen: writes the synthetic ELF fixtures for the elfclose gate (#316 item 2, DRA-178).
3note usage: elfgen DIR (DIR must exist; writes the files named in tnm, 1024 bytes or less each)
4note Each file is a little ELF64 image with one property under test; see fixtures/elf.expected
5note for the row elfclose must print for each. None of them is executable code.
6
7text tnm "dyn-gcc\ndyn-nomark\nbadneed\nneed-nostr\nstrtab-unmapped\nbad-shstrndx\nstatic-rust\nclang-lld\nstatic-pie-go\nbare\ngnu-phdr\ntrunc\nbadph\nelf32\nbigend\nnotelf\nneed-inject\nneed-comma\ninterp-tab\ninterp-del\nload-wrap\nesc\tname\\x\n"
8text tsr "/lib/ld-linux-aarch64.so.1\nlibc.so.6\nlibm.so.6\nGCC: (Ubuntu 13.2.0) 13.2.0\nrustc version 1.98.1\nclang version 18.1.3\nLinker: LLD 18.1.3\n.comment\n.shstrtab\n.go.buildinfo\n#!/bin/sh\n"
9text tuse "usage: elfgen DIR\n"
10
11global ob uchar 1024
12global dir uchar 4096
13global dirn ulong 1
14global path uchar 4096
15
16fn clr to void
17for i ulong 1024
18put ob i 0
19end
20end
21
22fn w16 o ulong v ulong to void
23put ob o uchar and v 255
24put ob add o 1 uchar and shr v 8 255
25end
26
27fn w32 o ulong v ulong to void
28for i ulong 4
29put ob add o i uchar and shr v mul i 8 255
30end
31end
32
33fn w64 o ulong v ulong to void
34for i ulong 8
35put ob add o i uchar and shr v mul i 8 255
36end
37end
38
39note start of entry k of tsr
40fn sst k ulong to ulong
41s = ulong 0
42j = ulong 0
43while lt j k bound 4096
44if eq get tsr s 10
45j = add j 1
46end
47s = add s 1
48end
49ret s
50end
51
52note copy entry k of tsr to ob[o..], then a NUL; the entry length
53fn wstr o ulong k ulong to ulong
54s = sst k
55n = ulong 0
56while ne get tsr add s n 10 bound 256
57put ob add o n get tsr add s n
58n = add n 1
59end
60put ob add o n 0
61ret n
62end
63
64fn base ty ulong mach ulong phn ulong to void
65clr
66put ob 0 127
67put ob 1 69
68put ob 2 76
69put ob 3 70
70put ob 4 2
71put ob 5 1
72put ob 6 1
73w16 16 ty
74w16 18 mach
75w32 20 1
76w64 24 4096
77w64 32 64
78w16 52 64
79w16 54 56
80w16 56 phn
81end
82
83fn phd i ulong t ulong off ulong va ulong fz ulong to void
84b = add 64 mul i 56
85w32 b t
86w32 add b 4 5
87w64 add b 8 off
88w64 add b 16 va
89w64 add b 24 va
90w64 add b 32 fz
91w64 add b 40 fz
92w64 add b 48 8
93end
94
95fn dyn i ulong tag ulong v ulong to void
96b = add 544 mul i 16
97w64 b tag
98w64 add b 8 v
99end
100
101fn shd i ulong nm ulong t ulong off ulong sz ulong to void
102b = add 768 mul i 64
103w32 b nm
104w32 add b 4 t
105w64 add b 24 off
106w64 add b 32 sz
107w64 add b 48 1
108end
109
110note three sections: null, entry k of tsr at 672 (csz bytes), .shstrtab at 736
111fn secs3 k ulong csz ulong to void
112put ob 736 0
113a = wstr 737 k
114b = wstr add 738 a 8
115w64 40 768
116w16 58 64
117w16 60 3
118w16 62 2
119shd 1 1 1 672 csz
120shd 2 add a 2 3 736 add add a b 3
121end
122
123note write n bytes of ob to DIR/name, name = entry k of tnm
124fn save k ulong n ulong to bool
125d = get dirn 0
126for i ulong d
127put path i get dir i
128end
129put path d 47
130s = ulong 0
131j = ulong 0
132while lt j k bound 4096
133if eq get tnm s 10
134j = add j 1
135end
136s = add s 1
137end
138m = ulong 0
139while ne get tnm add s m 10 bound 64
140put path add add d 1 m get tnm add s m
141m = add m 1
142end
143fd = fopen path 0 add add d 1 m 577 420
144if lt fd 0
145ret false
146end
147r = write int fd ob 0 n
148c = fclose int fd
149ret eq r long n
150end
151
152fn dyngcc to void
153base 3 183 3
154phd 0 3 512 512 27
155a = wstr 512 0
156phd 1 1 0 65536 1024
157phd 2 2 544 544 80
158dyn 0 1 1
159dyn 1 1 11
160dyn 2 5 66160
161dyn 3 10 32
162dyn 4 0 0
163put ob 624 0
164b = wstr 625 1
165c = wstr 635 2
166d = wstr 672 3
167secs3 7 add d 1
168end
169
170fn bare to void
171base 2 183 1
172phd 0 1 0 0 1024
173end
174
175fn main to int
176if lt argcnt 2
177r = write 2 tuse 0 len tuse
178ret 64
179end
180n = argread 1 dir 0 4000
181if lt n 1
182ret 64
183end
184put dirn 0 ulong n
185ok = true
186dyngcc
187if not save 0 1024
188ok = false
189end
190note dyn-nomark: dyn-gcc without its section headers: no toolchain mark, but dynamic
191dyngcc
192w64 40 0
193w16 60 0
194w16 62 0
195if not save 1 1024
196ok = false
197end
198dyngcc
199dyn 0 1 9999
200if not save 2 1024
201ok = false
202end
203dyngcc
204dyn 2 0 0
205if not save 3 1024
206ok = false
207end
208dyngcc
209dyn 2 5 999999
210if not save 4 1024
211ok = false
212end
213dyngcc
214w16 62 3
215if not save 5 1024
216ok = false
217end
218base 2 62 1
219phd 0 1 0 4194304 1024
220a = wstr 672 4
221secs3 7 add a 1
222if not save 6 1024
223ok = false
224end
225base 2 183 1
226phd 0 1 0 0 1024
227a = wstr 672 5
228b = wstr add 673 a 6
229secs3 7 add add a b 2
230if not save 7 1024
231ok = false
232end
233base 3 183 2
234phd 0 1 0 0 1024
235phd 1 2 544 544 16
236dyn 0 0 0
237secs3 9 16
238if not save 8 1024
239ok = false
240end
241bare
242if not save 9 1024
243ok = false
244end
245base 2 183 2
246phd 0 1 0 0 1024
247phd 1 1685382481 0 0 0
248if not save 10 1024
249ok = false
250end
251bare
252if not save 11 40
253ok = false
254end
255bare
256put ob 32 240
257for i ulong 7
258put ob add 33 i 255
259end
260if not save 12 1024
261ok = false
262end
263bare
264put ob 4 1
265if not save 13 1024
266ok = false
267end
268bare
269put ob 5 2
270if not save 14 1024
271ok = false
272end
273clr
274a = wstr 0 10
275put ob a 10
276if not save 15 add a 1
277ok = false
278end
279note need-inject: dyn-gcc with its first DT_NEEDED name "libc.so.6" replaced by the 9 bytes
280note x, newline, E, L, F, tab, /, o, k: written raw it would end the row and forge an ELF row
281dyngcc
282put ob 625 120
283put ob 626 10
284put ob 627 69
285put ob 628 76
286put ob 629 70
287put ob 630 9
288put ob 631 47
289put ob 632 111
290put ob 633 107
291if not save 16 1024
292ok = false
293end
294note need-comma: "libc,so.6" would split into two names in the comma-separated field
295dyngcc
296put ob 629 44
297if not save 17 1024
298ok = false
299end
300note interp-tab and interp-del: a tab or a DEL inside the PT_INTERP path
301dyngcc
302put ob 516 9
303if not save 18 1024
304ok = false
305end
306dyngcc
307put ob 516 127
308if not save 19 1024
309ok = false
310end
311note load-wrap: the PT_LOAD file offset is 2^64-4096 and DT_STRTAB is 4720 past its vaddr, so
312note offset + (v - vaddr) wraps to 624, the real strtab; the PT_LOAD itself leaves the file
313dyngcc
314phd 1 1 sub ulong 0 4096 65536 8192
315dyn 2 5 70256
316if not save 20 1024
317ok = false
318end
319note esc<TAB>name\x: a clean ELF whose file name holds a tab and a backslash
320bare
321if not save 21 1024
322ok = false
323end
324if not ok
325ret 1
326end
327ret 0
328end