Commit dbeccd05 authored by Tom Anderson's avatar Tom Anderson Committed by Commit Bot

[Reland] Add RPATH to shared libraries

Adds a fix for components/crash/content/tools/generate_breakpad_symbols.py which
saw significant slowdown causing telemetry_unittests and
telemetry_perf_unittests to timeout on the Linux Debug bot.  On my machine, the
time for this script to run is reduced from ~4m30s to ~6s.

> Fixes libfontconfig.so not being able to find libfreetype_harfbuzz.so:
>
> $ ldd libfontconfig.so | grep freetype_harfbuzz
>   libfreetype_harfbuzz.so => not found
> $ ls libfreetype_harfbuzz.so
> libfreetype_harfbuzz.so

TBR=dpranke
R=thestig
CC=mmoroz
BUG=913070,911836,912366
CQ_INCLUDE_TRYBOTS=luci.chromium.try:linux_chromium_dbg_ng

Change-Id: I94faed54a4ea9d50b8db38ca8c41b65d26e2bd5f
Reviewed-on: https://chromium-review.googlesource.com/c/1371080Reviewed-by: default avatarThomas Anderson <thomasanderson@chromium.org>
Reviewed-by: default avatarDirk Pranke <dpranke@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#615975}
parent 57dcb8c4
...@@ -385,6 +385,8 @@ config("shared_library_config") { ...@@ -385,6 +385,8 @@ config("shared_library_config") {
configs += [ "//build/config/ios:ios_dynamic_flags" ] configs += [ "//build/config/ios:ios_dynamic_flags" ]
} else if (is_chromecast) { } else if (is_chromecast) {
configs += [ "//build/config/chromecast:shared_library_config" ] configs += [ "//build/config/chromecast:shared_library_config" ]
} else if (is_linux || current_os == "aix") {
configs += [ "//build/config/gcc:shared_library_config" ]
} }
# If we're using the prebuilt instrumented libraries with the sanitizers, we # If we're using the prebuilt instrumented libraries with the sanitizers, we
......
...@@ -84,20 +84,24 @@ config("rpath_for_built_shared_libraries") { ...@@ -84,20 +84,24 @@ config("rpath_for_built_shared_libraries") {
} }
} }
if (is_component_build && !is_android) {
# See the rpath_for... config above for why this is necessary for component
# builds.
executable_and_shared_library_configs_ =
[ ":rpath_for_built_shared_libraries" ]
} else {
executable_and_shared_library_configs_ = []
}
# Settings for executables. # Settings for executables.
config("executable_config") { config("executable_config") {
configs = executable_and_shared_library_configs_
ldflags = [ "-pie" ] ldflags = [ "-pie" ]
if (is_android) { if (is_android) {
ldflags += [ ldflags += [
"-Bdynamic", "-Bdynamic",
"-Wl,-z,nocopyreloc", "-Wl,-z,nocopyreloc",
] ]
} else {
# See the rpath_for... config above for why this is necessary for component
# builds.
if (is_component_build) {
configs = [ ":rpath_for_built_shared_libraries" ]
}
} }
if (!is_android && current_os != "aix") { if (!is_android && current_os != "aix") {
...@@ -116,3 +120,8 @@ config("executable_config") { ...@@ -116,3 +120,8 @@ config("executable_config") {
] ]
} }
} }
# Settings for shared libraries.
config("shared_library_config") {
configs = executable_and_shared_library_configs_
}
...@@ -12,6 +12,7 @@ platforms is planned. ...@@ -12,6 +12,7 @@ platforms is planned.
import collections import collections
import errno import errno
import glob import glob
import multiprocessing
import optparse import optparse
import os import os
import Queue import Queue
...@@ -22,7 +23,7 @@ import sys ...@@ -22,7 +23,7 @@ import sys
import threading import threading
CONCURRENT_TASKS=4 CONCURRENT_TASKS=multiprocessing.cpu_count()
# The BINARY_INFO tuple describes a binary as dump_syms identifies it. # The BINARY_INFO tuple describes a binary as dump_syms identifies it.
BINARY_INFO = collections.namedtuple('BINARY_INFO', BINARY_INFO = collections.namedtuple('BINARY_INFO',
...@@ -60,7 +61,7 @@ def Resolve(path, exe_path, loader_path, rpaths): ...@@ -60,7 +61,7 @@ def Resolve(path, exe_path, loader_path, rpaths):
def GetSharedLibraryDependenciesLinux(binary): def GetSharedLibraryDependenciesLinux(binary):
"""Return absolute paths to all shared library dependecies of the binary. """Return absolute paths to all shared library dependencies of the binary.
This implementation assumes that we're running on a Linux system.""" This implementation assumes that we're running on a Linux system."""
# TODO(thakis): Figure out how to make this work for android # TODO(thakis): Figure out how to make this work for android
...@@ -72,7 +73,7 @@ def GetSharedLibraryDependenciesLinux(binary): ...@@ -72,7 +73,7 @@ def GetSharedLibraryDependenciesLinux(binary):
for line in ldd.splitlines(): for line in ldd.splitlines():
m = lib_re.match(line) m = lib_re.match(line)
if m: if m:
result.append(m.group(1)) result.append(os.path.abspath(m.group(1)))
return result return result
...@@ -106,7 +107,7 @@ def GetDeveloperDirMac(): ...@@ -106,7 +107,7 @@ def GetDeveloperDirMac():
def GetSharedLibraryDependenciesMac(binary, exe_path): def GetSharedLibraryDependenciesMac(binary, exe_path):
"""Return absolute paths to all shared library dependecies of the binary. """Return absolute paths to all shared library dependencies of the binary.
This implementation assumes that we're running on a Mac system.""" This implementation assumes that we're running on a Mac system."""
# realpath() serves two purposes: # realpath() serves two purposes:
...@@ -164,7 +165,7 @@ def GetSharedLibraryDependenciesMac(binary, exe_path): ...@@ -164,7 +165,7 @@ def GetSharedLibraryDependenciesMac(binary, exe_path):
def GetSharedLibraryDependencies(options, binary, exe_path): def GetSharedLibraryDependencies(options, binary, exe_path):
"""Return absolute paths to all shared library dependecies of the binary.""" """Return absolute paths to all shared library dependencies of the binary."""
deps = [] deps = []
if sys.platform.startswith('linux'): if sys.platform.startswith('linux'):
deps = GetSharedLibraryDependenciesLinux(binary) deps = GetSharedLibraryDependenciesLinux(binary)
...@@ -183,6 +184,29 @@ def GetSharedLibraryDependencies(options, binary, exe_path): ...@@ -183,6 +184,29 @@ def GetSharedLibraryDependencies(options, binary, exe_path):
return result return result
def GetTransitiveDependencies(options):
"""Return absolute paths to the transitive closure of all shared library
dependencies of the binary, along with the binary itself."""
binary = os.path.abspath(options.binary)
exe_path = os.path.dirname(binary)
if sys.platform.startswith('linux'):
# 'ldd' returns all transitive dependencies for us.
deps = set(GetSharedLibraryDependencies(options, binary, exe_path))
deps.add(binary)
return list(deps)
if sys.platform == 'darwin':
binaries = set([binary])
queue = [binary]
while queue:
deps = GetSharedLibraryDependencies(options, queue.pop(0), exe_path)
new_deps = set(deps) - binaries
binaries |= new_deps
queue.extend(list(new_deps))
return binaries
print "Platform not supported."
sys.exit(1)
def mkdir_p(path): def mkdir_p(path):
"""Simulates mkdir -p.""" """Simulates mkdir -p."""
try: try:
...@@ -328,14 +352,7 @@ def main(): ...@@ -328,14 +352,7 @@ def main():
return 1 return 1
# Build the transitive closure of all dependencies. # Build the transitive closure of all dependencies.
binaries = set([options.binary]) binaries = GetTransitiveDependencies(options)
queue = [options.binary]
exe_path = os.path.dirname(options.binary)
while queue:
deps = GetSharedLibraryDependencies(options, queue.pop(0), exe_path)
new_deps = set(deps) - binaries
binaries |= new_deps
queue.extend(list(new_deps))
GenerateSymbols(options, binaries) GenerateSymbols(options, binaries)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment