authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-10-18 18:43:48-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-19 16:51:11-04:00
log4d106076c3db840f786460e281aded056053ac35
tree34b1c1babde7ae4dfafbedf550f04a251927e4c7
parent530dc0405c9f48fa3b241f078cf815164e4448ab

link: initialize llvm before calling the llvm API


2 files changed, 10 insertions(+), 7 deletions(-)

src/codegen/llvm/Builder.zig+8-7
......@@ -7999,11 +7999,13 @@ pub fn init(options: Options) InitError!Builder {
79997999 assert(try self.string("") == .empty);
80008000
80018001 if (options.name.len > 0) self.source_filename = try self.string(options.name);
8002 self.initializeLLVMTarget(options.target.cpu.arch);
8003 if (self.useLibLlvm()) self.llvm.module = llvm.Module.createWithName(
8004 (self.source_filename.slice(&self) orelse ""),
8005 self.llvm.context,
8006 );
8002 if (self.useLibLlvm()) {
8003 initializeLLVMTarget(options.target.cpu.arch);
8004 self.llvm.module = llvm.Module.createWithName(
8005 (self.source_filename.slice(&self) orelse ""),
8006 self.llvm.context,
8007 );
8008 }
80078009
80088010 if (options.triple.len > 0) {
80098011 self.target_triple = try self.string(options.triple);
......@@ -8117,8 +8119,7 @@ pub fn deinit(self: *Builder) void {
81178119 self.* = undefined;
81188120}
81198121
8120pub fn initializeLLVMTarget(self: *const Builder, arch: std.Target.Cpu.Arch) void {
8121 if (!self.useLibLlvm()) return;
8122pub fn initializeLLVMTarget(arch: std.Target.Cpu.Arch) void {
81228123 switch (arch) {
81238124 .aarch64, .aarch64_be, .aarch64_32 => {
81248125 llvm.LLVMInitializeAArch64Target();
src/link.zig+2
......@@ -1150,7 +1150,9 @@ pub const File = struct {
11501150 }
11511151
11521152 const llvm_bindings = @import("codegen/llvm/bindings.zig");
1153 const Builder = @import("codegen/llvm/Builder.zig");
11531154 const llvm = @import("codegen/llvm.zig");
1155 Builder.initializeLLVMTarget(base.options.target.cpu.arch);
11541156 const os_tag = llvm.targetOs(base.options.target.os.tag);
11551157 const bad = llvm_bindings.WriteArchive(full_out_path_z, object_files.items.ptr, object_files.items.len, os_tag);
11561158 if (bad) return error.UnableToWriteArchive;