Skip to content

Commit cd963c9

Browse files
authored
Rollup merge of rust-lang#109677 - dpaoliello:rawdylib, r=michaelwoerister,wesleywiser
Stabilize raw-dylib, link_ordinal, import_name_type and -Cdlltool This stabilizes the `raw-dylib` feature (rust-lang#58713) for all architectures (i.e., `x86` as it is already stable for all other architectures). Changes: * Permit the use of the `raw-dylib` link kind for x86, the `link_ordinal` attribute and the `import_name_type` key for the `link` attribute. * Mark the `raw_dylib` feature as stable. * Stabilized the `-Zdlltool` argument as `-Cdlltool`. * Note the path to `dlltool` if invoking it failed (we don't need to do this if `dlltool` returns an error since it prints its path in the error message). * Adds tests for `-Cdlltool`. * Adds tests for being unable to find the dlltool executable, and dlltool failing. * Fixes a bug where we were checking the exit code of dlltool to see if it failed, but dlltool always returns 0 (indicating success), so instead we need to check if anything was written to `stderr`. NOTE: As previously noted (rust-lang#104218 (comment)) using dlltool within rustc is temporary, but this is not the first time that Rust has added a temporary tool use and argument: rust-lang#104218 (comment) Big thanks to `````@tbu-````` for the first version of this PR (rust-lang#104218)
2 parents 82cd953 + 1ece1ea commit cd963c9

File tree

62 files changed

+146
-223
lines changed

Some content is hidden

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

62 files changed

+146
-223
lines changed

compiler/rustc_codegen_llvm/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ codegen_llvm_error_writing_def_file =
2424
Error writing .DEF file: {$error}
2525
2626
codegen_llvm_error_calling_dlltool =
27-
Error calling dlltool: {$error}
27+
Error calling dlltool '{$dlltool_path}': {$error}
2828
2929
codegen_llvm_dlltool_fail_import_library =
3030
Dlltool could not create import library: {$stdout}

compiler/rustc_codegen_llvm/src/back/archive.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
198198
"arm" => ("arm", "--32"),
199199
_ => panic!("unsupported arch {}", sess.target.arch),
200200
};
201-
let result = std::process::Command::new(dlltool)
201+
let result = std::process::Command::new(&dlltool)
202202
.args([
203203
"-d",
204204
def_file_path.to_str().unwrap(),
@@ -218,9 +218,13 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
218218

219219
match result {
220220
Err(e) => {
221-
sess.emit_fatal(ErrorCallingDllTool { error: e });
221+
sess.emit_fatal(ErrorCallingDllTool {
222+
dlltool_path: dlltool.to_string_lossy(),
223+
error: e,
224+
});
222225
}
223-
Ok(output) if !output.status.success() => {
226+
// dlltool returns '0' on failure, so check for error output instead.
227+
Ok(output) if !output.stderr.is_empty() => {
224228
sess.emit_fatal(DlltoolFailImportLibrary {
225229
stdout: String::from_utf8_lossy(&output.stdout),
226230
stderr: String::from_utf8_lossy(&output.stderr),
@@ -431,7 +435,7 @@ fn string_to_io_error(s: String) -> io::Error {
431435

432436
fn find_binutils_dlltool(sess: &Session) -> OsString {
433437
assert!(sess.target.options.is_like_windows && !sess.target.options.is_like_msvc);
434-
if let Some(dlltool_path) = &sess.opts.unstable_opts.dlltool {
438+
if let Some(dlltool_path) = &sess.opts.cg.dlltool {
435439
return dlltool_path.clone().into_os_string();
436440
}
437441

compiler/rustc_codegen_llvm/src/errors.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ pub(crate) struct ErrorWritingDEFFile {
6767

6868
#[derive(Diagnostic)]
6969
#[diag(codegen_llvm_error_calling_dlltool)]
70-
pub(crate) struct ErrorCallingDllTool {
70+
pub(crate) struct ErrorCallingDllTool<'a> {
71+
pub dlltool_path: Cow<'a, str>,
7172
pub error: std::io::Error,
7273
}
7374

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -592,15 +592,6 @@ fn should_inherit_track_caller(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
592592

593593
fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &ast::Attribute) -> Option<u16> {
594594
use rustc_ast::{LitIntType, LitKind, MetaItemLit};
595-
if !tcx.features().raw_dylib && tcx.sess.target.arch == "x86" {
596-
feature_err(
597-
&tcx.sess.parse_sess,
598-
sym::raw_dylib,
599-
attr.span,
600-
"`#[link_ordinal]` is unstable on x86",
601-
)
602-
.emit();
603-
}
604595
let meta_item_list = attr.meta_item_list();
605596
let meta_item_list = meta_item_list.as_deref();
606597
let sole_meta_list = match meta_item_list {

compiler/rustc_feature/src/accepted.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ declare_features! (
280280
(accepted, pub_restricted, "1.18.0", Some(32409), None),
281281
/// Allows use of the postfix `?` operator in expressions.
282282
(accepted, question_mark, "1.13.0", Some(31436), None),
283+
/// Allows the use of raw-dylibs (RFC 2627).
284+
(accepted, raw_dylib, "CURRENT_RUSTC_VERSION", Some(58713), None),
283285
/// Allows keywords to be escaped for use as identifiers.
284286
(accepted, raw_identifiers, "1.30.0", Some(48589), None),
285287
/// Allows relaxing the coherence rules such that

compiler/rustc_feature/src/active.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,6 @@ declare_features! (
483483
(active, precise_pointer_size_matching, "1.32.0", Some(56354), None),
484484
/// Allows macro attributes on expressions, statements and non-inline modules.
485485
(active, proc_macro_hygiene, "1.30.0", Some(54727), None),
486-
/// Allows the use of raw-dylibs (RFC 2627).
487-
(active, raw_dylib, "1.65.0", Some(58713), None),
488486
/// Allows `&raw const $place_expr` and `&raw mut $place_expr` expressions.
489487
(active, raw_ref_op, "1.41.0", Some(64490), None),
490488
/// Allows using the `#[register_tool]` attribute.

compiler/rustc_interface/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ fn test_codegen_options_tracking_hash() {
547547
untracked!(ar, String::from("abc"));
548548
untracked!(codegen_units, Some(42));
549549
untracked!(default_linker_libraries, true);
550+
untracked!(dlltool, Some(PathBuf::from("custom_dlltool.exe")));
550551
untracked!(extra_filename, String::from("extra-filename"));
551552
untracked!(incremental, Some(String::from("abc")));
552553
// `link_arg` is omitted because it just forwards to `link_args`.
@@ -651,7 +652,6 @@ fn test_unstable_options_tracking_hash() {
651652
untracked!(assert_incr_state, Some(String::from("loaded")));
652653
untracked!(deduplicate_diagnostics, false);
653654
untracked!(dep_tasks, true);
654-
untracked!(dlltool, Some(PathBuf::from("custom_dlltool.exe")));
655655
untracked!(dont_buffer_diagnostics, true);
656656
untracked!(dump_dep_graph, true);
657657
untracked!(dump_drop_tracking_cfg, Some("cfg.dot".to_string()));

compiler/rustc_metadata/src/native_libs.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,6 @@ impl<'tcx> Collector<'tcx> {
161161
"raw-dylib" => {
162162
if !sess.target.is_like_windows {
163163
sess.emit_err(errors::FrameworkOnlyWindows { span });
164-
} else if !features.raw_dylib && sess.target.arch == "x86" {
165-
feature_err(
166-
&sess.parse_sess,
167-
sym::raw_dylib,
168-
span,
169-
"link kind `raw-dylib` is unstable on x86",
170-
)
171-
.emit();
172164
}
173165
NativeLibKind::RawDylib
174166
}
@@ -251,16 +243,6 @@ impl<'tcx> Collector<'tcx> {
251243
continue;
252244
}
253245
};
254-
if !features.raw_dylib {
255-
let span = item.name_value_literal_span().unwrap();
256-
feature_err(
257-
&sess.parse_sess,
258-
sym::raw_dylib,
259-
span,
260-
"import name type is unstable",
261-
)
262-
.emit();
263-
}
264246
import_name_type = Some((link_import_name_type, item.span()));
265247
}
266248
_ => {

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,8 @@ options! {
12351235
line-tables-only, limited, or full; default: 0)"),
12361236
default_linker_libraries: bool = (false, parse_bool, [UNTRACKED],
12371237
"allow the linker to link its default libraries (default: no)"),
1238+
dlltool: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
1239+
"import library generation tool (ignored except when targeting windows-gnu)"),
12381240
embed_bitcode: bool = (true, parse_bool, [TRACKED],
12391241
"emit bitcode in rlibs (default: yes)"),
12401242
extra_filename: String = (String::new(), parse_string, [UNTRACKED],
@@ -1391,8 +1393,6 @@ options! {
13911393
(default: no)"),
13921394
diagnostic_width: Option<usize> = (None, parse_opt_number, [UNTRACKED],
13931395
"set the current output width for diagnostic truncation"),
1394-
dlltool: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
1395-
"import library generation tool (windows-gnu only)"),
13961396
dont_buffer_diagnostics: bool = (false, parse_bool, [UNTRACKED],
13971397
"emit diagnostics rather than buffering (breaks NLL error downgrading, sorting) \
13981398
(default: no)"),

src/doc/rustc/src/codegen-options/index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ It takes one of the following values:
9090
For example, for gcc flavor linkers, this issues the `-nodefaultlibs` flag to
9191
the linker.
9292

93+
## dlltool
94+
95+
On `windows-gnu` targets, this flag controls which dlltool `rustc` invokes to
96+
generate import libraries when using the [`raw-dylib` link kind](../../reference/items/external-blocks.md#the-link-attribute).
97+
It takes a path to [the dlltool executable](https://sourceware.org/binutils/docs/binutils/dlltool.html).
98+
If this flag is not specified, a dlltool executable will be inferred based on
99+
the host environment and target.
100+
93101
## embed-bitcode
94102

95103
This flag controls whether or not the compiler embeds LLVM bitcode into object

0 commit comments

Comments
 (0)