xref: /aosp_15_r20/external/angle/build/config/gcc/BUILD.gn (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1# Copyright 2014 The Chromium Authors
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  rustflags = [ "-Zdefault-visibility=hidden" ]
36
37  # Visibility attribute is not supported on AIX.
38  if (current_os != "aix") {
39    cflags_cc = [ "-fvisibility-inlines-hidden" ]
40    cflags_objcc = cflags_cc
41  }
42}
43
44# This config is usually set when :symbol_visibility_hidden is removed.
45# It's often a good idea to set visibility explicitly, as there're flags
46# which would error out otherwise (e.g. -fsanitize=cfi-unrelated-cast)
47config("symbol_visibility_default") {
48  cflags = [ "-fvisibility=default" ]
49}
50
51# The rpath is the dynamic library search path. Setting this config on a link
52# step will put the directory where the build generates shared libraries into
53# the rpath.
54#
55# This is required for component builds since the build generates many shared
56# libraries in the build directory that we expect to be automatically loaded.
57# It will be automatically applied in this case by :executable_config.
58#
59# In non-component builds, certain test binaries may expect to load dynamic
60# libraries from the current directory. As long as these aren't distributed,
61# this is OK. For these cases use something like this:
62#
63#  if ((is_linux || is_chromeos) && !is_component_build) {
64#    configs += [ "//build/config/gcc:rpath_for_built_shared_libraries" ]
65#  }
66config("rpath_for_built_shared_libraries") {
67  if (!is_android && current_os != "aix" && !is_castos) {
68    # Note: Android, Aix don't support rpath. Chromecast has its own logic for
69    # setting the rpath in //build/config/chromecast.
70    if (current_toolchain != default_toolchain || gcc_target_rpath == "") {
71      ldflags = [
72        # Want to pass "\$". GN will re-escape as required for ninja.
73        "-Wl,-rpath=\$ORIGIN",
74      ]
75    } else {
76      ldflags = [ "-Wl,-rpath=${gcc_target_rpath}" ]
77    }
78    if (current_toolchain == default_toolchain && ldso_path != "") {
79      ldflags += [ "-Wl,--dynamic-linker=${ldso_path}" ]
80    }
81  }
82}
83
84if (is_component_build && !is_android) {
85  # See the rpath_for... config above for why this is necessary for component
86  # builds.
87  executable_and_shared_library_configs_ =
88      [ ":rpath_for_built_shared_libraries" ]
89} else {
90  executable_and_shared_library_configs_ = []
91}
92
93# Settings for executables.
94config("executable_config") {
95  configs = executable_and_shared_library_configs_
96  ldflags = [ "-pie" ]
97  if (is_android) {
98    ldflags += [
99      "-Bdynamic",
100      "-Wl,-z,nocopyreloc",
101    ]
102  }
103
104  if (!is_android && current_os != "aix") {
105    ldflags += [
106      # TODO(GYP): Do we need a check on the binutils version here?
107      #
108      # Newer binutils don't set DT_RPATH unless you disable "new" dtags
109      # and the new DT_RUNPATH doesn't work without --no-as-needed flag.
110      "-Wl,--disable-new-dtags",
111    ]
112  }
113}
114
115# Settings for shared libraries.
116config("shared_library_config") {
117  configs = executable_and_shared_library_configs_
118}
119