Skip to content

Commit 602a8b4

Browse files
Rollup merge of rust-lang#55659 - alexcrichton:musl-no-group, r=michaelwoerister
rustc: Delete grouping logic from the musl target This commit deletes the injection of `-(` and `-)` options to the linker for the musl targets. This actually causes problems today on nightly if you execute: $ echo 'fn main() {}' >> foo.rs $ rustc --target x86_64-unknown-linux-musl -C panic=abort you get a linker error about "cannot nest groups". This comes about because rustc injects its own `--start-group` and `--end-group` variables which clash with the outer `-(` and `-)` variables. It's not entirely clear to me why this doesn't affect the musl target by default (in `-C panic=unwind` mode). The compiler's own injection of `--start-group` and `--end-group` should solve the issues mentioned in the comment for injecting `-(` and `-)` as well.
2 parents 4805a97 + f3428a7 commit 602a8b4

File tree

1 file changed

+0
-25
lines changed

1 file changed

+0
-25
lines changed

src/librustc_target/spec/linux_musl_base.rs

-25
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,6 @@ pub fn opts() -> TargetOptions {
2424
// argument is *not* necessary for normal builds, but it can't hurt!
2525
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-Wl,--eh-frame-hdr".to_string());
2626

27-
// There's a whole bunch of circular dependencies when dealing with MUSL
28-
// unfortunately. To put this in perspective libc is statically linked to
29-
// liblibc and libunwind is statically linked to libstd:
30-
//
31-
// * libcore depends on `fmod` which is in libc (transitively in liblibc).
32-
// liblibc, however, depends on libcore.
33-
// * compiler-rt has personality symbols that depend on libunwind, but
34-
// libunwind is in libstd which depends on compiler-rt.
35-
//
36-
// Recall that linkers discard libraries and object files as much as
37-
// possible, and with all the static linking and archives flying around with
38-
// MUSL the linker is super aggressively stripping out objects. For example
39-
// the first case has fmod stripped from liblibc (it's in its own object
40-
// file) so it's not there when libcore needs it. In the second example all
41-
// the unused symbols from libunwind are stripped (each is in its own object
42-
// file in libstd) before we end up linking compiler-rt which depends on
43-
// those symbols.
44-
//
45-
// To deal with these circular dependencies we just force the compiler to
46-
// link everything as a group, not stripping anything out until everything
47-
// is processed. The linker will still perform a pass to strip out object
48-
// files but it won't do so until all objects/archives have been processed.
49-
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-Wl,-(".to_string());
50-
base.post_link_args.insert(LinkerFlavor::Gcc, vec!["-Wl,-)".to_string()]);
51-
5227
// When generating a statically linked executable there's generally some
5328
// small setup needed which is listed in these files. These are provided by
5429
// a musl toolchain and are linked by default by the `musl-gcc` script. Note

0 commit comments

Comments
 (0)