Skip to content

Commit e8f7666

Browse files
alexcrichtonbadboy
authored andcommitted
rustc: Fix data-layout for AArch64 targets
Also relax the assertion whenever we have a custom LLVM root as LLVM may disagree about exact specifics.
1 parent d851428 commit e8f7666

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

src/librustc_back/target/aarch64_linux_android.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn target() -> Target {
2020
llvm_target: "aarch64-linux-android".to_string(),
2121
target_endian: "little".to_string(),
2222
target_pointer_width: "64".to_string(),
23-
data_layout: "e-m:e-i64:64-i128:128-n32:64-S128".to_string(),
23+
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
2424
arch: "aarch64".to_string(),
2525
target_os: "android".to_string(),
2626
target_env: "".to_string(),

src/librustc_back/target/aarch64_unknown_linux_gnu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn target() -> Target {
1818
target_endian: "little".to_string(),
1919
target_pointer_width: "64".to_string(),
2020
target_env: "gnu".to_string(),
21-
data_layout: "e-m:e-i64:64-i128:128-n32:64-S128".to_string(),
21+
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
2222
arch: "aarch64".to_string(),
2323
target_os: "linux".to_string(),
2424
target_vendor: "unknown".to_string(),

src/librustc_trans/context.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,25 @@ unsafe fn create_context_and_module(sess: &Session, mod_name: &str) -> (ContextR
370370
let data_layout = str::from_utf8(CStr::from_ptr(data_layout).to_bytes())
371371
.ok().expect("got a non-UTF8 data-layout from LLVM");
372372

373-
if sess.target.target.data_layout != data_layout {
373+
// Unfortunately LLVM target specs change over time, and right now we
374+
// don't have proper support to work with any more than one
375+
// `data_layout` than the one that is in the rust-lang/rust repo. If
376+
// this compiler is configured against a custom LLVM, we may have a
377+
// differing data layout, even though we should update our own to use
378+
// that one.
379+
//
380+
// As an interim hack, if CFG_LLVM_ROOT is not an empty string then we
381+
// disable this check entirely as we may be configured with something
382+
// that has a different target layout.
383+
//
384+
// Unsure if this will actually cause breakage when rustc is configured
385+
// as such.
386+
//
387+
// FIXME(#34960)
388+
let cfg_llvm_root = option_env!("CFG_LLVM_ROOT").unwrap_or("");
389+
let custom_llvm_used = cfg_llvm_root.trim() != "";
390+
391+
if !custom_llvm_used && sess.target.target.data_layout != data_layout {
374392
bug!("data-layout for builtin `{}` target, `{}`, \
375393
differs from LLVM default, `{}`",
376394
sess.target.target.llvm_target,

0 commit comments

Comments
 (0)