diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2023-10-18 18:43:48 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-10-19 16:51:11 -0400 |
| commit | 4d106076c3db840f786460e281aded056053ac35 (patch) | |
| tree | 34b1c1babde7ae4dfafbedf550f04a251927e4c7 /src | |
| parent | 530dc0405c9f48fa3b241f078cf815164e4448ab (diff) | |
| download | zig-4d106076c3db840f786460e281aded056053ac35.tar.gz zig-4d106076c3db840f786460e281aded056053ac35.zip | |
link: initialize llvm before calling the llvm API
Diffstat (limited to 'src')
| -rw-r--r-- | src/codegen/llvm/Builder.zig | 15 | ||||
| -rw-r--r-- | src/link.zig | 2 |
2 files changed, 10 insertions, 7 deletions
diff --git a/src/codegen/llvm/Builder.zig b/src/codegen/llvm/Builder.zig index a4209da40a..5a9703af3d 100644 --- a/src/codegen/llvm/Builder.zig +++ b/src/codegen/llvm/Builder.zig @@ -7999,11 +7999,13 @@ pub fn init(options: Options) InitError!Builder { assert(try self.string("") == .empty); if (options.name.len > 0) self.source_filename = try self.string(options.name); - self.initializeLLVMTarget(options.target.cpu.arch); - if (self.useLibLlvm()) self.llvm.module = llvm.Module.createWithName( - (self.source_filename.slice(&self) orelse ""), - self.llvm.context, - ); + if (self.useLibLlvm()) { + initializeLLVMTarget(options.target.cpu.arch); + self.llvm.module = llvm.Module.createWithName( + (self.source_filename.slice(&self) orelse ""), + self.llvm.context, + ); + } if (options.triple.len > 0) { self.target_triple = try self.string(options.triple); @@ -8117,8 +8119,7 @@ pub fn deinit(self: *Builder) void { self.* = undefined; } -pub fn initializeLLVMTarget(self: *const Builder, arch: std.Target.Cpu.Arch) void { - if (!self.useLibLlvm()) return; +pub fn initializeLLVMTarget(arch: std.Target.Cpu.Arch) void { switch (arch) { .aarch64, .aarch64_be, .aarch64_32 => { llvm.LLVMInitializeAArch64Target(); diff --git a/src/link.zig b/src/link.zig index f7770b6f82..9c79de290d 100644 --- a/src/link.zig +++ b/src/link.zig @@ -1150,7 +1150,9 @@ pub const File = struct { } const llvm_bindings = @import("codegen/llvm/bindings.zig"); + const Builder = @import("codegen/llvm/Builder.zig"); const llvm = @import("codegen/llvm.zig"); + Builder.initializeLLVMTarget(base.options.target.cpu.arch); const os_tag = llvm.targetOs(base.options.target.os.tag); const bad = llvm_bindings.WriteArchive(full_out_path_z, object_files.items.ptr, object_files.items.len, os_tag); if (bad) return error.UnableToWriteArchive; |
