Skip to content

Commit 846c372

Browse files
wesleywisermichaelwoerister
authored andcommitted
Don't allow both the +bundle and +whole-archive modifiers for rlibs
1 parent 522f975 commit 846c372

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+14
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,19 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(
255255
// metadata of the rlib we're generating somehow.
256256
for lib in codegen_results.crate_info.used_libraries.iter() {
257257
match lib.kind {
258+
NativeLibKind::Static { bundle: None | Some(true), whole_archive: Some(true) }
259+
if flavor == RlibFlavor::Normal =>
260+
{
261+
// Don't allow mixing +bundle with +whole_archive since an rlib may contain
262+
// multiple native libs, some of which are +whole-archive and some of which are
263+
// -whole-archive and it isn't clear how we can currently handle such a
264+
// situation correctly.
265+
// See https://github.com/rust-lang/rust/issues/88085#issuecomment-901050897
266+
sess.err(
267+
"the linking modifiers `+bundle` and `+whole-archive` are not compatible \
268+
with each other when generating rlibs",
269+
);
270+
}
258271
NativeLibKind::Static { bundle: None | Some(true), .. } => {}
259272
NativeLibKind::Static { bundle: Some(false), .. }
260273
| NativeLibKind::Dylib { .. }
@@ -1223,6 +1236,7 @@ pub fn archive_search_paths(sess: &Session) -> Vec<PathBuf> {
12231236
sess.target_filesearch(PathKind::Native).search_path_dirs()
12241237
}
12251238

1239+
#[derive(PartialEq)]
12261240
enum RlibFlavor {
12271241
Normal,
12281242
StaticlibBase,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// compile-flags: -Zunstable-options --crate-type rlib
2+
// build-fail
3+
// error-pattern: the linking modifiers `+bundle` and `+whole-archive` are not compatible with each other when generating rlibs
4+
5+
#![feature(native_link_modifiers)]
6+
#![feature(native_link_modifiers_bundle)]
7+
#![feature(native_link_modifiers_whole_archive)]
8+
9+
#[link(name = "mylib", kind = "static", modifiers = "+bundle,+whole-archive")]
10+
extern "C" { }
11+
12+
fn main() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
error: the linking modifiers `+bundle` and `+whole-archive` are not compatible with each other when generating rlibs
2+
3+
error: could not find native static library `mylib`, perhaps an -L flag is missing?
4+
5+
error: aborting due to 2 previous errors
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Mixing +bundle and +whole-archive is not allowed
2+
3+
// compile-flags: -l static:+bundle,+whole-archive=mylib -Zunstable-options --crate-type rlib
4+
// build-fail
5+
// error-pattern: the linking modifiers `+bundle` and `+whole-archive` are not compatible with each other when generating rlibs
6+
7+
fn main() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
error: the linking modifiers `+bundle` and `+whole-archive` are not compatible with each other when generating rlibs
2+
3+
error: could not find native static library `mylib`, perhaps an -L flag is missing?
4+
5+
error: aborting due to 2 previous errors
6+

0 commit comments

Comments
 (0)