mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
std.builtin: make global linkage fields lowercase
This commit is contained in:
parent
aab84a3dec
commit
c260b4c753
15 changed files with 48 additions and 48 deletions
|
|
@ -8356,7 +8356,7 @@ test "main" {
|
|||
</p>
|
||||
{#code_begin|obj|export_builtin#}
|
||||
comptime {
|
||||
@export(internalName, .{ .name = "foo", .linkage = .Strong });
|
||||
@export(internalName, .{ .name = "foo", .linkage = .strong });
|
||||
}
|
||||
|
||||
fn internalName() callconv(.C) void {}
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@ fn clear_cache(start: usize, end: usize) callconv(.C) void {
|
|||
}
|
||||
}
|
||||
|
||||
const linkage = if (builtin.is_test) std.builtin.GlobalLinkage.Internal else std.builtin.GlobalLinkage.Weak;
|
||||
const linkage = if (builtin.is_test) std.builtin.GlobalLinkage.internal else std.builtin.GlobalLinkage.weak;
|
||||
|
||||
fn exportIt() void {
|
||||
@export(clear_cache, .{ .name = "__clear_cache", .linkage = linkage });
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@ const std = @import("std");
|
|||
const builtin = @import("builtin");
|
||||
const native_endian = builtin.cpu.arch.endian();
|
||||
|
||||
pub const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
|
||||
pub const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .internal else .weak;
|
||||
/// Determines the symbol's visibility to other objects.
|
||||
/// For WebAssembly this allows the symbol to be resolved to other modules, but will not
|
||||
/// export it to the host runtime.
|
||||
pub const visibility: std.builtin.SymbolVisibility =
|
||||
if (builtin.target.isWasm() and linkage != .Internal) .hidden else .default;
|
||||
if (builtin.target.isWasm() and linkage != .internal) .hidden else .default;
|
||||
pub const want_aeabi = switch (builtin.abi) {
|
||||
.eabi,
|
||||
.eabihf,
|
||||
|
|
|
|||
|
|
@ -64,10 +64,10 @@ pub const StackTrace = struct {
|
|||
/// This data structure is used by the Zig language code generation and
|
||||
/// therefore must be kept in sync with the compiler implementation.
|
||||
pub const GlobalLinkage = enum {
|
||||
Internal,
|
||||
Strong,
|
||||
Weak,
|
||||
LinkOnce,
|
||||
internal,
|
||||
strong,
|
||||
weak,
|
||||
link_once,
|
||||
};
|
||||
|
||||
/// This data structure is used by the Zig language code generation and
|
||||
|
|
@ -659,7 +659,7 @@ pub const PrefetchOptions = struct {
|
|||
/// therefore must be kept in sync with the compiler implementation.
|
||||
pub const ExportOptions = struct {
|
||||
name: []const u8,
|
||||
linkage: GlobalLinkage = .Strong,
|
||||
linkage: GlobalLinkage = .strong,
|
||||
section: ?[]const u8 = null,
|
||||
visibility: SymbolVisibility = .default,
|
||||
};
|
||||
|
|
@ -669,7 +669,7 @@ pub const ExportOptions = struct {
|
|||
pub const ExternOptions = struct {
|
||||
name: []const u8,
|
||||
library_name: ?[]const u8 = null,
|
||||
linkage: GlobalLinkage = .Strong,
|
||||
linkage: GlobalLinkage = .strong,
|
||||
is_thread_local: bool = false,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ const windows = std.os.windows;
|
|||
const system = std.os.system;
|
||||
|
||||
pub const DynLib = switch (builtin.os.tag) {
|
||||
.linux => if (!builtin.link_libc or builtin.abi == .musl and builtin.link_mode == .Static)
|
||||
.linux => if (!builtin.link_libc or builtin.abi == .musl and builtin.link_mode == .static)
|
||||
ElfDynLib
|
||||
else
|
||||
DlDynLib,
|
||||
|
|
|
|||
|
|
@ -279,7 +279,7 @@ pub const Export = struct {
|
|||
|
||||
pub const Options = struct {
|
||||
name: InternPool.NullTerminatedString,
|
||||
linkage: std.builtin.GlobalLinkage = .Strong,
|
||||
linkage: std.builtin.GlobalLinkage = .strong,
|
||||
section: InternPool.OptionalNullTerminatedString = .none,
|
||||
visibility: std.builtin.SymbolVisibility = .default,
|
||||
};
|
||||
|
|
|
|||
14
src/Sema.zig
14
src/Sema.zig
|
|
@ -6274,7 +6274,7 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
|
|||
.needed_comptime_reason = "export target must be comptime-known",
|
||||
});
|
||||
const options = try sema.resolveExportOptions(block, options_src, extra.options);
|
||||
if (options.linkage == .Internal)
|
||||
if (options.linkage == .internal)
|
||||
return;
|
||||
if (operand.val.getFunction(mod)) |function| {
|
||||
const decl_index = function.owner_decl;
|
||||
|
|
@ -6301,7 +6301,7 @@ pub fn analyzeExport(
|
|||
const gpa = sema.gpa;
|
||||
const mod = sema.mod;
|
||||
|
||||
if (options.linkage == .Internal)
|
||||
if (options.linkage == .internal)
|
||||
return;
|
||||
|
||||
try mod.ensureDeclAnalyzed(exported_decl_index);
|
||||
|
|
@ -23802,7 +23802,7 @@ fn resolveExportOptions(
|
|||
return sema.fail(block, name_src, "exported symbol name cannot be empty", .{});
|
||||
}
|
||||
|
||||
if (visibility != .default and linkage == .Internal) {
|
||||
if (visibility != .default and linkage == .internal) {
|
||||
return sema.fail(block, visibility_src, "symbol '{s}' exported with internal linkage has non-default visibility {s}", .{
|
||||
name, @tagName(visibility),
|
||||
});
|
||||
|
|
@ -25888,7 +25888,7 @@ fn resolveExternOptions(
|
|||
) CompileError!struct {
|
||||
name: InternPool.NullTerminatedString,
|
||||
library_name: InternPool.OptionalNullTerminatedString = .none,
|
||||
linkage: std.builtin.GlobalLinkage = .Strong,
|
||||
linkage: std.builtin.GlobalLinkage = .strong,
|
||||
is_thread_local: bool = false,
|
||||
} {
|
||||
const mod = sema.mod;
|
||||
|
|
@ -25938,7 +25938,7 @@ fn resolveExternOptions(
|
|||
return sema.fail(block, name_src, "extern symbol name cannot be empty", .{});
|
||||
}
|
||||
|
||||
if (linkage != .Weak and linkage != .Strong) {
|
||||
if (linkage != .weak and linkage != .strong) {
|
||||
return sema.fail(block, linkage_src, "extern symbol must use strong or weak linkage", .{});
|
||||
}
|
||||
|
||||
|
|
@ -25984,7 +25984,7 @@ fn zirBuiltinExtern(
|
|||
else => |e| return e,
|
||||
};
|
||||
|
||||
if (options.linkage == .Weak and !ty.ptrAllowsZero(mod)) {
|
||||
if (options.linkage == .weak and !ty.ptrAllowsZero(mod)) {
|
||||
ty = try mod.optionalType(ty.toIntern());
|
||||
}
|
||||
const ptr_info = ty.ptrInfo(mod);
|
||||
|
|
@ -26010,7 +26010,7 @@ fn zirBuiltinExtern(
|
|||
.is_extern = true,
|
||||
.is_const = ptr_info.flags.is_const,
|
||||
.is_threadlocal = options.is_thread_local,
|
||||
.is_weak_linkage = options.linkage == .Weak,
|
||||
.is_weak_linkage = options.linkage == .weak,
|
||||
} }),
|
||||
),
|
||||
}, options.name);
|
||||
|
|
|
|||
|
|
@ -1999,7 +1999,7 @@ pub const DeclGen = struct {
|
|||
try fwd.writeAll(if (is_global) "zig_extern " else "static ");
|
||||
const maybe_exports = dg.module.decl_exports.get(decl_index);
|
||||
const export_weak_linkage = if (maybe_exports) |exports|
|
||||
exports.items[0].opts.linkage == .Weak
|
||||
exports.items[0].opts.linkage == .weak
|
||||
else
|
||||
false;
|
||||
if (variable.is_weak_linkage or export_weak_linkage) try fwd.writeAll("zig_weak_linkage ");
|
||||
|
|
@ -2689,7 +2689,7 @@ fn genExports(o: *Object) !void {
|
|||
const is_variable_const = switch (ip.indexToKey(tv.val.toIntern())) {
|
||||
.func => return for (exports.items[1..], 1..) |@"export", i| {
|
||||
try fwd.writeAll("zig_extern ");
|
||||
if (@"export".opts.linkage == .Weak) try fwd.writeAll("zig_weak_linkage_fn ");
|
||||
if (@"export".opts.linkage == .weak) try fwd.writeAll("zig_weak_linkage_fn ");
|
||||
try o.dg.renderFunctionSignature(
|
||||
fwd,
|
||||
decl_index,
|
||||
|
|
@ -2707,7 +2707,7 @@ fn genExports(o: *Object) !void {
|
|||
};
|
||||
for (exports.items[1..]) |@"export"| {
|
||||
try fwd.writeAll("zig_extern ");
|
||||
if (@"export".opts.linkage == .Weak) try fwd.writeAll("zig_weak_linkage ");
|
||||
if (@"export".opts.linkage == .weak) try fwd.writeAll("zig_weak_linkage ");
|
||||
const export_name = ip.stringToSlice(@"export".opts.name);
|
||||
try o.dg.renderTypeAndName(
|
||||
fwd,
|
||||
|
|
@ -2842,7 +2842,7 @@ pub fn genFunc(f: *Function) !void {
|
|||
try fwd_decl_writer.writeAll(if (is_global) "zig_extern " else "static ");
|
||||
|
||||
if (mod.decl_exports.get(decl_index)) |exports|
|
||||
if (exports.items[0].opts.linkage == .Weak) try fwd_decl_writer.writeAll("zig_weak_linkage_fn ");
|
||||
if (exports.items[0].opts.linkage == .weak) try fwd_decl_writer.writeAll("zig_weak_linkage_fn ");
|
||||
try o.dg.renderFunctionSignature(fwd_decl_writer, decl_index, .forward, .{ .export_index = 0 });
|
||||
try fwd_decl_writer.writeAll(";\n");
|
||||
try genExports(o);
|
||||
|
|
|
|||
|
|
@ -1873,10 +1873,10 @@ pub const Object = struct {
|
|||
if (comp.config.dll_export_fns)
|
||||
global_index.setDllStorageClass(.dllexport, &o.builder);
|
||||
global_index.setLinkage(switch (exports[0].opts.linkage) {
|
||||
.Internal => unreachable,
|
||||
.Strong => .external,
|
||||
.Weak => .weak_odr,
|
||||
.LinkOnce => .linkonce_odr,
|
||||
.internal => unreachable,
|
||||
.strong => .external,
|
||||
.weak => .weak_odr,
|
||||
.link_once => .linkonce_odr,
|
||||
}, &o.builder);
|
||||
global_index.setVisibility(switch (exports[0].opts.visibility) {
|
||||
.default => .default,
|
||||
|
|
|
|||
|
|
@ -1599,11 +1599,11 @@ pub fn updateExports(
|
|||
}
|
||||
}
|
||||
|
||||
if (exp.opts.linkage == .LinkOnce) {
|
||||
if (exp.opts.linkage == .link_once) {
|
||||
try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(
|
||||
gpa,
|
||||
exp.getSrcLoc(mod),
|
||||
"Unimplemented: GlobalLinkage.LinkOnce",
|
||||
"Unimplemented: GlobalLinkage.link_once",
|
||||
.{},
|
||||
));
|
||||
continue;
|
||||
|
|
@ -1633,11 +1633,11 @@ pub fn updateExports(
|
|||
sym.type = atom.getSymbol(self).type;
|
||||
|
||||
switch (exp.opts.linkage) {
|
||||
.Strong => {
|
||||
.strong => {
|
||||
sym.storage_class = .EXTERNAL;
|
||||
},
|
||||
.Internal => @panic("TODO Internal"),
|
||||
.Weak => @panic("TODO WeakExternal"),
|
||||
.internal => @panic("TODO Internal"),
|
||||
.weak => @panic("TODO WeakExternal"),
|
||||
else => unreachable,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1436,10 +1436,10 @@ pub fn updateExports(
|
|||
}
|
||||
}
|
||||
const stb_bits: u8 = switch (exp.opts.linkage) {
|
||||
.Internal => elf.STB_LOCAL,
|
||||
.Strong => elf.STB_GLOBAL,
|
||||
.Weak => elf.STB_WEAK,
|
||||
.LinkOnce => {
|
||||
.internal => elf.STB_LOCAL,
|
||||
.strong => elf.STB_GLOBAL,
|
||||
.weak => elf.STB_WEAK,
|
||||
.link_once => {
|
||||
try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
|
||||
mod.failed_exports.putAssumeCapacityNoClobber(exp, try Module.ErrorMsg.create(
|
||||
gpa,
|
||||
|
|
|
|||
|
|
@ -1216,11 +1216,11 @@ pub fn updateExports(
|
|||
continue;
|
||||
}
|
||||
}
|
||||
if (exp.opts.linkage == .LinkOnce) {
|
||||
if (exp.opts.linkage == .link_once) {
|
||||
try mod.failed_exports.putNoClobber(mod.gpa, exp, try Module.ErrorMsg.create(
|
||||
gpa,
|
||||
exp.getSrcLoc(mod),
|
||||
"Unimplemented: GlobalLinkage.LinkOnce",
|
||||
"Unimplemented: GlobalLinkage.link_once",
|
||||
.{},
|
||||
));
|
||||
continue;
|
||||
|
|
@ -1242,12 +1242,12 @@ pub fn updateExports(
|
|||
self.symtab.items(.atom)[global_nlist_index] = self.symtab.items(.atom)[nlist_idx];
|
||||
|
||||
switch (exp.opts.linkage) {
|
||||
.Internal => {
|
||||
.internal => {
|
||||
// Symbol should be hidden, or in MachO lingo, private extern.
|
||||
global_nlist.n_type |= macho.N_PEXT;
|
||||
},
|
||||
.Strong => {},
|
||||
.Weak => {
|
||||
.strong => {},
|
||||
.weak => {
|
||||
// Weak linkage is specified as part of n_desc field.
|
||||
// Symbol's n_type is like for a symbol with strong linkage.
|
||||
global_nlist.n_desc |= macho.N_WEAK_DEF;
|
||||
|
|
|
|||
|
|
@ -896,14 +896,14 @@ pub fn updateExports(
|
|||
sym.name = export_name;
|
||||
|
||||
switch (exp.opts.linkage) {
|
||||
.Internal => {
|
||||
.internal => {
|
||||
sym.setFlag(.WASM_SYM_VISIBILITY_HIDDEN);
|
||||
},
|
||||
.Weak => {
|
||||
.weak => {
|
||||
sym.setFlag(.WASM_SYM_BINDING_WEAK);
|
||||
},
|
||||
.Strong => {}, // symbols are strong by default
|
||||
.LinkOnce => {
|
||||
.strong => {}, // symbols are strong by default
|
||||
.link_once => {
|
||||
try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(
|
||||
gpa,
|
||||
decl.srcLoc(mod),
|
||||
|
|
|
|||
|
|
@ -799,8 +799,8 @@ fn testEmitStaticLib(b: *Build, opts: Options) *Step {
|
|||
\\}
|
||||
\\export var strongBar: usize = 100;
|
||||
\\comptime {
|
||||
\\ @export(weakFoo, .{ .name = "weakFoo", .linkage = .Weak });
|
||||
\\ @export(strongBar, .{ .name = "strongBarAlias", .linkage = .Strong });
|
||||
\\ @export(weakFoo, .{ .name = "weakFoo", .linkage = .weak });
|
||||
\\ @export(strongBar, .{ .name = "strongBarAlias", .linkage = .strong });
|
||||
\\}
|
||||
,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1153,7 +1153,7 @@ fn testReexportsZig(b: *Build, opts: Options) *Step {
|
|||
\\ return x;
|
||||
\\}
|
||||
\\comptime {
|
||||
\\ @export(foo, .{ .name = "bar", .linkage = .Strong });
|
||||
\\ @export(foo, .{ .name = "bar", .linkage = .strong });
|
||||
\\}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue