authorgravatar for tristan.ross@midstall.comTristan Ross <tristan.ross@midstall.com> 2024-02-18 21:25:23-08:00
committergravatar for tristan.ross@midstall.comTristan Ross <tristan.ross@midstall.com> 2024-03-11 07:09:10-07:00
logc260b4c753d1e5f947e0d33ce39ce173e497309f
tree39b138128ab96c7abaf4b8d22fc6af1f0b95254c
parentaab84a3decd784a275c0bb694c7717d3c73ae4b1
signaturelock-open Commit is signed but in an unrecognized format.

std.builtin: make global linkage fields lowercase


15 files changed, 48 insertions(+), 48 deletions(-)

doc/langref.html.in+1-1
...@@ -8356,7 +8356,7 @@ test "main" {...@@ -8356,7 +8356,7 @@ test "main" {
8356 </p>8356 </p>
8357 {#code_begin|obj|export_builtin#}8357 {#code_begin|obj|export_builtin#}
8358comptime {8358comptime {
8359 @export(internalName, .{ .name = "foo", .linkage = .Strong });8359 @export(internalName, .{ .name = "foo", .linkage = .strong });
8360}8360}
83618361
8362fn internalName() callconv(.C) void {}8362fn internalName() callconv(.C) void {}
lib/compiler_rt/clear_cache.zig+1-1
...@@ -162,7 +162,7 @@ fn clear_cache(start: usize, end: usize) callconv(.C) void {...@@ -162,7 +162,7 @@ fn clear_cache(start: usize, end: usize) callconv(.C) void {
162 }162 }
163}163}
164164
165const linkage = if (builtin.is_test) std.builtin.GlobalLinkage.Internal else std.builtin.GlobalLinkage.Weak;165const linkage = if (builtin.is_test) std.builtin.GlobalLinkage.internal else std.builtin.GlobalLinkage.weak;
166166
167fn exportIt() void {167fn exportIt() void {
168 @export(clear_cache, .{ .name = "__clear_cache", .linkage = linkage });168 @export(clear_cache, .{ .name = "__clear_cache", .linkage = linkage });
lib/compiler_rt/common.zig+2-2
...@@ -2,12 +2,12 @@ const std = @import("std");...@@ -2,12 +2,12 @@ const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const native_endian = builtin.cpu.arch.endian();3const native_endian = builtin.cpu.arch.endian();
44
5pub const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;5pub const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .internal else .weak;
6/// Determines the symbol's visibility to other objects.6/// Determines the symbol's visibility to other objects.
7/// For WebAssembly this allows the symbol to be resolved to other modules, but will not7/// For WebAssembly this allows the symbol to be resolved to other modules, but will not
8/// export it to the host runtime.8/// export it to the host runtime.
9pub const visibility: std.builtin.SymbolVisibility =9pub const visibility: std.builtin.SymbolVisibility =
10 if (builtin.target.isWasm() and linkage != .Internal) .hidden else .default;10 if (builtin.target.isWasm() and linkage != .internal) .hidden else .default;
11pub const want_aeabi = switch (builtin.abi) {11pub const want_aeabi = switch (builtin.abi) {
12 .eabi,12 .eabi,
13 .eabihf,13 .eabihf,
lib/std/builtin.zig+6-6
...@@ -64,10 +64,10 @@ pub const StackTrace = struct {...@@ -64,10 +64,10 @@ pub const StackTrace = struct {
64/// This data structure is used by the Zig language code generation and64/// This data structure is used by the Zig language code generation and
65/// therefore must be kept in sync with the compiler implementation.65/// therefore must be kept in sync with the compiler implementation.
66pub const GlobalLinkage = enum {66pub const GlobalLinkage = enum {
67 Internal,67 internal,
68 Strong,68 strong,
69 Weak,69 weak,
70 LinkOnce,70 link_once,
71};71};
7272
73/// This data structure is used by the Zig language code generation and73/// This data structure is used by the Zig language code generation and
...@@ -659,7 +659,7 @@ pub const PrefetchOptions = struct {...@@ -659,7 +659,7 @@ pub const PrefetchOptions = struct {
659/// therefore must be kept in sync with the compiler implementation.659/// therefore must be kept in sync with the compiler implementation.
660pub const ExportOptions = struct {660pub const ExportOptions = struct {
661 name: []const u8,661 name: []const u8,
662 linkage: GlobalLinkage = .Strong,662 linkage: GlobalLinkage = .strong,
663 section: ?[]const u8 = null,663 section: ?[]const u8 = null,
664 visibility: SymbolVisibility = .default,664 visibility: SymbolVisibility = .default,
665};665};
...@@ -669,7 +669,7 @@ pub const ExportOptions = struct {...@@ -669,7 +669,7 @@ pub const ExportOptions = struct {
669pub const ExternOptions = struct {669pub const ExternOptions = struct {
670 name: []const u8,670 name: []const u8,
671 library_name: ?[]const u8 = null,671 library_name: ?[]const u8 = null,
672 linkage: GlobalLinkage = .Strong,672 linkage: GlobalLinkage = .strong,
673 is_thread_local: bool = false,673 is_thread_local: bool = false,
674};674};
675675
lib/std/dynamic_library.zig+1-1
...@@ -8,7 +8,7 @@ const windows = std.os.windows;...@@ -8,7 +8,7 @@ const windows = std.os.windows;
8const system = std.os.system;8const system = std.os.system;
99
10pub const DynLib = switch (builtin.os.tag) {10pub const DynLib = switch (builtin.os.tag) {
11 .linux => if (!builtin.link_libc or builtin.abi == .musl and builtin.link_mode == .Static)11 .linux => if (!builtin.link_libc or builtin.abi == .musl and builtin.link_mode == .static)
12 ElfDynLib12 ElfDynLib
13 else13 else
14 DlDynLib,14 DlDynLib,
src/Module.zig+1-1
...@@ -279,7 +279,7 @@ pub const Export = struct {...@@ -279,7 +279,7 @@ pub const Export = struct {
279279
280 pub const Options = struct {280 pub const Options = struct {
281 name: InternPool.NullTerminatedString,281 name: InternPool.NullTerminatedString,
282 linkage: std.builtin.GlobalLinkage = .Strong,282 linkage: std.builtin.GlobalLinkage = .strong,
283 section: InternPool.OptionalNullTerminatedString = .none,283 section: InternPool.OptionalNullTerminatedString = .none,
284 visibility: std.builtin.SymbolVisibility = .default,284 visibility: std.builtin.SymbolVisibility = .default,
285 };285 };
src/Sema.zig+7-7
...@@ -6274,7 +6274,7 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -6274,7 +6274,7 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
6274 .needed_comptime_reason = "export target must be comptime-known",6274 .needed_comptime_reason = "export target must be comptime-known",
6275 });6275 });
6276 const options = try sema.resolveExportOptions(block, options_src, extra.options);6276 const options = try sema.resolveExportOptions(block, options_src, extra.options);
6277 if (options.linkage == .Internal)6277 if (options.linkage == .internal)
6278 return;6278 return;
6279 if (operand.val.getFunction(mod)) |function| {6279 if (operand.val.getFunction(mod)) |function| {
6280 const decl_index = function.owner_decl;6280 const decl_index = function.owner_decl;
...@@ -6301,7 +6301,7 @@ pub fn analyzeExport(...@@ -6301,7 +6301,7 @@ pub fn analyzeExport(
6301 const gpa = sema.gpa;6301 const gpa = sema.gpa;
6302 const mod = sema.mod;6302 const mod = sema.mod;
63036303
6304 if (options.linkage == .Internal)6304 if (options.linkage == .internal)
6305 return;6305 return;
63066306
6307 try mod.ensureDeclAnalyzed(exported_decl_index);6307 try mod.ensureDeclAnalyzed(exported_decl_index);
...@@ -23802,7 +23802,7 @@ fn resolveExportOptions(...@@ -23802,7 +23802,7 @@ fn resolveExportOptions(
23802 return sema.fail(block, name_src, "exported symbol name cannot be empty", .{});23802 return sema.fail(block, name_src, "exported symbol name cannot be empty", .{});
23803 }23803 }
2380423804
23805 if (visibility != .default and linkage == .Internal) {23805 if (visibility != .default and linkage == .internal) {
23806 return sema.fail(block, visibility_src, "symbol '{s}' exported with internal linkage has non-default visibility {s}", .{23806 return sema.fail(block, visibility_src, "symbol '{s}' exported with internal linkage has non-default visibility {s}", .{
23807 name, @tagName(visibility),23807 name, @tagName(visibility),
23808 });23808 });
...@@ -25888,7 +25888,7 @@ fn resolveExternOptions(...@@ -25888,7 +25888,7 @@ fn resolveExternOptions(
25888) CompileError!struct {25888) CompileError!struct {
25889 name: InternPool.NullTerminatedString,25889 name: InternPool.NullTerminatedString,
25890 library_name: InternPool.OptionalNullTerminatedString = .none,25890 library_name: InternPool.OptionalNullTerminatedString = .none,
25891 linkage: std.builtin.GlobalLinkage = .Strong,25891 linkage: std.builtin.GlobalLinkage = .strong,
25892 is_thread_local: bool = false,25892 is_thread_local: bool = false,
25893} {25893} {
25894 const mod = sema.mod;25894 const mod = sema.mod;
...@@ -25938,7 +25938,7 @@ fn resolveExternOptions(...@@ -25938,7 +25938,7 @@ fn resolveExternOptions(
25938 return sema.fail(block, name_src, "extern symbol name cannot be empty", .{});25938 return sema.fail(block, name_src, "extern symbol name cannot be empty", .{});
25939 }25939 }
2594025940
25941 if (linkage != .Weak and linkage != .Strong) {25941 if (linkage != .weak and linkage != .strong) {
25942 return sema.fail(block, linkage_src, "extern symbol must use strong or weak linkage", .{});25942 return sema.fail(block, linkage_src, "extern symbol must use strong or weak linkage", .{});
25943 }25943 }
2594425944
...@@ -25984,7 +25984,7 @@ fn zirBuiltinExtern(...@@ -25984,7 +25984,7 @@ fn zirBuiltinExtern(
25984 else => |e| return e,25984 else => |e| return e,
25985 };25985 };
2598625986
25987 if (options.linkage == .Weak and !ty.ptrAllowsZero(mod)) {25987 if (options.linkage == .weak and !ty.ptrAllowsZero(mod)) {
25988 ty = try mod.optionalType(ty.toIntern());25988 ty = try mod.optionalType(ty.toIntern());
25989 }25989 }
25990 const ptr_info = ty.ptrInfo(mod);25990 const ptr_info = ty.ptrInfo(mod);
...@@ -26010,7 +26010,7 @@ fn zirBuiltinExtern(...@@ -26010,7 +26010,7 @@ fn zirBuiltinExtern(
26010 .is_extern = true,26010 .is_extern = true,
26011 .is_const = ptr_info.flags.is_const,26011 .is_const = ptr_info.flags.is_const,
26012 .is_threadlocal = options.is_thread_local,26012 .is_threadlocal = options.is_thread_local,
26013 .is_weak_linkage = options.linkage == .Weak,26013 .is_weak_linkage = options.linkage == .weak,
26014 } }),26014 } }),
26015 ),26015 ),
26016 }, options.name);26016 }, options.name);
src/codegen/c.zig+4-4
...@@ -1999,7 +1999,7 @@ pub const DeclGen = struct {...@@ -1999,7 +1999,7 @@ pub const DeclGen = struct {
1999 try fwd.writeAll(if (is_global) "zig_extern " else "static ");1999 try fwd.writeAll(if (is_global) "zig_extern " else "static ");
2000 const maybe_exports = dg.module.decl_exports.get(decl_index);2000 const maybe_exports = dg.module.decl_exports.get(decl_index);
2001 const export_weak_linkage = if (maybe_exports) |exports|2001 const export_weak_linkage = if (maybe_exports) |exports|
2002 exports.items[0].opts.linkage == .Weak2002 exports.items[0].opts.linkage == .weak
2003 else2003 else
2004 false;2004 false;
2005 if (variable.is_weak_linkage or export_weak_linkage) try fwd.writeAll("zig_weak_linkage ");2005 if (variable.is_weak_linkage or export_weak_linkage) try fwd.writeAll("zig_weak_linkage ");
...@@ -2689,7 +2689,7 @@ fn genExports(o: *Object) !void {...@@ -2689,7 +2689,7 @@ fn genExports(o: *Object) !void {
2689 const is_variable_const = switch (ip.indexToKey(tv.val.toIntern())) {2689 const is_variable_const = switch (ip.indexToKey(tv.val.toIntern())) {
2690 .func => return for (exports.items[1..], 1..) |@"export", i| {2690 .func => return for (exports.items[1..], 1..) |@"export", i| {
2691 try fwd.writeAll("zig_extern ");2691 try fwd.writeAll("zig_extern ");
2692 if (@"export".opts.linkage == .Weak) try fwd.writeAll("zig_weak_linkage_fn ");2692 if (@"export".opts.linkage == .weak) try fwd.writeAll("zig_weak_linkage_fn ");
2693 try o.dg.renderFunctionSignature(2693 try o.dg.renderFunctionSignature(
2694 fwd,2694 fwd,
2695 decl_index,2695 decl_index,
...@@ -2707,7 +2707,7 @@ fn genExports(o: *Object) !void {...@@ -2707,7 +2707,7 @@ fn genExports(o: *Object) !void {
2707 };2707 };
2708 for (exports.items[1..]) |@"export"| {2708 for (exports.items[1..]) |@"export"| {
2709 try fwd.writeAll("zig_extern ");2709 try fwd.writeAll("zig_extern ");
2710 if (@"export".opts.linkage == .Weak) try fwd.writeAll("zig_weak_linkage ");2710 if (@"export".opts.linkage == .weak) try fwd.writeAll("zig_weak_linkage ");
2711 const export_name = ip.stringToSlice(@"export".opts.name);2711 const export_name = ip.stringToSlice(@"export".opts.name);
2712 try o.dg.renderTypeAndName(2712 try o.dg.renderTypeAndName(
2713 fwd,2713 fwd,
...@@ -2842,7 +2842,7 @@ pub fn genFunc(f: *Function) !void {...@@ -2842,7 +2842,7 @@ pub fn genFunc(f: *Function) !void {
2842 try fwd_decl_writer.writeAll(if (is_global) "zig_extern " else "static ");2842 try fwd_decl_writer.writeAll(if (is_global) "zig_extern " else "static ");
28432843
2844 if (mod.decl_exports.get(decl_index)) |exports|2844 if (mod.decl_exports.get(decl_index)) |exports|
2845 if (exports.items[0].opts.linkage == .Weak) try fwd_decl_writer.writeAll("zig_weak_linkage_fn ");2845 if (exports.items[0].opts.linkage == .weak) try fwd_decl_writer.writeAll("zig_weak_linkage_fn ");
2846 try o.dg.renderFunctionSignature(fwd_decl_writer, decl_index, .forward, .{ .export_index = 0 });2846 try o.dg.renderFunctionSignature(fwd_decl_writer, decl_index, .forward, .{ .export_index = 0 });
2847 try fwd_decl_writer.writeAll(";\n");2847 try fwd_decl_writer.writeAll(";\n");
2848 try genExports(o);2848 try genExports(o);
src/codegen/llvm.zig+4-4
...@@ -1873,10 +1873,10 @@ pub const Object = struct {...@@ -1873,10 +1873,10 @@ pub const Object = struct {
1873 if (comp.config.dll_export_fns)1873 if (comp.config.dll_export_fns)
1874 global_index.setDllStorageClass(.dllexport, &o.builder);1874 global_index.setDllStorageClass(.dllexport, &o.builder);
1875 global_index.setLinkage(switch (exports[0].opts.linkage) {1875 global_index.setLinkage(switch (exports[0].opts.linkage) {
1876 .Internal => unreachable,1876 .internal => unreachable,
1877 .Strong => .external,1877 .strong => .external,
1878 .Weak => .weak_odr,1878 .weak => .weak_odr,
1879 .LinkOnce => .linkonce_odr,1879 .link_once => .linkonce_odr,
1880 }, &o.builder);1880 }, &o.builder);
1881 global_index.setVisibility(switch (exports[0].opts.visibility) {1881 global_index.setVisibility(switch (exports[0].opts.visibility) {
1882 .default => .default,1882 .default => .default,
src/link/Coff.zig+5-5
...@@ -1599,11 +1599,11 @@ pub fn updateExports(...@@ -1599,11 +1599,11 @@ pub fn updateExports(
1599 }1599 }
1600 }1600 }
16011601
1602 if (exp.opts.linkage == .LinkOnce) {1602 if (exp.opts.linkage == .link_once) {
1603 try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(1603 try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(
1604 gpa,1604 gpa,
1605 exp.getSrcLoc(mod),1605 exp.getSrcLoc(mod),
1606 "Unimplemented: GlobalLinkage.LinkOnce",1606 "Unimplemented: GlobalLinkage.link_once",
1607 .{},1607 .{},
1608 ));1608 ));
1609 continue;1609 continue;
...@@ -1633,11 +1633,11 @@ pub fn updateExports(...@@ -1633,11 +1633,11 @@ pub fn updateExports(
1633 sym.type = atom.getSymbol(self).type;1633 sym.type = atom.getSymbol(self).type;
16341634
1635 switch (exp.opts.linkage) {1635 switch (exp.opts.linkage) {
1636 .Strong => {1636 .strong => {
1637 sym.storage_class = .EXTERNAL;1637 sym.storage_class = .EXTERNAL;
1638 },1638 },
1639 .Internal => @panic("TODO Internal"),1639 .internal => @panic("TODO Internal"),
1640 .Weak => @panic("TODO WeakExternal"),1640 .weak => @panic("TODO WeakExternal"),
1641 else => unreachable,1641 else => unreachable,
1642 }1642 }
16431643
src/link/Elf/ZigObject.zig+4-4
...@@ -1436,10 +1436,10 @@ pub fn updateExports(...@@ -1436,10 +1436,10 @@ pub fn updateExports(
1436 }1436 }
1437 }1437 }
1438 const stb_bits: u8 = switch (exp.opts.linkage) {1438 const stb_bits: u8 = switch (exp.opts.linkage) {
1439 .Internal => elf.STB_LOCAL,1439 .internal => elf.STB_LOCAL,
1440 .Strong => elf.STB_GLOBAL,1440 .strong => elf.STB_GLOBAL,
1441 .Weak => elf.STB_WEAK,1441 .weak => elf.STB_WEAK,
1442 .LinkOnce => {1442 .link_once => {
1443 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);1443 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
1444 mod.failed_exports.putAssumeCapacityNoClobber(exp, try Module.ErrorMsg.create(1444 mod.failed_exports.putAssumeCapacityNoClobber(exp, try Module.ErrorMsg.create(
1445 gpa,1445 gpa,
src/link/MachO/ZigObject.zig+5-5
...@@ -1216,11 +1216,11 @@ pub fn updateExports(...@@ -1216,11 +1216,11 @@ pub fn updateExports(
1216 continue;1216 continue;
1217 }1217 }
1218 }1218 }
1219 if (exp.opts.linkage == .LinkOnce) {1219 if (exp.opts.linkage == .link_once) {
1220 try mod.failed_exports.putNoClobber(mod.gpa, exp, try Module.ErrorMsg.create(1220 try mod.failed_exports.putNoClobber(mod.gpa, exp, try Module.ErrorMsg.create(
1221 gpa,1221 gpa,
1222 exp.getSrcLoc(mod),1222 exp.getSrcLoc(mod),
1223 "Unimplemented: GlobalLinkage.LinkOnce",1223 "Unimplemented: GlobalLinkage.link_once",
1224 .{},1224 .{},
1225 ));1225 ));
1226 continue;1226 continue;
...@@ -1242,12 +1242,12 @@ pub fn updateExports(...@@ -1242,12 +1242,12 @@ pub fn updateExports(
1242 self.symtab.items(.atom)[global_nlist_index] = self.symtab.items(.atom)[nlist_idx];1242 self.symtab.items(.atom)[global_nlist_index] = self.symtab.items(.atom)[nlist_idx];
12431243
1244 switch (exp.opts.linkage) {1244 switch (exp.opts.linkage) {
1245 .Internal => {1245 .internal => {
1246 // Symbol should be hidden, or in MachO lingo, private extern.1246 // Symbol should be hidden, or in MachO lingo, private extern.
1247 global_nlist.n_type |= macho.N_PEXT;1247 global_nlist.n_type |= macho.N_PEXT;
1248 },1248 },
1249 .Strong => {},1249 .strong => {},
1250 .Weak => {1250 .weak => {
1251 // Weak linkage is specified as part of n_desc field.1251 // Weak linkage is specified as part of n_desc field.
1252 // Symbol's n_type is like for a symbol with strong linkage.1252 // Symbol's n_type is like for a symbol with strong linkage.
1253 global_nlist.n_desc |= macho.N_WEAK_DEF;1253 global_nlist.n_desc |= macho.N_WEAK_DEF;
src/link/Wasm/ZigObject.zig+4-4
...@@ -896,14 +896,14 @@ pub fn updateExports(...@@ -896,14 +896,14 @@ pub fn updateExports(
896 sym.name = export_name;896 sym.name = export_name;
897897
898 switch (exp.opts.linkage) {898 switch (exp.opts.linkage) {
899 .Internal => {899 .internal => {
900 sym.setFlag(.WASM_SYM_VISIBILITY_HIDDEN);900 sym.setFlag(.WASM_SYM_VISIBILITY_HIDDEN);
901 },901 },
902 .Weak => {902 .weak => {
903 sym.setFlag(.WASM_SYM_BINDING_WEAK);903 sym.setFlag(.WASM_SYM_BINDING_WEAK);
904 },904 },
905 .Strong => {}, // symbols are strong by default905 .strong => {}, // symbols are strong by default
906 .LinkOnce => {906 .link_once => {
907 try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(907 try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(
908 gpa,908 gpa,
909 decl.srcLoc(mod),909 decl.srcLoc(mod),
test/link/elf.zig+2-2
...@@ -799,8 +799,8 @@ fn testEmitStaticLib(b: *Build, opts: Options) *Step {...@@ -799,8 +799,8 @@ fn testEmitStaticLib(b: *Build, opts: Options) *Step {
799 \\}799 \\}
800 \\export var strongBar: usize = 100;800 \\export var strongBar: usize = 100;
801 \\comptime {801 \\comptime {
802 \\ @export(weakFoo, .{ .name = "weakFoo", .linkage = .Weak });802 \\ @export(weakFoo, .{ .name = "weakFoo", .linkage = .weak });
803 \\ @export(strongBar, .{ .name = "strongBarAlias", .linkage = .Strong });803 \\ @export(strongBar, .{ .name = "strongBarAlias", .linkage = .strong });
804 \\}804 \\}
805 ,805 ,
806 });806 });
test/link/macho.zig+1-1
...@@ -1153,7 +1153,7 @@ fn testReexportsZig(b: *Build, opts: Options) *Step {...@@ -1153,7 +1153,7 @@ fn testReexportsZig(b: *Build, opts: Options) *Step {
1153 \\ return x;1153 \\ return x;
1154 \\}1154 \\}
1155 \\comptime {1155 \\comptime {
1156 \\ @export(foo, .{ .name = "bar", .linkage = .Strong });1156 \\ @export(foo, .{ .name = "bar", .linkage = .strong });
1157 \\}1157 \\}
1158 });1158 });
11591159