mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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
59 lines
2.3 KiB
C++
59 lines
2.3 KiB
C++
//===--- SanitizerOptions.h - Helpers related to sanitizers -----*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_OPTIONS_SANITIZER_OPTIONS_H
|
|
#define SWIFT_OPTIONS_SANITIZER_OPTIONS_H
|
|
|
|
#include "swift/Basic/Sanitizers.h"
|
|
#include "swift/Basic/OptionSet.h"
|
|
#include "llvm/ADT/Triple.h"
|
|
#include "llvm/Option/Arg.h"
|
|
#include "llvm/Option/ArgList.h"
|
|
// FIXME: This include is just for llvm::SanitizerCoverageOptions. We should
|
|
// split the header upstream so we don't include so much.
|
|
#include "llvm/Transforms/Instrumentation.h"
|
|
|
|
namespace swift {
|
|
class DiagnosticEngine;
|
|
|
|
/// Parses a -sanitize= argument's values.
|
|
///
|
|
/// \param Diag If non null, the argument is used to diagnose invalid values.
|
|
/// \param sanitizerRuntimeLibExists Function which checks for existence of a
|
|
// sanitizer dylib with a given name.
|
|
/// \return Returns a SanitizerKind.
|
|
OptionSet<SanitizerKind> parseSanitizerArgValues(
|
|
const llvm::opt::ArgList &Args, const llvm::opt::Arg *A,
|
|
const llvm::Triple &Triple, DiagnosticEngine &Diag,
|
|
llvm::function_ref<bool(llvm::StringRef, bool)> sanitizerRuntimeLibExists);
|
|
|
|
OptionSet<SanitizerKind> parseSanitizerRecoverArgValues(
|
|
const llvm::opt::Arg *A, const OptionSet<SanitizerKind> &enabledSanitizers,
|
|
DiagnosticEngine &Diags, bool emitWarnings);
|
|
|
|
/// Parses a -sanitize-coverage= argument's value.
|
|
llvm::SanitizerCoverageOptions parseSanitizerCoverageArgValue(
|
|
const llvm::opt::Arg *A,
|
|
const llvm::Triple &Triple,
|
|
DiagnosticEngine &Diag,
|
|
OptionSet<SanitizerKind> sanitizers);
|
|
|
|
/// Parse -sanitize-address-use-odr-indicator's value.
|
|
bool parseSanitizerAddressUseODRIndicator(
|
|
const llvm::opt::Arg *A, const OptionSet<SanitizerKind> &enabledSanitizers,
|
|
DiagnosticEngine &Diags);
|
|
|
|
/// Returns the active sanitizers as a comma-separated list.
|
|
std::string getSanitizerList(const OptionSet<SanitizerKind> &Set);
|
|
}
|
|
#endif // SWIFT_OPTIONS_SANITIZER_OPTIONS_H
|