Commit Graph

1784 Commits

Author SHA1 Message Date
Adrian Prantl
6b1263bf5a [Driver] Add a -gdwarf-types option and set it up as an alias for -g (NFC-ish)
Background
----------

Now that Swift AST type support in LLDB has matured, we can stop emitting DWARF
type information by default to reduce compile time and ibject file size.
A future commit will change -g to emit only AST type references.

The full set of debug options will be
-gnone
-gline-tables-only
-g                 // AST types (= everything that LLDB needs)
-gdwarf-types      // AST types + DWARF types (for legacy debuggers)
2016-07-05 12:06:23 -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
Brian Gesiak
328de9e280 [SR-1738] add_swift_library takes SHARED/STATIC arg
As a first step to allowing the build script to build *only*
static library versions of the stdlib, change `add_swift_library`
such that callers must pass in `SHARED`, `STATIC`, or `OBJECT_LIBRARY`.

Ideally, only these flags would be used to determine whether to
build shared, static, or object libraries, but that is not currently
the case -- `add_swift_library` also checks whether the library
`IS_STDLIB` before performing certain additional actions. This will be
cleaned up in a future commit.
2016-06-16 13:15:58 -04:00
Mishal Shah
87b7bcfd3e Update master to build with Xcode 8 beta 1, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs. 2016-06-14 14:53:55 -07:00
Dan Liew
827f573d6b Teach the Swift front-end to generate code with
"Sanitizer Coverage" with a new flag ``-sanitize-coverage=``. This
flag is analogous to Clang's ``-fsanitize-coverage=``.

This instrumentation currently requires ASan or TSan to be enabled
because the module pass created by ``createSanitizerCoverageModulePass()``
inserts calls into functions found in compiler-rt's "sanitizer_common".
"sanitizer_common" is not shipped as an individual library but instead
exists in several of the sanitizer runtime libraries so we have to
link with one of them to avoid linking errors.

