Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Native library linking changes for crater testing #102832

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
328 changes: 187 additions & 141 deletions compiler/rustc_codegen_ssa/src/back/link.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ fn test_unstable_options_tracking_hash() {
tracked!(no_profiler_runtime, true);
tracked!(oom, OomStrategy::Panic);
tracked!(osx_rpath_install_name, true);
tracked!(packed_bundled_libs, true);
tracked!(packed_bundled_libs, false);
tracked!(panic_abort_tests, true);
tracked!(panic_in_drop, PanicStrategy::Abort);
tracked!(pick_stable_methods_before_any_unstable, false);
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_metadata/src/native_libs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,14 @@ impl<'tcx> Collector<'tcx> {
lib.name = Some(Symbol::intern(new_name));
}
lib.verbatim = passed_lib.verbatim;
if lib.filename.is_none() {
lib.filename = find_bundled_library(
lib.name,
lib.verbatim,
lib.kind,
self.tcx.sess,
);
}
return true;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/test/run-make-fulldeps/invalid-staticlib/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Staticlib format is no longer checked during bundling

include ../tools.mk

all:
touch $(TMPDIR)/libfoo.a
echo | $(RUSTC) - --crate-type=rlib -lstatic=foo 2>&1 | $(CGREP) "failed to add native library"
$(RUSTC) lib.rs --crate-type=rlib -lstatic=foo
1 change: 1 addition & 0 deletions src/test/run-make-fulldeps/invalid-staticlib/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// intentionally empty
2 changes: 1 addition & 1 deletion src/test/run-make-fulldeps/link-dedup/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ all:
$(RUSTC) depa.rs
$(RUSTC) depb.rs
$(RUSTC) depc.rs
$(RUSTC) empty.rs --cfg bar 2>&1 | $(CGREP) '"-ltesta" "-ltestb" "-ltesta"'
$(RUSTC) empty.rs --cfg bar 2>&1 | $(CGREP) -e '"-ltesta".*"-ltestb".*"-ltesta"'
$(RUSTC) empty.rs 2>&1 | $(CGREP) '"-ltesta"'
$(RUSTC) empty.rs 2>&1 | $(CGREP) -v '"-ltestb"'
$(RUSTC) empty.rs 2>&1 | $(CGREP) -v '"-ltesta" "-ltesta"'
2 changes: 1 addition & 1 deletion src/test/run-make/native-link-modifier-bundle/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ all: $(call NATIVE_STATICLIB,native-staticlib)
$(RUSTC) bundled.rs --crate-type=staticlib --crate-type=rlib
$(NM) $(TMPDIR)/libbundled.a | $(CGREP) -e "T _*native_func"
$(NM) $(TMPDIR)/libbundled.a | $(CGREP) -e "U _*native_func"
$(NM) $(TMPDIR)/libbundled.rlib | $(CGREP) -e "T _*native_func"
$(NM) $(TMPDIR)/libbundled.rlib | $(CGREP) -ve "T _*native_func"
$(NM) $(TMPDIR)/libbundled.rlib | $(CGREP) -e "U _*native_func"

# Build a staticlib and a rlib, the `native_func` symbol will not be bundled into it
Expand Down
3 changes: 3 additions & 0 deletions src/test/ui/native-library-link-flags/auxiliary/mylib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// no-prefer-dynamic

#![crate_type = "staticlib"]
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// compile-flags: -Zunstable-options --crate-type rlib
// build-fail
// error-pattern: the linking modifiers `+bundle` and `+whole-archive` are not compatible with each other when generating rlibs
// Mixing +bundle and +whole-archive is now allowed

// build-pass
// compile-flags: --crate-type rlib
// aux-build:mylib.rs

#[link(name = "mylib", kind = "static", modifiers = "+bundle,+whole-archive")]
extern "C" { }
extern "C" {}

fn main() { }
fn main() {}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Mixing +bundle and +whole-archive is not allowed
// Mixing +bundle and +whole-archive is now allowed

// compile-flags: -l static:+bundle,+whole-archive=mylib -Zunstable-options --crate-type rlib
// build-fail
// error-pattern: the linking modifiers `+bundle` and `+whole-archive` are not compatible with each other when generating rlibs
// build-pass
// compile-flags: --crate-type rlib -l static:+bundle,+whole-archive=mylib
// aux-build:mylib.rs

fn main() { }
fn main() {}

This file was deleted.