aot pass all tests

This commit is contained in:
2026-02-18 16:53:33 -06:00
parent 469b7ac478
commit c33c35de87
6 changed files with 583 additions and 149 deletions

View File

@@ -80,6 +80,17 @@ function content_hash(str) {
return text(crypto.blake2(bb, 32), 'h')
}
// Bump when native codegen/runtime ABI changes so stale dylibs are not reused.
def NATIVE_CACHE_VERSION = "native-v8"
// Enable AOT ASan by creating .cell/asan_aot in the package root.
function native_sanitize_flags() {
if (fd.is_file('.cell/asan_aot')) {
return ' -fsanitize=address -fno-omit-frame-pointer'
}
return ''
}
function get_build_dir() {
return shop.get_build_dir()
}
@@ -509,7 +520,8 @@ Build.build_static = function(packages, target, output, buildtype) {
// il_parts: {data: text, functions: [text, ...]}
// cc: C compiler path
// tmp_prefix: prefix for temp files (e.g. /tmp/cell_native_<hash>)
function compile_native_single(il_parts, cc, tmp_prefix) {
function compile_native_single(il_parts, cc, tmp_prefix, extra_flags) {
var _extra = extra_flags || ''
var helpers_il = (il_parts.helpers && length(il_parts.helpers) > 0)
? text(il_parts.helpers, "\n") : ""
var all_fns = text(il_parts.functions, "\n")
@@ -519,7 +531,7 @@ function compile_native_single(il_parts, cc, tmp_prefix) {
var o_path = tmp_prefix + '.o'
var rc = null
fd.slurpwrite(s_path, stone(blob(asm_text)))
rc = os.system(cc + ' -c ' + s_path + ' -o ' + o_path)
rc = os.system(cc + _extra + ' -c ' + s_path + ' -o ' + o_path)
if (rc != 0) {
print('Assembly failed'); disrupt
}
@@ -572,6 +584,8 @@ Build.compile_native = function(src_path, target, buildtype, pkg) {
var tc = toolchains[_target]
var dylib_ext = tc.system == 'windows' ? '.dll' : (tc.system == 'darwin' ? '.dylib' : '.so')
var cc = tc.c
var san_flags = native_sanitize_flags()
var san_suffix = length(san_flags) > 0 ? '_asan' : ''
// Step 1: Compile through pipeline
var optimized = shop.compile_file(src_path)
@@ -586,7 +600,7 @@ Build.compile_native = function(src_path, target, buildtype, pkg) {
var il_parts = qbe_emit(optimized, qbe_macros, sym_name)
// Content hash for cache key
var hash = content_hash(text(fd.slurp(src_path)) + '\n' + _target + '\nnative')
var hash = content_hash(text(fd.slurp(src_path)) + '\n' + _target + '\nnative\n' + NATIVE_CACHE_VERSION + '\n' + san_flags)
var build_dir = get_build_dir()
ensure_dir(build_dir)
@@ -596,22 +610,22 @@ Build.compile_native = function(src_path, target, buildtype, pkg) {
// Compile and assemble via batched parallel pipeline
var tmp = '/tmp/cell_native_' + hash
var rt_o_path = '/tmp/cell_qbe_rt.o'
var rt_o_path = '/tmp/cell_qbe_rt' + san_suffix + '.o'
var o_paths = compile_native_single(il_parts, cc, tmp)
var o_paths = compile_native_single(il_parts, cc, tmp, san_flags)
// Compile QBE runtime stubs if needed
var rc = null
if (!fd.is_file(rt_o_path)) {
qbe_rt_path = shop.get_package_dir('core') + '/qbe_rt.c'
rc = os.system(cc + ' -c ' + qbe_rt_path + ' -o ' + rt_o_path + ' -fPIC')
rc = os.system(cc + san_flags + ' -c ' + qbe_rt_path + ' -o ' + rt_o_path + ' -fPIC')
if (rc != 0) {
print('QBE runtime stubs compilation failed'); disrupt
}
}
// Link dylib
var link_cmd = cc + ' -shared -fPIC'
var link_cmd = cc + san_flags + ' -shared -fPIC'
if (tc.system == 'darwin') {
link_cmd = link_cmd + ' -undefined dynamic_lookup'
} else if (tc.system == 'linux') {
@@ -658,6 +672,8 @@ Build.compile_native_ir = function(optimized, src_path, opts) {
var tc = toolchains[_target]
var dylib_ext = tc.system == 'windows' ? '.dll' : (tc.system == 'darwin' ? '.dylib' : '.so')
var cc = tc.c
var san_flags = native_sanitize_flags()
var san_suffix = length(san_flags) > 0 ? '_asan' : ''
var qbe_macros = use('qbe')
var qbe_emit = use('qbe_emit')
@@ -669,7 +685,7 @@ Build.compile_native_ir = function(optimized, src_path, opts) {
var il_parts = qbe_emit(optimized, qbe_macros, sym_name)
var src = text(fd.slurp(src_path))
var hash = content_hash(src + '\n' + _target + '\nnative')
var hash = content_hash(src + '\n' + _target + '\nnative\n' + NATIVE_CACHE_VERSION + '\n' + san_flags)
var build_dir = get_build_dir()
ensure_dir(build_dir)
@@ -679,22 +695,22 @@ Build.compile_native_ir = function(optimized, src_path, opts) {
// Compile and assemble via batched parallel pipeline
var tmp = '/tmp/cell_native_' + hash
var rt_o_path = '/tmp/cell_qbe_rt.o'
var rt_o_path = '/tmp/cell_qbe_rt' + san_suffix + '.o'
var o_paths = compile_native_single(il_parts, cc, tmp)
var o_paths = compile_native_single(il_parts, cc, tmp, san_flags)
// Compile QBE runtime stubs if needed
var rc = null
if (!fd.is_file(rt_o_path)) {
qbe_rt_path = shop.get_package_dir('core') + '/qbe_rt.c'
rc = os.system(cc + ' -c ' + qbe_rt_path + ' -o ' + rt_o_path + ' -fPIC')
rc = os.system(cc + san_flags + ' -c ' + qbe_rt_path + ' -o ' + rt_o_path + ' -fPIC')
if (rc != 0) {
print('QBE runtime stubs compilation failed'); disrupt
}
}
// Link dylib
var link_cmd = cc + ' -shared -fPIC'
var link_cmd = cc + san_flags + ' -shared -fPIC'
if (tc.system == 'darwin') {
link_cmd = link_cmd + ' -undefined dynamic_lookup'
} else if (tc.system == 'linux') {