aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-07-27 15:47:25 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-07-27 15:47:25 -0700
commit66e5920dc3411daa4f0c84a8f4c733c1263e8523 (patch)
tree5838e1cd317a49591080fb038f96c085ba46acbe /src/codegen
parenta2eb91c42294ef380d70742e1111e4dc36ab2192 (diff)
downloadzig-66e5920dc3411daa4f0c84a8f4c733c1263e8523.tar.gz
zig-66e5920dc3411daa4f0c84a8f4c733c1263e8523.zip
llvm backend: LLVMGetNamedGlobalAlias requires a null terminated string
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/llvm.zig8
-rw-r--r--src/codegen/llvm/bindings.zig5
2 files changed, 8 insertions, 5 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index 2468b1dbde..74a51e6634 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -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;
}
diff --git a/src/codegen/llvm/bindings.zig b/src/codegen/llvm/bindings.zig
index d63a75d8bd..6d09d69447 100644
--- a/src/codegen/llvm/bindings.zig
+++ b/src/codegen/llvm/bindings.zig
@@ -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;
};