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

[SR-12001] Swift 5.2 toolchain ObjC Availability API crash #54436

Open
Agarunov opened this issue Jan 9, 2020 · 15 comments
Open

[SR-12001] Swift 5.2 toolchain ObjC Availability API crash #54436

Agarunov opened this issue Jan 9, 2020 · 15 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. regression swift 5.2

Comments

@Agarunov
Copy link

Agarunov commented Jan 9, 2020

Previous ID SR-12001
Radar rdar://problem/57837918
Original Reporter @Agarunov
Type Bug
Status Reopened
Resolution

Attachment: Download

Environment

Xcode 11.3

Toolchain: Swift 5.2 Snapshot 2020-01-06 (a)

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug, 5.2Regression
Assignee None
Priority Medium

Watchers: @shahmishal

md5: 8b5bac5d2fb7aa52431d9bb6bd0d5418

Issue Description:

This code produces compiler crash:

#import <Foundation/Foundation.h>

@interface Foo : NSObject

@end
#import "Foo.h"

@implementation Foo

- (instancetype)init {
    self = [super init];
    if (self) {
        if (@available(iOS 9.0, *)) {
            /*
            Undefined symbols for architecture arm64:
              "___isOSVersionAtLeast", referenced from:
                  -[Foo init] in Foo.o
            ld: symbol(s) not found for architecture arm64
            clang-7: error: linker command failed with exit code 1 (use -v to see invocation)
             */
        }
    }
    return self;
}

@end

Project minimum deployment target - iOS 8

@beccadax
Copy link
Contributor

beccadax commented Jan 9, 2020

@swift-ci create

@mikeash
Copy link
Contributor

mikeash commented Jan 28, 2020

This happens because the toolchains don't include compiler-rt libraries for iOS. We're looking into this, but in the meantime you can work around the problem by copying the compiler-rt libraries from Xcode. A command like this will take care of it (adjust the toolchain path as needed):

sudo cp `xcode-select -p`/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang//lib/darwin/libclang_rt..a /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2019-12-03-a.xctoolchain/usr/lib/clang/7.0.0/lib/darwin

@Agarunov
Copy link
Author

Agarunov commented Feb 6, 2020

@mikeash looks like it fixed in Xcode 10.4b1 toolchain ?

@mikeash
Copy link
Contributor

mikeash commented Feb 6, 2020

Xcode toolchains get built a bit differently so I think that's expected. This problem would show up with swift.org toolchains.

@swift-ci
Copy link
Collaborator

Comment by Peter Steinberger (JIRA)

This is still a problem with the June 9 Trunk Toolchain. Fix via:

sudo cp `xcode-select -p`/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/*/lib/darwin/libclang_rt.STAR.a /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-06-09-a.xctoolchain/usr/lib/clang/10.0.0/lib/darwin

Replace STAR with * (comment formatting issue)

@keith
Copy link
Collaborator

keith commented Aug 11, 2020

Hrm even with the cp workaround the original sample project still fails for me in the same way. I wonder if that isn't enough anymore?

Notes: swift-5.3-DEVELOPMENT-SNAPSHOT-2020-08-10-a installed locally in ~/Library/Developer/Toolchains instead of globally.

Passing the library forcibly still works as expected.

@keith
Copy link
Collaborator

keith commented Aug 11, 2020

Ok so the issue is that this call https://github.com/apple/llvm-project/blob/8cbcb6870920db32b52367504902b9bd8456ff91/clang/lib/Driver/ToolChains/Darwin.cpp#L1083 uses the default IgnoreSim = false value. So the derived library name is `libclang_rt.iossim.a` https://github.com/apple/llvm-project/blob/8cbcb6870920db32b52367504902b9bd8456ff91/clang/lib/Driver/ToolChains/Darwin.cpp#L1155-L1156 which doesn't exist in Xcode 11.5, but does exist in 12.x. Copying `libclang_rt.ios.a` to that path fixes the issue.

@edymtt
Copy link
Contributor

edymtt commented Oct 12, 2020

This has now been merged to main as part of

#31247

@edymtt
Copy link
Contributor

edymtt commented Oct 12, 2020

This is also merged as part of release/5.3

#34236

@shahmishal
Copy link
Member

@edymtt
Copy link
Contributor

edymtt commented Oct 13, 2020

Verified that with that toolchain I'm able to compile the sample program – also manually inspected the toolchain to ensure the files are there

> ls /Library/Developer/Toolchains/swift-5.3-DEVELOPMENT-SNAPSHOT-2020-10-12-a.xctoolchain/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.{ios,tvos,watchos}*
-rw-r--r--@ 1 root  wheel  265776 Oct 12 22:52 /Library/Developer/Toolchains/swift-5.3-DEVELOPMENT-SNAPSHOT-2020-10-12-a.xctoolchain/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.ios.a
-rw-r--r--@ 1 root  wheel  265776 Oct 12 22:52 /Library/Developer/Toolchains/swift-5.3-DEVELOPMENT-SNAPSHOT-2020-10-12-a.xctoolchain/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.iossim.a
-rw-r--r--@ 1 root  wheel  225664 Oct 12 22:52 /Library/Developer/Toolchains/swift-5.3-DEVELOPMENT-SNAPSHOT-2020-10-12-a.xctoolchain/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.tvos.a
-rw-r--r--@ 1 root  wheel  225664 Oct 12 22:52 /Library/Developer/Toolchains/swift-5.3-DEVELOPMENT-SNAPSHOT-2020-10-12-a.xctoolchain/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.tvossim.a
-rw-r--r--@ 1 root  wheel  366152 Oct 12 22:52 /Library/Developer/Toolchains/swift-5.3-DEVELOPMENT-SNAPSHOT-2020-10-12-a.xctoolchain/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.watchos.a
-rw-r--r--@ 1 root  wheel  366152 Oct 12 22:52 /Library/Developer/Toolchains/swift-5.3-DEVELOPMENT-SNAPSHOT-2020-10-12-a.xctoolchain/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.watchossim.a

@edymtt
Copy link
Contributor

edymtt commented Oct 16, 2020

Also downloaded https://swift.org/builds/development/xcode/swift-DEVELOPMENT-SNAPSHOT-2020-10-15-a/swift-DEVELOPMENT-SNAPSHOT-2020-10-15-a-osx.pkg

Test application builds and the builtins are in there

> ls /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-10-15-a.xctoolchain/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.{ios,tvos,watchos}*
-rw-r--r--@ 1 root  wheel  265776 Oct 15 17:53 /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-10-15-a.xctoolchain/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.ios.a
-rw-r--r--@ 1 root  wheel  265776 Oct 15 17:53 /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-10-15-a.xctoolchain/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.iossim.a
-rw-r--r--@ 1 root  wheel  225664 Oct 15 17:53 /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-10-15-a.xctoolchain/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.tvos.a
-rw-r--r--@ 1 root  wheel  225664 Oct 15 17:53 /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-10-15-a.xctoolchain/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.tvossim.a
-rw-r--r--@ 1 root  wheel  366152 Oct 15 17:53 /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-10-15-a.xctoolchain/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.watchos.a
-rw-r--r--@ 1 root  wheel  366152 Oct 15 17:53 /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-10-15-a.xctoolchain/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.watchossim.a

@swift-ci
Copy link
Collaborator

Comment by Peter Steinberger (JIRA)

This is not yet resolved. I downloaded the trunk development from November 12, 2020 and got this error:

ld: file not found: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-11-12-a.xctoolchain/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.profile_iossim.a``clang-10: error: linker command failed with exit code 1 (use -v to see invocation)

I had to apply the same workaround:

https://steipete.com/posts/building-with-swift-trunk/#libclang_rtprofile_iossima-not-found

`sudo cp `xcode-select -p`/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang//lib/darwin/libclang_rt..a /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-11-12-a.xctoolchain/usr/lib/clang/10.0.0/lib/darwin`

After copying above, it works.

@nikolaykasyanov
Copy link

I confirm this is not resolved, just tried the snapshot from 12th December with Xcode 12.3 Release Candidate:

ld: file not found: /Users/username/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-12-12-a.xctoolchain/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.profile_iossim.a

@drewcrawford
Copy link
Contributor

This is unresolved in swift-DEVELOPMENT-SNAPSHOT-2021-03-25-a.

After installing the toolchain, ls finds only one (osx) lib matching profile below

ls /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2021-03-25-a.xctoolchain/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.*profile*
/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2021-03-25-a.xctoolchain/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.profile_osx.a 

Compare this output with the xcode toolchain which has profile lib for all OS:

sudo ls /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/lib/darwin/libclang_rt.*profile*
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/lib/darwin/libclang_rt.profile_ios.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/lib/darwin/libclang_rt.profile_iossim.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/lib/darwin/libclang_rt.profile_osx.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/lib/darwin/libclang_rt.profile_tvos.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/lib/darwin/libclang_rt.profile_tvossim.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/lib/darwin/libclang_rt.profile_watchos.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/lib/darwin/libclang_rt.profile_watchossim.a 

The confusion here seems partly because there are a lot of libs in the toolchain but Xcode (ld) is looking specifically for libs with profile. So the presence of other libs in the toolchain is not sufficient to build with xcode.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. regression swift 5.2
Projects
None yet
Development

No branches or pull requests

10 participants