Commit Graph

98 Commits

Author SHA1 Message Date
Evan Wilde
500ddfeba4 [Driver] Don't hardcode default linker on Linux
This is the C++ driver counterpart to a change that landed in the Swift
driver a while ago to use the clang-linker to determine what the default
linker is. This is to avoid hard-coding gold, which is deprecated and
not available on some newer Linux distributions. The challenge is that
these newer Linux distributions don't already have Swift so we have to
use the old C++ driver implementation.
2025-04-02 16:32:44 -07:00
Egor Zhdan
2df1b6fee4 [cxx-interop] Remove -experimental-cxx-stdlib flag
This flag was added back in 2020, but it didn't function properly, since a lot of other code in the compiler assumed the platform-default C++ stdlib until recently (https://github.com/swiftlang/swift/pull/75589).

The recommended way to use a non-default C++ stdlib in Swift now is to pass `-Xcc -stdlib=xyz` argument to the compiler.

This change removes the `-experimental-cxx-stdlib` flag.
2024-09-05 15:19:19 +01:00
zoecarver
839839f924 [cxx-interop] Rename enable-cxx-interop -> enable-experimental-cxx-interop.
Also removes the driver flag, this will now also always be guarded on `-Xfrontend`.
2022-04-07 19:15:25 -07:00
Rajagopalan-Gangadharan
cd7a30b43a Address Test review comments 2021-08-11 10:09:23 +05:30
Rajagopalan-Gangadharan
c2ce6c5533 Add Tests to check if adding space doesn't break invocation 2021-08-04 21:52:26 +05:30
Butta
f5e1429bf8 [Driver] Remove redundant clang '-target' flag that wasn't being used
The target was added for Unix toolchains in #901, but a later pull #1891 added
it again. Since clang only uses the last target flag that's passed in, all
customization done for the first one was unused these last 4+ years, so remove
it and change tests that look for custom strings passed by the first one.
2020-12-09 16:35:21 +05:30
Brent Royal-Gordon
9f25450db5 [NFC] Rid ourselves of a troublesome test
apple/llvm-project#1587 made it so that macOS 10.16 is no longer clamped to macOS 11.0. Remove the Swift test checking for this behavior.
2020-08-04 21:10:59 -07:00
Brent Royal-Gordon
1ac99176d8 Revert "[Apple Silicon] Adjust linking deployment target from 11.0 down to 10.16 on x86."
This reverts the functional portions of commit 5566ace6e0 and adjusts the tests.
2020-08-03 11:37:35 -07:00
Nate Chandler
b9c43b4598 [Test] Disabled Driver/linker.swift.
See rdar://problem/65281056 .
2020-07-10 09:41:44 -07:00
martinboehme
40104ba8b1 Link against the C++ standard library when C++ interop is enabled (#30914)
This doesn't yet allow including C++ headers on platforms where libc++
isn't the default; see comments in UnixToolChains.cpp for details.

However, it does, for example, allow throwing and catching exceptions in C++
code used through interop, unblocking
https://github.com/apple/swift/pull/30674/files.

The flags (-enable-experimental-cxx-interop and -experimental-cxx-stdlib) carry
"experimental" in the name to emphasize that C++ interop is still an
experimental feature.

Co-authored-by: Michael Forster <forster@google.com>
2020-07-09 15:59:26 +02:00
Mishal Shah
899925add3 [Apple Silicon] Remove tvOS/watchOS simulator from Driver/linker test 2020-07-03 01:02:44 -07:00
Mishal Shah
710ba14ddc [Apple Silicon] [Platform] Baseline arm64 simulators at iOS/tvOS 14.0 and watchOS 7.0. 2020-07-02 19:18:52 -07:00
Mishal Shah
76fe814f9b [Apple Silicon] [Test] Fix a few tests for SDK differences 2020-07-02 19:12:05 -07:00
Mishal Shah
a8aec14bce [Apple Silicon] Adjust linking deployment target from 11.0 down to 10.16 on x86. 2020-07-02 18:31:09 -07:00
Mishal Shah
134f202e01 [Apple Silicon] Baseline arm64 macOS at Swift 5.3 / macOS 10.16 2020-07-02 16:42:15 -07:00
Doug Gregor
480c631209 Linux-specific fixes for the swift-frontend rename.
Hardlinking to a symlink is not permitted, so use "swift-frontend"
instead of "swift" as the hard-link target.

Also, update one Linux-specific test to check for swift-frontend.
2020-06-23 13:17:26 -07:00
Doug Gregor
b656955f79 [Driver tests] Be explicit when we don't care about SDK/target mismatches 2020-06-16 15:53:13 -07:00
Doug Gregor
1be17a2550 [Darwin test config] Use the SDK when running swift/swiftc in tests.
The Swift driver (swift/swiftc) is supposed to always be used with an
accompanying SDK, which it derives from the environment. Our test
infrastructure was clearing out this SDK, making it deviate from the
normal operating environment unnecessarily. Switch to providing the
SDK used for building the standard library, which provides a
more-consistent test environment, and tag the few places in tests
where we have explicit dependencies on "no SDK."
2020-06-15 14:11:08 -07:00
Doug Gregor
574f0e8a5b [Platform] Stop inferring simulator-ness.
The *-simulator target triples have been used consistently in tools for
several years to indicate simulator targets. Stop inferring the
simulator part, rdar://problem/35810403.
2020-04-20 08:50:34 -07:00
Saleem Abdulrasool
fbbf61f297 Revert "[Darwin] Further restrict inference of the simulator environment" 2020-04-19 16:43:22 -07:00
Doug Gregor
7e7dc648f2 [Platform] Stop inferring simulator-ness.
The *-simulator target triples have been used consistently in tools for
several years to indicate simulator targets. Stop inferring the
simulator part, rdar://problem/35810403.
2020-04-16 11:35:43 -07:00
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