summaryrefslogtreecommitdiffstats
path: root/build/toolchain
diff options
context:
space:
mode:
authoragrieve <agrieve@chromium.org>2015-08-10 14:17:56 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-10 21:18:34 +0000
commitc3cd5e6fe977af4a3c8b20ccb332896b2c888354 (patch)
tree4dccc3417f4063399d257b90cf48b1d892e100ec /build/toolchain
parenta5fa5e73f767269040ba6ebf29fd42fdfe62d8ee (diff)
downloadchromium_src-c3cd5e6fe977af4a3c8b20ccb332896b2c888354.zip
chromium_src-c3cd5e6fe977af4a3c8b20ccb332896b2c888354.tar.gz
chromium_src-c3cd5e6fe977af4a3c8b20ccb332896b2c888354.tar.bz2
GN: Use lib.unstripped rather than lib.stripped. Add a toolchain.gni
toolchain.gni introduces: root_shlib_dir, shlib_prefix, and shlib_extension The original goal of this change was to put shlibs under lib/ for Linux / Android, since that's where GYP puts them. However, the lack of support for loadable_module (or more specifically - per target output directory) in GN makes this infeasible at the moment. This change also mitigates a subtle bug where on Android the unstripped .so is used mistakenly instead of the lib.stripped/ version. It also fixes shlib's link_output being set to the unstripped .so rather than the stripped .so (on Android). BUG=509771 Review URL: https://codereview.chromium.org/1236503002 Cr-Commit-Position: refs/heads/master@{#342697}
Diffstat (limited to 'build/toolchain')
-rw-r--r--build/toolchain/android/BUILD.gn24
-rw-r--r--build/toolchain/gcc_toolchain.gni53
-rw-r--r--build/toolchain/toolchain.gni40
-rw-r--r--build/toolchain/win/BUILD.gn3
4 files changed, 81 insertions, 39 deletions
diff --git a/build/toolchain/android/BUILD.gn b/build/toolchain/android/BUILD.gn
index 867fa48..ed7c407 100644
--- a/build/toolchain/android/BUILD.gn
+++ b/build/toolchain/android/BUILD.gn
@@ -64,32 +64,10 @@ template("android_gcc_toolchain") {
ld = cxx
readelf = compiler_prefix + tool_prefix + "readelf"
nm = compiler_prefix + tool_prefix + "nm"
+ strip = "${tool_prefix}strip"
toolchain_os = "android"
toolchain_cpu = invoker.toolchain_cpu
-
- # We make the assumption that the gcc_toolchain will produce a soname with
- # the following definition.
- soname = "{{target_output_name}}{{output_extension}}"
-
- stripped_soname = "lib.stripped/${soname}"
- temp_stripped_soname = "${stripped_soname}.tmp"
-
- android_strip = "${tool_prefix}strip"
-
- strip_command =
- "$android_strip --strip-unneeded -o $temp_stripped_soname $soname"
- replace_command = "if ! cmp -s $temp_stripped_soname $stripped_soname; then mv $temp_stripped_soname $stripped_soname; fi"
- postsolink = "$strip_command && $replace_command"
- solink_outputs = [ stripped_soname ]
- default_output_extension = android_product_extension
-
- # We make the assumption that the gcc_toolchain will produce an exe with
- # the following definition.
- exe = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
- stripped_exe = "exe.stripped/$exe"
- postlink = "$android_strip --strip-unneeded -o $stripped_exe $exe"
- link_outputs = [ stripped_exe ]
}
}
diff --git a/build/toolchain/gcc_toolchain.gni b/build/toolchain/gcc_toolchain.gni
index 29b9137..14a66e4 100644
--- a/build/toolchain/gcc_toolchain.gni
+++ b/build/toolchain/gcc_toolchain.gni
@@ -2,6 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import("//build/toolchain/toolchain.gni")
+
# This value will be inherited in the toolchain below.
concurrent_links = exec_script("get_concurrent_links.py", [], "value")
@@ -34,6 +36,11 @@ concurrent_links = exec_script("get_concurrent_links.py", [], "value")
# - deps
# Just forwarded to the toolchain definition.
# - is_clang
+# Whether to use clang instead of gcc.
+# - strip
+# Location of the strip executable. When specified, strip will be run on
+# all shared libraries and executables as they are built. The pre-stripped
+# artifacts will be put in lib.stripped/ and exe.stripped/.
template("gcc_toolchain") {
toolchain(target_name) {
assert(defined(invoker.cc), "gcc_toolchain() must specify a \"cc\" value")
@@ -138,24 +145,34 @@ template("gcc_toolchain") {
tool("solink") {
soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so".
sofile = "{{root_out_dir}}/$soname" # Possibly including toolchain dir.
+ if (shlib_subdir != ".") {
+ sofile = "{{root_out_dir}}/$shlib_subdir/$soname"
+ }
rspfile = sofile + ".rsp"
+ unstripped_sofile = sofile
+ if (defined(invoker.strip)) {
+ unstripped_sofile = "{{root_out_dir}}/lib.unstripped/$soname"
+ }
+
# These variables are not built into GN but are helpers that implement
# (1) linking to produce a .so, (2) extracting the symbols from that file
# to a temporary file, (3) if the temporary file has differences from the
# existing .TOC file, overwrite it, otherwise, don't change it.
tocfile = sofile + ".TOC"
temporary_tocname = sofile + ".tmp"
- link_command =
- "$ld -shared {{ldflags}} -o $sofile -Wl,-soname=$soname @$rspfile"
+
+ link_command = "$ld -shared {{ldflags}} -o $unstripped_sofile -Wl,-soname=$soname @$rspfile"
assert(defined(readelf), "to solink you must have a readelf")
assert(defined(nm), "to solink you must have an nm")
- toc_command = "{ $readelf -d $sofile | grep SONAME ; $nm -gD -f p $sofile | cut -f1-2 -d' '; } > $temporary_tocname"
+ toc_command = "{ $readelf -d $unstripped_sofile | grep SONAME ; $nm -gD -f p $unstripped_sofile | cut -f1-2 -d' '; } > $temporary_tocname"
replace_command = "if ! cmp -s $temporary_tocname $tocfile; then mv $temporary_tocname $tocfile; fi"
command = "$link_command && $toc_command && $replace_command"
- if (defined(invoker.postsolink)) {
- command += " && " + invoker.postsolink
+ if (defined(invoker.strip)) {
+ strip_command =
+ "${invoker.strip} --strip-unneeded -o $sofile $unstripped_sofile"
+ command += " && " + strip_command
}
rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive $solink_libs_section_prefix {{libs}} $solink_libs_section_postfix"
@@ -164,7 +181,7 @@ template("gcc_toolchain") {
# Use this for {{output_extension}} expansions unless a target manually
# overrides it (in which case {{output_extension}} will be what the target
# specifies).
- default_output_extension = ".so"
+ default_output_extension = shlib_extension
if (defined(invoker.default_output_extension)) {
default_output_extension = invoker.default_output_extension
}
@@ -182,27 +199,35 @@ template("gcc_toolchain") {
sofile,
tocfile,
]
- if (defined(invoker.solink_outputs)) {
- outputs += invoker.solink_outputs
+ if (sofile != unstripped_sofile) {
+ outputs += [ unstripped_sofile ]
}
link_output = sofile
depend_output = tocfile
}
tool("link") {
- outfile = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
+ exename = "{{target_output_name}}{{output_extension}}"
+ outfile = "{{root_out_dir}}/$exename"
rspfile = "$outfile.rsp"
- command = "$ld {{ldflags}} -o $outfile -Wl,--start-group @$rspfile {{solibs}} -Wl,--end-group $libs_section_prefix {{libs}} $libs_section_postfix"
- if (defined(invoker.postlink)) {
- command += " && " + invoker.postlink
+ unstripped_outfile = outfile
+ if (defined(invoker.strip)) {
+ unstripped_outfile = "{{root_out_dir}}/exe.unstripped/$exename"
+ }
+
+ command = "$ld {{ldflags}} -o $unstripped_outfile -Wl,--start-group @$rspfile {{solibs}} -Wl,--end-group $libs_section_prefix {{libs}} $libs_section_postfix"
+ if (defined(invoker.strip)) {
+ strip_command =
+ "${invoker.strip} --strip-unneeded -o $outfile $unstripped_outfile"
+ command += " && " + strip_command
}
description = "LINK $outfile"
rspfile_content = "{{inputs}}"
outputs = [
outfile,
]
- if (defined(invoker.link_outputs)) {
- outputs += invoker.link_outputs
+ if (outfile != unstripped_outfile) {
+ outputs += [ unstripped_outfile ]
}
}
diff --git a/build/toolchain/toolchain.gni b/build/toolchain/toolchain.gni
new file mode 100644
index 0000000..5bd7d9c
--- /dev/null
+++ b/build/toolchain/toolchain.gni
@@ -0,0 +1,40 @@
+# Copyright 2015 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.
+
+# Toolchain-related configuration that may be needed outside the context of the
+# toolchain() rules themselves.
+
+# Subdirectory within root_out_dir for shared library files.
+# TODO(agrieve): GYP sets this to "lib" for Linux & Android, but this won't work
+# in GN until support for loadable_module() is added.
+# See: https://codereview.chromium.org/1236503002/
+shlib_subdir = "."
+
+# Root out dir for shared library files.
+root_shlib_dir = root_out_dir
+if (shlib_subdir != ".") {
+ root_shlib_dir += "/$shlib_subdir"
+}
+
+# Extension for shared library files (including leading dot).
+if (is_mac || is_ios) {
+ shlib_extension = ".dylib"
+} else if (is_android && is_component_build) {
+ # By appending .cr, we prevent name collisions with libraries already
+ # loaded by the Android zygote.
+ shlib_extension = ".cr.so"
+} else if (is_posix) {
+ shlib_extension = ".so"
+} else if (is_win) {
+ shlib_extension = ".dll"
+} else {
+ assert(false, "Platform not supported")
+}
+
+# Prefix for shared library files.
+if (is_posix) {
+ shlib_prefix = "lib"
+} else {
+ shlib_prefix = ""
+}
diff --git a/build/toolchain/win/BUILD.gn b/build/toolchain/win/BUILD.gn
index 6c3e06b..a054267 100644
--- a/build/toolchain/win/BUILD.gn
+++ b/build/toolchain/win/BUILD.gn
@@ -147,8 +147,7 @@ template("msvc_toolchain") {
tool("solink") {
dllname = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" # e.g. foo.dll
- libname =
- "{{root_out_dir}}/{{target_output_name}}{{output_extension}}.lib" # e.g. foo.dll.lib
+ libname = "${dllname}.lib" # e.g. foo.dll.lib
rspfile = "${dllname}.rsp"
link_command = "$python_path gyp-win-tool link-wrapper $env False link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:${dllname}.pdb @$rspfile"