New @export() handling

Use a struct as second parameter to be future proof (and also allows to
specify default values for the parameters)

Closes #2679 as it was just a matter of a few lines of code.
master
LemonBoy 2020-01-09 10:36:51 +01:00 committed by Andrew Kelley
parent 4613e4d15f
commit 5ab5de89c0
13 changed files with 314 additions and 277 deletions

View File

@ -7327,21 +7327,21 @@ test "main" {
{#header_close#} {#header_close#}
{#header_open|@export#} {#header_open|@export#}
<pre>{#syntax#}@export(comptime name: []const u8, target: var, linkage: builtin.GlobalLinkage) void{#endsyntax#}</pre> <pre>{#syntax#}@export(target: var, comptime options: std.builtin.ExportOptions) void{#endsyntax#}</pre>
<p> <p>
Creates a symbol in the output object file. Creates a symbol in the output object file.
</p> </p>
<p> <p>
This function can be called from a {#link|comptime#} block to conditionally export symbols. This function can be called from a {#link|comptime#} block to conditionally export symbols.
When {#syntax#}target{#endsyntax#} is a function with the C calling convention and When {#syntax#}target{#endsyntax#} is a function with the C calling convention and
{#syntax#}linkage{#endsyntax#} is {#syntax#}Strong{#endsyntax#}, this is equivalent to {#syntax#}options.linkage{#endsyntax#} is {#syntax#}Strong{#endsyntax#}, this is equivalent to
the {#syntax#}export{#endsyntax#} keyword used on a function: the {#syntax#}export{#endsyntax#} keyword used on a function:
</p> </p>
{#code_begin|obj#} {#code_begin|obj#}
const builtin = @import("builtin"); const builtin = @import("builtin");
comptime { comptime {
@export("foo", internalName, builtin.GlobalLinkage.Strong); @export(internalName, .{ .name = "foo", .linkage = .Strong });
} }
extern fn internalName() void {} extern fn internalName() void {}

View File

@ -419,6 +419,14 @@ pub const CallOptions = 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 ExportOptions = struct {
name: []const u8,
linkage: GlobalLinkage = .Strong,
section: ?[]const u8 = null,
};
/// This function type is used by the Zig language code generation and /// This function type is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation. /// therefore must be kept in sync with the compiler implementation.
pub const TestFn = struct { pub const TestFn = struct {

View File

@ -37,7 +37,7 @@ const mach_hdr = if (@sizeOf(usize) == 8) mach_header_64 else mach_header;
pub extern "c" var _mh_execute_header: mach_hdr = undefined; pub extern "c" var _mh_execute_header: mach_hdr = undefined;
comptime { comptime {
if (std.Target.current.isDarwin()) { if (std.Target.current.isDarwin()) {
@export("_mh_execute_header", _mh_execute_header, .Weak); @export(_mh_execute_header, .{ .name = "_mh_execute_header", .linkage = .Weak });
} }
} }

View File

@ -23,17 +23,17 @@ const is_freestanding = switch (builtin.os) {
}; };
comptime { comptime {
if (is_freestanding and is_wasm and builtin.link_libc) { if (is_freestanding and is_wasm and builtin.link_libc) {
@export("_start", wasm_start, .Strong); @export(wasm_start, .{ .name = "_start", .linkage = .Strong });
} }
if (builtin.link_libc) { if (builtin.link_libc) {
@export("strcmp", strcmp, .Strong); @export(strcmp, .{ .name = "strcmp", .linkage = .Strong });
@export("strncmp", strncmp, .Strong); @export(strncmp, .{ .name = "strncmp", .linkage = .Strong });
@export("strerror", strerror, .Strong); @export(strerror, .{ .name = "strerror", .linkage = .Strong });
@export("strlen", strlen, .Strong); @export(strlen, .{ .name = "strlen", .linkage = .Strong });
} else if (is_msvc) { } else if (is_msvc) {
@export("_fltused", _fltused, .Strong); @export(_fltused, .{ .name = "_fltused", .linkage = .Strong });
} else if (builtin.arch == builtin.Arch.arm and builtin.os == .linux) { } else if (builtin.arch == builtin.Arch.arm and builtin.os == .linux) {
@export("__aeabi_read_tp", std.os.linux.getThreadPointer, .Strong); @export(std.os.linux.getThreadPointer, .{ .name = "__aeabi_read_tp", .linkage = .Strong });
} }
} }
@ -182,10 +182,10 @@ comptime {
builtin.mode != builtin.Mode.ReleaseSmall and builtin.mode != builtin.Mode.ReleaseSmall and
builtin.os != builtin.Os.windows) builtin.os != builtin.Os.windows)
{ {
@export("__stack_chk_fail", __stack_chk_fail, builtin.GlobalLinkage.Strong); @export(__stack_chk_fail, .{ .name = "__stack_chk_fail" });
} }
if (builtin.os == builtin.Os.linux) { if (builtin.os == builtin.Os.linux) {
@export("clone", clone, builtin.GlobalLinkage.Strong); @export(clone, .{ .name = "clone" });
} }
} }
fn __stack_chk_fail() callconv(.C) noreturn { fn __stack_chk_fail() callconv(.C) noreturn {

View File

@ -12,289 +12,289 @@ comptime {
const strong_linkage = if (is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.Strong; const strong_linkage = if (is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.Strong;
switch (builtin.arch) { switch (builtin.arch) {
.i386, .x86_64 => @export("__zig_probe_stack", @import("compiler_rt/stack_probe.zig").zig_probe_stack, linkage), .i386, .x86_64 => @export(@import("compiler_rt/stack_probe.zig").zig_probe_stack, .{ .name = "__zig_probe_stack", .linkage = linkage }),
else => {}, else => {},
} }
@export("__lesf2", @import("compiler_rt/comparesf2.zig").__lesf2, linkage); @export(@import("compiler_rt/comparesf2.zig").__lesf2, .{ .name = "__lesf2", .linkage = linkage });
@export("__ledf2", @import("compiler_rt/comparedf2.zig").__ledf2, linkage); @export(@import("compiler_rt/comparedf2.zig").__ledf2, .{ .name = "__ledf2", .linkage = linkage });
@export("__letf2", @import("compiler_rt/comparetf2.zig").__letf2, linkage); @export(@import("compiler_rt/comparetf2.zig").__letf2, .{ .name = "__letf2", .linkage = linkage });
@export("__gesf2", @import("compiler_rt/comparesf2.zig").__gesf2, linkage); @export(@import("compiler_rt/comparesf2.zig").__gesf2, .{ .name = "__gesf2", .linkage = linkage });
@export("__gedf2", @import("compiler_rt/comparedf2.zig").__gedf2, linkage); @export(@import("compiler_rt/comparedf2.zig").__gedf2, .{ .name = "__gedf2", .linkage = linkage });
@export("__getf2", @import("compiler_rt/comparetf2.zig").__getf2, linkage); @export(@import("compiler_rt/comparetf2.zig").__getf2, .{ .name = "__getf2", .linkage = linkage });
if (!is_test) { if (!is_test) {
@export("__cmpsf2", @import("compiler_rt/comparesf2.zig").__lesf2, linkage); @export(@import("compiler_rt/comparesf2.zig").__lesf2, .{ .name = "__cmpsf2", .linkage = linkage });
@export("__cmpdf2", @import("compiler_rt/comparedf2.zig").__ledf2, linkage); @export(@import("compiler_rt/comparedf2.zig").__ledf2, .{ .name = "__cmpdf2", .linkage = linkage });
@export("__cmptf2", @import("compiler_rt/comparetf2.zig").__letf2, linkage); @export(@import("compiler_rt/comparetf2.zig").__letf2, .{ .name = "__cmptf2", .linkage = linkage });
@export("__eqsf2", @import("compiler_rt/comparesf2.zig").__eqsf2, linkage); @export(@import("compiler_rt/comparesf2.zig").__eqsf2, .{ .name = "__eqsf2", .linkage = linkage });
@export("__eqdf2", @import("compiler_rt/comparedf2.zig").__eqdf2, linkage); @export(@import("compiler_rt/comparedf2.zig").__eqdf2, .{ .name = "__eqdf2", .linkage = linkage });
@export("__eqtf2", @import("compiler_rt/comparetf2.zig").__letf2, linkage); @export(@import("compiler_rt/comparetf2.zig").__letf2, .{ .name = "__eqtf2", .linkage = linkage });
@export("__ltsf2", @import("compiler_rt/comparesf2.zig").__ltsf2, linkage); @export(@import("compiler_rt/comparesf2.zig").__ltsf2, .{ .name = "__ltsf2", .linkage = linkage });
@export("__ltdf2", @import("compiler_rt/comparedf2.zig").__ltdf2, linkage); @export(@import("compiler_rt/comparedf2.zig").__ltdf2, .{ .name = "__ltdf2", .linkage = linkage });
@export("__lttf2", @import("compiler_rt/comparetf2.zig").__letf2, linkage); @export(@import("compiler_rt/comparetf2.zig").__letf2, .{ .name = "__lttf2", .linkage = linkage });
@export("__nesf2", @import("compiler_rt/comparesf2.zig").__nesf2, linkage); @export(@import("compiler_rt/comparesf2.zig").__nesf2, .{ .name = "__nesf2", .linkage = linkage });
@export("__nedf2", @import("compiler_rt/comparedf2.zig").__nedf2, linkage); @export(@import("compiler_rt/comparedf2.zig").__nedf2, .{ .name = "__nedf2", .linkage = linkage });
@export("__netf2", @import("compiler_rt/comparetf2.zig").__letf2, linkage); @export(@import("compiler_rt/comparetf2.zig").__letf2, .{ .name = "__netf2", .linkage = linkage });
@export("__gtsf2", @import("compiler_rt/comparesf2.zig").__gtsf2, linkage); @export(@import("compiler_rt/comparesf2.zig").__gtsf2, .{ .name = "__gtsf2", .linkage = linkage });
@export("__gtdf2", @import("compiler_rt/comparedf2.zig").__gtdf2, linkage); @export(@import("compiler_rt/comparedf2.zig").__gtdf2, .{ .name = "__gtdf2", .linkage = linkage });
@export("__gttf2", @import("compiler_rt/comparetf2.zig").__getf2, linkage); @export(@import("compiler_rt/comparetf2.zig").__getf2, .{ .name = "__gttf2", .linkage = linkage });
@export("__gnu_h2f_ieee", @import("compiler_rt/extendXfYf2.zig").__extendhfsf2, linkage); @export(@import("compiler_rt/extendXfYf2.zig").__extendhfsf2, .{ .name = "__gnu_h2f_ieee", .linkage = linkage });
@export("__gnu_f2h_ieee", @import("compiler_rt/truncXfYf2.zig").__truncsfhf2, linkage); @export(@import("compiler_rt/truncXfYf2.zig").__truncsfhf2, .{ .name = "__gnu_f2h_ieee", .linkage = linkage });
} }
@export("__unordsf2", @import("compiler_rt/comparesf2.zig").__unordsf2, linkage); @export(@import("compiler_rt/comparesf2.zig").__unordsf2, .{ .name = "__unordsf2", .linkage = linkage });
@export("__unorddf2", @import("compiler_rt/comparedf2.zig").__unorddf2, linkage); @export(@import("compiler_rt/comparedf2.zig").__unorddf2, .{ .name = "__unorddf2", .linkage = linkage });
@export("__unordtf2", @import("compiler_rt/comparetf2.zig").__unordtf2, linkage); @export(@import("compiler_rt/comparetf2.zig").__unordtf2, .{ .name = "__unordtf2", .linkage = linkage });
@export("__addsf3", @import("compiler_rt/addXf3.zig").__addsf3, linkage); @export(@import("compiler_rt/addXf3.zig").__addsf3, .{ .name = "__addsf3", .linkage = linkage });
@export("__adddf3", @import("compiler_rt/addXf3.zig").__adddf3, linkage); @export(@import("compiler_rt/addXf3.zig").__adddf3, .{ .name = "__adddf3", .linkage = linkage });
@export("__addtf3", @import("compiler_rt/addXf3.zig").__addtf3, linkage); @export(@import("compiler_rt/addXf3.zig").__addtf3, .{ .name = "__addtf3", .linkage = linkage });
@export("__subsf3", @import("compiler_rt/addXf3.zig").__subsf3, linkage); @export(@import("compiler_rt/addXf3.zig").__subsf3, .{ .name = "__subsf3", .linkage = linkage });
@export("__subdf3", @import("compiler_rt/addXf3.zig").__subdf3, linkage); @export(@import("compiler_rt/addXf3.zig").__subdf3, .{ .name = "__subdf3", .linkage = linkage });
@export("__subtf3", @import("compiler_rt/addXf3.zig").__subtf3, linkage); @export(@import("compiler_rt/addXf3.zig").__subtf3, .{ .name = "__subtf3", .linkage = linkage });
@export("__mulsf3", @import("compiler_rt/mulXf3.zig").__mulsf3, linkage); @export(@import("compiler_rt/mulXf3.zig").__mulsf3, .{ .name = "__mulsf3", .linkage = linkage });
@export("__muldf3", @import("compiler_rt/mulXf3.zig").__muldf3, linkage); @export(@import("compiler_rt/mulXf3.zig").__muldf3, .{ .name = "__muldf3", .linkage = linkage });
@export("__multf3", @import("compiler_rt/mulXf3.zig").__multf3, linkage); @export(@import("compiler_rt/mulXf3.zig").__multf3, .{ .name = "__multf3", .linkage = linkage });
@export("__divsf3", @import("compiler_rt/divsf3.zig").__divsf3, linkage); @export(@import("compiler_rt/divsf3.zig").__divsf3, .{ .name = "__divsf3", .linkage = linkage });
@export("__divdf3", @import("compiler_rt/divdf3.zig").__divdf3, linkage); @export(@import("compiler_rt/divdf3.zig").__divdf3, .{ .name = "__divdf3", .linkage = linkage });
@export("__ashlti3", @import("compiler_rt/ashlti3.zig").__ashlti3, linkage); @export(@import("compiler_rt/ashlti3.zig").__ashlti3, .{ .name = "__ashlti3", .linkage = linkage });
@export("__lshrti3", @import("compiler_rt/lshrti3.zig").__lshrti3, linkage); @export(@import("compiler_rt/lshrti3.zig").__lshrti3, .{ .name = "__lshrti3", .linkage = linkage });
@export("__ashrti3", @import("compiler_rt/ashrti3.zig").__ashrti3, linkage); @export(@import("compiler_rt/ashrti3.zig").__ashrti3, .{ .name = "__ashrti3", .linkage = linkage });
@export("__floatsidf", @import("compiler_rt/floatsiXf.zig").__floatsidf, linkage); @export(@import("compiler_rt/floatsiXf.zig").__floatsidf, .{ .name = "__floatsidf", .linkage = linkage });
@export("__floatsisf", @import("compiler_rt/floatsiXf.zig").__floatsisf, linkage); @export(@import("compiler_rt/floatsiXf.zig").__floatsisf, .{ .name = "__floatsisf", .linkage = linkage });
@export("__floatdidf", @import("compiler_rt/floatdidf.zig").__floatdidf, linkage); @export(@import("compiler_rt/floatdidf.zig").__floatdidf, .{ .name = "__floatdidf", .linkage = linkage });
@export("__floatsitf", @import("compiler_rt/floatsiXf.zig").__floatsitf, linkage); @export(@import("compiler_rt/floatsiXf.zig").__floatsitf, .{ .name = "__floatsitf", .linkage = linkage });
@export("__floatunsisf", @import("compiler_rt/floatunsisf.zig").__floatunsisf, linkage); @export(@import("compiler_rt/floatunsisf.zig").__floatunsisf, .{ .name = "__floatunsisf", .linkage = linkage });
@export("__floatundisf", @import("compiler_rt/floatundisf.zig").__floatundisf, linkage); @export(@import("compiler_rt/floatundisf.zig").__floatundisf, .{ .name = "__floatundisf", .linkage = linkage });
@export("__floatunsidf", @import("compiler_rt/floatunsidf.zig").__floatunsidf, linkage); @export(@import("compiler_rt/floatunsidf.zig").__floatunsidf, .{ .name = "__floatunsidf", .linkage = linkage });
@export("__floatundidf", @import("compiler_rt/floatundidf.zig").__floatundidf, linkage); @export(@import("compiler_rt/floatundidf.zig").__floatundidf, .{ .name = "__floatundidf", .linkage = linkage });
@export("__floattitf", @import("compiler_rt/floattitf.zig").__floattitf, linkage); @export(@import("compiler_rt/floattitf.zig").__floattitf, .{ .name = "__floattitf", .linkage = linkage });
@export("__floattidf", @import("compiler_rt/floattidf.zig").__floattidf, linkage); @export(@import("compiler_rt/floattidf.zig").__floattidf, .{ .name = "__floattidf", .linkage = linkage });
@export("__floattisf", @import("compiler_rt/floattisf.zig").__floattisf, linkage); @export(@import("compiler_rt/floattisf.zig").__floattisf, .{ .name = "__floattisf", .linkage = linkage });
@export("__floatunditf", @import("compiler_rt/floatunditf.zig").__floatunditf, linkage); @export(@import("compiler_rt/floatunditf.zig").__floatunditf, .{ .name = "__floatunditf", .linkage = linkage });
@export("__floatunsitf", @import("compiler_rt/floatunsitf.zig").__floatunsitf, linkage); @export(@import("compiler_rt/floatunsitf.zig").__floatunsitf, .{ .name = "__floatunsitf", .linkage = linkage });
@export("__floatuntitf", @import("compiler_rt/floatuntitf.zig").__floatuntitf, linkage); @export(@import("compiler_rt/floatuntitf.zig").__floatuntitf, .{ .name = "__floatuntitf", .linkage = linkage });
@export("__floatuntidf", @import("compiler_rt/floatuntidf.zig").__floatuntidf, linkage); @export(@import("compiler_rt/floatuntidf.zig").__floatuntidf, .{ .name = "__floatuntidf", .linkage = linkage });
@export("__floatuntisf", @import("compiler_rt/floatuntisf.zig").__floatuntisf, linkage); @export(@import("compiler_rt/floatuntisf.zig").__floatuntisf, .{ .name = "__floatuntisf", .linkage = linkage });
@export("__extenddftf2", @import("compiler_rt/extendXfYf2.zig").__extenddftf2, linkage); @export(@import("compiler_rt/extendXfYf2.zig").__extenddftf2, .{ .name = "__extenddftf2", .linkage = linkage });
@export("__extendsftf2", @import("compiler_rt/extendXfYf2.zig").__extendsftf2, linkage); @export(@import("compiler_rt/extendXfYf2.zig").__extendsftf2, .{ .name = "__extendsftf2", .linkage = linkage });
@export("__extendhfsf2", @import("compiler_rt/extendXfYf2.zig").__extendhfsf2, linkage); @export(@import("compiler_rt/extendXfYf2.zig").__extendhfsf2, .{ .name = "__extendhfsf2", .linkage = linkage });
@export("__truncsfhf2", @import("compiler_rt/truncXfYf2.zig").__truncsfhf2, linkage); @export(@import("compiler_rt/truncXfYf2.zig").__truncsfhf2, .{ .name = "__truncsfhf2", .linkage = linkage });
@export("__truncdfhf2", @import("compiler_rt/truncXfYf2.zig").__truncdfhf2, linkage); @export(@import("compiler_rt/truncXfYf2.zig").__truncdfhf2, .{ .name = "__truncdfhf2", .linkage = linkage });
@export("__trunctfdf2", @import("compiler_rt/truncXfYf2.zig").__trunctfdf2, linkage); @export(@import("compiler_rt/truncXfYf2.zig").__trunctfdf2, .{ .name = "__trunctfdf2", .linkage = linkage });
@export("__trunctfsf2", @import("compiler_rt/truncXfYf2.zig").__trunctfsf2, linkage); @export(@import("compiler_rt/truncXfYf2.zig").__trunctfsf2, .{ .name = "__trunctfsf2", .linkage = linkage });
@export("__truncdfsf2", @import("compiler_rt/truncXfYf2.zig").__truncdfsf2, linkage); @export(@import("compiler_rt/truncXfYf2.zig").__truncdfsf2, .{ .name = "__truncdfsf2", .linkage = linkage });
@export("__extendsfdf2", @import("compiler_rt/extendXfYf2.zig").__extendsfdf2, linkage); @export(@import("compiler_rt/extendXfYf2.zig").__extendsfdf2, .{ .name = "__extendsfdf2", .linkage = linkage });
@export("__fixunssfsi", @import("compiler_rt/fixunssfsi.zig").__fixunssfsi, linkage); @export(@import("compiler_rt/fixunssfsi.zig").__fixunssfsi, .{ .name = "__fixunssfsi", .linkage = linkage });
@export("__fixunssfdi", @import("compiler_rt/fixunssfdi.zig").__fixunssfdi, linkage); @export(@import("compiler_rt/fixunssfdi.zig").__fixunssfdi, .{ .name = "__fixunssfdi", .linkage = linkage });
@export("__fixunssfti", @import("compiler_rt/fixunssfti.zig").__fixunssfti, linkage); @export(@import("compiler_rt/fixunssfti.zig").__fixunssfti, .{ .name = "__fixunssfti", .linkage = linkage });
@export("__fixunsdfsi", @import("compiler_rt/fixunsdfsi.zig").__fixunsdfsi, linkage); @export(@import("compiler_rt/fixunsdfsi.zig").__fixunsdfsi, .{ .name = "__fixunsdfsi", .linkage = linkage });
@export("__fixunsdfdi", @import("compiler_rt/fixunsdfdi.zig").__fixunsdfdi, linkage); @export(@import("compiler_rt/fixunsdfdi.zig").__fixunsdfdi, .{ .name = "__fixunsdfdi", .linkage = linkage });
@export("__fixunsdfti", @import("compiler_rt/fixunsdfti.zig").__fixunsdfti, linkage); @export(@import("compiler_rt/fixunsdfti.zig").__fixunsdfti, .{ .name = "__fixunsdfti", .linkage = linkage });
@export("__fixunstfsi", @import("compiler_rt/fixunstfsi.zig").__fixunstfsi, linkage); @export(@import("compiler_rt/fixunstfsi.zig").__fixunstfsi, .{ .name = "__fixunstfsi", .linkage = linkage });
@export("__fixunstfdi", @import("compiler_rt/fixunstfdi.zig").__fixunstfdi, linkage); @export(@import("compiler_rt/fixunstfdi.zig").__fixunstfdi, .{ .name = "__fixunstfdi", .linkage = linkage });
@export("__fixunstfti", @import("compiler_rt/fixunstfti.zig").__fixunstfti, linkage); @export(@import("compiler_rt/fixunstfti.zig").__fixunstfti, .{ .name = "__fixunstfti", .linkage = linkage });
@export("__fixdfdi", @import("compiler_rt/fixdfdi.zig").__fixdfdi, linkage); @export(@import("compiler_rt/fixdfdi.zig").__fixdfdi, .{ .name = "__fixdfdi", .linkage = linkage });
@export("__fixdfsi", @import("compiler_rt/fixdfsi.zig").__fixdfsi, linkage); @export(@import("compiler_rt/fixdfsi.zig").__fixdfsi, .{ .name = "__fixdfsi", .linkage = linkage });
@export("__fixdfti", @import("compiler_rt/fixdfti.zig").__fixdfti, linkage); @export(@import("compiler_rt/fixdfti.zig").__fixdfti, .{ .name = "__fixdfti", .linkage = linkage });
@export("__fixsfdi", @import("compiler_rt/fixsfdi.zig").__fixsfdi, linkage); @export(@import("compiler_rt/fixsfdi.zig").__fixsfdi, .{ .name = "__fixsfdi", .linkage = linkage });
@export("__fixsfsi", @import("compiler_rt/fixsfsi.zig").__fixsfsi, linkage); @export(@import("compiler_rt/fixsfsi.zig").__fixsfsi, .{ .name = "__fixsfsi", .linkage = linkage });
@export("__fixsfti", @import("compiler_rt/fixsfti.zig").__fixsfti, linkage); @export(@import("compiler_rt/fixsfti.zig").__fixsfti, .{ .name = "__fixsfti", .linkage = linkage });
@export("__fixtfdi", @import("compiler_rt/fixtfdi.zig").__fixtfdi, linkage); @export(@import("compiler_rt/fixtfdi.zig").__fixtfdi, .{ .name = "__fixtfdi", .linkage = linkage });
@export("__fixtfsi", @import("compiler_rt/fixtfsi.zig").__fixtfsi, linkage); @export(@import("compiler_rt/fixtfsi.zig").__fixtfsi, .{ .name = "__fixtfsi", .linkage = linkage });
@export("__fixtfti", @import("compiler_rt/fixtfti.zig").__fixtfti, linkage); @export(@import("compiler_rt/fixtfti.zig").__fixtfti, .{ .name = "__fixtfti", .linkage = linkage });
@export("__udivmoddi4", @import("compiler_rt/udivmoddi4.zig").__udivmoddi4, linkage); @export(@import("compiler_rt/udivmoddi4.zig").__udivmoddi4, .{ .name = "__udivmoddi4", .linkage = linkage });
@export("__popcountdi2", @import("compiler_rt/popcountdi2.zig").__popcountdi2, linkage); @export(@import("compiler_rt/popcountdi2.zig").__popcountdi2, .{ .name = "__popcountdi2", .linkage = linkage });
@export("__muldi3", @import("compiler_rt/muldi3.zig").__muldi3, linkage); @export(@import("compiler_rt/muldi3.zig").__muldi3, .{ .name = "__muldi3", .linkage = linkage });
@export("__divmoddi4", __divmoddi4, linkage); @export(__divmoddi4, .{ .name = "__divmoddi4", .linkage = linkage });
@export("__divsi3", __divsi3, linkage); @export(__divsi3, .{ .name = "__divsi3", .linkage = linkage });
@export("__divdi3", __divdi3, linkage); @export(__divdi3, .{ .name = "__divdi3", .linkage = linkage });
@export("__udivsi3", __udivsi3, linkage); @export(__udivsi3, .{ .name = "__udivsi3", .linkage = linkage });
@export("__udivdi3", __udivdi3, linkage); @export(__udivdi3, .{ .name = "__udivdi3", .linkage = linkage });
@export("__modsi3", __modsi3, linkage); @export(__modsi3, .{ .name = "__modsi3", .linkage = linkage });
@export("__moddi3", __moddi3, linkage); @export(__moddi3, .{ .name = "__moddi3", .linkage = linkage });
@export("__umodsi3", __umodsi3, linkage); @export(__umodsi3, .{ .name = "__umodsi3", .linkage = linkage });
@export("__umoddi3", __umoddi3, linkage); @export(__umoddi3, .{ .name = "__umoddi3", .linkage = linkage });
@export("__divmodsi4", __divmodsi4, linkage); @export(__divmodsi4, .{ .name = "__divmodsi4", .linkage = linkage });
@export("__udivmodsi4", __udivmodsi4, linkage); @export(__udivmodsi4, .{ .name = "__udivmodsi4", .linkage = linkage });
@export("__negsf2", @import("compiler_rt/negXf2.zig").__negsf2, linkage); @export(@import("compiler_rt/negXf2.zig").__negsf2, .{ .name = "__negsf2", .linkage = linkage });
@export("__negdf2", @import("compiler_rt/negXf2.zig").__negdf2, linkage); @export(@import("compiler_rt/negXf2.zig").__negdf2, .{ .name = "__negdf2", .linkage = linkage });
if (is_arm_arch and !is_arm_64 and !is_test) { if (is_arm_arch and !is_arm_64 and !is_test) {
@export("__aeabi_unwind_cpp_pr0", __aeabi_unwind_cpp_pr0, strong_linkage); @export(__aeabi_unwind_cpp_pr0, .{ .name = "__aeabi_unwind_cpp_pr0", .linkage = strong_linkage });
@export("__aeabi_unwind_cpp_pr1", __aeabi_unwind_cpp_pr1, linkage); @export(__aeabi_unwind_cpp_pr1, .{ .name = "__aeabi_unwind_cpp_pr1", .linkage = linkage });
@export("__aeabi_unwind_cpp_pr2", __aeabi_unwind_cpp_pr2, linkage); @export(__aeabi_unwind_cpp_pr2, .{ .name = "__aeabi_unwind_cpp_pr2", .linkage = linkage });
@export("__aeabi_lmul", @import("compiler_rt/muldi3.zig").__muldi3, linkage); @export(@import("compiler_rt/muldi3.zig").__muldi3, .{ .name = "__aeabi_lmul", .linkage = linkage });
@export("__aeabi_ldivmod", __aeabi_ldivmod, linkage); @export(__aeabi_ldivmod, .{ .name = "__aeabi_ldivmod", .linkage = linkage });
@export("__aeabi_uldivmod", __aeabi_uldivmod, linkage); @export(__aeabi_uldivmod, .{ .name = "__aeabi_uldivmod", .linkage = linkage });
@export("__aeabi_idiv", __divsi3, linkage); @export(__divsi3, .{ .name = "__aeabi_idiv", .linkage = linkage });
@export("__aeabi_idivmod", __aeabi_idivmod, linkage); @export(__aeabi_idivmod, .{ .name = "__aeabi_idivmod", .linkage = linkage });
@export("__aeabi_uidiv", __udivsi3, linkage); @export(__udivsi3, .{ .name = "__aeabi_uidiv", .linkage = linkage });
@export("__aeabi_uidivmod", __aeabi_uidivmod, linkage); @export(__aeabi_uidivmod, .{ .name = "__aeabi_uidivmod", .linkage = linkage });
@export("__aeabi_memcpy", __aeabi_memcpy, linkage); @export(__aeabi_memcpy, .{ .name = "__aeabi_memcpy", .linkage = linkage });
@export("__aeabi_memcpy4", __aeabi_memcpy, linkage); @export(__aeabi_memcpy, .{ .name = "__aeabi_memcpy4", .linkage = linkage });
@export("__aeabi_memcpy8", __aeabi_memcpy, linkage); @export(__aeabi_memcpy, .{ .name = "__aeabi_memcpy8", .linkage = linkage });
@export("__aeabi_memmove", __aeabi_memmove, linkage); @export(__aeabi_memmove, .{ .name = "__aeabi_memmove", .linkage = linkage });
@export("__aeabi_memmove4", __aeabi_memmove, linkage); @export(__aeabi_memmove, .{ .name = "__aeabi_memmove4", .linkage = linkage });
@export("__aeabi_memmove8", __aeabi_memmove, linkage); @export(__aeabi_memmove, .{ .name = "__aeabi_memmove8", .linkage = linkage });
@export("__aeabi_memset", __aeabi_memset, linkage); @export(__aeabi_memset, .{ .name = "__aeabi_memset", .linkage = linkage });
@export("__aeabi_memset4", __aeabi_memset, linkage); @export(__aeabi_memset, .{ .name = "__aeabi_memset4", .linkage = linkage });
@export("__aeabi_memset8", __aeabi_memset, linkage); @export(__aeabi_memset, .{ .name = "__aeabi_memset8", .linkage = linkage });
@export("__aeabi_memclr", __aeabi_memclr, linkage); @export(__aeabi_memclr, .{ .name = "__aeabi_memclr", .linkage = linkage });
@export("__aeabi_memclr4", __aeabi_memclr, linkage); @export(__aeabi_memclr, .{ .name = "__aeabi_memclr4", .linkage = linkage });
@export("__aeabi_memclr8", __aeabi_memclr, linkage); @export(__aeabi_memclr, .{ .name = "__aeabi_memclr8", .linkage = linkage });
@export("__aeabi_memcmp", __aeabi_memcmp, linkage); @export(__aeabi_memcmp, .{ .name = "__aeabi_memcmp", .linkage = linkage });
@export("__aeabi_memcmp4", __aeabi_memcmp, linkage); @export(__aeabi_memcmp, .{ .name = "__aeabi_memcmp4", .linkage = linkage });
@export("__aeabi_memcmp8", __aeabi_memcmp, linkage); @export(__aeabi_memcmp, .{ .name = "__aeabi_memcmp8", .linkage = linkage });
@export("__aeabi_f2d", @import("compiler_rt/extendXfYf2.zig").__aeabi_f2d, linkage); @export(@import("compiler_rt/extendXfYf2.zig").__aeabi_f2d, .{ .name = "__aeabi_f2d", .linkage = linkage });
@export("__aeabi_i2d", @import("compiler_rt/floatsiXf.zig").__aeabi_i2d, linkage); @export(@import("compiler_rt/floatsiXf.zig").__aeabi_i2d, .{ .name = "__aeabi_i2d", .linkage = linkage });
@export("__aeabi_l2d", @import("compiler_rt/floatdidf.zig").__aeabi_l2d, linkage); @export(@import("compiler_rt/floatdidf.zig").__aeabi_l2d, .{ .name = "__aeabi_l2d", .linkage = linkage });
@export("__aeabi_ui2d", @import("compiler_rt/floatunsidf.zig").__aeabi_ui2d, linkage); @export(@import("compiler_rt/floatunsidf.zig").__aeabi_ui2d, .{ .name = "__aeabi_ui2d", .linkage = linkage });
@export("__aeabi_ul2d", @import("compiler_rt/floatundidf.zig").__aeabi_ul2d, linkage); @export(@import("compiler_rt/floatundidf.zig").__aeabi_ul2d, .{ .name = "__aeabi_ul2d", .linkage = linkage });
@export("__aeabi_ui2f", @import("compiler_rt/floatunsisf.zig").__aeabi_ui2f, linkage); @export(@import("compiler_rt/floatunsisf.zig").__aeabi_ui2f, .{ .name = "__aeabi_ui2f", .linkage = linkage });
@export("__aeabi_ul2f", @import("compiler_rt/floatundisf.zig").__aeabi_ul2f, linkage); @export(@import("compiler_rt/floatundisf.zig").__aeabi_ul2f, .{ .name = "__aeabi_ul2f", .linkage = linkage });
@export("__aeabi_fneg", @import("compiler_rt/negXf2.zig").__aeabi_fneg, linkage); @export(@import("compiler_rt/negXf2.zig").__aeabi_fneg, .{ .name = "__aeabi_fneg", .linkage = linkage });
@export("__aeabi_dneg", @import("compiler_rt/negXf2.zig").__aeabi_dneg, linkage); @export(@import("compiler_rt/negXf2.zig").__aeabi_dneg, .{ .name = "__aeabi_dneg", .linkage = linkage });
@export("__aeabi_fmul", @import("compiler_rt/mulXf3.zig").__aeabi_fmul, linkage); @export(@import("compiler_rt/mulXf3.zig").__aeabi_fmul, .{ .name = "__aeabi_fmul", .linkage = linkage });
@export("__aeabi_dmul", @import("compiler_rt/mulXf3.zig").__aeabi_dmul, linkage); @export(@import("compiler_rt/mulXf3.zig").__aeabi_dmul, .{ .name = "__aeabi_dmul", .linkage = linkage });
@export("__aeabi_d2h", @import("compiler_rt/truncXfYf2.zig").__aeabi_d2h, linkage); @export(@import("compiler_rt/truncXfYf2.zig").__aeabi_d2h, .{ .name = "__aeabi_d2h", .linkage = linkage });
@export("__aeabi_f2ulz", @import("compiler_rt/fixunssfdi.zig").__aeabi_f2ulz, linkage); @export(@import("compiler_rt/fixunssfdi.zig").__aeabi_f2ulz, .{ .name = "__aeabi_f2ulz", .linkage = linkage });
@export("__aeabi_d2ulz", @import("compiler_rt/fixunsdfdi.zig").__aeabi_d2ulz, linkage); @export(@import("compiler_rt/fixunsdfdi.zig").__aeabi_d2ulz, .{ .name = "__aeabi_d2ulz", .linkage = linkage });
@export("__aeabi_f2lz", @import("compiler_rt/fixsfdi.zig").__aeabi_f2lz, linkage); @export(@import("compiler_rt/fixsfdi.zig").__aeabi_f2lz, .{ .name = "__aeabi_f2lz", .linkage = linkage });
@export("__aeabi_d2lz", @import("compiler_rt/fixdfdi.zig").__aeabi_d2lz, linkage); @export(@import("compiler_rt/fixdfdi.zig").__aeabi_d2lz, .{ .name = "__aeabi_d2lz", .linkage = linkage });
@export("__aeabi_d2uiz", @import("compiler_rt/fixunsdfsi.zig").__aeabi_d2uiz, linkage); @export(@import("compiler_rt/fixunsdfsi.zig").__aeabi_d2uiz, .{ .name = "__aeabi_d2uiz", .linkage = linkage });
@export("__aeabi_h2f", @import("compiler_rt/extendXfYf2.zig").__aeabi_h2f, linkage); @export(@import("compiler_rt/extendXfYf2.zig").__aeabi_h2f, .{ .name = "__aeabi_h2f", .linkage = linkage });
@export("__aeabi_f2h", @import("compiler_rt/truncXfYf2.zig").__aeabi_f2h, linkage); @export(@import("compiler_rt/truncXfYf2.zig").__aeabi_f2h, .{ .name = "__aeabi_f2h", .linkage = linkage });
@export("__aeabi_i2f", @import("compiler_rt/floatsiXf.zig").__aeabi_i2f, linkage); @export(@import("compiler_rt/floatsiXf.zig").__aeabi_i2f, .{ .name = "__aeabi_i2f", .linkage = linkage });
@export("__aeabi_d2f", @import("compiler_rt/truncXfYf2.zig").__aeabi_d2f, linkage); @export(@import("compiler_rt/truncXfYf2.zig").__aeabi_d2f, .{ .name = "__aeabi_d2f", .linkage = linkage });
@export("__aeabi_fadd", @import("compiler_rt/addXf3.zig").__aeabi_fadd, linkage); @export(@import("compiler_rt/addXf3.zig").__aeabi_fadd, .{ .name = "__aeabi_fadd", .linkage = linkage });
@export("__aeabi_dadd", @import("compiler_rt/addXf3.zig").__aeabi_dadd, linkage); @export(@import("compiler_rt/addXf3.zig").__aeabi_dadd, .{ .name = "__aeabi_dadd", .linkage = linkage });
@export("__aeabi_fsub", @import("compiler_rt/addXf3.zig").__aeabi_fsub, linkage); @export(@import("compiler_rt/addXf3.zig").__aeabi_fsub, .{ .name = "__aeabi_fsub", .linkage = linkage });
@export("__aeabi_dsub", @import("compiler_rt/addXf3.zig").__aeabi_dsub, linkage); @export(@import("compiler_rt/addXf3.zig").__aeabi_dsub, .{ .name = "__aeabi_dsub", .linkage = linkage });
@export("__aeabi_f2uiz", @import("compiler_rt/fixunssfsi.zig").__aeabi_f2uiz, linkage); @export(@import("compiler_rt/fixunssfsi.zig").__aeabi_f2uiz, .{ .name = "__aeabi_f2uiz", .linkage = linkage });
@export("__aeabi_f2iz", @import("compiler_rt/fixsfsi.zig").__aeabi_f2iz, linkage); @export(@import("compiler_rt/fixsfsi.zig").__aeabi_f2iz, .{ .name = "__aeabi_f2iz", .linkage = linkage });
@export("__aeabi_d2iz", @import("compiler_rt/fixdfsi.zig").__aeabi_d2iz, linkage); @export(@import("compiler_rt/fixdfsi.zig").__aeabi_d2iz, .{ .name = "__aeabi_d2iz", .linkage = linkage });
@export("__aeabi_fdiv", @import("compiler_rt/divsf3.zig").__aeabi_fdiv, linkage); @export(@import("compiler_rt/divsf3.zig").__aeabi_fdiv, .{ .name = "__aeabi_fdiv", .linkage = linkage });
@export("__aeabi_ddiv", @import("compiler_rt/divdf3.zig").__aeabi_ddiv, linkage); @export(@import("compiler_rt/divdf3.zig").__aeabi_ddiv, .{ .name = "__aeabi_ddiv", .linkage = linkage });
@export("__aeabi_fcmpeq", @import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmpeq, linkage); @export(@import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmpeq, .{ .name = "__aeabi_fcmpeq", .linkage = linkage });
@export("__aeabi_fcmplt", @import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmplt, linkage); @export(@import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmplt, .{ .name = "__aeabi_fcmplt", .linkage = linkage });
@export("__aeabi_fcmple", @import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmple, linkage); @export(@import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmple, .{ .name = "__aeabi_fcmple", .linkage = linkage });
@export("__aeabi_fcmpge", @import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmpge, linkage); @export(@import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmpge, .{ .name = "__aeabi_fcmpge", .linkage = linkage });
@export("__aeabi_fcmpgt", @import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmpgt, linkage); @export(@import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmpgt, .{ .name = "__aeabi_fcmpgt", .linkage = linkage });
@export("__aeabi_fcmpun", @import("compiler_rt/comparesf2.zig").__aeabi_fcmpun, linkage); @export(@import("compiler_rt/comparesf2.zig").__aeabi_fcmpun, .{ .name = "__aeabi_fcmpun", .linkage = linkage });
@export("__aeabi_dcmpeq", @import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmpeq, linkage); @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmpeq, .{ .name = "__aeabi_dcmpeq", .linkage = linkage });
@export("__aeabi_dcmplt", @import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmplt, linkage); @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmplt, .{ .name = "__aeabi_dcmplt", .linkage = linkage });
@export("__aeabi_dcmple", @import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmple, linkage); @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmple, .{ .name = "__aeabi_dcmple", .linkage = linkage });
@export("__aeabi_dcmpge", @import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmpge, linkage); @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmpge, .{ .name = "__aeabi_dcmpge", .linkage = linkage });
@export("__aeabi_dcmpgt", @import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmpgt, linkage); @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmpgt, .{ .name = "__aeabi_dcmpgt", .linkage = linkage });
@export("__aeabi_dcmpun", @import("compiler_rt/comparedf2.zig").__aeabi_dcmpun, linkage); @export(@import("compiler_rt/comparedf2.zig").__aeabi_dcmpun, .{ .name = "__aeabi_dcmpun", .linkage = linkage });
} }
if (builtin.os == .windows) { if (builtin.os == .windows) {
// Default stack-probe functions emitted by LLVM // Default stack-probe functions emitted by LLVM
if (is_mingw) { if (is_mingw) {
@export("_alloca", @import("compiler_rt/stack_probe.zig")._chkstk, strong_linkage); @export(@import("compiler_rt/stack_probe.zig")._chkstk, .{ .name = "_alloca", .linkage = strong_linkage });
@export("___chkstk_ms", @import("compiler_rt/stack_probe.zig").___chkstk_ms, strong_linkage); @export(@import("compiler_rt/stack_probe.zig").___chkstk_ms, .{ .name = "___chkstk_ms", .linkage = strong_linkage });
} else if (!builtin.link_libc) { } else if (!builtin.link_libc) {
// This symbols are otherwise exported by MSVCRT.lib // This symbols are otherwise exported by MSVCRT.lib
@export("_chkstk", @import("compiler_rt/stack_probe.zig")._chkstk, strong_linkage); @export(@import("compiler_rt/stack_probe.zig")._chkstk, .{ .name = "_chkstk", .linkage = strong_linkage });
@export("__chkstk", @import("compiler_rt/stack_probe.zig").__chkstk, strong_linkage); @export(@import("compiler_rt/stack_probe.zig").__chkstk, .{ .name = "__chkstk", .linkage = strong_linkage });
} }
if (is_mingw) { if (is_mingw) {
@export("__stack_chk_fail", __stack_chk_fail, strong_linkage); @export(__stack_chk_fail, .{ .name = "__stack_chk_fail", .linkage = strong_linkage });
@export("__stack_chk_guard", __stack_chk_guard, strong_linkage); @export(__stack_chk_guard, .{ .name = "__stack_chk_guard", .linkage = strong_linkage });
} }
switch (builtin.arch) { switch (builtin.arch) {
.i386 => { .i386 => {
// Don't let LLVM apply the stdcall name mangling on those MSVC // Don't let LLVM apply the stdcall name mangling on those MSVC
// builtin functions // builtin functions
@export("\x01__alldiv", @import("compiler_rt/aulldiv.zig")._alldiv, strong_linkage); @export(@import("compiler_rt/aulldiv.zig")._alldiv, .{ .name = "\x01__alldiv", .linkage = strong_linkage });
@export("\x01__aulldiv", @import("compiler_rt/aulldiv.zig")._aulldiv, strong_linkage); @export(@import("compiler_rt/aulldiv.zig")._aulldiv, .{ .name = "\x01__aulldiv", .linkage = strong_linkage });
@export("\x01__allrem", @import("compiler_rt/aullrem.zig")._allrem, strong_linkage); @export(@import("compiler_rt/aullrem.zig")._allrem, .{ .name = "\x01__allrem", .linkage = strong_linkage });
@export("\x01__aullrem", @import("compiler_rt/aullrem.zig")._aullrem, strong_linkage); @export(@import("compiler_rt/aullrem.zig")._aullrem, .{ .name = "\x01__aullrem", .linkage = strong_linkage });
@export("__divti3", @import("compiler_rt/divti3.zig").__divti3, linkage); @export(@import("compiler_rt/divti3.zig").__divti3, .{ .name = "__divti3", .linkage = linkage });
@export("__modti3", @import("compiler_rt/modti3.zig").__modti3, linkage); @export(@import("compiler_rt/modti3.zig").__modti3, .{ .name = "__modti3", .linkage = linkage });
@export("__multi3", @import("compiler_rt/multi3.zig").__multi3, linkage); @export(@import("compiler_rt/multi3.zig").__multi3, .{ .name = "__multi3", .linkage = linkage });
@export("__udivti3", @import("compiler_rt/udivti3.zig").__udivti3, linkage); @export(@import("compiler_rt/udivti3.zig").__udivti3, .{ .name = "__udivti3", .linkage = linkage });
@export("__udivmodti4", @import("compiler_rt/udivmodti4.zig").__udivmodti4, linkage); @export(@import("compiler_rt/udivmodti4.zig").__udivmodti4, .{ .name = "__udivmodti4", .linkage = linkage });
@export("__umodti3", @import("compiler_rt/umodti3.zig").__umodti3, linkage); @export(@import("compiler_rt/umodti3.zig").__umodti3, .{ .name = "__umodti3", .linkage = linkage });
}, },
.x86_64 => { .x86_64 => {
// The "ti" functions must use @Vector(2, u64) parameter types to adhere to the ABI // The "ti" functions must use @Vector(2, u64) parameter types to adhere to the ABI
// that LLVM expects compiler-rt to have. // that LLVM expects compiler-rt to have.
@export("__divti3", @import("compiler_rt/divti3.zig").__divti3_windows_x86_64, linkage); @export(@import("compiler_rt/divti3.zig").__divti3_windows_x86_64, .{ .name = "__divti3", .linkage = linkage });
@export("__modti3", @import("compiler_rt/modti3.zig").__modti3_windows_x86_64, linkage); @export(@import("compiler_rt/modti3.zig").__modti3_windows_x86_64, .{ .name = "__modti3", .linkage = linkage });
@export("__multi3", @import("compiler_rt/multi3.zig").__multi3_windows_x86_64, linkage); @export(@import("compiler_rt/multi3.zig").__multi3_windows_x86_64, .{ .name = "__multi3", .linkage = linkage });
@export("__udivti3", @import("compiler_rt/udivti3.zig").__udivti3_windows_x86_64, linkage); @export(@import("compiler_rt/udivti3.zig").__udivti3_windows_x86_64, .{ .name = "__udivti3", .linkage = linkage });
@export("__udivmodti4", @import("compiler_rt/udivmodti4.zig").__udivmodti4_windows_x86_64, linkage); @export(@import("compiler_rt/udivmodti4.zig").__udivmodti4_windows_x86_64, .{ .name = "__udivmodti4", .linkage = linkage });
@export("__umodti3", @import("compiler_rt/umodti3.zig").__umodti3_windows_x86_64, linkage); @export(@import("compiler_rt/umodti3.zig").__umodti3_windows_x86_64, .{ .name = "__umodti3", .linkage = linkage });
}, },
else => {}, else => {},
} }
} else { } else {
if (builtin.glibc_version != null) { if (builtin.glibc_version != null) {
@export("__stack_chk_guard", __stack_chk_guard, linkage); @export(__stack_chk_guard, .{ .name = "__stack_chk_guard", .linkage = linkage });
} }
@export("__divti3", @import("compiler_rt/divti3.zig").__divti3, linkage); @export(@import("compiler_rt/divti3.zig").__divti3, .{ .name = "__divti3", .linkage = linkage });
@export("__modti3", @import("compiler_rt/modti3.zig").__modti3, linkage); @export(@import("compiler_rt/modti3.zig").__modti3, .{ .name = "__modti3", .linkage = linkage });
@export("__multi3", @import("compiler_rt/multi3.zig").__multi3, linkage); @export(@import("compiler_rt/multi3.zig").__multi3, .{ .name = "__multi3", .linkage = linkage });
@export("__udivti3", @import("compiler_rt/udivti3.zig").__udivti3, linkage); @export(@import("compiler_rt/udivti3.zig").__udivti3, .{ .name = "__udivti3", .linkage = linkage });
@export("__udivmodti4", @import("compiler_rt/udivmodti4.zig").__udivmodti4, linkage); @export(@import("compiler_rt/udivmodti4.zig").__udivmodti4, .{ .name = "__udivmodti4", .linkage = linkage });
@export("__umodti3", @import("compiler_rt/umodti3.zig").__umodti3, linkage); @export(@import("compiler_rt/umodti3.zig").__umodti3, .{ .name = "__umodti3", .linkage = linkage });
} }
@export("__muloti4", @import("compiler_rt/muloti4.zig").__muloti4, linkage); @export(@import("compiler_rt/muloti4.zig").__muloti4, .{ .name = "__muloti4", .linkage = linkage });
@export("__mulodi4", @import("compiler_rt/mulodi4.zig").__mulodi4, linkage); @export(@import("compiler_rt/mulodi4.zig").__mulodi4, .{ .name = "__mulodi4", .linkage = linkage });
} }
const std = @import("std"); const std = @import("std");

View File

@ -22,23 +22,23 @@ const start_sym_name = if (is_mips) "__start" else "_start";
comptime { comptime {
if (builtin.output_mode == .Lib and builtin.link_mode == .Dynamic) { if (builtin.output_mode == .Lib and builtin.link_mode == .Dynamic) {
if (builtin.os == .windows and !@hasDecl(root, "_DllMainCRTStartup")) { if (builtin.os == .windows and !@hasDecl(root, "_DllMainCRTStartup")) {
@export("_DllMainCRTStartup", _DllMainCRTStartup, .Strong); @export(_DllMainCRTStartup, .{ .name = "_DllMainCRTStartup" });
} }
} else if (builtin.output_mode == .Exe or @hasDecl(root, "main")) { } else if (builtin.output_mode == .Exe or @hasDecl(root, "main")) {
if (builtin.link_libc and @hasDecl(root, "main")) { if (builtin.link_libc and @hasDecl(root, "main")) {
if (@typeInfo(@TypeOf(root.main)).Fn.calling_convention != .C) { if (@typeInfo(@TypeOf(root.main)).Fn.calling_convention != .C) {
@export("main", main, .Weak); @export(main, .{ .name = "main", .linkage = .Weak });
} }
} else if (builtin.os == .windows) { } else if (builtin.os == .windows) {
if (!@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup")) { if (!@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup")) {
@export("WinMainCRTStartup", WinMainCRTStartup, .Strong); @export(WinMainCRTStartup, .{ .name = "WinMainCRTStartup" });
} }
} else if (builtin.os == .uefi) { } else if (builtin.os == .uefi) {
if (!@hasDecl(root, "EfiMain")) @export("EfiMain", EfiMain, .Strong); if (!@hasDecl(root, "EfiMain")) @export(EfiMain, .{ .name = "EfiMain" });
} else if (is_wasm and builtin.os == .freestanding) { } else if (is_wasm and builtin.os == .freestanding) {
if (!@hasDecl(root, start_sym_name)) @export(start_sym_name, wasm_freestanding_start, .Strong); if (!@hasDecl(root, start_sym_name)) @export(wasm_freestanding_start, .{ .name = start_sym_name });
} else if (builtin.os != .other and builtin.os != .freestanding) { } else if (builtin.os != .other and builtin.os != .freestanding) {
if (!@hasDecl(root, start_sym_name)) @export(start_sym_name, _start, .Strong); if (!@hasDecl(root, start_sym_name)) @export(_start, .{ .name = start_sym_name });
} }
} }
} }

View File

@ -526,7 +526,6 @@ struct TldVar {
ZigVar *var; ZigVar *var;
Buf *extern_lib_name; Buf *extern_lib_name;
Buf *section_name;
bool analyzing_type; // flag to detect dependency loops bool analyzing_type; // flag to detect dependency loops
}; };
@ -2231,6 +2230,8 @@ struct ZigVar {
size_t mem_slot_index; size_t mem_slot_index;
IrExecutable *owner_exec; IrExecutable *owner_exec;
Buf *section_name;
// In an inline loop, multiple variables may be created, // In an inline loop, multiple variables may be created,
// In this case, a reference to a variable should follow // In this case, a reference to a variable should follow
// this pointer to the redefined variable. // this pointer to the redefined variable.
@ -3785,9 +3786,8 @@ struct IrInstructionArgType {
struct IrInstructionExport { struct IrInstructionExport {
IrInstruction base; IrInstruction base;
IrInstruction *name;
IrInstruction *linkage;
IrInstruction *target; IrInstruction *target;
IrInstruction *options;
}; };
struct IrInstructionErrorReturnTrace { struct IrInstructionErrorReturnTrace {

View File

@ -3955,8 +3955,8 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) {
} }
if (var_decl->section_expr != nullptr) { if (var_decl->section_expr != nullptr) {
if (!analyze_const_string(g, tld_var->base.parent_scope, var_decl->section_expr, &tld_var->section_name)) { if (!analyze_const_string(g, tld_var->base.parent_scope, var_decl->section_expr, &tld_var->var->section_name)) {
tld_var->section_name = nullptr; tld_var->var->section_name = nullptr;
} }
} }

View File

@ -7538,8 +7538,8 @@ static void do_code_gen(CodeGen *g) {
LLVMSetLinkage(global_value, to_llvm_linkage(linkage)); LLVMSetLinkage(global_value, to_llvm_linkage(linkage));
maybe_export_dll(g, global_value, GlobalLinkageIdStrong); maybe_export_dll(g, global_value, GlobalLinkageIdStrong);
} }
if (tld_var->section_name) { if (var->section_name) {
LLVMSetSection(global_value, buf_ptr(tld_var->section_name)); LLVMSetSection(global_value, buf_ptr(var->section_name));
} }
LLVMSetAlignment(global_value, var->align_bytes); LLVMSetAlignment(global_value, var->align_bytes);
@ -8264,7 +8264,7 @@ static void define_builtin_fns(CodeGen *g) {
create_builtin_fn(g, BuiltinFnIdOpaqueType, "OpaqueType", 0); create_builtin_fn(g, BuiltinFnIdOpaqueType, "OpaqueType", 0);
create_builtin_fn(g, BuiltinFnIdSetAlignStack, "setAlignStack", 1); create_builtin_fn(g, BuiltinFnIdSetAlignStack, "setAlignStack", 1);
create_builtin_fn(g, BuiltinFnIdArgType, "ArgType", 2); create_builtin_fn(g, BuiltinFnIdArgType, "ArgType", 2);
create_builtin_fn(g, BuiltinFnIdExport, "export", 3); create_builtin_fn(g, BuiltinFnIdExport, "export", 2);
create_builtin_fn(g, BuiltinFnIdErrorReturnTrace, "errorReturnTrace", 0); create_builtin_fn(g, BuiltinFnIdErrorReturnTrace, "errorReturnTrace", 0);
create_builtin_fn(g, BuiltinFnIdAtomicRmw, "atomicRmw", 5); create_builtin_fn(g, BuiltinFnIdAtomicRmw, "atomicRmw", 5);
create_builtin_fn(g, BuiltinFnIdAtomicLoad, "atomicLoad", 3); create_builtin_fn(g, BuiltinFnIdAtomicLoad, "atomicLoad", 3);

View File

@ -2227,19 +2227,17 @@ static IrInstruction *ir_build_resize_slice(IrAnalyze *ira, IrInstruction *sourc
} }
static IrInstruction *ir_build_export(IrBuilder *irb, Scope *scope, AstNode *source_node, static IrInstruction *ir_build_export(IrBuilder *irb, Scope *scope, AstNode *source_node,
IrInstruction *name, IrInstruction *target, IrInstruction *linkage) IrInstruction *target, IrInstruction *options)
{ {
IrInstructionExport *export_instruction = ir_build_instruction<IrInstructionExport>( IrInstructionExport *export_instruction = ir_build_instruction<IrInstructionExport>(
irb, scope, source_node); irb, scope, source_node);
export_instruction->base.value->special = ConstValSpecialStatic; export_instruction->base.value->special = ConstValSpecialStatic;
export_instruction->base.value->type = irb->codegen->builtin_types.entry_void; export_instruction->base.value->type = irb->codegen->builtin_types.entry_void;
export_instruction->name = name;
export_instruction->target = target; export_instruction->target = target;
export_instruction->linkage = linkage; export_instruction->options = options;
ir_ref_instruction(name, irb->current_basic_block);
ir_ref_instruction(target, irb->current_basic_block); ir_ref_instruction(target, irb->current_basic_block);
if (linkage) ir_ref_instruction(linkage, irb->current_basic_block); ir_ref_instruction(options, irb->current_basic_block);
return &export_instruction->base; return &export_instruction->base;
} }
@ -6272,22 +6270,26 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
} }
case BuiltinFnIdExport: case BuiltinFnIdExport:
{ {
AstNode *arg0_node = node->data.fn_call_expr.params.at(0); // Cast the options parameter to the options type
IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); ZigType *options_type = get_builtin_type(irb->codegen, "ExportOptions");
if (arg0_value == irb->codegen->invalid_instruction) IrInstruction *options_type_inst = ir_build_const_type(irb, scope, node, options_type);
return arg0_value; ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, options_type_inst, no_result_loc());
AstNode *arg1_node = node->data.fn_call_expr.params.at(1); AstNode *target_node = node->data.fn_call_expr.params.at(0);
IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); IrInstruction *target_value = ir_gen_node(irb, target_node, scope);
if (arg1_value == irb->codegen->invalid_instruction) if (target_value == irb->codegen->invalid_instruction)
return arg1_value; return target_value;
AstNode *arg2_node = node->data.fn_call_expr.params.at(2); AstNode *options_node = node->data.fn_call_expr.params.at(1);
IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope); IrInstruction *options_value = ir_gen_node_extra(irb, options_node,
if (arg2_value == irb->codegen->invalid_instruction) scope, LValNone, &result_loc_cast->base);
return arg2_value; if (options_value == irb->codegen->invalid_instruction)
return options_value;
IrInstruction *ir_export = ir_build_export(irb, scope, node, arg0_value, arg1_value, arg2_value); IrInstruction *casted_options_value = ir_build_implicit_cast(
irb, scope, options_node, options_value, result_loc_cast);
IrInstruction *ir_export = ir_build_export(irb, scope, node, target_value, casted_options_value);
return ir_lval_wrap(irb, scope, ir_export, lval, result_loc); return ir_lval_wrap(irb, scope, ir_export, lval, result_loc);
} }
case BuiltinFnIdErrorReturnTrace: case BuiltinFnIdErrorReturnTrace:
@ -16683,26 +16685,60 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
} }
static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExport *instruction) { static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExport *instruction) {
Error err;
IrInstruction *name = instruction->name->child;
Buf *symbol_name = ir_resolve_str(ira, name);
if (symbol_name == nullptr) {
return ira->codegen->invalid_instruction;
}
IrInstruction *target = instruction->target->child; IrInstruction *target = instruction->target->child;
if (type_is_invalid(target->value->type)) { if (type_is_invalid(target->value->type))
return ira->codegen->invalid_instruction;
IrInstruction *options = instruction->options->child;
if (type_is_invalid(options->value->type))
return ira->codegen->invalid_instruction;
ZigType *options_type = options->value->type;
assert(options_type->id == ZigTypeIdStruct);
TypeStructField *name_field = find_struct_type_field(options_type, buf_create_from_str("name"));
ir_assert(name_field != nullptr, &instruction->base);
IrInstruction *name_inst = ir_analyze_struct_value_field_value(ira, &instruction->base, options, name_field);
if (type_is_invalid(name_inst->value->type))
return ira->codegen->invalid_instruction;
TypeStructField *linkage_field = find_struct_type_field(options_type, buf_create_from_str("linkage"));
ir_assert(linkage_field != nullptr, &instruction->base);
IrInstruction *linkage_inst = ir_analyze_struct_value_field_value(ira, &instruction->base, options, linkage_field);
if (type_is_invalid(linkage_inst->value->type))
return ira->codegen->invalid_instruction;
TypeStructField *section_field = find_struct_type_field(options_type, buf_create_from_str("section"));
ir_assert(section_field != nullptr, &instruction->base);
IrInstruction *section_inst = ir_analyze_struct_value_field_value(ira, &instruction->base, options, section_field);
if (type_is_invalid(section_inst->value->type))
return ira->codegen->invalid_instruction;
// The `section` field is optional, we have to unwrap it first
IrInstruction *non_null_check = ir_analyze_test_non_null(ira, &instruction->base, section_inst);
bool is_non_null;
if (!ir_resolve_bool(ira, non_null_check, &is_non_null))
return ira->codegen->invalid_instruction;
IrInstruction *section_str_inst = nullptr;
if (is_non_null) {
section_str_inst = ir_analyze_optional_value_payload_value(ira, &instruction->base, section_inst, false);
if (type_is_invalid(section_str_inst->value->type))
return ira->codegen->invalid_instruction; return ira->codegen->invalid_instruction;
} }
GlobalLinkageId global_linkage_id = GlobalLinkageIdStrong; // Resolve all the comptime values
if (instruction->linkage != nullptr) { Buf *symbol_name = ir_resolve_str(ira, name_inst);
IrInstruction *linkage_value = instruction->linkage->child; if (!symbol_name)
if (!ir_resolve_global_linkage(ira, linkage_value, &global_linkage_id)) { return ira->codegen->invalid_instruction;
GlobalLinkageId global_linkage_id;
if (!ir_resolve_global_linkage(ira, linkage_inst, &global_linkage_id))
return ira->codegen->invalid_instruction;
Buf *section_name = nullptr;
if (section_str_inst != nullptr && !(section_name = ir_resolve_str(ira, section_str_inst)))
return ira->codegen->invalid_instruction; return ira->codegen->invalid_instruction;
}
}
// TODO: This function needs to be audited. // TODO: This function needs to be audited.
// It's not clear how all the different types are supposed to be handled. // It's not clear how all the different types are supposed to be handled.
@ -16721,6 +16757,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
return ira->codegen->invalid_instruction; return ira->codegen->invalid_instruction;
} }
Error err;
bool want_var_export = false; bool want_var_export = false;
switch (target->value->type->id) { switch (target->value->type->id) {
case ZigTypeIdInvalid: case ZigTypeIdInvalid:
@ -16755,6 +16792,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
case CallingConventionAAPCS: case CallingConventionAAPCS:
case CallingConventionAAPCSVFP: case CallingConventionAAPCSVFP:
add_fn_export(ira->codegen, fn_entry, buf_ptr(symbol_name), global_linkage_id, cc); add_fn_export(ira->codegen, fn_entry, buf_ptr(symbol_name), global_linkage_id, cc);
fn_entry->section_name = section_name;
break; break;
} }
} break; } break;
@ -16896,6 +16934,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
IrInstructionVarPtr *var_ptr = reinterpret_cast<IrInstructionVarPtr *>(load_ptr->ptr); IrInstructionVarPtr *var_ptr = reinterpret_cast<IrInstructionVarPtr *>(load_ptr->ptr);
ZigVar *var = var_ptr->var; ZigVar *var = var_ptr->var;
add_var_export(ira->codegen, var, buf_ptr(symbol_name), global_linkage_id); add_var_export(ira->codegen, var, buf_ptr(symbol_name), global_linkage_id);
var->section_name = section_name;
} }
} }

