llvm: force strip without libllvm to avoid unimplemented behavior

Also fix deinit bugs.
This commit is contained in:
Jacob Young 2023-08-08 22:34:24 -04:00
parent 53bea0f7e4
commit 3e1dd93bb2
2 changed files with 21 additions and 6 deletions

View File

@ -823,7 +823,7 @@ pub const Object = struct {
var builder = try Builder.init(.{
.allocator = gpa,
.use_lib_llvm = options.use_lib_llvm,
.strip = options.strip,
.strip = options.strip or !options.use_lib_llvm, // TODO
.name = options.root_name,
.target = options.target,
.triple = llvm_target_triple,
@ -961,14 +961,17 @@ pub const Object = struct {
}
pub fn deinit(self: *Object, gpa: Allocator) void {
self.di_map.deinit(gpa);
self.di_type_map.deinit(gpa);
self.target_data.dispose();
self.target_machine.dispose();
if (self.builder.useLibLlvm()) {
self.di_map.deinit(gpa);
self.di_type_map.deinit(gpa);
self.target_data.dispose();
self.target_machine.dispose();
}
self.decl_map.deinit(gpa);
self.named_enum_map.deinit(gpa);
self.type_map.deinit(gpa);
self.extern_collisions.deinit(gpa);
self.builder.deinit();
self.* = undefined;
}
@ -1182,6 +1185,9 @@ pub const Object = struct {
emit_asm_msg, emit_bin_msg, emit_llvm_ir_msg, emit_llvm_bc_msg,
});
if (emit_asm_path == null and emit_bin_path == null and
emit_llvm_ir_path == null and emit_llvm_bc_path == null) return;
if (!self.builder.useLibLlvm()) {
log.err("emitting without libllvm not implemented", .{});
return error.FailedToEmit;

View File

@ -1131,7 +1131,16 @@ void ZigLLVMEraseGlobalValue(LLVMValueRef GlobalVal) {
}
void ZigLLVMDeleteGlobalValue(LLVMValueRef GlobalVal) {
delete unwrap<GlobalVariable>(GlobalVal);
auto *GV = unwrap<GlobalValue>(GlobalVal);
assert(GV->getParent() == nullptr);
switch (GV->getValueID()) {
#define HANDLE_GLOBAL_VALUE(NAME) \
case Value::NAME##Val: \
delete static_cast<NAME *>(GV); \
break;
#include <llvm/IR/Value.def>
default: llvm_unreachable("Expected global value");
}
}
void ZigLLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal) {