fix(gpu): link AIR modules deployed to other versions of the same target

This commit is contained in:
Tyler Smith committed 2026-11-07 00:02:26 +00:00
1 parent 22d813ce3e
commit 34148b141c
2 files changed
+27 -1

No files matched your search

@@ -29,6 +29,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
/* Beyond any call chain Metal compiles, it bounds the walk of hostile input,
@@ -424,6 +425,19 @@ hide_entry_points(struct stela_air_metadata *m)
return true;
}
/* Whether two target triples name one target, whatever their deployment
* versions: air64_v29-apple-macosx27.0.0 links with ...-macosx27.2.0. */
static bool
same_target(const char *a, const char *b)
{
size_t a_bytes = strlen(a), b_bytes = strlen(b);
while (a_bytes && (isdigit((unsigned char)a[a_bytes - 1]) || a[a_bytes - 1] == '.'))
a_bytes--;
while (b_bytes && (isdigit((unsigned char)b[b_bytes - 1]) || b[b_bytes - 1] == '.'))
b_bytes--;
return a_bytes == b_bytes && !memcmp(a, b, a_bytes);
}
/* Whether module is valid AIR compiled as m's module was, after
* specializing its function constants with values. */
static bool
@@ -437,7 +451,7 @@ prepared(struct stela_air_metadata *m, LLVMModuleRef module,
LLVMDisposeMessage(verification);
if (!verified || !stela_air_metadata_layout(&linked) || !stela_air_metadata_validate(&linked))
return fail(m, STELA_AIR_INPUT, "a linked module is not valid AIR");
if (strcmp(LLVMGetTarget(module), LLVMGetTarget(m->module)) ||
if (!same_target(LLVMGetTarget(module), LLVMGetTarget(m->module)) ||
strcmp(LLVMGetDataLayoutStr(module), LLVMGetDataLayoutStr(m->module)) ||
linked.air_major != m->air_major || linked.air_minor != m->air_minor ||
linked.language_major != m->language_major ||
@@ -2592,6 +2592,18 @@ linked_functions_resolve_tables_and_externals(void)
shader = compile_linked(sized, "tables", &linked, 1, functions, 3, &error);
assert(shader);
stela_metal_release(shader);
/* A library deployed to another version of the same target links. */
static const char *redeployed_linked =
"target triple = \"air64_v29-apple-macosx27.0.0\"\n"
"define i32 @external(i32 %x) {\n%y = add i32 %x, 7\nret i32 %y\n}\n"
"define i32 @negated(i32 %x) {\n%y = sub i32 0, %x\nret i32 %y\n}\n"
"define i64 @wide(i64 %x) {\nret i64 %x\n}\n"
"!air.visible = !{}\n";
shader = compile_linked(tables, "tables", &redeployed_linked, 1, functions, 3, &error);
if (!shader)
fprintf(stderr, "redeployed: %u %s\n", error.kind, error.detail);
assert(shader);
stela_metal_release(shader);
shader = compile_linked(tested, "tables", &linked, 1, functions, 3, &error);
if (!shader)
fprintf(stderr, "tested: %u %s\n", error.kind, error.detail);