# Copyright (c) 2013 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import("//build/config/android/config.gni") import("//build/config/sysroot.gni") if (cpu_arch == "arm") { import("//build/config/arm.gni") } # compiler --------------------------------------------------------------------- # # Base compiler configuration. # # See also "runtime_library" below for related stuff and a discusison about # where stuff should go. Put warning related stuff in the "warnings" config. config("compiler") { cflags = [] cflags_c = [] cflags_cc = [] ldflags = [] defines = [] include_dirs = [] include_dirs += [ "//", root_gen_dir ] # In general, Windows is totally different, but all the other builds share # some common GCC configuration. This section sets up Windows and the common # GCC flags, and then we handle the other non-Windows platforms specifically # below. if (is_win) { # Windows compiler flags setup. # ----------------------------- cflags += [ "/Gy", # Enable function-level linking. "/GS", # Enable buffer security checking. "/EHsc", # Assume C functions can't throw exceptions and don't catch # structured exceptions (only C++ ones). ] } else { # Common GCC compiler flags setup. # -------------------------------- cflags += [ "-fno-strict-aliasing", # See http://crbug.com/32204 "-fvisibility=hidden", ] cflags_cc += [ "-fno-exceptions", "-fno-threadsafe-statics", "-fvisibility-inlines-hidden", ] # Stack protection. if (is_mac) { cflags += [ "-fstack-protector-all" ] } else if (is_linux) { cflags += [ "-fstack-protector", "--param=ssp-buffer-size=4" ] } } # Mac-specific compiler flags setup. # ---------------------------------- if (is_mac) { # These flags are shared between the C compiler and linker. common_mac_flags = [ "-isysroot", sysroot, "-mmacosx-version-min=10.6", ] # CPU architecture. if (cpu_arch == "x64") { common_mac_flags += [ "-arch x86_64" ] } else if (cpu_arch == "x86") { common_mac_flags += [ "-arch i386" ] } cflags += common_mac_flags + [ # Without this, the constructors and destructors of a C++ object inside # an Objective C struct won't be called, which is very bad. "-fobjc-call-cxx-cdtors", ] cflags_c += [ "-std=c99" ] cflags_cc += [ "-std=gnu++11" ] ldflags += common_mac_flags + [ "-L.", # TODO(brettW) I don't understand these options. "-Wl,-rpath,@loader_path/.", "-Wl,-rpath,@loader_path/../../..", ] } else if (is_posix) { # Non-Mac Posix compiler flags setup. # ----------------------------------- # CPU architecture. We may or may not be doing a cross compile now, so for # simplicity we always explicitly set the architecture. if (cpu_arch == "x64") { cflags += [ "-m64" ] ldflags += [ "-m64" ] } else if (cpu_arch == "x86") { cflags += [ "-m32" ] ldflags += [ "-m32" ] } else if (cpu_arch == "arm") { # Don't set the compiler flags for the WebView build. These will come # from the Android build system. if (!is_android_webview_build) { cflags += [ "-march=$arm_arch", "-mfpu=$arm_fpu", "-mfloat-abi=$arm_float_abi", ] if (arm_tune != "") { cflags += [ "-mtune=$arm_tune" ] } if (arm_use_thumb) { cflags += [ "-mthumb" ] if (is_android && !is_clang) { # Clang doesn't support this option. cflags += [ "-mthumb-interwork" ] } } } } defines += [ "_FILE_OFFSET_BITS=64" ] # Omit unwind support in official builds to save space. We can use breakpad # for these builds. if (is_chrome_branded && is_official_build) { cflags += [ "-fno-unwind-tables", "-fno-asynchronous-unwind-tables", ] } else { cflags += [ "-funwind-tables" ] } } # Linux-specific compiler flags setup. # ------------------------------------ if (is_linux) { cflags += [ "-fPIC", "-pipe", # Use pipes for communicating between sub-processes. Faster. ] if (!is_android) { cflags += [ "-pthread" ] } if (cpu_arch == "x64") { # Use gold for linking on 64-bit Linux only (on 32-bit it runs out of # address space, and it doesn't support cross-compiling). gold_path = rebase_path("//third_party/gold", ".", root_build_dir) ldflags += [ "-B$gold_path", # There seems to be a conflict of --icf and -pie in gold which can # generate crashy binaries. As a security measure, -pie takes # precendence for now. # TODO(brettw) common.gypi has this only for target toolset. #"-Wl,--icf=safe", "-Wl,--icf=none", # Experimentation found that using four linking threads # saved ~20% of link time. # https://groups.google.com/a/chromium.org/group/chromium-dev/browse_thread/thread/281527606915bb36 # Only apply this to the target linker, since the host # linker might not be gold, but isn't used much anyway. "-Wl,--threads", "-Wl,--thread-count=4", ] } if (sysroot != "") { cflags += [ "--sysroot=" + sysroot ] ldflags += [ "--sysroot=" + sysroot ] # Need to get some linker flags out of the sysroot. ldflags += [ exec_script("../linux/sysroot_ld_path.py", [rebase_path("../../linux/sysroot_ld_path.sh", ".", root_build_dir), sysroot], "value") ] } ldflags += [ "-fPIC", "-pthread", "-Wl,-z,noexecstack", "-Wl,-z,now", "-Wl,-z,relro", ] } # Clang-specific compiler flags setup. # ------------------------------------ if (is_clang) { cflags += [ "-fcolor-diagnostics", ] cflags_cc += [ "-std=gnu++11", ] } # Android-specific flags setup. # ----------------------------- if (is_android) { cflags += [ "-ffunction-sections", "-funwind-tables", "-fno-short-enums", ] if (!is_clang) { # Clang doesn't support this one. cflags += [ "-finline-limit=64" ] } if (is_android_webview_build) { # Android predefines this as 1; undefine it here so Chromium can redefine # it later to be 2 for chromium code and unset for third party code. This # works because cflags are added before defines. # TODO(brettw) the above comment seems incorrect. We specify defines # before cflags on our compiler command lines. cflags += [ "-U_FORTIFY_SOURCE" ] } if (is_asan) { # Android build relies on -Wl,--gc-sections removing unreachable code. # ASan instrumentation for globals inhibits this and results in a library # with unresolvable relocations. # TODO(eugenis): find a way to reenable this. cflags += [ "-mllvm -asan-globals=0" ] } defines += [ "ANDROID" ] if (!is_android_webview_build) { # The NDK has these things, but doesn't define the constants # to say that it does. Define them here instead. defines += [ "HAVE_SYS_UIO_H" ] } ldflags += [ "-Wl,--no-undefined", # Don't export symbols from statically linked libraries. "-Wl,--exclude-libs=ALL", ] if (cpu_arch == "arm") { ldflags += [ # Enable identical code folding to reduce size. "-Wl,--icf=safe", ] } if (is_clang) { if (cpu_arch == "arm") { cflags += [ "-target arm-linux-androideabi", "-mllvm -arm-enable-ehabi", ] ldflags += [ "-target arm-linux-androideabi" ] } else if (cpu_arch == "x86") { cflags += [ "-target x86-linux-androideabi" ] ldflags += [ "-target x86-linux-androideabi" ] } } } } # runtime_library ------------------------------------------------------------- # # Sets the runtime library and associated options. # # How do you determine what should go in here vs. "compiler" above? Consider if # a target might choose to use a different runtime library (ignore for a moment # if this is possible or reasonable on your system). If such a target would want # to change or remove your option, put it in the runtime_library config. If a # target wants the option regardless, put it in the compiler config. config("runtime_library") { cflags = [] defines = [] ldflags = [] lib_dirs = [] libs = [] if (is_component_build) { # Component mode: dynamic CRT. defines += [ "COMPONENT_BUILD" ] if (is_win) { # Since the library is shared, it requires exceptions or will give errors # about things not matching, so keep exceptions on. if (is_debug) { cflags += [ "/MDd" ] } else { cflags += [ "/MD" ] } } } else { # Static CRT. if (is_win) { # We don't use exceptions, and when we link statically we can just get # rid of them entirely. defines += [ "_HAS_EXCEPTIONS=0" ] if (is_debug) { cflags += [ "/MTd" ] } else { cflags += [ "/MT" ] } } } if (is_win) { defines += [ "__STD_C", "__STDC_CONSTANT_MACROS", "__STDC_FORMAT_MACROS", "_CRT_RAND_S", "_CRT_SECURE_NO_DEPRECATE", "_SCL_SECURE_NO_DEPRECATE", "_UNICODE", "UNICODE", ] } # Stlport setup. Android uses a different (smaller) version of the STL. if (is_android) { if (is_clang) { # Work around incompatibilities between bionic and clang headers. defines += [ "__compiler_offsetof=__builtin_offsetof", "nan=__builtin_nan", ] } defines += [ "USE_STLPORT=1", "_STLP_USE_PTR_SPECIALIZATIONS=1", "__GNU_SOURCE=1", # Necessary for clone(). ] ldflags += [ "-nostdlib", ] libs += [ # TODO(brettw) write a version of this, hopefully we can express this # without forking out to GCC just to get the library name. The android # toolchain directory should probably be extracted into a .gni file that # this file and the android toolchain .gn file can share. # # Manually link the libgcc.a that the cross compiler uses. # '