diff --git a/lib/compiler/aro/aro/TypeStore.zig b/lib/compiler/aro/aro/TypeStore.zig index 4cc30508cc4f06c0979a565bc97f46087a381b77..00c5152f5d9e296346e680c6dd02133e3deb2daa 100644 --- a/lib/compiler/aro/aro/TypeStore.zig +++ b/lib/compiler/aro/aro/TypeStore.zig @@ -1201,9 +1201,8 @@ pub const QualType = packed struct(u32) { } pub fn linkage(qt: QualType, comp: *const Compilation) std.builtin.GlobalLinkage { - if (qt.hasAttribute(comp, .internal_linkage)) return .internal; if (qt.hasAttribute(comp, .weak)) return .weak; - if (qt.hasAttribute(comp, .selectany)) return .link_once; + if (qt.hasAttribute(comp, .selectany)) return .weak; return .strong; } diff --git a/lib/compiler_rt.zig b/lib/compiler_rt.zig index e5cffd9d7e50b7cd35dbc94c49ead55d663fb873..885af93f59009fe62c6344475b7333435e60ac93 100644 --- a/lib/compiler_rt.zig +++ b/lib/compiler_rt.zig @@ -23,27 +23,15 @@ else unreachable; pub inline fn symbol(comptime func: *const anyopaque, comptime name: []const u8) void { - @export(func, .{ .name = name, .linkage = linkage, .visibility = visibility }); + // The function shouldn't be exported at all when testing compiler_rt. + // Instead, we just need to reference the function so that it's compiled. + if (!builtin.is_test) @export(func, .{ + .name = name, + .linkage = if (ofmt_c) .strong else .weak, + .visibility = .hidden, + }); } -/// For now, we prefer weak linkage because some of the routines we implement here may also be -/// provided by system/dynamic libc. Eventually we should be more disciplined about this on a -/// per-symbol, per-target basis: https://github.com/ziglang/zig/issues/11883 -pub const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) - .internal -else if (ofmt_c) - .strong -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 (linkage == .internal or builtin.link_mode == .dynamic) - .default -else - .hidden; - pub const test_safety = switch (builtin.zig_backend) { .stage2_aarch64 => false, else => builtin.is_test, diff --git a/lib/std/lang.zig b/lib/std/lang.zig index d0fd96a912a1b8dde4a6be70aea5983d225f1204..fbe36760bca652bf37909ed033be562cdb2da489 100644 --- a/lib/std/lang.zig +++ b/lib/std/lang.zig @@ -15,11 +15,9 @@ 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(u2) { - internal, +pub const GlobalLinkage = enum(u1) { strong, weak, - link_once, }; /// This data structure is used by the Zig language code generation and diff --git a/src/InternPool.zig b/src/InternPool.zig index 30b9ab71f2d317be392537b01e1a1bc819cbb25d..68d4fae575e3f02351194f3d0c3747e0631b1c24 100644 --- a/src/InternPool.zig +++ b/src/InternPool.zig @@ -5433,7 +5433,7 @@ pub const Tag = enum(u8) { relocation: std.lang.ExternOptions.Relocation, source: Source, decoration_type: DecorationType, - _: u23 = 0, + _: u24 = 0, pub const Source = enum(u1) { builtin, syntax }; pub const DecorationType = enum(u2) { none, location, descriptor, flat }; diff --git a/src/Sema.zig b/src/Sema.zig index a960980eec00ed4a5af9d8b6ce2e35c42c0f5dee..7c573a4d63b7c543113a446ff0bd2ab170e89456 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -23107,12 +23107,6 @@ fn resolveExportOptions( return sema.fail(block, name_src, "exported symbol name cannot be empty", .{}); } - 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), - }); - } - return .{ .name = try ip.getOrPutString(gpa, io, pt.tid, name, .no_embedded_nulls), .linkage = linkage, @@ -25290,13 +25284,6 @@ fn zirBuiltinExtern( } const options = try sema.resolveExternOptions(block, options_src, extra.rhs); - switch (options.linkage) { - .internal => if (options.visibility != .default) { - return sema.fail(block, options_src, "internal symbol cannot have non-default visibility", .{}); - }, - .strong, .weak => {}, - .link_once => return sema.fail(block, options_src, "external symbol cannot have link once linkage", .{}), - } switch (options.relocation) { .any => {}, .pcrel => if (options.visibility == .default) return sema.fail(block, options_src, "cannot require a pc-relative relocation to a symbol with default visibility", .{}), diff --git a/src/Zcu/PerThread.zig b/src/Zcu/PerThread.zig index 6635be1a1428d9971b6d23f8b0d61c2ec401681b..a143fcd93f6caac80b87b4ed943e9262e113bbf4 100644 --- a/src/Zcu/PerThread.zig +++ b/src/Zcu/PerThread.zig @@ -3657,7 +3657,7 @@ pub fn processExports(pt: Zcu.PerThread) (Allocator.Error || Io.Cancelable)!void const exp = export_index.ptr(zcu); switch (exp.opts.linkage) { .strong => {}, - .weak, .internal, .link_once => continue, + .weak => continue, } const gop = exports_by_name.getOrPutAssumeCapacity(exp.opts.name); if (gop.found_existing) { diff --git a/src/codegen.zig b/src/codegen.zig index f1ddcab5750d0d311bcfbbefcf6cad82125b996a..a71f2e9d13710379a141de0b7969e31e92156cb4 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -830,53 +830,37 @@ pub fn genNavRef( log.debug("genNavRef({f})", .{nav.fqn.fmt(ip)}); const is_threadlocal = nav.resolved.?.@"threadlocal" and zcu.comp.config.any_non_single_threaded; - const lib_name, const linkage = if (nav.getExtern(ip)) |e| - .{ e.lib_name, e.linkage } - else - .{ .none, .internal }; if (lf.cast(.elf)) |elf_file| { const zo = elf_file.zigObjectPtr().?; - switch (linkage) { - .internal => { - const sym_index = try zo.getOrCreateMetadataForNav(zcu, nav_index); - if (is_threadlocal) zo.symbol(sym_index).flags.is_tls = true; - return @fromBackingInt(@intCast(sym_index)); - }, - .strong, .weak => { - const sym_index = try elf_file.getGlobalSymbol(nav.name.toSlice(ip), lib_name.toSlice(ip)); - switch (linkage) { - .internal => unreachable, - .strong => {}, - .weak => zo.symbol(sym_index).flags.weak = true, - .link_once => unreachable, - } - if (is_threadlocal) zo.symbol(sym_index).flags.is_tls = true; - return @fromBackingInt(@intCast(sym_index)); - }, - .link_once => unreachable, + if (nav.getExtern(ip)) |e| { + const sym_index = try elf_file.getGlobalSymbol(nav.name.toSlice(ip), e.lib_name.toSlice(ip)); + switch (e.linkage) { + .strong => {}, + .weak => zo.symbol(sym_index).flags.weak = true, + } + if (is_threadlocal) zo.symbol(sym_index).flags.is_tls = true; + return @fromBackingInt(@intCast(sym_index)); + } else { + const sym_index = try zo.getOrCreateMetadataForNav(zcu, nav_index); + if (is_threadlocal) zo.symbol(sym_index).flags.is_tls = true; + return @fromBackingInt(@intCast(sym_index)); } } else if (lf.cast(.elf2)) |elf| { return elf.navSymbol(nav_index); } else if (lf.cast(.macho)) |macho_file| { const zo = macho_file.getZigObject().?; - switch (linkage) { - .internal => { - const sym_index = try zo.getOrCreateMetadataForNav(macho_file, nav_index); - if (is_threadlocal) zo.symbols.items[sym_index].flags.tlv = true; - return @fromBackingInt(@intCast(sym_index)); - }, - .strong, .weak => { - const sym_index = try macho_file.getGlobalSymbol(nav.name.toSlice(ip), lib_name.toSlice(ip)); - switch (linkage) { - .internal => unreachable, - .strong => {}, - .weak => zo.symbols.items[sym_index].flags.weak = true, - .link_once => unreachable, - } - if (is_threadlocal) zo.symbols.items[sym_index].flags.tlv = true; - return @fromBackingInt(@intCast(sym_index)); - }, - .link_once => unreachable, + if (nav.getExtern(ip)) |e| { + const sym_index = try macho_file.getGlobalSymbol(nav.name.toSlice(ip), e.lib_name.toSlice(ip)); + switch (e.linkage) { + .strong => {}, + .weak => zo.symbols.items[sym_index].flags.weak = true, + } + if (is_threadlocal) zo.symbols.items[sym_index].flags.tlv = true; + return @fromBackingInt(@intCast(sym_index)); + } else { + const sym_index = try zo.getOrCreateMetadataForNav(macho_file, nav_index); + if (is_threadlocal) zo.symbols.items[sym_index].flags.tlv = true; + return @fromBackingInt(@intCast(sym_index)); } } else if (lf.cast(.coff2)) |coff| { return @fromBackingInt(@intCast(@backingInt(try coff.navSymbol(zcu, nav_index)))); diff --git a/src/codegen/c.zig b/src/codegen/c.zig index e795e5aabf10fb2a2cd54a411da64b069b04a683..4cb12fdbcdfa42680cc44e305a89b6fd85a5f499 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -2515,10 +2515,8 @@ pub fn genDeclFwd(dg: *DeclGen, w: *Writer) Error!void { }, else => { switch (@"extern".linkage) { - .internal => try w.writeAll("static "), .strong => try w.print("zig_extern zig_visibility({t}) ", .{@"extern".visibility}), .weak => try w.print("zig_extern zig_weak_linkage zig_visibility({t}) ", .{@"extern".visibility}), - .link_once => return dg.fail("TODO: CBE: implement linkonce linkage?", .{}), } if (nav.resolved.?.@"threadlocal" and !dg.mod.single_threaded) { try w.writeAll("zig_threadlocal "); diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 30bd4fc0da7d1d6539b75addb6ceee819619b2a3..d6306efe283c597de97eb703da03f25440be6757 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -1077,10 +1077,8 @@ pub const Object = struct { false => .default, }; llvm_global.ptr(&o.builder).linkage = switch (@"extern".linkage) { - .internal => if (o.builder.strip and !workaroundPrivateSymbolBugs(zcu.getTarget(), &resolved)) .private else .internal, .strong => .external, .weak => .extern_weak, - .link_once => unreachable, }; llvm_global.ptr(&o.builder).visibility = .fromSymbolVisibility(@"extern".visibility); } else { @@ -1304,10 +1302,8 @@ pub const Object = struct { if (comp.config.dll_export_fns and exp.opts.visibility != .hidden) alias_global.setDllStorageClass(.dllexport, &o.builder); alias_global.setLinkage(switch (exp.opts.linkage) { - .internal => if (o.builder.strip) .private else .internal, // we still did useful work in replacing an existing symbol if there was one .strong => .external, .weak => .weak_odr, - .link_once => .linkonce_odr, }, &o.builder); alias_global.setVisibility(switch (exp.opts.visibility) { .default => .default, diff --git a/src/link/Elf/ZigObject.zig b/src/link/Elf/ZigObject.zig index 98ca8b9f25792bd25f091735689ec6e6fecaf916..ea092197086be61f652433464a06f31a481e7ebe 100644 --- a/src/link/Elf/ZigObject.zig +++ b/src/link/Elf/ZigObject.zig @@ -1910,19 +1910,8 @@ pub fn updateExports( } } const stb_bits: u8 = switch (exp.opts.linkage) { - .internal => elf.STB_LOCAL, .strong => elf.STB_GLOBAL, .weak => elf.STB_WEAK, - .link_once => { - try zcu.failed_exports.ensureUnusedCapacity(gpa, 1); - zcu.failed_exports.putAssumeCapacityNoClobber(export_index, try Zcu.ErrorMsg.create( - gpa, - exp.src, - "Unimplemented: GlobalLinkage.LinkOnce", - .{}, - )); - continue; - }, }; const stt_bits: u8 = @as(u4, @truncate(esym.st_info)); const exp_name = exp.opts.name.toSlice(&zcu.intern_pool); diff --git a/src/link/Elf2.zig b/src/link/Elf2.zig index a697ff93f2fdcbac91400f434e95d97a247f3b75..10043990722a7482f2a537aa8191b6c81020787f 100644 --- a/src/link/Elf2.zig +++ b/src/link/Elf2.zig @@ -4245,8 +4245,6 @@ fn externSymbolInner(elf: *Elf, opts: ExternSymbolOpts) Error!Symbol.Id { .bind = switch (opts.linkage) { .strong => .strong, .weak => .weak, - .internal => return elf.base.comp.link_diags.fail("TODO(Elf2): '.internal' linkage", .{}), - .link_once => return elf.base.comp.link_diags.fail("TODO(Elf2): '.link_once' linkage", .{}), }, .visibility = switch (opts.visibility) { .default => .DEFAULT, @@ -12205,8 +12203,6 @@ fn updateExportInner( .bind = switch (@"export".opts.linkage) { .strong => .strong, .weak => .weak, - .internal => return elf.base.comp.link_diags.fail("TODO(Elf2): '.internal' linkage", .{}), - .link_once => return elf.base.comp.link_diags.fail("TODO(Elf2): '.link_once' linkage", .{}), }, .visibility = switch (@"export".opts.visibility) { .default => .DEFAULT, diff --git a/src/link/MachO/ZigObject.zig b/src/link/MachO/ZigObject.zig index 93a76ca63a92db3d6528b70f827ddc93a1c89022..6d7f9d19d3a63a102ec137c4a29f896e03b83572 100644 --- a/src/link/MachO/ZigObject.zig +++ b/src/link/MachO/ZigObject.zig @@ -1301,15 +1301,6 @@ pub fn updateExports( continue; } } - if (exp.opts.linkage == .link_once) { - try zcu.failed_exports.putNoClobber(zcu.gpa, export_index, try Zcu.ErrorMsg.create( - gpa, - exp.src, - "Unimplemented: GlobalLinkage.link_once", - .{}, - )); - continue; - } const exp_name = exp.opts.name.toSlice(&zcu.intern_pool); const global_nlist_index = try self.getGlobalSymbol(macho_file, exp_name, null); @@ -1326,11 +1317,6 @@ pub fn updateExports( global_sym.atom_ref = .{ .index = atom_index, .file = self.index }; switch (exp.opts.linkage) { - .internal => { - // Symbol should be hidden, or in MachO lingo, private extern. - global_nlist.n_type.bits.pext = true; - global_sym.visibility = .hidden; - }, .strong => { global_sym.visibility = .global; }, @@ -1341,7 +1327,6 @@ pub fn updateExports( global_sym.visibility = .global; global_sym.flags.weak = true; }, - else => unreachable, } } } diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index 30868f14272601c048c01e495e239d9819c32a85..e83fa056802e10d9c961ebdd3f77ea9355de6739 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -972,10 +972,8 @@ pub const ZcuFunc = union { const name_string = wasm.getExistingString(name_slice).?; return .{ .binding = switch (ext.linkage) { - .internal => .local, .strong => .strong, .weak => .weak, - .link_once => @panic("TODO: COMDAT"), }, .visibility_hidden = switch (ext.visibility) { .default => false, @@ -1952,10 +1950,8 @@ pub const ObjectDataImport = extern struct { const name_string = wasm.getExistingString(name_slice).?; return .{ .binding = switch (ext.linkage) { - .internal => .local, .strong => .strong, .weak => .weak, - .link_once => @panic("TODO: COMDAT"), }, .visibility_hidden = switch (ext.visibility) { .default => false, @@ -2591,10 +2587,8 @@ pub const ZcuImportIndex = enum(u32) { const name_string = wasm.getExistingString(name_slice).?; return .{ .binding = switch (ext.linkage) { - .internal => .local, .strong => .strong, .weak => .weak, - .link_once => @panic("TODO: COMDAT"), }, .visibility_hidden = switch (ext.visibility) { .default => false, diff --git a/src/link/Wasm/Flush.zig b/src/link/Wasm/Flush.zig index 413d6fd1ce27a6bdf96e95ac613e9b762f6096b8..745e3023dc0a9e61e68f7f6164c6ed220915447f 100644 --- a/src/link/Wasm/Flush.zig +++ b/src/link/Wasm/Flush.zig @@ -319,10 +319,8 @@ pub fn finish(f: *Flush, wasm: *Wasm) !void { .function_index = function_index, .flags = .{ .binding = switch (opts.linkage) { - .internal => .local, .strong => .strong, .weak => .weak, - .link_once => @panic("TODO: COMDAT"), }, .visibility_hidden = is_hidden, .exported = !is_hidden, @@ -346,10 +344,8 @@ pub fn finish(f: *Flush, wasm: *Wasm) !void { .resolution = .fromIpNav(wasm, nav_export.nav_index), .flags = if (is_obj) .{ .binding = switch (opts.linkage) { - .internal => .local, .strong => .strong, .weak => .weak, - .link_once => @panic("TODO: COMDAT"), }, .visibility_hidden = !explicit and switch (opts.visibility) { .default => false, @@ -383,10 +379,8 @@ pub fn finish(f: *Flush, wasm: *Wasm) !void { .resolution = .fromIpIndex(wasm, uav_export.uav_index), .flags = if (is_obj) .{ .binding = switch (opts.linkage) { - .internal => .local, .strong => .strong, .weak => .weak, - .link_once => @panic("TODO: COMDAT"), }, .visibility_hidden = !explicit and switch (opts.visibility) { .default => false, diff --git a/test/behavior/export_builtin.zig b/test/behavior/export_builtin.zig index 84187b403168c6ee2e786ea0e51f1fccf3c447c8..ff46cda875af235356f751a05744b3fc7451dd2e 100644 --- a/test/behavior/export_builtin.zig +++ b/test/behavior/export_builtin.zig @@ -16,18 +16,6 @@ test "exporting enum value" { try expect(S.e == .two); } -test "exporting with internal linkage" { - if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; - - const S = struct { - fn foo() callconv(.c) void {} - comptime { - @export(&foo, .{ .name = "exporting_with_internal_linkage_foo", .linkage = .internal }); - } - }; - S.foo(); -} - test "exporting using namespace access" { if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; @@ -37,7 +25,7 @@ test "exporting using namespace access" { const x: u32 = 5; }; comptime { - @export(&Inner.x, .{ .name = "foo", .linkage = .internal }); + @export(&Inner.x, .{ .name = "foo", .linkage = .strong }); } }; diff --git a/test/standalone/global_linkage/obj1.zig b/test/standalone/global_linkage/obj1.zig index fa253582444d2f69df8a91a2425c8ad6d5f5afad..227c12ae9113d7b9e826458661f70bb364e618e7 100644 --- a/test/standalone/global_linkage/obj1.zig +++ b/test/standalone/global_linkage/obj1.zig @@ -1,7 +1,5 @@ -var internal_integer: usize = 1; var obj1_integer: usize = 421; comptime { - @export(&internal_integer, .{ .name = "internal_integer", .linkage = .internal }); @export(&obj1_integer, .{ .name = "obj1_integer", .linkage = .strong }); } diff --git a/test/standalone/global_linkage/obj2.zig b/test/standalone/global_linkage/obj2.zig index d95081af111546a214e68c31621eff27c1792986..e07d4f6f3a1435b94d3804d4e911aef292954287 100644 --- a/test/standalone/global_linkage/obj2.zig +++ b/test/standalone/global_linkage/obj2.zig @@ -1,7 +1,5 @@ -var internal_integer: usize = 2; var obj2_integer: usize = 422; comptime { - @export(&internal_integer, .{ .name = "internal_integer", .linkage = .internal }); @export(&obj2_integer, .{ .name = "obj2_integer", .linkage = .strong }); } diff --git a/test/tests.zig b/test/tests.zig index 251d3f3f474ba1a7a57eea78b4ce735f101a4df1..ff475109fb084df3c5948f05c7d9b0f0a4ffd0b5 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -1294,7 +1294,6 @@ const module_test_targets = blk: { .os_tag = .linux, }, .new_linker = true, - .skip_modules = &.{ "compiler-rt", "behavior" }, // '@export' with '.internal' linkage }, .{ .target = .{ @@ -1304,7 +1303,6 @@ const module_test_targets = blk: { }, .link_libc = true, .new_linker = true, - .skip_modules = &.{ "compiler-rt", "behavior" }, // '@export' with '.internal' linkage }, .{ .target = .{ @@ -1314,7 +1312,6 @@ const module_test_targets = blk: { }, .link_libc = true, .new_linker = true, - .skip_modules = &.{ "compiler-rt", "behavior" }, // '@export' with '.internal' linkage }, // Darwin Targets