rtl: fix LinkerSet on release builds

LLVM seemed to like doing DCE on those symbols, so export them to
ensure they are used. The `Tag` mess is because we need to generate
a unique symbol name, and the pointer cast is so we can export e.g zig
functions. This is messy.
This commit is contained in:
Loïc Grégoire
2026-07-12 17:15:48 -04:00
parent 2a38cd4f4d
commit f6dec9f334
+16 -3
View File
@@ -26,12 +26,25 @@ pub fn LinkerSet(name: []const u8, comptime T: type) type {
return arr[0..n];
}
pub fn insert(elem: T) type {
pub fn insert(comptime elem: T) type {
const U = struct {
var storage: T linksection("set_" ++ name) = elem;
var storage: T = elem;
fn Tag(comptime e: T) type {
return struct {
const tagged = e;
};
}
comptime {
_ = &storage;
// What the fuck?
@export(
@as(*const usize, @ptrCast(&storage)),
.{
.name = "_set_elem_" ++ name ++ "_" ++ @typeName(Tag(elem)),
.section = "set_" ++ name,
},
);
}
};