Commit b162c3c820
Changed files (3)
src
src/codegen/llvm.zig
@@ -15,6 +15,7 @@ const link = @import("../link.zig");
const Compilation = @import("../Compilation.zig");
const build_options = @import("build_options");
const Module = @import("../Module.zig");
+const Zcu = Module;
const InternPool = @import("../InternPool.zig");
const Package = @import("../Package.zig");
const TypedValue = @import("../TypedValue.zig");
@@ -1723,7 +1724,7 @@ pub const Object = struct {
try global_index.rename(decl_name, &self.builder);
global_index.setLinkage(.external, &self.builder);
global_index.setUnnamedAddr(.default, &self.builder);
- if (mod.wantDllExports()) global_index.setDllStorageClass(.default, &self.builder);
+ if (wantDllExports(mod)) global_index.setDllStorageClass(.default, &self.builder);
if (self.di_map.get(decl)) |di_node| {
const decl_name_slice = decl_name.slice(&self.builder).?;
if (try decl.isFunction(mod)) {
@@ -1789,7 +1790,7 @@ pub const Object = struct {
);
try global_index.rename(fqn, &self.builder);
global_index.setLinkage(.internal, &self.builder);
- if (mod.wantDllExports()) global_index.setDllStorageClass(.default, &self.builder);
+ if (wantDllExports(mod)) global_index.setDllStorageClass(.default, &self.builder);
global_index.setUnnamedAddr(.unnamed_addr, &self.builder);
if (decl.val.getVariable(mod)) |decl_var| {
const decl_namespace = mod.namespacePtr(decl.namespace_index);
@@ -1848,7 +1849,7 @@ pub const Object = struct {
exports: []const *Module.Export,
) link.File.UpdateExportsError!void {
global_index.setUnnamedAddr(.default, &o.builder);
- if (mod.wantDllExports()) global_index.setDllStorageClass(.dllexport, &o.builder);
+ if (wantDllExports(mod)) global_index.setDllStorageClass(.dllexport, &o.builder);
global_index.setLinkage(switch (exports[0].opts.linkage) {
.Internal => unreachable,
.Strong => .external,
@@ -11767,3 +11768,9 @@ fn constraintAllowsRegister(constraint: []const u8) bool {
}
} else return false;
}
+
+fn wantDllExports(zcu: *const Zcu) bool {
+ const lf = zcu.bin_file.?;
+ const coff = lf.cast(link.File.Coff) orelse return false;
+ return coff.dll_export_fns;
+}
src/link/Coff.zig
@@ -9,6 +9,7 @@ llvm_object: ?*LlvmObject = null,
base: link.File,
image_base: u64,
error_flags: link.File.ErrorFlags = .{},
+dll_export_fns: bool,
ptr_width: PtrWidth,
page_size: u32,
@@ -400,6 +401,8 @@ pub fn createEmpty(arena: Allocator, options: link.File.OpenOptions) !*Coff {
.Lib => 0x10000000,
.Obj => 0,
},
+
+ .dll_export_fns = options.dll_export_fns,
};
const use_llvm = comp.config.use_llvm;
src/Module.zig
@@ -3335,7 +3335,7 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func_index: InternPool.Index) SemaEr
const comp = mod.comp;
- const no_bin_file = (comp.bin_file.options.emit == null and
+ const no_bin_file = (comp.bin_file == null and
comp.emit_asm == null and
comp.emit_llvm_ir == null and
comp.emit_llvm_bc == null);
@@ -4311,14 +4311,14 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err
1 => blk: {
// test decl with no name. Skip the part where we check against
// the test name filter.
- if (!comp.bin_file.options.is_test) break :blk false;
+ if (!comp.config.is_test) break :blk false;
if (decl_mod != mod.main_mod) break :blk false;
try mod.test_functions.put(gpa, new_decl_index, {});
break :blk true;
},
else => blk: {
if (!is_named_test) break :blk false;
- if (!comp.bin_file.options.is_test) break :blk false;
+ if (!comp.config.is_test) break :blk false;
if (decl_mod != mod.main_mod) break :blk false;
if (comp.test_filter) |test_filter| {
if (mem.indexOf(u8, ip.stringToSlice(decl_name), test_filter) == null) {
@@ -4627,7 +4627,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
// If we don't get an error return trace from a caller, create our own.
if (func.analysis(ip).calls_or_awaits_errorable_fn and
- mod.comp.bin_file.options.error_return_tracing and
+ mod.comp.config.error_tracing and
!sema.fn_ret_ty.isError(mod))
{
sema.setupErrorReturnTrace(&inner_block, last_arg_index) catch |err| switch (err) {
@@ -5475,7 +5475,7 @@ pub fn populateTestFunctions(
pub fn linkerUpdateDecl(mod: *Module, decl_index: Decl.Index) !void {
const comp = mod.comp;
- const no_bin_file = (comp.bin_file.options.emit == null and
+ const no_bin_file = (comp.bin_file == null and
comp.emit_asm == null and
comp.emit_llvm_ir == null and
comp.emit_llvm_bc == null);
@@ -5597,10 +5597,6 @@ pub fn addGlobalAssembly(mod: *Module, decl_index: Decl.Index, source: []const u
}
}
-pub fn wantDllExports(mod: Module) bool {
- return mod.comp.bin_file.options.dll_export_fns and mod.getTarget().os.tag == .windows;
-}
-
pub fn getDeclExports(mod: Module, decl_index: Decl.Index) []const *Export {
if (mod.decl_exports.get(decl_index)) |l| {
return l.items;