Skip to content
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

Undefined symbols in fmt with i386-uefi-msvc #3530

Closed
JamesLupiani opened this issue Oct 26, 2019 · 5 comments · Fixed by #4231
Closed

Undefined symbols in fmt with i386-uefi-msvc #3530

JamesLupiani opened this issue Oct 26, 2019 · 5 comments · Fixed by #4231
Labels
arch-x86 32-bit x86 contributor friendly This issue is limited in scope and/or knowledge of Zig internals. os-uefi
Milestone

Comments

@JamesLupiani
Copy link

When compiling this program:

const fmt = @import("std").fmt;

pub fn main() void {
    var buf: [100]u8 = undefined;
    var a: u64 = 42;
    _ = fmt.bufPrint(buf[0..], "{}", a) catch unreachable;
}

I get linker errors when building for UEFI 32-bit:

zig build-exe -target i386-uefi-msvc minimal.zig

lld: error: undefined symbol: __aullrem
>>> referenced by /snap/zig/966/lib/zig/std/fmt.zig:950
>>>               ./minimal.obj:(_std.fmt.formatIntUnsigned)

lld: error: undefined symbol: __aulldiv
>>> referenced by /snap/zig/966/lib/zig/std/fmt.zig:953
>>>               ./minimal.obj:(_std.fmt.formatIntUnsigned)

It does work on x86_64-uefi-msvc and i386-windows-msvc, however.

@LemonBoy
Copy link
Contributor

Changing this line to if (builtin.os == .windows or builtin.os == .uefi) { should fix the problem.

@nrdmn
Copy link
Contributor

nrdmn commented Oct 26, 2019

Changing this line to if (builtin.os == .windows or builtin.os == .uefi) { should fix the problem.

But why would we want this code in an EFI application? Shouldn't we get llvm to not require these symbols?

@LemonBoy
Copy link
Contributor

But why would we want this code in an EFI application? Shouldn't we get llvm to not require these symbols?

For the same reason you want those in a standard Win32 non-EFI application, LLVM expects those to be defined by the Microsoft compiler runtime and so makes use of them.

@andrewrk
Copy link
Member

I wrote a tiny bit about the purpose of compiler-rt here: https://ziglang.org/download/0.5.0/release-notes.html#compiler-rt

@andrewrk andrewrk added the contributor friendly This issue is limited in scope and/or knowledge of Zig internals. label Oct 26, 2019
@andrewrk andrewrk added this to the 0.6.0 milestone Oct 26, 2019
@nrdmn
Copy link
Contributor

nrdmn commented Oct 26, 2019

LLVM expects those to be defined by the Microsoft compiler runtime

LLVM expects those because we're currently telling LLVM to compile EFI applications as Windows applications. See here

EDIT: Seems like we don't have much of a choice. As I understand the situation, LLVM can't generate COFF files for non-windows OSes right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-x86 32-bit x86 contributor friendly This issue is limited in scope and/or knowledge of Zig internals. os-uefi
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants