Skip to content

Commit 7521bda

Browse files
committed
Auto merge of rust-lang#129225 - jieyouxu:rollup-xwtkwgr, r=jieyouxu
Rollup of 5 pull requests Successful merges: - rust-lang#129164 (Use `ar_archive_writer` for writing COFF import libs on all backends) - rust-lang#129173 (Fix `is_val_statically_known` for floats) - rust-lang#129185 (Port `run-make/libtest-json/validate_json.py` to Rust) - rust-lang#129203 (Use cnum for extern crate data key) - rust-lang#129221 (Remove JohnTitor from review rotation) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 79f5c16 + f31f0f3 commit 7521bda

File tree

21 files changed

+217
-220
lines changed

21 files changed

+217
-220
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ dependencies = [
205205

206206
[[package]]
207207
name = "ar_archive_writer"
208-
version = "0.3.3"
208+
version = "0.4.0"
209209
source = "registry+https://github.com/rust-lang/crates.io-index"
210-
checksum = "3f2bcb7cf51decfbbfc7ef476e28b0775b13e5eb1190f8b7df145cd53d4f4374"
210+
checksum = "de11a9d32db3327f981143bdf699ade4d637c6887b13b97e6e91a9154666963c"
211211
dependencies = [
212212
"object 0.36.2",
213213
]
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
use std::borrow::Borrow;
2-
use std::fs;
3-
use std::path::Path;
4-
5-
use ar_archive_writer::{COFFShortExport, MachineTypes};
61
use rustc_codegen_ssa::back::archive::{
7-
create_mingw_dll_import_lib, ArArchiveBuilder, ArchiveBuilder, ArchiveBuilderBuilder,
8-
DEFAULT_OBJECT_READER,
2+
ArArchiveBuilder, ArchiveBuilder, ArchiveBuilderBuilder, DEFAULT_OBJECT_READER,
93
};
10-
use rustc_codegen_ssa::common::is_mingw_gnu_toolchain;
114
use rustc_session::Session;
125

136
pub(crate) struct ArArchiveBuilderBuilder;
@@ -16,78 +9,4 @@ impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
169
fn new_archive_builder<'a>(&self, sess: &'a Session) -> Box<dyn ArchiveBuilder + 'a> {
1710
Box::new(ArArchiveBuilder::new(sess, &DEFAULT_OBJECT_READER))
1811
}
19-
20-
fn create_dll_import_lib(
21-
&self,
22-
sess: &Session,
23-
lib_name: &str,
24-
import_name_and_ordinal_vector: Vec<(String, Option<u16>)>,
25-
output_path: &Path,
26-
) {
27-
if is_mingw_gnu_toolchain(&sess.target) {
28-
// The binutils linker used on -windows-gnu targets cannot read the import
29-
// libraries generated by LLVM: in our attempts, the linker produced an .EXE
30-
// that loaded but crashed with an AV upon calling one of the imported
31-
// functions. Therefore, use binutils to create the import library instead,
32-
// by writing a .DEF file to the temp dir and calling binutils's dlltool.
33-
create_mingw_dll_import_lib(
34-
sess,
35-
lib_name,
36-
import_name_and_ordinal_vector,
37-
output_path,
38-
);
39-
} else {
40-
let mut file =
41-
match fs::OpenOptions::new().write(true).create_new(true).open(&output_path) {
42-
Ok(file) => file,
43-
Err(error) => {
44-
sess.dcx().fatal(format!(
45-
"failed to create import library file `{path}`: {error}",
46-
path = output_path.display(),
47-
));
48-
}
49-
};
50-
51-
let machine = match sess.target.arch.borrow() {
52-
"x86" => MachineTypes::I386,
53-
"x86_64" => MachineTypes::AMD64,
54-
"arm" => MachineTypes::ARMNT,
55-
"aarch64" => MachineTypes::ARM64,
56-
_ => {
57-
sess.dcx().fatal(format!(
58-
"unsupported target architecture `{arch}`",
59-
arch = sess.target.arch,
60-
));
61-
}
62-
};
63-
64-
let exports = import_name_and_ordinal_vector
65-
.iter()
66-
.map(|(name, ordinal)| COFFShortExport {
67-
name: name.to_string(),
68-
ext_name: None,
69-
symbol_name: None,
70-
alias_target: None,
71-
ordinal: ordinal.unwrap_or(0),
72-
noname: ordinal.is_some(),
73-
data: false,
74-
private: false,
75-
constant: false,
76-
})
77-
.collect::<Vec<_>>();
78-
79-
if let Err(error) = ar_archive_writer::write_import_library(
80-
&mut file,
81-
lib_name,
82-
&exports,
83-
machine,
84-
!sess.target.is_like_msvc,
85-
) {
86-
sess.dcx().fatal(format!(
87-
"failed to create import library `{path}`: `{error}`",
88-
path = output_path.display(),
89-
));
90-
}
91-
}
92-
}
9312
}

compiler/rustc_codegen_cranelift/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#![warn(unused_lifetimes)]
1313
// tidy-alphabetical-end
1414

