omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / bridge / cuda / fixture.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note bridge/cuda/fixture.om: the test inputs of the CUDA C0 admission check (bridge/cuda/c0_check.om), written in |
| 3 | note seeded Omega. It replaces three things CUDApp compat/cuda did with files and host tools: the committed PTX |
| 4 | note fixture (fixture/vadd_u32.ptx), the link-only stub libcuda.so.1 (build.sh: cc -shared -nostdlib with one |
| 5 | note -Wl,--defsym,cuX=0 per undefined cu* symbol) and, new here, an admission executable that carries exactly the |
| 6 | note dynamic surface the check reads, so the check can be exercised without a C toolchain. |
| 7 | note Build: seed/out/omc < bridge/cuda/fixture.om > fixture |
| 8 | note fixture ptx OUT the PTX kernel vadd_u32, byte for byte the CUDApp fixture |
| 9 | note fixture stub PROFILE OUT a link-only ELF64 shared object: soname = the profile's |
| 10 | note "needed NAME replacement" row, one absolute symbol (value 0) per |
| 11 | note "import NAME cuda" row, machine from the "host ISA" row |
| 12 | note fixture exe TABLE PROFILE full|nolib OUT |
| 13 | note an ELF64 ET_DYN whose .dynsym/.gnu.version_r/.dynamic hold the |
| 14 | note "import NAME global|weak", "verneed VERSION FILE" and "needed NAME" |
| 15 | note rows of TABLE in TABLE order (TABLE is c0_check emit output); |
| 16 | note nolib leaves out every import the profile classes "cuda" and every |
| 17 | note needed library it marks "replacement" (the C link with |
| 18 | note --unresolved-symbols=ignore-all and no libcuda.so.1) |
| 19 | note Neither ELF is ever run: the stub is a link-time placeholder, the executable a table the check reads. |
| 20 | note Exit 0 written, 1 a table without the rows the output needs, 2 usage, 3 an input unreadable or larger than |
| 21 | note the 16 MiB buffers, or an output that would be (every limit is a clean refusal, never a truncation). |
| 22 | om2 |
| 23 | const BIG ulong 16777216 |
| 24 | const ROWS ulong 2097152 |
| 25 | global ib uchar 16777216 |
| 26 | global ob uchar 16777216 |
| 27 | global gs uchar 16777216 |
| 28 | global ss uchar 128 |
| 29 | global ag uchar 4096 |
| 30 | global sy ulong 2097152 |
| 31 | global sb ulong 2097152 |
| 32 | global nd ulong 2097152 |
| 33 | global vf ulong 2097152 |
| 34 | global vc ulong 2097152 |
| 35 | global va ulong 2097152 |
| 36 | global hk ulong 2097152 |
| 37 | global bk ulong 17 |
| 38 | global fo ulong 8 |
| 39 | global fl ulong 8 |
| 40 | global nv ulong 64 |
| 41 | note nv: 0 table end, 1 profile start, 2 profile end, 3 dynstr length, 4 symbols, 5 needed, 6 verneed groups, |
| 42 | note 7 verneed versions, 8 machine, 9 soname offset, 10 mode (0 exe, 1 stub), 11 fields, 12 output length, |
| 43 | note 13 offset and 14 length of the current group's file field, 15 nolib |
| 44 | text m_ptx "ptx" |
| 45 | text m_stub "stub" |
| 46 | text m_exe "exe" |
| 47 | text m_full "full" |
| 48 | text m_nolib "nolib" |
| 49 | text k_imp "import" |
| 50 | text k_ver "verneed" |
| 51 | text k_need "needed" |
| 52 | text k_host "host" |
| 53 | text k_cuda "cuda" |
| 54 | text k_repl "replacement" |
| 55 | text k_glob "global" |
| 56 | text k_weak "weak" |
| 57 | text k_a64 "aarch64" |
| 58 | text k_x64 "x86_64" |
| 59 | text n_dynstr ".dynstr" |
| 60 | text n_dynsym ".dynsym" |
| 61 | text n_hash ".hash" |
| 62 | text n_vr ".gnu.version_r" |
| 63 | text n_dyn ".dynamic" |
| 64 | text n_shs ".shstrtab" |
| 65 | text p01 "// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\n" |
| 66 | text p02 "// CUDApp#184 C0 fixture kernel. Hand-authored from the public PTX ISA (PROVENANCE class A);\n" |
| 67 | text p03 "// this file is not compiler output. c[i] = a[i] + b[i] modulo 2^32 for i < n, nothing for i >= n.\n" |
| 68 | text p04 "// Parameters: three global-space byte addresses (u64) and the element count (u32).\n" |
| 69 | text p05 ".version 8.0\n" |
| 70 | text p06 ".target sm_80\n" |
| 71 | text p07 ".address_size 64\n" |
| 72 | text p08 "\n" |
| 73 | text p09 ".visible .entry vadd_u32(\n" |
| 74 | text p10 "\t.param .u64 vadd_u32_a,\n" |
| 75 | text p11 "\t.param .u64 vadd_u32_b,\n" |
| 76 | text p12 "\t.param .u64 vadd_u32_c,\n" |
| 77 | text p13 "\t.param .u32 vadd_u32_n\n" |
| 78 | text p14 ")\n" |
| 79 | text p15 "{\n" |
| 80 | text p16 "\t.reg .pred %p<2>;\n" |
| 81 | text p17 "\t.reg .b32 %r<8>;\n" |
| 82 | text p18 "\t.reg .b64 %rd<11>;\n" |
| 83 | text p19 "\n" |
| 84 | text p20 "\tld.param.u64 %rd1, [vadd_u32_a];\n" |
| 85 | text p21 "\tld.param.u64 %rd2, [vadd_u32_b];\n" |
| 86 | text p22 "\tld.param.u64 %rd3, [vadd_u32_c];\n" |
| 87 | text p23 "\tld.param.u32 %r1, [vadd_u32_n];\n" |
| 88 | text p24 "\tmov.u32 %r2, %ctaid.x;\n" |
| 89 | text p25 "\tmov.u32 %r3, %ntid.x;\n" |
| 90 | text p26 "\tmov.u32 %r4, %tid.x;\n" |
| 91 | text p27 "\tmad.lo.u32 %r5, %r2, %r3, %r4;\n" |
| 92 | text p28 "\tsetp.ge.u32 %p1, %r5, %r1;\n" |
| 93 | text p29 "\t@%p1 bra DONE;\n" |
| 94 | text p30 "\tcvta.to.global.u64 %rd4, %rd1;\n" |
| 95 | text p31 "\tcvta.to.global.u64 %rd5, %rd2;\n" |
| 96 | text p32 "\tcvta.to.global.u64 %rd6, %rd3;\n" |
| 97 | text p33 "\tmul.wide.u32 %rd7, %r5, 4;\n" |
| 98 | text p34 "\tadd.s64 %rd8, %rd4, %rd7;\n" |
| 99 | text p35 "\tadd.s64 %rd9, %rd5, %rd7;\n" |
| 100 | text p36 "\tadd.s64 %rd10, %rd6, %rd7;\n" |
| 101 | text p37 "\tld.global.u32 %r6, [%rd8];\n" |
| 102 | text p38 "\tld.global.u32 %r7, [%rd9];\n" |
| 103 | text p39 "\tadd.u32 %r6, %r6, %r7;\n" |
| 104 | text p40 "\tst.global.u32 [%rd10], %r6;\n" |
| 105 | text p41 "DONE:\n" |
| 106 | text p42 "\tret;\n" |
| 107 | text p43 "}\n" |
| 108 | note ---- small helpers |
| 109 | fn al8 x ulong to ulong |
| 110 | ret and add x 7 not ulong 7 |
| 111 | end |
| 112 | fn w8 o ulong v ulong to void |
| 113 | put ob o uchar and v 255 |
| 114 | end |
| 115 | fn w16 o ulong v ulong to void |
| 116 | w8 o v |
| 117 | w8 add o 1 shr v 8 |
| 118 | end |
| 119 | fn w32 o ulong v ulong to void |
| 120 | w16 o and v 65535 |
| 121 | w16 add o 2 shr v 16 |
| 122 | end |
| 123 | fn w64 o ulong v ulong to void |
| 124 | w32 o and v 4294967295 |
| 125 | w32 add o 4 shr v 32 |
| 126 | end |
| 127 | note the argument ai as a path in ag; exit 2 when absent |
| 128 | fn arg ai ulong to ulong |
| 129 | r = argread ai ag 0 sub len ag 1 |
| 130 | if le r 0 |
| 131 | exit 2 |
| 132 | end |
| 133 | ret ulong r |
| 134 | end |
| 135 | note the argument ai equals t |
| 136 | fn argis ai ulong t view uchar * to bool |
| 137 | r = argread ai ag 0 sub len ag 1 |
| 138 | if ne r long len t |
| 139 | ret false |
| 140 | end |
| 141 | for i ulong len t bound 4096 |
| 142 | if ne get ag i get t i |
| 143 | ret false |
| 144 | end |
| 145 | end |
| 146 | ret true |
| 147 | end |
| 148 | note load argument ai's file into ib from at; returns the end, exit 3 when unreadable or too large |
| 149 | fn ldf ai ulong from ulong to ulong |
| 150 | m = arg ai |
| 151 | fd = fopen ag 0 m int 524288 int 0 |
| 152 | if lt fd 0 |
| 153 | exit 3 |
| 154 | end |
| 155 | n = from |
| 156 | while true bound 16777218 |
| 157 | x = read int fd ib n sub BIG n |
| 158 | if lt x 0 |
| 159 | exit 3 |
| 160 | end |
| 161 | if eq x 0 |
| 162 | break |
| 163 | end |
| 164 | n = add n ulong x |
| 165 | if ge n BIG |
| 166 | exit 3 |
| 167 | end |
| 168 | end |
| 169 | r = fclose int fd |
| 170 | ret n |
| 171 | end |
| 172 | note write ob[0, n) to the path in argument ai; exit 3 when that fails |
| 173 | fn save ai ulong n ulong to void |
| 174 | m = arg ai |
| 175 | r = unlink ag 0 m |
| 176 | fd = fopen ag 0 m int 524865 int 420 |
| 177 | if lt fd 0 |
| 178 | exit 3 |
| 179 | end |
| 180 | o = ulong 0 |
| 181 | while lt o n bound 16777217 |
| 182 | x = write int fd ob o sub n o |
| 183 | if le x 0 |
| 184 | exit 3 |
| 185 | end |
| 186 | o = add o ulong x |
| 187 | end |
| 188 | r = fclose int fd |
| 189 | end |
| 190 | note ---- rows: fields of one tab-separated line into fo/fl, count into nv 11; returns the next line |
| 191 | fn row o ulong e ulong to ulong |
| 192 | put nv 11 0 |
| 193 | s = o |
| 194 | p = o |
| 195 | while lt p e bound 16777217 |
| 196 | c = get ib p |
| 197 | if eq c 10 |
| 198 | break |
| 199 | end |
| 200 | if eq c 9 |
| 201 | k = get nv 11 |
| 202 | if lt k 8 |
| 203 | put fo k s |
| 204 | put fl k sub p s |
| 205 | end |
| 206 | put nv 11 add k 1 |
| 207 | s = add p 1 |
| 208 | end |
| 209 | p = add p 1 |
| 210 | end |
| 211 | k = get nv 11 |
| 212 | if lt k 8 |
| 213 | put fo k s |
| 214 | put fl k sub p s |
| 215 | end |
| 216 | put nv 11 add k 1 |
| 217 | if lt p e |
| 218 | p = add p 1 |
| 219 | end |
| 220 | ret p |
| 221 | end |
| 222 | note field i of the current row equals t |
| 223 | fn ft i ulong t view uchar * to bool |
| 224 | if ge i get nv 11 |
| 225 | ret false |
| 226 | end |
| 227 | if ne get fl i len t |
| 228 | ret false |
| 229 | end |
| 230 | o = get fo i |
| 231 | for j ulong len t bound 4096 |
| 232 | if ne get ib add o j get t j |
| 233 | ret false |
| 234 | end |
| 235 | end |
| 236 | ret true |
| 237 | end |
| 238 | note ib[a, a+n) equals field i of the current row |
| 239 | fn fbytes i ulong a ulong n ulong to bool |
| 240 | if ge i get nv 11 |
| 241 | ret false |
| 242 | end |
| 243 | if ne get fl i n |
| 244 | ret false |
| 245 | end |
| 246 | o = get fo i |
| 247 | for j ulong n bound 16777216 |
| 248 | if ne get ib add o j get ib add a j |
| 249 | ret false |
| 250 | end |
| 251 | end |
| 252 | ret true |
| 253 | end |
| 254 | note append field i of the current row and a zero to .dynstr; its offset |
| 255 | fn sadd i ulong to ulong |
| 256 | s = get nv 3 |
| 257 | n = get fl i |
| 258 | if ge add add s n 1 BIG |
| 259 | exit 3 |
| 260 | end |
| 261 | o = get fo i |
| 262 | for j ulong n bound 16777216 |
| 263 | put gs add s j get ib add o j |
| 264 | end |
| 265 | put gs add s n 0 |
| 266 | put nv 3 add add s n 1 |
| 267 | ret s |
| 268 | end |
| 269 | note SysV ELF hash of the .dynstr string at o |
| 270 | fn ehash o ulong to ulong |
| 271 | h = ulong 0 |
| 272 | p = o |
| 273 | while ne get gs p 0 bound 16777216 |
| 274 | h = and add shl h 4 ulong get gs p 4294967295 |
| 275 | g = and h 4026531840 |
| 276 | if ne g 0 |
| 277 | h = xor h shr g 24 |
| 278 | end |
| 279 | h = and h not g |
| 280 | p = add p 1 |
| 281 | end |
| 282 | ret h |
| 283 | end |
| 284 | note the machine of a "host ISA" row; exit 1 for another ISA |
| 285 | fn mach to ulong |
| 286 | if ft 1 k_a64 |
| 287 | ret 183 |
| 288 | end |
| 289 | if ft 1 k_x64 |
| 290 | ret 62 |
| 291 | end |
| 292 | exit 1 |
| 293 | end |
| 294 | note a slot in one of the row arrays; exit 3 past it |
| 295 | fn slot k ulong to void |
| 296 | if ge k ROWS |
| 297 | exit 3 |
| 298 | end |
| 299 | end |
| 300 | note ---- profile queries for nolib (each walks the profile and leaves fo/fl on its last row) |
| 301 | note the profile classes import ib[a, a+n) as cuda |
| 302 | fn iscuda a ulong n ulong to bool |
| 303 | p = get nv 1 |
| 304 | e = get nv 2 |
| 305 | while lt p e bound 16777217 |
| 306 | p = row p e |
| 307 | if ft 0 k_imp |
| 308 | if ft 2 k_cuda |
| 309 | if fbytes 1 a n |
| 310 | ret true |
| 311 | end |
| 312 | end |
| 313 | end |
| 314 | end |
| 315 | ret false |
| 316 | end |
| 317 | note the profile marks needed library ib[a, a+n) as replacement |
| 318 | fn isrepl a ulong n ulong to bool |
| 319 | p = get nv 1 |
| 320 | e = get nv 2 |
| 321 | while lt p e bound 16777217 |
| 322 | p = row p e |
| 323 | if ft 0 k_need |
| 324 | if ft 2 k_repl |
| 325 | if fbytes 1 a n |
| 326 | ret true |
| 327 | end |
| 328 | end |
| 329 | end |
| 330 | end |
| 331 | ret false |
| 332 | end |
| 333 | note ---- the order GNU ld gives a --defsym stub's .dynsym, which the executable linked against it copies into |
| 334 | note its .dynstr (measured with the binutils that built the v3 profiles: the gcc stub of CUDApp build.sh lists its symbols by |
| 335 | note GNU hash bucket, then by slot in ld's 4051-slot symbol table; with another order the linked executable |
| 336 | note differs in .dynstr and in its build ID). The bucket count is ld's for a link without -O: the largest of |
| 337 | note 1 3 17 37 67 ... 32771 not above the symbol count. |
| 338 | fn nbk n ulong to ulong |
| 339 | put bk 0 1 |
| 340 | put bk 1 3 |
| 341 | put bk 2 17 |
| 342 | put bk 3 37 |
| 343 | put bk 4 67 |
| 344 | put bk 5 97 |
| 345 | put bk 6 131 |
| 346 | put bk 7 197 |
| 347 | put bk 8 263 |
| 348 | put bk 9 521 |
| 349 | put bk 10 1031 |
| 350 | put bk 11 2053 |
| 351 | put bk 12 4099 |
| 352 | put bk 13 8209 |
| 353 | put bk 14 16411 |
| 354 | put bk 15 32771 |
| 355 | best = ulong 1 |
| 356 | for i ulong 16 |
| 357 | best = get bk i |
| 358 | if lt i 15 |
| 359 | if lt n get bk add i 1 |
| 360 | ret best |
| 361 | end |
| 362 | end |
| 363 | end |
| 364 | ret best |
| 365 | end |
| 366 | note GNU hash (h = h*33 + c from 5381, 32 bits) of the .dynstr string at o |
| 367 | fn ghash o ulong to ulong |
| 368 | h = ulong 5381 |
| 369 | p = o |
| 370 | while ne get gs p 0 bound 16777216 |
| 371 | h = and add mul h 33 ulong get gs p 4294967295 |
| 372 | p = add p 1 |
| 373 | end |
| 374 | ret h |
| 375 | end |
| 376 | note the slot of the .dynstr string at o in ld's symbol table (bfd_hash_hash modulo 4051) |
| 377 | fn bslot o ulong to ulong |
| 378 | h = ulong 0 |
| 379 | p = o |
| 380 | while ne get gs p 0 bound 16777216 |
| 381 | c = ulong get gs p |
| 382 | h = add h add c shl c 17 |
| 383 | h = xor h shr h 2 |
| 384 | p = add p 1 |
| 385 | end |
| 386 | n = sub p o |
| 387 | h = add h add n shl n 17 |
| 388 | h = xor h shr h 2 |
| 389 | ret rem h 4051 |
| 390 | end |
| 391 | note sort the stub's symbols into ld's order (stable insertion sort on bucket, then slot) |
| 392 | fn ldorder to void |
| 393 | ns = get nv 4 |
| 394 | nb = nbk ns |
| 395 | for i ulong ns bound 2097152 |
| 396 | s = get sy i |
| 397 | put hk i add mul rem ghash s nb 4096 bslot s |
| 398 | end |
| 399 | for i ulong ns bound 2097152 |
| 400 | k = get hk i |
| 401 | s = get sy i |
| 402 | j = i |
| 403 | while gt j 0 bound 2097152 |
| 404 | if le get hk sub j 1 k |
| 405 | break |
| 406 | end |
| 407 | put hk j get hk sub j 1 |
| 408 | put sy j get sy sub j 1 |
| 409 | j = sub j 1 |
| 410 | end |
| 411 | put hk j k |
| 412 | put sy j s |
| 413 | end |
| 414 | end |
| 415 | note ---- collect: stub rows from the profile ib[0, nv 0) |
| 416 | fn cstub to void |
| 417 | p = ulong 0 |
| 418 | e = get nv 0 |
| 419 | while lt p e bound 16777217 |
| 420 | p = row p e |
| 421 | if ft 0 k_host |
| 422 | put nv 8 mach |
| 423 | end |
| 424 | if ft 0 k_need |
| 425 | if ft 2 k_repl |
| 426 | if eq get nv 9 0 |
| 427 | put nv 9 sadd 1 |
| 428 | end |
| 429 | end |
| 430 | end |
| 431 | if ft 0 k_imp |
| 432 | if ft 2 k_cuda |
| 433 | k = get nv 4 |
| 434 | slot k |
| 435 | put sy k sadd 1 |
| 436 | put sb k 1 |
| 437 | put nv 4 add k 1 |
| 438 | end |
| 439 | end |
| 440 | end |
| 441 | end |
| 442 | note append ib[a, a+n) and a zero to .dynstr; its offset |
| 443 | fn sadd_at a ulong n ulong to ulong |
| 444 | s = get nv 3 |
| 445 | if ge add add s n 1 BIG |
| 446 | exit 3 |
| 447 | end |
| 448 | for j ulong n bound 16777216 |
| 449 | put gs add s j get ib add a j |
| 450 | end |
| 451 | put gs add s n 0 |
| 452 | put nv 3 add add s n 1 |
| 453 | ret s |
| 454 | end |
| 455 | note one table row into the symbol, needed or verneed arrays (exe) |
| 456 | fn cexe1 to void |
| 457 | if ft 0 k_host |
| 458 | put nv 8 mach |
| 459 | ret |
| 460 | end |
| 461 | nl = eq get nv 15 1 |
| 462 | if ft 0 k_imp |
| 463 | b = ulong 0 |
| 464 | if ft 2 k_glob |
| 465 | b = 1 |
| 466 | end |
| 467 | if ft 2 k_weak |
| 468 | b = 2 |
| 469 | end |
| 470 | if eq b 0 |
| 471 | exit 1 |
| 472 | end |
| 473 | a = get fo 1 |
| 474 | n = get fl 1 |
| 475 | keep = true |
| 476 | if nl |
| 477 | if iscuda a n |
| 478 | keep = false |
| 479 | end |
| 480 | end |
| 481 | if keep |
| 482 | k = get nv 4 |
| 483 | slot k |
| 484 | put sy k sadd_at a n |
| 485 | put sb k b |
| 486 | put nv 4 add k 1 |
| 487 | end |
| 488 | ret |
| 489 | end |
| 490 | if ft 0 k_need |
| 491 | a = get fo 1 |
| 492 | n = get fl 1 |
| 493 | keep = true |
| 494 | if nl |
| 495 | if isrepl a n |
| 496 | keep = false |
| 497 | end |
| 498 | end |
| 499 | if keep |
| 500 | k = get nv 5 |
| 501 | slot k |
| 502 | put nd k sadd_at a n |
| 503 | put nv 5 add k 1 |
| 504 | end |
| 505 | ret |
| 506 | end |
| 507 | if ft 0 k_ver |
| 508 | g = get nv 6 |
| 509 | same = false |
| 510 | if gt g 0 |
| 511 | if fbytes 2 get nv 13 get nv 14 |
| 512 | same = true |
| 513 | end |
| 514 | end |
| 515 | if not same |
| 516 | slot g |
| 517 | put vf g sadd 2 |
| 518 | put vc g 0 |
| 519 | put nv 6 add g 1 |
| 520 | put nv 13 get fo 2 |
| 521 | put nv 14 get fl 2 |
| 522 | end |
| 523 | g = sub get nv 6 1 |
| 524 | put vc g add get vc g 1 |
| 525 | k = get nv 7 |
| 526 | slot k |
| 527 | put va k sadd 1 |
| 528 | put nv 7 add k 1 |
| 529 | end |
| 530 | end |
| 531 | note ---- collect: exe rows from the table ib[0, nv 0) |
| 532 | fn cexe to void |
| 533 | p = ulong 0 |
| 534 | e = get nv 0 |
| 535 | while lt p e bound 16777217 |
| 536 | p = row p e |
| 537 | cexe1 |
| 538 | end |
| 539 | end |
| 540 | note append t and a zero to .shstrtab at s; the new end |
| 541 | fn sname s ulong t view uchar * to ulong |
| 542 | for j ulong len t bound 64 |
| 543 | put ss add s j get t j |
| 544 | end |
| 545 | put ss add s len t 0 |
| 546 | ret add add s len t 1 |
| 547 | end |
| 548 | note one section header at o |
| 549 | fn shdr o ulong nm ulong ty ulong fg ulong off ulong sz ulong to void |
| 550 | w32 o nm |
| 551 | w32 add o 4 ty |
| 552 | w64 add o 8 fg |
| 553 | w64 add o 24 off |
| 554 | w64 add o 32 sz |
| 555 | end |
| 556 | fn shad o ulong addr ulong lk ulong inf ulong ag8 ulong es ulong to void |
| 557 | w64 add o 16 addr |
| 558 | w32 add o 40 lk |
| 559 | w32 add o 44 inf |
| 560 | w64 add o 48 ag8 |
| 561 | w64 add o 56 es |
| 562 | end |
| 563 | note one dynamic entry |
| 564 | fn dent o ulong t ulong v ulong to void |
| 565 | w64 o t |
| 566 | w64 add o 8 v |
| 567 | end |
| 568 | note the hash table for the stub at o |
| 569 | fn hashat o ulong ns ulong to void |
| 570 | w32 o 1 |
| 571 | w32 add o 4 ns |
| 572 | if gt ns 1 |
| 573 | w32 add o 8 1 |
| 574 | end |
| 575 | for i ulong ns bound 2097153 |
| 576 | nx = add i 1 |
| 577 | if ge nx ns |
| 578 | nx = 0 |
| 579 | end |
| 580 | if eq i 0 |
| 581 | nx = 0 |
| 582 | end |
| 583 | w32 add add o 12 mul i 4 nx |
| 584 | end |
| 585 | end |
| 586 | note the version needs at o |
| 587 | fn vrat o ulong to void |
| 588 | q = o |
| 589 | x = ulong 0 |
| 590 | ng = get nv 6 |
| 591 | for g ulong ng bound 2097152 |
| 592 | c = get vc g |
| 593 | w16 q 1 |
| 594 | w16 add q 2 c |
| 595 | w32 add q 4 get vf g |
| 596 | w32 add q 8 16 |
| 597 | if lt add g 1 ng |
| 598 | w32 add q 12 add 16 mul c 16 |
| 599 | end |
| 600 | q = add q 16 |
| 601 | for k ulong c bound 2097152 |
| 602 | s = get va x |
| 603 | w32 q ehash s |
| 604 | w16 add q 6 add x 2 |
| 605 | w32 add q 8 s |
| 606 | if lt add k 1 c |
| 607 | w32 add q 12 16 |
| 608 | end |
| 609 | q = add q 16 |
| 610 | x = add x 1 |
| 611 | end |
| 612 | end |
| 613 | end |
| 614 | note the symbols at o |
| 615 | fn symat o ulong to void |
| 616 | ns = get nv 4 |
| 617 | for i ulong ns bound 2097152 |
| 618 | e = add o mul add i 1 24 |
| 619 | w32 e get sy i |
| 620 | w8 add e 4 shl get sb i 4 |
| 621 | if eq get nv 10 1 |
| 622 | w16 add e 6 65521 |
| 623 | end |
| 624 | end |
| 625 | end |
| 626 | note ---- the image: header, two program headers, .dynstr, .dynsym, [.hash], [.gnu.version_r], .dynamic, .shstrtab |
| 627 | fn image to ulong |
| 628 | st = get nv 10 |
| 629 | s = get nv 3 |
| 630 | nsym = add get nv 4 1 |
| 631 | osym = al8 add 176 s |
| 632 | p = add osym mul nsym 24 |
| 633 | oh = p |
| 634 | if eq st 1 |
| 635 | p = al8 add p mul 4 add 3 nsym |
| 636 | end |
| 637 | ovr = p |
| 638 | ng = get nv 6 |
| 639 | if eq st 0 |
| 640 | p = al8 add p mul 16 add ng get nv 7 |
| 641 | end |
| 642 | odyn = p |
| 643 | nd8 = ulong 7 |
| 644 | if eq st 0 |
| 645 | nd8 = add get nv 5 5 |
| 646 | if gt ng 0 |
| 647 | nd8 = add nd8 2 |
| 648 | end |
| 649 | end |
| 650 | oshs = add odyn mul nd8 16 |
| 651 | put nv 20 osym |
| 652 | put nv 21 oh |
| 653 | put nv 22 ovr |
| 654 | put nv 23 odyn |
| 655 | put nv 24 nd8 |
| 656 | put nv 25 oshs |
| 657 | z = image2 |
| 658 | ret z |
| 659 | end |
| 660 | fn image2 to ulong |
| 661 | st = get nv 10 |
| 662 | ng = get nv 6 |
| 663 | l = ulong 1 |
| 664 | put ss 0 0 |
| 665 | put nv 30 l |
| 666 | l = sname l n_dynstr |
| 667 | put nv 31 l |
| 668 | l = sname l n_dynsym |
| 669 | put nv 32 l |
| 670 | l = sname l n_hash |
| 671 | put nv 33 l |
| 672 | l = sname l n_vr |
| 673 | put nv 34 l |
| 674 | l = sname l n_dyn |
| 675 | put nv 35 l |
| 676 | l = sname l n_shs |
| 677 | put nv 36 l |
| 678 | shn = ulong 5 |
| 679 | if eq st 1 |
| 680 | shn = 6 |
| 681 | end |
| 682 | if eq st 0 |
| 683 | if gt ng 0 |
| 684 | shn = 6 |
| 685 | end |
| 686 | end |
| 687 | osh = al8 add get nv 25 l |
| 688 | tot = add osh mul shn 64 |
| 689 | if gt tot BIG |
| 690 | exit 3 |
| 691 | end |
| 692 | put nv 26 osh |
| 693 | put nv 27 shn |
| 694 | put nv 28 l |
| 695 | put nv 12 tot |
| 696 | ehdr |
| 697 | body |
| 698 | sects |
| 699 | ret tot |
| 700 | end |
| 701 | fn ehdr to void |
| 702 | w32 0 1179403647 |
| 703 | w8 4 2 |
| 704 | w8 5 1 |
| 705 | w8 6 1 |
| 706 | w16 16 3 |
| 707 | w16 18 get nv 8 |
| 708 | w32 20 1 |
| 709 | w64 32 64 |
| 710 | w64 40 get nv 26 |
| 711 | w16 52 64 |
| 712 | w16 54 56 |
| 713 | w16 56 2 |
| 714 | w16 58 64 |
| 715 | w16 60 get nv 27 |
| 716 | w16 62 sub get nv 27 1 |
| 717 | odyn = get nv 23 |
| 718 | dz = mul get nv 24 16 |
| 719 | w32 64 1 |
| 720 | w32 68 6 |
| 721 | w64 96 add odyn dz |
| 722 | w64 104 add odyn dz |
| 723 | w64 112 4096 |
| 724 | w32 120 2 |
| 725 | w32 124 6 |
| 726 | w64 128 odyn |
| 727 | w64 136 odyn |
| 728 | w64 144 odyn |
| 729 | w64 152 dz |
| 730 | w64 160 dz |
| 731 | w64 168 8 |
| 732 | end |
| 733 | fn body to void |
| 734 | s = get nv 3 |
| 735 | for i ulong s bound 16777216 |
| 736 | put ob add 176 i get gs i |
| 737 | end |
| 738 | symat get nv 20 |
| 739 | st = get nv 10 |
| 740 | nsym = add get nv 4 1 |
| 741 | if eq st 1 |
| 742 | hashat get nv 21 nsym |
| 743 | end |
| 744 | if eq st 0 |
| 745 | vrat get nv 22 |
| 746 | end |
| 747 | q = get nv 23 |
| 748 | if eq st 1 |
| 749 | dent q 14 get nv 9 |
| 750 | dent add q 16 4 get nv 21 |
| 751 | q = add q 32 |
| 752 | end |
| 753 | if eq st 0 |
| 754 | for i ulong get nv 5 bound 2097152 |
| 755 | dent q 1 get nd i |
| 756 | q = add q 16 |
| 757 | end |
| 758 | end |
| 759 | dent q 5 176 |
| 760 | dent add q 16 6 get nv 20 |
| 761 | dent add q 32 10 s |
| 762 | dent add q 48 11 24 |
| 763 | q = add q 64 |
| 764 | if eq st 0 |
| 765 | if gt get nv 6 0 |
| 766 | dent q 1879048190 get nv 22 |
| 767 | dent add q 16 1879048191 get nv 6 |
| 768 | q = add q 32 |
| 769 | end |
| 770 | end |
| 771 | dent q 0 0 |
| 772 | o = get nv 25 |
| 773 | for i ulong get nv 28 bound 128 |
| 774 | put ob add o i get ss i |
| 775 | end |
| 776 | end |
| 777 | fn sects to void |
| 778 | st = get nv 10 |
| 779 | o = add get nv 26 64 |
| 780 | shdr o get nv 30 3 2 176 get nv 3 |
| 781 | shad o 176 0 0 1 0 |
| 782 | o = add o 64 |
| 783 | nsym = add get nv 4 1 |
| 784 | shdr o get nv 31 11 2 get nv 20 mul nsym 24 |
| 785 | shad o get nv 20 1 1 8 24 |
| 786 | o = add o 64 |
| 787 | if eq st 1 |
| 788 | shdr o get nv 32 5 2 get nv 21 mul 4 add 3 nsym |
| 789 | shad o get nv 21 2 0 8 4 |
| 790 | o = add o 64 |
| 791 | end |
| 792 | ng = get nv 6 |
| 793 | if eq st 0 |
| 794 | if gt ng 0 |
| 795 | shdr o get nv 33 1879048190 2 get nv 22 mul 16 add ng get nv 7 |
| 796 | shad o get nv 22 1 ng 8 0 |
| 797 | o = add o 64 |
| 798 | end |
| 799 | end |
| 800 | dz = mul get nv 24 16 |
| 801 | shdr o get nv 34 6 3 get nv 23 dz |
| 802 | shad o get nv 23 1 0 8 16 |
| 803 | o = add o 64 |
| 804 | shdr o get nv 35 3 0 get nv 25 get nv 28 |
| 805 | shad o 0 0 0 1 0 |
| 806 | end |
| 807 | note ---- the PTX fixture |
| 808 | note append t to the output image |
| 809 | fn pw t view uchar * to void |
| 810 | o = get nv 12 |
| 811 | for j ulong len t bound 4096 |
| 812 | put ob add o j get t j |
| 813 | end |
| 814 | put nv 12 add o len t |
| 815 | end |
| 816 | fn ptxout to void |
| 817 | pw p01 |
| 818 | pw p02 |
| 819 | pw p03 |
| 820 | pw p04 |
| 821 | pw p05 |
| 822 | pw p06 |
| 823 | pw p07 |
| 824 | pw p08 |
| 825 | pw p09 |
| 826 | pw p10 |
| 827 | pw p11 |
| 828 | pw p12 |
| 829 | pw p13 |
| 830 | pw p14 |
| 831 | pw p15 |
| 832 | pw p16 |
| 833 | pw p17 |
| 834 | pw p18 |
| 835 | pw p19 |
| 836 | pw p20 |
| 837 | pw p21 |
| 838 | pw p22 |
| 839 | pw p23 |
| 840 | pw p24 |
| 841 | pw p25 |
| 842 | pw p26 |
| 843 | pw p27 |
| 844 | pw p28 |
| 845 | pw p29 |
| 846 | pw p30 |
| 847 | pw p31 |
| 848 | pw p32 |
| 849 | pw p33 |
| 850 | pw p34 |
| 851 | pw p35 |
| 852 | pw p36 |
| 853 | pw p37 |
| 854 | pw p38 |
| 855 | pw p39 |
| 856 | pw p40 |
| 857 | pw p41 |
| 858 | pw p42 |
| 859 | pw p43 |
| 860 | end |
| 861 | fn main to int |
| 862 | c = argcnt |
| 863 | note .dynstr starts with the empty name |
| 864 | put nv 3 1 |
| 865 | if lt c 3 |
| 866 | exit 2 |
| 867 | end |
| 868 | if argis 1 m_ptx |
| 869 | if ne c 3 |
| 870 | exit 2 |
| 871 | end |
| 872 | ptxout |
| 873 | save 2 get nv 12 |
| 874 | ret 0 |
| 875 | end |
| 876 | if argis 1 m_stub |
| 877 | if ne c 4 |
| 878 | exit 2 |
| 879 | end |
| 880 | put nv 0 ldf 2 0 |
| 881 | put nv 10 1 |
| 882 | cstub |
| 883 | ldorder |
| 884 | if eq get nv 8 0 |
| 885 | exit 1 |
| 886 | end |
| 887 | if eq get nv 4 0 |
| 888 | exit 1 |
| 889 | end |
| 890 | if eq get nv 9 0 |
| 891 | exit 1 |
| 892 | end |
| 893 | save 3 image |
| 894 | ret 0 |
| 895 | end |
| 896 | if argis 1 m_exe |
| 897 | if ne c 6 |
| 898 | exit 2 |
| 899 | end |
| 900 | if argis 4 m_nolib |
| 901 | put nv 15 1 |
| 902 | else |
| 903 | if not argis 4 m_full |
| 904 | exit 2 |
| 905 | end |
| 906 | end |
| 907 | n = ldf 2 0 |
| 908 | put nv 0 n |
| 909 | put nv 1 n |
| 910 | put nv 2 ldf 3 n |
| 911 | cexe |
| 912 | if eq get nv 8 0 |
| 913 | exit 1 |
| 914 | end |
| 915 | save 5 image |
| 916 | ret 0 |
| 917 | end |
| 918 | exit 2 |
| 919 | end |