Skip to content

Rollup of 8 pull requests #132751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
b2fd8a0
Test fixing raw-dylib
dpaoliello Sep 19, 2024
cc0ec04
Fix #131977 parens mangled in shared mut static lint suggestion
Oct 24, 2024
65b986b
compiletest: add `{ignore,needs}-{rustc,std}-debug-assertions` direct…
jieyouxu Oct 19, 2024
3870022
bootstrap: pass `--with-{rustc,std}-debug-assertions` to compiletest
jieyouxu Oct 21, 2024
0d5cc8e
tests: `ignore-debug` -> `ignore-std-debug-assertions`
jieyouxu Oct 19, 2024
0720880
Separate f128 `%` operation to deal with missing `fmodl` symbol
raoulstrackx Nov 6, 2024
9f5e17f
Fix file formatting
GuillaumeGomez Nov 7, 2024
03383ad
Initialize channel `Block`s directly on the heap
cuviper Nov 7, 2024
0e58f1c
Update test for LLVM 20's new vector splat syntax
zmodem Nov 7, 2024
0ce579f
[StableMIR] API to retrieve definitions from crates
celinval Oct 25, 2024
e7dae08
Rollup merge of #130586 - dpaoliello:fixrawdylib, r=wesleywiser
GuillaumeGomez Nov 7, 2024
72efe76
Rollup merge of #131913 - jieyouxu:only_debug_assertions, r=onur-ozkan
GuillaumeGomez Nov 7, 2024
57b89a4
Rollup merge of #132095 - gechelberger:fix-131977, r=wesleywiser
GuillaumeGomez Nov 7, 2024
24144e9
Rollup merge of #132131 - celinval:smir-crate-defs, r=compiler-errors
GuillaumeGomez Nov 7, 2024
2a2eb3d
Rollup merge of #132696 - fortanix:raoul/rte-235-fix_fmodl_missing_sy…
GuillaumeGomez Nov 7, 2024
928e000
Rollup merge of #132738 - cuviper:channel-heap-init, r=ibraheemdev
GuillaumeGomez Nov 7, 2024
8a06367
Rollup merge of #132739 - GuillaumeGomez:cleanup-scrape-code, r=notri…
GuillaumeGomez Nov 7, 2024
b173464
Rollup merge of #132740 - zmodem:simd_syntax_update, r=durin42
GuillaumeGomez Nov 7, 2024
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
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_gcc/src/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::path::Path;

use rustc_codegen_ssa::back::archive::{
ArArchiveBuilder, ArchiveBuilder, ArchiveBuilderBuilder, DEFAULT_OBJECT_READER,
ImportLibraryItem,
};
use rustc_session::Session;

Expand All @@ -16,7 +17,7 @@ impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
&self,
_sess: &Session,
_lib_name: &str,
_import_name_and_ordinal_vector: Vec<(String, Option<u16>)>,
_items: Vec<ImportLibraryItem>,
_output_path: &Path,
) {
unimplemented!("creating dll imports is not yet supported");
Expand Down
25 changes: 16 additions & 9 deletions compiler/rustc_codegen_llvm/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'t
let llfn = if tcx.sess.target.arch == "x86"
&& let Some(dllimport) = crate::common::get_dllimport(tcx, instance_def_id, sym)
{
// When calling functions in generated import libraries, MSVC needs
// the fully decorated name (as would have been in the declaring
// object file), but MinGW wants the name as exported (as would be
// in the def file) which may be missing decorations.
let mingw_gnu_toolchain = common::is_mingw_gnu_toolchain(&tcx.sess.target);
let llfn = cx.declare_fn(
&common::i686_decorated_name(
dllimport,
mingw_gnu_toolchain,
true,
!mingw_gnu_toolchain,
),
fn_abi,
Some(instance),
);

// Fix for https://github.com/rust-lang/rust/issues/104453
// On x86 Windows, LLVM uses 'L' as the prefix for any private
// global symbols, so when we create an undecorated function symbol
Expand All @@ -55,15 +71,6 @@ pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'t
// LLVM will prefix the name with `__imp_`. Ideally, we'd like the
// existing logic below to set the Storage Class, but it has an
// exemption for MinGW for backwards compatibility.
let llfn = cx.declare_fn(
&common::i686_decorated_name(
dllimport,
common::is_mingw_gnu_toolchain(&tcx.sess.target),
true,
),
fn_abi,
Some(instance),
);
unsafe {
llvm::LLVMSetDLLStorageClass(llfn, llvm::DLLStorageClass::DllImport);
}
Expand Down
10 changes: 2 additions & 8 deletions compiler/rustc_codegen_llvm/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,10 @@ fn check_and_apply_linkage<'ll, 'tcx>(
unsafe { llvm::LLVMSetInitializer(g2, g1) };
g2
} else if cx.tcx.sess.target.arch == "x86"
&& common::is_mingw_gnu_toolchain(&cx.tcx.sess.target)
&& let Some(dllimport) = crate::common::get_dllimport(cx.tcx, def_id, sym)
{
cx.declare_global(
&common::i686_decorated_name(
dllimport,
common::is_mingw_gnu_toolchain(&cx.tcx.sess.target),
true,
),
llty,
)
cx.declare_global(&common::i686_decorated_name(dllimport, true, true, false), llty)
} else {
// Generate an external declaration.
// FIXME(nagisa): investigate whether it can be changed into define_global
Expand Down
63 changes: 37 additions & 26 deletions compiler/rustc_codegen_ssa/src/back/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,35 @@ use crate::errors::{
DlltoolFailImportLibrary, ErrorCallingDllTool, ErrorCreatingImportLibrary, ErrorWritingDEFFile,
};

/// An item to be included in an import library.
/// This is a slimmed down version of `COFFShortExport` from `ar-archive-writer`.
pub struct ImportLibraryItem {
/// The name to be exported.
pub name: String,
/// The ordinal to be exported, if any.
pub ordinal: Option<u16>,
/// The original, decorated name if `name` is not decorated.
pub symbol_name: Option<String>,
/// True if this is a data export, false if it is a function export.
pub is_data: bool,
}

impl From<ImportLibraryItem> for COFFShortExport {
fn from(item: ImportLibraryItem) -> Self {
COFFShortExport {
name: item.name,
ext_name: None,
symbol_name: item.symbol_name,
alias_target: None,
ordinal: item.ordinal.unwrap_or(0),
noname: item.ordinal.is_some(),
data: item.is_data,
private: false,
constant: false,
}
}
}

pub trait ArchiveBuilderBuilder {
fn new_archive_builder<'a>(&self, sess: &'a Session) -> Box<dyn ArchiveBuilder + 'a>;

Expand All @@ -38,7 +67,7 @@ pub trait ArchiveBuilderBuilder {
&self,
sess: &Session,
lib_name: &str,
import_name_and_ordinal_vector: Vec<(String, Option<u16>)>,
items: Vec<ImportLibraryItem>,
output_path: &Path,
) {
if common::is_mingw_gnu_toolchain(&sess.target) {
Expand All @@ -47,21 +76,16 @@ pub trait ArchiveBuilderBuilder {
// that loaded but crashed with an AV upon calling one of the imported
// functions. Therefore, use binutils to create the import library instead,
// by writing a .DEF file to the temp dir and calling binutils's dlltool.
create_mingw_dll_import_lib(
sess,
lib_name,
import_name_and_ordinal_vector,
output_path,
);
create_mingw_dll_import_lib(sess, lib_name, items, output_path);
} else {
trace!("creating import library");
trace!(" dll_name {:#?}", lib_name);
trace!(" output_path {}", output_path.display());
trace!(
" import names: {}",
import_name_and_ordinal_vector
items
.iter()
.map(|(name, _ordinal)| name.clone())
.map(|ImportLibraryItem { name, .. }| name.clone())
.collect::<Vec<_>>()
.join(", "),
);
Expand All @@ -79,20 +103,7 @@ pub trait ArchiveBuilderBuilder {
.emit_fatal(ErrorCreatingImportLibrary { lib_name, error: error.to_string() }),
};

let exports = import_name_and_ordinal_vector
.iter()
.map(|(name, ordinal)| COFFShortExport {
name: name.to_string(),
ext_name: None,
symbol_name: None,
alias_target: None,
ordinal: ordinal.unwrap_or(0),
noname: ordinal.is_some(),
data: false,
private: false,
constant: false,
})
.collect::<Vec<_>>();
let exports = items.into_iter().map(Into::into).collect::<Vec<_>>();
let machine = match &*sess.target.arch {
"x86_64" => MachineTypes::AMD64,
"x86" => MachineTypes::I386,
Expand Down Expand Up @@ -160,16 +171,16 @@ pub trait ArchiveBuilderBuilder {
fn create_mingw_dll_import_lib(
sess: &Session,
lib_name: &str,
import_name_and_ordinal_vector: Vec<(String, Option<u16>)>,
items: Vec<ImportLibraryItem>,
output_path: &Path,
) {
let def_file_path = output_path.with_extension("def");

let def_file_content = format!(
"EXPORTS\n{}",
import_name_and_ordinal_vector
items
.into_iter()
.map(|(name, ordinal)| {
.map(|ImportLibraryItem { name, ordinal, .. }| {
match ordinal {
Some(n) => format!("{name} @{n} NONAME"),
None => name,
Expand Down
35 changes: 27 additions & 8 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use rustc_target::spec::{
use tempfile::Builder as TempFileBuilder;
use tracing::{debug, info, warn};

use super::archive::{ArchiveBuilder, ArchiveBuilderBuilder};
use super::archive::{ArchiveBuilder, ArchiveBuilderBuilder, ImportLibraryItem};
use super::command::Command;
use super::linker::{self, Linker};
use super::metadata::{MetadataPosition, create_wrapper_file};
Expand Down Expand Up @@ -495,24 +495,43 @@ fn create_dll_import_libs<'a>(

let mingw_gnu_toolchain = common::is_mingw_gnu_toolchain(&sess.target);

let import_name_and_ordinal_vector: Vec<(String, Option<u16>)> = raw_dylib_imports
let items: Vec<ImportLibraryItem> = raw_dylib_imports
.iter()
.map(|import: &DllImport| {
if sess.target.arch == "x86" {
(
common::i686_decorated_name(import, mingw_gnu_toolchain, false),
import.ordinal(),
)
ImportLibraryItem {
name: common::i686_decorated_name(
import,
mingw_gnu_toolchain,
false,
false,
),
ordinal: import.ordinal(),
symbol_name: import.is_missing_decorations().then(|| {
common::i686_decorated_name(
import,
mingw_gnu_toolchain,
false,
true,
)
}),
is_data: !import.is_fn,
}
} else {
(import.name.to_string(), import.ordinal())
ImportLibraryItem {
name: import.name.to_string(),
ordinal: import.ordinal(),
symbol_name: None,
is_data: !import.is_fn,
}
}
})
.collect();

archive_builder_builder.create_dll_import_lib(
sess,
&raw_dylib_name,
import_name_and_ordinal_vector,
items,
&output_path,
);

Expand Down
9 changes: 6 additions & 3 deletions compiler/rustc_codegen_ssa/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,15 @@ pub fn i686_decorated_name(
dll_import: &DllImport,
mingw: bool,
disable_name_mangling: bool,
force_fully_decorated: bool,
) -> String {
let name = dll_import.name.as_str();

let (add_prefix, add_suffix) = match dll_import.import_name_type {
Some(PeImportNameType::NoPrefix) => (false, true),
Some(PeImportNameType::Undecorated) => (false, false),
let (add_prefix, add_suffix) = match (force_fully_decorated, dll_import.import_name_type) {
// No prefix is a bit weird, in that LLVM/ar_archive_writer won't emit it, so we will
// ignore `force_fully_decorated` and always partially decorate it.
(_, Some(PeImportNameType::NoPrefix)) => (false, true),
(false, Some(PeImportNameType::Undecorated)) => (false, false),
_ => (true, true),
};

Expand Down
27 changes: 19 additions & 8 deletions compiler/rustc_lint/src/static_mut_refs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use rustc_hir::{Expr, Stmt};
use rustc_middle::ty::{Mutability, TyKind};
use rustc_session::lint::FutureIncompatibilityReason;
use rustc_session::{declare_lint, declare_lint_pass};
use rustc_span::Span;
use rustc_span::edition::Edition;
use rustc_span::{BytePos, Span};

use crate::lints::{MutRefSugg, RefOfMutStatic};
use crate::{LateContext, LateLintPass, LintContext};
Expand Down Expand Up @@ -71,13 +71,24 @@ impl<'tcx> LateLintPass<'tcx> for StaticMutRefs {
if matches!(borrow_kind, hir::BorrowKind::Ref)
&& let Some(err_span) = path_is_static_mut(ex, err_span) =>
{
emit_static_mut_refs(
cx,
err_span,
err_span.with_hi(ex.span.lo()),
m,
!expr.span.from_expansion(),
);
let source_map = cx.sess().source_map();
let snippet = source_map.span_to_snippet(err_span);

let sugg_span = if let Ok(snippet) = snippet {
// ( ( &IDENT ) )
// ~~~~ exclude these from the suggestion span to avoid unmatching parens
let exclude_n_bytes: u32 = snippet
.chars()
.take_while(|ch| ch.is_whitespace() || *ch == '(')
.map(|ch| ch.len_utf8() as u32)
.sum();

err_span.with_lo(err_span.lo() + BytePos(exclude_n_bytes)).with_hi(ex.span.lo())
} else {
err_span.with_hi(ex.span.lo())
};

emit_static_mut_refs(cx, err_span, sugg_span, m, !expr.span.from_expansion());
}
hir::ExprKind::MethodCall(_, e, _, _)
if let Some(err_span) = path_is_static_mut(e, expr.span)
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ provide! { tcx, def_id, other, cdata,
crate_hash => { cdata.root.header.hash }
crate_host_hash => { cdata.host_hash }
crate_name => { cdata.root.header.name }
num_extern_def_ids => { cdata.num_def_ids() }

extra_filename => { cdata.root.extra_filename.clone() }

Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1844,6 +1844,16 @@ rustc_queries! {
desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id) }
}

/// Gets the number of definitions in a foreign crate.
///
/// This allows external tools to iterate over all definitions in a foreign crate.
///
/// This should never be used for the local crate, instead use `iter_local_def_id`.
query num_extern_def_ids(_: CrateNum) -> usize {
desc { "fetching the number of definitions in a crate" }
separate_provide_extern
}

query lib_features(_: CrateNum) -> &'tcx LibFeatures {
desc { "calculating the lib features defined in a crate" }
separate_provide_extern
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_session/src/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ impl DllImport {
None
}
}

pub fn is_missing_decorations(&self) -> bool {
self.import_name_type == Some(PeImportNameType::Undecorated)
|| self.import_name_type == Some(PeImportNameType::NoPrefix)
}
}

/// Calling convention for a function defined in an external library.
Expand Down
16 changes: 15 additions & 1 deletion compiler/rustc_smir/src/rustc_smir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use stable_mir::{Crate, CrateDef, CrateItem, CrateNum, DefId, Error, Filename, I

use crate::rustc_internal::RustcInternal;
use crate::rustc_smir::builder::BodyBuilder;
use crate::rustc_smir::{Stable, Tables, alloc, new_item_kind, smir_crate};
use crate::rustc_smir::{Stable, Tables, alloc, filter_def_ids, new_item_kind, smir_crate};

impl<'tcx> Context for TablesWrapper<'tcx> {
fn target_info(&self) -> MachineInfo {
Expand Down Expand Up @@ -80,6 +80,20 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
.collect()
}

fn crate_functions(&self, crate_num: CrateNum) -> Vec<FnDef> {
let mut tables = self.0.borrow_mut();
let tcx = tables.tcx;
let krate = crate_num.internal(&mut *tables, tcx);
filter_def_ids(tcx, krate, |def_id| tables.to_fn_def(def_id))
}

fn crate_statics(&self, crate_num: CrateNum) -> Vec<StaticDef> {
let mut tables = self.0.borrow_mut();
let tcx = tables.tcx;
let krate = crate_num.internal(&mut *tables, tcx);
filter_def_ids(tcx, krate, |def_id| tables.to_static(def_id))
}

fn foreign_module(
&self,
mod_def: stable_mir::ty::ForeignModuleDef,
Expand Down
Loading
Loading