From ea7142c43f6a7539f6deb1e77ae5af168fde613e Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 2 May 2022 21:35:03 -0700 Subject: [PATCH] LLVM: set module PIC, PIE, and CodeModel Some simple code from stage1 ported over to stage2. --- src/codegen/llvm.zig | 4 ++++ src/codegen/llvm/bindings.zig | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index d11a359bb6..6c74fc8223 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -340,6 +340,10 @@ pub const Object = struct { llvm_module.setModuleDataLayout(target_data); + if (options.pic) llvm_module.setModulePICLevel(); + if (options.pie) llvm_module.setModulePIELevel(); + if (code_model != .Default) llvm_module.setModuleCodeModel(code_model); + return Object{ .gpa = gpa, .module = options.module.?, diff --git a/src/codegen/llvm/bindings.zig b/src/codegen/llvm/bindings.zig index b8dc3e1830..560b9544dd 100644 --- a/src/codegen/llvm/bindings.zig +++ b/src/codegen/llvm/bindings.zig @@ -310,6 +310,15 @@ pub const Module = opaque { pub const setModuleDataLayout = LLVMSetModuleDataLayout; extern fn LLVMSetModuleDataLayout(*const Module, *const TargetData) void; + pub const setModulePICLevel = ZigLLVMSetModulePICLevel; + extern fn ZigLLVMSetModulePICLevel(module: *const Module) void; + + pub const setModulePIELevel = ZigLLVMSetModulePIELevel; + extern fn ZigLLVMSetModulePIELevel(module: *const Module) void; + + pub const setModuleCodeModel = ZigLLVMSetModuleCodeModel; + extern fn ZigLLVMSetModuleCodeModel(module: *const Module, code_model: CodeModel) void; + pub const addFunction = LLVMAddFunction; extern fn LLVMAddFunction(*const Module, Name: [*:0]const u8, FunctionTy: *const Type) *const Value;