mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
wasm linker: handle weak globals in relocs
This commit is contained in:
parent
7a4d4357e8
commit
d9d49ce995
@ -441,6 +441,14 @@ pub const GlobalIndex = enum(u32) {
|
||||
return @enumFromInt(wasm.globals.getIndex(.fromObjectGlobal(wasm, i)).?);
|
||||
}
|
||||
|
||||
pub fn fromObjectGlobalHandlingWeak(wasm: *const Wasm, index: ObjectGlobalIndex) GlobalIndex {
|
||||
const global = index.ptr(wasm);
|
||||
return if (global.flags.binding == .weak)
|
||||
fromSymbolName(wasm, global.name.unwrap().?)
|
||||
else
|
||||
fromObjectGlobal(wasm, index);
|
||||
}
|
||||
|
||||
pub fn fromSymbolName(wasm: *const Wasm, name: String) GlobalIndex {
|
||||
const import = wasm.object_global_imports.getPtr(name).?;
|
||||
return @enumFromInt(wasm.globals.getIndex(import.resolution).?);
|
||||
|
||||
@ -1477,8 +1477,8 @@ fn applyRelocs(code: []u8, code_offset: u32, relocs: Wasm.ObjectRelocation.Itera
|
||||
.table_import_index_sleb => @panic("TODO indirect function table needs to support object functions too"),
|
||||
.table_import_index_sleb64 => @panic("TODO indirect function table needs to support object functions too"),
|
||||
|
||||
.global_index_i32 => reloc_u32_global(sliced_code, .fromObjectGlobal(wasm, pointee.global)),
|
||||
.global_index_leb => reloc_leb_global(sliced_code, .fromObjectGlobal(wasm, pointee.global)),
|
||||
.global_index_i32 => reloc_u32_global(sliced_code, .fromObjectGlobalHandlingWeak(wasm, pointee.global)),
|
||||
.global_index_leb => reloc_leb_global(sliced_code, .fromObjectGlobalHandlingWeak(wasm, pointee.global)),
|
||||
|
||||
.global_import_index_i32 => reloc_u32_global(sliced_code, .fromSymbolName(wasm, pointee.symbol_name)),
|
||||
.global_import_index_leb => reloc_leb_global(sliced_code, .fromSymbolName(wasm, pointee.symbol_name)),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user