Skip to content

Commit 40f94c0

Browse files
author
Jorge Aparicio
committed
compiler_builtins: support the thumb* targets
1 parent 05b64c3 commit 40f94c0

File tree

1 file changed

+75
-37
lines changed

1 file changed

+75
-37
lines changed

src/libcompiler_builtins/build.rs

+75-37
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ impl Sources {
7272
}
7373
}
7474
}
75+
76+
fn remove(&mut self, symbols: &[&str]) {
77+
for symbol in symbols {
78+
self.map.remove(*symbol).unwrap();
79+
}
80+
}
7581
}
7682

7783
fn main() {
@@ -107,6 +113,25 @@ fn main() {
107113
cfg.flag("-ffreestanding");
108114
}
109115

116+
// NOTE Most of the ARM intrinsics are written in assembly. Tell gcc which arch we are going to
117+
// target to make sure that the assembly implementations really work for the target. If the
118+
// implementation is not valid for the arch, then gcc will error when compiling it.
119+
if llvm_target[0].starts_with("thumb") {
120+
cfg.flag("-mthumb");
121+
}
122+
123+
if llvm_target[0] == "thumbv6m" {
124+
cfg.flag("-march=armv6-m");
125+
}
126+
127+
if llvm_target[0] == "thumbv7m" {
128+
cfg.flag("-march=armv7-m");
129+
}
130+
131+
if llvm_target[0] == "thumbv7em" {
132+
cfg.flag("-march=armv7e-m");
133+
}
134+
110135
let mut sources = Sources::new();
111136
sources.extend(&["absvdi2.c",
112137
"absvsi2.c",
@@ -252,7 +277,7 @@ fn main() {
252277
"atomic_thread_fence.c"]);
253278
}
254279

255-
if target_os != "windows" {
280+
if target_os != "windows" && target_os != "none" {
256281
sources.extend(&["emutls.c"]);
257282
}
258283

@@ -356,42 +381,43 @@ fn main() {
356381
}
357382

358383
if llvm_target.last().unwrap().ends_with("eabihf") {
359-
sources.extend(&["arm/adddf3vfp.S",
360-
"arm/addsf3vfp.S",
361-
"arm/divdf3vfp.S",
362-
"arm/divsf3vfp.S",
363-
"arm/eqdf2vfp.S",
364-
"arm/eqsf2vfp.S",
365-
"arm/extendsfdf2vfp.S",
366-
"arm/fixdfsivfp.S",
367-
"arm/fixsfsivfp.S",
368-
"arm/fixunsdfsivfp.S",
369-
"arm/fixunssfsivfp.S",
370-
"arm/floatsidfvfp.S",
371-
"arm/floatsisfvfp.S",
372-
"arm/floatunssidfvfp.S",
373-
"arm/floatunssisfvfp.S",
374-
"arm/gedf2vfp.S",
375-
"arm/gesf2vfp.S",
376-
"arm/gtdf2vfp.S",
377-
"arm/gtsf2vfp.S",
378-
"arm/ledf2vfp.S",
379-
"arm/lesf2vfp.S",
380-
"arm/ltdf2vfp.S",
381-
"arm/ltsf2vfp.S",
382-
"arm/muldf3vfp.S",
383-
"arm/mulsf3vfp.S",
384-
"arm/negdf2vfp.S",
385-
"arm/negsf2vfp.S",
386-
"arm/nedf2vfp.S",
387-
"arm/nesf2vfp.S",
388-
"arm/restore_vfp_d8_d15_regs.S",
389-
"arm/save_vfp_d8_d15_regs.S",
390-
"arm/subdf3vfp.S",
391-
"arm/subsf3vfp.S",
392-
"arm/truncdfsf2vfp.S",
393-
"arm/unorddf2vfp.S",
394-
"arm/unordsf2vfp.S"]);
384+
if !llvm_target[0].starts_with("thumbv7em") {
385+
sources.extend(&["arm/adddf3vfp.S",
386+
"arm/addsf3vfp.S",
387+
"arm/divdf3vfp.S",
388+
"arm/divsf3vfp.S",
389+
"arm/eqdf2vfp.S",
390+
"arm/eqsf2vfp.S",
391+
"arm/extendsfdf2vfp.S",
392+
"arm/fixdfsivfp.S",
393+
"arm/fixsfsivfp.S",
394+
"arm/fixunsdfsivfp.S",
395+
"arm/fixunssfsivfp.S",
396+
"arm/floatsidfvfp.S",
397+
"arm/floatsisfvfp.S",
398+
"arm/floatunssidfvfp.S",
399+
"arm/floatunssisfvfp.S",
400+
"arm/gedf2vfp.S",
401+
"arm/gesf2vfp.S",
402+
"arm/gtdf2vfp.S",
403+
"arm/gtsf2vfp.S",
404+
"arm/ledf2vfp.S",
405+
"arm/lesf2vfp.S",
406+
"arm/ltdf2vfp.S",
407+
"arm/ltsf2vfp.S",
408+
"arm/muldf3vfp.S",
409+
"arm/mulsf3vfp.S",
410+
"arm/nedf2vfp.S",
411+
"arm/nesf2vfp.S",
412+
"arm/restore_vfp_d8_d15_regs.S",
413+
"arm/save_vfp_d8_d15_regs.S",
414+
"arm/subdf3vfp.S",
415+
"arm/subsf3vfp.S",
416+
]);
417+
}
418+
419+
sources.extend(&["arm/negdf2vfp.S", "arm/negsf2vfp.S"]);
420+
395421
}
396422

397423
if target_arch == "aarch64" {
@@ -413,6 +439,18 @@ fn main() {
413439
"trunctfsf2.c"]);
414440
}
415441

442+
// Remove the assembly implementations that won't compile for the target
443+
if llvm_target[0] == "thumbv6m" {
444+
sources.remove(&["aeabi_cdcmp", "aeabi_cfcmp", "aeabi_dcmp", "aeabi_fcmp", "aeabi_ldivmod",
445+
"aeabi_memset", "aeabi_uldivmod", "clzdi2", "clzsi2", "comparesf2",
446+
"divmodsi4", "divsi3", "modsi3", "switch16", "switch32", "switch8",
447+
"switchu8", "udivmodsi4", "udivsi3", "umodsi3"]);
448+
}
449+
450+
if llvm_target[0] == "thumbv7m" || llvm_target[0] == "thumbv7em" {
451+
sources.remove(&["aeabi_cdcmp", "aeabi_cfcmp"]);
452+
}
453+
416454
for src in sources.map.values() {
417455
cfg.file(Path::new("../compiler-rt/lib/builtins").join(src));
418456
}

0 commit comments

Comments
 (0)