15-
extern crate ar_archive_writer;
1615
extern crate jobserver;
1716
#[macro_use]
1817
extern crate rustc_middle;

compiler/rustc_codegen_llvm/messages.ftl

-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ codegen_llvm_dynamic_linking_with_lto =
55
.note = only 'staticlib', 'bin', and 'cdylib' outputs are supported with LTO
66
77
8-
codegen_llvm_error_creating_import_library =
9-
Error creating import library for {$lib_name}: {$error}
10-
118
codegen_llvm_fixed_x18_invalid_arch = the `-Zfixed-x18` flag is not supported on the `{$arch}` architecture
129
1310
codegen_llvm_from_llvm_diag = {$message}

compiler/rustc_codegen_llvm/src/back/archive.rs

+3-91
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@ use std::path::{Path, PathBuf};
55
use std::{io, mem, ptr, str};
66

77
use rustc_codegen_ssa::back::archive::{
8-
create_mingw_dll_import_lib, try_extract_macho_fat_archive, ArArchiveBuilder,
9-
ArchiveBuildFailure, ArchiveBuilder, ArchiveBuilderBuilder, ObjectReader, UnknownArchiveKind,
10-
DEFAULT_OBJECT_READER,
8+
try_extract_macho_fat_archive, ArArchiveBuilder, ArchiveBuildFailure, ArchiveBuilder,
9+
ArchiveBuilderBuilder, ObjectReader, UnknownArchiveKind, DEFAULT_OBJECT_READER,
1110
};
12-
use rustc_codegen_ssa::common;
1311
use rustc_session::Session;
14-
use tracing::trace;
1512

16-
use crate::errors::ErrorCreatingImportLibrary;
1713
use crate::llvm::archive_ro::{ArchiveRO, Child};
18-
use crate::llvm::{self, ArchiveKind, LLVMMachineType, LLVMRustCOFFShortExport};
14+
use crate::llvm::{self, ArchiveKind};
1915

2016
/// Helper for adding many files to an archive.
2117
#[must_use = "must call build() to finish building the archive"]
@@ -44,18 +40,6 @@ fn is_relevant_child(c: &Child<'_>) -> bool {
4440
}
4541
}
4642

47-
/// Map machine type strings to values of LLVM's MachineTypes enum.
48-
fn llvm_machine_type(cpu: &str) -> LLVMMachineType {
49-
match cpu {
50-
"x86_64" => LLVMMachineType::AMD64,
51-
"x86" => LLVMMachineType::I386,
52-
"aarch64" => LLVMMachineType::ARM64,
53-
"arm64ec" => LLVMMachineType::ARM64EC,
54-
"arm" => LLVMMachineType::ARM,
55-
_ => panic!("unsupported cpu type {cpu}"),
56-
}
57-
}
58-
5943
impl<'a> ArchiveBuilder for LlvmArchiveBuilder<'a> {
6044
fn add_archive(
6145
&mut self,
@@ -116,78 +100,6 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
116100
Box::new(ArArchiveBuilder::new(sess, &LLVM_OBJECT_READER))
117101
}
118102
}
119-
120-
fn create_dll_import_lib(
121-
&self,
122-
sess: &Session,
123-
lib_name: &str,
124-
import_name_and_ordinal_vector: Vec<(String, Option<u16>)>,
125-
output_path: &Path,
126-
) {
127-
if common::is_mingw_gnu_toolchain(&sess.target) {
128-
// The binutils linker used on -windows-gnu targets cannot read the import
129-
// libraries generated by LLVM: in our attempts, the linker produced an .EXE
130-
// that loaded but crashed with an AV upon calling one of the imported
131-
// functions. Therefore, use binutils to create the import library instead,
132-
// by writing a .DEF file to the temp dir and calling binutils's dlltool.
133-
create_mingw_dll_import_lib(
134-
sess,
135-
lib_name,
136-
import_name_and_ordinal_vector,
137-
output_path,
138-
);
139-
} else {
140-
// we've checked for \0 characters in the library name already
141-
let dll_name_z = CString::new(lib_name).unwrap();
142-
143-
let output_path_z = rustc_fs_util::path_to_c_string(&output_path);
144-
145-
trace!("invoking LLVMRustWriteImportLibrary");
146-
trace!(" dll_name {:#?}", dll_name_z);
147-
trace!(" output_path {}", output_path.display());
148-
trace!(
149-
" import names: {}",
150-
import_name_and_ordinal_vector
151-
.iter()
152-
.map(|(name, _ordinal)| name.clone())
153-
.collect::<Vec<_>>()
154-
.join(", "),
155-
);
156-
157-
// All import names are Rust identifiers and therefore cannot contain \0 characters.
158-
// FIXME: when support for #[link_name] is implemented, ensure that the import names
159-
// still don't contain any \0 characters. Also need to check that the names don't
160-
// contain substrings like " @" or "NONAME" that are keywords or otherwise reserved
161-
// in definition files.
162-
let cstring_import_name_and_ordinal_vector: Vec<(CString, Option<u16>)> =
163-
import_name_and_ordinal_vector
164-
.into_iter()
165-
.map(|(name, ordinal)| (CString::new(name).unwrap(), ordinal))
166-
.collect();
167-
168-
let ffi_exports: Vec<LLVMRustCOFFShortExport> = cstring_import_name_and_ordinal_vector
169-
.iter()
170-
.map(|(name_z, ordinal)| LLVMRustCOFFShortExport::new(name_z.as_ptr(), *ordinal))
171-
.collect();
172-
let result = unsafe {
173-
crate::llvm::LLVMRustWriteImportLibrary(
174-
dll_name_z.as_ptr(),
175-
output_path_z.as_ptr(),
176-
ffi_exports.as_ptr(),
177-
ffi_exports.len(),
178-
llvm_machine_type(&sess.target.arch) as u16,
179-
!sess.target.is_like_msvc,
180-
)
181-
};
182-
183-
if result == crate::llvm::LLVMRustResult::Failure {
184-
sess.dcx().emit_fatal(ErrorCreatingImportLibrary {
185-
lib_name,
186-
error: llvm::last_error().unwrap_or("unknown LLVM error".to_string()),
187-
});
188-
}
189-
}
190-
}
191103
}
192104

