[compiler-rt] 7c80e7a - [builtins] Check __SIZEOF_INT128__ for CRT_HAS_128BIT

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 6 19:02:13 PST 2022


Author: Sean Cross
Date: 2022-11-06T19:02:08-08:00
New Revision: 7c80e7a2943ade7b999c14ad582b52035098e5ae

URL: https://github.com/llvm/llvm-project/commit/7c80e7a2943ade7b999c14ad582b52035098e5ae
DIFF: https://github.com/llvm/llvm-project/commit/7c80e7a2943ade7b999c14ad582b52035098e5ae.diff

LOG: [builtins] Check __SIZEOF_INT128__ for CRT_HAS_128BIT

When building libstd on Rust for a riscv32 target, `compiler-rt` fails to build with the following error:

```
  running: "riscv-none-elf-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-march=rv32imac" "-mabi=ilp32" "-mcmodel=medany" "-fno-builtin" "-fvisibility=hidden" "-ffreestanding" "-fomit-frame-pointer" "-ffile-prefix-map=E:\\Code\\Xous\\rust-next\\src\\llvm-project\\compiler-rt=." "-DVISIBILITY_HIDDEN" "-o" "E:\\Code\\Xous\\rust-next\\target\\riscv32imac-unknown-xous-elf\\release\\build\\compiler_builtins-b0d7dd25c6999904\\out\\absvdi2.o" "-c" "E:\\Code\\Xous\\rust-next\\src\\llvm-project\\compiler-rt\\lib/builtins\\absvdi2.c"
  cargo:warning=In file included from E:\Code\Xous\rust-next\src\llvm-project\compiler-rt\lib/builtins\int_lib.h:99,
  cargo:warning=                 from E:\Code\Xous\rust-next\src\llvm-project\compiler-rt\lib/builtins\absvdi2.c:13:
  cargo:warning=E:\Code\Xous\rust-next\src\llvm-project\compiler-rt\lib/builtins\int_types.h:79:1: error: unable to emulate 'TI'
  cargo:warning=   79 | typedef int ti_int __attribute__((mode(TI)));
  cargo:warning=      | ^~~~~~~
  cargo:warning=E:\Code\Xous\rust-next\src\llvm-project\compiler-rt\lib/builtins\int_types.h:80:1: error: unable to emulate 'TI'
  cargo:warning=   80 | typedef unsigned tu_int __attribute__((mode(TI)));
  cargo:warning=      | ^~~~~~~
  exit code: 1
```

This is because 128-bit support is gated on the `__riscv` compiler macro which is valid for both rv32 and rv64. However, only rv64 has 128-bit support, so this fails when building for rv32.

Add a check for `__SIZEOF_INT128__` to ensure that 128-bit support is only enabled on targets that support it.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D137485

Added: 
    

Modified: 
    compiler-rt/lib/builtins/int_types.h

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/builtins/int_types.h b/compiler-rt/lib/builtins/int_types.h
index 7a72de480676..e94d3154c6d4 100644
--- a/compiler-rt/lib/builtins/int_types.h
+++ b/compiler-rt/lib/builtins/int_types.h
@@ -64,7 +64,7 @@ typedef union {
 } udwords;
 
 #if defined(__LP64__) || defined(__wasm__) || defined(__mips64) ||             \
-    defined(__riscv) || defined(_WIN64)
+    defined(__SIZEOF_INT128__) || defined(_WIN64)
 #define CRT_HAS_128BIT
 #endif
 


        


More information about the llvm-commits mailing list