Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 56ebadf

Browse files
committedJan 24, 2024
Auto merge of rust-lang#120289 - fmease:rollup-f3qh886, r=fmease
Rollup of 7 pull requests Successful merges: - rust-lang#119460 (coverage: Never emit improperly-ordered coverage regions) - rust-lang#120062 (llvm: change data layout bug to an error and make it trigger more) - rust-lang#120124 (Split assembly tests for ELF and MachO) - rust-lang#120185 (coverage: Don't instrument `#[automatically_derived]` functions) - rust-lang#120265 (Remove no-system-llvm) - rust-lang#120277 (Normalize field types before checking validity) - rust-lang#120285 (Remove extra # from url in suggestion) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0b77301 + 4727f25 commit 56ebadf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+256
-253
lines changed
 

‎compiler/rustc_codegen_llvm/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ codegen_llvm_lto_dylib = lto cannot be used for `dylib` crate type without `-Zdy
3939
4040
codegen_llvm_lto_proc_macro = lto cannot be used for `proc-macro` crate type without `-Zdylib-lto`
4141
42+
codegen_llvm_mismatch_data_layout =
43+
data-layout for target `{$rustc_target}`, `{$rustc_layout}`, differs from LLVM target's `{$llvm_target}` default layout, `{$llvm_layout}`
44+
4245
codegen_llvm_missing_features =
4346
add the missing features in a `target_feature` attribute
4447

‎compiler/rustc_codegen_llvm/src/context.rs

+9-29
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use rustc_target::spec::{HasTargetSpec, RelocModel, Target, TlsModel};
3434
use smallvec::SmallVec;
3535

3636
use libc::c_uint;
37+
use std::borrow::Borrow;
3738
use std::cell::{Cell, RefCell};
3839
use std::ffi::CStr;
3940
use std::str;
@@ -155,42 +156,21 @@ pub unsafe fn create_module<'ll>(
155156
}
156157

157158
// Ensure the data-layout values hardcoded remain the defaults.
158-
if sess.target.is_builtin {
159-
// tm is disposed by its drop impl
159+
{
160160
let tm = crate::back::write::create_informational_target_machine(tcx.sess);
161161
llvm::LLVMRustSetDataLayoutFromTargetMachine(llmod, &tm);
162162

163163
let llvm_data_layout = llvm::LLVMGetDataLayoutStr(llmod);
164164
let llvm_data_layout = str::from_utf8(CStr::from_ptr(llvm_data_layout).to_bytes())
165165
.expect("got a non-UTF8 data-layout from LLVM");
166166

167-
// Unfortunately LLVM target specs change over time, and right now we
168-
// don't have proper support to work with any more than one
169-
// `data_layout` than the one that is in the rust-lang/rust repo. If
170-
// this compiler is configured against a custom LLVM, we may have a
171-
// differing data layout, even though we should update our own to use
172-
// that one.
173-
//
174-
// As an interim hack, if CFG_LLVM_ROOT is not an empty string then we
175-
// disable this check entirely as we may be configured with something
176-
// that has a different target layout.
177-
//
178-
// Unsure if this will actually cause breakage when rustc is configured
179-
// as such.
180-
//
181-
// FIXME(#34960)
182-
let cfg_llvm_root = option_env!("CFG_LLVM_ROOT").unwrap_or("");
183-
let custom_llvm_used = !cfg_llvm_root.trim().is_empty();
184-
185-
if !custom_llvm_used && target_data_layout != llvm_data_layout {
186-
bug!(
187-
"data-layout for target `{rustc_target}`, `{rustc_layout}`, \
188-
differs from LLVM target's `{llvm_target}` default layout, `{llvm_layout}`",
189-
rustc_target = sess.opts.target_triple,
190-
rustc_layout = target_data_layout,
191-
llvm_target = sess.target.llvm_target,
192-
llvm_layout = llvm_data_layout
193-
);
167+
if target_data_layout != llvm_data_layout {
168+
tcx.dcx().emit_err(crate::errors::MismatchedDataLayout {
169+
rustc_target: sess.opts.target_triple.to_string().as_str(),
170+
rustc_layout: target_data_layout.as_str(),
171+
llvm_target: sess.target.llvm_target.borrow(),
172+
llvm_layout: llvm_data_layout,
173+
});
194174
}
195175
}
196176

0 commit comments

Comments
 (0)
Please sign in to comment.