Commit Graph

85 Commits

Author SHA1 Message Date
Yuta Saito
678585238d [wasm] Add WASI as a supported target for sanitizers 2025-04-30 09:54:23 +00:00
swift-ci
1a305de854 Merge remote-tracking branch 'origin/main' into rebranch 2024-05-14 10:13:39 -07:00
Blue Gaston
68923d4035 Adds valid arguments to -sanitize-coverage: pc-table and inline-8bit-counter.
As is, you cannot set all default fuzzer options directly using -sanitize-coverage. Because of this you can use default fuzzer sanitize-coverage args, or a limited number coverage options.

This PR adds pc-table and inline-8bit-counter as valid args to be parsed for sanitize-coverage flag. These are default fuzzer options -- and will allow customizing sanitizer-coverage in variations of fuzzer defaults. (i.e. w/o pc-table enabled).

In upstream clang the option -fno-sanitize-coverage exists to disable various coverage options. Swift currently does not have a convention of using excluding args for sanitizer flags. This aims to limit the need for a new flag by inclusively setting desired coverage up to current fuzzer defaults.

rdar://127881891
2024-05-13 07:51:25 -07:00
Ben Barham
acd0efa67f Migrate to common OptTable macros
`OptTable` was a source of consistent churn due to new arguments to the
`OPTION` macro. LLVM 3f092f37b7362447cbb13f5502dae4bdd5762afd extracted
the handling of the common option parts (eg. an ID and an info) out into
separate macros to reduce this - use those here (since unsurprisingly,
more arguments were added).
2024-04-08 08:58:58 -07:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Ellie Shin
6c002edb38 Add emit-package-module-interface-path and experimental-package-interface-load to features.json 2024-01-11 18:49:26 -08:00
Steven Wu
e2f888b311 Merge pull request #70384 from cachemeifyoucan/eng/PR-119387650
[Caching] Encoding cache key for input file with index instead of path
2024-01-04 12:04:25 -08:00
Steven Wu
76bde39ee7 [Caching] Encoding cache key for input file with index instead of path
Avoid path encoding difference (for example, real_path vs. path from
symlink) by eliminating the path from cache key. Cache key is now
encoded with the index of the input file from all the input files from
the command-line, reguardless if those inputs will produce output or
not. This is to ensure stable ordering even the batching is different.

Add a new cache computation API that is preferred for using input index
directly. Old API for cache key is deprecated but still updated to
fallback to real_path comparsion if needed.

As a result of swift scan API change, rename the feature in JSON file to
avoid version confusion between swift-driver and libSwiftScan.

rdar://119387650
2023-12-18 14:06:00 -08:00
usama
3053fe01b5 [Sanitizers] Add new sanitize-stable-abi flag for libsanitizers.
This patch adds a new flag sanitize-stable-abi to support linking
against the Sanitizers stable ABI added recently in compiler-rt. The
patch also passes extra options for the ASan pass when using this flag
to outline instrumentation code and remove version check.

rdar://112915278
2023-12-16 14:13:00 -08:00
Steven Wu
a09052f2a7 Add cache-compile-job to features.json
Add `cache-compile-job` to toolchain feature JSON file so build
system/swift driver can query.
2023-11-10 10:46:13 -08:00
Max Desiatov
b7d8a9b22b Add ld-path-driver-option to features.json (#69586)
Dependency of https://github.com/apple/swift-package-manager/pull/7021.

The `-ld-path` option was introduced on `main` in https://github.com/apple/swift-driver/pull/1442 and `release/5.10` in https://github.com/apple/swift-driver/pull/1442. SwiftPM needs to detect this flag to pass options to the driver correctly, and it's suitable to do this via `feature.json` instead of checking for the compiler version via other means.

Partially resolves rdar://117049947.
2023-11-02 18:08:18 +00:00
Evan Wilde
b0d3b398d8 Diagnose sanitizer use with scudo
Scudo is now a standalone sanitizer that must be used in isolation.
Fixing the driver logic to identify and diagnose when it is used with
any other sanitizer.
2023-08-23 15:36:24 -07:00
Evan Wilde
a582339bfa Fix StringLiteral conversion failure
StringLiterals don't covert to a `const char *`. I've updated the option
initialization to handle the new behavior.
2023-07-25 12:28:28 -07:00
Evan Wilde
41d59b215a Update Triple.h location
Triple moved from ADT to TargetParser. Updating includes to reflect
that.
2023-07-17 10:53:42 -07:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Artem Chikin
3f0c0f0553 [Compile Time Constant Extraction] Add extraction of all conformances and type aliases of applicable nominal types
This change adds to the extracted type metadata the following fields:
- Conformances: this is a list of all protocols that the given nominal type conforms to
- associated type aliases: this is a list of all associated types across all conformances that the given nominal type substitutes with concrete types. For a given associated type, we gather:
  - Associated type name
  - Substituted type's fully-qualified name
  - Substituted type's mangled name
  - If the substituted type is opaque:
    - List of conformance requirements of this opaque type
    - List of same-type requirements of this opaque type
2023-06-22 07:13:24 -07:00
Ellie Shin
3c81a02112 Rename package-name flag 2023-04-12 15:22:45 -07:00
Ellie Shin
f26890a31d Add package-name to lib/Option/features.json
Resolves rdar://106448681
2023-03-08 13:46:38 -08:00
Franklin Schrans
d3e96590d9 Merge pull request #61637 from theMomax/extension-block-symbols-deactivation-flag
Make emission of extension block symbols a formal feature
2022-12-01 08:18:24 +01:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Max Obermeier
504fe3c3a4 Make emission of extension block symbols formal feature
- add name to lib/Option/features.json
 - add flag for explicitly disabling extension block symbols feature
2022-10-19 19:13:11 +02:00
Artem Chikin
869e70f993 [Compile Time Constant Extraction] Add 'features.json' entry for ability to emit constant value side-car file 2022-08-19 11:40:08 -07:00
Artem Chikin
514996e755 [Compile Time Constant Extraction] Use 'Expr::printConstExprValue' instead of rolling it ourselves. 2022-08-19 11:39:40 -07:00
swift-ci
ba127e7324 Merge pull request #58586 from jsoref/spelling-lib-option
spelling: existence
2022-07-22 20:03:14 -07:00
Jan Svoboda
f9c5c45e7a [build] Merge Clang's features.json from binary directory, handle values 2022-06-06 15:02:39 +02:00
Josh Soref
719400c4da spelling: existence
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-05-01 04:32:23 -04:00
Xi Ge
f8986dcdb6 FeatureFlags: rename feature flag enable-bare-slash-regex. NFC 2022-04-21 11:01:34 -07:00
Artem Chikin
7ba377b3c2 Rename flag for enabling forward slash literals to be less ambiguous.
Previous spelling could easily be mistaken for gating the entire feature.

Part of rdar://91119995
2022-04-06 09:46:40 -07:00
Artem Chikin
b04ae26391 Add support for -enable-regex-literals flag
- Add driver and frontend option
- Add LangOptions entry
- Ensure driver propagates flag to frontends
- Add feature to `features.json`

Part of rdar://91119995
2022-04-01 12:14:28 -07:00
Ben Barham
a1e3afadb2 [Option] Add feature flag for empty ABI descriptors
Allow clients to check whether they can force empty ABI descriptors to
be output.
2022-03-21 13:25:51 -07:00
Saleem Abdulrasool
75ddb7c224 Update CMakeLists.txt
Explicitly invoke the script executor rather than the script as running a script is meaningless.  Shebangs are not a portable manner of indicating the script executor and worse yet do not guarantee portability on such systems either.  Ideally the shebang line would be removed from the script.

Thanks to @pcbeard for reporting the issue!
2022-03-06 14:41:56 -08:00
Ben Barham
e95453ee22 [CMake] Merge Clang's features file with Swift's
Clang has a new `redirecting-with` property in the VFS overlay files.
While this could be added to Swift's features as well, it is generally
the case that features provided by Clang can also be useful to know for
clients of Swift. Merge the features from Clang into Swift's features
file with the "clang-" prefix to differentiate them.
2022-02-28 13:20:12 -08:00
Saleem Abdulrasool
1f690ff04b Revert "[CMake] Merge Clang's features file with Swift's" 2022-02-27 15:24:48 -08:00
Ben Barham
914b984e3d [CMake] Merge Clang's features file with Swift's
Clang has a new `redirecting-with` property in the VFS overlay files.
While this could be added to Swift's features as well, it is generally
the case that features provided by Clang can also be useful to know for
clients of Swift. Merge the features from Clang into Swift's features
file with the "clang-" prefix to differentiate them.
2022-02-25 11:55:39 -08:00
Ben Barham
50c9af4fca [Frontend] Add feature flag for the index unit path warning removal
6e683ca823 removed the warning that was
being output when `-index-unit-output-path` was given without
`-index-store-path`. Add a feature flag to mark the compiler as having
removed this warning.

Resolves rdar://86833719.
2022-01-20 10:34:37 -08:00
Xi Ge
f97653ef37 Frontend: teach -emit-module and -merge-modules to emit ABI descriptor files 2021-09-21 16:51:52 -07:00
Alexis Laferrière
97c4fdc0e3 [Driver] Set the feature flag library-level
Set the flag to indicate the availability of the -library-level flag in
the compiler and driver. As driver submissions can be delayed we are
integrating this flag late as a safety measure.

rdar://82742547
2021-09-03 15:45:06 -07:00
Nathan Hawes
117f03b2f5 [Driver][Index] Add driver support to specify an overriding output path to record in the index data
The frontend supports this via new options -index-unit-output-path and
-index-unit-output-path-filelist that mirror -o and -output-filelist. These are
intended to allow sharing index data across builds in separate directories (so
different -o values) that are otherwise equivalent as far as the index data is
concerned (e.g. an ASAN build and a non-ASAN build) by supplying the same
-index-unit-output-path for both.

This change updates the driver to add these new options to the frontend
invocation 1) when a new "index-unit-output-path" entry is specified for one
or more input files in the -output-file-map json or 2) if -index-file is
specified, when a new -index-unit-output-path driver option is passed.

Resolves rdar://problem/74816412
2021-03-06 13:44:14 +10:00
Dan Liew
9208b52de1 Disable "UseOdrIndicator" ASan instrumentation mode by default.
Previously Swift enabled the "UseOdrIndicator" ASan instrumentation mode
and gave no option to disable this. This probably wasn't intentional but
happened due to the fact the
`createModuleAddressSanitizerLegacyPassPass()` function has a default
value for the `UseOdrIndicator` parameter of `true` and in Swift we
never specified this parameter explicitly.

Clang disables the "UseOdrIndicator" mode by default but allows it to be
enabled using the `-fsanitize-address-use-odr-indicator` flag.
Having "UseOdrIndicator" off by default is probably the right
default choice because it bloats the binary. So this patch changes the
Swift compiler to match Clang's behavior.

This patch disables the "UseOdrIndicator" mode by default but adds a
hidden driver and frontend flag (`-sanitize-address-use-odr-indicator`)
to enable it. The flag is hidden so that we can remove it in the future
if needed.

A side effect  of disabling "UseOdrIndicator" is that by we will no
longer use private aliases for poisoning globals. Private aliases were
introduced to avoid crashes
(https://github.com/google/sanitizers/issues/398) due to ODR violations
with non-instrumented binaries. On Apple platforms the use of two-level
namespaces probably means that using private aliases wasn't ever really
necessary to avoid crashes. On platforms with a flat linking namespace
(e.g. Linux) using private aliases might matter more but should users
actually run into problems they can either:

* Fix their environment to remove the ODR, thus avoiding the crash.
* Instrument the previously non-instrumented code to avoid the crash.
* Use the new `-sanitize-address-use-odr-indicator` flag

rdar://problem/69335186
2020-12-15 11:09:30 -08:00
Ben Barham
d57d9fd726 Add features file describing new available flags
The only available method to check for features at the moment is through
version checks. This is errorprone and doesn't work well for OSS
toolchains or locally built compilers.

features.json is intended to communicate to build systems that a new
flag is available, in order to assist with a transitional period where
not all supported toolchains may have a particular flag. It is *not*
intended to be a comprehensive report of all flags available.

Note that the names are intended to be features, so while they may match
up to the corresponding flag name, this isn't necessarily the case.
2020-11-12 11:53:18 +10:00
Saleem Abdulrasool
b7b0a25acb build: remove meaningless dependency 2020-02-01 15:18:25 -08:00
Cory Benfield
565298620b [Sanitizers] Add Scudo support (#28538)
LLVM ships a hardened memory allocator called Scudo:
https://llvm.org/docs/ScudoHardenedAllocator.html. This allocator
provides additional mitigations against heap-based vulnerabilities, but
retains sufficient performance to be safely run in production
applications.

While ideal Swift applications are obviously written in pure Swift, in
practice most applications contain some amount of code written in
less-safe languages. Additionally, plenty of Swift programs themselves
contain unsafe code, particularly when attempting to implement
high-performance data structures. These sources of unsafety introduce
the risk of memory issues, and having the option to use the Scudo
allocator is a useful defense-in-depth tool.

This patch enables `-sanitize=scudo` as an extra `swiftc` flag. This
sanitizer is only supported on Linux, so no further work is required to
enable it on Windows or Apple platforms. As this "sanitizer" is only a
runtime component, we do not require any wider changes to instrument
code. This is similar to clang's `-fsanitize=scudo` flag.

The Swift driver rejects platforms that don't support Scudo using an
existing mechanism in the Driver that is not part of this patch. This
mechanism is in swift::parseSanitizerArgValues(...)
(lib/Option/SanitizerOptions.cpp). The mechanism determines if a
sanitizer is supported by checking for the existence of the
corresponding sanitizer runtime library in the compiler's resource
directory. The Scudo runtime library currently only exists in the
Linux compiler resource directory. This results in the driver only
allowing Scudo when targeting Linux.
2020-01-26 17:27:14 -08:00
Dan Liew
63e72909b5 [Sanitizers] Add Driver/Frontend option to enable sanitizer instrumentation that supports error recovery.
The new option `-sanitize-recover=` takes a list of sanitizers that
recovery instrumentation should be enabled for. Currently we only
support it for Address Sanitizer.

If the option is not specified then the generated instrumentation does
not allow error recovery.

This option mirrors the `-fsanitize-recover=` option of Clang.

We don't enable recoverable instrumentation by default because it may
lead to code size blow up (control flow has to be resumable).

The motivation behind this change is that today, setting
`ASAN_OPTIONS=halt_on_error=0` at runtime doesn't always work. If you
compile without the `-sanitize-recover=address` option (equivalent to
the current behavior of the swift compiler) then the generated
instrumentation doesn't allow for error recovery. What this means is
that if you set `ASAN_OPTIONS=halt_on_error=0` at runtime and if an ASan
issue is caught via instrumentation then the process will always halt
regardless of how `halt_on_error` is set. However, if ASan catches an
issue via one of its interceptors (e.g. memcpy) then `the halt_on_error`
runtime option is respected.

With `-sanitize-recover=address` the generated instrumentation allows
for error recovery which means that the `halt_on_error` runtime option
is also respected when the ASan issue is caught by instrumentation.

ASan's default for `halt_on_error` is true which means this issue only
effects people who choose to not use the default behavior.

rdar://problem/56346688
2019-11-12 11:33:58 -08:00
Michael Gottesman
91dbbc3088 Merge pull request #23204 from compnerd/silence-in-the-library
Remove custom handling in add_swift_host_library
2019-04-08 10:49:42 -07:00
Julian Lettner
34f830116d [Driver][NFC] Define sanitizer mapping <kind, name, file> in one place
Lower maintenance cost for explicit mapping between sanitizer enum and
string values.
2019-03-28 13:56:54 -07:00
Julian Lettner
e24585dc17 [Driver] Delegate linking of sanitizer runtimes to underlying Clang
For Unix tool chains.
2019-03-26 10:56:52 -07:00
Saleem Abdulrasool
f9df4cad97 build: remove DEPENDS from add_swift_host_library
Use the appropriate CMake mechanisms for building the libraries.
2019-03-10 17:01:27 -07:00
Saleem Abdulrasool
9934532e07 cmake: switch host libraries to use target_link_libraries
This is a follow up to the discussion on #22740 to switch the host
libraries to use the `target_link_libraries` rather than the
`LINK_LIBRARIES` special handling.  This allows the dependency to be
properly tracked by CMake and allows us to use the more modern syntax.
2019-02-22 15:28:07 -08:00
Rahul Malik
d3cc043e58 Add Undefined Behavior sanitizer to Swift Driver (#18553)
This change allows the swift driver to link the ubsan runtime if
`-sanitize=undefined` is specified.
This is useful for sanitizing linked Objective-C code.
2018-11-13 12:11:56 -08:00