The rationale between adding this feature is to allow experimentation
with libFuzzer which currently relies on "Sanitizer Coverage"
instrumentation.
2016-05-27 13:34:31 -07:00
Brian Gesiak
7218c41e60 Merge pull request #2609 from compnerd/linux-is-gold
utils: require gold on Linux targets
2016-05-24 16:29:53 -04:00
Bob Wilson
21413d3f0f Fix comment typo. 2016-05-22 19:17:37 -07:00
Saleem Abdulrasool
3b7b0d8091 utils: require gold on Linux targets
Given the discussion on swift-dev, and no opposition, swift the linux targets to
using gold by default.
2016-05-20 20:13:56 -07:00
Drew Crawford
7ae91eae3c Implement -static-stdlib for Linux (#1891)
[Driver] implement -static-stdlib for Linux

Implement the -static-stdlib driver flag for Linux, allowing the static
linking of the standard library.

This implementation largely follows the Darwin implementation in #1817,
although some pecularities warrant extended discussion.

The original "link with stdlib" implementation had some redundancies
with getRuntimeLibraryPath; these redundancies are resolved, and the
implementation alternates between getRuntimeLibraryPath and
getStaticRuntimeLibraryPath cleanly as appropriate.

A variety of libraries are required to link statically on Linux.  The
implementation currently dynamically links with them.  We should
probably support static linking of those as well, but I think that is
beyond the scope of a -static-stdlib flag.

The test coverage uses ldd here, as otool is not available on Linux.  As
a result, we currently have separate tests for Linux vs the other
platforms; that isn't ideal, but it seems necessary.

Perhaps the oddest part, and the one worth the most discussion, is the
use of --dynamic-list.  Inside
stdlib/public/runtime/ProtocolConformances.cpp appears the following
code:

    #elif defined(__ELF__)
    static int _addImageProtocolConformances(struct dl_phdr_info *info,
                                              size_t size, void *data) {
      // inspectArgs contains addImage*Block function and the section name
      InspectArgs *inspectArgs = reinterpret_cast<InspectArgs *>(data);

      void *handle;
      if (!info->dlpi_name || info->dlpi_name[0] == '\0') {
        handle = dlopen(nullptr, RTLD_LAZY);
      } else
        handle = dlopen(info->dlpi_name, RTLD_LAZY | RTLD_NOLOAD);
      auto conformances = reinterpret_cast<const uint8_t*>(
          dlsym(handle, inspectArgs->sectionName));

The effect of this is to search for protocol_conformances_start inside
the images.  However, dlsym only finds symbols that exist in the dynamic
table.  Failure to find the protocol conformances can be diagnosed by a
"hello world" program printing

    String(_core: Swift._StringCore(_baseAddress: Swift.OpaquePointer(_rawValue: (Opaque Value)), _countAndFlags: Swift.UInt(_value: (Opaque Value)), _owner: Swift.Optional<Swift.AnyObject>.none))

instead of "hello world".  (And also by the test coverage in this commit.)

Surprisingly, this behavior can still occur on ELF platforms even if
`objdump -t` reports a valid `.protocol_conformances_start`.  This is
because `objdump -t` searches the global table, not the dynamic table,
while dlsym only searches the dynamic table.  To configure objdump to
search only the dynamic table, use `-T`.

Inquiring minds may wonder whether dynamically-linked programs (e.g. all
Linux binaries up until now) also have a broken protocol conformance
table on ELF.  The answer is, surprisingly, no; I checked, and ordinary
ELF programs are fine.  The distinction is probably this, from the ld
manpage:

> the dynamic symbol table will normally contain only those
symbols which are referenced by some dynamic object mentioned in the
link.

I think the linker sees `.protocol_conformances_start` inside
libswiftCore.so and erroneously concludes the one in *the executable* is
"referenced by some dynamic object" (e.g. the standard library).  This
behavior seems to save the dyanmically-linked executable from a broken
protocol conformance table.  I wonder if it would be wise to apply a
similar fix to dynamically-linked programs to avoid relying on the
linker "helping" us here, but that's out of scope of this commit.

The linker manpage reflects that many people have been bitten by dlsym
"surprise", and encourages the use of `--export-dynamic`:

> If you use "dlopen" to load a dynamic object which needs to refer back
> to the symbols defined by the program, rather than some other dynamic
> object, then you will probably need to use [--export-dynamic] when
> linking the program itself.

However in this situation, the use of `--export-dynamic` causes the
entire stdlib to be exported, which is not ideal.  However, by combining
with the `--exclude-libs ALL` argument, we avoid exporting the entire stdlib.
2016-05-04 09:22:33 -07:00
Drew Crawford
d7f4d4c12b [Driver] add -static-stdlib flag (Darwin platforms) (#1817)
This commit adds the flags -static-stdlib and -no-static-stdlib to
create programs statically linked (or not) with the standard library.
Not is the default, which is also the current behavior.

These flags are currently placebos on non-Darwin platforms.
2016-05-04 09:19:56 -07:00
Ryan Lovelett
0c0bcbb094 Convert "armv7l" to "armv7" for the architecture component of paths (#2369)
On the Raspberry Pi 2 when trying to import Glibc, without this patch, it will attempt to
find the module map at "/usr/lib/swift/linux/armv7l/glibc.modulemap" and
fail to do so.

With this patch it will attempt to find the module map at
"/usr/lib/swift/linux/armv7/glibc.modulemap" where it will succeed in
finding the module map.

Similar behavior currently happens in the Driver and Frontend. To DRY up
this behavior it has been extracted to the Swift platform.
2016-05-02 15:25:58 -07:00
practicalswift
df23ceac38 [gardening] Fix recently introduced typo: "accomodate" → "accommodate" 2016-04-13 10:17:25 +02: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
Brian Gesiak
c0e1a7ce3f [Toolchains] Fix typo in header comment
Remove "t" added accidentally in previous typo fix commit. Sorry about that!
2016-04-11 14:43:45 -04:00
Brian Gesiak
bb20005b01 [Toolchains] Fix typo in virtual method docs
Remove a duplicate "the".
2016-04-11 14:42:14 -04:00
Brian Gesiak
a04dded0c0 [Toolchains] Document virtual methods (#2134)
Adds documentation for the methods added in
https://github.com/apple/swift/pull/1908.
2016-04-10 19:05:20 -07:00
Anna Zaks
92fae2e9a4 Add experimental support for Thread Sanitizer.
This patch threads the TSan option through the front end.
2016-04-06 11:53:43 -07:00
Jordan Rose
5810073579 Merge pull request #1908 from modocache/toolchain-hierarchy
[Toolchains] Cygwin toolchain inherits from Unix
2016-04-05 19:27:47 -07:00
Brian Gesiak
d0747b0f47 [Toolchains] Cygwin toolchain inherits from Unix
There is currently a great deal of duplication across the
`GenericUnix` and `Windows` toolchains. The Android port will
add even more duplication.

To mitigate this, have `Windows` inherit from `GenericUnix`, and
have them share most of their implementation.

In addition, rename `Windows` to `Cygwin` (it would be pretty strange
to have a `Windows` toolchain inherit from something named `*Unix`).
2016-04-05 21:20:10 -04:00
practicalswift
abfecfde17 [gardening] if ([space]…[space]) → if (…), for(…) → for (…), while(…) → while (…), [[space]x, y[space]] → [x, y] 2016-04-04 16:22:11 +02:00
Dmitri Gribenko
cc2a2f8921 Revert "[Driver] Default SDKROOT to / on FreeBSD." 2016-03-02 09:26:06 -08:00
Davide Italiano
d9bc8bf13f Merge pull request #1500 from dcci/sdkroot
[Driver] Default SDKROOT to / on FreeBSD.
2016-03-01 22:14:21 -08:00
Davide Italiano
c82588b01b [Driver] Default SDKROOT to / on FreeBSD.
This is needed for the testusuite to run correctly.
2016-03-01 20:15:24 +00:00
practicalswift
451a104116 [gardening] Fix recently introduced typo: "dependcy" → "dependency" 2016-03-01 11:28:52 +01:00
AnnaZaks
767d9ca914 Merge pull request #1434 from apple/asan
[asan] Add basic support for Address Sanitizer function instrumentation
2016-02-29 18:58:40 -08:00
zaks
2110235fd3 [asan] Cleanup based on Jordan's review comments 2016-02-26 16:02:40 -08:00
zaks
d727c68fde [asan] Add "unsupported option .. for target" error message
ASan support for Linux does not exist at this point.
2016-02-25 15:20:51 -08:00
zaks
ef925f8fb3 [asan] Add basic support for Address Sanitizer function instrumentation
ASan allows to catch and diagnose memory corruption errors, which are possible
when using unsafe pointers.

This patch introduces a new driver/frontend option -sanitize=address to enable
ASan. When option is passed in, the ASan llvm passes will be turned on and
all functions will gain SanitizeAddress llvm attribute.
2016-02-24 09:45:38 -08:00
Han Sangjin
e06c7136cb Porting to Cygwin. rebased and squashed 2016-02-22 13:20:21 +09:00
William Dillon
d0d9b1de5a Discard swift.ld and support gold linker 2016-02-17 17:47:35 -08:00
Orlando Bassotto
f889bcc64f Implement -use-ld= switch in Swift 2016-02-17 17:47:35 -08:00
AlexDenisov
f8688daf57 Use operator== to compare YAML iterators 2016-02-07 16:55:01 +01:00
William Dillon
ab7c87e7e8 Implemented ARMv6 and fixed up ARMv7 2016-01-29 21:41:22 +00:00
Jordan Rose
9c6cdd3296 [Driver] Fix references to Clang's profiling runtime.
(1) We no longer put the Clang version string in our copy of or symlink to
    Clang's resource directory.
(2) Newer Clang builds now generate a separate library for the Apple OS
    simulators, instead of a fat binary.

We still need a proper end-to-end test for this, but that depends on
building compiler-rt with Swift, which isn't a standard config yet.
2016-01-28 20:00:41 -08:00
practicalswift
8efa5f587e [gardening] Remove "-*- C++ -*-" tag from .cpp files
Emacs assumes .h files are C files by default which is why the
tag "-*- C++ -*-" is needed.

.cpp files do not have this problem.
2016-01-23 12:09:32 +01:00
Michael Ilseman
dc689e607c [Diagnostics] -suppress-warnings and -warnings-as-errors flags
Exposes the global warning suppression and treatment as errors
functionality to the Swift driver. Introduces the flags
"-suppress-warnings" and "-warnings-as-errors". Test case include.
2016-01-15 14:20:44 -08:00
Jordan Rose
bbc14afd04 [Driver] Write per-job filelists even under -save-temps.
Same as the previous commit; here's a test case that triggers it.

Last bit of https://bugs.swift.org/browse/SR-280.
2016-01-13 18:41:05 -08:00
Jordan Rose
ce34ed593c [Driver] Use filelists for the *output* of a threaded WMO build.
This is only the driver side of the work; the frontend doesn't understand
this new -output-filelist option yet. Next commit.

More https://bugs.swift.org/browse/SR-280.
2016-01-13 18:39:24 -08:00
Jordan Rose
062713d600 [Driver] Use -filelist for the merge-module step.
More https://bugs.swift.org/browse/SR-280.
2016-01-13 18:39:24 -08:00
Jordan Rose
3328a30ea8 [Driver] Write the all-sources file even under -save-temps.
We optimize subprocess invocation to a simple execve() if there's no
cleanup work to do, but that doesn't get us out of doing /setup/ work.
2016-01-13 18:39:24 -08:00
Jordan Rose
6067120f81 [Driver] Emit filelists for Jobs that want them (inputs).
This is the other half of the previous commit: we can use -filelist for
linking on Darwin.

More https://bugs.swift.org/browse/SR-280.
2016-01-13 18:39:24 -08: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
f8bb54f6e6 [Driver] Pass around 'const char *' instead of 'const std::string &'.
No functionality change -- lifetime extension is handled by the
ArgumentList already owned by the Compilation.
2016-01-13 18:39:24 -08:00
Jordan Rose
fe00083eb1 [Driver] Actually write out the source file list file.
This is simply a newline-separated list of files, matching the format
from Darwin ld's -filelist option.

Part 2 of https://bugs.swift.org/browse/SR-280.
2016-01-12 19:20:50 -08:00
Jordan Rose
b45a69ef09 [Driver] Allow passing all source files in a filelist.
Generate frontend commands with -filelist in them. This isn't actually
implemented yet, but we can start testing at this point.

Part 1 of https://bugs.swift.org/browse/SR-280.
2016-01-12 19:20:50 -08:00
Jordan Rose
7be3effeed [Driver] Remove an unused accessor.
No one should be accessing the raw input argument list; it's there merely
to keep the info about the derived argument list alive.
2016-01-12 16:17:27 -08:00
Jordan Rose
7552d49c4a [Driver] Eliminate unused fields from Compilation.
No functionality change.
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
Jordan Rose
af8eb3766d [Driver] Constify a parameter. No functionality change. 2016-01-12 11:52:31 -08:00
Jordan Rose
dbd0d47568 [Driver] Only JobActions have inputs, not InputActions.
Also, cluster the flags on Action into a single word. This probably doesn't
make any real difference, but it's the convention.

No functionality change.
2016-01-12 11:52:31 -08:00