-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing symbols when using LTO on Windows (LLD): _create_locale, _free_locale and _rand_s #15958
Comments
It seems at the moment the only workaround is to pass -fno-lto >.> |
Is there a known workaround for this, other than no LTO? I feel like I've seen someone before mention in another similar issue that there is a way to force the linker to not remove those functions if they're written down manually? |
You can preface the definition with |
Sorry, I forgot it did that. Here you can see how easy the fix is for a particular case, although I imagine in the general case the problem probably has something to do with lld discarding "unused" aliases to function pointers. Still probably worth poking MinGW guys about. Zig doesn't preprocess MinGW headers as I understand so almost certainly not Zig's bug anyway. |
I was getting the same issues described when building ReleaseFast on windows, unresolved externals for Alternatively, |
Have also hit this issue while building (cross-compiling from Linux to Windows) a program depending on The /weirdest/ thing is that everything worked just fine the entire day while I was experimenting, then once I did:
It worked fine the first time, but later I couldn't build in release modes anymore due to the linking error, even with the above line removed. |
Quick Fix! I'm on zig 0.11. if (optimize == .ReleaseFast and builtin.target.os.tag == .windows) {
// LTO breaks build of libcpp on windows in ReleastFast
exe.want_lto = false;
} |
FWIW, I'm not able to reproduce this on Zig 0.12.0. Can anyone else confirm that it's fixed? |
Enabled LTO for everything in my project, also not getting it anymore on 0.13.0-dev.28+3c5e84073 |
Yep works here too. I updated the exact example in my original post to work with Zig 0.12.0 and ran the same command. It works now. const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.resolveTargetQuery(std.Target.Query.parse(.{
.arch_os_abi = "x86_64-windows-gnu",
}) catch @panic("err"));
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "test",
.target = target,
.optimize = optimize,
});
exe.addCSourceFile(.{ .file = .{ .path = "src/main.c" } });
exe.linkLibC();
b.installArtifact(exe);
exe.want_lto = true; // LTO works!
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
} |
Zig Version
0.11.0-dev.3298+5744ceedb
Steps to Reproduce and Observed Behavior
I have found some more cases of link errors following on from this closed issue #8531. As it looks like there might be some unresolved parts, I thought it warrants this new issue.
Repro based on @ThePotatoChronicler code:
src/main.c:
build.zig:
result:
Expected Behavior
No link errors.
The text was updated successfully, but these errors were encountered: