PSA: [breaking-change] `extern crate compiler_builtins` is now included in #![no_std] crates


#1

As of the latest nightly (nightly-2018-04-08) the expansion of #![no_std] contains extern crate compiler_builtins. This unstable crate contains compiler intrinsics, like addsf3, which LLVM uses (calls) to perform operations, like addition of single precision floats, when they can’t be performed using native instructions. Some targets need this crate to link properly.

This is a breaking change:

If you had a crate that directly depended on the compiler_builtins crate you’ll have to remove the extern crate bit:

 #![no_std]

-#![feature(compiler_builtins_lib)]

-extern crate compiler_builtins;

  // ..

But this also means you can drop the compiler_builtins_lib feature gate, which is a good thing.

Also, if you were using Xargo (which requires nightly) v0.3.11 or older (NOTE that you don’t need Xargo if you are cross compiling for ARM Cortex-M) and you were building a sysroot that only contained core you’ll have to add / modify Xargo.toml to also (cross) compile the compiler_builtins crate.

$ cat Xargo.toml
[dependencies.core]
stage = 0

[dependencies.compiler_builtins]
features = ["mem"]
stage = 1

Alternatively, you can use the upcoming Xargo v0.3.12 which will compile both core and compiler_builtins by default.

This change is part of the effort towards making embedded development possible on the stable channel.

See this issue for previous discussion regarding this change.


#2

@japaric I guess this requires a new cortex-m-rt release to cope with the change?


#3

So post crossed action. :smiley: Thanks for the swift update, @japaric.


#4

So I’ve tried to move from rlibc to compiler_builtins with the mem feature. I’ve added

[dependencies.core]
stage = 0

[dependencies.compiler_builtins]
features = ["mem"]
stage = 1

to Xargo.toml, and removed the rlibc dependency. However, I get this:

error[E0464]: multiple matching crates for `compiler_builtins`
  |
  = note: candidates:
          crate `compiler_builtins`: /home/isaac/.xargo/lib/rustlib/x86_64-pebble-ker
nel/lib/libcompiler_builtins-cce33bae5ff46c9e.rlib
          crate `compiler_builtins`: /home/isaac/.xargo/lib/rustlib/x86_64-pebble-ker
nel/lib/libcompiler_builtins-da8cc54ee9220882.rlib

error[E0463]: can't find crate for `compiler_builtins`

Any ideas?


#5

Looks like a bad cache. Try cargo clean and removing the Xargo sysroot: rm -rf ~/.xargo.


#6

Had tried that, but tried it again, with no success. Same error.

Removing

[dependencies.compiler_builtins]
features = ["mem"]
stage = 1

compiles successfully, but obviously then can’t link since it doesn’t have memcpy and such.


#7

Could you open an issue in the Xargo repo providing instructions on how to reproduce the problem?


#8

I’m not sure I have a reliable reproduction. I updated Xargo to 0.3.12 and removed the entry from Xargo.toml, and compiler_builtins is now included automatically (and doesn’t cause the multiple crates problem), but does not have the memcpy etc. symbols needed for linking, even with the mem feature added again. I’ve resorted to leaving it and re-adding the dependency on rlibc. I’ll try again at some point, and if it still doesn’t work I’ll dig deeper and file it on the repo.


#9

I’m seeing a breakage when I updated to nightly-2018-09-16-x86_64-pc-windows-msvc which may be related to this change. Earlier I was using nightly-2018-03-30-x86_64-pc-windows-msvc and it worked fine.

My project is a UEFI bootloader and I’m using xargo and a custom target shown below to build it:

{                                                            
  "arch": "x86_64",                                          
  "cpu": "x86-64",                                           
  "crt-static-allows-dylibs": true,                          
  "crt-static-respected": true,                              
  "data-layout": "e-m:w-i64:64-f80:128-n8:16:32:64-S128",    
  "dll-prefix": "",                                          
  "dll-suffix": ".efi",                                      
  "dynamic-linking": true,                                   
  "env": "msvc",                                             
  "exe-suffix": ".efi",                                      
  "executables": true,                                       
  "has-elf-tls": true,                                       
  "is-builtin": false,                                        
  "is-like-msvc": true,                                      
  "is-like-windows": true,                                   
  "linker": "link.exe",                                      
  "linker-flavor": "msvc",                                   
  "llvm-target": "x86_64-pc-windows-msvc",                   
  "max-atomic-width": 64,                                    
  "os": "windows",                                           
  "pre-link-args": {                                         
    "msvc": [                                                
      "/NOLOGO",                                             
      "/SUBSYSTEM:EFI_APPLICATION"
    ]                                                        
  },                                                         
  "staticlib-prefix": "",                                    
  "staticlib-suffix": ".lib",                                
  "target-c-int-width": "32",                                
  "target-endian": "little",                                 
  "target-family": "windows",                                
  "target-pointer-width": "64",                              
  "vendor": "unknown",                                             
  "panic-strategy": "abort",
  "singlethread": true
}                                                            

