Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compiler flags suggested by security review (#4368) #177

Merged
merged 4 commits into from
Oct 18, 2018
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions build/config/compiler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ config("compiler") {
cflags_objcc += common_flags

# Stack protection.
if (is_mac) {
if (is_mac || is_android) {
cflags += [ "-fstack-protector-all" ]
} else if (is_linux) {
cflags += [
Expand Down Expand Up @@ -338,12 +338,10 @@ config("compiler") {
# ---------------------------------
if (is_linux || is_android) {
cflags += [
"-fPIC",
"-pipe", # Use pipes for communicating between sub-processes. Faster.
]

ldflags += [
"-fPIC",
"-Wl,-z,noexecstack",
"-Wl,-z,now",
"-Wl,-z,relro",
Expand All @@ -356,8 +354,14 @@ config("compiler") {
# Linux-specific compiler flags setup.
# ------------------------------------
if (is_linux) {
cflags += [ "-pthread" ]
ldflags += [ "-pthread" ]
cflags += [
"-pthread",
"-fPIC"
]
ldflags += [
"-pthread",
"-fPIC"
]

if (current_cpu == "arm64") {
cflags += [ "--target=aarch64-linux-gnu" ]
Expand Down Expand Up @@ -391,14 +395,29 @@ config("compiler") {
cflags_cc += cc_std
cflags_objcc += cc_std

# iOS-specific flags setup.
# -----------------------------
if (is_ios) {
cflags += [
"-fPIE"
]
ldflags += [
"-pie"
]
}

# Android-specific flags setup.
# -----------------------------
if (is_android) {
cflags += [
"-fPIE",
"-ffunction-sections",
"-funwind-tables",
"-fno-short-enums",
"-nostdinc++"
"-nostdinc++",
"-Wa,--noexecstack",
"-Wformat",
"-Wformat-security"
]
if (!is_clang) {
# Clang doesn't support these flags.
Expand All @@ -425,9 +444,11 @@ config("compiler") {
}

ldflags += [
"-pie",
"-Wl,--no-undefined",
"-Wl,--exclude-libs,ALL",
"-fuse-ld=lld",
"-Wl,-z,relro,-z,now",
"-fuse-ld=lld"
]
if (current_cpu == "arm") {
ldflags += [
Expand Down Expand Up @@ -653,7 +674,7 @@ config("chromium_code") {
"__STDC_FORMAT_MACROS",
]

if (!using_sanitizer && (!is_linux || !is_clang)) {
if (is_ios || is_android || (!using_sanitizer && (!is_linux || !is_clang))) {
# _FORTIFY_SOURCE isn't really supported by Clang now, see
# http://llvm.org/bugs/show_bug.cgi?id=16821.
# It seems to work fine with Ubuntu 12 headers though, so use it in
Expand Down