Skip to content

Conversation

@compnerd
Copy link
Member

On targets which support COMDAT (PE/COFF, ELF), use that to relax the
constraints on the emission of -force-autolink-symbol so that it is
possible to use that with -incremental.

Replace this paragraph with a description of your changes and rationale. Provide links to external references/discussions if appropriate.

Resolves SR-NNNN.

On targets which support COMDAT (PE/COFF, ELF), use that to relax the
constraints on the emission of `-force-autolink-symbol` so that it is
possible to use that with `-incremental`.
@compnerd
Copy link
Member Author

CC: @jckarter @rjmccall @jrose-apple

MachO does not support COMDAT, which means that we cannot have the linker coalesce and preserve a single definition - if there is a way to emulate that, it would be useful.

@compnerd
Copy link
Member Author

@swift-ci please test

@compnerd compnerd merged commit db4ce1f into swiftlang:master Aug 13, 2019
@compnerd compnerd deleted the incremental-force-autolink-symbol branch August 13, 2019 02:08
@rjmccall
Copy link
Contributor

MachO does not support COMDAT, which means that we cannot have the linker coalesce and preserve a single definition - if there is a way to emulate that, it would be useful.

Er. I don't know how you think MachO supports C++ without a basic ability to coalesce definitions. Weak linkage is a totally adequate facility for 99% of what languages need from symbol coalescing; all of COMDAT's complexity goes into supporting the relatively marginal use case of needing coordinated coalescing across multiple symbols.

Does this require coordination across symbols?

@compnerd
Copy link
Member Author

compnerd commented Aug 13, 2019

@rjmccall - hmm, the only coordination that is required is that a definition is preserved, nothing else. If there is a way to ensure that the symbol is preserved, then, I think that this is something that I can generalise to all targets. I'll do a follow up change to enable this for Darwin as well. (A quick glance at LangRef indicates weak_odr is what I had wanted.)

@compnerd
Copy link
Member Author

// UNSUPPORTED: OS=watchos
// UNSUPPORTED: OS=ios

// AUTOLINK_FORCE_LOAD-NOT: error: '-autolink-force-load' is not supported with '-incremental'
Copy link
Contributor

Choose a reason for hiding this comment

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

For negative checks, it's best not to include the exact text of a diagnostic, because we tweak that sometimes.

@@ -0,0 +1,8 @@
// RUN: not %swiftc_driver -incremental -autolink-force-load %s 2>&1 | %FileCheck -check-prefix=AUTOLINK_FORCE_LOAD %s
// RUN: not %swiftc_driver -autolink-force-load -incremental %s 2>&1 | %FileCheck -check-prefix=AUTOLINK_FORCE_LOAD %s
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no real reason to put this in a separate test file; since you're just testing the driver behavior, you can use -### and an explicit triple to check for the error cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, yes, this is driver, not IRGen. My mistake. Either way, #26635 will remove the file.


if (!IRGen.Opts.ForceLoadSymbolName.empty() &&
isFirstObjectFileInModule(*this)) {
(Triple.supportsCOMDAT() || isFirstObjectFileInModule(*this))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't we add this whole thing in the first place because we were using a COMMON global variable on Mach-O and that didn't work on Windows? Can't we go back to that on non-COMDAT platforms? (See #15647.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that is exactly what I did in #26635 (thanks to @rjmccall kicking my memory back into place!)

@jrose-apple
Copy link
Contributor

#15647 also explains why we can't use weak_odr.

@compnerd
Copy link
Member Author

@rjmccall - #26635 should also lift the restriction on MachO targets! Thanks for the reminder :-)

@rjmccall
Copy link
Contributor

rjmccall commented Aug 13, 2019

We could presumably use a used, weak_odr, hidden symbol if common isn't good enough for some reason.

EDIT: oh, no, not if the symbol needs to be visible outside the linkage unit.

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.

3 participants