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