Commit Graph

77 Commits

Author SHA1 Message Date
Doug Gregor
82ceb29576 [Driver] Fix platform name to match what the linker does, not what it says 2020-04-03 13:51:29 -07:00
Doug Gregor
970ff6b818 [Driver] Read SDK version information to pass to the Darwin linker.
Recent-ish SDKs for Darwin platforms include an SDKSettings.json
file with version information and Catalyst SDK version mappings. Read
these (when available) and use them to pass the appropriate SDK
version down to the Darwin linker via `-platform_version`.

Finishes rdar://problem/55972144.
2020-04-02 21:07:26 -07:00
Doug Gregor
336c0c2d54 [Driver] Use -platform_version to specify platform versions for the Darwin linker
Standardize the way in which we pass platform version information to
the Darwin linker, using the `-platform_version` option. In the case
of Mac Catalyst, there may be two such platform arguments.

The eventual point of this refactoring is to also pass information
about the SDK version, which `-platform_version` supports but the
mix of `-*_version_min` parameters do not. For now, the SDK
version is stubbed out to 0.0.0, which is this option's "unknown"
value.

Part of rdar://problem/55972144.
2020-04-02 21:07:26 -07:00
Saleem Abdulrasool
c7a198bc03 Driver: honour -no-toolchain-stdlib-rpath on Unices
Handle `-no-toolchain-stdlib-rpath` on Linux/android as well as Darwin.  This
enables the flags on other Unix platforms as it can be useful to control the
embedded rpath for the library.
2020-03-17 17:38:24 +00:00
3405691582
0d3b92dfb1 Swift Basic/Driver recognizes OpenBSD.
Add the platform conditional and set up other basics for the toolchain.

The ConditionalCompilation tests are updated to match, since otherwise
they seem to trip when building on non-OpenBSD platforms. The
Driver/linker test is updated to ensure lld is passed on this platform.
Note that OpenBSD calls "x86_64" as "amd64", so we use that name for the
architecture instead of trying to alias one to the other, as this makes
things simpler.
2020-02-27 17:14:22 -05:00
Saleem Abdulrasool
23b1a6b87a Driver: add support for WASI/WASM toolchain
Treat WASM/WASI as a generic Unix toolchain.  This adds the necessary
support to build a toolchain for WASM/WASI.
2019-12-04 20:14:08 -08:00
David Ungar
cca40fc2df Fix test to account for driver fix that now puts a.o into the linker filelist. 2019-11-19 19:54:16 -08:00
Saleem Abdulrasool
551a2a58a5 Driver: normalise linker triple on all android targets
Currently we only support building for android armv7, arm64, x86,
x86_64.  In the future, if support for MIPS and MIPS64 is added, we
should normalise those as well.  This is needed to support compilation
against modern NDKs.
2019-08-04 19:48:57 -07:00
Saleem Abdulrasool
67475dced4 Driver: avoid linking against the C++ runtime
Use `clang` rather than `clang++` as the linker driver.  This ensures
that we do not force a C++ runtime on the general code.  This is fine
for now as C++ interop is not yet available for Swift.  This prevents
the accidental mix-and-match of various C++ runtimes.  This can cause
problems on platforms like android where `libstdc++` is an unsupported
runtime but is generally the default for Linux platforms.
2019-07-24 19:48:02 -07:00
Luciano Almeida
ed432ac302 Missing forward 2019-07-15 22:56:56 -03:00
Luciano Almeida
83ede1f3cc Forward declaring and improvement on warning. 2019-07-15 22:20:00 -03:00
Luciano Almeida
fe49bb2537 Updating test/Driver tests. 2019-07-15 22:06:31 -03:00
Gwen Mittertreiner
8a6d28c7d0 Fix the Rest of the Windows Driver Tests 2019-03-06 14:23:49 -08:00
Jason Mittertreiner
4e0b092fbe Fixing Driver tests on Windows (#20209) 2018-12-10 18:27:37 -08:00
Daniel Rodríguez Troitiño
8dd8fc0cfa Add -Xclang-linker option to the compiler. (#20441)
In the Darwin toolchain the linker is invoked directly, and compiler_rt
is used if it is found, but in Unix platforms, clang++ is invoked
instead, and the clang driver will invoke the linker. Howerver there was
no way of modifying this clang++ invocation, so there's no way of
providing `--rtlib=` and change the platform default (which is normally
libgcc). The only workaround is doing the work that the Swift driver is
doing "manually".

The change adds a new option (with help hidden, but we can change that)
to allow providing extra arguments to the clang++ invocation. The change
is done in the two places in the Unix and Windows toolchains that I
found the clang driver was being used.

Includes some simple tests.
2018-11-28 10:48:20 -08:00
Keith Smiley
14f0241662 Add tests for -L vs -Xlinker order 2018-07-30 10:05:52 -07:00
Keith Smiley
1f4e643d42 Move linker arguments to the end 2018-07-27 14:34:00 -07:00
Keith Smiley
577b18f86d Unify linker argument order across platforms
Previously extra linker arguments had different behavior on darwin vs
other unix platforms. On darwin the arguments passed with -Xlinker would
be passed to the linker before the default arguments, where as with the
default unix toolchain they would be passed afterwards.

There isn't really a great option for which order these should be in.
If you want to have a custom rpath that takes precedence over the
default rpaths, you want them to be passed before, but if you want to
negate a default argument you want them to come after.

This change unifies the behavior so at least you always get the same
behavior across platforms.
2018-07-26 13:37:09 -07:00
Jordan Rose
d4668833e0 [Driver] Only link to compiler_rt if present for the target platform
Tweak the tests to check this correctly.
2018-07-10 12:45:59 -07:00
Jordan Rose
64b3d88d93 [Driver] Always link compiler_rt on Darwin
Turns out it's needed for normal builtins that can appear in inlinable
functions, including Objective-C's @available. Clang always links it
unconditionally, so so should Swift.

Note that this does mean you have to build compiler_rt to get a
successful test run on Apple platforms. That was always true if you
wanted the sanitizer tests to work, though.

rdar://problem/41911599
2018-07-09 13:42:02 -07:00
Thomas Roughton
5bb6ac2e12 Implement a Windows toolchain. 2018-04-18 15:26:05 +12:00
Nathan Hawes
0a4204e99f [Driver] Add -driver-filelist-threshold to set the number of inputs beyond which filelists are used
When generating a compiler invocation in driver::createCompilerInvocation()
we end up using filelists if the number of inputs is > 128 (to work around
command line arg limits). We never actually write them out though, and so
fail when parsing the frontend arguments that reference them.

As this function is called frequently by SourceKit and command line limits
aren't a concern here, this patch makes the 128 threshold value configurable
via a new -driver-filelist-threshold option. This is set to its maximum value
in driver::createCompilerInvocation() to ensure filelists aren't used. This
new option makes the existing -driver-use-filelists (that forces filelists to
be used) redundant as it's now equivalent to -driver-filelist-threshold=0.

Resolves rdar://problem/38231888
2018-04-12 05:24:03 -07:00
Saleem Abdulrasool
0c42b57962 ELF: restructure image metadata registration
Restructure the ELF handling to be completely agnostic to the OS.
Rather than usng the loader to query the section information, use the
linker to construct linker tables and synthetic markers for the
beginning and of the table.  Save off the values of these pointers and
pass them along through the constructor to the runtime for registration.

This removes the need for the begin/end objects.  Remove the special
construction of the begin/end objects through the special assembly
constructs, preferring to do this in C with a bit of inline assembly to
ensure that the section is always allocated.

Remove the special handling for the various targets, the empty object
file can be linked on all the targets.

The new object file has no requirements on the ordering.  It needs to
simply be injected into the link.

Name the replacement file `swiftrt.o` mirroring `crt.o` from libc.  Merge
the constructor and the definition into a single object file.

This approach is generally more portable, overall simpler to implement,
and more robust.

Thanks to Orlando Bassotto for help analyzing some of the odd behaviours
when switching over.
2017-11-28 10:04:04 -08:00
swift-ci
b382fa1f76 Merge pull request #12443 from modocache/driver-inferred-dylib-name-fixme 2017-11-01 16:10:49 -07:00
Brian Gesiak
162c4c78dd [Driver] Fix linker test by preparing empty dir
This fixes an intermittent failure introduced by
https://github.com/apple/swift/pull/12507.
2017-10-19 17:21:02 -07:00
Brian Gesiak
b81ad22cab [SR-2660][Driver] Handle .swiftmodule inputs
Allow users to pass `.swiftmodule` files into the Swift driver when
compiling without `-g`. The `.swiftmodule` files are then passed to the
linker via `-add_ast_path` so that LLDB can access their AST
information.

This addresses one of two driver changes suggested in the comments of
https://bugs.swift.org/browse/SR-2660.
2017-10-19 15:03:03 -07:00
Brian Gesiak
e2aa7a619c [Driver] Infer target-specific dylib names
When the Swift driver is invoked with the `-emit-library` option, but
without an `-o` option that specifies the emitted library's filename,
logic in the `getOutputFilename()` function derives a filename:
`"lib" + <a plasible base name>"`, and then the value of the
`LTDL_SHLIB_EXT` macro.

There are two problems here:

1. Windows shared library file names, by convention, do not begin with "lib".
2. The `LTDL_SHLIB_EXT` macro is set by
   `llvm/cmake/modules/HandleLLVMOptions.cmake`, based on
   `CMAKE_SHARED_LIBRARY_SUFFIX`, a built-in CMake variable that is set
   at the time LLVM is configured to be built. So, if LLVM and Swift
   were built on a Linux machine, but the `swiftc` executable that was
   built was then invoked to produce a shared library for a Darwin target,
   the library would have a ".so" suffix, not ".dylib". (It's for this
   reason that the tests for this name inference, in
   `test/Driver/linker.swift`, must use a regular expression that
   matches both ".dylib" and ".so", despite specifying a Darwin
   `-target`.)

In order to produce conventionally correct prefixes and suffixes based
on the target, modify the `getOutputFilename()` function to take an
`llvm::Triple` argument.
2017-10-15 00:25:14 -04:00
Grzegorz Miłoś
5bb433315f Add driver test for linux dynamic libraries. 2017-08-29 15:34:18 +01:00
Grzegorz Miłoś
b561452be0 Test -pie flag is present when building on Linux. 2017-08-29 13:22:43 +01:00
Keith Smiley
408c38fc16 Add test for static-stdlib
This test validates the arguments passed to the linker when statically
linking the swift standard library. Currently in order to ensure that no
-rpath is passed, we're using FileCheck's -implicit-check-not flag, and
strictly validating the order of the arguments. The order doesn't really
matter here but is required for that flag to validate that no -rpath is
passed.
2017-06-19 21:02:07 -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
486cab447d tests: replace 'rm -rf %t && mkdir -p %t' with '%empty-directory(%t)'
These changes were made using a script.
2017-06-04 11:08:39 -07:00
Jordan Rose
4ad2ea5c0c [Driver] Fix passing -Fsystem to the linker.
-Fsystem is not a linker flag. Pass it as -F to ld on Apple platforms,
and -iframework to Clang on other platforms.
2017-03-29 08:59:57 -07:00
Jordan Rose
d56fd64952 [test] Split out Mac-host-dependent parts of test/Driver/linker.swift.
...and tweak a few remaining things in that file to make it run on
Linux again. It's not great that we were losing this coverage!
2017-03-29 08:59:56 -07:00
Greg Parker
7a40af2967 [test] Re-enable tests that incorrectly use REQUIRES: X86. (#6697)
* [test] Re-enable tests that incorrectly use `REQUIRES: X86`.

* Update generic_metatypes.swift

* Update empty_array.sil

* Update function_types.sil
2017-01-11 11:39:26 -08:00
Dave Abrahams
a073d4a3f2 [testing] Support separate Output/ device
Hardlinking across distinct disks doesn't work, so copy as a fallback.
2016-09-12 19:42:56 -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
Jordan Rose
b9e622bdf1 [Driver] Link arclite on iOS 8 and OS X 10.10. (#3123)
(macOS? OS X? How does this work for past OSs?)

Noticed by inspection. Xcode doesn't use swiftc to link, and the few
things that went into arclite between iOS 7 and iOS 8 weren't critical,
but we should still get this right.
2016-06-22 08:55:28 -07:00
Zhuowei Zhang
7c502b6344 Port to Android
This adds an Android target for the stdlib. It is also the first
example of cross-compiling outside of Darwin.

Mailing list discussions:

1. https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151207/000171.html
2. https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151214/000492.html

The Android variant of Swift may be built using the following `build-script`
invocation:

```
$ utils/build-script \
  -R \                                           # Build in ReleaseAssert mode.
  --android \                                    # Build for Android.
  --android-ndk ~/android-ndk-r10e \             # Path to an Android NDK.
  --android-ndk-version 21 \
  --android-icu-uc ~/libicu-android/armeabi-v7a/libicuuc.so \
  --android-icu-uc-include ~/libicu-android/armeabi-v7a/icu/source/common \
  --android-icu-i18n ~/libicu-android/armeabi-v7a/libicui18n.so \
  --android-icu-i18n-include ~/libicu-android/armeabi-v7a/icu/source/i18n/
```

Android builds have the following dependencies, as can be seen in
the build script invocation:

1. An Android NDK of version 21 or greater, available to download
   here: http://developer.android.com/ndk/downloads/index.html.
2. A libicu compatible with android-armv7.
2016-04-12 19:26:21 -04:00
Ted Kremenek
b796305846 Merge pull request #1371 from hpux735/thumb
Added thumb to supported platforms conditions
2016-03-08 22:10:13 -08:00
Davide Italiano
edfa8fe428 [FreeBSD] XFAIL some Driver tests as we do on Linux. 2016-03-01 19:37:59 +00:00
William Dillon
390e50c999 Added thumb to supported platforms conditions 2016-02-21 16:56:02 +00:00
William Dillon
d0d9b1de5a Discard swift.ld and support gold linker 2016-02-17 17:47:35 -08:00
William Dillon
ab7c87e7e8 Implemented ARMv6 and fixed up ARMv7 2016-01-29 21:41:22 +00:00
Jordan Rose
f557563068 [Driver] Pass -filelist to Darwin 'ld' too.
Start sketching out a way for individual jobs to request filelists for
their inputs or their outputs. This should cover all the cases mentioned
in ad945426.

More https://bugs.swift.org/browse/SR-280.
2016-01-13 18:39:24 -08:00
Jordan Rose
d1b72c7b0c [test] Fix test case to account for temporary file names. 2016-01-12 16:17:27 -08:00
Jordan Rose
5f78d24e85 [Driver] Make the list of input files available when creating Jobs.
Previously jobs had to grovel this information out of the raw argument
list, which dropped the types we had inferred on input files. This
makes things more consistent across the compiler, though arguably we
should be able to designate "primary" and "non-primary" inputs on a
per-action basis rather than resorting to "global" state.

Use this new information to stop passing object file inputs to the
Swift frontend, fixing rdar://problem/23213785.

The list wouldn't have to live on the Compilation, but I'm going to use
it to fix SR-280 / rdar://problem/23878192 as well.
2016-01-12 11:52:31 -08:00
William Dillon
4bf81e09da Build working on ARMv7l 2015-12-12 22:06:13 -08:00
Dmitri Gribenko
4324e7c903 Remove conditional compilation of tvOS 2015-12-01 14:43:45 -07:00