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

cross compiled macos binaries with LLD which depend on TLS fail at runtime #3295

Closed
andrewrk opened this issue Sep 22, 2019 · 7 comments
Closed
Labels
bug Observed behavior contradicts documented or intended behavior os-macos upstream An issue with a third party project that Zig uses.
Milestone

Comments

@andrewrk
Copy link
Member

threadlocal var x: i32 = 1;
test "tls macos cross compile" {
    x += 1;
}
$ ./zig test test.zig
(ok)
$ ./zig test test.zig -target x86_64-macosx
dyld: Symbol not found: __tlv_bootstrap
@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior os-macos labels Sep 22, 2019
@andrewrk andrewrk added this to the 0.6.0 milestone Sep 22, 2019
@andrewrk
Copy link
Member Author

I think this ultimately comes down to a deficiency in LLD. See #1535

@andrewrk andrewrk added the upstream An issue with a third party project that Zig uses. label Sep 22, 2019
andrewrk added a commit that referenced this issue Sep 22, 2019
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Mar 12, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 30, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@daurnimator
Copy link
Contributor

(continuing from ziglang/zig-bootstrap#38): I think this may be caused by a too low OSX version. I can find similar issues elsewhere where wrong/low OSX version leads to Symbol not found: __tlv_bootstrap, e.g. rust-lang/rust#10842

Can you try passing -macosx_version_min 10.7.0 to lld?

@andrewrk
Copy link
Member Author

Can you try passing -macosx_version_min 10.7.0 to lld?

We do that here:

zig/src/link/MachO.zig

Lines 598 to 614 in 2eee058

switch (target.os.tag) {
.macos => {
try argv.append("-macosx_version_min");
},
.ios, .tvos, .watchos => switch (target.cpu.arch) {
.i386, .x86_64 => {
try argv.append("-ios_simulator_version_min");
},
else => {
try argv.append("-iphoneos_version_min");
},
},
else => unreachable,
}
const ver = target.os.version_range.semver.min;
const version_string = try std.fmt.allocPrint(arena, "{d}.{d}.{d}", .{ ver.major, ver.minor, ver.patch });
try argv.append(version_string);

@kubkon
Copy link
Member

kubkon commented Dec 22, 2020

Just an FYI that this one was fixed for cross-compiling C and Zig sources (C++ is still not in the clear) in #7318; however, ultimately this is a deficiency in LLD so I'm inclined to leave the issue open until LLD acknowledges and fixes it, or our self-hosted linker is up to the job.

@andrewrk
Copy link
Member Author

andrewrk commented May 9, 2021

The plan to address this issue is #8727. Once that is done, this issue can be closed as well.

@kubkon kubkon changed the title cross compiled macos binaries which depend on TLS fail at runtime cross compiled macos binaries with LLD which depend on TLS fail at runtime May 9, 2021
@kubkon
Copy link
Member

kubkon commented May 9, 2021

I will only add that cross-compilation is now exclusively handled by zig ld which handles TLVs properly on both x86_64 and arm64 architectures.

@andrewrk andrewrk modified the milestones: 0.8.0, 0.8.1 Jun 4, 2021
@kubkon
Copy link
Member

kubkon commented Jul 26, 2021

Given that we no longer rely on LLD when targeting macOS, I'm closing this issue regardless of whether it's been fixed in upstream since it's irrelevant for zig.

@kubkon kubkon closed this as completed Jul 26, 2021
@andrewrk andrewrk removed this from the 0.8.1 milestone Dec 1, 2021
@andrewrk andrewrk added this to the 0.9.0 milestone Dec 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior os-macos upstream An issue with a third party project that Zig uses.
Projects
None yet
Development

No branches or pull requests

3 participants