Skip to content

Only add '-fobjc-link-runtime' to the linker invocation when the driver is invoked with '-link-objc-runtime' #1224

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

Merged
merged 1 commit into from
Nov 15, 2022

Conversation

artemcm
Copy link
Contributor

@artemcm artemcm commented Nov 15, 2022

Otherwise, every single compiled program will end up linking it, and Foundation on top of it.

@artemcm
Copy link
Contributor Author

artemcm commented Nov 15, 2022

@swift-ci test

@@ -214,8 +214,14 @@ extension DarwinToolchain {
commandLine.appendPath(VirtualPath.lookup(sdkPath))
}

// -link-objc-runtime also implies -fobjc-link-runtime
if parsedOptions.hasFlag(positive: .linkObjcRuntime,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an existing option? Why not gate this on -enable-objc-interop?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is an existing option and seems to very explicitly map to Clang's equivalent.

I am not sure if there are cases where -enable-objc-interop is set where we wouldn't want to do this though, explicit override with -no-link-obcj-runtime aside...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only question then is, is there ever a case where you want to link the ObjC runtime (and Foundation) when ObjC is explicitly disabled? If not, I feel like -enable-objc-interop is nicer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-enable-objc-interop is actually a frontend-only flag (.noDriver) that the driver sets to be on by-default for Darwin platforms, always.

So we cannot use it as an input switch to enable/disable this. And if we did, because it is enabled by the driver by-default, it would essentially be equivalent to what things were like before this change. I may lack some historical context here, but the existence of -link-objc-runtime really indicates that it ought to be used to control this behavior.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, as a short term thing, I don't think that it is terrible. But it seems like having an extra flag that is unnecessary and we should figure out how to deprecate that IMO. Having the language runtime be linked in properly based on the build type seems like the right approach.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not that there are cases where you want this without ObjC, but there are cases where you want ObjC without this. For example, if you're in a binary which Foundation itself links.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(and then you manually link the runtime of course. I'm not aware of a situation where you want ObjC support but not the ObjC runtime, it's just Foundation that makes things tricky)

@artemcm artemcm force-pushed the INeverAskedForThisFoundation branch from d52a7f7 to 10a1437 Compare November 15, 2022 17:29
@artemcm
Copy link
Contributor Author

artemcm commented Nov 15, 2022

@swift-ci test

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be nice to add the negative test case for -lobjc and you have a typo in the commit message ("drivr").

@artemcm artemcm force-pushed the INeverAskedForThisFoundation branch from 10a1437 to 573c4f7 Compare November 15, 2022 17:36
@artemcm artemcm changed the title Only add '-fobjc-link-runtime' to the linker invocation when the drivr is invoked with '-link-objc-runtime' Only add '-fobjc-link-runtime' to the linker invocation when the driver is invoked with '-link-objc-runtime' Nov 15, 2022
@artemcm
Copy link
Contributor Author

artemcm commented Nov 15, 2022

@swift-ci test

…er is invoked with '-link-objc-runtime'

Resolves rdar://100994806
@artemcm artemcm force-pushed the INeverAskedForThisFoundation branch from 573c4f7 to cc83760 Compare November 15, 2022 17:37
@artemcm
Copy link
Contributor Author

artemcm commented Nov 15, 2022

@swift-ci test

@artemcm artemcm merged commit 8dc9215 into swiftlang:main Nov 15, 2022
@artemcm artemcm deleted the INeverAskedForThisFoundation branch November 15, 2022 17:43
@DougGregor
Copy link
Member

This might be causing CI failures in LLDB. Speculatively reverting to do more testing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants