ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
35.17k stars 2.57k forks source link

confusing error message when older glibc version does not contain needed symbol #6036

Open fengb opened 4 years ago

fengb commented 4 years ago

This only happens when using linux-gnu as the target, linux-musl and native macos seem to work just fine:

// https://godbolt.org/z/eef9ro

const c = @cImport({
    @cInclude("unistd.h");
});

pub fn main() void {
    var buf: [100]u8 = undefined;
    _ = getentropy(&buf, 100);
}

The error message is extra confusing as it seems to ignore the defined symbol?


$ zig build-exe entropy.zig  -target x86_64-linux-gnu -lc
lld: error: undefined symbol: getentropy
>>> referenced by entropy.zig:7 (<source>:7)
>>>               ./output.s.o:(main.0)
>>> did you mean: getentropy
>>> defined in: ~/.cache/zig/stage1/h/3B3uryfs1rNlgbc_ZR0H2oqWZpNC9zRda78zj4AcDQhfg-i4ffjBlY2FFb-5kMPI/libc.so.6.0.0```
daurnimator commented 4 years ago

Someone on discord reported the same issue; I think the fix was using a newer version of glibc as part of the target?

The error message reminds me of https://github.com/ziglang/zig/issues/5882

fengb commented 4 years ago

Aha! -target x86_64-linux-gnu.2.25 works fine. I think the major problem in this case is that while Zig detects the version does not contain the symbol, the generated error message makes no sense. Is this because we have a merged glibc and thus the symbol actually exists?

andrewrk commented 4 years ago

what version is your native system glibc?

fengb commented 4 years ago

I had errors in cross compilation. Native (glibc 2.31) seemed to work fine, although the reported version is a bit confused:

 "native": {
  "triple": "x86_64-linux.5.7.7...5.7.7-gnu.2.17",
andrewrk commented 4 years ago

although the reported version is a bit confused

covered by #6469