xref: /aosp_15_r20/external/tensorflow/tensorflow/tools/toolchains/clang6/CROSSTOOL.tpl (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1major_version: "v1"
2minor_version: "llvm:6.0.0"
3default_target_cpu: "k8"
4
5default_toolchain {
6  cpu: "k8"
7  toolchain_identifier: "k8-clang-6.0-cxx-4.8-linux-gnu"
8}
9
10toolchain {
11  compiler: "clang6"         # bazel build --compiler=clang6
12  target_cpu: "k8"           # bazel build --cpu=k8
13  target_libc: "GLIBC_2.19"  # bazel build --glibc=GLIBC_2.19
14
15  abi_libc_version: "2.19"
16  abi_version: "gcc-4.8-cxx11"
17  builtin_sysroot: ""
18  cc_target_os: "linux-gnu"
19  default_python_version: "python2.7"
20  dynamic_runtimes_filegroup: "dynamic-runtime-libs-k8"
21  host_system_name: "x86_64-unknown-linux-gnu"
22  needsPic: true
23  static_runtimes_filegroup: "static-runtime-libs-k8"
24  supports_embedded_runtimes: true
25  supports_fission: true
26  supports_gold_linker: true
27  supports_incremental_linker: true
28  supports_interface_shared_objects: true
29  supports_normalizing_ar: true
30  supports_start_end_lib: true
31  supports_thin_archives: true
32  target_system_name: "x86_64-unknown-linux-gnu"
33  toolchain_identifier: "k8-clang-6.0-cxx-4.8-linux-gnu"
34
35  tool_path { name: "ar" path: "%package(@local_config_clang6//clang6)%/llvm/bin/llvm-ar" }
36  tool_path { name: "as" path: "%package(@local_config_clang6//clang6)%/llvm/bin/llvm-as" }
37  tool_path { name: "compat-ld" path: "%package(@local_config_clang6//clang6)%/llvm/bin/ld.lld" }
38  tool_path { name: "cpp" path: "%package(@local_config_clang6//clang6)%/llvm/bin/llvm-cpp" }
39  tool_path { name: "dwp" path: "%package(@local_config_clang6//clang6)%/llvm/bin/llvm-dwp" }
40  tool_path { name: "gcc" path: "%package(@local_config_clang6//clang6)%/llvm/bin/clang" }
41  tool_path { name: "gcov" path: "%package(@local_config_clang6//clang6)%/llvm/bin/llvm-cov" }
42  tool_path { name: "ld" path: "%package(@local_config_clang6//clang6)%/llvm/bin/ld.lld" }
43  tool_path { name: "llvm-profdata" path: "%package(@local_config_clang6//clang6)%/llvm/bin/llvm-profdata" }
44  tool_path { name: "nm" path: "%package(@local_config_clang6//clang6)%/llvm/bin/llvm-nm" }
45  tool_path { name: "objcopy" path: "%package(@local_config_clang6//clang6)%/llvm/bin/llvm-objcopy" }
46  tool_path { name: "objdump" path: "%package(@local_config_clang6//clang6)%/sbin/objdump" }
47  tool_path { name: "strip" path: "%package(@local_config_clang6//clang6)%/sbin/strip" }
48
49  unfiltered_cxx_flag: "-no-canonical-prefixes"
50
51  # Make C++ compilation deterministic. Use linkstamping instead of these
52  # compiler symbols.
53  unfiltered_cxx_flag: "-Wno-builtin-macro-redefined"
54  unfiltered_cxx_flag: "-D__DATE__=\"redacted\""
55  unfiltered_cxx_flag: "-D__TIMESTAMP__=\"redacted\""
56  unfiltered_cxx_flag: "-D__TIME__=\"redacted\""
57
58  objcopy_embed_flag: "-I"
59  objcopy_embed_flag: "binary"
60
61  # This action_config makes features flags propagate
62  # to CC_FLAGS for genrules, and eventually skylark.
63  action_config {
64    action_name: "cc-flags-make-variable"
65    config_name: "cc-flags-make-variable"
66  }
67
68  # Security hardening on by default.
69  # Conservative choice; -D_FORTIFY_SOURCE=2 may be unsafe in some cases.
70  # We need to undef it before redefining it as some distributions now have
71  # it enabled by default.
72  compiler_flag: "-U_FORTIFY_SOURCE"
73  compiler_flag: "-D_FORTIFY_SOURCE=1"
74  compiler_flag: "-fstack-protector"
75  linker_flag: "-Wl,-z,relro,-z,now"
76
77  # TODO(b/151234342): Clean up the following options.
78  # This adds a little bit more durability to our Clang build.
79  #
80  # Folks who do maintenance work on TF Bazel Clang should consider
81  # commenting out these lines, while doing that work, to gain a better
82  # understanding of what the intersection of support looks like between GCC
83  # and Clang. Please note that Bazel does not support -Xclang-only.
84  compiler_flag: "-Wno-unknown-warning-option"
85  compiler_flag: "-Wno-unused-command-line-argument"
86  compiler_flag: "-Wno-ignored-optimization-argument"
87
88  #### Common compiler options. ####
89  compiler_flag: "-D_REENTRANT"
90  compiler_flag: "-D__STDC_FORMAT_MACROS"
91  compiler_flag: "-DSUPPRESS_USE_FILE_OFFSET64"
92  compiler_flag: "-Wall"
93  compiler_flag: "-Wformat-security"
94  compiler_flag: "-Wframe-larger-than=16384"
95  compiler_flag: "-Wno-char-subscripts"
96  compiler_flag: "-Wno-error=deprecated-declarations"
97  compiler_flag: "-Wno-uninitialized"
98  compiler_flag: "-Wno-sign-compare"
99  compiler_flag: "-Wno-strict-overflow"
100  compiler_flag: "-Wno-unused-function"
101  compiler_flag: "-fdiagnostics-show-option"
102  compiler_flag: "-fmessage-length=0"
103  compiler_flag: "-fno-exceptions"
104  compiler_flag: "-fno-omit-frame-pointer"
105  compiler_flag: "-fno-strict-aliasing"
106  compiler_flag: "-fno-use-init-array"
107  compiler_flag: "-funsigned-char"
108  compiler_flag: "-gmlt"
109  cxx_flag: "-Wno-deprecated"
110  cxx_flag: "-Wno-invalid-offsetof"  # Needed for protobuf code (2017-11-07)
111  cxx_flag: "-fshow-overloads=best"
112  compiler_flag: "-Wthread-safety-analysis"
113
114  # Python extensions unfortunately make this go wild.
115  compiler_flag: "-Wno-writable-strings"
116
117  # GCC's warning produces too many false positives:
118  cxx_flag: "-Woverloaded-virtual"
119  cxx_flag: "-Wnon-virtual-dtor"
120
121  # Enable coloring even if there's no attached terminal. Bazel removes the
122  # escape sequences if --nocolor is specified. This isn't supported by gcc
123  # on Ubuntu 14.04.
124  compiler_flag: "-fcolor-diagnostics"
125
126  # Disable some broken warnings from Clang.
127  compiler_flag: "-Wno-ambiguous-member-template"
128  compiler_flag: "-Wno-pointer-sign"
129
130  # These warnings have a low signal to noise ratio.
131  compiler_flag: "-Wno-reserved-user-defined-literal"
132  compiler_flag: "-Wno-return-type-c-linkage"
133  compiler_flag: "-Wno-invalid-source-encoding"
134
135  # Per default we switch off any layering related warnings.
136  compiler_flag: "-Wno-private-header"
137
138  # Clang-specific warnings that we explicitly enable for TensorFlow. Some of
139  # these aren't on by default, or under -Wall, or are subsets of warnings
140  # turned off above.
141  compiler_flag: "-Wfloat-overflow-conversion"
142  compiler_flag: "-Wfloat-zero-conversion"
143  compiler_flag: "-Wfor-loop-analysis"
144  compiler_flag: "-Wgnu-redeclared-enum"
145  compiler_flag: "-Winfinite-recursion"
146  compiler_flag: "-Wliteral-conversion"
147  compiler_flag: "-Wself-assign"
148  compiler_flag: "-Wstring-conversion"
149  compiler_flag: "-Wtautological-overlap-compare"
150  compiler_flag: "-Wunused-comparison"
151  compiler_flag: "-Wvla"
152  cxx_flag: "-Wdeprecated-increment-bool"
153
154  # Clang code-generation flags for performance optimization.
155  compiler_flag: "-faligned-allocation"
156  compiler_flag: "-fnew-alignment=8"
157
158  # Clang defaults to C99 while GCC defaults to C89. GCC plugins are written in
159  # C89 and don't have a BUILD rule we could add a copts flag to.
160  gcc_plugin_compiler_flag: "-std=gnu89"
161
162  compilation_mode_flags {
163    mode: FASTBUILD
164  }
165
166  compilation_mode_flags {
167    mode: DBG
168    compiler_flag: "-g"
169  }
170
171  compilation_mode_flags {
172    mode: OPT
173    compiler_flag: "-g0"
174    compiler_flag: "-fdebug-types-section"
175    compiler_flag: "-DNDEBUG"
176    compiler_flag: "-fno-split-dwarf-inlining"
177    compiler_flag: "-Os"
178    compiler_flag: "-fexperimental-new-pass-manager"
179    compiler_flag: "-fdebug-info-for-profiling"
180    compiler_flag: "-ffunction-sections"
181    compiler_flag: "-fdata-sections"
182    linker_flag: "-Wl,--gc-sections"
183    linker_flag: "-Wl,-z,relro,-z,now"
184  }
185
186  # Features indicating whether this is a host compile or not. Exactly one of
187  # these will be implicitly provided by bazel.
188  feature { name: "host" }
189  feature { name: "nonhost" }
190
191  # Features indicating which compiler will be used for code generation.
192  feature {
193    name: "llvm_codegen"
194    provides: "codegen"
195    enabled: true
196  }
197
198  # Features for compilation modes. Exactly one of these will be implicitly
199  # provided by bazel.
200  feature { name: "fastbuild" }
201  feature { name: "dbg" }
202  feature { name: "opt" }
203
204  # Features controlling the C++ language mode.
205  feature {
206    name: "c++11"
207    provides: "c++std"
208    flag_set {
209      action: "c++-compile"
210      action: "c++-header-parsing"
211      action: "c++-header-preprocessing"
212      action: "c++-module-compile"
213      action: "linkstamp-compile"
214      flag_group {
215        flag: "-nostdinc++"
216        flag: "-std=c++11"
217        flag: "-Wc++14-extensions"
218        flag: "-Wc++2a-extensions"
219        flag: "-Wno-binary-literal"
220      }
221    }
222  }
223  feature {
224    name: "c++14"
225    provides: "c++std"
226    flag_set {
227      action: "c++-compile"
228      action: "c++-header-parsing"
229      action: "c++-header-preprocessing"
230      action: "c++-module-compile"
231      action: "linkstamp-compile"
232      flag_group {
233        flag: "-nostdinc++"
234        flag: "-std=c++14"
235        flag: "-Wc++11-compat"
236        flag: "-Wno-c++11-compat-binary-literal"
237        flag: "-Wc++2a-extensions"
238      }
239    }
240  }
241  feature {
242    name: "c++17"
243    provides: "c++std"
244    flag_set {
245      action: "c++-compile"
246      action: "c++-header-parsing"
247      action: "c++-header-preprocessing"
248      action: "c++-module-compile"
249      action: "linkstamp-compile"
250      flag_group {
251        flag: "-nostdinc++"
252        flag: "-std=c++17"
253        flag: "-Wc++11-compat"
254        flag: "-Wno-c++11-compat-binary-literal"
255        flag: "-Wc++2a-extensions"
256      }
257    }
258  }
259  feature {
260    name: "c++2a"
261    provides: "c++std"
262    flag_set {
263      action: "c++-compile"
264      action: "c++-header-parsing"
265      action: "c++-header-preprocessing"
266      action: "c++-module-compile"
267      action: "linkstamp-compile"
268      flag_group {
269        flag: "-nostdinc++"
270        flag: "-std=c++2a"
271        flag: "-Wc++11-compat"
272        flag: "-Wno-c++11-compat-binary-literal"
273      }
274    }
275  }
276  feature {
277    name: "c++default"
278    enabled: true
279    flag_set {
280      # Provide the c++11 flags if no standard is selected
281      with_feature {
282        not_feature: "c++11"
283        not_feature: "c++14"
284        not_feature: "c++17"
285        not_feature: "c++2a"
286      }
287      action: "c++-compile"
288      action: "c++-header-parsing"
289      action: "c++-header-preprocessing"
290      action: "c++-module-compile"
291      action: "linkstamp-compile"
292      flag_group {
293        flag: "-nostdinc++"
294        flag: "-std=c++11"
295        flag: "-Wc++14-extensions"
296        flag: "-Wc++2a-extensions"
297        flag: "-Wno-binary-literal"
298      }
299    }
300  }
301
302  feature {
303    name: "use_compiler_rt"
304    requires { feature: "llvm_codegen" }
305    # TODO(saugustine): At the moment, "use_compiler_rt" also
306    # requires "linking_mode_flags { mode: FULLY_STATIC" ... },
307    # but that isn't a feature. We should probably convert it.
308    flag_set {
309      action: "c++-link"
310      action: "c++-link-interface-dynamic-library"
311      action: "c++-link-dynamic-library"
312      action: "c++-link-executable"
313      # "link" is a misnomer for these actions. They are really just
314      # invocations of ar.
315      #action: "c++-link-pic-static-library"
316      #action: "c++-link-static-library"
317      #action: "c++-link-alwayslink-static-library"
318      #action: "c++-link-pic-static-library"
319      #action: "c++-link-alwayslink-pic-static-library"
320      flag_group {
321        flag: "-rtlib=compiler-rt"
322        flag: "-lunwind"
323      }
324    }
325  }
326
327  feature {
328    name: "pie"
329    flag_set {
330      action: "assemble"
331      action: "preprocess-assemble"
332      action: "c-compile"
333      action: "c++-compile"
334      action: "c++-header-parsing"
335      action: "c++-header-preprocessing"
336      action: "c++-module-compile"
337      action: "c++-module-codegen"
338      action: "cc-flags-make-variable"
339      action: "lto-backend"
340      action: "linkstamp-compile"
341      flag_group {
342        flag: "-mpie-copy-relocations"
343        flag: "-fPIE"
344      }
345    }
346    flag_set {
347      action: "cc-flags-make-variable"
348      action: "c++-link-executable"
349      flag_group {
350        flag: "-pie"
351      }
352    }
353  }
354
355  # Pic must appear after pie, because pic may need to override pie, and bazel
356  # turns it on selectively. These don't interact with other options.
357  #
358  # TODO: In practice, normal vs pic vs pie is a ternary mode. We should
359  # implement it that way. This will require changes to bazel, which only
360  # calculates whether or not pic is needed, not pie.
361  #
362  # NOTE: Bazel might make this all a moot point.
363  feature {
364    name: "pic"
365    flag_set {
366      action: "assemble"
367      action: "preprocess-assemble"
368      action: "c-compile"
369      action: "c++-compile"
370      action: "c++-module-codegen"
371      action: "c++-module-compile"
372      action: "linkstamp-compile"
373      expand_if_all_available: "pic"
374      flag_group {
375        flag: "-fPIC"
376      }
377    }
378  }
379
380  feature {
381    name: "gold"
382    enabled: true
383    flag_set {
384      action: "c++-link-executable"
385      action: "c++-link-dynamic-library"
386      action: "c++-link-interface-dynamic-library"
387      flag_group {
388        expand_if_none_available: "lto"
389        flag: "-fuse-ld=gold"
390      }
391    }
392  }
393
394  # This is great if you want linking TensorFlow to take ten minutes.
395  feature {
396    name: "lto"
397    requires { feature: "nonhost" }
398    flag_set {
399      action: "c-compile"
400      action: "c++-compile"
401      flag_group {
402        flag: "-flto=thin"
403      }
404    }
405    flag_set {
406      action: "c++-link-executable"
407      action: "c++-link-dynamic-library"
408      action: "c++-link-interface-dynamic-library"
409      flag_group {
410        flag: "-flto=thin"
411      }
412    }
413  }
414
415  feature {
416    name: "parse_headers"
417    flag_set {
418      action: "c++-header-parsing"
419      flag_group {
420        flag: "-xc++-header"
421        flag: "-fsyntax-only"
422      }
423    }
424  }
425
426  feature {
427    name: "preprocess_headers"
428    flag_set {
429      action: "c++-header-preprocessing"
430      flag_group {
431        flag: "-xc++"
432        flag: "-E"
433      }
434    }
435  }
436
437  feature {
438    name: "per_object_debug_info"
439    flag_set {
440      action: "c-compile"
441      action: "c++-compile"
442      action: "c++-module-codegen"
443      action: "assemble"
444      action: "preprocess-assemble"
445      action: "lto-backend"
446      flag_group {
447        flag: "-gsplit-dwarf"
448        flag: "-ggnu-pubnames"
449      }
450    }
451    flag_set {
452      action: "c++-link-executable"
453      action: "c++-link-dynamic-library"
454      action: "c++-link-interface-dynamic-library"
455      flag_group {
456        expand_if_all_available: "is_using_fission"
457        flag: "-Wl,--gdb-index"
458      }
459    }
460  }
461
462  feature {
463    name: "xray"
464    requires {
465      feature: "llvm_codegen"
466      feature: "nonhost"
467    }
468    flag_set {
469      action: "c-compile"
470      action: "c++-compile"
471      action: "c++-header-parsing"
472      action: "c++-header-preprocessing"
473      action: "c++-module-compile"
474      action: "c++-link-interface-dynamic-library"
475      action: "c++-link-dynamic-library"
476      action: "c++-link-executable"
477      flag_group {
478        flag: "-fxray-instrument"
479      }
480    }
481  }
482
483  feature {
484    name: "minimal_ubsan"
485    requires { feature: "llvm_codegen" }
486    flag_set {
487      action: "c-compile"
488      action: "c++-compile"
489      action: "c++-header-parsing"
490      action: "c++-header-preprocessing"
491      action: "c++-module-compile"
492      action: "c++-module-codegen"
493      flag_group {
494        flag: "-fsanitize=return,returns-nonnull-attribute,vla-bound,unreachable,float-cast-overflow"
495        flag: "-fsanitize-trap=all"
496        flag: "-DUNDEFINED_BEHAVIOR_SANITIZER"
497      }
498    }
499  }
500
501  feature {
502    name: "minimal_ubsan_enabled_by_default"
503    requires {
504      feature: "llvm_codegen"
505      feature: "fastbuild"
506    }
507    enabled: true
508    implies: "minimal_ubsan"
509  }
510
511  cxx_builtin_include_directory: "%package(@local_config_clang6//clang6)%/llvm/lib/clang/6.0.0/include"
512  cxx_builtin_include_directory: "/usr/include"
513
514  unfiltered_cxx_flag: "-cxx-isystem"
515  unfiltered_cxx_flag: "/usr/include/c++/4.8"
516  unfiltered_cxx_flag: "-cxx-isystem"
517  unfiltered_cxx_flag: "/usr/include/x86_64-linux-gnu/c++/4.8"
518  unfiltered_cxx_flag: "-isystem"
519  unfiltered_cxx_flag: "%package(@local_config_clang6//clang6)%/llvm/lib/clang/6.0.0/include"
520  unfiltered_cxx_flag: "-isystem"
521  unfiltered_cxx_flag: "/usr/include/x86_64-linux-gnu"
522  unfiltered_cxx_flag: "-isystem"
523  unfiltered_cxx_flag: "/usr/include"
524
525  linker_flag: "-Wl,--build-id=md5"
526  linker_flag: "-Wl,--fatal-warnings"
527  linker_flag: "-Wl,--hash-style=gnu"
528  linker_flag: "-no-canonical-prefixes"
529  linker_flag: "--target=x86_64-unknown-linux-gnu"
530
531  linker_flag: "-L/usr/lib/gcc/x86_64-linux-gnu/4.8"
532
533  # This is the minimum x86 architecture TensorFlow supports.
534  compiler_flag: "-m64"
535
536  # These are for Linux.
537  ld_embed_flag: "-melf_x86_64"
538  linker_flag: "-Wl,--eh-frame-hdr"
539  linker_flag: "-Wl,-z,max-page-size=0x1000"
540
541  # Google never uses the stack like a heap, e.g. alloca(), because tcmalloc
542  # and jemalloc are so fast. However copts=["$(STACK_FRAME_UNLIMITED)"] can be
543  # specified when that can't be the case.
544  make_variable {
545    name: "STACK_FRAME_UNLIMITED"
546    value: "-Wframe-larger-than=100000000 -Wno-vla"
547  }
548
549  # These flags are for folks who build C/C++ code inside genrules.
550  make_variable {
551    name: "CC_FLAGS"
552    value: "-no-canonical-prefixes --target=x86_64-unknown-linux-gnu -fno-omit-frame-pointer -fno-tree-vrp -msse3"
553  }
554
555  feature {
556    name: "copts"
557    flag_set {
558      expand_if_all_available: "copts"
559      action: "assemble"
560      action: "preprocess-assemble"
561      action: "c-compile"
562      action: "c++-compile"
563      action: "c++-header-parsing"
564      action: "c++-header-preprocessing"
565      action: "c++-module-compile"
566      action: "c++-module-codegen"
567      action: "lto-backend"
568      flag_group {
569        iterate_over: "copts"
570        flag: "%{copts}"
571      }
572    }
573  }
574
575  # Please do not statically link libstdc++. This would probably lead to a lot
576  # of bloat since OpKernels need to use linkstatic=1 because  b/27630669 and
577  # it could cause memory leaks since Python uses dlopen() on our libraries:
578  # https://stackoverflow.com/a/35015415
579  linker_flag: "-lstdc++"
580  linker_flag: "-lm"
581  linker_flag: "-lpthread"
582  linker_flag: "-l:/lib/x86_64-linux-gnu/libc-2.19.so"
583}
584