Skip to content

Commit c000c9e

Browse files
authored
[Bazel] Export compiler-rt builtins sources (#157200)
This provides a structured collection of the source files used in the compiler-rt builtins library in Bazel. Normal build rules often don't work for runtime libraries as they may need to be built for a specific target platform and in an environment with the associated SDK available to build for that target. Instead, this PR exports the sources in a structured way that can be used by downstream users to collect and build these runtimes in a target-appropriate manner. Currently, this includes AArch64, AArch32 (with and without VFP), x86-64, i386, PPC, and RISC-V. Where I could see a useful division of functionality, those are also exposed. The rules use over-wide globs to minimize the need to manually update lists of files or to risk things slipping out of date.
1 parent 49f28f6 commit c000c9e

File tree

2 files changed

+308
-1
lines changed

2 files changed

+308
-1
lines changed

utils/bazel/llvm-project-overlay/compiler-rt/BUILD.bazel

Lines changed: 302 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,305 @@ cc_library(
113113
":orc_rt_common_headers",
114114
],
115115
)
116+
117+
BUILTINS_CRTBEGIN_SRCS = ["lib/builtins/crtbegin.c"]
118+
119+
filegroup(
120+
name = "builtins_crtbegin_src",
121+
srcs = BUILTINS_CRTBEGIN_SRCS,
122+
)
123+
124+
BUILTINS_CRTEND_SRCS = ["lib/builtins/crtend.c"]
125+
126+
filegroup(
127+
name = "builtins_crtend_src",
128+
srcs = BUILTINS_CRTEND_SRCS,
129+
)
130+
131+
BUILTINS_HOSTED_SRCS = [
132+
"lib/builtins/clear_cache.c",
133+
"lib/builtins/emutls.c",
134+
"lib/builtins/enable_execute_stack.c",
135+
"lib/builtins/eprintf.c",
136+
]
137+
138+
# Source files in the builtins library that build on top of libc and are only
139+
# appropriate in hosted environments.
140+
filegroup(
141+
name = "builtins_hosted_srcs",
142+
srcs = BUILTINS_HOSTED_SRCS,
143+
)
144+
145+
BUILTINS_BF16_SRCS_PATTERNS = [
146+
"lib/builtins/*bf*.c",
147+
]
148+
149+
# Source files for the 16-bit Brain floating-point number builtins.
150+
filegroup(
151+
name = "builtins_bf16_srcs",
152+
srcs = glob(BUILTINS_BF16_SRCS_PATTERNS),
153+
)
154+
155+
BUILTINS_X86_FP80_SRCS_PATTERNS = [
156+
# `xc` marks 80-bit complex number builtins.
157+
"lib/builtins/*xc*.c",
158+
159+
# `xf` marks 80-bit floating-point builtins.
160+
"lib/builtins/*xf*.c",
161+
]
162+
163+
# Source files for the 80-bit floating-point and complex number builtins.
164+
filegroup(
165+
name = "builtins_x86_fp80_srcs",
166+
srcs = glob(
167+
BUILTINS_X86_FP80_SRCS_PATTERNS,
168+
exclude = BUILTINS_BF16_SRCS_PATTERNS,
169+
),
170+
)
171+
172+
BUILTINS_TF_SRCS_PATTERNS = [
173+
# `tc` marks 128-bit complex number builtins.
174+
"lib/builtins/*tc*.c",
175+
176+
# `tf` marks 128-bit floating-point builtins.
177+
"lib/builtins/*tf*.c",
178+
]
179+
180+
BUILTINS_TF_EXCLUDES = (
181+
BUILTINS_HOSTED_SRCS +
182+
BUILTINS_BF16_SRCS_PATTERNS +
183+
BUILTINS_X86_FP80_SRCS_PATTERNS
184+
)
185+
186+
# Source files for the 128-bit floating-point and complex number builtins.
187+
filegroup(
188+
name = "builtins_tf_srcs",
189+
srcs = glob(
190+
BUILTINS_TF_SRCS_PATTERNS,
191+
exclude = BUILTINS_TF_EXCLUDES,
192+
),
193+
)
194+
195+
BUILTNS_ATOMICS_SRCS = ["lib/builtins/atomic.c"]
196+
197+
filegroup(
198+
name = "builtins_atomics_srcs",
199+
srcs = BUILTNS_ATOMICS_SRCS + ["lib/builtins/assembly.h"],
200+
)
201+
202+
BUILTINS_MACOS_ATOMIC_SRCS_PATTERNS = [
203+
"lib/builtins/atomic_*.c",
204+
]
205+
206+
# Source files for macOS atomic builtins.
207+
filegroup(
208+
name = "builtins_macos_atomic_srcs",
209+
srcs = glob(BUILTINS_MACOS_ATOMIC_SRCS_PATTERNS),
210+
)
211+
212+
# Apple-platform specific SME source file.
213+
filegroup(
214+
name = "builtins_aarch64_apple_sme_srcs",
215+
srcs = ["lib/builtins/aarch64/arm_apple_sme_abi.s"],
216+
)
217+
218+
# Non-Apple platform SME sources. These sources assume function
219+
# multi-versioning, `-fno-builtin`, `__ARM_UNALIGNED` feature support, and FP
220+
# availability. Other configurations will need to add a new filegroup if
221+
# desired.
222+
filegroup(
223+
name = "builtins_aarch64_sme_srcs",
224+
srcs = [
225+
"lib/builtins/aarch64/sme-abi.S",
226+
"lib/builtins/aarch64/sme-abi-assert.c",
227+
] + glob(["lib/builtins/aarch64/sme-libc-opt-*.S"]),
228+
)
229+
230+
# A list of (pat, size, model) tuples for AArch64's outline atomics.
231+
AARCH64_OUTLINE_ATOMICS = [
232+
(pat, size, model)
233+
for pat in [
234+
"cas",
235+
"swp",
236+
"ldadd",
237+
"ldclr",
238+
"ldeor",
239+
"ldset",
240+
]
241+
for size in [
242+
"1",
243+
"2",
244+
"4",
245+
"8",
246+
"16",
247+
]
248+
for model in [
249+
"1",
250+
"2",
251+
"3",
252+
"4",
253+
]
254+
if pat == "cas" or size != "16"
255+
]
256+
257+
AARCH64_OUTLINE_ATOMICS_FMT = "lib/builtins/aarch64/outline_atomic_{0}{1}_{2}.S"
258+
259+
# lse.S is compiled multiple times with different macros as the input. Model
260+
# this as a genrule producing individual files with the macros at the start.
261+
[[genrule(
262+
name = "builtins_aarch64_outline_atomic_" + pat + size + "_" + model,
263+
srcs = ["lib/builtins/aarch64/lse.S"],
264+
outs = [AARCH64_OUTLINE_ATOMICS_FMT.format(pat, size, model)],
265+
cmd = (
266+
"echo '#define L_" + pat + "' >> $(OUTS) && " +
267+
"echo '#define SIZE " + size + "' >> $(OUTS) && " +
268+
"echo '#define MODEL " + model + "' >> $(OUTS) && " +
269+
"cat $(SRCS) >> $(OUTS)"
270+
),
271+
)] for (pat, size, model) in AARCH64_OUTLINE_ATOMICS]
272+
273+
# Source files for the AArch64 architecture-specific builtins.
274+
filegroup(
275+
name = "builtins_aarch64_srcs",
276+
srcs = [
277+
"lib/builtins/cpu_model/aarch64.c",
278+
"lib/builtins/cpu_model/aarch64.h",
279+
] + [
280+
AARCH64_OUTLINE_ATOMICS_FMT.format(pat, size, model)
281+
for (pat, size, model) in AARCH64_OUTLINE_ATOMICS
282+
] + glob(
283+
[
284+
"lib/builtins/cpu_model/AArch64*.inc",
285+
"lib/builtins/cpu_model/aarch64/**/*.inc",
286+
"lib/builtins/aarch64/*.S",
287+
"lib/builtins/aarch64/*.c",
288+
"lib/builtins/aarch64/*.cpp",
289+
],
290+
allow_empty = True,
291+
exclude = [
292+
# This file isn't intended to directly compile, and instead is used
293+
# above to generate a collection of outline atomic helpers.
294+
"lib/builtins/aarch64/lse.S",
295+
# These files are provided by SME-specific file groups above.
296+
"lib/builtins/aarch64/*sme*",
297+
],
298+
),
299+
)
300+
301+
BUILTINS_ARM_VFP_SRCS_PATTERNS = [
302+
"lib/builtins/arm/*vfp*.S",
303+
"lib/builtins/arm/*vfp*.c",
304+
"lib/builtins/arm/*vfp*.cpp",
305+
]
306+
307+
# Source files for the ARM VFP-specific builtins.
308+
filegroup(
309+
name = "builtins_arm_vfp_srcs",
310+
srcs = glob(
311+
BUILTINS_ARM_VFP_SRCS_PATTERNS,
312+
allow_empty = True,
313+
),
314+
)
315+
316+
# Source files for the ARM architecture-specific builtins.
317+
filegroup(
318+
name = "builtins_arm_srcs",
319+
srcs = glob(
320+
[
321+
"lib/builtins/arm/*.S",
322+
"lib/builtins/arm/*.c",
323+
"lib/builtins/arm/*.cpp",
324+
],
325+
allow_empty = True,
326+
exclude = BUILTINS_ARM_VFP_SRCS_PATTERNS,
327+
),
328+
)
329+
330+
# Source files for the PPC architecture-specific builtins.
331+
filegroup(
332+
name = "builtins_ppc_srcs",
333+
srcs = glob(
334+
[
335+
"lib/builtins/ppc/*.S",
336+
"lib/builtins/ppc/*.c",
337+
"lib/builtins/ppc/*.cpp",
338+
],
339+
allow_empty = True,
340+
),
341+
)
342+
343+
# Source files for the RISC-V architecture-specific builtins.
344+
filegroup(
345+
name = "builtins_riscv_srcs",
346+
srcs = glob(
347+
[
348+
"lib/builtins/riscv/*.S",
349+
"lib/builtins/riscv/*.c",
350+
"lib/builtins/riscv/*.cpp",
351+
],
352+
allow_empty = True,
353+
),
354+
)
355+
356+
# Source files for the x86 architecture specific builtins (both 32-bit and
357+
# 64-bit).
358+
filegroup(
359+
name = "builtins_x86_arch_srcs",
360+
srcs = [
361+
"lib/builtins/cpu_model/x86.c",
362+
"lib/builtins/i386/fp_mode.c",
363+
],
364+
)
365+
366+
# Source files for the x86-64 architecture specific builtins.
367+
filegroup(
368+
name = "builtins_x86_64_srcs",
369+
srcs = glob(
370+
[
371+
"lib/builtins/x86_64/*.S",
372+
"lib/builtins/x86_64/*.c",
373+
"lib/builtins/x86_64/*.cpp",
374+
],
375+
allow_empty = True,
376+
),
377+
)
378+
379+
# Source files for the 32-bit-specific x86 architecture specific builtins.
380+
filegroup(
381+
name = "builtins_i386_srcs",
382+
srcs = glob(
383+
[
384+
"lib/builtins/i386/*.S",
385+
"lib/builtins/i386/*.c",
386+
"lib/builtins/i386/*.cpp",
387+
],
388+
allow_empty = True,
389+
exclude = [
390+
# This file is used for both i386 and x86_64 and so included in the
391+
# broader x86 sources.
392+
"lib/builtins/i386/fp_mode.c",
393+
],
394+
),
395+
)
396+
397+
# Source files for portable components of the compiler builtins library.
398+
filegroup(
399+
name = "builtins_generic_srcs",
400+
srcs = ["lib/builtins/cpu_model/cpu_model.h"] + glob(
401+
[
402+
"lib/builtins/*.c",
403+
"lib/builtins/*.cpp",
404+
"lib/builtins/*.h",
405+
"lib/builtins/*.inc",
406+
],
407+
allow_empty = True,
408+
exclude = (
409+
BUILTINS_CRTBEGIN_SRCS +
410+
BUILTINS_CRTEND_SRCS +
411+
BUILTINS_TF_EXCLUDES +
412+
BUILTINS_TF_SRCS_PATTERNS +
413+
BUILTNS_ATOMICS_SRCS +
414+
BUILTINS_MACOS_ATOMIC_SRCS_PATTERNS
415+
),
416+
),
417+
)

utils/bazel/llvm-project-overlay/third-party/siphash/BUILD.bazel

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ package(default_visibility = ["//visibility:public"])
88

99
licenses(["notice"])
1010

11+
filegroup(
12+
name = "siphash_header",
13+
srcs = ["include/siphash/SipHash.h"],
14+
)
15+
1116
cc_library(
1217
name = "siphash",
13-
hdrs = ["include/siphash/SipHash.h"],
18+
hdrs = [":siphash_header"],
1419
strip_include_prefix = "include",
1520
)

0 commit comments

Comments
 (0)