elf: implement exporting anon decls

This commit is contained in:
Jakub Konka 2023-10-29 13:28:17 +01:00
parent 209fd8cb93
commit eaca72534c
2 changed files with 16 additions and 4 deletions

View File

@ -3585,8 +3585,21 @@ pub fn updateExports(
_ = try self.getOrCreateMetadataForDecl(decl_index);
break :blk self.decls.getPtr(decl_index).?;
},
// TODO is it possible to request export before const being lowered?
.value => |value| self.anon_decls.getPtr(value).?,
.value => |value| self.anon_decls.getPtr(value) orelse blk: {
const first_exp = exports[0];
const res = try self.lowerAnonDecl(value, .none, first_exp.getSrcLoc(mod));
switch (res) {
.ok => {},
.fail => |em| {
// TODO maybe it's enough to return an error here and let Module.processExportsInner
// handle the error?
try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
mod.failed_exports.putAssumeCapacityNoClobber(first_exp, em);
return;
},
}
break :blk self.anon_decls.getPtr(value).?;
},
};
const sym_index = metadata.symbol_index;
const esym_index = self.symbol(sym_index).esym_index;

View File

@ -70,8 +70,7 @@ test "exporting comptime-known value" {
test "exporting comptime var" {
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
// if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;