llvm backend: LLVMGetNamedGlobalAlias requires a null terminated string

This commit is contained in:
Andrew Kelley 2021-07-27 15:47:25 -07:00
parent a2eb91c422
commit 66e5920dc3
2 changed files with 8 additions and 5 deletions

View File

@ -454,12 +454,12 @@ pub const Object = struct {
// Until then we iterate over existing aliases and make them point
// to the correct decl, or otherwise add a new alias. Old aliases are leaked.
for (exports) |exp| {
if (self.llvm_module.getNamedGlobalAlias(exp.options.name.ptr, exp.options.name.len)) |alias| {
const exp_name_z = try module.gpa.dupeZ(u8, exp.options.name);
defer module.gpa.free(exp_name_z);
if (self.llvm_module.getNamedGlobalAlias(exp_name_z.ptr, exp_name_z.len)) |alias| {
alias.setAliasee(llvm_fn);
} else {
const exp_name_z = try module.gpa.dupeZ(u8, exp.options.name);
defer module.gpa.free(exp_name_z);
const alias = self.llvm_module.addAlias(llvm_fn.typeOf(), llvm_fn, exp_name_z);
_ = alias;
}

View File

@ -193,7 +193,10 @@ pub const Module = opaque {
pub const getNamedGlobalAlias = LLVMGetNamedGlobalAlias;
extern fn LLVMGetNamedGlobalAlias(
M: *const Module,
Name: [*]const u8,
/// Empirically, LLVM will call strlen() on `Name` and so it
/// must be both null terminated and also have `NameLen` set
/// to the size.
Name: [*:0]const u8,
NameLen: usize,
) ?*const Value;
};