193105
// The object crate doesn't know how to get symbols for LLVM bitcode and COFF bigobj files.

compiler/rustc_codegen_llvm/src/context.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1000,8 +1000,10 @@ impl<'ll> CodegenCx<'ll, '_> {
10001000
ifn!("llvm.is.constant.i64", fn(t_i64) -> i1);
10011001
ifn!("llvm.is.constant.i128", fn(t_i128) -> i1);
10021002
ifn!("llvm.is.constant.isize", fn(t_isize) -> i1);
1003+
ifn!("llvm.is.constant.f16", fn(t_f16) -> i1);
10031004
ifn!("llvm.is.constant.f32", fn(t_f32) -> i1);
10041005
ifn!("llvm.is.constant.f64", fn(t_f64) -> i1);
1006+
ifn!("llvm.is.constant.f128", fn(t_f128) -> i1);
10051007
ifn!("llvm.is.constant.ptr", fn(ptr) -> i1);
10061008

10071009
ifn!("llvm.expect.i1", fn(i1, i1) -> i1);

compiler/rustc_codegen_llvm/src/errors.rs

-7
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@ pub(crate) enum PossibleFeature<'a> {
3939
None,
4040
}
4141

42-
#[derive(Diagnostic)]
43-
#[diag(codegen_llvm_error_creating_import_library)]
44-
pub(crate) struct ErrorCreatingImportLibrary<'a> {
45-
pub lib_name: &'a str,
46-
pub error: String,
47-
}
48-
4942
#[derive(Diagnostic)]
5043
#[diag(codegen_llvm_symbol_already_defined)]
5144
pub(crate) struct SymbolAlreadyDefined<'a> {

compiler/rustc_codegen_llvm/src/intrinsic.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,22 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
192192
}
193193
sym::is_val_statically_known => {
194194
let intrinsic_type = args[0].layout.immediate_llvm_type(self.cx);
195-
match self.type_kind(intrinsic_type) {
196-
TypeKind::Pointer | TypeKind::Integer | TypeKind::Float | TypeKind::Double => {
197-
self.call_intrinsic(
198-
&format!("llvm.is.constant.{:?}", intrinsic_type),
199-
&[args[0].immediate()],
200-
)
195+
let kind = self.type_kind(intrinsic_type);
196+
let intrinsic_name = match kind {
197+
TypeKind::Pointer | TypeKind::Integer => {
198+
Some(format!("llvm.is.constant.{intrinsic_type:?}"))
201199
}
202-
_ => self.const_bool(false),
200+
// LLVM float types' intrinsic names differ from their type names.
201+
TypeKind::Half => Some(format!("llvm.is.constant.f16")),
202+
TypeKind::Float => Some(format!("llvm.is.constant.f32")),
203+
TypeKind::Double => Some(format!("llvm.is.constant.f64")),
204+
TypeKind::FP128 => Some(format!("llvm.is.constant.f128")),
205+
_ => None,
206+
};
207+
if let Some(intrinsic_name) = intrinsic_name {
208+
self.call_intrinsic(&intrinsic_name, &[args[0].immediate()])
209+
} else {
210+
self.const_bool(false)
203211
}
204212
}
205213
sym::unlikely => self

compiler/rustc_codegen_ssa/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
ar_archive_writer = "0.3.3"
8+
ar_archive_writer = "0.4.0"
99
arrayvec = { version = "0.7", default-features = false }
1010
bitflags = "2.4.1"
1111
cc = "1.0.90"

compiler/rustc_codegen_ssa/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ codegen_ssa_dlltool_fail_import_library =
3232
codegen_ssa_error_calling_dlltool =
3333
Error calling dlltool '{$dlltool_path}': {$error}
3434
35+
codegen_ssa_error_creating_import_library =
36+
Error creating import library for {$lib_name}: {$error}
37+
3538
codegen_ssa_error_creating_remark_dir = failed to create remark directory: {$error}
3639
3740
codegen_ssa_error_writing_def_file =

0 commit comments

Comments
 (0)