@@ -39,9 +39,20 @@ def cc_toolchain_config(name, host_platform, custom_target_triple = None, overri
39
39
40
40
" extra_compile_flags" : list[string],
41
41
" extra_linker_flags" : list[string],
42
- " omit_hosted_linker_flags" : bool,
43
- " omit_cxx_stdlib_flag" : bool,
44
- " use_llvm_ar_instead_of_libtool_on_macos" : bool,
42
+ " custom_linker_tool" : {
43
+ " darwin" : string,
44
+ " k8" : string,
45
+ } ,
46
+ "omit_hosted_linker_flags": bool = False,
47
+
48
+ "linker_include_build_id_on_linux_hosts": bool = True,
49
+ "linker_use_gnu_hash_style_on_linux_hosts": bool = True,
50
+ "linker_use_elf_hardening_so_flags_on_linux_hosts": bool = True,
51
+
52
+ "prefer_static_cxx_libs_on_linux_hosts": bool = True,
53
+ "omit_cxx_stdlib_flag": bool = False,
54
+
55
+ "use_llvm_ar_instead_of_libtool_on_macos": bool = False,
45
56
}
46
57
```
47
58
"""
@@ -118,12 +129,19 @@ def cc_toolchain_config(name, host_platform, custom_target_triple = None, overri
118
129
# The linker has no way of knowing if there are C++ objects; so we
119
130
# always link C++ libraries.
120
131
"-L%{ toolchain_path_prefix} /lib",
132
+ ]
133
+
134
+ # Unless the target has a compelling reason not to want to do so (i.e.
135
+ # has a special linker that doesn't support this syntax), we'd like to
136
+ # prefer _statically_ linking the C++ libraries:
137
+ prefer_static_cxx_libs_on_linux_hosts =
138
+ overrides.get("prefer_static_cxx_libs_on_linux_hosts", True)
139
+ linker_flags += [
121
140
"-l:libc++.a",
122
141
"-l:libc++abi.a",
123
- # Other linker flags.
124
- "-Wl,--build-id=md5",
125
- "-Wl,--hash-style=gnu",
126
- "-Wl,-z,relro,-z,now",
142
+ ] if prefer_static_cxx_libs_on_linux_hosts else [
143
+ "-lc++",
144
+ "-lc++abi",
127
145
]
128
146
129
147
if enable_hosted_linker_flags:
@@ -135,6 +153,14 @@ def cc_toolchain_config(name, host_platform, custom_target_triple = None, overri
135
153
"-lpthread",
136
154
"-ldl",
137
155
]
156
+
157
+ # Other linker flags.
158
+ if overrides.get("linker_include_build_id_on_linux_hosts", True):
159
+ linker_flags += ["-Wl,--build-id=md5"]
160
+ if overrides.get("linker_use_gnu_hash_style_on_linux_hosts", True):
161
+ linker_flags += ["-Wl,--hash-style=gnu"]
162
+ if overrides.get("linker_use_elf_hardening_so_flags_on_linux_hosts", True):
163
+ linker_flags += ["-Wl,-z,relro,-z,now"]
138
164
elif host_platform == "darwin":
139
165
linker_flags = [
140
166
# Difficult to guess options to statically link C++ libraries with
0 commit comments