Commit 7dbed157 authored by glider's avatar glider Committed by Commit bot

Reland https://codereview.chromium.org/581983003/: Enable ASan default options on Mac.

This CL links libsanitizer_options into every executable built with ASan on OSX.
The existing implementation of __asan_default_options for Chromium.app is merged
with that in sanitizer_options.cc

Also now use_sanitizer_options is only set when building with sanitizers so that
there isn't an unconditional dependency on an empty object file in every
executable in non-sanitizer builds.

In addition to that, the dependency on sanitizers.gyp:sanitizer_options is removed
from ui/base/ui_base_tests.gyp:ui_base_tests_bundle which is not a real shared lib,
despite marked as such.

BUG=302040
TBR=earthdok@chromium.org,cpu@chromium.org
R=avi@chromium.org

Review URL: https://codereview.chromium.org/594843002

Cr-Commit-Position: refs/heads/master@{#296200}
parent a5a81ef6
......@@ -389,7 +389,7 @@
# Enable Chromium overrides of the default configurations for various
# dynamic tools (like ASan).
'use_sanitizer_options%': 1,
'use_sanitizer_options%': 0,
# Enable building with SyzyAsan.
# See https://code.google.com/p/sawbuck/wiki/SyzyASanHowTo
......@@ -2140,6 +2140,7 @@
['asan==1 or msan==1 or lsan==1 or tsan==1', {
'clang%': 1,
'use_allocator%': 'none',
'use_sanitizer_options%': 1,
}],
['asan==1 and OS=="linux" and chromeos==0', {
'use_custom_libcxx%': 1,
......@@ -3480,6 +3481,14 @@
'-Wl,-z,now',
'-Wl,-z,relro',
],
# TODO(glider): enable the default options on other systems.
'conditions': [
['use_sanitizer_options==1 and ((OS=="linux" and (chromeos==0 or target_arch!="ia32")) or OS=="mac")', {
'dependencies': [
'<(DEPTH)/build/sanitizers/sanitizers.gyp:sanitizer_options',
],
}],
],
},
}],
# TODO(jochen): Enable this on chromeos on arm. http://crbug.com/356580
......@@ -4096,14 +4105,6 @@
],
}],
],
# TODO(glider): enable the default options on other systems.
'conditions': [
['use_sanitizer_options==1 and OS=="linux" and (chromeos==0 or target_arch!="ia32")', {
'dependencies': [
'<(DEPTH)/build/sanitizers/sanitizers.gyp:sanitizer_options',
],
}],
],
}],
['asan==1', {
'target_conditions': [
......
......@@ -7,6 +7,11 @@
#include "build/build_config.h"
#if defined(ADDRESS_SANITIZER) && defined(OS_MACOSX)
#include <crt_externs.h> // for _NSGetArgc, _NSGetArgv
#include <string.h>
#endif // ADDRESS_SANITIZER && OS_MACOSX
// Functions returning default options are declared weak in the tools' runtime
// libraries. To make the linker pick the strong replacements for those
// functions from this module, we explicitly force its inclusion by passing
......@@ -61,6 +66,8 @@ const char *kAsanDefaultOptions =
const char *kAsanDefaultOptions =
"strict_memcmp=0 replace_intrin=0 check_printf=1 use_sigaltstack=1 "
"strip_path_prefix=Release/../../ ";
static const char kNaClDefaultOptions[] = "handle_segv=0";
static const char kNaClFlag[] = "--type=nacl-loader";
#endif // OS_LINUX
#if defined(OS_LINUX) || defined(OS_MACOSX)
......@@ -71,6 +78,18 @@ __attribute__((visibility("default")))
// stripped by the linker.
__attribute__((used))
const char *__asan_default_options() {
#if defined(OS_MACOSX)
char*** argvp = _NSGetArgv();
int* argcp = _NSGetArgc();
if (!argvp || !argcp) return kAsanDefaultOptions;
char** argv = *argvp;
int argc = *argcp;
for (int i = 0; i < argc; ++i) {
if (strcmp(argv[i], kNaClFlag) == 0) {
return kNaClDefaultOptions;
}
}
#endif
return kAsanDefaultOptions;
}
#endif // OS_LINUX || OS_MACOSX
......
......@@ -45,6 +45,15 @@
'ldflags': [
'-Wl,-u_sanitizer_options_link_helper',
],
'target_conditions': [
['_type=="executable"', {
'xcode_settings': {
'OTHER_LDFLAGS': [
'-Wl,-u,__sanitizer_options_link_helper',
],
},
}],
],
},
},
],
......
......@@ -5,45 +5,8 @@
// The entry point for all Mac Chromium processes, including the outer app
// bundle (browser) and helper app (renderer, plugin, and friends).
#if defined(ADDRESS_SANITIZER)
#include <crt_externs.h> // for _NSGetArgc, _NSGetArgv
#include <string.h>
#endif // ADDRESS_SANITIZER
#include <stdlib.h>
#if defined(ADDRESS_SANITIZER)
// NaCl requires its own SEGV handler, so we need to add handle_segv=0 to
// ASAN_OPTIONS. This is done by injecting __asan_default_options into the
// executable.
// Because there's no distinct NaCl executable on OSX, we have to look at the
// command line arguments to understand whether the process is a NaCl loader.
static const char kNaClDefaultOptions[] = "handle_segv=0";
static const char kNaClFlag[] = "--type=nacl-loader";
extern "C"
// __asan_default_options() is called at ASan initialization, so it must
// not be instrumented with ASan -- thus the "no_sanitize_address" attribute.
__attribute__((no_sanitize_address))
// The function isn't referenced from the executable itself. Make sure it isn't
// stripped by the linker.
__attribute__((used))
__attribute__((visibility("default")))
const char* __asan_default_options() {
char*** argvp = _NSGetArgv();
int* argcp = _NSGetArgc();
if (!argvp || !argcp) return NULL;
char** argv = *argvp;
int argc = *argcp;
for (int i = 0; i < argc; ++i) {
if (strcmp(argv[i], kNaClFlag) == 0) {
return kNaClDefaultOptions;
}
}
return NULL;
}
#endif // ADDRESS_SANITIZER
extern "C" {
int ChromeMain(int argc, char** argv);
} // extern "C"
......
......@@ -46,6 +46,9 @@ ___gcov_flush
___gcov_merge_add
___gcov_fork
# Provided by build/sanitizers/sanitizer_options.cc in ASan builds.
___asan_default_options
# Written in asm as a .globl. (Is that necessary?)
_NaClSwitch
_NaClSyscallSeg
......
......@@ -34,6 +34,17 @@
'../resources/ui_resources.gyp:ui_test_pak',
],
'includes': [ 'ui_base_tests_bundle.gypi' ],
# ui_base_tests_bundle doesn't actually contain a shared library and
# therefore should not depend on sanitizer_options or any other
# libraries. Adding such a dependency will result in creating a
# broken shared library within the bundle.
'conditions': [
['use_sanitizer_options==1', {
'dependencies!': [
'../../build/sanitizers/sanitizers.gyp:sanitizer_options',
],
}],
],
},
],
}],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment