rebuild iggy's rad runtime core global
This commit is contained in:
@@ -420,3 +420,20 @@ target_compile_definitions(
|
||||
PRIVATE IGGY_RECONSTRUCT_WIN32_RRTIME_DURANGO=1
|
||||
)
|
||||
configure_iggy_reconstructed_target(iggy_reconstructed_win32_rrTime_durango c_std_11)
|
||||
|
||||
# rrCore: 4-platform, data-only TU (one owned global, zero functions).
|
||||
foreach(platform IN ITEMS durango orbis ps3 vita)
|
||||
string(TOUPPER ${platform} platform_upper)
|
||||
set(target iggy_reconstructed_rrCore_${platform})
|
||||
add_library(${target} STATIC rrCore.c)
|
||||
target_compile_definitions(
|
||||
${target}
|
||||
PRIVATE IGGY_RECONSTRUCT_RRCORE_${platform_upper}
|
||||
)
|
||||
configure_iggy_reconstructed_target(${target} c_std_11)
|
||||
if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
|
||||
target_compile_options(${target} PRIVATE -fno-builtin)
|
||||
elseif(MSVC)
|
||||
target_compile_options(${target} PRIVATE /Oi-)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
@@ -340,6 +340,15 @@ Durango/Orbis/PS3, `sqrt` only on Durango/Vita) matches exactly. The Durango
|
||||
64-bit layout is the reconstruction base; the original SWF shape assets remain
|
||||
the caller.
|
||||
|
||||
`rrCore.c` restores the RAD runtime-core translation unit, a data-only object
|
||||
whose single owned symbol is the `g_fp_rrDisplayAssertion` display-assertion
|
||||
callback pointer (default NULL, in BSS on all four builds). The retail object
|
||||
contains no functions; the reconstruction defines just this one owned global,
|
||||
closing the assertion-callback import that the completed triangulate_ears and
|
||||
the AS3 VM units reference. The reconstructed-tree `rrCore.h` forwards to the
|
||||
authoritative RAD header so the base typedefs and the callback prototype stay a
|
||||
single source of truth.
|
||||
|
||||
Configure this directory directly with CMake to build the reconstructed units.
|
||||
Every added module must compile independently and have behavioral tests before
|
||||
it is listed in `modules.tsv` as complete.
|
||||
|
||||
@@ -61,3 +61,4 @@ gr_strokepath 21 3 durango complete
|
||||
gr_strokepath 19 3 orbis complete
|
||||
gr_strokepath 19 3 ps3 complete
|
||||
gr_strokepath 19 3 vita complete
|
||||
rrCore 0 0 durango,orbis,ps3,vita complete
|
||||
|
||||
|
68
iggy-decompiled/src/reconstructed/rrCore.c
Normal file
68
iggy-decompiled/src/reconstructed/rrCore.c
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* rrCore.c -- reconstructed RAD runtime core (data-only translation unit).
|
||||
*
|
||||
* Source-equivalent reconstruction of Iggy 1.2.30's rrCore compilation unit.
|
||||
* The retail object contains NO functions on any of the four platforms; its
|
||||
* only real symbol is the owned function-pointer global g_fp_rrDisplayAssertion
|
||||
* (Ghidra recovered nothing but this data symbol, so raw/<platform>/rrCore.c is
|
||||
* an empty stub on all four targets).
|
||||
*
|
||||
* Provenance (embedded paths recovered with `strings` from the retail objects):
|
||||
* durango: c:\projects\g\build\release\temps\libdu\iggy_durango\rrCore.obj
|
||||
* orbis: c:\projects\shared\radrtl\rrCore.c (the real RAD RTL source path)
|
||||
* ps3: rrCore.c
|
||||
* vita: rrCore.c
|
||||
* The orbis object retains the true source path, so this unit is anchored to it:
|
||||
* c:\projects\shared\radrtl\rrCore.c
|
||||
*
|
||||
* Retail symbol placement per platform (llvm-nm):
|
||||
* durango/orbis/ps3: B g_fp_rrDisplayAssertion (.bss, zero-initialized)
|
||||
* vita: D g_fp_rrDisplayAssertion (.data, still zero)
|
||||
* A NULL-initialized pointer lowers to .bss under clang on every target here,
|
||||
* matching durango/orbis/ps3 exactly and value-identical to vita.
|
||||
*
|
||||
* Signature: the authoritative header include/rrCore.h:1702 pins the callback
|
||||
* prototype exactly (and the already-reconstructed triangulate_ears/as3vm_class
|
||||
* importers use the same shape):
|
||||
*
|
||||
* rrbool (RADLINK *)(int *Ignored, const char *fileName, const int line,
|
||||
* const char *function, const char *message)
|
||||
*
|
||||
* i.e. FIRST argument is `int *` (not an unsigned flags word) and the callback
|
||||
* is FIXED five-argument, NOT variadic. This unit is kept self-contained (it
|
||||
* does not include the full RAD header) so it survives the freestanding
|
||||
* cross-compile the contract test performs; the typedef below mirrors the
|
||||
* authoritative prototype with the RADLINK calling-convention attribute dropped
|
||||
* (a data pointer's symbol/ABI is independent of the pointee's convention).
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/*
|
||||
* Exactly one platform-selection macro must be defined by the build (the CMake
|
||||
* foreach compiles this unit once per platform). This mirrors the single/
|
||||
* multi-platform #error idiom used by the other reconstructed modules and keeps
|
||||
* the data TU consistent with the per-platform build matrix, even though it
|
||||
* emits no code.
|
||||
*/
|
||||
#if (defined(IGGY_RECONSTRUCT_RRCORE_DURANGO) ? 1 : 0) \
|
||||
+ (defined(IGGY_RECONSTRUCT_RRCORE_ORBIS) ? 1 : 0) \
|
||||
+ (defined(IGGY_RECONSTRUCT_RRCORE_PS3) ? 1 : 0) \
|
||||
+ (defined(IGGY_RECONSTRUCT_RRCORE_VITA) ? 1 : 0) != 1
|
||||
#error "Define exactly one of IGGY_RECONSTRUCT_RRCORE_{DURANGO,ORBIS,PS3,VITA}."
|
||||
#endif
|
||||
|
||||
/* Mirror of include/rrCore.h:1702's fp_rrDisplayAssertion (pointer form). */
|
||||
typedef int (*fp_rrDisplayAssertion)(
|
||||
int *Ignored,
|
||||
const char *fileName,
|
||||
const int line,
|
||||
const char *function,
|
||||
const char *message);
|
||||
|
||||
/*
|
||||
* The module's sole owned symbol. Default NULL -> lands in BSS, matching the
|
||||
* retail `B g_fp_rrDisplayAssertion`. This is the live import that closes the
|
||||
* triangulate_ears and as3vm_class assertion callback references.
|
||||
*/
|
||||
fp_rrDisplayAssertion g_fp_rrDisplayAssertion = NULL;
|
||||
38
iggy-decompiled/src/reconstructed/rrCore.h
Normal file
38
iggy-decompiled/src/reconstructed/rrCore.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* rrCore.h -- reconstructed-tree entry point for the RAD runtime core header.
|
||||
*
|
||||
* rrCore is the RAD base module. Its authoritative public header already
|
||||
* exists in the decompilation tree at iggy-decompiled/include/rrCore.h (2322
|
||||
* lines of RAD platform detection plus the base typedefs F32/U32/S32/rrbool
|
||||
* and, at lines 1700-1707, the display-assertion callback contract):
|
||||
*
|
||||
* typedef rrbool (RADLINK fp_rrDisplayAssertion)(
|
||||
* int *Ignored, const char *fileName, const int line,
|
||||
* const char *function, const char *message);
|
||||
* extern fp_rrDisplayAssertion *g_fp_rrDisplayAssertion;
|
||||
* #define rrDisplayAssertion(i,n,l,f,m) \
|
||||
* ((g_fp_rrDisplayAssertion) ? (*g_fp_rrDisplayAssertion)(i,n,l,f,m) : 1)
|
||||
*
|
||||
* That authoritative header is what dependent reconstructed units include (for
|
||||
* example rrMath.h does `#include "rrCore.h"` to pull in F32/U32). Because
|
||||
* this file lives in the same directory as those dependents, a quoted
|
||||
* `#include "rrCore.h"` resolves here first; to avoid shadowing the real
|
||||
* declarations we simply forward to the authoritative header. Do NOT duplicate
|
||||
* the RAD base typedefs here -- a single source of truth keeps the assertion
|
||||
* prototype and base types consistent across the tree.
|
||||
*
|
||||
* The owned symbol g_fp_rrDisplayAssertion is DEFINED (default NULL) by the
|
||||
* reconstructed data-only TU rrCore.c. rrCore.c is intentionally
|
||||
* self-contained (it mirrors the prototype inline) so it can be cross-compiled
|
||||
* under the four freestanding platform triples, which the full RAD header
|
||||
* cannot survive (it requires the native MSVC/SDK platform macros).
|
||||
*/
|
||||
|
||||
#ifndef IGGY_RECONSTRUCTED_RRCORE_H
|
||||
#define IGGY_RECONSTRUCTED_RRCORE_H
|
||||
|
||||
/* Forward to the authoritative RAD Core header (base typedefs + the
|
||||
* fp_rrDisplayAssertion typedef and the extern g_fp_rrDisplayAssertion). */
|
||||
#include "../../include/rrCore.h"
|
||||
|
||||
#endif /* IGGY_RECONSTRUCTED_RRCORE_H */
|
||||
11
tests/support/rrCore_test_support.c
Normal file
11
tests/support/rrCore_test_support.c
Normal file
@@ -0,0 +1,11 @@
|
||||
/*
|
||||
* Host harness for the reconstructed rrCore translation unit.
|
||||
*
|
||||
* rrCore is a pure data-only unit: `llvm-nm --undefined-only` on every retail
|
||||
* object (durango/orbis/ps3/vita) returns zero symbols. There is nothing to
|
||||
* stub -- the module owns a single NULL function-pointer global and imports
|
||||
* nothing. This file exists only so the runtime dylib has a companion TU
|
||||
* mirroring the win32_rrAtomics harness convention.
|
||||
*/
|
||||
|
||||
typedef int rrCore_test_support_is_intentionally_empty;
|
||||
96
tests/test_reconstructed_rrCore.py
Normal file
96
tests/test_reconstructed_rrCore.py
Normal file
@@ -0,0 +1,96 @@
|
||||
"""Runtime tests for the reconstructed rrCore translation unit.
|
||||
|
||||
rrCore is a data-only module: its entire ABI surface is one owned
|
||||
function-pointer global, g_fp_rrDisplayAssertion, default NULL (the retail
|
||||
object stores it zero-initialized in .bss on durango/orbis/ps3 and .data on
|
||||
vita). There are no exported functions and no imports, so the support harness
|
||||
has no stubs.
|
||||
|
||||
These assertions are grounded in the retail objects under
|
||||
work/iggy-native-decomp/<platform>-objects/rrCore.obj, whose only real symbol
|
||||
is `g_fp_rrDisplayAssertion` (B on durango/orbis/ps3, D on vita). The dylib is
|
||||
built for the 64-bit host with IGGY_RECONSTRUCT_RRCORE_DURANGO selected; the
|
||||
symbol is read back through ctypes and confirmed NULL/zero by default.
|
||||
|
||||
The authoritative callback prototype (include/rrCore.h:1702) is
|
||||
`rrbool (RADLINK *)(int *Ignored, const char *fileName, const int line,
|
||||
const char *function, const char *message)`; here it is only exercised as a
|
||||
data pointer (its NULL default and mutability), so no call-signature is bound.
|
||||
"""
|
||||
|
||||
import ctypes
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
RECONSTRUCTED = ROOT / "iggy-decompiled/src/reconstructed"
|
||||
SOURCE = RECONSTRUCTED / "rrCore.c"
|
||||
HEADER = RECONSTRUCTED / "rrCore.h"
|
||||
SUPPORT = ROOT / "tests/support/rrCore_test_support.c"
|
||||
|
||||
|
||||
class ReconstructedRrCoreTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
missing = [str(path) for path in (SOURCE, HEADER, SUPPORT)
|
||||
if not path.exists()]
|
||||
if missing:
|
||||
raise AssertionError(
|
||||
"missing rrCore runtime inputs: " + ", ".join(missing))
|
||||
cls.temp = tempfile.TemporaryDirectory()
|
||||
output = Path(cls.temp.name) / "rrCore.dylib"
|
||||
build = subprocess.run([
|
||||
"clang", "-dynamiclib", "-std=c11", "-O2", "-Wall", "-Wextra",
|
||||
"-Werror", "-Wl,-undefined,dynamic_lookup",
|
||||
"-DIGGY_RECONSTRUCT_RRCORE_DURANGO=1",
|
||||
"-I", str(RECONSTRUCTED),
|
||||
str(SOURCE), str(SUPPORT), "-o", str(output),
|
||||
], capture_output=True, text=True)
|
||||
if build.returncode:
|
||||
raise AssertionError(build.stdout + build.stderr)
|
||||
cls.lib = ctypes.CDLL(str(output))
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
cls.temp.cleanup()
|
||||
|
||||
def test_display_assertion_symbol_exists(self):
|
||||
# The one owned global must be present in the built module.
|
||||
symbol = ctypes.c_void_p.in_dll(self.lib, "g_fp_rrDisplayAssertion")
|
||||
self.assertIsNotNone(symbol)
|
||||
|
||||
def test_display_assertion_defaults_to_null(self):
|
||||
# Retail places the pointer in BSS/DATA zero-initialized; the
|
||||
# reconstruction defines it `= NULL`, so it must read back as 0/None.
|
||||
symbol = ctypes.c_void_p.in_dll(self.lib, "g_fp_rrDisplayAssertion")
|
||||
self.assertIn(symbol.value, (None, 0))
|
||||
|
||||
def test_display_assertion_is_pointer_wide_storage(self):
|
||||
# Reading the address must succeed and the storage must be a full
|
||||
# pointer (matching the retail function-pointer data symbol).
|
||||
address = ctypes.addressof(
|
||||
ctypes.c_void_p.in_dll(self.lib, "g_fp_rrDisplayAssertion"))
|
||||
self.assertNotEqual(address, 0)
|
||||
raw = ctypes.c_void_p.from_address(address)
|
||||
self.assertIn(raw.value, (None, 0))
|
||||
|
||||
def test_display_assertion_is_writable_then_restored(self):
|
||||
# A host layer installs a callback by assigning the global; confirm the
|
||||
# storage is mutable and can be reset to NULL without disturbing others.
|
||||
symbol = ctypes.c_void_p.in_dll(self.lib, "g_fp_rrDisplayAssertion")
|
||||
self.assertIn(symbol.value, (None, 0))
|
||||
symbol.value = 0xDEADBEEF
|
||||
self.assertEqual(
|
||||
ctypes.c_void_p.in_dll(
|
||||
self.lib, "g_fp_rrDisplayAssertion").value, 0xDEADBEEF)
|
||||
symbol.value = 0
|
||||
self.assertIn(
|
||||
ctypes.c_void_p.in_dll(
|
||||
self.lib, "g_fp_rrDisplayAssertion").value, (None, 0))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
271
tests/test_reconstructed_rrCore_cross.py
Normal file
271
tests/test_reconstructed_rrCore_cross.py
Normal file
@@ -0,0 +1,271 @@
|
||||
r"""Cross-platform contract tests for the reconstructed rrCore module.
|
||||
|
||||
rrCore is a 4-platform, DATA-ONLY translation unit. Unlike win32_rrAtomics
|
||||
(functions, zero globals) this module inverts the shape: ZERO exported
|
||||
functions and exactly ONE owned data global. Structure copied from
|
||||
tests/test_reconstructed_win32_rrAtomics_cross.py and adapted so the module's
|
||||
"exports" are a data symbol, not functions.
|
||||
|
||||
How EXPECTED_* were derived (all four .obj under
|
||||
work/iggy-native-decomp/<platform>-objects/rrCore.obj; the perfmon/expr/patched
|
||||
variants are ignored):
|
||||
|
||||
EXPECTED_FUNCTIONS = empty. `llvm-nm --extern-only --defined-only <obj>`
|
||||
emits ZERO T-tagged names on every platform: rrCore
|
||||
contains no code at all.
|
||||
|
||||
EXPECTED_GLOBALS = {g_fp_rrDisplayAssertion}. The single owned data symbol,
|
||||
tagged `B` on durango/orbis/ps3 (.bss, zero-init) and `D`
|
||||
on vita (.data, still zero). It is the display-assertion
|
||||
callback default-initialized to NULL.
|
||||
|
||||
EXPECTED_IMPORTS = empty. `llvm-nm --undefined-only <obj>` emits zero lines
|
||||
on every platform: a data-only unit imports nothing.
|
||||
|
||||
RUNTIME_ALLOWLISTS = empty on all four platforms because the retail objects,
|
||||
and a clean freestanding recompile of rrCore.c, have zero
|
||||
undefined symbols.
|
||||
|
||||
Provenance (embedded paths recovered with `strings`):
|
||||
durango: c:\projects\g\build\release\temps\libdu\iggy_durango\rrCore.obj
|
||||
orbis: c:\projects\shared\radrtl\rrCore.c (real RAD RTL source path)
|
||||
ps3/vita: bare "rrCore.c"
|
||||
Because the durango object is a build-temp .obj path (no code -> no src\flash
|
||||
string) while the orbis object retains the true radrtl source path, the
|
||||
reconstruction anchors to the radrtl path and the test checks each object's own
|
||||
provenance independently.
|
||||
|
||||
modules.tsv convention: source_functions=0 (per-platform inventory column 3 is
|
||||
0 on all four) and external_functions=0 (zero T exports). The owned data
|
||||
global is tracked via EXPECTED_GLOBALS, not the function-count columns. Counts
|
||||
are identical on every platform, so a single combined row is used (like
|
||||
iggy_allocation), not per-platform rows.
|
||||
|
||||
Signature (authoritative, from iggy-decompiled/include/rrCore.h:1702, matching
|
||||
the already-reconstructed triangulate_ears/as3vm_class importers):
|
||||
|
||||
rrbool (RADLINK *)(int *Ignored, const char *fileName, const int line,
|
||||
const char *function, const char *message)
|
||||
|
||||
so the first argument is `int *` (not an unsigned flags word) and the callback
|
||||
is fixed five-argument, NOT variadic.
|
||||
|
||||
Header note: reconstructed/rrCore.h forwards to the authoritative RAD Core
|
||||
header (include/rrCore.h) so dependents such as rrMath.h keep resolving F32/U32
|
||||
and the assertion prototype. That full header only compiles under a native /
|
||||
platform toolchain (it needs MSVC/SDK platform macros and intrin.h), so the
|
||||
C11+C++17 header ABI probe runs on the HOST only. The four-target freestanding
|
||||
cross-compile exercises the self-contained rrCore.c, whose symbol table is the
|
||||
retail contract being verified.
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
RECONSTRUCTED = ROOT / "iggy-decompiled/src/reconstructed"
|
||||
SOURCE = RECONSTRUCTED / "rrCore.c"
|
||||
HEADER = RECONSTRUCTED / "rrCore.h"
|
||||
LLVM_NM = Path("/opt/homebrew/opt/llvm/bin/llvm-nm")
|
||||
VARIANTS = {
|
||||
"durango": ("clang", "x86_64-pc-windows-msvc"),
|
||||
"orbis": ("clang", "x86_64-unknown-freebsd"),
|
||||
"vita": ("clang", "armv7a-unknown-linux-gnueabihf"),
|
||||
}
|
||||
PS3_CLANG = Path("/opt/homebrew/opt/llvm/bin/clang")
|
||||
if PS3_CLANG.exists():
|
||||
VARIANTS["ps3"] = (str(PS3_CLANG), "powerpc-unknown-linux-gnu")
|
||||
|
||||
EXPECTED_FUNCTIONS = set()
|
||||
EXPECTED_GLOBALS = {"g_fp_rrDisplayAssertion"}
|
||||
EXPECTED_IMPORTS = set()
|
||||
RUNTIME_ALLOWLISTS = {
|
||||
"durango": set(), "orbis": set(), "ps3": set(), "vita": set(),
|
||||
}
|
||||
|
||||
# Per-platform embedded provenance strings, verified with `strings` on each
|
||||
# retail object.
|
||||
PROVENANCE = {
|
||||
"durango": r"c:\projects\g\build\release\temps\libdu\iggy_durango\rrCore.obj",
|
||||
"orbis": r"c:\projects\shared\radrtl\rrCore.c",
|
||||
"ps3": "rrCore.c",
|
||||
"vita": "rrCore.c",
|
||||
}
|
||||
# The source path the reconstruction embeds (the real RAD RTL location kept by
|
||||
# the orbis object).
|
||||
SOURCE_PROVENANCE = r"c:\projects\shared\radrtl\rrCore.c"
|
||||
|
||||
|
||||
def normalized_symbol(name):
|
||||
name = name.removeprefix(".")
|
||||
name = name.removeprefix("__imp_")
|
||||
if name == "_setjmp":
|
||||
return "setjmp"
|
||||
return name
|
||||
|
||||
|
||||
def defined_symbols_by_kind(output):
|
||||
functions = set()
|
||||
globals_ = set()
|
||||
for line in output.splitlines():
|
||||
parts = line.split()
|
||||
if len(parts) < 2:
|
||||
continue
|
||||
kind = parts[-2].upper()
|
||||
name = normalized_symbol(parts[-1])
|
||||
if kind == "T":
|
||||
functions.add(name)
|
||||
elif kind in {"D", "B", "C"}:
|
||||
globals_.add(name)
|
||||
return functions, globals_
|
||||
|
||||
|
||||
class ReconstructedRrCoreCrossTests(unittest.TestCase):
|
||||
def test_native_provenance_counts_source_path_and_inventory(self):
|
||||
# Per-platform inventory: category=platform, source_functions=0,
|
||||
# lines=3 (the raw .c is an empty Ghidra stub -- verified with wc -l).
|
||||
for platform in ("durango", "orbis", "ps3", "vita"):
|
||||
modules = ROOT / f"iggy-decompiled/symbols/iggy_{platform}.modules.tsv"
|
||||
row = next(
|
||||
line for line in modules.read_text(encoding="utf-8").splitlines()
|
||||
if line.startswith("rrCore\t"))
|
||||
cols = row.split("\t")
|
||||
self.assertEqual(cols[1], "platform", platform)
|
||||
self.assertEqual(int(cols[2]), 0, platform)
|
||||
self.assertEqual(int(cols[3]), 3, platform)
|
||||
|
||||
raw = ROOT / f"iggy-decompiled/raw/{platform}/rrCore.c"
|
||||
self.assertEqual(
|
||||
len(raw.read_text(encoding="utf-8").splitlines()), 3, platform)
|
||||
|
||||
obj = ROOT / (
|
||||
f"work/iggy-native-decomp/{platform}-objects/rrCore.obj")
|
||||
self.assertTrue(obj.exists(), f"missing {obj}")
|
||||
|
||||
# The one owned data global is present; nm -g surfaces it.
|
||||
symbols = subprocess.run(
|
||||
["nm", "-g", str(obj)], capture_output=True, text=True)
|
||||
self.assertEqual(symbols.returncode, 0, (platform, symbols.stderr))
|
||||
normalized = symbols.stdout.replace(" .", " ")
|
||||
for symbol in EXPECTED_GLOBALS:
|
||||
self.assertIn(symbol, normalized, (platform, symbol))
|
||||
|
||||
# Each object carries its own provenance string.
|
||||
strings = subprocess.run(
|
||||
["strings", "-a", str(obj)], capture_output=True, text=True)
|
||||
self.assertEqual(strings.returncode, 0, (platform, strings.stderr))
|
||||
self.assertIn(PROVENANCE[platform], strings.stdout, platform)
|
||||
|
||||
if LLVM_NM.exists():
|
||||
undefined = subprocess.run(
|
||||
[str(LLVM_NM), "--undefined-only", str(obj)],
|
||||
capture_output=True, text=True)
|
||||
self.assertEqual(undefined.returncode, 0, undefined.stderr)
|
||||
imports = {
|
||||
normalized_symbol(line.split()[-1])
|
||||
for line in undefined.stdout.splitlines()
|
||||
if line.split()
|
||||
}
|
||||
self.assertEqual(imports, EXPECTED_IMPORTS, platform)
|
||||
|
||||
defined = subprocess.run(
|
||||
[str(LLVM_NM), "--extern-only", "--defined-only", str(obj)],
|
||||
capture_output=True, text=True)
|
||||
self.assertEqual(defined.returncode, 0, defined.stderr)
|
||||
functions, globals_ = defined_symbols_by_kind(defined.stdout)
|
||||
self.assertEqual(functions, EXPECTED_FUNCTIONS, platform)
|
||||
self.assertEqual(globals_, EXPECTED_GLOBALS, platform)
|
||||
|
||||
if SOURCE.exists():
|
||||
cmake = (RECONSTRUCTED / "CMakeLists.txt").read_text(
|
||||
encoding="utf-8")
|
||||
self.assertIn("iggy_reconstructed_rrCore_${platform}", cmake)
|
||||
self.assertIn(
|
||||
"add_library(${target} STATIC rrCore.c)", cmake)
|
||||
self.assertIn("IGGY_RECONSTRUCT_RRCORE_${platform_upper}", cmake)
|
||||
inventory = (RECONSTRUCTED / "modules.tsv").read_text(
|
||||
encoding="utf-8")
|
||||
self.assertIn(
|
||||
"rrCore\t0\t0\tdurango,orbis,ps3,vita\tcomplete", inventory)
|
||||
|
||||
def test_four_target_cross_compile_symbol_equality(self):
|
||||
# The self-contained rrCore.c must cross-compile under all four
|
||||
# freestanding platform triples and, on each, define exactly the owned
|
||||
# data global with zero functions and zero imports -- the retail
|
||||
# contract from work/iggy-native-decomp/<platform>-objects/rrCore.obj.
|
||||
self.assertTrue(SOURCE.exists(), f"missing {SOURCE}")
|
||||
# The reconstruction embeds the real RAD RTL source path.
|
||||
self.assertIn(SOURCE_PROVENANCE, SOURCE.read_text(encoding="utf-8"))
|
||||
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
temporary = Path(directory)
|
||||
for platform, (compiler, target) in VARIANTS.items():
|
||||
extra = ["-mthumb"] if platform == "vita" else []
|
||||
output = temporary / f"rrCore_{platform}.o"
|
||||
build = subprocess.run([
|
||||
compiler, "-target", target, "-ffreestanding",
|
||||
"-fno-builtin", "-c", "-std=c11", "-O2", "-Wall", "-Wextra",
|
||||
"-Werror", *extra,
|
||||
f"-DIGGY_RECONSTRUCT_RRCORE_{platform.upper()}=1",
|
||||
"-I", str(RECONSTRUCTED), str(SOURCE), "-o", str(output),
|
||||
], capture_output=True, text=True)
|
||||
self.assertEqual(build.returncode, 0, (platform, build.stderr))
|
||||
|
||||
if LLVM_NM.exists():
|
||||
defined = subprocess.run([
|
||||
str(LLVM_NM), "--extern-only", "--defined-only",
|
||||
str(output),
|
||||
], capture_output=True, text=True)
|
||||
undefined = subprocess.run([
|
||||
str(LLVM_NM), "--undefined-only", str(output),
|
||||
], capture_output=True, text=True)
|
||||
self.assertEqual(defined.returncode, 0, defined.stderr)
|
||||
self.assertEqual(undefined.returncode, 0, undefined.stderr)
|
||||
functions, globals_ = defined_symbols_by_kind(
|
||||
defined.stdout)
|
||||
imports = {
|
||||
normalized_symbol(line.split()[-1])
|
||||
for line in undefined.stdout.splitlines()
|
||||
if line.split()
|
||||
}
|
||||
self.assertEqual(functions, EXPECTED_FUNCTIONS, platform)
|
||||
self.assertEqual(globals_, EXPECTED_GLOBALS, platform)
|
||||
self.assertEqual(
|
||||
imports - RUNTIME_ALLOWLISTS[platform],
|
||||
EXPECTED_IMPORTS, (platform, imports))
|
||||
self.assertEqual(imports, set(), platform)
|
||||
|
||||
def test_header_forwards_and_is_c11_cpp17_includable(self):
|
||||
# reconstructed/rrCore.h forwards to the authoritative RAD Core header,
|
||||
# so it must (a) actually forward and (b) be includable as both C11 and
|
||||
# C++17 on the host, where the full RAD header resolves the platform.
|
||||
self.assertTrue(HEADER.exists(), f"missing {HEADER}")
|
||||
self.assertIn(
|
||||
'#include "../../include/rrCore.h"',
|
||||
HEADER.read_text(encoding="utf-8"))
|
||||
|
||||
probe_text = (
|
||||
'#include "rrCore.h"\n'
|
||||
'int rrcore_abi_probe(void) {\n'
|
||||
' return g_fp_rrDisplayAssertion == 0 ? 1 : 0;\n'
|
||||
'}\n')
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
temporary = Path(directory)
|
||||
for language, standard in (("c", "c11"), ("c++", "c++17")):
|
||||
suffix = "c" if language == "c" else "cpp"
|
||||
probe = temporary / f"rrCore_abi.{suffix}"
|
||||
probe.write_text(probe_text, encoding="utf-8")
|
||||
syntax = subprocess.run([
|
||||
"clang", "-fsyntax-only", f"-std={standard}",
|
||||
"-Wall", "-Wextra", "-Werror",
|
||||
"-I", str(RECONSTRUCTED), str(probe),
|
||||
], capture_output=True, text=True)
|
||||
self.assertEqual(
|
||||
syntax.returncode, 0, (language, syntax.stderr))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user