# Copyright 2014 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/compiler/compiler.gni") import("//build/config/sanitizers/sanitizers.gni") import("//build/config/sysroot.gni") import("//build/toolchain/toolchain.gni") declare_args() { # When non empty, overrides the target rpath value. This allows a user to # make a Chromium build where binaries and shared libraries are meant to be # installed into separate directories, like /usr/bin/chromium and # /usr/lib/chromium for instance. It is useful when a build system that # generates a whole target root filesystem (like Yocto) is used on top of gn, # especially when cross-compiling. # Note: this gn arg is similar to gyp target_rpath generator flag. gcc_target_rpath = "" } # This config causes functions not to be automatically exported from shared # libraries. By default, all symbols are exported but this means there are # lots of exports that slow everything down. In general we explicitly mark # which functiosn we want to export from components. # # Some third_party code assumes all functions are exported so this is separated # into its own config so such libraries can remove this config to make symbols # public again. # # See http://gcc.gnu.org/wiki/Visibility config("symbol_visibility_hidden") { cflags = [ "-fvisibility=hidden" ] # Visibility attribute is not supported on AIX. if (current_os != "aix") { cflags_cc = [ "-fvisibility-inlines-hidden" ] cflags_objcc = cflags_cc } } # This config is usually set when :symbol_visibility_hidden is removed. # It's often a good idea to set visibility explicitly, as there're flags # which would error out otherwise (e.g. -fsanitize=cfi-unrelated-cast) config("symbol_visibility_default") { cflags = [ "-fvisibility=default" ] } # The rpath is the dynamic library search path. Setting this config on a link # step will put the directory where the build generates shared libraries into # the rpath. # # It's important that this *not* be used for release builds we push out. # Chrome uses some setuid binaries, and hard links preserve setuid bits. An # unprivileged user could gain root privileges by hardlinking a setuid # executable and then adding in whatever binaries they want to run into the lib # directory. # # Example bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=520126 # # This is required for component builds since the build generates many shared # libraries in the build directory that we expect to be automatically loaded. # It will be automatically applied in this case by :executable_ldconfig. # # In non-component builds, certain test binaries may expect to load dynamic # libraries from the current directory. As long as these aren't distributed, # this is OK. For these cases use something like this: # # if (is_linux && !is_component_build) { # configs += [ "//build/config/gcc:rpath_for_built_shared_libraries" ] # } config("rpath_for_built_shared_libraries") { if (!is_android) { # Note: Android doesn't support rpath. if (shlib_subdir != ".") { rpath_link = "${shlib_subdir}/" } else { rpath_link = "." } if (current_toolchain != default_toolchain || gcc_target_rpath == "") { ldflags = [ # Want to pass "\$". GN will re-escape as required for ninja. "-Wl,-rpath=\$ORIGIN/${rpath_link}", "-Wl,-rpath-link=${rpath_link}", ] } else { ldflags = [ "-Wl,-rpath=${gcc_target_rpath}", "-Wl,-rpath-link=${rpath_link}", ] } } } # Settings for executables. config("executable_ldconfig") { # WARNING! //sandbox/linux:chrome_sandbox will not pick up this # config, because it is a setuid binary that needs special flags. # If you add things to this config, make sure you check to see # if they should be added to that target as well. ldflags = [] if (is_android) { ldflags += [ "-Bdynamic", "-Wl,-z,nocopyreloc", ] } else { # See the rpath_for... config above for why this is necessary for component # builds. Sanitizers use a custom libc++ where this is also necessary. if (is_component_build || using_sanitizer) { configs = [ ":rpath_for_built_shared_libraries" ] } if (current_cpu == "mipsel" || current_cpu == "mips64el") { ldflags += [ "-pie" ] } } if ((!is_android || !use_gold) && current_os != "aix") { # Find the path containing shared libraries for this toolchain # relative to the build directory. ${root_out_dir} will be a # subdirectory of ${root_build_dir} when cross compiling. _rpath_link = rebase_path(root_out_dir, root_build_dir) if (shlib_subdir != ".") { _rpath_link += "/$shlib_subdir" } if (is_android) { _rebased_sysroot = rebase_path(sysroot, root_build_dir) _rpath_link += ":$_rebased_sysroot/usr/lib" } ldflags += [ "-Wl,-rpath-link=$_rpath_link", # TODO(GYP): Do we need a check on the binutils version here? # # Newer binutils don't set DT_RPATH unless you disable "new" dtags # and the new DT_RUNPATH doesn't work without --no-as-needed flag. "-Wl,--disable-new-dtags", ] } }