Skip to content

Commit c14e3af

Browse files
committed
[temp] link_rlib used_libraries
1 parent e1c9121 commit c14e3af

File tree

5 files changed

+20
-67
lines changed

5 files changed

+20
-67
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,9 @@ pub fn each_linked_rlib(
274274

275275
/// Create an 'rlib'.
276276
///
277-
/// An rlib in its current incarnation is essentially a renamed .a file. The rlib primarily contains
278-
/// the object file of the crate, but it also contains all of the object files from native
279-
/// libraries. This is done by unzipping native libraries and inserting all of the contents into
280-
/// this archive.
277+
/// An rlib in its current incarnation is essentially a renamed .a file (with "dummy" object files).
278+
/// The rlib primarily contains the object file of the crate, but it also some of the object files
279+
/// from native libraries.
281280
fn link_rlib<'a>(
282281
sess: &'a Session,
283282
archive_builder_builder: &dyn ArchiveBuilderBuilder,
@@ -351,43 +350,24 @@ fn link_rlib<'a>(
351350
// loaded from the libraries found here and then encode that into the
352351
// metadata of the rlib we're generating somehow.
353352
for lib in codegen_results.crate_info.used_libraries.iter() {
354-
match lib.kind {
355-
NativeLibKind::Static { bundle: None | Some(true), whole_archive: Some(true) }
356-
if flavor == RlibFlavor::Normal && sess.opts.unstable_opts.packed_bundled_libs => {}
357-
NativeLibKind::Static { bundle: None | Some(true), whole_archive: Some(true) }
358-
if flavor == RlibFlavor::Normal =>
359-
{
360-
// Don't allow mixing +bundle with +whole_archive since an rlib may contain
361-
// multiple native libs, some of which are +whole-archive and some of which are
362-
// -whole-archive and it isn't clear how we can currently handle such a
363-
// situation correctly.
364-
// See https://github.com/rust-lang/rust/issues/88085#issuecomment-901050897
365-
sess.emit_err(errors::IncompatibleLinkingModifiers);
366-
}
367-
NativeLibKind::Static { bundle: None | Some(true), .. } => {}
368-
NativeLibKind::Static { bundle: Some(false), .. }
369-
| NativeLibKind::Dylib { .. }
370-
| NativeLibKind::Framework { .. }
371-
| NativeLibKind::RawDylib
372-
| NativeLibKind::LinkArg
373-
| NativeLibKind::Unspecified => continue,
374-
}
375-
if let Some(name) = lib.name {
376-
let location =
353+
let NativeLibKind::Static { bundle: None | Some(true), whole_archive } = lib.kind else {
354+
continue;
355+
};
356+
if flavor == RlibFlavor::Normal
357+
&& (sess.opts.unstable_opts.packed_bundled_libs || whole_archive == Some(true))
358+
{
359+
let name = lib.filename.unwrap();
360+
let path = find_native_static_library(name.as_str(), true, &lib_search_paths, sess);
361+
let src =
362+
read(path).map_err(|e| sess.emit_fatal(errors::ReadFileError { message: e }))?;
363+
let (data, _) = create_wrapper_file(sess, b".bundled_lib".to_vec(), &src);
364+
let wrapper_file = emit_wrapper_file(sess, &data, tmpdir, name.as_str());
365+
packed_bundled_libs.push(wrapper_file);
366+
} else if let Some(name) = lib.name {
367+
let path =
377368
find_native_static_library(name.as_str(), lib.verbatim, &lib_search_paths, sess);
378-
if sess.opts.unstable_opts.packed_bundled_libs && flavor == RlibFlavor::Normal {
379-
let filename = lib.filename.unwrap();
380-
let lib_path =
381-
find_native_static_library(filename.as_str(), true, &lib_search_paths, sess);
382-
let src = read(lib_path)
383-
.map_err(|e| sess.emit_fatal(errors::ReadFileError { message: e }))?;
384-
let (data, _) = create_wrapper_file(sess, b".bundled_lib".to_vec(), &src);
385-
let wrapper_file = emit_wrapper_file(sess, &data, tmpdir, filename.as_str());
386-
packed_bundled_libs.push(wrapper_file);
387-
continue;
388-
}
389-
ab.add_archive(&location, Box::new(|_| false)).unwrap_or_else(|error| {
390-
sess.emit_fatal(errors::AddNativeLibrary { library_path: location, error });
369+
ab.add_archive(&path, Box::new(|_| false)).unwrap_or_else(|error| {
370+
sess.emit_fatal(errors::AddNativeLibrary { library_path: path, error });
391371
});
392372
}
393373
}

src/test/ui/native-library-link-flags/mix-bundle-and-whole-archive-link-attr.rs

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/test/ui/native-library-link-flags/mix-bundle-and-whole-archive-link-attr.stderr

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/test/ui/native-library-link-flags/mix-bundle-and-whole-archive.rs

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/test/ui/native-library-link-flags/mix-bundle-and-whole-archive.stderr

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)