diff --git a/CMakeLists.txt b/CMakeLists.txt index 509af34..8496899 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,21 @@ if(APPLE) enable_language(OBJCXX) endif() +# The native runtime ABI for targets with no operating system. Built for +# every host because the sources are portable; only its link test is ELF. +add_library(nilruntime_freestanding STATIC + nilruntime-freestanding/freestanding_runtime.cpp) +target_compile_features(nilruntime_freestanding PRIVATE cxx_std_17) +set_target_properties(nilruntime_freestanding PROPERTIES + CXX_EXTENSIONS OFF + POSITION_INDEPENDENT_CODE ON) +if(NOT MSVC) + # No hosted assumptions, no unwinder, no type information: a kernel or + # loader links this archive without providing any of them. + target_compile_options(nilruntime_freestanding PRIVATE + -ffreestanding -fno-exceptions -fno-rtti) +endif() + add_subdirectory(nilcompiler) add_subdirectory(nilinterpreter) add_subdirectory(nillsp) @@ -695,6 +710,17 @@ if(BUILD_TESTING) set_tests_properties(nil.native-symbol-surface PROPERTIES LABELS "native;abi;rc" SKIP_RETURN_CODE 77 TIMEOUT 180) endif() + # Prove the freestanding boundary closes: object plus runtime, linked + # with no C library and its own entry, actually runs. + if(NIL_ENABLE_LLVM AND NOT MSVC) + add_test(NAME nil.freestanding-runtime + COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/tools/freestanding_runtime_contract.py" + --compiler $ --assembler $ + --archive $ + --cxx "${CMAKE_CXX_COMPILER}") + set_tests_properties(nil.freestanding-runtime PROPERTIES + LABELS "native;abi;runtime;rc" SKIP_RETURN_CODE 77 TIMEOUT 300) + endif() add_test(NAME nil.ui-models COMMAND $ run --compiler $ --interpreter $ diff --git a/nilassembler/main.cpp b/nilassembler/main.cpp index 88e871d..6995f0a 100644 --- a/nilassembler/main.cpp +++ b/nilassembler/main.cpp @@ -42,18 +42,22 @@ struct command_line { bool version = false; bool unmanaged = false; bool freestanding = false; + bool no_red_zone = false; + std::string emit_llvm; bool embed_context = false; }; void print_usage(std::ostream &stream) { stream << "Usage: nilassembler [-o ] [--unmanaged] [--freestanding]" - " [--embed-context] \n" + " [--no-red-zone] [--emit-llvm ] [--embed-context] \n" << "\n" << "Options:\n" << " -o, --output Write the host relocatable object to \n" << " --unmanaged Use manual native memory management\n" << " --freestanding Emit the entry as __ny_entry() with no C main wrapper\n" + << " --no-red-zone Mark generated definitions noredzone\n" + << " --emit-llvm Also write the generated LLVM IR\n" << " --embed-context Retain AI annotations in x86_64 ELF/COFF or x86_64/arm64 Mach-O objects\n" << " --version Show the nilassembler version\n" << " -h, --help Show this help\n"; @@ -65,6 +69,8 @@ bool parse_command_line(int argc, char **argv, command_line &result, bool output_seen = false; bool unmanaged_seen = false; bool freestanding_seen = false; + bool no_red_zone_seen = false; + bool emit_llvm_seen = false; bool embed_context_seen = false; for (int index = 1; index < argc; ++index) { const std::string argument = argv[index]; @@ -106,6 +112,32 @@ bool parse_command_line(int argc, char **argv, command_line &result, result.freestanding = true; continue; } + if (options && argument == "--no-red-zone") { + if (no_red_zone_seen) { + error = "the no-red-zone option was provided more than once"; + return false; + } + no_red_zone_seen = true; + result.no_red_zone = true; + continue; + } + if (options && argument == "--emit-llvm") { + if (emit_llvm_seen) { + error = "the emit-llvm option was provided more than once"; + return false; + } + if (++index >= argc) { + error = "missing IR path after " + argument; + return false; + } + result.emit_llvm = argv[index]; + if (result.emit_llvm.empty()) { + error = "the IR path must not be empty"; + return false; + } + emit_llvm_seen = true; + continue; + } if (options && argument == "--embed-context") { if (embed_context_seen) { error = "the embed-context option was provided more than once"; @@ -145,7 +177,8 @@ bool parse_command_line(int argc, char **argv, command_line &result, if (result.help || result.version) { if (!result.input.empty() || output_seen || unmanaged_seen || - freestanding_seen || embed_context_seen || + freestanding_seen || no_red_zone_seen || emit_llvm_seen || + embed_context_seen || (result.help && result.version)) { error = "--help and --version must be used without input or output paths"; return false; @@ -415,6 +448,7 @@ int run_assembler(const command_line &arguments) { native.setMemoryMode(arguments.unmanaged ? ny::MemoryMode::UNSAFE_MANUAL : ny::MemoryMode::SAFE_GC); native.setFreestandingEntry(arguments.freestanding); + native.setDisableRedZone(arguments.no_red_zone); native.setEmbedContext(arguments.embed_context); if (!native.initialize()) { std::cerr << "nilassembler: failed to initialize the LLVM target\n"; @@ -424,6 +458,10 @@ int run_assembler(const command_line &arguments) { std::cerr << "nilassembler: native lowering failed\n"; return 1; } + if (!arguments.emit_llvm.empty() && !native.emitLlvmIr(arguments.emit_llvm)) { + std::cerr << "nilassembler: could not write LLVM IR\n"; + return 1; + } if (!native.emitObjectFile(workspace->object().string())) { std::cerr << "nilassembler: object emission failed\n"; return 1; diff --git a/nilcompiler/src/llvm_backend.cpp b/nilcompiler/src/llvm_backend.cpp index 9384836..02fd19c 100644 --- a/nilcompiler/src/llvm_backend.cpp +++ b/nilcompiler/src/llvm_backend.cpp @@ -1196,6 +1196,7 @@ struct NativeCodegen::Impl { MemoryMode memory_mode = MemoryMode::UNSAFE_MANUAL; bool embed_context = false; bool freestanding_entry = false; + bool disable_red_zone = false; llvm::Function *current_function = nullptr; // State matching generateModule usage @@ -1373,6 +1374,27 @@ void NativeCodegen::setFreestandingEntry(bool enabled) { impl_->freestanding_entry = enabled; } +void NativeCodegen::setDisableRedZone(bool enabled) { + impl_->disable_red_zone = enabled; +} + +bool NativeCodegen::emitLlvmIr(const std::string &path) { + if (!impl_->module) { + std::cerr << "[NativeCodegen] no module to write\n"; + return false; + } + std::error_code code; + llvm::raw_fd_ostream out(path, code, llvm::sys::fs::OF_Text); + if (code) { + std::cerr << "[NativeCodegen] could not write LLVM IR: " << code.message() + << '\n'; + return false; + } + impl_->module->print(out, nullptr); + out.flush(); + return !out.has_error(); +} + bool NativeCodegen::initialize() { llvm::InitializeNativeTarget(); llvm::InitializeNativeTargetAsmPrinter(); @@ -9007,6 +9029,13 @@ bool NativeCodegen::generateModule(const nil_module &mod) { llvm::appendToUsed(*impl_->module, {manifest}); } + if (impl_->disable_red_zone) { + for (auto &function : *impl_->module) { + if (function.isDeclaration()) continue; + function.addFnAttr(llvm::Attribute::NoRedZone); + } + } + std::string err; llvm::raw_string_ostream err_s(err); if (llvm::verifyModule(*impl_->module, &err_s)) { diff --git a/nilcompiler/src/llvm_backend.hpp b/nilcompiler/src/llvm_backend.hpp index f6496aa..2fffebc 100644 --- a/nilcompiler/src/llvm_backend.hpp +++ b/nilcompiler/src/llvm_backend.hpp @@ -56,6 +56,17 @@ class NativeCodegen { // initialisation, user main, context end -- is unchanged. void setFreestandingEntry(bool enabled); + // Mark every generated definition `noredzone`, so no leaf function uses + // the 128 bytes below the stack pointer. A kernel or interrupt-reentrant + // target needs that; a user-space target whose interrupt entry switches + // stacks does not, so this stays independent of the freestanding entry + // rather than being implied by it. + void setDisableRedZone(bool enabled); + + // Write the generated LLVM IR, so what the backend produced can be + // inspected and asserted rather than inferred from an object. + bool emitLlvmIr(const std::string &path); + // Opt in to a retained, read-only context manifest on supported native // targets. Annotation contents are embedded verbatim; the default is off. void setEmbedContext(bool enabled); diff --git a/nilruntime-freestanding/freestanding_runtime.cpp b/nilruntime-freestanding/freestanding_runtime.cpp new file mode 100644 index 0000000..4a478b2 --- /dev/null +++ b/nilruntime-freestanding/freestanding_runtime.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2008 - 2026 Execute Software. All rights reserved. + * SPDX-License-Identifier: MIT + */ +// The native runtime ABI for a target with no operating system. +// +// An object emitted by `nilassembler --freestanding` imports exactly five +// symbols -- nyrt_abi_version, nyrt_context_begin, nyrt_context_end, +// nyrt_fail and nyrt_profile_site -- and nothing else. This translation unit +// supplies them without calling into libc, a kernel, or an allocator, so a +// freestanding host can link it instead of reimplementing the boundary or +// satisfying it with stubs that fail if reached. +// +// What it deliberately does not do: allocate, format, read a clock, or touch +// a device. Those belong to a host. nyrt_fail reports through a weak hook the +// host may define; the default stops the caller rather than returning into a +// program whose invariants have already been broken. +// +// pinned: this file must not gain an #include of a hosted header. The +// freestanding link test asserts the resulting archive imports nothing. +#include + +namespace { + +// Recorded for a host that wants them; nothing here interprets them. +int entry_argc = 0; +const char *const *entry_argv = nullptr; +bool context_active = false; + +} // namespace + +extern "C" { + +// A host that can report a failure defines this. The default below is weak so +// linking the archive alone still produces a complete program. +__attribute__((weak)) void __ny_host_fail(const char *message) noexcept; + +// Must equal the version the generated entry checks for; a mismatch makes the +// entry call nyrt_fail before running any user code. +std::uint32_t nyrt_abi_version() noexcept { return 1; } + +void nyrt_context_begin(int argc, const char *const *argv) noexcept { + entry_argc = argc; + entry_argv = argv; + context_active = true; +} + +void nyrt_context_end() noexcept { + context_active = false; + entry_argc = 0; + entry_argv = nullptr; +} + +// Profiling attribution is a hosted capture facility. Accepting and ignoring +// the call keeps generated code identical across hosted and freestanding +// builds, which is the point of the boundary. +void nyrt_profile_site(const char *file, const char *function, + std::uint64_t line) noexcept { + (void)file; + (void)function; + (void)line; +} + +[[noreturn]] void nyrt_fail(const char *message) noexcept { + if (__ny_host_fail) __ny_host_fail(message); + // No host reporter, or one that returned anyway: a failed program must not + // continue. Stop here rather than unwinding into broken state. + for (;;) { + } +} + +// Reads what the entry recorded. Not part of the five imported symbols; a +// host links this only if it wants the values. +int __ny_entry_argc() noexcept { return entry_argc; } +const char *const *__ny_entry_argv() noexcept { return entry_argv; } +int __ny_context_active() noexcept { return context_active ? 1 : 0; } + +} // extern "C" diff --git a/notebook/2026-11-09-anomalous-abi.md b/notebook/2026-11-09-anomalous-abi.md new file mode 100644 index 0000000..9e08e6d --- /dev/null +++ b/notebook/2026-11-09-anomalous-abi.md @@ -0,0 +1,129 @@ +# Anomalous ABI: freestanding native targets + +Working log for making NIL emit code that an Anomalous vessel can consume. +Anomalous is a separate project at `exec-anomalous`, an experimental operating +system in Rust that has adopted Ny as its implementation language (its ADR +0016). It will eventually support several major ABIs and also ships its own; +its own is the one targeted here. + +## What the Anomalous ABI is + +Two layers, neither of them a calling convention in the usual sense. + +**Wire types** live in `crates/anomalous-abi`, a `no_std`, allocation-free +crate holding data layout only. `rite_call` is `#[repr(C)]`: `header_size`, +`operation`, `payload_kind`, `reserved`, `rights_present: u64`, +`payload_size`, `payload_limit`, `trace_id: id_128`, with payload bytes +following. `rite_status` is a `u16` with `ok`, `would_block`, `denied`, +`bad_operation`, `bad_payload`, `limit_exceeded`, `interrupted`, `faulted`. +The crate states the ABI is not stable while Anomalous is pre-alpha. + +**The rite gate** is the kernel/user boundary (their ADR 0019). A vessel +writes the call into a fixed mailbox, zeroes scratch registers, and issues +`int $0xf3`; the scheduler gate is `0xf2`. The reply is read back from the +mailbox: forty bytes of `header_size`, `status`, `sequence`, `trace_id`. The +first operations are `console_write`, `input_read`, `task_exit`, `task_yield` +and `display_update`, each gated by one right bit, failing closed. + +The useful consequence: this ABI is struct layout plus one interrupt. NIL +needs no new calling convention for it. What it needed was to stop dragging a +hosted runtime along. + +## Why the work was NIL-side + +Anomalous ADR 0049 qualifies a bounded freestanding Ny object and records +exactly what that cost them. The SDK emitted Linux host-targeted ELF plus a +generated C `main(int, char **)` wrapper, so a "separate narrow assembly shim +calls the generated C wrapper with zero arguments and implements only its +observed ABI-version, context-begin, context-end and failure hooks". The shape +was observed because nothing published one. The compiler's "unconditional +unused string helper imports `strlen`, `calloc`, and `memcpy`", which they +satisfied with fatal trap stubs that fail the proof if reached. The ordinary +runtime assumed hosted allocation, OS services and TLS, which "would silently +exceed the qualified kernel profile". And "Ny has no red-zone-disabling CLI +option". + +Every one of those is a NIL emission problem, and every one is testable on +Linux by inspecting what the toolchain produces. None of it needed a Mac, a +VM, or CI. + +## What changed + +- **The string helper is built on first use.** `__ny_string_concat` was + created in every module while its only caller looked it up on demand, so + `strlen`, `memcpy` and `calloc` were undefined in the object of a program + that never concatenated anything. An object for such a program now imports + exactly the five native runtime hooks and no libc at all. +- **`nilassembler --freestanding`** emits the same entry sequence -- runtime + ABI check, context begin, global initialisation, user main, context end -- + as `__ny_entry()` taking no arguments, defining no `main`. The argc/argv + derivation is skipped rather than fed zeroes, so no argument-vector code is + emitted at all. +- **`nilassembler --no-red-zone`** marks every generated definition + `noredzone`. Deliberately independent of `--freestanding`: the two answer + different questions, and ADR 0049 describes a working configuration whose + userspace red zone is fine because interrupt entry switches stacks. +- **`nilassembler --emit-llvm `** writes the generated IR. The red-zone + attribute does not survive into an object, so without this the guarantee + could only be asserted, not checked. +- **`nilruntime_freestanding`** implements the five hooks with no libc, + kernel or allocator. The archive imports nothing but a weak + `__ny_host_fail`, which a host defines to observe a failure and which + defaults to stopping the caller. It deliberately does not allocate, format, + read a clock or touch a device. + +## What is actually proved + +`nil.native-symbol-surface` reads the ELF symbol table directly, so it needs +no binutils. It pins that a plain object imports only +`nyrt_abi_version`, `nyrt_context_begin`, `nyrt_context_end`, `nyrt_fail` and +`nyrt_profile_site`; that a concatenating program still pulls the helper's +dependencies back, so the first assertion cannot pass by the helper having +been dropped entirely; that a hosted object is entered through `main` and a +freestanding one through `__ny_entry` with no `main`; and that `noredzone` +reaches every definition, checked through the attribute groups the +definitions reference rather than by grepping for the word. + +`nil.freestanding-runtime` links the emitted object and the archive with +`-nostdlib` and its own `_start`, so a hosted toolchain cannot satisfy a +symbol by accident -- if either side still needed libc the link fails rather +than succeeding quietly on the build host -- then runs the program and +requires the exit status to be the value Ny returned. It also links a program +that replaces the weak reporter, since a hook that cannot be overridden is no +use to a host. + +Linux stands at 574 registered, 0 failed, 3 environment skips. + +## What is not proved + +Nothing here shows that a vessel boots under the Anomalous kernel or issues a +rite. That needs the `int $0xf3` path and their repository. What these changes +remove is the reason they needed a reverse-engineered shim and trap stubs. + +## Open, in the order they probably matter + +1. **Allocation.** The moment a vessel concatenates a string it needs + `calloc`, and the freestanding runtime deliberately has none. A bump + allocator in the runtime, or a host-delegated hook, is a decision about who + owns vessel memory rather than a gap to fill quietly. The maintainer + expects later features to need the shipped runtime, so this is the next + real question. +2. **A written ABI document.** The contract is currently pinned by tests and + described here. Anomalous should be able to read it rather than infer it + from our test file: the five hooks and their signatures, `__ny_entry`, the + flags, and what a host must supply. +3. **Rite bindings stay in Anomalous.** Agreed with the maintainer: their ABI + is theirs and is explicitly unstable, so it should not enter `nilstd`. NIL + supplies the capability -- freestanding objects, exact record layout, + inline assembly, no unconditional imports. +4. `docs/release/v1-profile.md` still lists freestanding targets as not + qualified for release. That remains true and deliberate; qualification is a + separate decision from capability. + +## Branch state + +All of the above is on `anomalous-abi-symbol-surface`, pushed, unmerged. It +also carries `72c9547`, the macOS desktop acceptance record, because the +branch was cut from `macos-ui-acceptance-record` before that merged. Merging +this branch therefore brings the macOS documentation with it and makes +`macos-ui-acceptance-record` redundant. diff --git a/tests/tools/freestanding_runtime_contract.py b/tests/tools/freestanding_runtime_contract.py new file mode 100644 index 0000000..5f44aa1 --- /dev/null +++ b/tests/tools/freestanding_runtime_contract.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python3 +"""Link and run a freestanding program with no C library at all. + +`nilassembler --freestanding` emits an object importing only the five native +runtime hooks, and nilruntime_freestanding supplies them. This builds the two +together with -nostdlib and its own `_start`, so nothing from a hosted +toolchain can satisfy a symbol by accident: if either side still needed libc, +the link fails rather than quietly succeeding on the build host. + +Running it then proves the entry sequence itself works -- runtime ABI check, +context begin, user main, context end -- because the process exit status is +the value Ny returned. +""" +from __future__ import annotations + +import argparse +from pathlib import Path +import subprocess +import sys +import tempfile + +# A value with no special meaning, chosen so a zero from some other path +# cannot be mistaken for success. +expected_exit = 7 + +driver_source = """ +extern "C" int __ny_entry(); + +// No C runtime is linked, so this is the process entry. Exit through the +// kernel directly; returning would have nowhere to go. +extern "C" [[noreturn]] void _start() { + const long code = __ny_entry(); + asm volatile("syscall" :: "a"(60L), "D"(code) : "rcx", "r11", "memory"); + __builtin_unreachable(); +} +""" + +# Linking succeeds with the weak default in place; this one replaces it, which +# is how a host reports a failure instead of stopping silently. +host_fail_source = """ +extern "C" int __ny_entry(); +extern "C" void __ny_host_fail(const char *message) { (void)message; } + +extern "C" [[noreturn]] void _start() { + const long code = __ny_entry(); + asm volatile("syscall" :: "a"(60L), "D"(code) : "rcx", "r11", "memory"); + __builtin_unreachable(); +} +""" + + +def run(command, timeout=180): + result = subprocess.run(list(map(str, command)), stdin=subprocess.DEVNULL, + capture_output=True, text=True, timeout=timeout) + return result + + +def checked(command, timeout=180): + result = run(command, timeout) + assert result.returncode == 0, (command, result.returncode, result.stdout, result.stderr) + return result + + +def build(compiler, assembler, archive, cxx, root: Path, name: str, driver: str) -> Path: + source = root / f'{name}.ny' + source.write_text(f'fn main() -> i64 {{\n return {expected_exit};\n}}\n', newline='\n') + nil = root / f'{name}.nil' + obj = root / f'{name}.o' + checked([compiler, '--no-stdlib', '--no-bundle', '--unmanaged', '-o', nil, source]) + checked([assembler, '--unmanaged', '--freestanding', '-o', obj, nil]) + driver_path = root / f'{name}_driver.cpp' + driver_path.write_text(driver, newline='\n') + program = root / name + checked([cxx, '-nostdlib', '-static', '-fno-exceptions', '-fno-rtti', + '-o', program, driver_path, obj, archive]) + return program + + +def main() -> int: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--compiler', type=Path, required=True) + parser.add_argument('--assembler', type=Path, required=True) + parser.add_argument('--archive', type=Path, required=True) + parser.add_argument('--cxx', type=Path, required=True) + args = parser.parse_args() + if sys.platform != 'linux': + print('SKIP: the freestanding link contract is exercised on ELF hosts') + return 77 + + checks = 0 + with tempfile.TemporaryDirectory(prefix='nil-freestanding-') as directory: + root = Path(directory) + + program = build(args.compiler, args.assembler, args.archive, args.cxx, + root, 'plain', driver_source) + checks += 1 # linking with -nostdlib at all is the first assertion + + result = run([program], timeout=60) + assert result.returncode == expected_exit, ( + 'the freestanding program must run and return what Ny returned; ' + f'got {result.returncode}, stderr: {result.stderr!r}') + checks += 1 + + # The failure reporter is weak so the archive links alone, and + # replaceable so a host can observe a failure. + overridden = build(args.compiler, args.assembler, args.archive, args.cxx, + root, 'reporter', host_fail_source) + checks += 1 + result = run([overridden], timeout=60) + assert result.returncode == expected_exit, ( + 'defining the host failure reporter must not change ordinary execution; ' + f'got {result.returncode}') + checks += 1 + + print(f'Freestanding runtime: {checks} checks passed') + return 0 + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/tests/tools/native_symbol_surface.py b/tests/tools/native_symbol_surface.py index 2dfccfb..0d9410f 100644 --- a/tests/tools/native_symbol_surface.py +++ b/tests/tools/native_symbol_surface.py @@ -82,8 +82,31 @@ def text(table_offset: int, index: int) -> str: return undefined, exported +def definitions_without_noredzone(ir: Path) -> list[str]: + """Definitions in the IR whose attribute group lacks noredzone. + + Checked through the attribute groups the definitions actually reference, + because the bare word appearing somewhere in the file would also be true + if a single function carried it. + """ + groups_with: set[str] = set() + definitions: list[tuple[str, str]] = [] + for line in ir.read_text().splitlines(): + if line.startswith('attributes #'): + name = line.split('=')[0].strip().removeprefix('attributes ') + if 'noredzone' in line: + groups_with.add(name) + elif line.startswith('define'): + head = line.split('{')[0].split() + group = next((piece for piece in head if piece.startswith('#')), '') + definitions.append((line.split('(')[0].split()[-1], group)) + assert definitions, f'no definitions found in {ir}' + return [name for name, group in definitions if group not in groups_with] + + def emit(compiler: Path, assembler: Path, root: Path, name: str, source: str, - freestanding: bool = False): + freestanding: bool = False, no_red_zone: bool = False, + ir: Path | None = None): path = root / f'{name}.ny' path.write_text(source, newline='\n') nil = root / f'{name}.nil' @@ -91,6 +114,10 @@ def emit(compiler: Path, assembler: Path, root: Path, name: str, source: str, assemble = [assembler, '--unmanaged'] if freestanding: assemble.append('--freestanding') + if no_red_zone: + assemble.append('--no-red-zone') + if ir is not None: + assemble += ['--emit-llvm', str(ir)] for command in ([compiler, '--no-stdlib', '--no-bundle', '--unmanaged', '-o', nil, path], assemble + ['-o', obj, nil]): result = subprocess.run(list(map(str, command)), stdin=subprocess.DEVNULL, @@ -155,6 +182,23 @@ def main() -> int: f'unexpected: {sorted(free - runtime_abi)}') checks += 1 + # The red zone is a separate decision from the entry shape: a target + # whose interrupt entry switches stacks keeps it, a kernel-reentrant + # one cannot. So it is its own option and is checked on its own. + hosted_ir = root / 'hosted.ll' + emit(args.compiler, args.assembler, root, 'hosted_ir', trivial, ir=hosted_ir) + assert definitions_without_noredzone(hosted_ir), ( + 'the red zone stays available unless it is turned off') + checks += 1 + guarded_ir = root / 'guarded.ll' + emit(args.compiler, args.assembler, root, 'guarded_ir', trivial, + freestanding=True, no_red_zone=True, ir=guarded_ir) + missing = definitions_without_noredzone(guarded_ir) + assert not missing, ( + 'every generated definition must carry noredzone when it is requested; ' + f'without it: {missing}') + checks += 1 + print(f'Native symbol surface: {checks} checks passed') return 0