authorbors <bors@rust-lang.org> 2025-03-04 15:39:44 UTC
committerbors <bors@rust-lang.org> 2025-03-04 15:39:44 UTC
logf9e0239a7bc813b4aceffc7f069f4797cde3175c
treef128676be91c2dd790e76ba5570d648917ee56d1
parentfd17deacce374a4185c882795be162e17b557050
parenta954c512809a2d6f3e592c0287dbe41264b54808

Auto merge of #135695 - Noratrieb:elf-raw-dylib, r=bjorn3

Support raw-dylib link kind on ELF raw-dylib is a link kind that allows rustc to link against a library without having any library files present. This currently only exists on Windows. rustc will take all the symbols from raw-dylib link blocks and put them in an import library, where they can then be resolved by the linker. While import libraries don't exist on ELF, it would still be convenient to have this same functionality. Not having the libraries present at build-time can be convenient for several reasons, especially cross-compilation. With raw-dylib, code linking against a library can be cross-compiled without needing to have these libraries available on the build machine. If the libc crate makes use of this, it would allow cross-compilation without having any libc available on the build machine. This is not yet possible with this implementation, at least against libc's like glibc that use symbol versioning. The raw-dylib kind could be extended with support for symbol versioning in the future. This implementation is very experimental and I have not tested it very well. I have tested it for a toy example and the lz4-sys crate, where it was able to successfully link a binary despite not having a corresponding library at build-time. I was inspired by Björn's comments in https://internals.rust-lang.org/t/bundle-zig-cc-in-rustup-by-default/22096/27 Tracking issue: #135694 r? bjorn3 try-job: aarch64-apple try-job: x86_64-msvc-1 try-job: x86_64-msvc-2 try-job: test-various

104 files changed, 1278 insertions(+), 646 deletions(-)

compiler/rustc_codegen_ssa/src/back/link.rs+81-137
......@@ -1,3 +1,5 @@
1mod raw_dylib;
2
13use std::collections::BTreeSet;
24use std::ffi::OsString;
35use std::fs::{File, OpenOptions, read};
......@@ -12,7 +14,7 @@ use itertools::Itertools;
1214use regex::Regex;
1315use rustc_arena::TypedArena;
1416use rustc_ast::CRATE_NODE_ID;
15use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
17use rustc_data_structures::fx::FxIndexSet;
1618use rustc_data_structures::memmap::Mmap;
1719use rustc_data_structures::temp_dir::MaybeTempDir;
1820use rustc_errors::{DiagCtxtHandle, LintDiagnostic};
......@@ -30,7 +32,6 @@ use rustc_session::config::{
3032 self, CFGuard, CrateType, DebugInfo, LinkerFeaturesCli, OutFileName, OutputFilenames,
3133 OutputType, PrintKind, SplitDwarfKind, Strip,
3234};
33use rustc_session::cstore::DllImport;
3435use rustc_session::lint::builtin::LINKER_MESSAGES;
3536use rustc_session::output::{check_file_is_writeable, invalid_output_for_target, out_filename};
3637use rustc_session::search_paths::PathKind;
......@@ -41,22 +42,21 @@ use rustc_session::{Session, filesearch};
4142use rustc_span::Symbol;
4243use rustc_target::spec::crt_objects::CrtObjects;
4344use rustc_target::spec::{
44 Cc, LinkOutputKind, LinkSelfContainedComponents, LinkSelfContainedDefault, LinkerFeatures,
45 LinkerFlavor, LinkerFlavorCli, Lld, PanicStrategy, RelocModel, RelroLevel, SanitizerSet,
46 SplitDebuginfo,
45 BinaryFormat, Cc, LinkOutputKind, LinkSelfContainedComponents, LinkSelfContainedDefault,
46 LinkerFeatures, LinkerFlavor, LinkerFlavorCli, Lld, PanicStrategy, RelocModel, RelroLevel,
47 SanitizerSet, SplitDebuginfo,
4748};
4849use tempfile::Builder as TempFileBuilder;
4950use tracing::{debug, info, warn};
5051
51use super::archive::{ArchiveBuilder, ArchiveBuilderBuilder, ImportLibraryItem};
52use super::archive::{ArchiveBuilder, ArchiveBuilderBuilder};
5253use super::command::Command;
5354use super::linker::{self, Linker};
5455use super::metadata::{MetadataPosition, create_wrapper_file};
5556use super::rpath::{self, RPathConfig};
5657use super::{apple, versioned_llvm_target};
5758use crate::{
58 CodegenResults, CompiledModule, CrateInfo, NativeLib, common, errors,
59 looks_like_rust_object_file,
59 CodegenResults, CompiledModule, CrateInfo, NativeLib, errors, looks_like_rust_object_file,
6060};
6161
6262pub fn ensure_removed(dcx: DiagCtxtHandle<'_>, path: &Path) {
......@@ -376,16 +376,22 @@ fn link_rlib<'a>(
376376 }
377377 }
378378
379 for output_path in create_dll_import_libs(
380 sess,
381 archive_builder_builder,
382 codegen_results.crate_info.used_libraries.iter(),
383 tmpdir.as_ref(),
384 true,
385 ) {
386 ab.add_archive(&output_path, Box::new(|_| false)).unwrap_or_else(|error| {
387 sess.dcx().emit_fatal(errors::AddNativeLibrary { library_path: output_path, error });
388 });
379 // On Windows, we add the raw-dylib import libraries to the rlibs already.
380 // But on ELF, this is not possible, as a shared object cannot be a member of a static library.
381 // Instead, we add all raw-dylibs to the final link on ELF.
382 if sess.target.is_like_windows {
383 for output_path in raw_dylib::create_raw_dylib_dll_import_libs(
384 sess,
385 archive_builder_builder,
386 codegen_results.crate_info.used_libraries.iter(),
387 tmpdir.as_ref(),
388 true,
389 ) {
390 ab.add_archive(&output_path, Box::new(|_| false)).unwrap_or_else(|error| {
391 sess.dcx()
392 .emit_fatal(errors::AddNativeLibrary { library_path: output_path, error });
393 });
394 }
389395 }
390396
391397 if let Some(trailing_metadata) = trailing_metadata {
......@@ -426,108 +432,6 @@ fn link_rlib<'a>(
426432 ab
427433}
428434
429/// Extract all symbols defined in raw-dylib libraries, collated by library name.
430///
431/// If we have multiple extern blocks that specify symbols defined in the same raw-dylib library,
432/// then the CodegenResults value contains one NativeLib instance for each block. However, the
433/// linker appears to expect only a single import library for each library used, so we need to
434/// collate the symbols together by library name before generating the import libraries.
435fn collate_raw_dylibs<'a>(
436 sess: &Session,
437 used_libraries: impl IntoIterator<Item = &'a NativeLib>,
438) -> Vec<(String, Vec<DllImport>)> {
439 // Use index maps to preserve original order of imports and libraries.
440 let mut dylib_table = FxIndexMap::<String, FxIndexMap<Symbol, &DllImport>>::default();
441
442 for lib in used_libraries {
443 if lib.kind == NativeLibKind::RawDylib {
444 let ext = if lib.verbatim { "" } else { ".dll" };
445 let name = format!("{}{}", lib.name, ext);
446 let imports = dylib_table.entry(name.clone()).or_default();
447 for import in &lib.dll_imports {
448 if let Some(old_import) = imports.insert(import.name, import) {
449 // FIXME: when we add support for ordinals, figure out if we need to do anything
450 // if we have two DllImport values with the same name but different ordinals.
451 if import.calling_convention != old_import.calling_convention {
452 sess.dcx().emit_err(errors::MultipleExternalFuncDecl {
453 span: import.span,
454 function: import.name,
455 library_name: &name,
456 });
457 }
458 }
459 }
460 }
461 }
462 sess.dcx().abort_if_errors();
463 dylib_table
464 .into_iter()
465 .map(|(name, imports)| {
466 (name, imports.into_iter().map(|(_, import)| import.clone()).collect())
467 })
468 .collect()
469}
470
471fn create_dll_import_libs<'a>(
472 sess: &Session,
473 archive_builder_builder: &dyn ArchiveBuilderBuilder,
474 used_libraries: impl IntoIterator<Item = &'a NativeLib>,
475 tmpdir: &Path,
476 is_direct_dependency: bool,
477) -> Vec<PathBuf> {
478 collate_raw_dylibs(sess, used_libraries)
479 .into_iter()
480 .map(|(raw_dylib_name, raw_dylib_imports)| {
481 let name_suffix = if is_direct_dependency { "_imports" } else { "_imports_indirect" };
482 let output_path = tmpdir.join(format!("{raw_dylib_name}{name_suffix}.lib"));
483
484 let mingw_gnu_toolchain = common::is_mingw_gnu_toolchain(&sess.target);
485
486 let items: Vec<ImportLibraryItem> = raw_dylib_imports
487 .iter()
488 .map(|import: &DllImport| {
489 if sess.target.arch == "x86" {
490 ImportLibraryItem {
491 name: common::i686_decorated_name(
492 import,
493 mingw_gnu_toolchain,
494 false,
495 false,
496 ),
497 ordinal: import.ordinal(),
498 symbol_name: import.is_missing_decorations().then(|| {
499 common::i686_decorated_name(
500 import,
501 mingw_gnu_toolchain,
502 false,
503 true,
504 )
505 }),
506 is_data: !import.is_fn,
507 }
508 } else {
509 ImportLibraryItem {
510 name: import.name.to_string(),
511 ordinal: import.ordinal(),
512 symbol_name: None,
513 is_data: !import.is_fn,
514 }
515 }
516 })
517 .collect();
518
519 archive_builder_builder.create_dll_import_lib(
520 sess,
521 &raw_dylib_name,
522 items,
523 &output_path,
524 );
525
526 output_path
527 })
528 .collect()
529}
530
531435/// Create a static archive.
532436///
533437/// This is essentially the same thing as an rlib, but it also involves adding all of the upstream
......@@ -2422,15 +2326,39 @@ fn linker_with_args(
24222326 link_output_kind,
24232327 );
24242328
2329 // Raw-dylibs from all crates.
2330 let raw_dylib_dir = tmpdir.join("raw-dylibs");
2331 if sess.target.binary_format == BinaryFormat::Elf {
2332 // On ELF we can't pass the raw-dylibs stubs to the linker as a path,
2333 // instead we need to pass them via -l. To find the stub, we need to add
2334 // the directory of the stub to the linker search path.
2335 // We make an extra directory for this to avoid polluting the search path.
2336 if let Err(error) = fs::create_dir(&raw_dylib_dir) {
2337 sess.dcx().emit_fatal(errors::CreateTempDir { error })
2338 }
2339 cmd.include_path(&raw_dylib_dir);
2340 }
2341
24252342 // Link with the import library generated for any raw-dylib functions.
2426 for output_path in create_dll_import_libs(
2427 sess,
2428 archive_builder_builder,
2429 codegen_results.crate_info.used_libraries.iter(),
2430 tmpdir,
2431 true,
2432 ) {
2433 cmd.add_object(&output_path);
2343 if sess.target.is_like_windows {
2344 for output_path in raw_dylib::create_raw_dylib_dll_import_libs(
2345 sess,
2346 archive_builder_builder,
2347 codegen_results.crate_info.used_libraries.iter(),
2348 tmpdir,
2349 true,
2350 ) {
2351 cmd.add_object(&output_path);
2352 }
2353 } else {
2354 for link_path in raw_dylib::create_raw_dylib_elf_stub_shared_objects(
2355 sess,
2356 codegen_results.crate_info.used_libraries.iter(),
2357 &raw_dylib_dir,
2358 ) {
2359 // Always use verbatim linkage, see comments in create_raw_dylib_elf_stub_shared_objects.
2360 cmd.link_dylib_by_name(&link_path, true, false);
2361 }
24342362 }
24352363 // As with add_upstream_native_libraries, we need to add the upstream raw-dylib symbols in case
24362364 // they are used within inlined functions or instantiated generic functions. We do this *after*
......@@ -2449,19 +2377,35 @@ fn linker_with_args(
24492377 .native_libraries
24502378 .iter()
24512379 .filter_map(|(&cnum, libraries)| {
2452 (dependency_linkage[cnum] != Linkage::Static).then_some(libraries)
2380 if sess.target.is_like_windows {
2381 (dependency_linkage[cnum] != Linkage::Static).then_some(libraries)
2382 } else {
2383 Some(libraries)
2384 }
24532385 })
24542386 .flatten()
24552387 .collect::<Vec<_>>();
24562388 native_libraries_from_nonstatics.sort_unstable_by(|a, b| a.name.as_str().cmp(b.name.as_str()));
2457 for output_path in create_dll_import_libs(
2458 sess,
2459 archive_builder_builder,
2460 native_libraries_from_nonstatics,
2461 tmpdir,
2462 false,
2463 ) {
2464 cmd.add_object(&output_path);
2389
2390 if sess.target.is_like_windows {
2391 for output_path in raw_dylib::create_raw_dylib_dll_import_libs(
2392 sess,
2393 archive_builder_builder,
2394 native_libraries_from_nonstatics,
2395 tmpdir,
2396 false,
2397 ) {
2398 cmd.add_object(&output_path);
2399 }
2400 } else {
2401 for link_path in raw_dylib::create_raw_dylib_elf_stub_shared_objects(
2402 sess,
2403 native_libraries_from_nonstatics,
2404 &raw_dylib_dir,
2405 ) {
2406 // Always use verbatim linkage, see comments in create_raw_dylib_elf_stub_shared_objects.
2407 cmd.link_dylib_by_name(&link_path, true, false);
2408 }
24652409 }
24662410
24672411 // Library linking above uses some global state for things like `-Bstatic`/`-Bdynamic` to make
compiler/rustc_codegen_ssa/src/back/link/raw_dylib.rs created+373
......@@ -0,0 +1,373 @@
1use std::fs;
2use std::io::{BufWriter, Write};
3use std::path::{Path, PathBuf};
4
5use rustc_abi::Endian;
6use rustc_data_structures::base_n::{CASE_INSENSITIVE, ToBaseN};
7use rustc_data_structures::fx::FxIndexMap;
8use rustc_data_structures::stable_hasher::StableHasher;
9use rustc_hashes::Hash128;
10use rustc_session::Session;
11use rustc_session::cstore::DllImport;
12use rustc_session::utils::NativeLibKind;
13use rustc_span::Symbol;
14
15use crate::back::archive::ImportLibraryItem;
16use crate::back::link::ArchiveBuilderBuilder;
17use crate::errors::ErrorCreatingImportLibrary;
18use crate::{NativeLib, common, errors};
19
20/// Extract all symbols defined in raw-dylib libraries, collated by library name.
21///
22/// If we have multiple extern blocks that specify symbols defined in the same raw-dylib library,
23/// then the CodegenResults value contains one NativeLib instance for each block. However, the
24/// linker appears to expect only a single import library for each library used, so we need to
25/// collate the symbols together by library name before generating the import libraries.
26fn collate_raw_dylibs_windows<'a>(
27 sess: &Session,
28 used_libraries: impl IntoIterator<Item = &'a NativeLib>,
29) -> Vec<(String, Vec<DllImport>)> {
30 // Use index maps to preserve original order of imports and libraries.
31 let mut dylib_table = FxIndexMap::<String, FxIndexMap<Symbol, &DllImport>>::default();
32
33 for lib in used_libraries {
34 if lib.kind == NativeLibKind::RawDylib {
35 let ext = if lib.verbatim { "" } else { ".dll" };
36 let name = format!("{}{}", lib.name, ext);
37 let imports = dylib_table.entry(name.clone()).or_default();
38 for import in &lib.dll_imports {
39 if let Some(old_import) = imports.insert(import.name, import) {
40 // FIXME: when we add support for ordinals, figure out if we need to do anything
41 // if we have two DllImport values with the same name but different ordinals.
42 if import.calling_convention != old_import.calling_convention {
43 sess.dcx().emit_err(errors::MultipleExternalFuncDecl {
44 span: import.span,
45 function: import.name,
46 library_name: &name,
47 });
48 }
49 }
50 }
51 }
52 }
53 sess.dcx().abort_if_errors();
54 dylib_table
55 .into_iter()
56 .map(|(name, imports)| {
57 (name, imports.into_iter().map(|(_, import)| import.clone()).collect())
58 })
59 .collect()
60}
61
62pub(super) fn create_raw_dylib_dll_import_libs<'a>(
63 sess: &Session,
64 archive_builder_builder: &dyn ArchiveBuilderBuilder,
65 used_libraries: impl IntoIterator<Item = &'a NativeLib>,
66 tmpdir: &Path,
67 is_direct_dependency: bool,
68) -> Vec<PathBuf> {
69 collate_raw_dylibs_windows(sess, used_libraries)
70 .into_iter()
71 .map(|(raw_dylib_name, raw_dylib_imports)| {
72 let name_suffix = if is_direct_dependency { "_imports" } else { "_imports_indirect" };
73 let output_path = tmpdir.join(format!("{raw_dylib_name}{name_suffix}.lib"));
74
75 let mingw_gnu_toolchain = common::is_mingw_gnu_toolchain(&sess.target);
76
77 let items: Vec<ImportLibraryItem> = raw_dylib_imports
78 .iter()
79 .map(|import: &DllImport| {
80 if sess.target.arch == "x86" {
81 ImportLibraryItem {
82 name: common::i686_decorated_name(
83 import,
84 mingw_gnu_toolchain,
85 false,
86 false,
87 ),
88 ordinal: import.ordinal(),
89 symbol_name: import.is_missing_decorations().then(|| {
90 common::i686_decorated_name(
91 import,
92 mingw_gnu_toolchain,
93 false,
94 true,
95 )
96 }),
97 is_data: !import.is_fn,
98 }
99 } else {
100 ImportLibraryItem {
101 name: import.name.to_string(),
102 ordinal: import.ordinal(),
103 symbol_name: None,
104 is_data: !import.is_fn,
105 }
106 }
107 })
108 .collect();
109
110 archive_builder_builder.create_dll_import_lib(
111 sess,
112 &raw_dylib_name,
113 items,
114 &output_path,
115 );
116
117 output_path
118 })
119 .collect()
120}
121
122/// Extract all symbols defined in raw-dylib libraries, collated by library name.
123///
124/// If we have multiple extern blocks that specify symbols defined in the same raw-dylib library,
125/// then the CodegenResults value contains one NativeLib instance for each block. However, the
126/// linker appears to expect only a single import library for each library used, so we need to
127/// collate the symbols together by library name before generating the import libraries.
128fn collate_raw_dylibs_elf<'a>(
129 sess: &Session,
130 used_libraries: impl IntoIterator<Item = &'a NativeLib>,
131) -> Vec<(String, Vec<DllImport>)> {
132 // Use index maps to preserve original order of imports and libraries.
133 let mut dylib_table = FxIndexMap::<String, FxIndexMap<Symbol, &DllImport>>::default();
134
135 for lib in used_libraries {
136 if lib.kind == NativeLibKind::RawDylib {
137 let filename = if lib.verbatim {
138 lib.name.as_str().to_owned()
139 } else {
140 let ext = sess.target.dll_suffix.as_ref();
141 let prefix = sess.target.dll_prefix.as_ref();
142 format!("{prefix}{}{ext}", lib.name)
143 };
144
145 let imports = dylib_table.entry(filename.clone()).or_default();
146 for import in &lib.dll_imports {
147 imports.insert(import.name, import);
148 }
149 }
150 }
151 sess.dcx().abort_if_errors();
152 dylib_table
153 .into_iter()
154 .map(|(name, imports)| {
155 (name, imports.into_iter().map(|(_, import)| import.clone()).collect())
156 })
157 .collect()
158}
159
160pub(super) fn create_raw_dylib_elf_stub_shared_objects<'a>(
161 sess: &Session,
162 used_libraries: impl IntoIterator<Item = &'a NativeLib>,
163 raw_dylib_so_dir: &Path,
164) -> Vec<String> {
165 collate_raw_dylibs_elf(sess, used_libraries)
166 .into_iter()
167 .map(|(load_filename, raw_dylib_imports)| {
168 use std::hash::Hash;
169
170 // `load_filename` is the *target/loader* filename that will end up in NEEDED.
171 // Usually this will be something like `libc.so` or `libc.so.6` but with
172 // verbatim it might also be an absolute path.
173 // To be able to support this properly, we always put this load filename
174 // into the SONAME of the library and link it via a temporary file with a random name.
175 // This also avoids naming conflicts with non-raw-dylib linkage of the same library.
176
177 let shared_object = create_elf_raw_dylib_stub(sess, &load_filename, &raw_dylib_imports);
178
179 let mut file_name_hasher = StableHasher::new();
180 load_filename.hash(&mut file_name_hasher);
181 for raw_dylib in raw_dylib_imports {
182 raw_dylib.name.as_str().hash(&mut file_name_hasher);
183 }
184
185 let library_filename: Hash128 = file_name_hasher.finish();
186 let temporary_lib_name = format!(
187 "{}{}{}",
188 sess.target.dll_prefix,
189 library_filename.as_u128().to_base_fixed_len(CASE_INSENSITIVE),
190 sess.target.dll_suffix
191 );
192 let link_path = raw_dylib_so_dir.join(&temporary_lib_name);
193
194 let file = match fs::File::create_new(&link_path) {
195 Ok(file) => file,
196 Err(error) => sess.dcx().emit_fatal(ErrorCreatingImportLibrary {
197 lib_name: &load_filename,
198 error: error.to_string(),
199 }),
200 };
201 if let Err(error) = BufWriter::new(file).write_all(&shared_object) {
202 sess.dcx().emit_fatal(ErrorCreatingImportLibrary {
203 lib_name: &load_filename,
204 error: error.to_string(),
205 });
206 };
207
208 temporary_lib_name
209 })
210 .collect()
211}
212
213/// Create an ELF .so stub file for raw-dylib.
214/// It exports all the provided symbols, but is otherwise empty.
215fn create_elf_raw_dylib_stub(sess: &Session, soname: &str, symbols: &[DllImport]) -> Vec<u8> {
216 use object::write::elf as write;
217 use object::{Architecture, elf};
218
219 let mut stub_buf = Vec::new();
220
221 // Build the stub ELF using the object crate.
222 // The high-level portable API does not allow for the fine-grained control we need,
223 // so this uses the low-level object::write::elf API.
224 // The low-level API consists of two stages: reservation and writing.
225 // We first reserve space for all the things in the binary and then write them.
226 // It is important that the order of reservation matches the order of writing.
227 // The object crate contains many debug asserts that fire if you get this wrong.
228
229 let endianness = match sess.target.options.endian {
230 Endian::Little => object::Endianness::Little,
231 Endian::Big => object::Endianness::Big,
232 };
233 let mut stub = write::Writer::new(endianness, true, &mut stub_buf);
234
235 // These initial reservations don't reserve any bytes in the binary yet,
236 // they just allocate in the internal data structures.
237
238 // First, we crate the dynamic symbol table. It starts with a null symbol
239 // and then all the symbols and their dynamic strings.
240 stub.reserve_null_dynamic_symbol_index();
241
242 let dynstrs = symbols
243 .iter()
244 .map(|sym| {
245 stub.reserve_dynamic_symbol_index();
246 (sym, stub.add_dynamic_string(sym.name.as_str().as_bytes()))
247 })
248 .collect::<Vec<_>>();
249
250 let soname = stub.add_dynamic_string(soname.as_bytes());
251
252 // Reserve the sections.
253 // We have the minimal sections for a dynamic SO and .text where we point our dummy symbols to.
254 stub.reserve_shstrtab_section_index();
255 let text_section_name = stub.add_section_name(".text".as_bytes());
256 let text_section = stub.reserve_section_index();
257 stub.reserve_dynstr_section_index();
258 stub.reserve_dynsym_section_index();
259 stub.reserve_dynamic_section_index();
260
261 // These reservations now determine the actual layout order of the object file.
262 stub.reserve_file_header();
263 stub.reserve_shstrtab();
264 stub.reserve_section_headers();
265 stub.reserve_dynstr();
266 stub.reserve_dynsym();
267 stub.reserve_dynamic(2); // DT_SONAME, DT_NULL
268
269 // First write the ELF header with the arch information.
270 let Some((arch, sub_arch)) = sess.target.object_architecture(&sess.unstable_target_features)
271 else {
272 sess.dcx().fatal(format!(
273 "raw-dylib is not supported for the architecture `{}`",
274 sess.target.arch
275 ));
276 };
277 let e_machine = match (arch, sub_arch) {
278 (Architecture::Aarch64, None) => elf::EM_AARCH64,
279 (Architecture::Aarch64_Ilp32, None) => elf::EM_AARCH64,
280 (Architecture::Arm, None) => elf::EM_ARM,
281 (Architecture::Avr, None) => elf::EM_AVR,
282 (Architecture::Bpf, None) => elf::EM_BPF,
283 (Architecture::Csky, None) => elf::EM_CSKY,
284 (Architecture::E2K32, None) => elf::EM_MCST_ELBRUS,
285 (Architecture::E2K64, None) => elf::EM_MCST_ELBRUS,
286 (Architecture::I386, None) => elf::EM_386,
287 (Architecture::X86_64, None) => elf::EM_X86_64,
288 (Architecture::X86_64_X32, None) => elf::EM_X86_64,
289 (Architecture::Hexagon, None) => elf::EM_HEXAGON,
290 (Architecture::LoongArch64, None) => elf::EM_LOONGARCH,
291 (Architecture::M68k, None) => elf::EM_68K,
292 (Architecture::Mips, None) => elf::EM_MIPS,
293 (Architecture::Mips64, None) => elf::EM_MIPS,
294 (Architecture::Mips64_N32, None) => elf::EM_MIPS,
295 (Architecture::Msp430, None) => elf::EM_MSP430,
296 (Architecture::PowerPc, None) => elf::EM_PPC,
297 (Architecture::PowerPc64, None) => elf::EM_PPC64,
298 (Architecture::Riscv32, None) => elf::EM_RISCV,
299 (Architecture::Riscv64, None) => elf::EM_RISCV,
300 (Architecture::S390x, None) => elf::EM_S390,
301 (Architecture::Sbf, None) => elf::EM_SBF,
302 (Architecture::Sharc, None) => elf::EM_SHARC,
303 (Architecture::Sparc, None) => elf::EM_SPARC,
304 (Architecture::Sparc32Plus, None) => elf::EM_SPARC32PLUS,
305 (Architecture::Sparc64, None) => elf::EM_SPARCV9,
306 (Architecture::Xtensa, None) => elf::EM_XTENSA,
307 _ => {
308 sess.dcx().fatal(format!(
309 "raw-dylib is not supported for the architecture `{}`",
310 sess.target.arch
311 ));
312 }
313 };
314
315 stub.write_file_header(&write::FileHeader {
316 os_abi: crate::back::metadata::elf_os_abi(sess),
317 abi_version: 0,
318 e_type: object::elf::ET_DYN,
319 e_machine,
320 e_entry: 0,
321 e_flags: crate::back::metadata::elf_e_flags(arch, sess),
322 })
323 .unwrap();
324
325 // .shstrtab
326 stub.write_shstrtab();
327
328 // Section headers
329 stub.write_null_section_header();
330 stub.write_shstrtab_section_header();
331 // Create a dummy .text section for our dummy symbols.
332 stub.write_section_header(&write::SectionHeader {
333 name: Some(text_section_name),
334 sh_type: elf::SHT_PROGBITS,
335 sh_flags: 0,
336 sh_addr: 0,
337 sh_offset: 0,
338 sh_size: 0,
339 sh_link: 0,
340 sh_info: 0,
341 sh_addralign: 1,
342 sh_entsize: 0,
343 });
344 stub.write_dynstr_section_header(0);
345 stub.write_dynsym_section_header(0, 1);
346 stub.write_dynamic_section_header(0);
347
348 // .dynstr
349 stub.write_dynstr();
350
351 // .dynsym
352 stub.write_null_dynamic_symbol();
353 for (_, name) in dynstrs {
354 stub.write_dynamic_symbol(&write::Sym {
355 name: Some(name),
356 st_info: (elf::STB_GLOBAL << 4) | elf::STT_NOTYPE,
357 st_other: elf::STV_DEFAULT,
358 section: Some(text_section),
359 st_shndx: 0, // ignored by object in favor of the `section` field
360 st_value: 0,
361 st_size: 0,
362 });
363 }
364
365 // .dynamic
366 // the DT_SONAME will be used by the linker to populate DT_NEEDED
367 // which the loader uses to find the library.
368 // DT_NULL terminates the .dynamic table.
369 stub.write_dynamic_string(elf::DT_SONAME, soname);
370 stub.write_dynamic(elf::DT_NULL, 0);
371
372 stub_buf
373}
compiler/rustc_codegen_ssa/src/back/metadata.rs+26-60
......@@ -9,8 +9,7 @@ use itertools::Itertools;
99use object::write::{self, StandardSegment, Symbol, SymbolSection};
1010use object::{
1111 Architecture, BinaryFormat, Endianness, FileFlags, Object, ObjectSection, ObjectSymbol,
12 SectionFlags, SectionKind, SubArchitecture, SymbolFlags, SymbolKind, SymbolScope, elf, pe,
13 xcoff,
12 SectionFlags, SectionKind, SymbolFlags, SymbolKind, SymbolScope, elf, pe, xcoff,
1413};
1514use rustc_abi::Endian;
1615use rustc_data_structures::memmap::Mmap;
......@@ -206,51 +205,10 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
206205 Endian::Little => Endianness::Little,
207206 Endian::Big => Endianness::Big,
208207 };
209 let (architecture, sub_architecture) = match &sess.target.arch[..] {
210 "arm" => (Architecture::Arm, None),
211 "aarch64" => (
212 if sess.target.pointer_width == 32 {
213 Architecture::Aarch64_Ilp32
214 } else {
215 Architecture::Aarch64
216 },
217 None,
218 ),
219 "x86" => (Architecture::I386, None),
220 "s390x" => (Architecture::S390x, None),
221 "mips" | "mips32r6" => (Architecture::Mips, None),
222 "mips64" | "mips64r6" => (Architecture::Mips64, None),
223 "x86_64" => (
224 if sess.target.pointer_width == 32 {
225 Architecture::X86_64_X32
226 } else {
227 Architecture::X86_64
228 },
229 None,
230 ),
231 "powerpc" => (Architecture::PowerPc, None),
232 "powerpc64" => (Architecture::PowerPc64, None),
233 "riscv32" => (Architecture::Riscv32, None),
234 "riscv64" => (Architecture::Riscv64, None),
235 "sparc" => {
236 if sess.unstable_target_features.contains(&sym::v8plus) {
237 // Target uses V8+, aka EM_SPARC32PLUS, aka 64-bit V9 but in 32-bit mode
238 (Architecture::Sparc32Plus, None)
239 } else {
240 // Target uses V7 or V8, aka EM_SPARC
241 (Architecture::Sparc, None)
242 }
243 }
244 "sparc64" => (Architecture::Sparc64, None),
245 "avr" => (Architecture::Avr, None),
246 "msp430" => (Architecture::Msp430, None),
247 "hexagon" => (Architecture::Hexagon, None),
248 "bpf" => (Architecture::Bpf, None),
249 "loongarch64" => (Architecture::LoongArch64, None),
250 "csky" => (Architecture::Csky, None),
251 "arm64ec" => (Architecture::Aarch64, Some(SubArchitecture::Arm64EC)),
252 // Unsupported architecture.
253 _ => return None,
208 let Some((architecture, sub_architecture)) =
209 sess.target.object_architecture(&sess.unstable_target_features)
210 else {
211 return None;
254212 };
255213 let binary_format = sess.target.binary_format.to_object();
256214
......@@ -292,7 +250,26 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
292250
293251 file.set_mangling(original_mangling);
294252 }
295 let e_flags = match architecture {
253 let e_flags = elf_e_flags(architecture, sess);
254 // adapted from LLVM's `MCELFObjectTargetWriter::getOSABI`
255 let os_abi = elf_os_abi(sess);
256 let abi_version = 0;
257 add_gnu_property_note(&mut file, architecture, binary_format, endianness);
258 file.flags = FileFlags::Elf { os_abi, abi_version, e_flags };
259 Some(file)
260}
261
262pub(super) fn elf_os_abi(sess: &Session) -> u8 {
263 match sess.target.options.os.as_ref() {
264 "hermit" => elf::ELFOSABI_STANDALONE,
265 "freebsd" => elf::ELFOSABI_FREEBSD,
266 "solaris" => elf::ELFOSABI_SOLARIS,
267 _ => elf::ELFOSABI_NONE,
268 }
269}
270
271pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
272 match architecture {
296273 Architecture::Mips => {
297274 let arch = match sess.target.options.cpu.as_ref() {
298275 "mips1" => elf::EF_MIPS_ARCH_1,
......@@ -387,18 +364,7 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
387364 e_flags
388365 }
389366 _ => 0,
390 };
391 // adapted from LLVM's `MCELFObjectTargetWriter::getOSABI`
392 let os_abi = match sess.target.options.os.as_ref() {
393 "hermit" => elf::ELFOSABI_STANDALONE,
394 "freebsd" => elf::ELFOSABI_FREEBSD,
395 "solaris" => elf::ELFOSABI_SOLARIS,
396 _ => elf::ELFOSABI_NONE,
397 };
398 let abi_version = 0;
399 add_gnu_property_note(&mut file, architecture, binary_format, endianness);
400 file.flags = FileFlags::Elf { os_abi, abi_version, e_flags };
401 Some(file)
367 }
402368}
403369
404370/// Mach-O files contain information about:
compiler/rustc_feature/src/unstable.rs+2
......@@ -601,6 +601,8 @@ declare_features! (
601601 (unstable, precise_capturing_in_traits, "1.83.0", Some(130044)),
602602 /// Allows macro attributes on expressions, statements and non-inline modules.
603603 (unstable, proc_macro_hygiene, "1.30.0", Some(54727)),
604 /// Allows the use of raw-dylibs on ELF platforms
605 (incomplete, raw_dylib_elf, "CURRENT_RUSTC_VERSION", Some(135694)),
604606 /// Makes `&` and `&mut` patterns eat only one layer of references in Rust 2024.
605607 (incomplete, ref_pat_eat_one_layer_2024, "1.79.0", Some(123076)),
606608 /// Makes `&` and `&mut` patterns eat only one layer of references in Rust 2024—structural variant
compiler/rustc_metadata/messages.ftl+3
......@@ -244,6 +244,9 @@ metadata_prev_alloc_error_handler =
244244metadata_prev_global_alloc =
245245 previous global allocator defined here
246246
247metadata_raw_dylib_elf_unstable =
248 link kind `raw-dylib` is unstable on ELF platforms
249
247250metadata_raw_dylib_no_nul =
248251 link name must not contain NUL characters if link kind is `raw-dylib`
249252
compiler/rustc_metadata/src/native_libs.rs+19-2
......@@ -17,7 +17,7 @@ use rustc_session::search_paths::PathKind;
1717use rustc_session::utils::NativeLibKind;
1818use rustc_span::def_id::{DefId, LOCAL_CRATE};
1919use rustc_span::{Symbol, sym};
20use rustc_target::spec::LinkSelfContainedComponents;
20use rustc_target::spec::{BinaryFormat, LinkSelfContainedComponents};
2121
2222use crate::{errors, fluent_generated};
2323
......@@ -263,9 +263,26 @@ impl<'tcx> Collector<'tcx> {
263263 NativeLibKind::Framework { as_needed: None }
264264 }
265265 "raw-dylib" => {
266 if !sess.target.is_like_windows {
266 if sess.target.is_like_windows {
267 // raw-dylib is stable and working on Windows
268 } else if sess.target.binary_format == BinaryFormat::Elf
269 && features.raw_dylib_elf()
270 {
271 // raw-dylib is unstable on ELF, but the user opted in
272 } else if sess.target.binary_format == BinaryFormat::Elf
273 && sess.is_nightly_build()
274 {
275 feature_err(
276 sess,
277 sym::raw_dylib_elf,
278 span,
279 fluent_generated::metadata_raw_dylib_elf_unstable,
280 )
281 .emit();
282 } else {
267283 sess.dcx().emit_err(errors::RawDylibOnlyWindows { span });
268284 }
285
269286 NativeLibKind::RawDylib
270287 }
271288 "link-arg" => {
compiler/rustc_session/src/utils.rs+1
......@@ -34,6 +34,7 @@ pub enum NativeLibKind {
3434 as_needed: Option<bool>,
3535 },
3636 /// Dynamic library (e.g. `foo.dll` on Windows) without a corresponding import library.
37 /// On Linux, it refers to a generated shared library stub.
3738 RawDylib,
3839 /// A macOS-specific kind of dynamic libraries.
3940 Framework {
compiler/rustc_span/src/symbol.rs+1
......@@ -1625,6 +1625,7 @@ symbols! {
16251625 quote,
16261626 range_inclusive_new,
16271627 raw_dylib,
1628 raw_dylib_elf,
16281629 raw_eq,
16291630 raw_identifiers,
16301631 raw_ref_op,
compiler/rustc_target/src/spec/mod.rs+54-1
......@@ -43,7 +43,7 @@ use std::str::FromStr;
4343use std::{fmt, io};
4444
4545use rustc_abi::{Endian, ExternAbi, Integer, Size, TargetDataLayout, TargetDataLayoutErrors};
46use rustc_data_structures::fx::FxHashSet;
46use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
4747use rustc_fs_util::try_canonicalize;
4848use rustc_macros::{Decodable, Encodable, HashStable_Generic};
4949use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
......@@ -3535,6 +3535,59 @@ impl Target {
35353535 s => s.clone(),
35363536 }
35373537 }
3538
3539 pub fn object_architecture(
3540 &self,
3541 unstable_target_features: &FxIndexSet<Symbol>,
3542 ) -> Option<(object::Architecture, Option<object::SubArchitecture>)> {
3543 use object::Architecture;
3544 Some(match self.arch.as_ref() {
3545 "arm" => (Architecture::Arm, None),
3546 "aarch64" => (
3547 if self.pointer_width == 32 {
3548 Architecture::Aarch64_Ilp32
3549 } else {
3550 Architecture::Aarch64
3551 },
3552 None,
3553 ),
3554 "x86" => (Architecture::I386, None),
3555 "s390x" => (Architecture::S390x, None),
3556 "mips" | "mips32r6" => (Architecture::Mips, None),
3557 "mips64" | "mips64r6" => (Architecture::Mips64, None),
3558 "x86_64" => (
3559 if self.pointer_width == 32 {
3560 Architecture::X86_64_X32
3561 } else {
3562 Architecture::X86_64
3563 },
3564 None,
3565 ),
3566 "powerpc" => (Architecture::PowerPc, None),
3567 "powerpc64" => (Architecture::PowerPc64, None),
3568 "riscv32" => (Architecture::Riscv32, None),
3569 "riscv64" => (Architecture::Riscv64, None),
3570 "sparc" => {
3571 if unstable_target_features.contains(&sym::v8plus) {
3572 // Target uses V8+, aka EM_SPARC32PLUS, aka 64-bit V9 but in 32-bit mode
3573 (Architecture::Sparc32Plus, None)
3574 } else {
3575 // Target uses V7 or V8, aka EM_SPARC
3576 (Architecture::Sparc, None)
3577 }
3578 }
3579 "sparc64" => (Architecture::Sparc64, None),
3580 "avr" => (Architecture::Avr, None),
3581 "msp430" => (Architecture::Msp430, None),
3582 "hexagon" => (Architecture::Hexagon, None),
3583 "bpf" => (Architecture::Bpf, None),
3584 "loongarch64" => (Architecture::LoongArch64, None),
3585 "csky" => (Architecture::Csky, None),
3586 "arm64ec" => (Architecture::Aarch64, Some(object::SubArchitecture::Arm64EC)),
3587 // Unsupported architecture.
3588 _ => return None,
3589 })
3590 }
35383591}
35393592
35403593/// Either a target tuple string or a path to a JSON file.
src/doc/rustc-dev-guide/src/tests/directives.md+1
......@@ -142,6 +142,7 @@ Some examples of `X` in `ignore-X` or `only-X`:
142142 matches that target as well as the emscripten targets.
143143- Pointer width: `32bit`, `64bit`
144144- Endianness: `endian-big`
145- Binary format: `elf`
145146- Stage: `stage0`, `stage1`, `stage2`
146147- Channel: `stable`, `beta`
147148- When cross compiling: `cross-compile`
src/tools/compiletest/src/directive-list.rs+2
......@@ -52,6 +52,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
5252 "ignore-coverage-run",
5353 "ignore-cross-compile",
5454 "ignore-eabi",
55 "ignore-elf",
5556 "ignore-emscripten",
5657 "ignore-endian-big",
5758 "ignore-enzyme",
......@@ -182,6 +183,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
182183 "only-bpf",
183184 "only-cdb",
184185 "only-dist",
186 "only-elf",
185187 "only-emscripten",
186188 "only-gnu",
187189 "only-i686-pc-windows-gnu",
src/tools/compiletest/src/header/cfg.rs+10
......@@ -166,6 +166,16 @@ fn parse_cfg_name_directive<'a>(
166166 message: "when the target vendor is Apple"
167167 }
168168
169 condition! {
170 name: "elf",
171 condition: !config.target.contains("windows")
172 && !config.target.contains("wasm")
173 && !config.target.contains("apple")
174 && !config.target.contains("aix")
175 && !config.target.contains("uefi"),
176 message: "when the target binary format is ELF"
177 }
178
169179 condition! {
170180 name: "enzyme",
171181 condition: config.has_enzyme,
tests/run-make/linker-warning/rmake.rs+2
......@@ -60,6 +60,8 @@ fn main() {
6060 regex::escape(run_make_support::build_root().to_str().unwrap()),
6161 "/build-root",
6262 )
63 .normalize(r#""[^"]*\/symbols.o""#, "\"/symbols.o\"")
64 .normalize(r#""[^"]*\/raw-dylibs""#, "\"/raw-dylibs\"")
6365 .run();
6466 }
6567
tests/run-make/linker-warning/short-error.txt+1-1
......@@ -1,6 +1,6 @@
11error: linking with `./fake-linker` failed: exit status: 1
22 |
3 = note: "./fake-linker" "-m64" "/tmp/rustc/symbols.o" "<2 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,libcfg_if-*,liblibc-*,liballoc-*,librustc_std_workspace_core-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/build-root/test/run-make/linker-warning/rmake_out" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "main" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs" "run_make_error"
3 = note: "./fake-linker" "-m64" "/symbols.o" "<2 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,libcfg_if-*,liblibc-*,liballoc-*,librustc_std_workspace_core-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/raw-dylibs" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/build-root/test/run-make/linker-warning/rmake_out" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "main" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs" "run_make_error"
44 = note: some arguments are omitted. use `--verbose` to show all linker arguments
55 = note: error: baz
66
tests/run-make/raw-dylib-elf-verbatim-absolute/main.rs created+11
......@@ -0,0 +1,11 @@
1#![feature(raw_dylib_elf)]
2#![allow(incomplete_features)]
3
4#[link(name = "/absolute-path/liblibrary.so.1", kind = "raw-dylib", modifiers = "+verbatim")]
5unsafe extern "C" {
6 safe fn this_is_a_library_function() -> core::ffi::c_int;
7}
8
9fn main() {
10 println!("{}", this_is_a_library_function())
11}
tests/run-make/raw-dylib-elf-verbatim-absolute/output.txt created+1
......@@ -0,0 +1 @@
142
tests/run-make/raw-dylib-elf-verbatim-absolute/rmake.rs created+20
......@@ -0,0 +1,20 @@
1//@ only-elf
2//@ ignore-cross-compile: Runs a binary.
3//@ needs-dynamic-linking
4// FIXME(raw_dylib_elf): Debug the failures on other targets.
5//@ only-gnu
6//@ only-x86_64
7
8//! Ensure ELF raw-dylib is able to link against a non-existent verbatim absolute path
9//! by embedding the absolute path in the DT_SONAME and passing a different path for
10//! the linker for the stub.
11
12use run_make_support::{build_native_dynamic_lib, cwd, diff, rfs, run, rustc};
13
14fn main() {
15 // We compile the binary without having the library present.
16 // The verbatim library name is an absolute path.
17 rustc().crate_type("bin").input("main.rs").run();
18
19 // FIXME(raw_dylib_elf): Read the NEEDED of the library to ensure it's the absolute path.
20}
tests/run-make/raw-dylib-elf-verbatim/library.c created+3
......@@ -0,0 +1,3 @@
1int this_is_a_library_function() {
2 return 42;
3}
tests/run-make/raw-dylib-elf-verbatim/main.rs created+11
......@@ -0,0 +1,11 @@
1#![feature(raw_dylib_elf)]
2#![allow(incomplete_features)]
3
4#[link(name = "liblibrary.so.1", kind = "raw-dylib", modifiers = "+verbatim")]
5unsafe extern "C" {
6 safe fn this_is_a_library_function() -> core::ffi::c_int;
7}
8
9fn main() {
10 println!("{}", this_is_a_library_function())
11}
tests/run-make/raw-dylib-elf-verbatim/output.txt created+1
......@@ -0,0 +1 @@
142
tests/run-make/raw-dylib-elf-verbatim/rmake.rs created+31
......@@ -0,0 +1,31 @@
1//@ only-elf
2//@ ignore-cross-compile: Runs a binary.
3//@ needs-dynamic-linking
4// FIXME(raw_dylib_elf): Debug the failures on other targets.
5//@ only-gnu
6//@ only-x86_64
7
8//! Ensure ELF raw-dylib is able to link against the verbatim versioned library
9//! without it being present, and then be executed against this library.
10
11use run_make_support::{build_native_dynamic_lib, cwd, diff, rfs, run, rustc};
12
13fn main() {
14 // We compile the binary without having the library present.
15 // We also set the rpath to the current directory so we can pick up the library at runtime.
16 rustc()
17 .crate_type("bin")
18 .input("main.rs")
19 .arg(&format!("-Wl,-rpath={}", cwd().display()))
20 .run();
21
22 // Now, *after* building the binary, we build the library...
23 build_native_dynamic_lib("library");
24 // ... rename it to have the versioned library name...
25 rfs::rename("liblibrary.so", "liblibrary.so.1");
26
27 // ... and run with this library, ensuring it was linked correctly at runtime.
28 let output = run("main").stdout_utf8();
29
30 diff().expected_file("output.txt").actual_text("actual", output).run();
31}
tests/run-make/raw-dylib-elf/library.c created+3
......@@ -0,0 +1,3 @@
1int this_is_a_library_function() {
2 return 42;
3}
tests/run-make/raw-dylib-elf/main.rs created+11
......@@ -0,0 +1,11 @@
1#![feature(raw_dylib_elf)]
2#![allow(incomplete_features)]
3
4#[link(name = "library", kind = "raw-dylib")]
5unsafe extern "C" {
6 safe fn this_is_a_library_function() -> core::ffi::c_int;
7}
8
9fn main() {
10 println!("{}", this_is_a_library_function())
11}
tests/run-make/raw-dylib-elf/output.txt created+1
......@@ -0,0 +1 @@
142
tests/run-make/raw-dylib-elf/rmake.rs created+29
......@@ -0,0 +1,29 @@
1//@ only-elf
2//@ ignore-cross-compile: Runs a binary.
3//@ needs-dynamic-linking
4// FIXME(raw_dylib_elf): Debug the failures on other targets.
5//@ only-gnu
6//@ only-x86_64
7
8//! Ensure ELF raw-dylib is able to link the binary without having the library present,
9//! and then successfully run against the real library.
10
11use run_make_support::{build_native_dynamic_lib, cwd, diff, run, rustc};
12
13fn main() {
14 // We compile the binary without having the library present.
15 // We also set the rpath to the current directory so we can pick up the library at runtime.
16 rustc()
17 .crate_type("bin")
18 .input("main.rs")
19 .arg(&format!("-Wl,-rpath={}", cwd().display()))
20 .run();
21
22 // Now, *after* building the binary, we build the library...
23 build_native_dynamic_lib("library");
24
25 // ... and run with this library, ensuring it was linked correctly at runtime.
26 let output = run("main").stdout_utf8();
27
28 diff().expected_file("output.txt").actual_text("actual", output).run();
29}
tests/run-make/reproducible-build/linker.rs+2
......@@ -17,6 +17,8 @@ fn main() {
1717 for arg in env::args().skip(1) {
1818 let path = Path::new(&arg);
1919 if !path.is_file() {
20 // This directory is produced during linking in a temporary directory (ELF only).
21 let arg = if arg.ends_with("/raw-dylibs") { "/raw-dylibs" } else { &*arg };
2022 out.push_str(&arg);
2123 out.push_str("\n");
2224 continue;
tests/ui/feature-gates/feature-gate-raw-dylib-elf.rs created+9
......@@ -0,0 +1,9 @@
1//@ only-elf
2//@ needs-dynamic-linking
3
4#[link(name = "meow", kind = "raw-dylib")] //~ ERROR: link kind `raw-dylib` is unstable on ELF platforms
5unsafe extern "C" {
6 safe fn meowmeow();
7}
8
9fn main() {}
tests/ui/feature-gates/feature-gate-raw-dylib-elf.stderr created+13
......@@ -0,0 +1,13 @@
1error[E0658]: link kind `raw-dylib` is unstable on ELF platforms
2 --> $DIR/feature-gate-raw-dylib-elf.rs:4:30
3 |
4LL | #[link(name = "meow", kind = "raw-dylib")]
5 | ^^^^^^^^^^^
6 |
7 = note: see issue #135694 <https://github.com/rust-lang/rust/issues/135694> for more information
8 = help: add `#![feature(raw_dylib_elf)]` to the crate attributes to enable
9 = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10
11error: aborting due to 1 previous error
12
13For more information about this error, try `rustc --explain E0658`.
tests/ui/linkage-attr/raw-dylib/elf/multiple-libraries.rs created+37
......@@ -0,0 +1,37 @@
1//@ only-elf
2//@ needs-dynamic-linking
3// FIXME(raw_dylib_elf): Debug the failures on other targets.
4//@ only-gnu
5//@ only-x86_64
6
7//@ revisions: with without
8
9//@ [without] build-fail
10//@ [without] regex-error-pattern:error: linking with `.*` failed
11//@ [without] dont-check-compiler-stderr
12
13//@ [with] build-pass
14
15//! Ensures that linking fails when there's an undefined symbol,
16//! and that it does succeed with raw-dylib.
17
18#![feature(raw_dylib_elf)]
19#![allow(incomplete_features)]
20
21#[cfg_attr(with, link(name = "rawdylibbutforcats", kind = "raw-dylib"))]
22#[cfg_attr(without, link(name = "rawdylibbutforcats"))]
23unsafe extern "C" {
24 safe fn meooooooooooooooow();
25}
26
27
28#[cfg_attr(with, link(name = "rawdylibbutfordogs", kind = "raw-dylib"))]
29#[cfg_attr(without, link(name = "rawdylibbutfordogs"))]
30unsafe extern "C" {
31 safe fn woooooooooooooooooof();
32}
33
34fn main() {
35 meooooooooooooooow();
36 woooooooooooooooooof();
37}
tests/ui/linkage-attr/raw-dylib/elf/single-symbol.rs created+28
......@@ -0,0 +1,28 @@
1//@ only-elf
2//@ needs-dynamic-linking
3// FIXME(raw_dylib_elf): Debug the failures on other targets.
4//@ only-gnu
5//@ only-x86_64
6//@ revisions: with without
7
8//@ [without] build-fail
9//@ [without] regex-error-pattern:error: linking with `.*` failed
10//@ [without] dont-check-compiler-stderr
11
12//@ [with] build-pass
13
14//! Ensures that linking fails when there's an undefined symbol,
15//! and that it does succeed with raw-dylib.
16
17#![feature(raw_dylib_elf)]
18#![allow(incomplete_features)]
19
20#[cfg_attr(with, link(name = "rawdylibbutforcats", kind = "raw-dylib"))]
21#[cfg_attr(without, link(name = "rawdylibbutforcats"))]
22unsafe extern "C" {
23 safe fn meooooooooooooooow();
24}
25
26fn main() {
27 meooooooooooooooow();
28}
tests/ui/linkage-attr/raw-dylib/elf/verbatim.rs created+29
......@@ -0,0 +1,29 @@
1//@ only-elf
2//@ needs-dynamic-linking
3// FIXME(raw_dylib_elf): Debug the failures on other targets.
4//@ only-gnu
5//@ only-x86_64
6
7//@ revisions: with without
8
9//@ [without] build-fail
10//@ [without] regex-error-pattern:error: linking with `.*` failed
11//@ [without] dont-check-compiler-stderr
12
13//@ [with] build-pass
14
15//! Ensures that linking fails when there's an undefined symbol,
16//! and that it does succeed with raw-dylib, but with verbatim.
17
18#![feature(raw_dylib_elf)]
19#![allow(incomplete_features)]
20
21#[cfg_attr(with, link(name = "rawdylibbutforcats", kind = "raw-dylib", modifiers = "+verbatim"))]
22#[cfg_attr(without, link(name = "rawdylibbutforcats", modifiers = "+verbatim"))]
23unsafe extern "C" {
24 safe fn meooooooooooooooow();
25}
26
27fn main() {
28 meooooooooooooooow();
29}
tests/ui/linkage-attr/raw-dylib/windows/dlltool-failed.rs created+21
......@@ -0,0 +1,21 @@
1// Tests that dlltool failing to generate an import library will raise an error.
2
3//@ needs-dlltool
4//@ compile-flags: --crate-type lib --emit link
5//@ normalize-stderr: "[^ ']*/dlltool.exe" -> "$$DLLTOOL"
6//@ normalize-stderr: "[^ ]*/foo.dll_imports.def" -> "$$DEF_FILE"
7//@ normalize-stderr: "[^ ]*/foo.dll_imports.lib" -> "$$LIB_FILE"
8//@ normalize-stderr: "-m [^ ]*" -> "$$TARGET_MACHINE"
9//@ normalize-stderr: "-f [^ ]*" -> "$$ASM_FLAGS"
10//@ normalize-stderr: "--temp-prefix [^ ]*/foo.dll" -> "$$TEMP_PREFIX"
11#[link(name = "foo", kind = "raw-dylib")]
12extern "C" {
13 // `@1` is an invalid name to export, as it usually indicates that something
14 // is being exported via ordinal.
15 #[link_name = "@1"]
16 fn f(x: i32);
17}
18
19pub fn lib_main() {
20 unsafe { f(42); }
21}
tests/ui/linkage-attr/raw-dylib/windows/dlltool-failed.stderr created+6
......@@ -0,0 +1,6 @@
1error: Dlltool could not create import library with $DLLTOOL -d $DEF_FILE -D foo.dll -l $LIB_FILE $TARGET_MACHINE $ASM_FLAGS --no-leading-underscore $TEMP_PREFIX:
2
3 $DLLTOOL: Syntax error in def file $DEF_FILE:1␍
4
5error: aborting due to 1 previous error
6
tests/ui/linkage-attr/raw-dylib/windows/import-name-type-invalid-format.rs created+7
......@@ -0,0 +1,7 @@
1//@ only-windows
2//@ only-x86
3#[link(name = "foo", kind = "raw-dylib", import_name_type = 6)]
4//~^ ERROR import name type must be of the form `import_name_type = "string"`
5extern "C" { }
6
7fn main() {}
tests/ui/linkage-attr/raw-dylib/windows/import-name-type-invalid-format.stderr created+8
......@@ -0,0 +1,8 @@
1error: import name type must be of the form `import_name_type = "string"`
2 --> $DIR/import-name-type-invalid-format.rs:3:42
3 |
4LL | #[link(name = "foo", kind = "raw-dylib", import_name_type = 6)]
5 | ^^^^^^^^^^^^^^^^^^^^
6
7error: aborting due to 1 previous error
8
tests/ui/linkage-attr/raw-dylib/windows/import-name-type-multiple.rs created+8
......@@ -0,0 +1,8 @@
1// ignore-tidy-linelength
2//@ only-windows
3//@ only-x86
4#[link(name = "foo", kind = "raw-dylib", import_name_type = "decorated", import_name_type = "decorated")]
5//~^ ERROR multiple `import_name_type` arguments in a single `#[link]` attribute
6extern "C" { }
7
8fn main() {}
tests/ui/linkage-attr/raw-dylib/windows/import-name-type-multiple.stderr created+8
......@@ -0,0 +1,8 @@
1error: multiple `import_name_type` arguments in a single `#[link]` attribute
2 --> $DIR/import-name-type-multiple.rs:4:74
3 |
4LL | #[link(name = "foo", kind = "raw-dylib", import_name_type = "decorated", import_name_type = "decorated")]
5 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6
7error: aborting due to 1 previous error
8
tests/ui/linkage-attr/raw-dylib/windows/import-name-type-unknown-value.rs created+7
......@@ -0,0 +1,7 @@
1//@ only-windows
2//@ only-x86
3#[link(name = "foo", kind = "raw-dylib", import_name_type = "unknown")]
4//~^ ERROR unknown import name type `unknown`, expected one of: decorated, noprefix, undecorated
5extern "C" { }
6
7fn main() {}
tests/ui/linkage-attr/raw-dylib/windows/import-name-type-unknown-value.stderr created+8
......@@ -0,0 +1,8 @@
1error: unknown import name type `unknown`, expected one of: decorated, noprefix, undecorated
2 --> $DIR/import-name-type-unknown-value.rs:3:42
3 |
4LL | #[link(name = "foo", kind = "raw-dylib", import_name_type = "unknown")]
5 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6
7error: aborting due to 1 previous error
8
tests/ui/linkage-attr/raw-dylib/windows/import-name-type-unsupported-link-kind.rs created+15
......@@ -0,0 +1,15 @@
1//@ only-windows
2//@ only-x86
3#[link(name = "foo", import_name_type = "decorated")]
4//~^ ERROR import name type can only be used with link kind `raw-dylib`
5extern "C" { }
6
7#[link(name = "bar", kind = "static", import_name_type = "decorated")]
8//~^ ERROR import name type can only be used with link kind `raw-dylib`
9extern "C" { }
10
11// Specifying `import_name_type` before `kind` shouldn't raise an error.
12#[link(name = "bar", import_name_type = "decorated", kind = "raw-dylib")]
13extern "C" { }
14
15fn main() {}
tests/ui/linkage-attr/raw-dylib/windows/import-name-type-unsupported-link-kind.stderr created+14
......@@ -0,0 +1,14 @@
1error: import name type can only be used with link kind `raw-dylib`
2 --> $DIR/import-name-type-unsupported-link-kind.rs:3:22
3 |
4LL | #[link(name = "foo", import_name_type = "decorated")]
5 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6
7error: import name type can only be used with link kind `raw-dylib`
8 --> $DIR/import-name-type-unsupported-link-kind.rs:7:39
9 |
10LL | #[link(name = "bar", kind = "static", import_name_type = "decorated")]
11 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12
13error: aborting due to 2 previous errors
14
tests/ui/linkage-attr/raw-dylib/windows/import-name-type-x86-only.rs created+7
......@@ -0,0 +1,7 @@
1//@ only-windows
2//@ ignore-x86
3#[link(name = "foo", kind = "raw-dylib", import_name_type = "decorated")]
4//~^ ERROR import name type is only supported on x86
5extern "C" { }
6
7fn main() {}
tests/ui/linkage-attr/raw-dylib/windows/import-name-type-x86-only.stderr created+8
......@@ -0,0 +1,8 @@
1error: import name type is only supported on x86
2 --> $DIR/import-name-type-x86-only.rs:3:42
3 |
4LL | #[link(name = "foo", kind = "raw-dylib", import_name_type = "decorated")]
5 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6
7error: aborting due to 1 previous error
8
tests/ui/linkage-attr/raw-dylib/windows/invalid-dlltool.rs created+12
......@@ -0,0 +1,12 @@
1// Tests that failing to run dlltool will raise an error.
2
3//@ needs-dlltool
4//@ compile-flags: --crate-type lib --emit link -Cdlltool=does_not_exist.exe
5#[link(name = "foo", kind = "raw-dylib")]
6extern "C" {
7 fn f(x: i32);
8}
9
10pub fn lib_main() {
11 unsafe { f(42); }
12}
tests/ui/linkage-attr/raw-dylib/windows/invalid-dlltool.stderr created+4
......@@ -0,0 +1,4 @@
1error: Error calling dlltool 'does_not_exist.exe': program not found
2
3error: aborting due to 1 previous error
4
tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-and-name.rs created+13
......@@ -0,0 +1,13 @@
1#[link(name="foo")]
2extern "C" {
3 #[link_name="foo"]
4 #[link_ordinal(42)]
5 //~^ ERROR cannot use `#[link_name]` with `#[link_ordinal]`
6 fn foo();
7 #[link_name="foo"]
8 #[link_ordinal(5)]
9 //~^ ERROR cannot use `#[link_name]` with `#[link_ordinal]`
10 static mut imported_variable: i32;
11}
12
13fn main() {}
tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-and-name.stderr created+14
......@@ -0,0 +1,14 @@
1error: cannot use `#[link_name]` with `#[link_ordinal]`
2 --> $DIR/link-ordinal-and-name.rs:4:5
3 |
4LL | #[link_ordinal(42)]
5 | ^^^^^^^^^^^^^^^^^^^
6
7error: cannot use `#[link_name]` with `#[link_ordinal]`
8 --> $DIR/link-ordinal-and-name.rs:8:5
9 |
10LL | #[link_ordinal(5)]
11 | ^^^^^^^^^^^^^^^^^^
12
13error: aborting due to 2 previous errors
14
tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-invalid-format.rs created+11
......@@ -0,0 +1,11 @@
1#[link(name = "foo")]
2extern "C" {
3 #[link_ordinal("JustMonika")]
4 //~^ ERROR illegal ordinal format in `link_ordinal`
5 fn foo();
6 #[link_ordinal("JustMonika")]
7 //~^ ERROR illegal ordinal format in `link_ordinal`
8 static mut imported_variable: i32;
9}
10
11fn main() {}
tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-invalid-format.stderr created+18
......@@ -0,0 +1,18 @@
1error: illegal ordinal format in `link_ordinal`
2 --> $DIR/link-ordinal-invalid-format.rs:3:5
3 |
4LL | #[link_ordinal("JustMonika")]
5 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6 |
7 = note: an unsuffixed integer value, e.g., `1`, is expected
8
9error: illegal ordinal format in `link_ordinal`
10 --> $DIR/link-ordinal-invalid-format.rs:6:5
11 |
12LL | #[link_ordinal("JustMonika")]
13 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14 |
15 = note: an unsuffixed integer value, e.g., `1`, is expected
16
17error: aborting due to 2 previous errors
18
tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-missing-argument.rs created+11
......@@ -0,0 +1,11 @@
1#[link(name = "foo")]
2extern "C" {
3 #[link_ordinal()]
4 //~^ ERROR incorrect number of arguments to `#[link_ordinal]`
5 fn foo();
6 #[link_ordinal()]
7 //~^ ERROR incorrect number of arguments to `#[link_ordinal]`
8 static mut imported_variable: i32;
9}
10
11fn main() {}
tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-missing-argument.stderr created+18
......@@ -0,0 +1,18 @@
1error: incorrect number of arguments to `#[link_ordinal]`
2 --> $DIR/link-ordinal-missing-argument.rs:3:5
3 |
4LL | #[link_ordinal()]
5 | ^^^^^^^^^^^^^^^^^
6 |
7 = note: the attribute requires exactly one argument
8
9error: incorrect number of arguments to `#[link_ordinal]`
10 --> $DIR/link-ordinal-missing-argument.rs:6:5
11 |
12LL | #[link_ordinal()]
13 | ^^^^^^^^^^^^^^^^^
14 |
15 = note: the attribute requires exactly one argument
16
17error: aborting due to 2 previous errors
18
tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-multiple.rs created+12
......@@ -0,0 +1,12 @@
1//@ only-windows
2#[link(name = "foo", kind = "raw-dylib")]
3extern "C" {
4 #[link_ordinal(1)] //~ ERROR multiple `link_ordinal` attributes
5 #[link_ordinal(2)]
6 fn foo();
7 #[link_ordinal(1)] //~ ERROR multiple `link_ordinal` attributes
8 #[link_ordinal(2)]
9 static mut imported_variable: i32;
10}
11
12fn main() {}
tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-multiple.stderr created+26
......@@ -0,0 +1,26 @@
1error: multiple `link_ordinal` attributes
2 --> $DIR/link-ordinal-multiple.rs:4:5
3 |
4LL | #[link_ordinal(1)]
5 | ^^^^^^^^^^^^^^^^^^ help: remove this attribute
6 |
7note: attribute also specified here
8 --> $DIR/link-ordinal-multiple.rs:5:5
9 |
10LL | #[link_ordinal(2)]
11 | ^^^^^^^^^^^^^^^^^^
12
13error: multiple `link_ordinal` attributes
14 --> $DIR/link-ordinal-multiple.rs:7:5
15 |
16LL | #[link_ordinal(1)]
17 | ^^^^^^^^^^^^^^^^^^ help: remove this attribute
18 |
19note: attribute also specified here
20 --> $DIR/link-ordinal-multiple.rs:8:5
21 |
22LL | #[link_ordinal(2)]
23 | ^^^^^^^^^^^^^^^^^^
24
25error: aborting due to 2 previous errors
26
tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-not-foreign-fn.rs created+22
......@@ -0,0 +1,22 @@
1#[link_ordinal(123)]
2//~^ ERROR attribute should be applied to a foreign function or static
3struct Foo {}
4
5#[link_ordinal(123)]
6//~^ ERROR attribute should be applied to a foreign function or static
7fn test() {}
8
9#[link_ordinal(42)]
10//~^ ERROR attribute should be applied to a foreign function or static
11static mut imported_val: i32 = 123;
12
13#[link(name = "exporter", kind = "raw-dylib")]
14extern "C" {
15 #[link_ordinal(13)]
16 fn imported_function();
17
18 #[link_ordinal(42)]
19 static mut imported_variable: i32;
20}
21
22fn main() {}
tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-not-foreign-fn.stderr created+20
......@@ -0,0 +1,20 @@
1error: attribute should be applied to a foreign function or static
2 --> $DIR/link-ordinal-not-foreign-fn.rs:1:1
3 |
4LL | #[link_ordinal(123)]
5 | ^^^^^^^^^^^^^^^^^^^^
6
7error: attribute should be applied to a foreign function or static
8 --> $DIR/link-ordinal-not-foreign-fn.rs:5:1
9 |
10LL | #[link_ordinal(123)]
11 | ^^^^^^^^^^^^^^^^^^^^
12
13error: attribute should be applied to a foreign function or static
14 --> $DIR/link-ordinal-not-foreign-fn.rs:9:1
15 |
16LL | #[link_ordinal(42)]
17 | ^^^^^^^^^^^^^^^^^^^
18
19error: aborting due to 3 previous errors
20
tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-too-large.rs created+11
......@@ -0,0 +1,11 @@
1#[link(name = "foo")]
2extern "C" {
3 #[link_ordinal(72436)]
4 //~^ ERROR ordinal value in `link_ordinal` is too large: `72436`
5 fn foo();
6 #[link_ordinal(72436)]
7 //~^ ERROR ordinal value in `link_ordinal` is too large: `72436`
8 static mut imported_variable: i32;
9}
10
11fn main() {}
tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-too-large.stderr created+18
......@@ -0,0 +1,18 @@
1error: ordinal value in `link_ordinal` is too large: `72436`
2 --> $DIR/link-ordinal-too-large.rs:3:5
3 |
4LL | #[link_ordinal(72436)]
5 | ^^^^^^^^^^^^^^^^^^^^^^
6 |
7 = note: the value may not exceed `u16::MAX`
8
9error: ordinal value in `link_ordinal` is too large: `72436`
10 --> $DIR/link-ordinal-too-large.rs:6:5
11 |
12LL | #[link_ordinal(72436)]
13 | ^^^^^^^^^^^^^^^^^^^^^^
14 |
15 = note: the value may not exceed `u16::MAX`
16
17error: aborting due to 2 previous errors
18
tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-too-many-arguments.rs created+11
......@@ -0,0 +1,11 @@
1#[link(name = "foo")]
2extern "C" {
3 #[link_ordinal(3, 4)]
4 //~^ ERROR incorrect number of arguments to `#[link_ordinal]`
5 fn foo();
6 #[link_ordinal(3, 4)]
7 //~^ ERROR incorrect number of arguments to `#[link_ordinal]`
8 static mut imported_variable: i32;
9}
10
11fn main() {}
tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-too-many-arguments.stderr created+18
......@@ -0,0 +1,18 @@
1error: incorrect number of arguments to `#[link_ordinal]`
2 --> $DIR/link-ordinal-too-many-arguments.rs:3:5
3 |
4LL | #[link_ordinal(3, 4)]
5 | ^^^^^^^^^^^^^^^^^^^^^
6 |
7 = note: the attribute requires exactly one argument
8
9error: incorrect number of arguments to `#[link_ordinal]`
10 --> $DIR/link-ordinal-too-many-arguments.rs:6:5
11 |
12LL | #[link_ordinal(3, 4)]
13 | ^^^^^^^^^^^^^^^^^^^^^
14 |
15 = note: the attribute requires exactly one argument
16
17error: aborting due to 2 previous errors
18
tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-unsupported-link-kind.rs created+15
......@@ -0,0 +1,15 @@
1#[link(name = "foo")]
2extern "C" {
3 #[link_ordinal(3)]
4 //~^ ERROR `#[link_ordinal]` is only supported if link kind is `raw-dylib`
5 fn foo();
6}
7
8#[link(name = "bar", kind = "static")]
9extern "C" {
10 #[link_ordinal(3)]
11 //~^ ERROR `#[link_ordinal]` is only supported if link kind is `raw-dylib`
12 fn bar();
13}
14
15fn main() {}
tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-unsupported-link-kind.stderr created+14
......@@ -0,0 +1,14 @@
1error: `#[link_ordinal]` is only supported if link kind is `raw-dylib`
2 --> $DIR/link-ordinal-unsupported-link-kind.rs:3:5
3 |
4LL | #[link_ordinal(3)]
5 | ^^^^^^^^^^^^^^^^^^
6
7error: `#[link_ordinal]` is only supported if link kind is `raw-dylib`
8 --> $DIR/link-ordinal-unsupported-link-kind.rs:10:5
9 |
10LL | #[link_ordinal(3)]
11 | ^^^^^^^^^^^^^^^^^^
12
13error: aborting due to 2 previous errors
14
tests/ui/linkage-attr/raw-dylib/windows/multiple-declarations.rs created+18
......@@ -0,0 +1,18 @@
1//@ only-x86
2//@ only-windows
3//@ compile-flags: --crate-type lib --emit link
4#![allow(clashing_extern_declarations)]
5#[link(name = "foo", kind = "raw-dylib")]
6extern "C" {
7 fn f(x: i32);
8}
9
10pub fn lib_main() {
11 #[link(name = "foo", kind = "raw-dylib")]
12 extern "stdcall" {
13 fn f(x: i32);
14 //~^ ERROR multiple declarations of external function `f` from library `foo.dll` have different calling conventions
15 }
16
17 unsafe { f(42); }
18}
tests/ui/linkage-attr/raw-dylib/windows/multiple-declarations.stderr created+8
......@@ -0,0 +1,8 @@
1error: multiple declarations of external function `f` from library `foo.dll` have different calling conventions
2 --> $DIR/multiple-declarations.rs:13:9
3 |
4LL | fn f(x: i32);
5 | ^^^^^^^^^^^^^
6
7error: aborting due to 1 previous error
8
tests/ui/linkage-attr/raw-dylib/windows/raw-dylib-windows-only.elf.stderr created+13
......@@ -0,0 +1,13 @@
1error[E0658]: link kind `raw-dylib` is unstable on ELF platforms
2 --> $DIR/raw-dylib-windows-only.rs:6:29
3 |
4LL | #[link(name = "foo", kind = "raw-dylib")]
5 | ^^^^^^^^^^^
6 |
7 = note: see issue #135694 <https://github.com/rust-lang/rust/issues/135694> for more information
8 = help: add `#![feature(raw_dylib_elf)]` to the crate attributes to enable
9 = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10
11error: aborting due to 1 previous error
12
13For more information about this error, try `rustc --explain E0658`.
tests/ui/linkage-attr/raw-dylib/windows/raw-dylib-windows-only.notelf.stderr created+9
......@@ -0,0 +1,9 @@
1error[E0455]: link kind `raw-dylib` is only supported on Windows targets
2 --> $DIR/raw-dylib-windows-only.rs:6:29
3 |
4LL | #[link(name = "foo", kind = "raw-dylib")]
5 | ^^^^^^^^^^^
6
7error: aborting due to 1 previous error
8
9For more information about this error, try `rustc --explain E0455`.
tests/ui/linkage-attr/raw-dylib/windows/raw-dylib-windows-only.rs created+9
......@@ -0,0 +1,9 @@
1//@ revisions: elf notelf
2//@ [elf] only-elf
3//@ [notelf] ignore-windows
4//@ [notelf] ignore-elf
5//@ compile-flags: --crate-type lib
6#[link(name = "foo", kind = "raw-dylib")]
7//[notelf]~^ ERROR: link kind `raw-dylib` is only supported on Windows targets
8//[elf]~^^ ERROR: link kind `raw-dylib` is unstable on ELF platforms
9extern "C" {}
tests/ui/linkage-attr/raw-dylib/windows/unsupported-abi.rs created+12
......@@ -0,0 +1,12 @@
1//@ only-x86_64
2//@ only-windows
3//@ compile-flags: --crate-type lib --emit link
4#[link(name = "foo", kind = "raw-dylib")]
5extern "stdcall" {
6 fn f(x: i32);
7 //~^ ERROR ABI not supported by `#[link(kind = "raw-dylib")]` on this architecture
8}
9
10pub fn lib_main() {
11 unsafe { f(42); }
12}
tests/ui/linkage-attr/raw-dylib/windows/unsupported-abi.stderr created+8
......@@ -0,0 +1,8 @@
1error: ABI not supported by `#[link(kind = "raw-dylib")]` on this architecture
2 --> $DIR/unsupported-abi.rs:6:5
3 |
4LL | fn f(x: i32);
5 | ^^^^^^^^^^^^^
6
7error: aborting due to 1 previous error
8
tests/ui/rfcs/rfc-2627-raw-dylib/dlltool-failed.rs deleted-21
......@@ -1,21 +0,0 @@
1// Tests that dlltool failing to generate an import library will raise an error.
2
3//@ needs-dlltool
4//@ compile-flags: --crate-type lib --emit link
5//@ normalize-stderr: "[^ ']*/dlltool.exe" -> "$$DLLTOOL"
6//@ normalize-stderr: "[^ ]*/foo.dll_imports.def" -> "$$DEF_FILE"
7//@ normalize-stderr: "[^ ]*/foo.dll_imports.lib" -> "$$LIB_FILE"
8//@ normalize-stderr: "-m [^ ]*" -> "$$TARGET_MACHINE"
9//@ normalize-stderr: "-f [^ ]*" -> "$$ASM_FLAGS"
10//@ normalize-stderr: "--temp-prefix [^ ]*/foo.dll" -> "$$TEMP_PREFIX"
11#[link(name = "foo", kind = "raw-dylib")]
12extern "C" {
13 // `@1` is an invalid name to export, as it usually indicates that something
14 // is being exported via ordinal.
15 #[link_name = "@1"]
16 fn f(x: i32);
17}
18
19pub fn lib_main() {
20 unsafe { f(42); }
21}
tests/ui/rfcs/rfc-2627-raw-dylib/dlltool-failed.stderr deleted-6
......@@ -1,6 +0,0 @@
1error: Dlltool could not create import library with $DLLTOOL -d $DEF_FILE -D foo.dll -l $LIB_FILE $TARGET_MACHINE $ASM_FLAGS --no-leading-underscore $TEMP_PREFIX:
2
3 $DLLTOOL: Syntax error in def file $DEF_FILE:1␍
4
5error: aborting due to 1 previous error
6
tests/ui/rfcs/rfc-2627-raw-dylib/import-name-type-invalid-format.rs deleted-7
......@@ -1,7 +0,0 @@
1//@ only-windows
2//@ only-x86
3#[link(name = "foo", kind = "raw-dylib", import_name_type = 6)]
4//~^ ERROR import name type must be of the form `import_name_type = "string"`
5extern "C" { }
6
7fn main() {}
tests/ui/rfcs/rfc-2627-raw-dylib/import-name-type-invalid-format.stderr deleted-8
......@@ -1,8 +0,0 @@
1error: import name type must be of the form `import_name_type = "string"`
2 --> $DIR/import-name-type-invalid-format.rs:3:42
3 |
4LL | #[link(name = "foo", kind = "raw-dylib", import_name_type = 6)]
5 | ^^^^^^^^^^^^^^^^^^^^
6
7error: aborting due to 1 previous error
8
tests/ui/rfcs/rfc-2627-raw-dylib/import-name-type-multiple.rs deleted-8
......@@ -1,8 +0,0 @@
1// ignore-tidy-linelength
2//@ only-windows
3//@ only-x86
4#[link(name = "foo", kind = "raw-dylib", import_name_type = "decorated", import_name_type = "decorated")]
5//~^ ERROR multiple `import_name_type` arguments in a single `#[link]` attribute
6extern "C" { }
7
8fn main() {}
tests/ui/rfcs/rfc-2627-raw-dylib/import-name-type-multiple.stderr deleted-8
......@@ -1,8 +0,0 @@
1error: multiple `import_name_type` arguments in a single `#[link]` attribute
2 --> $DIR/import-name-type-multiple.rs:4:74
3 |
4LL | #[link(name = "foo", kind = "raw-dylib", import_name_type = "decorated", import_name_type = "decorated")]
5 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6
7error: aborting due to 1 previous error
8
tests/ui/rfcs/rfc-2627-raw-dylib/import-name-type-unknown-value.rs deleted-7
......@@ -1,7 +0,0 @@
1//@ only-windows
2//@ only-x86
3#[link(name = "foo", kind = "raw-dylib", import_name_type = "unknown")]
4//~^ ERROR unknown import name type `unknown`, expected one of: decorated, noprefix, undecorated
5extern "C" { }
6
7fn main() {}
tests/ui/rfcs/rfc-2627-raw-dylib/import-name-type-unknown-value.stderr deleted-8
......@@ -1,8 +0,0 @@
1error: unknown import name type `unknown`, expected one of: decorated, noprefix, undecorated
2 --> $DIR/import-name-type-unknown-value.rs:3:42
3 |
4LL | #[link(name = "foo", kind = "raw-dylib", import_name_type = "unknown")]
5 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6
7error: aborting due to 1 previous error
8
tests/ui/rfcs/rfc-2627-raw-dylib/import-name-type-unsupported-link-kind.rs deleted-15
......@@ -1,15 +0,0 @@
1//@ only-windows
2//@ only-x86
3#[link(name = "foo", import_name_type = "decorated")]
4//~^ ERROR import name type can only be used with link kind `raw-dylib`
5extern "C" { }
6
7#[link(name = "bar", kind = "static", import_name_type = "decorated")]
8//~^ ERROR import name type can only be used with link kind `raw-dylib`
9extern "C" { }
10
11// Specifying `import_name_type` before `kind` shouldn't raise an error.
12#[link(name = "bar", import_name_type = "decorated", kind = "raw-dylib")]
13extern "C" { }
14
15fn main() {}
tests/ui/rfcs/rfc-2627-raw-dylib/import-name-type-unsupported-link-kind.stderr deleted-14
......@@ -1,14 +0,0 @@
1error: import name type can only be used with link kind `raw-dylib`
2 --> $DIR/import-name-type-unsupported-link-kind.rs:3:22
3 |
4LL | #[link(name = "foo", import_name_type = "decorated")]
5 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6
7error: import name type can only be used with link kind `raw-dylib`
8 --> $DIR/import-name-type-unsupported-link-kind.rs:7:39
9 |
10LL | #[link(name = "bar", kind = "static", import_name_type = "decorated")]
11 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12
13error: aborting due to 2 previous errors
14
tests/ui/rfcs/rfc-2627-raw-dylib/import-name-type-x86-only.rs deleted-7
......@@ -1,7 +0,0 @@
1//@ only-windows
2//@ ignore-x86
3#[link(name = "foo", kind = "raw-dylib", import_name_type = "decorated")]
4//~^ ERROR import name type is only supported on x86
5extern "C" { }
6
7fn main() {}
tests/ui/rfcs/rfc-2627-raw-dylib/import-name-type-x86-only.stderr deleted-8
......@@ -1,8 +0,0 @@
1error: import name type is only supported on x86
2 --> $DIR/import-name-type-x86-only.rs:3:42
3 |
4LL | #[link(name = "foo", kind = "raw-dylib", import_name_type = "decorated")]
5 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6
7error: aborting due to 1 previous error
8
tests/ui/rfcs/rfc-2627-raw-dylib/invalid-dlltool.rs deleted-12
......@@ -1,12 +0,0 @@
1// Tests that failing to run dlltool will raise an error.
2
3//@ needs-dlltool
4//@ compile-flags: --crate-type lib --emit link -Cdlltool=does_not_exist.exe
5#[link(name = "foo", kind = "raw-dylib")]
6extern "C" {
7 fn f(x: i32);
8}
9
10pub fn lib_main() {
11 unsafe { f(42); }
12}
tests/ui/rfcs/rfc-2627-raw-dylib/invalid-dlltool.stderr deleted-4
......@@ -1,4 +0,0 @@
1error: Error calling dlltool 'does_not_exist.exe': program not found
2
3error: aborting due to 1 previous error
4
tests/ui/rfcs/rfc-2627-raw-dylib/link-ordinal-and-name.rs deleted-13
......@@ -1,13 +0,0 @@
1#[link(name="foo")]
2extern "C" {
3 #[link_name="foo"]
4 #[link_ordinal(42)]
5 //~^ ERROR cannot use `#[link_name]` with `#[link_ordinal]`
6 fn foo();
7 #[link_name="foo"]
8 #[link_ordinal(5)]
9 //~^ ERROR cannot use `#[link_name]` with `#[link_ordinal]`
10 static mut imported_variable: i32;
11}
12
13fn main() {}
tests/ui/rfcs/rfc-2627-raw-dylib/link-ordinal-and-name.stderr deleted-14
......@@ -1,14 +0,0 @@
1error: cannot use `#[link_name]` with `#[link_ordinal]`
2 --> $DIR/link-ordinal-and-name.rs:4:5
3 |
4LL | #[link_ordinal(42)]
5 | ^^^^^^^^^^^^^^^^^^^
6
7error: cannot use `#[link_name]` with `#[link_ordinal]`
8 --> $DIR/link-ordinal-and-name.rs:8:5
9 |
10LL | #[link_ordinal(5)]
11 | ^^^^^^^^^^^^^^^^^^
12
13error: aborting due to 2 previous errors
14
tests/ui/rfcs/rfc-2627-raw-dylib/link-ordinal-invalid-format.rs deleted-11
......@@ -1,11 +0,0 @@
1#[link(name = "foo")]
2extern "C" {
3 #[link_ordinal("JustMonika")]
4 //~^ ERROR illegal ordinal format in `link_ordinal`
5 fn foo();
6 #[link_ordinal("JustMonika")]
7 //~^ ERROR illegal ordinal format in `link_ordinal`
8 static mut imported_variable: i32;
9}
10
11fn main() {}
tests/ui/rfcs/rfc-2627-raw-dylib/link-ordinal-invalid-format.stderr deleted-18
......@@ -1,18 +0,0 @@
1error: illegal ordinal format in `link_ordinal`
2 --> $DIR/link-ordinal-invalid-format.rs:3:5
3 |
4LL | #[link_ordinal("JustMonika")]
5 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6 |
7 = note: an unsuffixed integer value, e.g., `1`, is expected
8
9error: illegal ordinal format in `link_ordinal`
10 --> $DIR/link-ordinal-invalid-format.rs:6:5
11 |
12LL | #[link_ordinal("JustMonika")]
13 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14 |
15 = note: an unsuffixed integer value, e.g., `1`, is expected
16
17error: aborting due to 2 previous errors
18
tests/ui/rfcs/rfc-2627-raw-dylib/link-ordinal-missing-argument.rs deleted-11
......@@ -1,11 +0,0 @@
1#[link(name = "foo")]
2extern "C" {
3 #[link_ordinal()]
4 //~^ ERROR incorrect number of arguments to `#[link_ordinal]`
5 fn foo();
6 #[link_ordinal()]
7 //~^ ERROR incorrect number of arguments to `#[link_ordinal]`
8 static mut imported_variable: i32;
9}
10
11fn main() {}
tests/ui/rfcs/rfc-2627-raw-dylib/link-ordinal-missing-argument.stderr deleted-18
......@@ -1,18 +0,0 @@
1error: incorrect number of arguments to `#[link_ordinal]`
2 --> $DIR/link-ordinal-missing-argument.rs:3:5
3 |
4LL | #[link_ordinal()]
5 | ^^^^^^^^^^^^^^^^^
6 |
7 = note: the attribute requires exactly one argument
8
9error: incorrect number of arguments to `#[link_ordinal]`
10 --> $DIR/link-ordinal-missing-argument.rs:6:5
11 |
12LL | #[link_ordinal()]
13 | ^^^^^^^^^^^^^^^^^
14 |
15 = note: the attribute requires exactly one argument
16
17error: aborting due to 2 previous errors
18
tests/ui/rfcs/rfc-2627-raw-dylib/link-ordinal-multiple.rs deleted-12
......@@ -1,12 +0,0 @@
1//@ only-windows
2#[link(name = "foo", kind = "raw-dylib")]
3extern "C" {
4 #[link_ordinal(1)] //~ ERROR multiple `link_ordinal` attributes
5 #[link_ordinal(2)]
6 fn foo();
7 #[link_ordinal(1)] //~ ERROR multiple `link_ordinal` attributes
8 #[link_ordinal(2)]
9 static mut imported_variable: i32;
10}
11
12fn main() {}
tests/ui/rfcs/rfc-2627-raw-dylib/link-ordinal-multiple.stderr deleted-26
......@@ -1,26 +0,0 @@
1error: multiple `link_ordinal` attributes
2 --> $DIR/link-ordinal-multiple.rs:4:5
3 |
4LL | #[link_ordinal(1)]
5 | ^^^^^^^^^^^^^^^^^^ help: remove this attribute
6 |
7note: attribute also specified here
8 --> $DIR/link-ordinal-multiple.rs:5:5
9 |
10LL | #[link_ordinal(2)]
11 | ^^^^^^^^^^^^^^^^^^
12
13error: multiple `link_ordinal` attributes
14 --> $DIR/link-ordinal-multiple.rs:7:5
15 |
16LL | #[link_ordinal(1)]
17 | ^^^^^^^^^^^^^^^^^^ help: remove this attribute
18 |
19note: attribute also specified here
20 --> $DIR/link-ordinal-multiple.rs:8:5
21 |
22LL | #[link_ordinal(2)]
23 | ^^^^^^^^^^^^^^^^^^
24
25error: aborting due to 2 previous errors
26
tests/ui/rfcs/rfc-2627-raw-dylib/link-ordinal-not-foreign-fn.rs deleted-22
......@@ -1,22 +0,0 @@
1#[link_ordinal(123)]
2//~^ ERROR attribute should be applied to a foreign function or static
3struct Foo {}
4
5#[link_ordinal(123)]
6//~^ ERROR attribute should be applied to a foreign function or static
7fn test() {}
8
9#[link_ordinal(42)]
10//~^ ERROR attribute should be applied to a foreign function or static
11static mut imported_val: i32 = 123;
12
13#[link(name = "exporter", kind = "raw-dylib")]
14extern "C" {
15 #[link_ordinal(13)]
16 fn imported_function();
17
18 #[link_ordinal(42)]
19 static mut imported_variable: i32;
20}
21
22fn main() {}
tests/ui/rfcs/rfc-2627-raw-dylib/link-ordinal-not-foreign-fn.stderr deleted-20
......@@ -1,20 +0,0 @@
1error: attribute should be applied to a foreign function or static
2 --> $DIR/link-ordinal-not-foreign-fn.rs:1:1
3 |
4LL | #[link_ordinal(123)]
5 | ^^^^^^^^^^^^^^^^^^^^
6
7error: attribute should be applied to a foreign function or static
8 --> $DIR/link-ordinal-not-foreign-fn.rs:5:1
9 |
10LL | #[link_ordinal(123)]
11 | ^^^^^^^^^^^^^^^^^^^^
12
13error: attribute should be applied to a foreign function or static
14 --> $DIR/link-ordinal-not-foreign-fn.rs:9:1
15 |
16LL | #[link_ordinal(42)]
17 | ^^^^^^^^^^^^^^^^^^^
18
19error: aborting due to 3 previous errors
20
tests/ui/rfcs/rfc-2627-raw-dylib/link-ordinal-too-large.rs deleted-11
......@@ -1,11 +0,0 @@
1#[link(name = "foo")]
2extern "C" {
3 #[link_ordinal(72436)]
4 //~^ ERROR ordinal value in `link_ordinal` is too large: `72436`
5 fn foo();
6 #[link_ordinal(72436)]
7 //~^ ERROR ordinal value in `link_ordinal` is too large: `72436`
8 static mut imported_variable: i32;
9}
10
11fn main() {}
tests/ui/rfcs/rfc-2627-raw-dylib/link-ordinal-too-large.stderr deleted-18
......@@ -1,18 +0,0 @@
1error: ordinal value in `link_ordinal` is too large: `72436`
2 --> $DIR/link-ordinal-too-large.rs:3:5
3 |
4LL | #[link_ordinal(72436)]
5 | ^^^^^^^^^^^^^^^^^^^^^^
6 |
7 = note: the value may not exceed `u16::MAX`
8
9error: ordinal value in `link_ordinal` is too large: `72436`
10 --> $DIR/link-ordinal-too-large.rs:6:5
11 |
12LL | #[link_ordinal(72436)]
13 | ^^^^^^^^^^^^^^^^^^^^^^
14 |
15 = note: the value may not exceed `u16::MAX`
16
17error: aborting due to 2 previous errors
18
tests/ui/rfcs/rfc-2627-raw-dylib/link-ordinal-too-many-arguments.rs deleted-11
......@@ -1,11 +0,0 @@
1#[link(name = "foo")]
2extern "C" {
3 #[link_ordinal(3, 4)]
4 //~^ ERROR incorrect number of arguments to `#[link_ordinal]`
5 fn foo();
6 #[link_ordinal(3, 4)]
7 //~^ ERROR incorrect number of arguments to `#[link_ordinal]`
8 static mut imported_variable: i32;
9}
10
11fn main() {}
tests/ui/rfcs/rfc-2627-raw-dylib/link-ordinal-too-many-arguments.stderr deleted-18
......@@ -1,18 +0,0 @@
1error: incorrect number of arguments to `#[link_ordinal]`
2 --> $DIR/link-ordinal-too-many-arguments.rs:3:5
3 |
4LL | #[link_ordinal(3, 4)]
5 | ^^^^^^^^^^^^^^^^^^^^^
6 |
7 = note: the attribute requires exactly one argument
8
9error: incorrect number of arguments to `#[link_ordinal]`
10 --> $DIR/link-ordinal-too-many-arguments.rs:6:5
11 |
12LL | #[link_ordinal(3, 4)]
13 | ^^^^^^^^^^^^^^^^^^^^^
14 |
15 = note: the attribute requires exactly one argument
16
17error: aborting due to 2 previous errors
18
tests/ui/rfcs/rfc-2627-raw-dylib/link-ordinal-unsupported-link-kind.rs deleted-15
......@@ -1,15 +0,0 @@
1#[link(name = "foo")]
2extern "C" {
3 #[link_ordinal(3)]
4 //~^ ERROR `#[link_ordinal]` is only supported if link kind is `raw-dylib`
5 fn foo();
6}
7
8#[link(name = "bar", kind = "static")]
9extern "C" {
10 #[link_ordinal(3)]
11 //~^ ERROR `#[link_ordinal]` is only supported if link kind is `raw-dylib`
12 fn bar();
13}
14
15fn main() {}
tests/ui/rfcs/rfc-2627-raw-dylib/link-ordinal-unsupported-link-kind.stderr deleted-14
......@@ -1,14 +0,0 @@
1error: `#[link_ordinal]` is only supported if link kind is `raw-dylib`
2 --> $DIR/link-ordinal-unsupported-link-kind.rs:3:5
3 |
4LL | #[link_ordinal(3)]
5 | ^^^^^^^^^^^^^^^^^^
6
7error: `#[link_ordinal]` is only supported if link kind is `raw-dylib`
8 --> $DIR/link-ordinal-unsupported-link-kind.rs:10:5
9 |
10LL | #[link_ordinal(3)]
11 | ^^^^^^^^^^^^^^^^^^
12
13error: aborting due to 2 previous errors
14
tests/ui/rfcs/rfc-2627-raw-dylib/multiple-declarations.rs deleted-18
......@@ -1,18 +0,0 @@
1//@ only-x86
2//@ only-windows
3//@ compile-flags: --crate-type lib --emit link
4#![allow(clashing_extern_declarations)]
5#[link(name = "foo", kind = "raw-dylib")]
6extern "C" {
7 fn f(x: i32);
8}
9
10pub fn lib_main() {
11 #[link(name = "foo", kind = "raw-dylib")]
12 extern "stdcall" {
13 fn f(x: i32);
14 //~^ ERROR multiple declarations of external function `f` from library `foo.dll` have different calling conventions
15 }
16
17 unsafe { f(42); }
18}
tests/ui/rfcs/rfc-2627-raw-dylib/multiple-declarations.stderr deleted-8
......@@ -1,8 +0,0 @@
1error: multiple declarations of external function `f` from library `foo.dll` have different calling conventions
2 --> $DIR/multiple-declarations.rs:13:9
3 |
4LL | fn f(x: i32);
5 | ^^^^^^^^^^^^^
6
7error: aborting due to 1 previous error
8
tests/ui/rfcs/rfc-2627-raw-dylib/raw-dylib-windows-only.rs deleted-5
......@@ -1,5 +0,0 @@
1//@ ignore-windows
2//@ compile-flags: --crate-type lib
3#[link(name = "foo", kind = "raw-dylib")]
4//~^ ERROR: link kind `raw-dylib` is only supported on Windows targets
5extern "C" {}
tests/ui/rfcs/rfc-2627-raw-dylib/raw-dylib-windows-only.stderr deleted-9
......@@ -1,9 +0,0 @@
1error[E0455]: link kind `raw-dylib` is only supported on Windows targets
2 --> $DIR/raw-dylib-windows-only.rs:3:29
3 |
4LL | #[link(name = "foo", kind = "raw-dylib")]
5 | ^^^^^^^^^^^
6
7error: aborting due to 1 previous error
8
9For more information about this error, try `rustc --explain E0455`.
tests/ui/rfcs/rfc-2627-raw-dylib/unsupported-abi.rs deleted-12
......@@ -1,12 +0,0 @@
1//@ only-x86_64
2//@ only-windows
3//@ compile-flags: --crate-type lib --emit link
4#[link(name = "foo", kind = "raw-dylib")]
5extern "stdcall" {
6 fn f(x: i32);
7 //~^ ERROR ABI not supported by `#[link(kind = "raw-dylib")]` on this architecture
8}
9
10pub fn lib_main() {
11 unsafe { f(42); }
12}
tests/ui/rfcs/rfc-2627-raw-dylib/unsupported-abi.stderr deleted-8
......@@ -1,8 +0,0 @@
1error: ABI not supported by `#[link(kind = "raw-dylib")]` on this architecture
2 --> $DIR/unsupported-abi.rs:6:5
3 |
4LL | fn f(x: i32);
5 | ^^^^^^^^^^^^^
6
7error: aborting due to 1 previous error
8