Skip to content

Fix use of extraCPPFlags #5793

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
Oct 4, 2022
Merged

Fix use of extraCPPFlags #5793

merged 1 commit into from
Oct 4, 2022

Conversation

neonichu
Copy link
Contributor

@neonichu neonichu commented Oct 3, 2022

We should not use extraCPPFlags as a vehicle for specifying linker flags, instead just decide on which C++ library to link based on the target triple in BuildPlan.

Separately, it seems worthwhile to look into refactoring `Destination` to actually allow specifying linker flags since that seems to have been an accidental feature of `extraCPPFlags` (as long as one didn't pass compiler flags there as well).

rdar://100575898

@neonichu neonichu self-assigned this Oct 3, 2022
@neonichu
Copy link
Contributor Author

neonichu commented Oct 3, 2022

@swift-ci please smoke test

@neonichu
Copy link
Contributor Author

neonichu commented Oct 3, 2022

Looks like we have some tests asserting the broken behavior since -lc++ happens to also be recognized by swiftc. I don't think we have to special case since -Xcc -lc++ is presumably identical to -lc++?

@neonichu neonichu force-pushed the fix-cxx-linker-flags branch from a47085c to c4eeb98 Compare October 3, 2022 20:25
@abertelrud
Copy link
Contributor

Wouldn't we need -Xlinker instead of -Xcc if we want to pass it to the linker?

@neonichu
Copy link
Contributor Author

neonichu commented Oct 3, 2022

Wouldn't we need -Xlinker instead of -Xcc if we want to pass it to the linker?

Yah, looks like it, the question is why are we even passing extraCPPFlags to the linker at all. Seems like instead Destination should be changed to explicitly declare its linker flags separately or we could filter extraCPPFlags and only pass the linker relevant flags.

@abertelrud
Copy link
Contributor

abertelrud commented Oct 3, 2022

Yes, that seems more correct. Compilation flags and linking flags should generally be separate. There might be some leniency in that compiler drivers might accept and ignore a linker flag if only doing compilation, but it would better to not rely on that (also less confusing for users who are looking at build logs).

@neonichu
Copy link
Contributor Author

neonichu commented Oct 3, 2022

I guess that would mean to also have per-language linker flags in the destination, because otherwise we won't be able to make -lc++ conditional on targets containing C++. I wonder if the right fix for this particular bug is to move this code into the build plan and then a follow up can explore how to restructure the Destination type.

We should not use `extraCPPFlags` as a vehicle for specifying linker flags, instead just decide on which C++ library to link based on the target triple in `BuildPlan`.

Separately, it seems worthwhile to look into refactoring `Destination` to actually allow specifying linker flags since that seems to have been an accidental feature of `extraCPPFlags` (as long as one didn't pass compiler flags there as well).

rdar://100575898
@neonichu neonichu force-pushed the fix-cxx-linker-flags branch from c4eeb98 to 236834a Compare October 3, 2022 23:24
@neonichu
Copy link
Contributor Author

neonichu commented Oct 3, 2022

Updated to move the code for deciding on C++ library linkage, but I think we should be revisiting Destination separately as well.

@neonichu
Copy link
Contributor Author

neonichu commented Oct 3, 2022

@swift-ci please smoke test

@abertelrud
Copy link
Contributor

I guess that would mean to also have per-language linker flags in the destination, because otherwise we won't be able to make -lc++ conditional on targets containing C++. I wonder if the right fix for this particular bug is to move this code into the build plan and then a follow up can explore how to restructure the Destination type.

That seems reasonable. Separately, it seems to me that we should also factor out all of these platform specifics into separate protocol-conforming entities that provide the specifics. Maybe that is what you were saying about the Destination. But that, too, is something that can be done in the future. This change looks good for what it is.

@neonichu neonichu merged commit e78cc4c into main Oct 4, 2022
@neonichu neonichu deleted the fix-cxx-linker-flags branch October 4, 2022 23:20
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.

2 participants