aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/llvm.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-06-07 13:08:22 -0400
committerGitHub <noreply@github.com>2025-06-07 13:08:22 -0400
commit8b875b17ade95c4e0098c7c3b20134f03745aac3 (patch)
tree02ee642b33451b453994f484a2204ddca42e4857 /src/codegen/llvm.zig
parent173bc4274446a14aca2eea128b70b35b0ba18ebe (diff)
parent5a52da1b7a8c467087da8f3a20ab902ec8c1e25d (diff)
downloadzig-8b875b17ade95c4e0098c7c3b20134f03745aac3.tar.gz
zig-8b875b17ade95c4e0098c7c3b20134f03745aac3.zip
Merge pull request #24072 from jacobly0/x86_64-default
Compilation: enable the x86_64 backend by default for debug builds
Diffstat (limited to 'src/codegen/llvm.zig')
-rw-r--r--src/codegen/llvm.zig123
1 files changed, 73 insertions, 50 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index 7790840d20..3fc6250d3f 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -2979,36 +2979,49 @@ pub const Object = struct {
const zcu = pt.zcu;
const ip = &zcu.intern_pool;
const nav = ip.getNav(nav_index);
- const is_extern, const is_threadlocal, const is_weak_linkage, const is_dll_import = switch (nav.status) {
+ const linkage: std.builtin.GlobalLinkage, const visibility: Builder.Visibility, const is_threadlocal, const is_dll_import = switch (nav.status) {
.unresolved => unreachable,
.fully_resolved => |r| switch (ip.indexToKey(r.val)) {
- .variable => |variable| .{ false, variable.is_threadlocal, variable.is_weak_linkage, false },
- .@"extern" => |@"extern"| .{ true, @"extern".is_threadlocal, @"extern".is_weak_linkage, @"extern".is_dll_import },
- else => .{ false, false, false, false },
+ .variable => |variable| .{ .internal, .default, variable.is_threadlocal, false },
+ .@"extern" => |@"extern"| .{ @"extern".linkage, .fromSymbolVisibility(@"extern".visibility), @"extern".is_threadlocal, @"extern".is_dll_import },
+ else => .{ .internal, .default, false, false },
},
// This means it's a source declaration which is not `extern`!
- .type_resolved => |r| .{ false, r.is_threadlocal, false, false },
+ .type_resolved => |r| .{ .internal, .default, r.is_threadlocal, false },
};
const variable_index = try o.builder.addVariable(
- try o.builder.strtabString((if (is_extern) nav.name else nav.fqn).toSlice(ip)),
+ try o.builder.strtabString(switch (linkage) {
+ .internal => nav.fqn,
+ .strong, .weak => nav.name,
+ .link_once => unreachable,
+ }.toSlice(ip)),
try o.lowerType(Type.fromInterned(nav.typeOf(ip))),
toLlvmGlobalAddressSpace(nav.getAddrspace(), zcu.getTarget()),
);
gop.value_ptr.* = variable_index.ptrConst(&o.builder).global;
// This is needed for declarations created by `@extern`.
- if (is_extern) {
- variable_index.setLinkage(.external, &o.builder);
- variable_index.setUnnamedAddr(.default, &o.builder);
- if (is_threadlocal and !zcu.navFileScope(nav_index).mod.?.single_threaded)
- variable_index.setThreadLocal(.generaldynamic, &o.builder);
- if (is_weak_linkage) variable_index.setLinkage(.extern_weak, &o.builder);
- if (is_dll_import) variable_index.setDllStorageClass(.dllimport, &o.builder);
- } else {
- variable_index.setLinkage(.internal, &o.builder);
- variable_index.setUnnamedAddr(.unnamed_addr, &o.builder);
- }
+ switch (linkage) {
+ .internal => {
+ variable_index.setLinkage(.internal, &o.builder);
+ variable_index.setUnnamedAddr(.unnamed_addr, &o.builder);
+ },
+ .strong, .weak => {
+ variable_index.setLinkage(switch (linkage) {
+ .internal => unreachable,
+ .strong => .external,
+ .weak => .extern_weak,
+ .link_once => unreachable,
+ }, &o.builder);
+ variable_index.setUnnamedAddr(.default, &o.builder);
+ if (is_threadlocal and !zcu.navFileScope(nav_index).mod.?.single_threaded)
+ variable_index.setThreadLocal(.generaldynamic, &o.builder);
+ if (is_dll_import) variable_index.setDllStorageClass(.dllimport, &o.builder);
+ },
+ .link_once => unreachable,
+ }
+ variable_index.setVisibility(visibility, &o.builder);
return variable_index;
}
@@ -4530,14 +4543,14 @@ pub const NavGen = struct {
const nav = ip.getNav(nav_index);
const resolved = nav.status.fully_resolved;
- const is_extern, const lib_name, const is_threadlocal, const is_weak_linkage, const is_dll_import, const is_const, const init_val, const owner_nav = switch (ip.indexToKey(resolved.val)) {
- .variable => |variable| .{ false, .none, variable.is_threadlocal, variable.is_weak_linkage, false, false, variable.init, variable.owner_nav },
- .@"extern" => |@"extern"| .{ true, @"extern".lib_name, @"extern".is_threadlocal, @"extern".is_weak_linkage, @"extern".is_dll_import, @"extern".is_const, .none, @"extern".owner_nav },
- else => .{ false, .none, false, false, false, true, resolved.val, nav_index },
+ const lib_name, const linkage, const visibility: Builder.Visibility, const is_threadlocal, const is_dll_import, const is_const, const init_val, const owner_nav = switch (ip.indexToKey(resolved.val)) {
+ .variable => |variable| .{ .none, .internal, .default, variable.is_threadlocal, false, false, variable.init, variable.owner_nav },
+ .@"extern" => |@"extern"| .{ @"extern".lib_name, @"extern".linkage, .fromSymbolVisibility(@"extern".visibility), @"extern".is_threadlocal, @"extern".is_dll_import, @"extern".is_const, .none, @"extern".owner_nav },
+ else => .{ .none, .internal, .default, false, false, true, resolved.val, nav_index },
};
const ty = Type.fromInterned(nav.typeOf(ip));
- if (is_extern and ip.isFunctionType(ty.toIntern())) {
+ if (linkage != .internal and ip.isFunctionType(ty.toIntern())) {
_ = try o.resolveLlvmFunction(owner_nav);
} else {
const variable_index = try o.resolveGlobalNav(nav_index);
@@ -4549,6 +4562,7 @@ pub const NavGen = struct {
.none => .no_init,
else => try o.lowerValue(init_val),
}, &o.builder);
+ variable_index.setVisibility(visibility, &o.builder);
const file_scope = zcu.navFileScopeIndex(nav_index);
const mod = zcu.fileByIndex(file_scope).mod.?;
@@ -4568,7 +4582,7 @@ pub const NavGen = struct {
line_number,
try o.lowerDebugType(ty),
variable_index,
- .{ .local = !is_extern },
+ .{ .local = linkage == .internal },
);
const debug_expression = try o.builder.debugExpression(&.{});
@@ -4583,38 +4597,47 @@ pub const NavGen = struct {
}
}
- if (is_extern) {
- const global_index = o.nav_map.get(nav_index).?;
+ switch (linkage) {
+ .internal => {},
+ .strong, .weak => {
+ const global_index = o.nav_map.get(nav_index).?;
- const decl_name = decl_name: {
- if (zcu.getTarget().cpu.arch.isWasm() and ty.zigTypeTag(zcu) == .@"fn") {
- if (lib_name.toSlice(ip)) |lib_name_slice| {
- if (!std.mem.eql(u8, lib_name_slice, "c")) {
- break :decl_name try o.builder.strtabStringFmt("{}|{s}", .{ nav.name.fmt(ip), lib_name_slice });
+ const decl_name = decl_name: {
+ if (zcu.getTarget().cpu.arch.isWasm() and ty.zigTypeTag(zcu) == .@"fn") {
+ if (lib_name.toSlice(ip)) |lib_name_slice| {
+ if (!std.mem.eql(u8, lib_name_slice, "c")) {
+ break :decl_name try o.builder.strtabStringFmt("{}|{s}", .{ nav.name.fmt(ip), lib_name_slice });
+ }
}
}
- }
- break :decl_name try o.builder.strtabString(nav.name.toSlice(ip));
- };
+ break :decl_name try o.builder.strtabString(nav.name.toSlice(ip));
+ };
- if (o.builder.getGlobal(decl_name)) |other_global| {
- if (other_global != global_index) {
- // Another global already has this name; just use it in place of this global.
- try global_index.replace(other_global, &o.builder);
- return;
+ if (o.builder.getGlobal(decl_name)) |other_global| {
+ if (other_global != global_index) {
+ // Another global already has this name; just use it in place of this global.
+ try global_index.replace(other_global, &o.builder);
+ return;
+ }
}
- }
- try global_index.rename(decl_name, &o.builder);
- global_index.setLinkage(.external, &o.builder);
- global_index.setUnnamedAddr(.default, &o.builder);
- if (is_dll_import) {
- global_index.setDllStorageClass(.dllimport, &o.builder);
- } else if (zcu.comp.config.dll_export_fns) {
- global_index.setDllStorageClass(.default, &o.builder);
- }
+ try global_index.rename(decl_name, &o.builder);
+ global_index.setUnnamedAddr(.default, &o.builder);
+ if (is_dll_import) {
+ global_index.setDllStorageClass(.dllimport, &o.builder);
+ } else if (zcu.comp.config.dll_export_fns) {
+ global_index.setDllStorageClass(.default, &o.builder);
+ }
- if (is_weak_linkage) global_index.setLinkage(.extern_weak, &o.builder);
+ global_index.setLinkage(switch (linkage) {
+ .internal => unreachable,
+ .strong => .external,
+ .weak => .extern_weak,
+ .link_once => unreachable,
+ }, &o.builder);
+ global_index.setVisibility(visibility, &o.builder);
+ },
+ .link_once => unreachable,
}
}
};
@@ -5023,7 +5046,7 @@ pub const FuncGen = struct {
.vector_store_elem => try self.airVectorStoreElem(inst),
- .tlv_dllimport_ptr => try self.airTlvDllimportPtr(inst),
+ .runtime_nav_ptr => try self.airRuntimeNavPtr(inst),
.inferred_alloc, .inferred_alloc_comptime => unreachable,
@@ -8122,7 +8145,7 @@ pub const FuncGen = struct {
return .none;
}
- fn airTlvDllimportPtr(fg: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
+ fn airRuntimeNavPtr(fg: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
const o = fg.ng.object;
const ty_nav = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_nav;
const llvm_ptr_const = try o.lowerNavRefValue(ty_nav.nav);