Skip to content

Commit 4d10607

Browse files
jacobly0andrewrk
authored andcommitted
link: initialize llvm before calling the llvm API
1 parent 530dc04 commit 4d10607

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/codegen/llvm/Builder.zig

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

8120-
pub fn initializeLLVMTarget(self: *const Builder, arch: std.Target.Cpu.Arch) void {
8121-
if (!self.useLibLlvm()) return;
8122+
pub fn initializeLLVMTarget(arch: std.Target.Cpu.Arch) void {
81228123
switch (arch) {
81238124
.aarch64, .aarch64_be, .aarch64_32 => {
81248125
llvm.LLVMInitializeAArch64Target();

src/link.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

0 commit comments

Comments
 (0)