Hello! I am writing a compiler for Scheme and have to initialize GLOBALS array for GC to trace globals. This array is initialized like this:
let globals_array = self
.module
.declare_data("CAPY_GLOBALS", Linkage::Export, false, false)
.unwrap();
let mut desc = DataDescription::new();
desc.set_align(size_of::<usize>() as _);
let datas = self
.constants
.values()
.copied()
.chain(self.cache_cells.values().copied());
let mut offset = 0;
for data in datas {
let gv = self.module.declare_data_in_data(data, &mut desc);
desc.write_data_addr(offset, gv, 0);
offset += 8;
}
desc.define_zeroinit(offset as usize);
self.module.define_data(globals_array, &desc).unwrap();
but when I load produced shared-library using dlopen and then dlsym the array it is not populated with anyfing but fully zeroed, is that expected?
what would be the correct way to put addresses of all constants into that array?
Oh apparently I had to use .define(vec![0; offset]) instead of zeroinit, that makes this thing work properly.
Adel Prokurov has marked this topic as resolved.
Last updated: Dec 06 2025 at 07:03 UTC