authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-27 15:47:25-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-27 15:47:25-07:00
log66e5920dc3411daa4f0c84a8f4c733c1263e8523
tree5838e1cd317a49591080fb038f96c085ba46acbe
parenta2eb91c42294ef380d70742e1111e4dc36ab2192

llvm backend: LLVMGetNamedGlobalAlias requires a null terminated string


2 files changed, 8 insertions(+), 5 deletions(-)

src/codegen/llvm.zig+4-4
...@@ -454,12 +454,12 @@ pub const Object = struct {...@@ -454,12 +454,12 @@ pub const Object = struct {
454 // Until then we iterate over existing aliases and make them point454 // Until then we iterate over existing aliases and make them point
455 // to the correct decl, or otherwise add a new alias. Old aliases are leaked.455 // to the correct decl, or otherwise add a new alias. Old aliases are leaked.
456 for (exports) |exp| {456 for (exports) |exp| {
457 if (self.llvm_module.getNamedGlobalAlias(exp.options.name.ptr, exp.options.name.len)) |alias| {457 const exp_name_z = try module.gpa.dupeZ(u8, exp.options.name);
458 defer module.gpa.free(exp_name_z);
459
460 if (self.llvm_module.getNamedGlobalAlias(exp_name_z.ptr, exp_name_z.len)) |alias| {
458 alias.setAliasee(llvm_fn);461 alias.setAliasee(llvm_fn);
459 } else {462 } else {
460 const exp_name_z = try module.gpa.dupeZ(u8, exp.options.name);
461 defer module.gpa.free(exp_name_z);
462
463 const alias = self.llvm_module.addAlias(llvm_fn.typeOf(), llvm_fn, exp_name_z);463 const alias = self.llvm_module.addAlias(llvm_fn.typeOf(), llvm_fn, exp_name_z);
464 _ = alias;464 _ = alias;
465 }465 }
src/codegen/llvm/bindings.zig+4-1
...@@ -193,7 +193,10 @@ pub const Module = opaque {...@@ -193,7 +193,10 @@ pub const Module = opaque {
193 pub const getNamedGlobalAlias = LLVMGetNamedGlobalAlias;193 pub const getNamedGlobalAlias = LLVMGetNamedGlobalAlias;
194 extern fn LLVMGetNamedGlobalAlias(194 extern fn LLVMGetNamedGlobalAlias(
195 M: *const Module,195 M: *const Module,
196 Name: [*]const u8,196 /// Empirically, LLVM will call strlen() on `Name` and so it
197 /// must be both null terminated and also have `NameLen` set
198 /// to the size.
199 Name: [*:0]const u8,
197 NameLen: usize,200 NameLen: usize,
198 ) ?*const Value;201 ) ?*const Value;
199};202};