• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/sanitizers/sanitizers.gni")
6import("//build/toolchain/toolchain.gni")
7
8# This config causes functions not to be automatically exported from shared
9# libraries. By default, all symbols are exported but this means there are
10# lots of exports that slow everything down. In general we explicitly mark
11# which functiosn we want to export from components.
12#
13# Some third_party code assumes all functions are exported so this is separated
14# into its own config so such libraries can remove this config to make symbols
15# public again.
16#
17# See http://gcc.gnu.org/wiki/Visibility
18config("symbol_visibility_hidden") {
19  # Note that -fvisibility-inlines-hidden is set globally in the compiler
20  # config since that can almost always be applied.
21  cflags = [ "-fvisibility=hidden" ]
22}
23
24# This config is usually set when :symbol_visibility_hidden is removed.
25# It's often a good idea to set visibility explicitly, as there're flags
26# which would error out otherwise (e.g. -fsanitize=cfi-unrelated-cast)
27config("symbol_visibility_default") {
28  cflags = [ "-fvisibility=default" ]
29}
30
31# The rpath is the dynamic library search path. Setting this config on a link
32# step will put the directory where the build generates shared libraries into
33# the rpath.
34#
35# It's important that this *not* be used for release builds we push out.
36# Chrome uses some setuid binaries, and hard links preserve setuid bits. An
37# unprivileged user could gain root privileges by hardlinking a setuid
38# executable and then adding in whatever binaries they want to run into the lib
39# directory.
40#
41# Example bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=520126
42#
43# This is required for component builds since the build generates many shared
44# libraries in the build directory that we expect to be automatically loaded.
45# It will be automatically applied in this case by :executable_ldconfig.
46#
47# In non-component builds, certain test binaries may expect to load dynamic
48# libraries from the current directory. As long as these aren't distributed,
49# this is OK. For these cases use something like this:
50#
51#  if (is_linux && !is_component_build) {
52#    configs += [ "//build/config/gcc:rpath_for_built_shared_libraries" ]
53#  }
54config("rpath_for_built_shared_libraries") {
55  if (!is_android) {
56    # Note: Android doesn't support rpath.
57    if (shlib_subdir != ".") {
58      rpath_link = "${shlib_subdir}/"
59    } else {
60      rpath_link = "."
61    }
62    ldflags = [
63      # Want to pass "\$". GN will re-escape as required for ninja.
64      "-Wl,-rpath=\$ORIGIN/${rpath_link}",
65      "-Wl,-rpath-link=${rpath_link}",
66    ]
67  }
68}
69
70# Settings for executables.
71config("executable_ldconfig") {
72  if (is_android) {
73    ldflags = [
74      "-Bdynamic",
75      "-Wl,-z,nocopyreloc",
76    ]
77  } else {
78    # See the rpath_for... config above for why this is necessary for component
79    # builds. Sanitizers use a custom libc++ where this is also necessary.
80    if (is_component_build || using_sanitizer) {
81      configs = [ ":rpath_for_built_shared_libraries" ]
82    }
83
84    # Find the path containing shared libraries for this toolchain
85    # relative to the build directory. ${root_out_dir} will be a
86    # subdirectory of ${root_build_dir} when cross compiling.
87    rebased_out_dir = rebase_path(root_out_dir, root_build_dir)
88    if (shlib_subdir != ".") {
89      rpath_link = "${rebased_out_dir}/${shlib_subdir}"
90    } else {
91      rpath_link = rebased_out_dir
92    }
93
94    ldflags = [
95      "-Wl,-rpath-link=${rpath_link}",
96
97      # TODO(GYP): Do we need a check on the binutils version here?
98      #
99      # Newer binutils don't set DT_RPATH unless you disable "new" dtags
100      # and the new DT_RUNPATH doesn't work without --no-as-needed flag.
101      "-Wl,--disable-new-dtags",
102    ]
103    if (current_cpu == "mipsel") {
104      ldflags += [ "-pie" ]
105    }
106  }
107}
108
109config("no_exceptions") {
110  cflags_cc = [ "-fno-exceptions" ]
111  cflags_objcc = cflags_cc
112}
113