Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b6c9a6a
Generalize setting `rust-lld` as the default linker on Linux
Kobzol Sep 29, 2025
8dd97f8
Destructure `TomlConfig` and add missing `default_linker` config
Kobzol Sep 29, 2025
902cec2
Allow manually opting in and out of Linux linker overrides
Kobzol Oct 6, 2025
e7c9e12
Update change tracker
Kobzol Sep 29, 2025
b07d88f
Handle external LLVM config
Kobzol Oct 6, 2025
3452415
repr_transparent_external_private_fields: normalize types during trav…
RalfJung Oct 9, 2025
da86710
Rename default linker linux field
Kobzol Oct 9, 2025
10393a8
Add LLDB commands to `tests/debuginfo/basic-types-globals.rs`
Zalathar Oct 12, 2025
2be88e3
Add doc links between `{integer}::from_str_radix` and `from_str`
Zalathar Oct 12, 2025
b6ea824
Hoist some stranded `use` declarations
Zalathar Oct 4, 2025
45e9ebe
Extract `DIBuilderExt::create_expression`
Zalathar Oct 4, 2025
1db7d41
Extract `DIBuilderExt::create_static_variable`
Zalathar Oct 4, 2025
1081d98
Use `LLVMDIBuilderCreateGlobalVariableExpression`
Zalathar Oct 4, 2025
9ff52bf
Clear `ChunkedBitSet` without reallocating
Zalathar Oct 13, 2025
e755d71
Add a warning when running tests with the GCC backend and debug asser…
Kobzol Oct 13, 2025
4a7e152
Rollup merge of #147514 - RalfJung:transparent-nonexhaustive-normaliz…
GuillaumeGomez Oct 13, 2025
b7ea44a
Rollup merge of #147605 - Zalathar:from-str-radix, r=Mark-Simulacrum
GuillaumeGomez Oct 13, 2025
3938f42
Rollup merge of #147608 - Zalathar:debuginfo, r=nnethercote
GuillaumeGomez Oct 13, 2025
d808d28
Rollup merge of #147623 - Zalathar:clear-mixed, r=nnethercote
GuillaumeGomez Oct 13, 2025
8ced599
Rollup merge of #147625 - Kobzol:gcc-debug-assertions, r=GuillaumeGomez
GuillaumeGomez Oct 13, 2025
0e6ec72
Rollup merge of #147626 - Kobzol:lld-generalize2, r=jieyouxu
GuillaumeGomez Oct 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions bootstrap.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -758,12 +758,8 @@
# Currently, the only standard options supported here are `"llvm"`, `"cranelift"` and `"gcc"`.
#rust.codegen-backends = ["llvm"]

# Indicates whether LLD will be compiled and made available in the sysroot for rustc to execute, and
# whether to set it as rustc's default linker on `x86_64-unknown-linux-gnu`. This will also only be
# when *not* building an external LLVM (so only when using `download-ci-llvm` or building LLVM from
# the in-tree source): setting `llvm-config` in the `[target.x86_64-unknown-linux-gnu]` section will
# make this default to false.
#rust.lld = false in all cases, except on `x86_64-unknown-linux-gnu` as described above, where it is true
# Indicates whether LLD will be compiled and made available in the sysroot for rustc to execute,
#rust.lld = false, except for targets that opt into LLD (see `target.default-linker-linux-override`)

# Indicates if we should override the linker used to link Rust crates during bootstrap to be LLD.
# If set to `true` or `"external"`, a global `lld` binary that has to be in $PATH
Expand Down Expand Up @@ -1067,3 +1063,17 @@
# Link the compiler and LLVM against `jemalloc` instead of the default libc allocator.
# This overrides the global `rust.jemalloc` option. See that option for more info.
#jemalloc = rust.jemalloc (bool)

# The linker configuration that will *override* the default linker used for Linux
# targets in the built compiler.
#
# The following values are supported:
# - `off` => do not apply any override and use the default linker. This can be used to opt out of
# linker overrides set by bootstrap for specific targets (see below).
# - `self-contained-lld-cc` => override the default linker to be self-contained LLD (`rust-lld`)
# that is invoked through `cc`.
#
# Currently, the following targets automatically opt into the self-contained LLD linker, unless you
# pass `off`:
# - x86_64-unknown-linux-gnu
#default-linker-linux-override = "off" (for most targets)
69 changes: 69 additions & 0 deletions compiler/rustc_codegen_llvm/src/debuginfo/di_builder.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use libc::c_uint;
use rustc_abi::Align;

use crate::llvm::debuginfo::DIBuilder;
use crate::llvm::{self, ToLlvmBool};

/// Extension trait for defining safe wrappers and helper methods on
/// `&DIBuilder<'ll>`, without requiring it to be defined in the same crate.
pub(crate) trait DIBuilderExt<'ll> {
fn as_di_builder(&self) -> &DIBuilder<'ll>;

fn create_expression(&self, addr_ops: &[u64]) -> &'ll llvm::Metadata {
let this = self.as_di_builder();
unsafe { llvm::LLVMDIBuilderCreateExpression(this, addr_ops.as_ptr(), addr_ops.len()) }
}

fn create_static_variable(
&self,
scope: Option<&'ll llvm::Metadata>,
name: &str,
linkage_name: &str,
file: &'ll llvm::Metadata,
line_number: c_uint,
ty: &'ll llvm::Metadata,
is_local_to_unit: bool,
val: &'ll llvm::Value,
decl: Option<&'ll llvm::Metadata>,
align: Option<Align>,
) -> &'ll llvm::Metadata {
let this = self.as_di_builder();
let align_in_bits = align.map_or(0, |align| align.bits() as u32);

// `LLVMDIBuilderCreateGlobalVariableExpression` would assert if we
// gave it a null `Expr` pointer, so give it an empty expression
// instead, which is what the C++ `createGlobalVariableExpression`
// method would do if given a null `DIExpression` pointer.
let expr = self.create_expression(&[]);

let global_var_expr = unsafe {
llvm::LLVMDIBuilderCreateGlobalVariableExpression(
this,
scope,
name.as_ptr(),
name.len(),
linkage_name.as_ptr(),
linkage_name.len(),
file,
line_number,
ty,
is_local_to_unit.to_llvm_bool(),
expr,
decl,
align_in_bits,
)
};

unsafe { llvm::LLVMGlobalSetMetadata(val, llvm::MD_dbg, global_var_expr) };

global_var_expr
}
}

impl<'ll> DIBuilderExt<'ll> for &DIBuilder<'ll> {
fn as_di_builder(&self) -> &DIBuilder<'ll> {
self
}

// All other methods have default bodies that rely on `as_di_builder`.
}
61 changes: 25 additions & 36 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ use super::namespace::mangled_name_of_instance;
use super::type_names::{compute_debuginfo_type_name, compute_debuginfo_vtable_name};
use super::utils::{DIB, debug_context, get_namespace_for_item, is_node_local_to_unit};
use crate::common::{AsCCharPtr, CodegenCx};
use crate::debuginfo::dwarf_const;
use crate::debuginfo::metadata::type_map::build_type_with_children;
use crate::debuginfo::utils::{WidePtrKind, wide_pointer_kind};
use crate::debuginfo::{DIBuilderExt, dwarf_const};
use crate::llvm::debuginfo::{
DIBasicType, DIBuilder, DICompositeType, DIDescriptor, DIFile, DIFlags, DILexicalBlock,
DIScope, DIType, DebugEmissionKind, DebugNameTableKind,
Expand Down Expand Up @@ -1410,23 +1410,18 @@ pub(crate) fn build_global_var_di_node<'ll>(

let global_align = cx.align_of(variable_type);

unsafe {
llvm::LLVMRustDIBuilderCreateStaticVariable(
DIB(cx),
Some(var_scope),
var_name.as_c_char_ptr(),
var_name.len(),
linkage_name.as_c_char_ptr(),
linkage_name.len(),
file_metadata,
line_number,
type_di_node,
is_local_to_unit,
global,
None,
global_align.bits() as u32,
);
}
DIB(cx).create_static_variable(
Some(var_scope),
var_name,
linkage_name,
file_metadata,
line_number,
type_di_node,
is_local_to_unit,
global, // (value)
None, // (decl)
Some(global_align),
);
}

/// Generates LLVM debuginfo for a vtable.
Expand Down Expand Up @@ -1643,25 +1638,19 @@ pub(crate) fn create_vtable_di_node<'ll, 'tcx>(
let vtable_name =
compute_debuginfo_vtable_name(cx.tcx, ty, poly_trait_ref, VTableNameKind::GlobalVariable);
let vtable_type_di_node = build_vtable_type_di_node(cx, ty, poly_trait_ref);
let linkage_name = "";

unsafe {
llvm::LLVMRustDIBuilderCreateStaticVariable(
DIB(cx),
NO_SCOPE_METADATA,
vtable_name.as_c_char_ptr(),
vtable_name.len(),
linkage_name.as_c_char_ptr(),
linkage_name.len(),
unknown_file_metadata(cx),
UNKNOWN_LINE_NUMBER,
vtable_type_di_node,
true,
vtable,
None,
0,
);
}
DIB(cx).create_static_variable(
NO_SCOPE_METADATA,
&vtable_name,
"", // (linkage_name)
unknown_file_metadata(cx),
UNKNOWN_LINE_NUMBER,
vtable_type_di_node,
true, // (is_local_to_unit)
vtable, // (value)
None, // (decl)
None::<Align>,
);
}

/// Creates an "extension" of an existing `DIScope` into another file.
Expand Down
11 changes: 5 additions & 6 deletions compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ use rustc_target::spec::DebuginfoKind;
use smallvec::SmallVec;
use tracing::debug;

use self::create_scope_map::compute_mir_scopes;
pub(crate) use self::di_builder::DIBuilderExt;
pub(crate) use self::metadata::build_global_var_di_node;
use self::metadata::{
UNKNOWN_COLUMN_NUMBER, UNKNOWN_LINE_NUMBER, file_metadata, spanned_type_di_node, type_di_node,
};
Expand All @@ -42,15 +45,13 @@ use crate::llvm::debuginfo::{
use crate::llvm::{self, Value};

mod create_scope_map;
mod di_builder;
mod dwarf_const;
mod gdb;
pub(crate) mod metadata;
mod namespace;
mod utils;

use self::create_scope_map::compute_mir_scopes;
pub(crate) use self::metadata::build_global_var_di_node;

/// A context object for maintaining all state needed by the debuginfo module.
pub(crate) struct CodegenUnitDebugContext<'ll, 'tcx> {
llmod: &'ll llvm::Module,
Expand Down Expand Up @@ -182,9 +183,7 @@ impl<'ll> DebugInfoBuilderMethods for Builder<'_, 'll, '_> {
}

let di_builder = DIB(self.cx());
let addr_expr = unsafe {
llvm::LLVMDIBuilderCreateExpression(di_builder, addr_ops.as_ptr(), addr_ops.len())
};
let addr_expr = di_builder.create_expression(&addr_ops);
unsafe {
llvm::LLVMDIBuilderInsertDeclareRecordAtEnd(
di_builder,
Expand Down
39 changes: 19 additions & 20 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ use libc::{c_char, c_int, c_uchar, c_uint, c_ulonglong, c_void, size_t};

use super::RustString;
use super::debuginfo::{
DIArray, DIBuilder, DIDerivedType, DIDescriptor, DIEnumerator, DIFile, DIFlags,
DIGlobalVariableExpression, DILocation, DISPFlags, DIScope, DISubprogram,
DITemplateTypeParameter, DIType, DebugEmissionKind, DebugNameTableKind,
DIArray, DIBuilder, DIDerivedType, DIDescriptor, DIEnumerator, DIFile, DIFlags, DILocation,
DISPFlags, DIScope, DISubprogram, DITemplateTypeParameter, DIType, DebugEmissionKind,
DebugNameTableKind,
};
use crate::llvm::MetadataKindId;
use crate::{TryFromU32, llvm};
Expand Down Expand Up @@ -781,7 +781,6 @@ pub(crate) mod debuginfo {
pub(crate) type DIDerivedType = DIType;
pub(crate) type DICompositeType = DIDerivedType;
pub(crate) type DIVariable = DIDescriptor;
pub(crate) type DIGlobalVariableExpression = DIDescriptor;
pub(crate) type DIArray = DIDescriptor;
pub(crate) type DIEnumerator = DIDescriptor;
pub(crate) type DITemplateTypeParameter = DIDescriptor;
Expand Down Expand Up @@ -1877,6 +1876,22 @@ unsafe extern "C" {
Length: size_t,
) -> &'ll Metadata;

pub(crate) fn LLVMDIBuilderCreateGlobalVariableExpression<'ll>(
Builder: &DIBuilder<'ll>,
Scope: Option<&'ll Metadata>,
Name: *const c_uchar, // See "PTR_LEN_STR".
NameLen: size_t,
Linkage: *const c_uchar, // See "PTR_LEN_STR".
LinkLen: size_t,
File: &'ll Metadata,
LineNo: c_uint,
Ty: &'ll Metadata,
LocalToUnit: llvm::Bool,
Expr: &'ll Metadata,
Decl: Option<&'ll Metadata>,
AlignInBits: u32,
) -> &'ll Metadata;

pub(crate) fn LLVMDIBuilderInsertDeclareRecordAtEnd<'ll>(
Builder: &DIBuilder<'ll>,
Storage: &'ll Value,
Expand Down Expand Up @@ -2213,22 +2228,6 @@ unsafe extern "C" {
Ty: &'a DIType,
) -> &'a DIType;

pub(crate) fn LLVMRustDIBuilderCreateStaticVariable<'a>(
Builder: &DIBuilder<'a>,
Context: Option<&'a DIScope>,
Name: *const c_char,
NameLen: size_t,
LinkageName: *const c_char,
LinkageNameLen: size_t,
File: &'a DIFile,
LineNo: c_uint,
Ty: &'a DIType,
isLocalToUnit: bool,
Val: &'a Value,
Decl: Option<&'a DIDescriptor>,
AlignInBits: u32,
) -> &'a DIGlobalVariableExpression;

pub(crate) fn LLVMRustDIBuilderCreateEnumerator<'a>(
Builder: &DIBuilder<'a>,
Name: *const c_char,
Expand Down
15 changes: 10 additions & 5 deletions compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1510,11 +1510,11 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
return;
}

let typing_env = ty::TypingEnv::non_body_analysis(tcx, adt.did());
// For each field, figure out if it's known to have "trivial" layout (i.e., is a 1-ZST), with
// "known" respecting #[non_exhaustive] attributes.
let field_infos = adt.all_fields().map(|field| {
let ty = field.ty(tcx, GenericArgs::identity_for_item(tcx, field.did));
let typing_env = ty::TypingEnv::non_body_analysis(tcx, field.did);
let layout = tcx.layout_of(typing_env.as_query_input(ty));
// We are currently checking the type this field came from, so it must be local
let span = tcx.hir_span_if_local(field.did).unwrap();
Expand All @@ -1526,11 +1526,16 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)

fn check_non_exhaustive<'tcx>(
tcx: TyCtxt<'tcx>,
typing_env: ty::TypingEnv<'tcx>,
t: Ty<'tcx>,
) -> ControlFlow<(&'static str, DefId, GenericArgsRef<'tcx>, bool)> {
// We can encounter projections during traversal, so ensure the type is normalized.
let t = tcx.try_normalize_erasing_regions(typing_env, t).unwrap_or(t);
match t.kind() {
ty::Tuple(list) => list.iter().try_for_each(|t| check_non_exhaustive(tcx, t)),
ty::Array(ty, _) => check_non_exhaustive(tcx, *ty),
ty::Tuple(list) => {
list.iter().try_for_each(|t| check_non_exhaustive(tcx, typing_env, t))
}
ty::Array(ty, _) => check_non_exhaustive(tcx, typing_env, *ty),
ty::Adt(def, args) => {
if !def.did().is_local()
&& !find_attr!(
Expand All @@ -1555,13 +1560,13 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
}
def.all_fields()
.map(|field| field.ty(tcx, args))
.try_for_each(|t| check_non_exhaustive(tcx, t))
.try_for_each(|t| check_non_exhaustive(tcx, typing_env, t))
}
_ => ControlFlow::Continue(()),
}
}

(span, trivial, check_non_exhaustive(tcx, ty).break_value())
(span, trivial, check_non_exhaustive(tcx, typing_env, ty).break_value())
});

let non_trivial_fields = field_infos
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_index/src/bit_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,7 @@ impl<T: Idx> ChunkedBitSet<T> {
}

pub fn clear(&mut self) {
let domain_size = self.domain_size();
*self = ChunkedBitSet::new_empty(domain_size);
self.chunks.fill_with(|| Chunk::Zeros);
}

#[cfg(test)]
Expand Down Expand Up @@ -684,9 +683,7 @@ impl<T: Idx> ChunkedBitSet<T> {

/// Sets all bits to true.
pub fn insert_all(&mut self) {
for chunk in self.chunks.iter_mut() {
*chunk = Ones;
}
self.chunks.fill_with(|| Chunk::Ones);
}

/// Returns `true` if the set has changed.
Expand Down
31 changes: 0 additions & 31 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,37 +1038,6 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariantMemberType(
fromRust(Flags), unwrapDI<DIType>(Ty)));
}

extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStaticVariable(
LLVMDIBuilderRef Builder, LLVMMetadataRef Context, const char *Name,
size_t NameLen, const char *LinkageName, size_t LinkageNameLen,
LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty,
bool IsLocalToUnit, LLVMValueRef V, LLVMMetadataRef Decl = nullptr,
uint32_t AlignInBits = 0) {
llvm::GlobalVariable *InitVal = cast<llvm::GlobalVariable>(unwrap(V));

llvm::DIExpression *InitExpr = nullptr;
if (llvm::ConstantInt *IntVal = llvm::dyn_cast<llvm::ConstantInt>(InitVal)) {
InitExpr = unwrap(Builder)->createConstantValueExpression(
IntVal->getValue().getSExtValue());
} else if (llvm::ConstantFP *FPVal =
llvm::dyn_cast<llvm::ConstantFP>(InitVal)) {
InitExpr = unwrap(Builder)->createConstantValueExpression(
FPVal->getValueAPF().bitcastToAPInt().getZExtValue());
}

llvm::DIGlobalVariableExpression *VarExpr =
unwrap(Builder)->createGlobalVariableExpression(
unwrapDI<DIDescriptor>(Context), StringRef(Name, NameLen),
StringRef(LinkageName, LinkageNameLen), unwrapDI<DIFile>(File),
LineNo, unwrapDI<DIType>(Ty), IsLocalToUnit,
/* isDefined */ true, InitExpr, unwrapDIPtr<MDNode>(Decl),
/* templateParams */ nullptr, AlignInBits);

InitVal->setMetadata("dbg", VarExpr);

return wrap(VarExpr);
}

extern "C" LLVMMetadataRef
LLVMRustDIBuilderCreateEnumerator(LLVMDIBuilderRef Builder, const char *Name,
size_t NameLen, const uint64_t Value[2],
Expand Down
Loading
Loading