Commit Graph

42 Commits

Author SHA1 Message Date
Arnold Schwaighofer
92499e1a98 Fix directory test/Serialization 2023-06-20 13:15:20 -07:00
Arnold Schwaighofer
c1a93e0bde Move tests over to use the %use_no_opaque_pointers option 2023-06-14 10:49:48 -07:00
Michael Gottesman
1bc94bfa6a [concurrency] Implement a compatibility .a library for Concurrency.
In a back deployment scenario, this will provide a place where one could provide
function implementations that are not available in the relevant stdlib.

This is just setting up for future work and isn't doing anything interesting
beyond wiring it up/making sure that it is wired up correctly with tests.
2021-08-18 09:35:37 -07:00
Mishal Shah
3722bcb85a Revert "[concurrency] Implement a compatibility .a library for Concurrency." 2021-07-29 11:26:51 -07:00
Michael Gottesman
8441871a04 [concurrency] Implement a compatibility .a library for Concurrency.
In a back deployment scenario, this will provide a place where one could provide
function implementations that are not available in the relevant stdlib.

This is just setting up for future work and isn't doing anything interesting
beyond wiring it up/making sure that it is wired up correctly with tests.
2021-07-23 17:30:18 -07:00
Yuta Saito
6362a98aa0 [Frontend] Add -public-autolink-library option (#35936)
Foundation imports CoreFoundation with `@_implementationOnly`,
so CoreFoundation's modulemap won't be read, and the dependent libraries
of CoreFoundation will not be automatically linked when using static
linking.

For example, CoreFoundation depends on libicui18n and it's modulemap has
`link "icui18n"` statement. If Foundation imports CoreFoundation with
`@_implementationOnly` as a private dependency, the toolchain doesn't have
CoreFoundation's modulemap and Foundation's swiftmodule  doesn't import
CoreFoundation. So the swiftc can't know that libicui18n is required.

This new option will add LINK_LIBRARY entry in swiftmodule to
specify dependent libraries (in the example case, Foundation's
swiftmodule should have LINK_LIBRARY entry of libicui18n)


See also: [Autolinking behavior of @_implementationOnly with static linking](https://forums.swift.org/t/autolinking-behavior-of-implementationonly-with-static-linking/44393)
2021-06-15 12:38:19 +01:00
Robert Widmann
f6b2294d5a Undo Force Load + Incremental Ban on Darwin Platforms
Gather 'round to hear tell of the saga of autolinking in incremental
mode.

In the beginning, there was Swift code, and there was Objective-C code.
To make one import bind two languages, a twinned Swift module named the same as an
Objective-C module could be imported as an overlay. But all was not
well, for an overlay could be created which had no Swift content, yet
required Swift symbols. And there was much wailing and gnashing of teeth
as loaders everywhere disregarded loading these content-less Swift
libraries.

So, a solution was found - a magical symbol _swift_FORCE_LOAD_$_<MODULE>
that forced the loaders to heed the dependency on a Swift library
regardless of its content. It was a constant with common linkage, and it
was good. But, along came COFF which needed to support autolinking but
had no support for such matters. It did, however, have support for
COMDAT sections into which we placed the symbol. Immediately, a darkness
fell across the land as the windows linker loudly proclaimed it had
discovered a contradiction: "_swift_FORCE_LOAD_$_<MODULE> cannot be
a constant!", it said, gratingly, "for this value requires rebasing."
Undeterred, we switched to a function instead, and the windows linker
happily added a level of indirection to its symbol resolution procedure
and all was right with the world.

But this definition was not all right. In order to support multiple
translation units emitting it, and to prevent the linker from dead
stripping it, Weak ODR linkage was used. Weak ODR linkage has the nasty
side effect of pessimizing load times since the dynamic linker must
assume that loading a later library could produce a more definitive
definition for the symbol.

A compromise was drawn up: To keep load times low, external linkage was
used. To keep the linker from complaining about multiple strong
definitions for the same symbol, the first translation unit in the
module was nominated to recieve the magic symbol. But one final problem
remained:

Incremental builds allow for files to be added or removed during the
build procedure. The placement of the symbol was therefore dependent
entirely upon the order of files passed at the command line. This was no
good, so a decree was set forth that using -autolink-force-load and
-incremental together was a criminal offense.

So we must compromise once more: Return to a symbol with common linkage,
but only on Mach-O targets. Preserve the existing COMDAT-friendly
approach everywhere else.

This concludes our tale.

rdar://77803299
2021-05-24 15:53:13 -07:00
Erik Eckstein
78ec15cf38 tests: remove some unused FileCheck prefix options
Such tests would fail with the -allow-unused-prefixes FileCheck option.

diff --git a/test/lit.cfg b/test/lit.cfg
-run_filecheck = '%s %s --sanitize BUILD_DIR=%s --sanitize SOURCE_DIR=%s --use-filecheck %s %s' % (
+run_filecheck = '%s %s --sanitize BUILD_DIR=%s --sanitize SOURCE_DIR=%s --use-filecheck %s %s -allow-unused-prefixes=false' % (

It helps avoiding some wrong CHECK patterns.
I just looked briefly at some of the fails. TODO: fix remaining tests, too.

rdar://74189761
2021-03-25 15:19:30 +01:00
Saleem Abdulrasool
72e6bbca9a test: repair Serialization.autolinking after #33379
The order of attribution was swapped which failed on platforms which use
`comdat` (i.e. Windows).
2020-08-09 11:14:27 -07:00
John McCall
03d94b44a6 Add default IR attributes to helper functions and convert
several more places to use getOrCreateHelperFunction.

This means that several of these places are now emitting
shared functions rather than private ones, which I've
verified is okay.  There are some other places where
privacy is still unfortunately necessary.

I've also fixed the name of the store-extra-inhabitants
helper function to say "store" instead of "get", which
is longstanding (but harmless because it's private).

Fixes rdar://66707994.
2020-08-08 16:57:02 -04:00
Saleem Abdulrasool
0f694819f7 test: address Windows test regression
The change to relax forced autolinking symbol emission restrictions
caused a regression due to over-fitting of the output where the
symbol's comdat annotation was not accounted for.  Adjust the test
accordingly.
2019-08-13 08:05:08 -07:00
Jim Ingham
be4da4680d We don't need the metadata for the auto linking when debugging either.
So it is simpler to just early return when we are running on the
debugger's behalf.
2019-07-03 19:02:39 -07:00
Jim Ingham
abc35e5366 Don't emit the FORCE_LOAD symbols when the compiler is running
on behalf of the debugger.  The debugger will read the LinkLibrary's
from all the modules it sees, and hand load all the required dependencies,
and since the symbol is weak it doesn't even tell us whether a
required dependency is missing. So it serves no purpose in this case.

<rdar://problem/51463642>
2019-07-03 15:27:21 -07:00
Arnold Schwaighofer
5d329464d6 Use thread private key to avoid weak linkage
We use one bit of the third reserved swift private tls key.

Also move the functionality into a separate static archive that is
always linked dependent on deployment target.
2019-06-17 15:03:45 -07:00
Joe Groff
4ed8de10f9 Revert "Revert "Use autolinking to pull in compatibility libraries."" 2019-06-03 20:10:51 -07:00
Joe Groff
a7cc3a38cc Revert "Use autolinking to pull in compatibility libraries." 2019-06-03 14:18:39 -07:00
Joe Groff
dffd1b27a1 Use autolinking to pull in compatibility libraries.
Many build systems that support Swift don't use swiftc to drive the linker. To make things
easier for these build systems, also use autolinking to pull in the needed compatibility
libraries. This is less ideal than letting the driver add it at link time, since individual
compile jobs don't know whether they're building an executable or not. Introduce a
`-disable-autolink-runtime-compatibility` flag, which build systems that do drive the linker
with swiftc can pass to avoid autolinking.

rdar://problem/50057445
2019-05-31 13:11:14 -07:00
Saleem Abdulrasool
68ca11bb2a IRGen: do not use WeakImport on PE/COFF
PE/COFF does not provide weak import semantics.  Fallback to strong
import semantics on PE/COFF.
2019-04-24 20:55:42 -07:00
Bob Wilson
dd94a9f90f References to _swift_FORCE_LOAD* symbols should be weak
When Swift always copied the overlay dylibs into app bundles, it was OK
for these symbol references to be non-weak, but with the overlays now
part of the OS on Apple platforms, we need to handle backward deployment
scenarios where a new overlay does not exist on an old OS version.
A weak reference will serve to pull in the overlay dylib if it exists,
without causing a fatal error if it does not. rdar://problem/50110036
2019-04-24 09:45:07 -07:00
Daniel Rodríguez Troitiño
e649bebcdf [android][test] Disabling autolinking tests for Android AArch64 (#23551)
The OS sadly changes between Android ARMv7 and Android AArch64, to
avoid this and any future problems, mark the autolinking tests that
I can find with `UNSUPPORTED: autolink-extract`, which should apply
to all platforms that need autolink-extract.

This should remove these tests from failing in Android 64.
2019-03-26 08:37:05 -07:00
Saleem Abdulrasool
c932f60403 Merge pull request #21533 from compnerd/excessive-force
IRGen: COMDAT the force load thunks
2019-01-02 21:37:38 -08:00
Saleem Abdulrasool
d4ea98436b test: port Serialization tests to Windows
These changes enable the serialization test suite to pass on Windows.
2018-12-30 15:19:03 -08:00
Saleem Abdulrasool
e6354fe206 IRGen: COMDAT the force load thunks
Use `ApplyIRLinkage` to the force load thunks to permit multiple
emissions to be COMDATed on Windows.  The multi-module tests would emit
the symbols multiply and would fail to link.
2018-12-27 18:43:28 -08:00
Jordan Rose
6af333f307 [IRGen] Be smarter about adding the FORCE_LINK symbols for overlays (#15647)
We use dummy symbols to force overlays not to get dropped when
autolinking, even if the user doesn't use anything from them
explicitly. This behavior is triggered by the semi-hidden flag
-autolink-force-load.

(It's semi-hidden because it has few legitimate uses in real life. If
you searched for "how to force autolinking to pick up a library" and
found this commit, don't just do this and move on. Come talk to me on
forums.swift.org.)

Previously we added these dummy symbols to every object file using
"common" linkage, a little-known feature added for C that ensures that
only one definition will actually get used in the final object file.
However, the way we were doing that wouldn't work so well for COFF,
and so in 1025eed64 Saleem changed this to use "weak ODR" linkage.
This has *nearly* the same effect, and avoids some other weirdness,
but has the downside of making the symbol in the final dylib "weak"
itself, meaning that some /other/ library could come along and
override it. That impacts loading time, and an Apple-internal tool
caught that as rdar://39019606.

To avoid this whole mess, "just" emit the symbol into the object file
that corresponds to the first file in the module, which allows us to
mark it as a normal public symbol.

P.S. None of this is actually important at the moment because all of
the overlays are built with single-threaded WMO, which always produces
one object file anyway. But I wanted to get it right once and for all.
2018-03-31 15:20:13 -07:00
Saleem Abdulrasool
1025eed645 IRGen: make the autolink work better in COFF environments
This was obscured due to local workarounds.  Because the reference is
cross-module, and the symbol itself will be rebased, it cannot serve as
a constant initializer (the value is not known until runtime).  However,
using a function pointer is permissible.  The linker will materialize a
thunk for the function itself and cause the module to be force linked.
This also works on ELF and MachO as well.  The overhead associated with
this is pretty minimal as the function itself has an empty body, and
flags will differentiate between a function and data symbol.  The slight
penalty in size (on the order of 2-4 bytes) allows for the same pattern
to be used across all the targets.
2018-02-10 18:02:50 -08:00
Jordan Rose
2b7ab7d8d1 [test] Update autolinking tests to match LLVM.
The test part of 90ca8f119a, which went in early to unblock the build.
2017-07-25 14:57:27 -07:00
Robert Widmann
6509f78f13 tests: replace remaining 'mkdir -p' calls with %empty-directory(...)'
These changes were made manually.
2017-06-04 11:08:39 -07:00
Dmitri Gribenko
984210aa53 tests: replace '// RUN: rm -rf' '// RUN: mkdir' pairs with '%empty-directory(...)'
These changes were made using a script.
2017-06-04 11:08:39 -07:00
Dmitri Gribenko
55864d10cb Tests: use 'mkdir -p' 2016-09-02 21:36:45 -07:00
Dmitri Gribenko
d175b3b66d Migrate FileCheck to %FileCheck in tests 2016-08-10 23:52:02 -07:00
Brian Gesiak
fd3ecb1d94 [test] Prepare tests to run on Android
- Expand operating system checks such that Glibc is properly
  imported on Android.
- For tests that are unsupported on platforms that normally
  do not support an Objective-C runtime, expand the unsupported
  checks to include Android.
- Pass the `-sdk` parameter when invoking `%target-sil-opt`.
- Expect failures when testing semaphores, which are not included
  in Android Bionic.
2016-06-07 15:59:51 -04:00
Brian Gesiak
2eb028b5ce [test] Mark tests unsupported on all Linux flavors
Autolinking was added to the frontend in 22912bc3b. It was disabled on
Linux in 198402dcf, and further constrained to be disabled on "linux-gnu"
in 83b4384fa. Since then, more flavors of Linux have become supported
by Swift: "linux-gnueabihf" in 4bf81e09d, and "freebsd" in f41b791d4.

Autolinking most likely does not work on any of these platforms, so
mark it as unsupported for now.

Other tests that only mark "linux-gnu" as unsupported do so for similar
reasons. Ensure unsupported tests for "linux-gnu" are also unsupported
on similar platforms.
2016-01-25 11:57:14 -05:00
Jordan Rose
bbb41c1b66 Use 'common' linkage for force-load symbols rather than 'weak_odr'.
As suggested by John. This results in the symbols being coalesced at static
link time into a single strong symbol in a built dylib. Fortunately we don't
care about the contents of these global symbols, so common linkage's
forced zero-initialization is fine. (Hey, C's tentative definitions are
useful for something after all.)

rdar://problem/20072051

Swift SVN r25804
2015-03-06 19:42:15 +00:00
Graham Batty
83b4384fac Update test flags for linux failures and support.
Also removed the sdk 'feature' in favour of the more specific
objc_interop.

Swift SVN r24856
2015-01-30 21:31:48 +00:00
Dmitri Hrybenko
3b04d1b013 tests: reorganize tests so that they actually use the target platform
Most tests were using %swift or similar substitutions, which did not
include the target triple and SDK.  The driver was defaulting to the
host OS.  Thus, we could not run the tests when the standard library was
not built for OS X.

Swift SVN r24504
2015-01-19 06:52:49 +00:00
Jordan Rose
6b4dc17038 [Serialization] Serialize and check the target a module was compiled with.
Refuse to load a module if it was compiled for a different architecture or
OS, or if its minimum deployment target is newer than the current target.
Additionally, provide the target triple as part of pre-loading validation
for clients who care (like LLDB).

Part of rdar://problem/17670778

Swift SVN r24469
2015-01-16 02:48:59 +00:00
Adrian Prantl
162bc8d24c Updated testcases for upstream assembler changes.
Swift SVN r23942
2014-12-15 19:39:21 +00:00
Graham Batty
83f27a8af7 Revert "Mark tests that don't pass on linux as XFAIL."
This reverts commit 2711ca86de7bf6a7885ccea24219a48a590b1e95.

Swift SVN r23577
2014-11-24 17:42:13 +00:00
Graham Batty
198402dcfe Mark tests that don't pass on linux as XFAIL.
Swift SVN r23573
2014-11-24 17:40:37 +00:00
Jordan Rose
9c3b9c0a55 [IRGen] Hide the symbols used to force-load other frameworks.
Exposing these symbols was unnecessary and triggered internal build
verifiers.

<rdar://problem/16901604>

Swift SVN r18526
2014-05-21 22:21:54 +00:00
Ted Kremenek
fad874708e Adjust test cases.
Swift SVN r17964
2014-05-12 22:01:52 +00:00
Jordan Rose
22912bc3b3 Add a -l flag to Swift and use it to provide autolinking information.
The spelling of the flag can certainly be changed; I just wanted to get
something up and running.

Swift SVN r7582
2013-08-26 18:57:48 +00:00