My host machine is Windows 10 and I’m using VS 2017’s build tools. Earlier the build worked fine, but when I switched to nightly-2018-09-16-x86_64-pc-windows-msvc I started seeing the below error:

D:\Projects\Rust\peerboot>xargo  build --target x86_64-unknown-efi
    Updating crates.io index
   Compiling cc v1.0.25
   Compiling core v0.0.0 (C:\Users\gurinder.singh\.rustup\toolchains\nightly-2018-09-16-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src\libcore)
   Compiling compiler_builtins v0.0.0 (C:\Users\gurinder.singh\.rustup\toolchains\nightly-2018-09-16-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src\rustc\compiler_builtins_shim)
error: failed to run custom build command for `compiler_builtins v0.0.0 (C:\Users\gurinder.singh\.rustup\toolchains\nightly-2018-09-16-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src\rustc\compiler_builtins_shim)`
process didn't exit successfully: `C:\Users\GURIND~1.SIN\AppData\Local\Temp\xargo.CLhBM4IFqVT6\target\release\build\compiler_builtins-551350075561f652\build-script-build` (exit code: 101)
--- stdout
cargo:rerun-if-changed=build.rs
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\absvdi2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\absvsi2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\absvti2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\addvdi3.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\addvsi3.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\addvti3.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\apple_versioning.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\clzdi2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\clzsi2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\clzti2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\cmpdi2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\cmpti2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\ctzdi2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\ctzsi2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\ctzti2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\divdc3.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\divsc3.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\divxc3.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\extendhfsf2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\ffsdi2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\ffsti2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\x86_64/floatdisf.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\x86_64/floatdixf.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\int_util.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\muldc3.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\mulsc3.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\mulvdi3.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\mulvsi3.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\mulvti3.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\mulxc3.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\negdf2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\negdi2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\negsf2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\negti2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\negvdi2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\negvsi2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\negvti2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\paritydi2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\paritysi2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\parityti2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\popcountdi2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\popcountsi2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\popcountti2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\powixf2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\subvdi3.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\subvsi3.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\subvti3.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\truncdfhf2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\truncdfsf2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\truncsfhf2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\ucmpdi2.c
cargo:rerun-if-changed=../../libcompiler_builtins\compiler-rt/lib/builtins\ucmpti2.c
TARGET = Some("x86_64-unknown-efi")
OPT_LEVEL = Some("3")
HOST = Some("x86_64-pc-windows-msvc")
CC_x86_64-unknown-efi = None
CC_x86_64_unknown_efi = None
TARGET_CC = None
CC = None
CROSS_COMPILE = None
CFLAGS_x86_64-unknown-efi = None
CFLAGS_x86_64_unknown_efi = None
TARGET_CFLAGS = None
CFLAGS = None
DEBUG = Some("false")
running: "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "/Zl" "-D__func__=__FUNCTION__" "-o" "C:\\Users\\GURIND~1.SIN\\AppData\\Local\\Temp\\xargo.CLhBM4IFqVT6\\target\\x86_64-unknown-efi\\release\\build\\compiler_builtins-e8f577f13bcd0c00\\out\\../../libcompiler_builtins\\compiler-rt/lib/builtins\\absvdi2.o" "-c" "../../libcompiler_builtins\\compiler-rt/lib/builtins\\absvdi2.c"

--- stderr
thread 'main' panicked at '

Internal error occurred: Failed to find tool. Is `cc` installed? (see https://github.com/alexcrichton/cc-rs#compile-time-requirements for help)

', C:\Users\gurinder.singh\.cargo\registry\src\github.com-1ecc6299db9ec823\cc-1.0.25\src\lib.rs:2260:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.

I’m running this inside Visual Studio developer prompt and cl.exe is in path then why is cc-rs trying to use linux’s cc? Is this due to something wrong in my target spec? Is the CC = None line in the error a clue? How can I resolve this problem?

Any help will be greatly appreciated :slight_smile:.