View File

@ -1893,21 +1893,11 @@ static void ir_print_enum_tag_type(IrPrint *irp, IrInstructionTagType *instructi
} }
static void ir_print_export(IrPrint *irp, IrInstructionExport *instruction) { static void ir_print_export(IrPrint *irp, IrInstructionExport *instruction) {
if (instruction->linkage == nullptr) {
fprintf(irp->f, "@export("); fprintf(irp->f, "@export(");
ir_print_other_instruction(irp, instruction->name);
fprintf(irp->f, ",");
ir_print_other_instruction(irp, instruction->target);
fprintf(irp->f, ")");
} else {
fprintf(irp->f, "@exportWithLinkage(");
ir_print_other_instruction(irp, instruction->name);
fprintf(irp->f, ",");
ir_print_other_instruction(irp, instruction->target); ir_print_other_instruction(irp, instruction->target);
fprintf(irp->f, ","); fprintf(irp->f, ",");
ir_print_other_instruction(irp, instruction->linkage); ir_print_other_instruction(irp, instruction->options);
fprintf(irp->f, ")"); fprintf(irp->f, ")");
}
} }
static void ir_print_error_return_trace(IrPrint *irp, IrInstructionErrorReturnTrace *instruction) { static void ir_print_error_return_trace(IrPrint *irp, IrInstructionErrorReturnTrace *instruction) {

View File

@ -5650,10 +5650,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add("wrong types given to @export", cases.add("wrong types given to @export",
\\fn entry() callconv(.C) void { } \\fn entry() callconv(.C) void { }
\\comptime { \\comptime {
\\ @export("entry", entry, @as(u32, 1234)); \\ @export(entry, .{.name = "entry", .linkage = @as(u32, 1234) });
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:3:29: error: expected type 'std.builtin.GlobalLinkage', found 'u32'", "tmp.zig:3:50: error: expected type 'std.builtin.GlobalLinkage', found 'u32'",
}); });
cases.add("struct with invalid field", cases.add("struct with invalid field",

View File

@ -16,7 +16,7 @@ test "empty function with comments" {
} }
comptime { comptime {
@export("disabledExternFn", disabledExternFn, builtin.GlobalLinkage.Internal); @export(disabledExternFn, .{ .name = "disabledExternFn", .linkage = .Internal });
} }
fn disabledExternFn() callconv(.C) void {} fn disabledExternFn() callconv(.C) void {}