1*8975f5c5SAndroid Build Coastguard Worker# Copyright 2014 The Chromium Authors 2*8975f5c5SAndroid Build Coastguard Worker# Use of this source code is governed by a BSD-style license that can be 3*8975f5c5SAndroid Build Coastguard Worker# found in the LICENSE file. 4*8975f5c5SAndroid Build Coastguard Worker 5*8975f5c5SAndroid Build Coastguard Workerimport("//build/config/c++/c++.gni") 6*8975f5c5SAndroid Build Coastguard Workerimport("//build/config/compiler/compiler.gni") 7*8975f5c5SAndroid Build Coastguard Workerimport("//build/config/sanitizers/sanitizers.gni") 8*8975f5c5SAndroid Build Coastguard Workerimport("//build/config/sysroot.gni") 9*8975f5c5SAndroid Build Coastguard Workerimport("//build/toolchain/toolchain.gni") 10*8975f5c5SAndroid Build Coastguard Worker 11*8975f5c5SAndroid Build Coastguard Workerdeclare_args() { 12*8975f5c5SAndroid Build Coastguard Worker # When non empty, overrides the target rpath value. This allows a user to 13*8975f5c5SAndroid Build Coastguard Worker # make a Chromium build where binaries and shared libraries are meant to be 14*8975f5c5SAndroid Build Coastguard Worker # installed into separate directories, like /usr/bin/chromium and 15*8975f5c5SAndroid Build Coastguard Worker # /usr/lib/chromium for instance. It is useful when a build system that 16*8975f5c5SAndroid Build Coastguard Worker # generates a whole target root filesystem (like Yocto) is used on top of gn, 17*8975f5c5SAndroid Build Coastguard Worker # especially when cross-compiling. 18*8975f5c5SAndroid Build Coastguard Worker # Note: this gn arg is similar to gyp target_rpath generator flag. 19*8975f5c5SAndroid Build Coastguard Worker gcc_target_rpath = "" 20*8975f5c5SAndroid Build Coastguard Worker ldso_path = "" 21*8975f5c5SAndroid Build Coastguard Worker} 22*8975f5c5SAndroid Build Coastguard Worker 23*8975f5c5SAndroid Build Coastguard Worker# This config causes functions not to be automatically exported from shared 24*8975f5c5SAndroid Build Coastguard Worker# libraries. By default, all symbols are exported but this means there are 25*8975f5c5SAndroid Build Coastguard Worker# lots of exports that slow everything down. In general we explicitly mark 26*8975f5c5SAndroid Build Coastguard Worker# which functions we want to export from components. 27*8975f5c5SAndroid Build Coastguard Worker# 28*8975f5c5SAndroid Build Coastguard Worker# Some third_party code assumes all functions are exported so this is separated 29*8975f5c5SAndroid Build Coastguard Worker# into its own config so such libraries can remove this config to make symbols 30*8975f5c5SAndroid Build Coastguard Worker# public again. 31*8975f5c5SAndroid Build Coastguard Worker# 32*8975f5c5SAndroid Build Coastguard Worker# See http://gcc.gnu.org/wiki/Visibility 33*8975f5c5SAndroid Build Coastguard Workerconfig("symbol_visibility_hidden") { 34*8975f5c5SAndroid Build Coastguard Worker cflags = [ "-fvisibility=hidden" ] 35*8975f5c5SAndroid Build Coastguard Worker rustflags = [ "-Zdefault-visibility=hidden" ] 36*8975f5c5SAndroid Build Coastguard Worker 37*8975f5c5SAndroid Build Coastguard Worker # Visibility attribute is not supported on AIX. 38*8975f5c5SAndroid Build Coastguard Worker if (current_os != "aix") { 39*8975f5c5SAndroid Build Coastguard Worker cflags_cc = [ "-fvisibility-inlines-hidden" ] 40*8975f5c5SAndroid Build Coastguard Worker cflags_objcc = cflags_cc 41*8975f5c5SAndroid Build Coastguard Worker } 42*8975f5c5SAndroid Build Coastguard Worker} 43*8975f5c5SAndroid Build Coastguard Worker 44*8975f5c5SAndroid Build Coastguard Worker# This config is usually set when :symbol_visibility_hidden is removed. 45*8975f5c5SAndroid Build Coastguard Worker# It's often a good idea to set visibility explicitly, as there're flags 46*8975f5c5SAndroid Build Coastguard Worker# which would error out otherwise (e.g. -fsanitize=cfi-unrelated-cast) 47*8975f5c5SAndroid Build Coastguard Workerconfig("symbol_visibility_default") { 48*8975f5c5SAndroid Build Coastguard Worker cflags = [ "-fvisibility=default" ] 49*8975f5c5SAndroid Build Coastguard Worker} 50*8975f5c5SAndroid Build Coastguard Worker 51*8975f5c5SAndroid Build Coastguard Worker# The rpath is the dynamic library search path. Setting this config on a link 52*8975f5c5SAndroid Build Coastguard Worker# step will put the directory where the build generates shared libraries into 53*8975f5c5SAndroid Build Coastguard Worker# the rpath. 54*8975f5c5SAndroid Build Coastguard Worker# 55*8975f5c5SAndroid Build Coastguard Worker# This is required for component builds since the build generates many shared 56*8975f5c5SAndroid Build Coastguard Worker# libraries in the build directory that we expect to be automatically loaded. 57*8975f5c5SAndroid Build Coastguard Worker# It will be automatically applied in this case by :executable_config. 58*8975f5c5SAndroid Build Coastguard Worker# 59*8975f5c5SAndroid Build Coastguard Worker# In non-component builds, certain test binaries may expect to load dynamic 60*8975f5c5SAndroid Build Coastguard Worker# libraries from the current directory. As long as these aren't distributed, 61*8975f5c5SAndroid Build Coastguard Worker# this is OK. For these cases use something like this: 62*8975f5c5SAndroid Build Coastguard Worker# 63*8975f5c5SAndroid Build Coastguard Worker# if ((is_linux || is_chromeos) && !is_component_build) { 64*8975f5c5SAndroid Build Coastguard Worker# configs += [ "//build/config/gcc:rpath_for_built_shared_libraries" ] 65*8975f5c5SAndroid Build Coastguard Worker# } 66*8975f5c5SAndroid Build Coastguard Workerconfig("rpath_for_built_shared_libraries") { 67*8975f5c5SAndroid Build Coastguard Worker if (!is_android && current_os != "aix" && !is_castos) { 68*8975f5c5SAndroid Build Coastguard Worker # Note: Android, Aix don't support rpath. Chromecast has its own logic for 69*8975f5c5SAndroid Build Coastguard Worker # setting the rpath in //build/config/chromecast. 70*8975f5c5SAndroid Build Coastguard Worker if (current_toolchain != default_toolchain || gcc_target_rpath == "") { 71*8975f5c5SAndroid Build Coastguard Worker ldflags = [ 72*8975f5c5SAndroid Build Coastguard Worker # Want to pass "\$". GN will re-escape as required for ninja. 73*8975f5c5SAndroid Build Coastguard Worker "-Wl,-rpath=\$ORIGIN", 74*8975f5c5SAndroid Build Coastguard Worker ] 75*8975f5c5SAndroid Build Coastguard Worker } else { 76*8975f5c5SAndroid Build Coastguard Worker ldflags = [ "-Wl,-rpath=${gcc_target_rpath}" ] 77*8975f5c5SAndroid Build Coastguard Worker } 78*8975f5c5SAndroid Build Coastguard Worker if (current_toolchain == default_toolchain && ldso_path != "") { 79*8975f5c5SAndroid Build Coastguard Worker ldflags += [ "-Wl,--dynamic-linker=${ldso_path}" ] 80*8975f5c5SAndroid Build Coastguard Worker } 81*8975f5c5SAndroid Build Coastguard Worker } 82*8975f5c5SAndroid Build Coastguard Worker} 83*8975f5c5SAndroid Build Coastguard Worker 84*8975f5c5SAndroid Build Coastguard Workerif (is_component_build && !is_android) { 85*8975f5c5SAndroid Build Coastguard Worker # See the rpath_for... config above for why this is necessary for component 86*8975f5c5SAndroid Build Coastguard Worker # builds. 87*8975f5c5SAndroid Build Coastguard Worker executable_and_shared_library_configs_ = 88*8975f5c5SAndroid Build Coastguard Worker [ ":rpath_for_built_shared_libraries" ] 89*8975f5c5SAndroid Build Coastguard Worker} else { 90*8975f5c5SAndroid Build Coastguard Worker executable_and_shared_library_configs_ = [] 91*8975f5c5SAndroid Build Coastguard Worker} 92*8975f5c5SAndroid Build Coastguard Worker 93*8975f5c5SAndroid Build Coastguard Worker# Settings for executables. 94*8975f5c5SAndroid Build Coastguard Workerconfig("executable_config") { 95*8975f5c5SAndroid Build Coastguard Worker configs = executable_and_shared_library_configs_ 96*8975f5c5SAndroid Build Coastguard Worker ldflags = [ "-pie" ] 97*8975f5c5SAndroid Build Coastguard Worker if (is_android) { 98*8975f5c5SAndroid Build Coastguard Worker ldflags += [ 99*8975f5c5SAndroid Build Coastguard Worker "-Bdynamic", 100*8975f5c5SAndroid Build Coastguard Worker "-Wl,-z,nocopyreloc", 101*8975f5c5SAndroid Build Coastguard Worker ] 102*8975f5c5SAndroid Build Coastguard Worker } 103*8975f5c5SAndroid Build Coastguard Worker 104*8975f5c5SAndroid Build Coastguard Worker if (!is_android && current_os != "aix") { 105*8975f5c5SAndroid Build Coastguard Worker ldflags += [ 106*8975f5c5SAndroid Build Coastguard Worker # TODO(GYP): Do we need a check on the binutils version here? 107*8975f5c5SAndroid Build Coastguard Worker # 108*8975f5c5SAndroid Build Coastguard Worker # Newer binutils don't set DT_RPATH unless you disable "new" dtags 109*8975f5c5SAndroid Build Coastguard Worker # and the new DT_RUNPATH doesn't work without --no-as-needed flag. 110*8975f5c5SAndroid Build Coastguard Worker "-Wl,--disable-new-dtags", 111*8975f5c5SAndroid Build Coastguard Worker ] 112*8975f5c5SAndroid Build Coastguard Worker } 113*8975f5c5SAndroid Build Coastguard Worker} 114*8975f5c5SAndroid Build Coastguard Worker 115*8975f5c5SAndroid Build Coastguard Worker# Settings for shared libraries. 116*8975f5c5SAndroid Build Coastguard Workerconfig("shared_library_config") { 117*8975f5c5SAndroid Build Coastguard Worker configs = executable_and_shared_library_configs_ 118*8975f5c5SAndroid Build Coastguard Worker} 119