Auto merge of #129257 - ChrisDenton:rename-null-descriptor, r= · rust-lang/rust@04f2fce (original) (raw)

File tree

8 files changed

lines changed

8 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -205,9 +205,8 @@ dependencies = [
205 205
206 206 [[package]]
207 207 name = "ar_archive_writer"
208 -version = "0.4.0"
209 -source = "registry+https://github.com/rust-lang/crates.io-index"
210 -checksum = "de11a9d32db3327f981143bdf699ade4d637c6887b13b97e6e91a9154666963c"
208 +version = "0.3.3"
209 +source = "git+https://github.com/ChrisDenton/ar\_archive\_writer.git?branch=rename2#a5b424a6ef9d6416b299ac27c2dba224e2470253"
211 210 dependencies = [
212 211 "object 0.36.2",
213 212 ]
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ edition = "2021"
5 5
6 6 [dependencies]
7 7 # tidy-alphabetical-start
8 -ar_archive_writer = "0.4.0"
8 +ar_archive_writer = { git = 'https://github.com/ChrisDenton/ar\_archive\_writer.git', branch = "rename2" }
9 9 arrayvec = { version = "0.7", default-features = false }
10 10 bitflags = "2.4.1"
11 11 cc = "1.0.90"
@@ -52,7 +52,17 @@ libc = "0.2.50"
52 52 [dependencies.object]
53 53 version = "0.36.2"
54 54 default-features = false
55 -features = ["read_core", "elf", "macho", "pe", "xcoff", "unaligned", "archive", "write", "wasm"]
55 +features = [
56 +"read_core",
57 +"elf",
58 +"macho",
59 +"pe",
60 +"xcoff",
61 +"unaligned",
62 +"archive",
63 +"write",
64 +"wasm",
65 +]
56 66
57 67 [target.'cfg(windows)'.dependencies.windows]
58 68 version = "0.52.0"
Original file line number Diff line number Diff line change
@@ -108,7 +108,11 @@ pub trait ArchiveBuilderBuilder {
108 108 &exports,
109 109 machine,
110 110 !sess.target.is_like_msvc,
111 -/*comdat=*/ false,
111 +// Tell the import library writer to make `.idata$3` a COMDAT section.
112 +// This prevents duplicate symbol errors when using /WHOLEARCHIVE
113 +// to link a staticlib with the MSVC linker.
114 +// See #129020
115 +true,
112 116 ) {
113 117 sess.dcx()
114 118 .emit_fatal(ErrorCreatingImportLibrary { lib_name, error: error.to_string() });
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ const ALLOWED_SOURCES: &[&str] = &[
8 8 r#""registry+https://github.com/rust-lang/crates.io-index""#,
9 9 // This is `rust_team_data` used by `site` in src/tools/rustc-perf,
10 10 r#""git+https://github.com/rust-lang/team#a5260e76d3aa894c64c56e6ddc8545b9a98043ec""#,
11 +r#""git+https://github.com/ChrisDenton/ar\_archive\_writer.git?branch=rename2#a5b424a6ef9d6416b299ac27c2dba224e2470253""#,
11 12 ];
12 13
13 14 /// Checks for external package sources. `root` is the path to the directory that contains the
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 +// This page is intentionally left blank
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1 +LIBRARY dll
2 +EXPORTS
3 + hello
4 + number
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
1 +//@ only-msvc
2 +// Reason: this is testing the MSVC linker
3 +
4 +// This is a regression test for #129020
5 +// It ensures we can link a rust staticlib into DLL using the MSVC linker
6 +
7 +use std::path::Path;
8 +
9 +use run_make_support::{cc, env_var, extra_c_flags, rustc};
10 +
11 +fn main() {
12 +// FIXME: Make this test either work with or ignore LLVM.
13 +if false {
14 +return;
15 +}
16 +// Build the staticlib
17 +rustc().crate_type("staticlib").input("static.rs").output("static.lib").run();
18 +// Create an empty obj file (using the C compiler)
19 +// Then use it to link in the staticlib using `/WHOLEARCHIVE` and produce a DLL.
20 +// We test for `cl.exe` to ensure we're using MSVC's tools and not the LLVM equivalents.
21 +
22 +if env_var("CC").ends_with("cl.exe") {
23 +cc().input("c.c")
24 +.args([
25 +"-MT",
26 +"-link",
27 +"-WHOLEARCHIVE:./static.lib",
28 +"-dll",
29 +"-def:dll.def",
30 +"-out:dll.dll",
31 +])
32 +.args(extra_c_flags())
33 +.run();
34 +}
35 +
36 +// As a sanity check, make sure it works without /WHOLEARCHIVE
37 +cc().input("c.c")
38 +.args(["-MT", "-link", "./static.lib", "-dll", "-def:dll.def", "-out:dll2.dll"])
39 +.args(extra_c_flags())
40 +.run();
41 +}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
1 +#[no_mangle]
2 +pub extern "C" fn hello() {
3 +println!("Hello world!");
4 +}
5 +
6 +#[no_mangle]
7 +pub extern "C" fn number() -> u32 {
8 +42
9 +}