Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 60968c8

Browse files
authored
Don't use objcopy to embed Android icudtl (#46862)
When objcopy is used to embed data into a linkable object file, that object file will only have default bits set in its header for ABI etc.. If the linker doesn't cooperate by ignoring ABI mismatches on object files without code, then linking will fail. This PR stops using objcopy to create an object file that embeds icudtl.dat into the Android embedder, and instead uses the `bin_to_assembly.py` script that we're already using for Dart VM snapshot data. Context in llvm/llvm-project#68915
1 parent f9aed02 commit 60968c8

7 files changed

Lines changed: 121 additions & 284 deletions

File tree

build/bin_to_obj.gni

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Copyright 2013 The Flutter 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+
5+
# Generates an assembly file defining a given symbol with the bytes from a
6+
# binary file. Places the symbol in a text section if 'executable' is true,
7+
# otherwise places the symbol in a read-only data section.
8+
template("bin_to_assembly") {
9+
assert(defined(invoker.deps), "Must define deps")
10+
assert(defined(invoker.input), "Must define input binary file")
11+
assert(defined(invoker.symbol), "Must define symbol name")
12+
assert(defined(invoker.executable), "Must define boolean executable")
13+
14+
action(target_name) {
15+
deps = invoker.deps
16+
script = "//third_party/dart/runtime/tools/bin_to_assembly.py"
17+
output = "$target_gen_dir/${invoker.input}.S"
18+
args = [
19+
"--input",
20+
rebase_path(invoker.input),
21+
"--output",
22+
rebase_path(output),
23+
"--symbol_name",
24+
invoker.symbol,
25+
"--target_os",
26+
current_os,
27+
]
28+
if (defined(invoker.size_symbol)) {
29+
args += [
30+
"--size_symbol_name",
31+
invoker.size_symbol,
32+
"--target_arch",
33+
current_cpu,
34+
]
35+
}
36+
if (invoker.executable) {
37+
args += [ "--executable" ]
38+
}
39+
if (current_os != "win") {
40+
args += [ "--incbin" ]
41+
}
42+
inputs = [
43+
script,
44+
invoker.input,
45+
]
46+
outputs = [ output ]
47+
}
48+
}
49+
50+
# Generates an object file defining a given symbol with the bytes from a
51+
# binary file. Places the symbol in the read-only data section.
52+
template("bin_to_coff") {
53+
assert(defined(invoker.deps), "Must define deps")
54+
assert(defined(invoker.input), "Must define input binary file")
55+
assert(defined(invoker.symbol), "Must define symbol name")
56+
assert(defined(invoker.executable), "Must define executable")
57+
58+
action(target_name) {
59+
deps = invoker.deps
60+
script = "//third_party/dart/runtime/tools/bin_to_coff.py"
61+
output = "$target_gen_dir/${invoker.input}.o"
62+
args = [
63+
"--input",
64+
rebase_path(invoker.input),
65+
"--output",
66+
rebase_path(output),
67+
"--symbol_name",
68+
invoker.symbol,
69+
]
70+
71+
if (defined(invoker.size_symbol)) {
72+
args += [
73+
"--size_symbol_name",
74+
invoker.size_symbol,
75+
]
76+
}
77+
78+
if (invoker.executable) {
79+
args += [ "--executable" ]
80+
}
81+
82+
args += [ "--arch=$current_cpu" ]
83+
inputs = [ invoker.input ]
84+
outputs = [ output ]
85+
}
86+
}
87+
88+
# Generates a linkable output file defining the specified symbol with the bytes
89+
# from the binary file. Emits a COFF object file when targeting Windows,
90+
# otherwise assembly.
91+
template("bin_to_linkable") {
92+
assert(defined(invoker.deps), "Must define deps")
93+
assert(defined(invoker.input), "Must define input binary file")
94+
assert(defined(invoker.symbol), "Must define symbol name")
95+
target_type = "bin_to_assembly"
96+
if (is_win) {
97+
target_type = "bin_to_coff"
98+
}
99+
100+
target(target_type, target_name) {
101+
forward_variables_from(invoker, "*")
102+
}
103+
}

ci/licenses_golden/excluded_files

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,6 @@
388388
../../../flutter/sky/tools/create_xcframework.py
389389
../../../flutter/sky/tools/dist_dart_pkg.py
390390
../../../flutter/sky/tools/install_framework_headers.py
391-
../../../flutter/sky/tools/objcopy.py
392391
../../../flutter/testing
393392
../../../flutter/third_party/.clang-tidy
394393
../../../flutter/third_party/.gitignore

lib/snapshot/BUILD.gn

Lines changed: 1 addition & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import("//build/compiled_action.gni")
66
import("//build/fuchsia/sdk.gni")
7+
import("//flutter/build/bin_to_obj.gni")
78
import("//flutter/common/config.gni")
89
import("//flutter/impeller/tools/impeller.gni")
910
import("//flutter/lib/ui/dart_ui.gni")
@@ -110,103 +111,6 @@ compiled_action("generate_snapshot_bin") {
110111
}
111112
}
112113

113-
# Generates an assembly file defining a given symbol with the bytes from a
114-
# binary file. Places the symbol in a text section if 'executable' is true,
115-
# otherwise places the symbol in a read-only data section.
116-
template("bin_to_assembly") {
117-
assert(defined(invoker.deps), "Must define deps")
118-
assert(defined(invoker.input), "Must define input binary file")
119-
assert(defined(invoker.symbol), "Must define symbol name")
120-
assert(defined(invoker.executable), "Must define boolean executable")
121-
122-
action(target_name) {
123-
deps = invoker.deps
124-
script = "//third_party/dart/runtime/tools/bin_to_assembly.py"
125-
output = invoker.input + ".S"
126-
args = [
127-
"--input",
128-
rebase_path(invoker.input),
129-
"--output",
130-
rebase_path(output),
131-
"--symbol_name",
132-
invoker.symbol,
133-
"--target_os",
134-
current_os,
135-
]
136-
if (defined(invoker.size_symbol)) {
137-
args += [
138-
"--size_symbol_name",
139-
invoker.size_symbol,
140-
"--target_arch",
141-
current_cpu,
142-
]
143-
}
144-
if (invoker.executable) {
145-
args += [ "--executable" ]
146-
}
147-
inputs = [
148-
script,
149-
invoker.input,
150-
]
151-
outputs = [ output ]
152-
}
153-
}
154-
155-
# Generates an object file defining a given symbol with the bytes from a
156-
# binary file. Places the symbol in the read-only data section.
157-
template("bin_to_coff") {
158-
assert(defined(invoker.deps), "Must define deps")
159-
assert(defined(invoker.input), "Must define input binary file")
160-
assert(defined(invoker.symbol), "Must define symbol name")
161-
assert(defined(invoker.executable), "Must define executable")
162-
163-
action(target_name) {
164-
deps = invoker.deps
165-
script = "//third_party/dart/runtime/tools/bin_to_coff.py"
166-
output = invoker.input + ".o"
167-
args = [
168-
"--input",
169-
rebase_path(invoker.input),
170-
"--output",
171-
rebase_path(output),
172-
"--symbol_name",
173-
invoker.symbol,
174-
]
175-
176-
if (defined(invoker.size_symbol)) {
177-
args += [
178-
"--size_symbol_name",
179-
invoker.size_symbol,
180-
]
181-
}
182-
183-
if (invoker.executable) {
184-
args += [ "--executable" ]
185-
}
186-
187-
args += [ "--arch=$current_cpu" ]
188-
inputs = [ invoker.input ]
189-
outputs = [ output ]
190-
}
191-
}
192-
193-
# Generates a linkable output file defining the specified symbol with the bytes
194-
# from the binary file. Emits a COFF object file when targeting Windows,
195-
# otherwise assembly.
196-
template("bin_to_linkable") {
197-
assert(defined(invoker.deps), "Must define deps")
198-
assert(defined(invoker.input), "Must define input binary file")
199-
assert(defined(invoker.symbol), "Must define symbol name")
200-
target_type = "bin_to_assembly"
201-
if (is_win) {
202-
target_type = "bin_to_coff"
203-
}
204-
205-
target(target_type, target_name) {
206-
forward_variables_from(invoker, "*")
207-
}
208-
}
209-
210114
bin_to_linkable("vm_snapshot_data_linkable") {
211115
deps = [ ":generate_snapshot_bin" ]
212116
input = "$target_gen_dir/vm_isolate_snapshot.bin"

shell/common/switches.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,11 @@ static const std::string kAllowedDartFlags[] = {
7878
// of the engine's own symbols on some older versions of Android.
7979
#if FML_OS_ANDROID
8080
extern uint8_t _binary_icudtl_dat_start[];
81-
extern uint8_t _binary_icudtl_dat_end[];
81+
extern size_t _binary_icudtl_dat_size;
8282

8383
static std::unique_ptr<fml::Mapping> GetICUStaticMapping() {
84-
return std::make_unique<fml::NonOwnedMapping>(
85-
_binary_icudtl_dat_start,
86-
_binary_icudtl_dat_end - _binary_icudtl_dat_start);
84+
return std::make_unique<fml::NonOwnedMapping>(_binary_icudtl_dat_start,
85+
_binary_icudtl_dat_size);
8786
}
8887
#endif
8988

shell/platform/android/BUILD.gn

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import("//build/config/android/config.gni")
66
import("//build/toolchain/clang.gni")
7+
import("//flutter/build/bin_to_obj.gni")
78
import("//flutter/build/zip_bundle.gni")
89
import("//flutter/common/config.gni")
910
import("//flutter/impeller/tools/impeller.gni")
@@ -63,11 +64,18 @@ shared_library("flutter_shell_native") {
6364
ldflags = [ "-Wl,--version-script=" + rebase_path("android_exports.lst") ]
6465
}
6566

67+
bin_to_assembly("icudtl_asm") {
68+
deps = []
69+
input = "//third_party/icu/flutter/icudtl.dat"
70+
symbol = "_binary_icudtl_dat_start"
71+
size_symbol = "_binary_icudtl_dat_size"
72+
executable = false
73+
}
74+
6675
source_set("flutter_shell_native_src") {
6776
visibility = [ ":*" ]
6877

6978
sources = [
70-
"$root_build_dir/flutter_icu/icudtl.o",
7179
"android_choreographer.cc",
7280
"android_choreographer.h",
7381
"android_context_gl_impeller.cc",
@@ -121,9 +129,11 @@ source_set("flutter_shell_native_src") {
121129
"vsync_waiter_android.h",
122130
]
123131

132+
sources += get_target_outputs(":icudtl_asm")
133+
124134
public_deps = [
125135
":android_gpu_configuration",
126-
":icudtl_object",
136+
":icudtl_asm",
127137
":image_generator",
128138
"//flutter/assets",
129139
"//flutter/common",
@@ -424,28 +434,6 @@ action("flutter_shell_java") {
424434
]
425435
}
426436

427-
action("icudtl_object") {
428-
script = "//flutter/sky/tools/objcopy.py"
429-
430-
icudtl_input = "//third_party/icu/flutter/icudtl.dat"
431-
icudtl_output = "$root_build_dir/flutter_icu/icudtl.o"
432-
433-
inputs = [ "$icudtl_input" ]
434-
435-
outputs = [ "$icudtl_output" ]
436-
437-
args = [
438-
"--objcopy",
439-
rebase_path(android_objcopy),
440-
"--input",
441-
rebase_path(icudtl_input),
442-
"--output",
443-
rebase_path(icudtl_output),
444-
"--arch",
445-
current_cpu,
446-
]
447-
}
448-
449437
action("android_jar") {
450438
script = "//build/android/gyp/create_flutter_jar.py"
451439

sky/tools/objcopy.py

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)