Skip to content

Commit

Permalink
Abseil component build (default symbols visibility).
Browse files Browse the repository at this point in the history
This CL introduces an Abseil component on which all Chromium Abseil
clients will have to depend on.

Abseil doesn't export symbols explicitly, so for the moment Chromium
exports all of them when is_component_build=true. On Android, Linux and
Mac -fvisibility=default is used while on Windows a .def file is
generated at Abseil roll time.

Bug: 1046390
Change-Id: I1697eb9e0179cee01badcf1b687acd94160e5f6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2174434
Commit-Queue: Mirko Bonadei <mbonadei@chromium.org>
Reviewed-by: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781225}
  • Loading branch information
Mirko Bonadei authored and Commit Bot committed Jun 23, 2020
1 parent 538764b commit 5906c25
Show file tree
Hide file tree
Showing 14 changed files with 1,356 additions and 39 deletions.
7 changes: 6 additions & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ group("gn_all") {
"//services/service_manager/public/cpp",
"//skia:skia_unittests",
"//sql:sql_unittests",
"//third_party/abseil-cpp:absl_tests",
"//third_party/flatbuffers:flatbuffers_unittests",
"//tools/binary_size:binary_size_trybot_py",
"//tools/ipc_fuzzer:ipc_fuzzer_all",
Expand All @@ -90,6 +89,12 @@ group("gn_all") {
"//url:url_unittests",
]

if (!is_component_build) {
deps += [
"//third_party/abseil-cpp:absl_tests",
]
}

if (!is_android && !is_chromecast) {
deps += [
"//crypto:crypto_unittests",
Expand Down
73 changes: 46 additions & 27 deletions third_party/abseil-cpp/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,30 @@
import("//build/toolchain/toolchain.gni")
import("//testing/test.gni")

config("absl_component_build") {
defines = [ "ABSL_CONSUME_DLL" ]
}

# TODO(mbonadei): WebRTC tests and binaries use absl flags but they are
# marked testonly because we don't want them to be usable in Chromium.
# Add an absl_flags component which depends on the main absl component.
component("absl") {
if (is_component_build) {
public_configs = [ ":absl_component_build" ]

if (is_win) {
if (target_cpu == "x64") {
sources = [ "symbols_x64.def" ]
}
if (target_cpu == "x86") {
sources = [ "symbols_x86.def" ]
}
if (target_cpu == "arm64") {
sources = [ "symbols_arm64.def" ]
}
}
}

# This is a placeholder target (that will become a "component" in a follow up
# CL) to allow both WebRTC and OpenScreen to depend on
# //third_party/abseil-cpp:absl. This is beneficial for the
# migration from an always statically linked Abseil to an Abseil that
# will respect the value of is_component_build.
group("absl") {
public_deps = [
"//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/base:config",
Expand Down Expand Up @@ -103,25 +120,27 @@ config("absl_test_cflags_cc") {
}
}

test("absl_tests") {
testonly = true
deps = [
"absl/algorithm:algorithm_test",
"absl/algorithm:container_test",
"absl/base:config_test",
"absl/container:inlined_vector_test",
"absl/memory:memory_test",
"absl/meta:type_traits_test",
"absl/strings:ascii_test",
"absl/strings:match_test",
"absl/strings:str_replace_test",
"absl/strings:string_view_test",

# TODO(mbonadei): On iOS, gtest doesn't support death tests. Fix upstream
# Abseil to use EXPECT_DEATH_IF_SUPPORTED instead of EXPECT_DEATH.
# "absl/types:optional_test",
# "absl/types:variant_test",

"//third_party/googletest:gtest_main",
]
if (!is_component_build) {
test("absl_tests") {
testonly = true
deps = [
"absl/algorithm:algorithm_test",
"absl/algorithm:container_test",
"absl/base:config_test",
"absl/container:inlined_vector_test",
"absl/memory:memory_test",
"absl/meta:type_traits_test",
"absl/strings:ascii_test",
"absl/strings:match_test",
"absl/strings:str_replace_test",
"absl/strings:string_view_test",

# TODO(mbonadei): On iOS, gtest doesn't support death tests. Fix upstream
# Abseil to use EXPECT_DEATH_IF_SUPPORTED instead of EXPECT_DEATH.
# "absl/types:optional_test",
# "absl/types:variant_test",

"//third_party/googletest:gtest_main",
]
}
}
8 changes: 8 additions & 0 deletions third_party/abseil-cpp/absl.gni
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ template("absl_source_set") {
"//third_party/abseil-cpp:absl_default_cflags_cc",
]

if (is_component_build) {
defines = [ "ABSL_BUILD_DLL" ]
if (!is_win) {
configs -= [ "//build/config/gcc:symbol_visibility_hidden" ]
configs += [ "//build/config/gcc:symbol_visibility_default" ]
}
}

if (!defined(public_configs)) {
public_configs = []
}
Expand Down
2 changes: 1 addition & 1 deletion third_party/abseil-cpp/absl/base/internal/raw_logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ bool RawLoggingFullySupported() {
#endif // !ABSL_LOW_LEVEL_WRITE_SUPPORTED
}

ABSL_DLL ABSL_INTERNAL_ATOMIC_HOOK_ATTRIBUTES
ABSL_INTERNAL_ATOMIC_HOOK_ATTRIBUTES ABSL_DLL
absl::base_internal::AtomicHook<InternalLogFunction>
internal_log_function(DefaultInternalLog);

Expand Down
2 changes: 1 addition & 1 deletion third_party/abseil-cpp/absl/base/internal/raw_logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ using InternalLogFunction = void (*)(absl::LogSeverity severity,
const char* file, int line,
const std::string& message);

ABSL_DLL ABSL_INTERNAL_ATOMIC_HOOK_ATTRIBUTES extern base_internal::AtomicHook<
ABSL_INTERNAL_ATOMIC_HOOK_ATTRIBUTES ABSL_DLL extern base_internal::AtomicHook<
InternalLogFunction>
internal_log_function;

Expand Down
2 changes: 1 addition & 1 deletion third_party/abseil-cpp/absl/strings/string_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ constexpr bool operator>=(string_view x, string_view y) noexcept {
}

// IO Insertion Operator
std::ostream& operator<<(std::ostream& o, string_view piece);
ABSL_DLL std::ostream& operator<<(std::ostream& o, string_view piece);

ABSL_NAMESPACE_END
} // namespace absl
Expand Down
91 changes: 91 additions & 0 deletions third_party/abseil-cpp/generate_def_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
"""Script to generate Chromium's Abseil .def file at roll time.
This script generates //third_party/abseil-app/absl/symbols_x64.def at Abseil
roll time.
Since Abseil doesn't export symbols, Chromium is forced to consider all
Abseil's symbols as publicly visible. On POSIX it is possible to use
-fvisibility=default but on Windows a .def file with all the symbols
is needed.
Unless you are on a Windows machine, you need to set up your Chromium
checkout for cross-compilation by following the instructions at
https://chromium.googlesource.com/chromium/src.git/+/master/docs/win_cross.md.
"""

import fnmatch
import logging
import os
import re
import subprocess
import tempfile
import time

# Matches a mangled symbol that has 'absl' in it, this should be a good
# enough heuristic to select Abseil symbols to list in the .def file.
ABSL_SYM_RE = re.compile(r'0* [BT] (?P<symbol>\?{1}[^\?].*absl.*)')


def _GenerateDefFile(cpu):
"""Generates a .def file for the absl component build on the specified CPU."""
gn_args = [
'ffmpeg_branding = "Chrome"',
'is_component_build = false',
'is_debug = true',
'proprietary_codecs = true',
'symbol_level = 0',
'target_cpu = "{}"'.format(cpu),
'target_os = "win"',
]

with tempfile.TemporaryDirectory() as out_dir:
logging.info('[%s] Creating tmp out dir in %s', cpu, out_dir)
subprocess.check_call(['gn', 'gen', out_dir, '--args=' + ' '.join(gn_args)],
cwd=os.getcwd())
logging.info('[%s] gn gen completed', cpu)
subprocess.check_call(
['autoninja', '-C', out_dir, 'third_party/abseil-cpp:absl'],
cwd=os.getcwd())
logging.info('[%s] autoninja completed', cpu)

obj_files = []
for root, _dirnames, filenames in os.walk(
os.path.join(out_dir, 'obj', 'third_party', 'abseil-cpp')):
matched_files = fnmatch.filter(filenames, '*.obj')
obj_files.extend((os.path.join(root, f) for f in matched_files))

logging.info('[%s] Found %d object files.', cpu, len(obj_files))

absl_symbols = []
for f in obj_files:
stdout = subprocess.check_output(['llvm-nm-9', f], cwd=os.getcwd())
for line in stdout.splitlines():
match = re.match(ABSL_SYM_RE, line.decode('utf-8'))
if match:
absl_symbols.append(match.group('symbol'))

logging.info('[%s] Found %d absl symbols.', cpu, len(absl_symbols))

def_file = os.path.join('third_party', 'abseil-cpp',
'symbols_{}.def'.format(cpu))
with open(def_file, 'w') as f:
f.write('EXPORTS\n')
for s in sorted(absl_symbols):
f.write(' {}\n'.format(s))

# Hack, it looks like there is a race in the directory cleanup.
time.sleep(3)

logging.info('[%s] .def file successfully generated.', cpu)


if __name__ == '__main__':
logging.getLogger().setLevel(logging.INFO)

if not os.getcwd().endswith('chromium/src'):
logging.error('Run this script from Chromium\'s src/ directory.')
exit(1)

_GenerateDefFile('x86')
_GenerateDefFile('x64')
_GenerateDefFile('arm64')
53 changes: 53 additions & 0 deletions third_party/abseil-cpp/patches/0002-Manual-ABSL_DLL-fixes.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
From 330cb7c7a62ab3187a6a2a3dc3a7b92f3690677c Mon Sep 17 00:00:00 2001
From: Mirko Bonadei <mbonadei@chromium.org>
Date: Wed, 17 Jun 2020 21:37:18 +0200
Subject: [PATCH] Manual ABSL_DLL fixes.

---
third_party/abseil-cpp/absl/base/internal/raw_logging.cc | 2 +-
third_party/abseil-cpp/absl/base/internal/raw_logging.h | 2 +-
third_party/abseil-cpp/absl/strings/string_view.h | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/third_party/abseil-cpp/absl/base/internal/raw_logging.cc b/third_party/abseil-cpp/absl/base/internal/raw_logging.cc
index 40cea5506172..f27e2838d72b 100644
--- a/third_party/abseil-cpp/absl/base/internal/raw_logging.cc
+++ b/third_party/abseil-cpp/absl/base/internal/raw_logging.cc
@@ -227,7 +227,7 @@ bool RawLoggingFullySupported() {
#endif // !ABSL_LOW_LEVEL_WRITE_SUPPORTED
}

-ABSL_DLL ABSL_INTERNAL_ATOMIC_HOOK_ATTRIBUTES
+ABSL_INTERNAL_ATOMIC_HOOK_ATTRIBUTES ABSL_DLL
absl::base_internal::AtomicHook<InternalLogFunction>
internal_log_function(DefaultInternalLog);

diff --git a/third_party/abseil-cpp/absl/base/internal/raw_logging.h b/third_party/abseil-cpp/absl/base/internal/raw_logging.h
index 418d6c856feb..51551bafff48 100644
--- a/third_party/abseil-cpp/absl/base/internal/raw_logging.h
+++ b/third_party/abseil-cpp/absl/base/internal/raw_logging.h
@@ -170,7 +170,7 @@ using InternalLogFunction = void (*)(absl::LogSeverity severity,
const char* file, int line,
const std::string& message);

-ABSL_DLL ABSL_INTERNAL_ATOMIC_HOOK_ATTRIBUTES extern base_internal::AtomicHook<
+ABSL_INTERNAL_ATOMIC_HOOK_ATTRIBUTES ABSL_DLL extern base_internal::AtomicHook<
InternalLogFunction>
internal_log_function;

diff --git a/third_party/abseil-cpp/absl/strings/string_view.h b/third_party/abseil-cpp/absl/strings/string_view.h
index 8a9db8c3d796..7fb033300338 100644
--- a/third_party/abseil-cpp/absl/strings/string_view.h
+++ b/third_party/abseil-cpp/absl/strings/string_view.h
@@ -586,7 +586,7 @@ constexpr bool operator>=(string_view x, string_view y) noexcept {
}

// IO Insertion Operator
-std::ostream& operator<<(std::ostream& o, string_view piece);
+ABSL_DLL std::ostream& operator<<(std::ostream& o, string_view piece);

ABSL_NAMESPACE_END
} // namespace absl
--
2.27.0.290.gba653c62da-goog

Loading

0 comments on commit 5906c25

Please sign in to comment.