Skip to content

Instantly share code, notes, and snippets.

@joerg-krause
Created January 6, 2016 02:21
Show Gist options
  • Save joerg-krause/7a7351b6e4ae7267a0ae to your computer and use it in GitHub Desktop.
Save joerg-krause/7a7351b6e4ae7267a0ae to your computer and use it in GitHub Desktop.
arm-unknown-linux-musl target for Rust
# arm-unknown-linux-musl configuration
CC_arm-unknown-linux-musl=$(CFG_MUSL_ROOT)/bin/musl-gcc
CXX_arm-unknown-linux-musl=notaprogram
CPP_arm-unknown-linux-musl=$(CFG_MUSL_ROOT)/bin/musl-gcc -E
AR_arm-unknown-linux-musl=$(AR)
CFG_INSTALL_ONLY_RLIB_arm-unknown-linux-musl = 1
CFG_LIB_NAME_arm-unknown-linux-musl=lib$(1).so
CFG_STATIC_LIB_NAME_arm-unknown-linux-musl=lib$(1).a
CFG_LIB_GLOB_arm-unknown-linux-musl=lib$(1)-*.so
CFG_LIB_DSYM_GLOB_arm-unknown-linux-musl=lib$(1)-*.dylib.dSYM
CFG_JEMALLOC_CFLAGS_arm-unknown-linux-musl := -D__arm__ -msoft-float $(CFLAGS)
CFG_GCCISH_CFLAGS_arm-unknown-linux-musl := -Wall -g -fPIC -D__arm__ -msoft-float $(CFLAGS)
CFG_GCCISH_CXXFLAGS_arm-unknown-linux-musl := -fno-rtti $(CXXFLAGS)
CFG_GCCISH_LINK_FLAGS_arm-unknown-linux-musl := -shared -fPIC -g -msoft-float
CFG_GCCISH_DEF_FLAG_arm-unknown-linux-musl := -Wl,--export-dynamic,--dynamic-list=
CFG_LLC_FLAGS_arm-unknown-linux-musl :=
CFG_INSTALL_NAME_arm-unknown-linux-musl =
CFG_EXE_SUFFIX_arm-unknown-linux-musl :=
CFG_WINDOWSY_arm-unknown-linux-musl :=
CFG_UNIXY_arm-unknown-linux-musl := 1
CFG_LDPATH_arm-unknown-linux-musl :=
CFG_RUN_arm-unknown-linux-musl=$(2)
CFG_RUN_TARG_arm-unknown-linux-musl=$(call CFG_RUN_arm-unknown-linux-musl,,$(2))
RUSTC_FLAGS_arm-unknown-linux-musl :=
RUSTC_CROSS_FLAGS_arm-unknown-linux-musl := -C target-cpu=arm926ej-s -C target-feature="+v5te" -C soft-float
CFG_GNU_TRIPLE_arm-unknown-linux-musl := arm-unknown-linux-musl
CFG_THIRD_PARTY_OBJECTS_arm-unknown-linux-musl := crt1.o crti.o crtn.o
CFG_INSTALLED_OBJECTS_arm-unknown-linux-musl := crt1.o crti.o crtn.o
NATIVE_DEPS_libc_T_arm-unknown-linux-musl += libc.a
NATIVE_DEPS_std_T_arm-unknown-linux-musl += libunwind.a crt1.o crti.o crtn.o
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use target::Target;
pub fn target() -> Target {
let mut base = super::linux_base::opts();
base.cpu = "arm926ej-s".to_string();
// Make sure that the linker/gcc really don't pull in anything, including
// default objects, libs, etc.
base.pre_link_args.push("-nostdlib".to_string());
base.pre_link_args.push("-static".to_string());
// At least when this was tested, the linker would not add the
// `GNU_EH_FRAME` program header to executables generated, which is required
// when unwinding to locate the unwinding information. I'm not sure why this
// argument is *not* necessary for normal builds, but it can't hurt!
base.pre_link_args.push("-Wl,--eh-frame-hdr".to_string());
// There's a whole bunch of circular dependencies when dealing with MUSL
// unfortunately. To put this in perspective libc is statically linked to
// liblibc and libunwind is statically linked to libstd:
//
// * libcore depends on `fmod` which is in libc (transitively in liblibc).
// liblibc, however, depends on libcore.
// * compiler-rt has personality symbols that depend on libunwind, but
// libunwind is in libstd which depends on compiler-rt.
//
// Recall that linkers discard libraries and object files as much as
// possible, and with all the static linking and archives flying around with
// MUSL the linker is super aggressively stripping out objects. For example
// the first case has fmod stripped from liblibc (it's in its own object
// file) so it's not there when libcore needs it. In the second example all
// the unused symbols from libunwind are stripped (each is in its own object
// file in libstd) before we end up linking compiler-rt which depends on
// those symbols.
//
// To deal with these circular dependencies we just force the compiler to
// link everything as a group, not stripping anything out until everything
// is processed. The linker will still perform a pass to strip out object
// files but it won't do so until all objects/archives have been processed.
base.pre_link_args.push("-Wl,-(".to_string());
base.post_link_args.push("-Wl,-)".to_string());
// When generating a statically linked executable there's generally some
// small setup needed which is listed in these files. These are provided by
// a musl toolchain and are linked by default by the `musl-gcc` script. Note
// that `gcc` also does this by default, it just uses some different files.
//
// Each target directory for musl has these object files included in it so
// they'll be included from there.
base.pre_link_objects_exe.push("crt1.o".to_string());
base.pre_link_objects_exe.push("crti.o".to_string());
base.post_link_objects.push("crtn.o".to_string());
// MUSL support doesn't currently include dynamic linking, so there's no
// need for dylibs or rpath business. Additionally `-pie` is incompatible
// with `-static`, so we can't pass `-pie`.
base.dynamic_linking = false;
base.has_rpath = false;
base.position_independent_executables = false;
Target {
llvm_target: "arm-unknown-linux-musl".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "32".to_string(),
arch: "arm".to_string(),
target_os: "linux".to_string(),
target_env: "musl".to_string(),
target_vendor: "unknown".to_string(),
options: base,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment