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-7206] ld: symbol(s) not found for classes defined in Swift marked as @objc #49754

Closed
swift-ci opened this issue Mar 15, 2018 · 23 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-7206
Radar rdar://problem/38506059
Original Reporter benasher44 (JIRA User)
Type Bug
Status Closed
Resolution Done

Attachment: Download

Environment

macOS 10.13.3

Xcode 9.3b4 (9Q127n)

Old build system

Toolchain: org.swift.3020180314a

Debug confguration; no WMO nor new batch mode

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 7e969f0d54359216d33b4c3aad721898

blocks:

  • SR-7221 Class lookup at runtime fails in master toolchains

Issue Description:

In the recent master snapshot with toolchain id org.swift.3020180314a, we get symbol not found errors during linking due to Obj-C files not being able to find Objc-class-refs defined in Swift.

The errors all look something like this:

"_OBJC_CLASS_$_SomeObjCClassDefinedInSwift", referenced from:
objc-class-ref in ObjCClass1.o
objc-class-ref in ObjCClass2.o

I ran into this trying to help test the new batch mode that was announced here, however this was not using the new batch mode.

@swift-ci
Copy link
Collaborator Author

Comment by Ben A (JIRA)

The odd thing here is that all of the symbols that can't be found do seem to show up in the appropriate -Swift.h headers.

@belkadan
Copy link
Contributor

Hm. These are classes declared with explicit @objc names?

@swift-ci
Copy link
Collaborator Author

Comment by Ben A (JIRA)

That's correct! Some are @objc and some are @objc(ExplictNameForObjC).

@swift-ci
Copy link
Collaborator Author

Comment by Ben A (JIRA)

Anonymized declarations from all of the Swift classes in question:

// These classes are in the app, which is failing to link
@objc(PGModel1)
public class _ObjCModel1: OtherClassDeclaredInObjC

final class SomeViewController: UIViewController

@objc
final class Info: NSObject


// These classes are in a library module linked by the app
public final class PGModel2: NSObject, PGProtocol1

@objc(PGModel3)
public final class _ObjCModel3: NSObject, PGProtocol2

@objc(PGModel4)
public final class _ObjCModel4: NSObject

@objc
public final class OtherInfo: NSObject

@objc
public final class Helper

After compiling these, I realized I was missing @objc in 2 places. I added it to the 2 decls missing it above, and I still get the same result.

@jckarter
Copy link
Member

@swift-ci create

@belkadan
Copy link
Contributor

FWIW, @objc on a class is inherited when possible, so it's okay to not include it on Info and OtherInfo. (It's also okay to include it just to be explicit.)

@swift-ci
Copy link
Collaborator Author

Comment by Ben A (JIRA)

Thanks for the tip! Some of those may be there from a previous run of some version of the Xcode Swift migrator.

@swift-ci
Copy link
Collaborator Author

Comment by Ben A (JIRA)

I binary searched the last 2 weeks of snapshots, and I found that swift-DEVELOPMENT-SNAPSHOT-2018-03-08-a-osx.pkg is the latest snapshot pkg that builds our project without this error, and swift-DEVELOPMENT-SNAPSHOT-2018-03-11-a-osx.pkg is the first snapshot the builds and emits this ld error. Hope that helps!

@swift-ci
Copy link
Collaborator Author

Comment by Ben A (JIRA)

Using swiftenv to help install the snapshots, doing that isn't so bad 🙂

@jckarter
Copy link
Member

This might be a dup of SR-7221. It should be fixed in later master snapshots since @slavapestov reverted the change that caused it. Do the affected classes have Foundation value types (like URL or Data) in them?

@swift-ci
Copy link
Collaborator Author

Comment by Ben A (JIRA)

They did yes! I'm trying on the 3/26 snapshot now, and I'm hitting a compiler crash. So, not making it all the way to linking. Will try to file this one and update here once I can fully verify.

@swift-ci
Copy link
Collaborator Author

Comment by Ben A (JIRA)

Okay I was able to get passed the crasher. Still working on a small repro there.

Unfortunately as of the 3/26 snapshot (org.swift.3020180326a), I'm still getting the same issue. Going to reopen

@swift-ci
Copy link
Collaborator Author

Comment by Ben A (JIRA)

Happy to try again and close, if you all think that change is coming to a snapshot after the 3/26 one?

@swift-ci
Copy link
Collaborator Author

Comment by Ben A (JIRA)

Figured out a short repro for that crasher and filed it here: SR-7282!

@jckarter
Copy link
Member

Thanks! To be clear, you're saying you're still getting the "symbol not found" errors? Do you have a reproducing project for that problem as well?

@slavapestov would the 3/26 snapshot have picked up the fix for SR-7221?

@swift-ci
Copy link
Collaborator Author

Comment by Ben A (JIRA)

That's correct. It's the original symbol not found errors. I have some time later in the week that I can spend trying to get a small repro for this. If that doesn't work, I'll see if I can source drop the files containing the failing files via a radar.

@swift-ci
Copy link
Collaborator Author

Comment by Ben A (JIRA)

BTW, if local engineers were willing to meet for coffee to show/review these if it came down to it, I'd be willing 🙂

@swift-ci
Copy link
Collaborator Author

swift-ci commented Apr 3, 2018

Comment by Ben A (JIRA)

I'm currently blocked from trying any master snapshots after the March 26 one due to SR-7341. I'm still working on figuring out a more useful repro to add here. Sorry for the delay!

@swift-ci
Copy link
Collaborator Author

swift-ci commented Apr 3, 2018

Comment by Ben A (JIRA)

I've attached this sample project which minimally reproduces at least one of the linker failures SwiftObjCLinkerIssue.zip. I've confirmed that this is still an issue in the April 2nd master snapshot, and it's fixed if I go back to the March 8 master snapshot.

There are other linker failures that all look like this (in terms of their error output), but the situations are all just a little bit different (e.g. this sample project's error involves an Obj-C category but others in the actual project don't). I'm hoping that reproducing one will be enough to point at a root cause/regression.

@slavapestov
Copy link
Member

#15720

@swift-ci
Copy link
Collaborator Author

Comment by Ben A (JIRA)

Thanks! Will give this another go once a snapshot is available with the fix

@AnnaZaks
Copy link
Mannequin

AnnaZaks mannequin commented May 16, 2018

A snapshot with a fix is available. I cannot reproduce with the sample project anymore.

@swift-ci
Copy link
Collaborator Author

Comment by Ben A (JIRA)

Verified that this is fixed. Thanks everyone!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

4 participants