forked from bazelbuild/rules_android_ndk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ndk_cc_toolchain_config.bzl
1623 lines (1550 loc) · 63.2 KB
/
ndk_cc_toolchain_config.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright 2022 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Toolchain command-line configuration logic."""
load(
"@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
"action_config",
"feature",
"feature_set",
"flag_group",
"tool",
"tool_path",
"variable_with_value",
"with_feature_set",
flag_set_ = "flag_set",
)
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", action = "ACTION_NAMES")
def ndk_cc_toolchain_config(
api_level,
target_system_name,
tools,
**config):
"""Implement the arguments to cc_common.create_cc_toolchain_config_info.
Args:
api_level: Integer level of the SDK version.
target_system_name: Argument to the --target flag.
tools: Dict of (tool_name, tool_path) items.
**config: Legacy/default arguments.
Returns:
A keyword argument dictionary for cc_common.create_cc_toolchain_config_info.
"""
actions = construct_actions_(action)
# Construct tool_paths.
tool_of_tool_name = {
tool_name: tool(path = path)
for (tool_name, path) in tools.items()
}
tool_paths = [
tool_path(
name = tool_name,
path = path,
)
for (tool_name, path) in tools.items()
]
if "gcc" not in tools:
tool_paths.append(tool_path(name = "gcc", path = tools["clang"]))
# Construct action configurations.
action_configs = [
action_config(
action_name = action.cpp_link_nodeps_dynamic_library,
enabled = True,
tools = [tool_of_tool_name["clang"]],
),
action_config(
action_name = action.strip,
enabled = True,
flag_sets = [
flag_set(
flags = ["--strip-unneeded"],
features = ["fully_strip"],
),
flag_set(
flags = ["--strip-debug"],
not_features = ["fully_strip"],
),
flag_set(
flag_groups = [
flag_group(flags = ["-p", "-o", "%{output_file}"]),
flag_group(
flags = " ".join([
"-R .gnu.switches.text.quote_paths",
"-R .gnu.switches.text.bracket_paths",
"-R .gnu.switches.text.system_paths",
"-R .gnu.switches.text.cpp_defines",
"-R .gnu.switches.text.cpp_includes",
"-R .gnu.switches.text.cl_args",
"-R .gnu.switches.text.lipo_info",
"-R .gnu.switches.text.annotation",
]).split(" "),
),
flag_group(
flags = ["%{stripopts}"],
iterate_over = "stripopts",
),
flag_group(flags = ["%{input_file}"]),
],
),
],
tools = [tool_of_tool_name["strip"]],
),
action_config(
action_name = action.cpp_link_dynamic_library,
enabled = True,
tools = [tool_of_tool_name["clang"]],
),
action_config(
action_name = action.cc_flags_make_variable,
enabled = True,
),
action_config(
action_name = action.assemble,
enabled = True,
tools = [tool_of_tool_name["clang"]],
),
action_config(
action_name = action.preprocess_assemble,
enabled = True,
tools = [tool_of_tool_name["clang"]],
),
action_config(
action_name = action.cpp_module_compile,
enabled = True,
tools = [tool_of_tool_name["clang"]],
),
action_config(
action_name = action.c_compile,
enabled = True,
tools = [tool_of_tool_name["clang"]],
),
action_config(
action_name = action.cpp_header_parsing,
enabled = True,
tools = [tool_of_tool_name["clang"]],
),
action_config(
action_name = action.cpp_module_codegen,
enabled = True,
tools = [tool_of_tool_name["clang"]],
),
action_config(
action_name = action.cpp_link_static_library,
enabled = True,
flag_sets = [
flag_set(
flag_groups = [
flag_group(
flags = ["rcsD", "%{output_execpath}"],
expand_if_available = "output_execpath",
),
],
),
flag_set(
flag_groups = [
flag_group(
iterate_over = "libraries_to_link",
flag_groups = [
flag_group(
flags = ["%{libraries_to_link.name}"],
expand_if_equal = variable_with_value(
name = "libraries_to_link.type",
value = "object_file",
),
),
flag_group(
flags = ["%{libraries_to_link.object_files}"],
iterate_over = "libraries_to_link.object_files",
expand_if_equal = variable_with_value(
name = "libraries_to_link.type",
value = "object_file_group",
),
),
],
expand_if_available = "libraries_to_link",
),
],
),
flag_set(
flag_groups = [
flag_group(
flags = ["@%{linker_param_file}"],
expand_if_available = "linker_param_file",
),
],
),
],
tools = [tool_of_tool_name["ar"]],
),
action_config(
action_name = "objcopy_embed_data",
enabled = True,
flag_sets = [
flag_set(
flags = {
"aarch64-linux-android": "-I binary -B aarch64 -O elf64-littleaarch64",
"arm-linux-androideabi": "-I binary -B arm -O elf32-littlearm",
"i686-linux-android": "-I binary -B i386 -O elf32-i386",
"x86_64-linux-android": "-I binary -B i386 -O elf64-x86-64",
}[target_system_name].split(" "),
),
],
tools = [tool_of_tool_name["objcopy"]],
),
action_config(
action_name = action.cpp_compile,
enabled = True,
tools = [tool_of_tool_name["clang"]],
),
action_config(
action_name = action.linkstamp_compile,
enabled = True,
tools = [tool_of_tool_name["clang"]],
),
action_config(
action_name = action.clif_match,
enabled = True,
tools = [tool_of_tool_name["clang"]],
),
action_config(
action_name = action.cpp_link_executable,
enabled = True,
tools = [tool_of_tool_name["clang"]],
),
action_config(
action_name = action.lto_backend,
enabled = True,
tools = [tool_of_tool_name["clang"]],
),
action_config(
action_name = action.lto_index_for_executable,
enabled = True,
tools = [tool_of_tool_name["clang"]],
),
action_config(
action_name = action.lto_index_for_dynamic_library,
enabled = True,
tools = [tool_of_tool_name["clang"]],
),
action_config(
action_name = action.lto_index_for_nodeps_dynamic_library,
enabled = True,
tools = [tool_of_tool_name["clang"]],
),
]
# Construct features.
features = [
# This set of magic "feature"s are important configuration information for bazel.
feature(
name = "no_legacy_features",
enabled = True,
),
feature(
name = "has_configured_linker_path",
enabled = True,
),
# Blaze requests this feature by default, but we don't care.
feature(name = "dependency_file"),
# Blaze requests this feature by default, but we don't care.
feature(name = "random_seed"),
# Blaze requests this feature if fission is requested
# Blaze tests if it's supported to see if we support fission.
feature(name = "per_object_debug_info"),
# Blaze tests if this feature is supported before setting preprocess_defines.
feature(name = "preprocessor_defines"),
# Blaze requests this feature by default.
# Blaze tests if this feature is supported before setting includes.
feature(name = "include_paths"),
# Blaze tests if this feature is enabled in order to create implicit
# "nodeps" .so outputs from cc_library rules.
feature(
name = "supports_dynamic_linker",
enabled = True,
),
# Blaze requests this feature when linking a cc_binary which is
# "dynamic" aka linked against nodeps-dynamic-library cc_library
# outputs.
feature(name = "dynamic_linking_mode"),
feature(
name = "static_link_cpp_runtimes",
enabled = True,
),
feature(
name = "supports_start_end_lib",
enabled = True,
),
# This feature stanza is used by third_party/stl/BUILD to determine
# which headers to include in the module.
feature(
name = "has_cxx17_headers",
enabled = True,
),
# This feature is used generically to determine which STL is enabled by
# default. (e.g. for //tools/cpp:standard_library)
feature(
name = "has_libcxx",
enabled = True,
),
# This feature is needed to prevent name mangling during dynamic library links.
feature(name = "copy_dynamic_libraries_to_binary"),
#### Configuration features
feature(
name = "crosstool_cpu",
enabled = True,
implies = [{
"arm-linux-androideabi": "crosstool_cpu_arm",
"aarch64-linux-android": "crosstool_cpu_arm64",
"i686-linux-android": "crosstool_cpu_x86",
"x86_64-linux-android": "crosstool_cpu_x86_64",
}[target_system_name]],
),
feature(
name = "crosstool_cpu_arm",
provides = ["variant:crosstool_cpu"],
),
feature(
name = "crosstool_cpu_arm64",
provides = ["variant:crosstool_cpu"],
),
feature(
name = "crosstool_cpu_x86",
provides = ["variant:crosstool_cpu"],
),
feature(
name = "crosstool_cpu_x86_64",
provides = ["variant:crosstool_cpu"],
),
feature(
name = "crosstool_has_neon",
enabled = api_level >= 23,
),
feature(
name = "crosstool_needs_stackrealign",
enabled = api_level < 24,
),
feature(
name = "do_not_split_linking_cmdline",
),
feature(
name = "crosstool_needs_memmove_fix",
enabled = api_level < 21,
),
feature(
name = "crosstool_linker_gold",
provides = ["variant:crosstool_linker"],
enabled = False,
),
feature(
name = "crosstool_linker_lld",
provides = ["variant:crosstool_linker"],
enabled = True,
),
feature(
name = "proto_force_lite_runtime",
implies = ["proto_disable_services"],
enabled = True,
),
feature(
name = "proto_disable_services",
enabled = True,
),
feature(
name = "proto_one_output_per_message",
implies = ["proto_force_lite_runtime"],
enabled = True,
requires = [feature_set(features = ["opt"])],
),
# Allows disabling nolegacy_whole_archive for individual targets. Automatically turned on
# for cc_proto_library targets, but requires proto_one_output_per_message
feature(
name = "disable_whole_archive_for_static_lib",
requires = [feature_set(features = ["proto_one_output_per_message"])],
),
# These 3 features will be automatically enabled by bazel in the
# corresponding build mode.
feature(
name = "opt",
provides = ["variant:crosstool_build_mode"],
),
feature(
name = "dbg",
provides = ["variant:crosstool_build_mode"],
),
feature(
name = "fastbuild",
provides = ["variant:crosstool_build_mode"],
),
# User-settable strip features
feature(
# --strip-all for .stripped binaries
name = "fully_strip", # --strip-all for strip=always
enabled = True,
requires = [feature_set(features = ["opt"])], # Only fully strip in opt mode.
),
feature(
# --strip-all for --strip=always
name = "linker_fully_strip",
requires = [feature_set(features = ["opt"])], # Only fully strip in opt mode.
),
feature(name = "lto_unit"),
# This reduces bitcode compatibility issues.
feature(
name = "no_use_lto_indexing_bitcode_file",
enabled = True,
),
feature(
name = "thin_lto",
flag_sets = [
flag_set(
actions = [
action.c_compile,
action.cpp_compile,
action.cpp_link_dynamic_library,
action.cpp_link_nodeps_dynamic_library,
action.cpp_link_executable,
],
flag_groups = [
flag_group(flags = ["-flto=thin"]),
flag_group(
expand_if_available = "lto_indexing_bitcode_file",
flags = [
"-Xclang",
"-fthin-link-bitcode=%{lto_indexing_bitcode_file}",
],
),
],
),
flag_set(
actions = [action.c_compile, action.cpp_compile],
with_features = [with_feature_set(not_features = ["lto_unit"])],
flag_groups = [flag_group(flags = ["-Xclang", "-fno-lto-unit"])],
),
flag_set(
actions = [action.linkstamp_compile],
flag_groups = [flag_group(flags = ["-DBUILD_LTO_TYPE=thin"])],
),
flag_set(
actions = actions.lto_index,
flag_groups = [
flag_group(flags = [
# No need to mark flags for Clang -- this action only runs Clang.
"-flto=thin",
"-Wl,-plugin-opt,thinlto-index-only%{thinlto_optional_params_file}",
"-Wl,-plugin-opt,thinlto-emit-imports-files",
"-Wl,-plugin-opt,thinlto-prefix-replace=%{thinlto_prefix_replace}",
]),
flag_group(
expand_if_available = "thinlto_object_suffix_replace",
flags = [
"-Wl,-plugin-opt,thinlto-object-suffix-replace=%{thinlto_object_suffix_replace}",
],
),
flag_group(
expand_if_available = "thinlto_merged_object_file",
flags = [
"-Wl,-plugin-opt,obj-path=%{thinlto_merged_object_file}",
],
),
],
),
flag_set(
actions = [action.lto_backend],
flag_groups = [
flag_group(flags = [
# No need to mark flags for Clang -- this action only runs Clang.
"-c",
"-fthinlto-index=%{thinlto_index}",
"-o",
"%{thinlto_output_object_file}",
"-x",
"ir",
"%{thinlto_input_bitcode_file}",
]),
],
),
],
),
feature(name = "thin_lto_linkstatic_tests_use_shared_nonlto_backends"),
feature(name = "thin_lto_all_linkstatic_use_shared_nonlto_backends"),
# User-settable features for sanitizer modes
feature(name = "asan"),
feature(
name = "hwasan",
enabled = config.get("use_hwasan", False),
),
feature(name = "ubsan"),
# User-settable features to control optimization level
feature(
# -O3 for all compilation actions
name = "android_optimize_for_speed",
requires = [feature_set(features = ["opt"])], # Only use -O3 in opt mode.
),
# By default, we build with unwind tables, but for folks who are not using
# exceptions, and who are willing to sacrifice stack traces for size, they can
# disable this feature.
feature(
name = "android_unwind_tables",
enabled = True,
),
# User-settable feature controls warning aggressiveness for compilation.
feature(name = "warnings_as_errors"),
# Configure the header parsing and preprocessing. Blaze will test to see if
# the Crosstool supports it if the cc_toolchain specifies
# supports_header_parsing = True.
feature(name = "parse_headers"),
# We have different features for module consumers and producers:
# 'header_modules' is enabled for targets that support being compiled as a
# header module.
# 'use_header_modules' is enabled for targets that want to use the provided
# header modules from their transitive closure. We enable this globally and
# disable it for targets that do not support builds with header modules.
feature(
name = "header_modules",
requires = [
feature_set(features = ["use_header_modules"]),
],
implies = [
"header_module_compile",
],
),
feature(
name = "header_module_codegen",
requires = [
feature_set(features = ["header_modules"]),
],
),
feature(
name = "header_modules_codegen_functions",
implies = ["header_module_codegen"],
),
feature(
name = "header_modules_codegen_debuginfo",
implies = ["header_module_codegen"],
),
feature(
name = "header_module_compile",
),
feature(
name = "use_header_modules",
implies = ["use_module_maps"],
),
feature(
name = "use_module_maps",
requires = [feature_set(features = ["module_maps"])],
),
feature(
name = "module_maps",
implies = [
"module_map_home_cwd",
"module_map_without_extern_module",
"generate_submodules",
],
),
feature(name = "module_map_home_cwd"),
feature(name = "module_map_without_extern_module"),
# Indicate that the crosstool supports submodules.
feature(name = "generate_submodules"),
# Configure the strict layering check.
feature(
name = "layering_check",
implies = [
"use_module_maps",
],
),
# Disallow undefined symbols in final shared objects.
feature(
name = "no_undefined",
enabled = True,
),
# The following flag_set list defines the crucial set of flag_sets for primary
# compilation and linking. Its order is incredibly important.
feature(
name = "crosstool_compiler_flags",
enabled = True,
flag_sets = [
# Compile, Link, and CC_FLAGS make variable
flag_set(
actions = actions.all_compile_and_link + actions.cc_flags_make_variable,
flags = [
"-no-canonical-prefixes",
"--target=%s%d" % (target_system_name, api_level),
],
),
# Compile + Link
flag_set(
actions = actions.all_compile_and_link,
# This forces color diagnostics even on Forge (where we don't have an
# attached terminal).
flags = ["-fdiagnostics-color"],
),
# These flags are used to enfore the NX (no execute) security feature
# in the generated machine code. This adds a special section to the
# generated shared libraries that instruct the Linux kernel to disable
# code execution from the stack and the heap.
flag_set(
actions = actions.all_compile,
flags = ["-Wa,--noexecstack"],
),
flag_set(
actions = actions.all_link,
flags = ["-Wl,-z,noexecstack"],
),
flag_set(
actions = actions.all_link,
flags = ["-Wl,-zseparate-code", "-Wl,--no-rosegment"],
features = ["crosstool_linker_lld"],
),
# C++ compiles
flag_set(
actions = actions.all_cpp_compile,
flags = [
"-std=gnu++17",
"-Wc++2a-extensions",
"-Woverloaded-virtual",
"-Wnon-virtual-dtor",
"-Wno-deprecated",
"-fshow-overloads=best",
"-Wdeprecated-increment-bool",
"-Wimplicit-fallthrough",
"-Wno-final-dtor-non-final-class",
"-Wno-dynamic-exception-spec",
],
),
# All compiles
flag_set(
actions = actions.all_compile,
flags = [
"-faddrsig",
"-faligned-new",
"-fdata-sections",
"-ffunction-sections",
"-funsigned-char",
"-fstack-protector",
"-g",
],
),
flag_set(
actions = actions.all_compile,
flags = [
"-funwind-tables",
],
features = ["android_unwind_tables"],
),
## Options for particular compile modes:
# OPT-specific flags
flag_set(
actions = actions.preprocessor_compile,
flags = ["-DNDEBUG"],
features = ["opt"],
),
flag_set(
actions = actions.all_compile,
flags = [
"-fno-strict-aliasing",
"-fomit-frame-pointer",
"-g0",
],
features = ["opt"],
),
flag_set(
actions = actions.all_compile,
flags = [
"-Oz",
],
features = ["opt"],
not_features = ["android_optimize_for_speed"],
),
flag_set(
actions = actions.all_compile,
flags = [
"-O3",
],
features = ["opt", "android_optimize_for_speed"],
),
flag_set(
actions = actions.all_cpp_compile,
flags = ["-fvisibility-inlines-hidden"],
features = ["opt"],
),
# DBG-specific flags
flag_set(
actions = actions.all_compile,
flags = [
"-O0",
"-fno-omit-frame-pointer",
"-fno-strict-aliasing",
],
features = ["dbg"],
),
## NDK-version specific options
flag_set(
actions = actions.preprocessor_compile,
# The clang shipped with NDK r15 is a pre-release Clang 5.0
# binary, which has a buggy "clang::xray_log_args" that
# doesn't work on the 'implicit this' argument of a class
# method. It was fixed in llvm svn r305544.
flags = ["-DABSL_NO_XRAY_ATTRIBUTES"],
features = ["crosstool_disable_xray"],
),
## CPU-specific options
# ARM options
flag_set(
actions = actions.all_compile,
flags = ["-march=armv7-a", "-mfloat-abi=softfp"],
features = ["crosstool_cpu_arm"],
),
flag_set(
actions = actions.all_compile,
flags = ["-mfpu=vfpv3-d16"],
features = ["crosstool_cpu_arm"],
not_features = ["crosstool_has_neon"],
),
flag_set(
actions = actions.all_compile,
flags = ["-mfpu=neon"],
features = ["crosstool_cpu_arm", "crosstool_has_neon"],
),
flag_set(
actions = actions.all_compile,
flags = ["-mthumb"],
features = ["crosstool_cpu_arm", "opt"],
),
flag_set(
actions = actions.all_compile,
flags = ["-marm"],
features = ["crosstool_cpu_arm", "dbg"],
),
flag_set(
actions = actions.all_link,
flags = ["-Wl,--fix-cortex-a8", "-march=armv7-a"],
features = ["crosstool_cpu_arm"],
),
flag_set(
actions = actions.all_link,
flags = ["-Wl,-z,max-page-size=4096"],
features = ["crosstool_cpu_arm64", "crosstool_linker_lld"],
),
# X86 options
flag_set(
actions = actions.all_compile,
flags = ["-mstackrealign"],
features = ["crosstool_cpu_x86", "crosstool_needs_stackrealign"],
),
## Warning flag sets
flag_set(
actions = actions.all_compile,
flags = ["-Werror"],
features = ["warnings_as_errors"],
),
# Generic warning flag list
flag_set(
actions = actions.all_compile,
flags = [
"-Wall",
"-Wformat-security",
"-Wno-char-subscripts",
"-Wno-error=deprecated-declarations",
"-Wno-maybe-uninitialized",
"-Wno-sign-compare",
"-Wno-strict-overflow",
"-Wno-unused-but-set-variable",
"-Wunused-but-set-parameter",
"-Wno-unknown-warning-option",
"-Wno-unused-command-line-argument",
"-Wno-ignored-optimization-argument",
# Disable some broken warnings from Clang.
"-Wno-ambiguous-member-template",
"-Wno-char-subscripts",
"-Wno-error=deprecated-declarations",
"-Wno-extern-c-compat",
"-Wno-gnu-alignof-expression",
"-Wno-gnu-variable-sized-type-not-at-end",
"-Wno-implicit-int-float-conversion",
"-Wno-invalid-source-encoding",
"-Wno-mismatched-tags",
"-Wno-pointer-sign",
"-Wno-private-header",
"-Wno-sign-compare",
"-Wno-signed-unsigned-wchar",
"-Wno-strict-overflow",
"-Wno-trigraphs",
"-Wno-unknown-pragmas",
"-Wno-unused-const-variable",
"-Wno-unused-function",
"-Wno-unused-private-field",
"-Wno-user-defined-warnings",
# Low SNR or otherwise not desirable.
"-Wno-extern-c-compat",
"-Wno-gnu-alignof-expression",
"-Wno-gnu-designator",
"-Wno-gnu-variable-sized-type-not-at-end",
"-Wno-invalid-source-encoding",
"-Wno-mismatched-tags",
"-Wno-reserved-user-defined-literal",
"-Wno-return-type-c-linkage",
"-Wno-self-assign-overloaded",
"-Wno-tautological-constant-in-range-compare",
"-Wno-unknown-pragmas",
"-Wfloat-overflow-conversion",
"-Wfloat-zero-conversion",
"-Wfor-loop-analysis",
"-Wgnu-redeclared-enum",
"-Winfinite-recursion",
"-Wliteral-conversion",
"-Wself-assign",
"-Wstring-conversion",
"-Wtautological-overlap-compare",
"-Wunused-comparison",
"-Wvla",
# Turn on thread safety analysis.
"-Wthread-safety-analysis",
],
),
# C++-specific warning flags
flag_set(
actions = actions.all_cpp_compile,
flags = [
"-Wno-deprecated",
"-Wdeprecated-increment-bool",
"-Wnon-virtual-dtor",
"-Woverloaded-virtual",
],
),
# Defines and Includes and Paths and such
flag_set(
actions = actions.all_compile,
flag_groups = [
flag_group(flags = ["-fPIC"]),
],
),
flag_set(
actions = actions.all_compile,
flag_groups = [
flag_group(
flags = ["-gsplit-dwarf", "-g"],
expand_if_available = "per_object_debug_info_file",
),
],
),
flag_set(
actions = actions.preprocessor_compile,
flag_groups = [
flag_group(
flags = ["-D%{preprocessor_defines}"],
iterate_over = "preprocessor_defines",
),
],
),
flag_set(
actions = actions.preprocessor_compile,
flag_groups = [
flag_group(
flags = ["-include", "%{includes}"],
iterate_over = "includes",
expand_if_available = "includes",
),
],
),
flag_set(
actions = actions.preprocessor_compile,
flag_groups = [
flag_group(
flags = ["-iquote", "%{quote_include_paths}"],
iterate_over = "quote_include_paths",
),
flag_group(
flags = ["-I%{include_paths}"],
iterate_over = "include_paths",
),
flag_group(
flags = ["-isystem", "%{system_include_paths}"],
iterate_over = "system_include_paths",
),
],
),
## Linking options (not libs -- those go last)
# Generic link options
flag_set(
actions = actions.all_link,
flags = [
"-Wl,--gc-sections",
# Never re-export libgcc.a symbols.
"-Wl,--exclude-libs,libgcc.a",
"-Wl,--build-id=md5",
# Force JNI symbols to be linked.
"-Wl,--undefined-glob='Java_*'",
"-Wl,--undefined-glob='JNI_*'",
],
),
flag_set(
actions = actions.all_link,
flag_groups = [
flag_group(
flags = ["-Wl,--print-symbol-counts=%{symbol_counts_output}"],
expand_if_available = "symbol_counts_output",
),
],
),
flag_set(
actions = actions.all_link,
flag_groups = [
flag_group(
flags = ["-Wl,--gdb-index"],
expand_if_available = "is_using_fission",
),
],
),
flag_set(
actions = actions.all_link,
flag_groups = [
flag_group(
flags = ["-Wl,-s"],
expand_if_available = "strip_debug_symbols",
),
],
with_features = [with_feature_set(features = ["linker_fully_strip"])],
),
flag_set(
actions = actions.all_link,
flag_groups = [
flag_group(
flags = ["-Wl,-S"],
expand_if_available = "strip_debug_symbols",
),
],
with_features = [with_feature_set(not_features = ["linker_fully_strip"])],
),
flag_set(
actions = [action.cpp_link_executable],
flags = ["-pie"],
),
flag_set(
# Dynamic Link Actions only:
actions = [
action.cpp_link_dynamic_library,
action.cpp_link_nodeps_dynamic_library,
action.lto_index_for_dynamic_library,
action.lto_index_for_nodeps_dynamic_library,
],
# In API >= 23, having a TEXTREL section will stop the system
# from loading the so. Catch this at link time.
flags = ["-shared", "-Wl,-z,text"],
),
flag_set(
actions = actions.all_link,
# Never re-export libunwind.a symbols.
flags = ["-Wl,--exclude-libs,libunwind.a"],
),
# LLD/Gold specific linking options
flag_set(
actions = actions.all_link,
flags = ["-fuse-ld=gold"],