xargo icon indicating copy to clipboard operation
xargo copied to clipboard

Failed to compile for custom armv7 target

Open glebpom opened this issue 6 years ago • 1 comments

I'm trying to compile my project with xargo for the custom armv7 target (for uclibc). Here is the definition (based on default armv7 target):

{
  "abi-blacklist": [
    "stdcall",
    "fastcall",
    "vectorcall",
    "thiscall",
    "win64",
    "sysv64"
  ],
  "arch": "arm",
  "data-layout": "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64",
  "dynamic-linking": true,
  "env": "uclibc",
  "executables": true,
  "features": "+v7,+vfp3,+d16,+thumb2,-neon",
  "has-elf-tls": true,
  "has-rpath": true,
  "linker-flavor": "gcc",
  "linker-is-gnu": true,
  "llvm-target": "armv7-iris-linux-uclibcgnueabihf",
  "max-atomic-width": 64,
  "os": "linux",
  "panic-strategy": "abort",
  "position-independent-executables": true,
  "pre-link-args": {
    "gcc": [
      "-Wl,--as-needed",
      "-Wl,-z,noexecstack"
    ]
  },
  "relro-level": "full",
  "target-c-int-width": "32",
  "target-endian": "little",
  "target-family": "unix",
  "target-pointer-width": "32",
  "vendor": "iris"
}

I have cross-compiler for uclibcgnueabihf target based on buildroot.

export AR_armv7_iris_linux_uclibcgnueabihf=<..path_to_ar..>
export CC_armv7_iris_linux_uclibcgnueabihf=<..path_to_gcc..>
export CXX_armv7_iris_linux_uclibcgnueabihf=<..path_to_g++..>

When trying to compile with xargo, I have a bunch of errors like this:

  = note: /firmware/hi3516a/buildroot/output/host/usr/lib/gcc/arm-buildroot-linux-uclibcgnueabihf/6.3.0/../../../../arm-buildroot-linux-uclibcgnueabihf/bin/ld: error: /xargo-tmp/xargo.3e3lNHWZCSEZ/target/armv7-iris-linux-uclibcgnueabihf/release/deps/libstd.so uses VFP register arguments, /xargo-tmp/xargo.3e3lNHWZCSEZ/target/armv7-iris-linux-uclibcgnueabihf/release/deps/std.std0.rcgu.o does not

When I add "exe-allocation-crate": "alloc_jemalloc", to target json, I'm getting another error:

  = note: /xargo-tmp/rustc.X6nVYxA8h1dx/liballoc_jemalloc-870beb061ba96b09.rlib: member /xargo-tmp/rustc.X6nVYxA8h1dx/liballoc_jemalloc-870beb061ba96b09.rlib(jemalloc.pic.o) in archive is not an object

I have checked the file /xargo-tmp/rustc.X6nVYxA8h1dx/liballoc_jemalloc-870beb061ba96b09.rlib, and I can see that it's built for X86_64, and not arm-v7.

cargo config:

[target.armv7-iris-linux-uclibcgnueabihf]
linker = "/firmware/hi3516a/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-gcc"

Xargo.toml

[target.armv7-iris-linux-uclibcgnueabihf.dependencies.std]
features = ["jemalloc"]
root@8bb1dce6b2e9:/xargo-tmp/xargo.ItU0B85Xk0hc/target/armv7-iris-linux-uclibcgnueabihf/release# file ./build/libcompiler_builtins/compiler-rt/lib/builtins/divxc3.o
./build/libcompiler_builtins/compiler-rt/lib/builtins/divxc3.o: ELF 32-bit LSB relocatable, ARM, EABI5 version 1 (SYSV), not stripped
root@8bb1dce6b2e9:/xargo-tmp/xargo.ItU0B85Xk0hc/target/armv7-iris-linux-uclibcgnueabihf/release# file ./build/alloc_jemalloc-8e36de72226c458a/out/jemalloc/src/rtree.o
./build/alloc_jemalloc-8e36de72226c458a/out/jemalloc/src/rtree.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped

This config works fine: https://github.com/joerg-krause/rust-cross-libs/blob/master/cfg/armv7a-rcross-linux-musleabihf.json

glebpom avatar Dec 08 '17 16:12 glebpom

export AR_armv7_iris_linux_uclibcgnueabihf=<..path_to_ar..> export CC_armv7_iris_linux_uclibcgnueabihf=<..path_to_gcc..> export CXX_armv7_iris_linux_uclibcgnueabihf=<..path_to_g++..>

Did you set these env variables before calling Xargo for the first time? If you didn't then Xargo has built the C dependencies of the sysroot crates using gcc. As Xargo won't rebuild the sysroot when you set AR_* and co. you'll always link against the sysroot that contains the miscompiled C libraries. Try removing the Xargo directory: rm -rf ~/.xargo and calling xargo build again.

japaric avatar Dec 16 '17 14:12 japaric