From 6204f6512a31cae3db320cfa459f4ec96b0bfcd7 Mon Sep 17 00:00:00 2001 From: Bryanskiy Date: Tue, 26 Jul 2022 15:54:47 +0300 Subject: [PATCH 01/13] add -Z split_bundled_libs --- compiler/rustc_codegen_ssa/src/back/link.rs | 105 ++++++++++++++------ compiler/rustc_session/src/options.rs | 2 + 2 files changed, 78 insertions(+), 29 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 878a670cba3ef..3d61d7644812a 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -317,37 +317,66 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>( // loaded from the libraries found here and then encode that into the // metadata of the rlib we're generating somehow. for lib in codegen_results.crate_info.used_libraries.iter() { - match lib.kind { - NativeLibKind::Static { bundle: None | Some(true), whole_archive: Some(true) } - if flavor == RlibFlavor::Normal => - { - // Don't allow mixing +bundle with +whole_archive since an rlib may contain - // multiple native libs, some of which are +whole-archive and some of which are - // -whole-archive and it isn't clear how we can currently handle such a - // situation correctly. - // See https://github.com/rust-lang/rust/issues/88085#issuecomment-901050897 - sess.err( - "the linking modifiers `+bundle` and `+whole-archive` are not compatible \ + if !sess.opts.unstable_opts.split_bundled_libs { + match lib.kind { + NativeLibKind::Static { bundle: None | Some(true), whole_archive: Some(true) } + if flavor == RlibFlavor::Normal => + { + // Don't allow mixing +bundle with +whole_archive since an rlib may contain + // multiple native libs, some of which are +whole-archive and some of which are + // -whole-archive and it isn't clear how we can currently handle such a + // situation correctly. + // See https://github.com/rust-lang/rust/issues/88085#issuecomment-901050897 + sess.err( + "the linking modifiers `+bundle` and `+whole-archive` are not compatible \ with each other when generating rlibs", + ); + } + NativeLibKind::Static { bundle: None | Some(true), .. } => {} + NativeLibKind::Static { bundle: Some(false), .. } + | NativeLibKind::Dylib { .. } + | NativeLibKind::Framework { .. } + | NativeLibKind::RawDylib + | NativeLibKind::Unspecified => continue, + } + if let Some(name) = lib.name { + let location = find_library( + name.as_str(), + lib.verbatim.unwrap_or(false), + &lib_search_paths, + sess, ); + ab.add_archive(&location, |_| false).unwrap_or_else(|e| { + sess.fatal(&format!( + "failed to add native library {}: {}", + location.to_string_lossy(), + e + )); + }); + } + } else { + match lib.kind { + NativeLibKind::Static { bundle: None | Some(true), .. } + if flavor == RlibFlavor::Normal => + { + let Some(name) = lib.name else { + continue; + }; + + let location = find_library( + name.as_str(), + lib.verbatim.unwrap_or(false), + &lib_search_paths, + sess, + ); + + let suffix = &sess.target.staticlib_suffix; + let crate_name = out_filename.to_str().unwrap(); + let bundle_lib = PathBuf::from(&format!("{crate_name}.bundle.{name}{suffix}")); + fs::copy(location, bundle_lib).unwrap(); + } + _ => {} } - NativeLibKind::Static { bundle: None | Some(true), .. } => {} - NativeLibKind::Static { bundle: Some(false), .. } - | NativeLibKind::Dylib { .. } - | NativeLibKind::Framework { .. } - | NativeLibKind::RawDylib - | NativeLibKind::Unspecified => continue, - } - if let Some(name) = lib.name { - let location = - find_library(name.as_str(), lib.verbatim.unwrap_or(false), &lib_search_paths, sess); - ab.add_archive(&location, |_| false).unwrap_or_else(|e| { - sess.fatal(&format!( - "failed to add native library {}: {}", - location.to_string_lossy(), - e - )); - }); } } @@ -2362,7 +2391,24 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>( (lib.name, lib.kind, lib.verbatim) }; - if let NativeLibKind::Static { bundle: Some(false), whole_archive } = + if sess.opts.unstable_opts.split_bundled_libs { + if let NativeLibKind::Static { + bundle: Some(true) | None, + whole_archive, + } = lib.kind + { + let suffix = &sess.target.staticlib_suffix; + let crate_path = src.paths().next().unwrap().to_str().unwrap(); + let bundle_lib = + PathBuf::from(&format!("{crate_path}.bundle.{name}{suffix}")); + if whole_archive == Some(true) { + cmd.link_whole_rlib(&bundle_lib); + } else { + cmd.link_rlib(&bundle_lib); + } + } + } else { + if let NativeLibKind::Static { bundle: Some(false), whole_archive } = lib.kind { let verbatim = lib.verbatim.unwrap_or(false); @@ -2376,6 +2422,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>( cmd.link_staticlib(name, verbatim); } } + } } } } diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 01ff9e254f792..2a6ba14095fb1 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1512,6 +1512,8 @@ options! { file which is ignored by the linker `single`: sections which do not require relocation are written into object file but ignored by the linker"), + split_bundled_libs: bool = (false, parse_bool, [TRACKED], + "split bundled libs"), split_dwarf_inlining: bool = (true, parse_bool, [TRACKED], "provide minimal debug info in the object/executable to facilitate online \ symbolication/stack traces in the absence of .dwo/.dwp files when using Split DWARF"), From 33983060510b118b1ea9175019823b7512c4eb85 Mon Sep 17 00:00:00 2001 From: Bryanskiy Date: Tue, 26 Jul 2022 22:03:27 +0300 Subject: [PATCH 02/13] fix staticlib bundling --- compiler/rustc_codegen_ssa/src/back/link.rs | 100 ++++++++------------ 1 file changed, 42 insertions(+), 58 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 3d61d7644812a..a5e56d3c66480 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -317,35 +317,41 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>( // loaded from the libraries found here and then encode that into the // metadata of the rlib we're generating somehow. for lib in codegen_results.crate_info.used_libraries.iter() { - if !sess.opts.unstable_opts.split_bundled_libs { - match lib.kind { - NativeLibKind::Static { bundle: None | Some(true), whole_archive: Some(true) } - if flavor == RlibFlavor::Normal => - { - // Don't allow mixing +bundle with +whole_archive since an rlib may contain - // multiple native libs, some of which are +whole-archive and some of which are - // -whole-archive and it isn't clear how we can currently handle such a - // situation correctly. - // See https://github.com/rust-lang/rust/issues/88085#issuecomment-901050897 - sess.err( - "the linking modifiers `+bundle` and `+whole-archive` are not compatible \ - with each other when generating rlibs", - ); - } - NativeLibKind::Static { bundle: None | Some(true), .. } => {} - NativeLibKind::Static { bundle: Some(false), .. } - | NativeLibKind::Dylib { .. } - | NativeLibKind::Framework { .. } - | NativeLibKind::RawDylib - | NativeLibKind::Unspecified => continue, - } - if let Some(name) = lib.name { + match lib.kind { + NativeLibKind::Static { bundle: None | Some(true), whole_archive } => { + let Some(name) = lib.name else { + continue; + }; + let location = find_library( name.as_str(), lib.verbatim.unwrap_or(false), &lib_search_paths, sess, ); + if flavor == RlibFlavor::Normal { + if whole_archive == Some(true) && !sess.opts.unstable_opts.split_bundled_libs { + // Don't allow mixing +bundle with +whole_archive since an rlib may contain + // multiple native libs, some of which are +whole-archive and some of which are + // -whole-archive and it isn't clear how we can currently handle such a + // situation correctly. + // See https://github.com/rust-lang/rust/issues/88085#issuecomment-901050897 + sess.err( + "the linking modifiers `+bundle` and `+whole-archive` are not compatible \ + with each other when generating rlibs", + ); + } + + if sess.opts.unstable_opts.split_bundled_libs { + let suffix = &sess.target.staticlib_suffix; + let crate_name = out_filename.to_str().unwrap(); + let bundle_lib = + PathBuf::from(&format!("{crate_name}.bundle.{name}{suffix}")); + fs::copy(location, bundle_lib).unwrap(); + continue; + } + } + ab.add_archive(&location, |_| false).unwrap_or_else(|e| { sess.fatal(&format!( "failed to add native library {}: {}", @@ -354,29 +360,7 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>( )); }); } - } else { - match lib.kind { - NativeLibKind::Static { bundle: None | Some(true), .. } - if flavor == RlibFlavor::Normal => - { - let Some(name) = lib.name else { - continue; - }; - - let location = find_library( - name.as_str(), - lib.verbatim.unwrap_or(false), - &lib_search_paths, - sess, - ); - - let suffix = &sess.target.staticlib_suffix; - let crate_name = out_filename.to_str().unwrap(); - let bundle_lib = PathBuf::from(&format!("{crate_name}.bundle.{name}{suffix}")); - fs::copy(location, bundle_lib).unwrap(); - } - _ => {} - } + _ => {} } } @@ -2409,20 +2393,20 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>( } } else { if let NativeLibKind::Static { bundle: Some(false), whole_archive } = - lib.kind - { - let verbatim = lib.verbatim.unwrap_or(false); - if whole_archive == Some(true) { - cmd.link_whole_staticlib( - name, - verbatim, - search_path.get_or_init(|| archive_search_paths(sess)), - ); - } else { - cmd.link_staticlib(name, verbatim); + lib.kind + { + let verbatim = lib.verbatim.unwrap_or(false); + if whole_archive == Some(true) { + cmd.link_whole_staticlib( + name, + verbatim, + search_path.get_or_init(|| archive_search_paths(sess)), + ); + } else { + cmd.link_staticlib(name, verbatim); + } } } - } } } } From 7fc1864e8ed3b1ba3d3280a044a530d3e0e956f0 Mon Sep 17 00:00:00 2001 From: Bryanskiy Date: Tue, 26 Jul 2022 23:37:23 +0300 Subject: [PATCH 03/13] fix error message --- compiler/rustc_codegen_ssa/src/back/link.rs | 41 +++++++++++---------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index a5e56d3c66480..c767634f11eef 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -319,6 +319,21 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>( for lib in codegen_results.crate_info.used_libraries.iter() { match lib.kind { NativeLibKind::Static { bundle: None | Some(true), whole_archive } => { + if flavor == RlibFlavor::Normal + && whole_archive == Some(true) + && !sess.opts.unstable_opts.split_bundled_libs + { + // Don't allow mixing +bundle with +whole_archive since an rlib may contain + // multiple native libs, some of which are +whole-archive and some of which are + // -whole-archive and it isn't clear how we can currently handle such a + // situation correctly. + // See https://github.com/rust-lang/rust/issues/88085#issuecomment-901050897 + sess.err( + "the linking modifiers `+bundle` and `+whole-archive` are not compatible \ + with each other when generating rlibs", + ); + } + let Some(name) = lib.name else { continue; }; @@ -329,27 +344,13 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>( &lib_search_paths, sess, ); - if flavor == RlibFlavor::Normal { - if whole_archive == Some(true) && !sess.opts.unstable_opts.split_bundled_libs { - // Don't allow mixing +bundle with +whole_archive since an rlib may contain - // multiple native libs, some of which are +whole-archive and some of which are - // -whole-archive and it isn't clear how we can currently handle such a - // situation correctly. - // See https://github.com/rust-lang/rust/issues/88085#issuecomment-901050897 - sess.err( - "the linking modifiers `+bundle` and `+whole-archive` are not compatible \ - with each other when generating rlibs", - ); - } - if sess.opts.unstable_opts.split_bundled_libs { - let suffix = &sess.target.staticlib_suffix; - let crate_name = out_filename.to_str().unwrap(); - let bundle_lib = - PathBuf::from(&format!("{crate_name}.bundle.{name}{suffix}")); - fs::copy(location, bundle_lib).unwrap(); - continue; - } + if (flavor == RlibFlavor::Normal) && sess.opts.unstable_opts.split_bundled_libs { + let suffix = &sess.target.staticlib_suffix; + let crate_name = out_filename.to_str().unwrap(); + let bundle_lib = PathBuf::from(&format!("{crate_name}.bundle.{name}{suffix}")); + fs::copy(location, bundle_lib).unwrap(); + continue; } ab.add_archive(&location, |_| false).unwrap_or_else(|e| { From 42a200d66c02f00fd890f09586bc91b4685dc901 Mon Sep 17 00:00:00 2001 From: Bryanskiy Date: Wed, 27 Jul 2022 12:42:08 +0300 Subject: [PATCH 04/13] fix rustdoc-ui test --- compiler/rustc_session/src/options.rs | 4 ++-- src/test/rustdoc-ui/z-help.stdout | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 2a6ba14095fb1..9bd48f475529a 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1504,6 +1504,8 @@ options! { "control if mem::uninitialized and mem::zeroed panic on more UB"), strip: Strip = (Strip::None, parse_strip, [UNTRACKED], "tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`)"), + split_bundled_libs: bool = (false, parse_bool, [TRACKED], + "if libfoo.rlib is the rlib, then libfoo.rlib.bundle.* are the corresponding bundled static libraries"), split_dwarf_kind: SplitDwarfKind = (SplitDwarfKind::Split, parse_split_dwarf_kind, [TRACKED], "split dwarf variant (only if -Csplit-debuginfo is enabled and on relevant platform) (default: `split`) @@ -1512,8 +1514,6 @@ options! { file which is ignored by the linker `single`: sections which do not require relocation are written into object file but ignored by the linker"), - split_bundled_libs: bool = (false, parse_bool, [TRACKED], - "split bundled libs"), split_dwarf_inlining: bool = (true, parse_bool, [TRACKED], "provide minimal debug info in the object/executable to facilitate online \ symbolication/stack traces in the absence of .dwo/.dwp files when using Split DWARF"), diff --git a/src/test/rustdoc-ui/z-help.stdout b/src/test/rustdoc-ui/z-help.stdout index 7296b35788a9d..eee47ecefb82e 100644 --- a/src/test/rustdoc-ui/z-help.stdout +++ b/src/test/rustdoc-ui/z-help.stdout @@ -145,6 +145,7 @@ -Z stack-protector=val -- control stack smash protection strategy (`rustc --print stack-protector-strategies` for details) -Z strict-init-checks=val -- control if mem::uninitialized and mem::zeroed panic on more UB -Z strip=val -- tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`) + -Z split-bundled-libs=val -- if libfoo.rlib is the rlib, then libfoo.rlib.bundle.* are the corresponding bundled static libraries -Z split-dwarf-kind=val -- split dwarf variant (only if -Csplit-debuginfo is enabled and on relevant platform) (default: `split`) From f7660775732578cc131b1c08b0a7dd2253910524 Mon Sep 17 00:00:00 2001 From: Bryanskiy Date: Wed, 27 Jul 2022 15:39:30 +0300 Subject: [PATCH 05/13] add test + small fix --- compiler/rustc_codegen_ssa/src/back/link.rs | 30 ++++++++-------- .../Makefile | 35 +++++++++++++++++++ .../bundled.rs | 11 ++++++ .../cdylib-bundled.rs | 1 + .../cdylib-non-bundled.rs | 1 + .../native-staticlib.c | 1 + .../non-bundled.rs | 11 ++++++ 7 files changed, 76 insertions(+), 14 deletions(-) create mode 100644 src/test/run-make/native-link-modifier-bundle-split/Makefile create mode 100644 src/test/run-make/native-link-modifier-bundle-split/bundled.rs create mode 100644 src/test/run-make/native-link-modifier-bundle-split/cdylib-bundled.rs create mode 100644 src/test/run-make/native-link-modifier-bundle-split/cdylib-non-bundled.rs create mode 100644 src/test/run-make/native-link-modifier-bundle-split/native-staticlib.c create mode 100644 src/test/run-make/native-link-modifier-bundle-split/non-bundled.rs diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index c767634f11eef..0a08200e7162d 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -2391,21 +2391,23 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>( } else { cmd.link_rlib(&bundle_lib); } + + continue; } - } else { - if let NativeLibKind::Static { bundle: Some(false), whole_archive } = - lib.kind - { - let verbatim = lib.verbatim.unwrap_or(false); - if whole_archive == Some(true) { - cmd.link_whole_staticlib( - name, - verbatim, - search_path.get_or_init(|| archive_search_paths(sess)), - ); - } else { - cmd.link_staticlib(name, verbatim); - } + } + + if let NativeLibKind::Static { bundle: Some(false), whole_archive } = + lib.kind + { + let verbatim = lib.verbatim.unwrap_or(false); + if whole_archive == Some(true) { + cmd.link_whole_staticlib( + name, + verbatim, + search_path.get_or_init(|| archive_search_paths(sess)), + ); + } else { + cmd.link_staticlib(name, verbatim); } } } diff --git a/src/test/run-make/native-link-modifier-bundle-split/Makefile b/src/test/run-make/native-link-modifier-bundle-split/Makefile new file mode 100644 index 0000000000000..3660f487d0dfd --- /dev/null +++ b/src/test/run-make/native-link-modifier-bundle-split/Makefile @@ -0,0 +1,35 @@ +# ignore-cross-compile +# ignore-windows-msvc + +-include ../../run-make-fulldeps/tools.mk + +# We're using the llvm-nm instead of the system nm to ensure it is compatible +# with the LLVM bitcode generated by rustc. +NM = "$(LLVM_BIN_DIR)"/llvm-nm +SPLIT = "-Zsplit-bundled-libs" +BUNDLED_LIB = "libbundled.rlib.bundle.native-staticlib.a" + +all: $(call NATIVE_STATICLIB,native-staticlib) + # Build a staticlib and a rlib, the `native_func` symbol will be bundled only into staticlib + $(RUSTC) bundled.rs --crate-type=staticlib --crate-type=rlib $(SPLIT) + $(NM) $(TMPDIR)/libbundled.a | $(CGREP) -e "T _*native_func" + $(NM) $(TMPDIR)/libbundled.a | $(CGREP) -e "U _*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 + $(RUSTC) non-bundled.rs --crate-type=staticlib --crate-type=rlib $(SPLIT) + $(NM) $(TMPDIR)/libnon_bundled.a | $(CGREP) -ve "T _*native_func" + $(NM) $(TMPDIR)/libnon_bundled.a | $(CGREP) -e "U _*native_func" + $(NM) $(TMPDIR)/libnon_bundled.rlib | $(CGREP) -ve "T _*native_func" + $(NM) $(TMPDIR)/libnon_bundled.rlib | $(CGREP) -e "U _*native_func" + + # Build a cdylib, 'BUNDLED_LIB' will appear on the linker line + # The cdylib will contain the `native_func` symbol in the end + $(RUSTC) cdylib-bundled.rs --crate-type=cdylib --print link-args $(SPLIT) | $(CGREP) -e $(BUNDLED_LIB) + $(NM) $(call DYLIB,cdylib_bundled) | $(CGREP) -e "[Tt] _*native_func" + + # Build a cdylib, `native-staticlib` will appear on the linker line because it was not bundled previously + # The cdylib will contain the `native_func` symbol in the end + $(RUSTC) cdylib-non-bundled.rs --crate-type=cdylib --print link-args $(SPLIT) > $(TMPDIR)/tmp + $(NM) $(call DYLIB,cdylib_non_bundled) | $(CGREP) -e "[Tt] _*native_func" diff --git a/src/test/run-make/native-link-modifier-bundle-split/bundled.rs b/src/test/run-make/native-link-modifier-bundle-split/bundled.rs new file mode 100644 index 0000000000000..0bbae8752d7b3 --- /dev/null +++ b/src/test/run-make/native-link-modifier-bundle-split/bundled.rs @@ -0,0 +1,11 @@ +#[link(name = "native-staticlib", kind = "static", modifiers = "+bundle")] +extern "C" { + pub fn native_func(); +} + +#[no_mangle] +pub extern "C" fn wrapped_func() { + unsafe { + native_func(); + } +} diff --git a/src/test/run-make/native-link-modifier-bundle-split/cdylib-bundled.rs b/src/test/run-make/native-link-modifier-bundle-split/cdylib-bundled.rs new file mode 100644 index 0000000000000..7291309168a48 --- /dev/null +++ b/src/test/run-make/native-link-modifier-bundle-split/cdylib-bundled.rs @@ -0,0 +1 @@ +extern crate bundled; diff --git a/src/test/run-make/native-link-modifier-bundle-split/cdylib-non-bundled.rs b/src/test/run-make/native-link-modifier-bundle-split/cdylib-non-bundled.rs new file mode 100644 index 0000000000000..1df81fd101f75 --- /dev/null +++ b/src/test/run-make/native-link-modifier-bundle-split/cdylib-non-bundled.rs @@ -0,0 +1 @@ +extern crate non_bundled; diff --git a/src/test/run-make/native-link-modifier-bundle-split/native-staticlib.c b/src/test/run-make/native-link-modifier-bundle-split/native-staticlib.c new file mode 100644 index 0000000000000..d300fdf1c1742 --- /dev/null +++ b/src/test/run-make/native-link-modifier-bundle-split/native-staticlib.c @@ -0,0 +1 @@ +void native_func() {} diff --git a/src/test/run-make/native-link-modifier-bundle-split/non-bundled.rs b/src/test/run-make/native-link-modifier-bundle-split/non-bundled.rs new file mode 100644 index 0000000000000..8181e6387c5c7 --- /dev/null +++ b/src/test/run-make/native-link-modifier-bundle-split/non-bundled.rs @@ -0,0 +1,11 @@ +#[link(name = "native-staticlib", kind = "static", modifiers = "-bundle")] +extern "C" { + pub fn native_func(); +} + +#[no_mangle] +pub extern "C" fn wrapped_func() { + unsafe { + native_func(); + } +} From 70fa93d95e26d2c9772236f8768606d499842901 Mon Sep 17 00:00:00 2001 From: Bryanskiy Date: Wed, 27 Jul 2022 15:41:30 +0300 Subject: [PATCH 06/13] test cleaunup --- src/test/run-make/native-link-modifier-bundle-split/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/run-make/native-link-modifier-bundle-split/Makefile b/src/test/run-make/native-link-modifier-bundle-split/Makefile index 3660f487d0dfd..16c216afdb228 100644 --- a/src/test/run-make/native-link-modifier-bundle-split/Makefile +++ b/src/test/run-make/native-link-modifier-bundle-split/Makefile @@ -31,5 +31,5 @@ all: $(call NATIVE_STATICLIB,native-staticlib) # Build a cdylib, `native-staticlib` will appear on the linker line because it was not bundled previously # The cdylib will contain the `native_func` symbol in the end - $(RUSTC) cdylib-non-bundled.rs --crate-type=cdylib --print link-args $(SPLIT) > $(TMPDIR)/tmp + $(RUSTC) cdylib-non-bundled.rs --crate-type=cdylib --print link-args | $(CGREP) -e '-l[" ]*native-staticlib' $(NM) $(call DYLIB,cdylib_non_bundled) | $(CGREP) -e "[Tt] _*native_func" From 604e4b0d477d1a3b8a9511d15a43f0ca2ec86a68 Mon Sep 17 00:00:00 2001 From: Bryanskiy Date: Wed, 27 Jul 2022 16:57:36 +0300 Subject: [PATCH 07/13] fix test --- src/test/run-make/native-link-modifier-bundle-split/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/run-make/native-link-modifier-bundle-split/Makefile b/src/test/run-make/native-link-modifier-bundle-split/Makefile index 16c216afdb228..09734951a1508 100644 --- a/src/test/run-make/native-link-modifier-bundle-split/Makefile +++ b/src/test/run-make/native-link-modifier-bundle-split/Makefile @@ -31,5 +31,5 @@ all: $(call NATIVE_STATICLIB,native-staticlib) # Build a cdylib, `native-staticlib` will appear on the linker line because it was not bundled previously # The cdylib will contain the `native_func` symbol in the end - $(RUSTC) cdylib-non-bundled.rs --crate-type=cdylib --print link-args | $(CGREP) -e '-l[" ]*native-staticlib' + $(RUSTC) cdylib-non-bundled.rs --crate-type=cdylib --print link-args $(SPLIT) | $(CGREP) -e '-l[" ]*native-staticlib' $(NM) $(call DYLIB,cdylib_non_bundled) | $(CGREP) -e "[Tt] _*native_func" From 9702309346bf9fcc5a8e291d40ba35fc01a7184f Mon Sep 17 00:00:00 2001 From: Bryanskiy Date: Thu, 28 Jul 2022 14:23:16 +0300 Subject: [PATCH 08/13] code cleanup --- compiler/rustc_codegen_ssa/src/back/link.rs | 86 +++++++++++---------- compiler/rustc_session/src/options.rs | 16 ++-- 2 files changed, 53 insertions(+), 49 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 0a08200e7162d..021590db9e627 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -335,8 +335,8 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>( } let Some(name) = lib.name else { - continue; - }; + continue; + }; let location = find_library( name.as_str(), @@ -345,23 +345,28 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>( sess, ); - if (flavor == RlibFlavor::Normal) && sess.opts.unstable_opts.split_bundled_libs { + if flavor == RlibFlavor::Normal && sess.opts.unstable_opts.split_bundled_libs { let suffix = &sess.target.staticlib_suffix; - let crate_name = out_filename.to_str().unwrap(); - let bundle_lib = PathBuf::from(&format!("{crate_name}.bundle.{name}{suffix}")); - fs::copy(location, bundle_lib).unwrap(); - continue; + let bundle_lib = PathBuf::from(format!("{}.bundle.{name}{suffix}", out_filename.display())); + match fs::copy(location, bundle_lib) { + Ok(_) => {}, + Err(_) => sess.fatal("unable to create file for bundle lib"), + } + } else { + ab.add_archive(&location, |_| false).unwrap_or_else(|e| { + sess.fatal(&format!( + "failed to add native library {}: {}", + location.to_string_lossy(), + e + )); + }); } - - ab.add_archive(&location, |_| false).unwrap_or_else(|e| { - sess.fatal(&format!( - "failed to add native library {}: {}", - location.to_string_lossy(), - e - )); - }); } - _ => {} + NativeLibKind::Static { bundle: Some(false), .. } + | NativeLibKind::Dylib { .. } + | NativeLibKind::Framework { .. } + | NativeLibKind::RawDylib + | NativeLibKind::Unspecified => continue, } } @@ -2376,40 +2381,39 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>( (lib.name, lib.kind, lib.verbatim) }; - if sess.opts.unstable_opts.split_bundled_libs { - if let NativeLibKind::Static { - bundle: Some(true) | None, - whole_archive, - } = lib.kind + match lib.kind { + NativeLibKind::Static { bundle: None | Some(true), whole_archive } + if sess.opts.unstable_opts.split_bundled_libs => { let suffix = &sess.target.staticlib_suffix; - let crate_path = src.paths().next().unwrap().to_str().unwrap(); + let cratepath = &src.rlib.as_ref().unwrap().0; let bundle_lib = - PathBuf::from(&format!("{crate_path}.bundle.{name}{suffix}")); + PathBuf::from(format!("{}.bundle.{name}{suffix}", cratepath.display())); if whole_archive == Some(true) { - cmd.link_whole_rlib(&bundle_lib); + cmd.link_whole_rlib(&fix_windows_verbatim_for_gcc(&bundle_lib)); } else { - cmd.link_rlib(&bundle_lib); + cmd.link_rlib(&fix_windows_verbatim_for_gcc(&bundle_lib)); } - - continue; } - } - if let NativeLibKind::Static { bundle: Some(false), whole_archive } = - lib.kind - { - let verbatim = lib.verbatim.unwrap_or(false); - if whole_archive == Some(true) { - cmd.link_whole_staticlib( - name, - verbatim, - search_path.get_or_init(|| archive_search_paths(sess)), - ); - } else { - cmd.link_staticlib(name, verbatim); + NativeLibKind::Static { bundle: Some(false), whole_archive } => { + let verbatim = lib.verbatim.unwrap_or(false); + if whole_archive == Some(true) { + cmd.link_whole_staticlib( + name, + verbatim, + search_path.get_or_init(|| archive_search_paths(sess)), + ); + } else { + cmd.link_staticlib(name, verbatim); + } } - } + NativeLibKind::Static { bundle: None | Some(true), .. } + | NativeLibKind::Dylib { .. } + | NativeLibKind::Framework { .. } + | NativeLibKind::RawDylib + | NativeLibKind::Unspecified => {} + }; } } } diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 9bd48f475529a..3857740ad4abf 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1496,14 +1496,6 @@ options! { /// o/w tests have closure@path span_free_formats: bool = (false, parse_bool, [UNTRACKED], "exclude spans when debug-printing compiler state (default: no)"), - src_hash_algorithm: Option = (None, parse_src_file_hash, [TRACKED], - "hash algorithm of source files in debug info (`md5`, `sha1`, or `sha256`)"), - stack_protector: StackProtector = (StackProtector::None, parse_stack_protector, [TRACKED], - "control stack smash protection strategy (`rustc --print stack-protector-strategies` for details)"), - strict_init_checks: bool = (false, parse_bool, [TRACKED], - "control if mem::uninitialized and mem::zeroed panic on more UB"), - strip: Strip = (Strip::None, parse_strip, [UNTRACKED], - "tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`)"), split_bundled_libs: bool = (false, parse_bool, [TRACKED], "if libfoo.rlib is the rlib, then libfoo.rlib.bundle.* are the corresponding bundled static libraries"), split_dwarf_kind: SplitDwarfKind = (SplitDwarfKind::Split, parse_split_dwarf_kind, [TRACKED], @@ -1517,6 +1509,14 @@ options! { split_dwarf_inlining: bool = (true, parse_bool, [TRACKED], "provide minimal debug info in the object/executable to facilitate online \ symbolication/stack traces in the absence of .dwo/.dwp files when using Split DWARF"), + src_hash_algorithm: Option = (None, parse_src_file_hash, [TRACKED], + "hash algorithm of source files in debug info (`md5`, `sha1`, or `sha256`)"), + stack_protector: StackProtector = (StackProtector::None, parse_stack_protector, [TRACKED], + "control stack smash protection strategy (`rustc --print stack-protector-strategies` for details)"), + strict_init_checks: bool = (false, parse_bool, [TRACKED], + "control if mem::uninitialized and mem::zeroed panic on more UB"), + strip: Strip = (Strip::None, parse_strip, [UNTRACKED], + "tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`)"), symbol_mangling_version: Option = (None, parse_symbol_mangling_version, [TRACKED], "which mangling version to use for symbol names ('legacy' (default) or 'v0')"), From 7ffd8d3fab21f6fd9b2ae7e01f71b440c6c64f9a Mon Sep 17 00:00:00 2001 From: Bryanskiy Date: Thu, 28 Jul 2022 16:17:24 +0300 Subject: [PATCH 09/13] merge tests + cleanup --- compiler/rustc_codegen_ssa/src/back/link.rs | 16 ++++---- .../Makefile | 35 ------------------ .../bundled.rs | 11 ------ .../cdylib-bundled.rs | 1 - .../cdylib-non-bundled.rs | 1 - .../native-staticlib.c | 1 - .../non-bundled.rs | 11 ------ .../native-link-modifier-bundle/Makefile | 15 ++++++++ .../libbundled-split | Bin 0 -> 6686 bytes ...libbundled-split.bundle.native-staticlib.a | Bin 0 -> 1552 bytes 10 files changed, 24 insertions(+), 67 deletions(-) delete mode 100644 src/test/run-make/native-link-modifier-bundle-split/Makefile delete mode 100644 src/test/run-make/native-link-modifier-bundle-split/bundled.rs delete mode 100644 src/test/run-make/native-link-modifier-bundle-split/cdylib-bundled.rs delete mode 100644 src/test/run-make/native-link-modifier-bundle-split/cdylib-non-bundled.rs delete mode 100644 src/test/run-make/native-link-modifier-bundle-split/native-staticlib.c delete mode 100644 src/test/run-make/native-link-modifier-bundle-split/non-bundled.rs create mode 100644 src/test/run-make/native-link-modifier-bundle/libbundled-split create mode 100644 src/test/run-make/native-link-modifier-bundle/libbundled-split.bundle.native-staticlib.a diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 021590db9e627..5da6e741ac001 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -347,11 +347,11 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>( if flavor == RlibFlavor::Normal && sess.opts.unstable_opts.split_bundled_libs { let suffix = &sess.target.staticlib_suffix; - let bundle_lib = PathBuf::from(format!("{}.bundle.{name}{suffix}", out_filename.display())); - match fs::copy(location, bundle_lib) { - Ok(_) => {}, - Err(_) => sess.fatal("unable to create file for bundle lib"), - } + let bundle_lib = + PathBuf::from(format!("{}.bundle.{name}{suffix}", out_filename.display())); + fs::copy(location, bundle_lib).unwrap_or_else(|e| { + sess.fatal(format!("Unable to create bundle lib: {}", e)); + }); } else { ab.add_archive(&location, |_| false).unwrap_or_else(|e| { sess.fatal(&format!( @@ -2387,8 +2387,10 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>( { let suffix = &sess.target.staticlib_suffix; let cratepath = &src.rlib.as_ref().unwrap().0; - let bundle_lib = - PathBuf::from(format!("{}.bundle.{name}{suffix}", cratepath.display())); + let bundle_lib = PathBuf::from(format!( + "{}.bundle.{name}{suffix}", + cratepath.display() + )); if whole_archive == Some(true) { cmd.link_whole_rlib(&fix_windows_verbatim_for_gcc(&bundle_lib)); } else { diff --git a/src/test/run-make/native-link-modifier-bundle-split/Makefile b/src/test/run-make/native-link-modifier-bundle-split/Makefile deleted file mode 100644 index 09734951a1508..0000000000000 --- a/src/test/run-make/native-link-modifier-bundle-split/Makefile +++ /dev/null @@ -1,35 +0,0 @@ -# ignore-cross-compile -# ignore-windows-msvc - --include ../../run-make-fulldeps/tools.mk - -# We're using the llvm-nm instead of the system nm to ensure it is compatible -# with the LLVM bitcode generated by rustc. -NM = "$(LLVM_BIN_DIR)"/llvm-nm -SPLIT = "-Zsplit-bundled-libs" -BUNDLED_LIB = "libbundled.rlib.bundle.native-staticlib.a" - -all: $(call NATIVE_STATICLIB,native-staticlib) - # Build a staticlib and a rlib, the `native_func` symbol will be bundled only into staticlib - $(RUSTC) bundled.rs --crate-type=staticlib --crate-type=rlib $(SPLIT) - $(NM) $(TMPDIR)/libbundled.a | $(CGREP) -e "T _*native_func" - $(NM) $(TMPDIR)/libbundled.a | $(CGREP) -e "U _*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 - $(RUSTC) non-bundled.rs --crate-type=staticlib --crate-type=rlib $(SPLIT) - $(NM) $(TMPDIR)/libnon_bundled.a | $(CGREP) -ve "T _*native_func" - $(NM) $(TMPDIR)/libnon_bundled.a | $(CGREP) -e "U _*native_func" - $(NM) $(TMPDIR)/libnon_bundled.rlib | $(CGREP) -ve "T _*native_func" - $(NM) $(TMPDIR)/libnon_bundled.rlib | $(CGREP) -e "U _*native_func" - - # Build a cdylib, 'BUNDLED_LIB' will appear on the linker line - # The cdylib will contain the `native_func` symbol in the end - $(RUSTC) cdylib-bundled.rs --crate-type=cdylib --print link-args $(SPLIT) | $(CGREP) -e $(BUNDLED_LIB) - $(NM) $(call DYLIB,cdylib_bundled) | $(CGREP) -e "[Tt] _*native_func" - - # Build a cdylib, `native-staticlib` will appear on the linker line because it was not bundled previously - # The cdylib will contain the `native_func` symbol in the end - $(RUSTC) cdylib-non-bundled.rs --crate-type=cdylib --print link-args $(SPLIT) | $(CGREP) -e '-l[" ]*native-staticlib' - $(NM) $(call DYLIB,cdylib_non_bundled) | $(CGREP) -e "[Tt] _*native_func" diff --git a/src/test/run-make/native-link-modifier-bundle-split/bundled.rs b/src/test/run-make/native-link-modifier-bundle-split/bundled.rs deleted file mode 100644 index 0bbae8752d7b3..0000000000000 --- a/src/test/run-make/native-link-modifier-bundle-split/bundled.rs +++ /dev/null @@ -1,11 +0,0 @@ -#[link(name = "native-staticlib", kind = "static", modifiers = "+bundle")] -extern "C" { - pub fn native_func(); -} - -#[no_mangle] -pub extern "C" fn wrapped_func() { - unsafe { - native_func(); - } -} diff --git a/src/test/run-make/native-link-modifier-bundle-split/cdylib-bundled.rs b/src/test/run-make/native-link-modifier-bundle-split/cdylib-bundled.rs deleted file mode 100644 index 7291309168a48..0000000000000 --- a/src/test/run-make/native-link-modifier-bundle-split/cdylib-bundled.rs +++ /dev/null @@ -1 +0,0 @@ -extern crate bundled; diff --git a/src/test/run-make/native-link-modifier-bundle-split/cdylib-non-bundled.rs b/src/test/run-make/native-link-modifier-bundle-split/cdylib-non-bundled.rs deleted file mode 100644 index 1df81fd101f75..0000000000000 --- a/src/test/run-make/native-link-modifier-bundle-split/cdylib-non-bundled.rs +++ /dev/null @@ -1 +0,0 @@ -extern crate non_bundled; diff --git a/src/test/run-make/native-link-modifier-bundle-split/native-staticlib.c b/src/test/run-make/native-link-modifier-bundle-split/native-staticlib.c deleted file mode 100644 index d300fdf1c1742..0000000000000 --- a/src/test/run-make/native-link-modifier-bundle-split/native-staticlib.c +++ /dev/null @@ -1 +0,0 @@ -void native_func() {} diff --git a/src/test/run-make/native-link-modifier-bundle-split/non-bundled.rs b/src/test/run-make/native-link-modifier-bundle-split/non-bundled.rs deleted file mode 100644 index 8181e6387c5c7..0000000000000 --- a/src/test/run-make/native-link-modifier-bundle-split/non-bundled.rs +++ /dev/null @@ -1,11 +0,0 @@ -#[link(name = "native-staticlib", kind = "static", modifiers = "-bundle")] -extern "C" { - pub fn native_func(); -} - -#[no_mangle] -pub extern "C" fn wrapped_func() { - unsafe { - native_func(); - } -} diff --git a/src/test/run-make/native-link-modifier-bundle/Makefile b/src/test/run-make/native-link-modifier-bundle/Makefile index e4b0f74ac26ac..b7ee56ff52ec3 100644 --- a/src/test/run-make/native-link-modifier-bundle/Makefile +++ b/src/test/run-make/native-link-modifier-bundle/Makefile @@ -6,6 +6,9 @@ # We're using the llvm-nm instead of the system nm to ensure it is compatible # with the LLVM bitcode generated by rustc. NM = "$(LLVM_BIN_DIR)"/llvm-nm +SPLIT = "-Zsplit-bundled-libs" +BUNDLED_LIB = "libbundled.rlib.bundle.native-staticlib.a" + all: $(call NATIVE_STATICLIB,native-staticlib) # Build a staticlib and a rlib, the `native_func` symbol will be bundled into them @@ -31,3 +34,15 @@ all: $(call NATIVE_STATICLIB,native-staticlib) # The cdylib will contain the `native_func` symbol in the end $(RUSTC) cdylib-non-bundled.rs --crate-type=cdylib --print link-args | $(CGREP) -e '-l[" ]*native-staticlib' $(NM) $(call DYLIB,cdylib_non_bundled) | $(CGREP) -e "[Tt] _*native_func" + + # Build a staticlib and a rlib, the `native_func` symbol will be bundled only into staticlib + $(RUSTC) bundled.rs --crate-type=staticlib --crate-type=rlib $(SPLIT) --crate-name=bundled_split + $(NM) $(TMPDIR)/libbundled_split.a | $(CGREP) -e "T _*native_func" + $(NM) $(TMPDIR)/libbundled_split.a | $(CGREP) -e "U _*native_func" + $(NM) $(TMPDIR)/libbundled_split.rlib | $(CGREP) -ve "T _*native_func" + $(NM) $(TMPDIR)/libbundled_split.rlib | $(CGREP) -e "U _*native_func" + + # Build a cdylib, `native-staticlib` will appear on the linker line because it was not bundled previously + # The cdylib will contain the `native_func` symbol in the end + $(RUSTC) cdylib-non-bundled.rs --crate-type=cdylib --print link-args $(SPLIT) --crate-name=cdylib_non_bundled_split | $(CGREP) -e '-l[" ]*native-staticlib' + $(NM) $(call DYLIB,cdylib_non_bundled_split) | $(CGREP) -e "[Tt] _*native_func" \ No newline at end of file diff --git a/src/test/run-make/native-link-modifier-bundle/libbundled-split b/src/test/run-make/native-link-modifier-bundle/libbundled-split new file mode 100644 index 0000000000000000000000000000000000000000..f0e00e3600b3795d81e56b2f21daa0c631c3ab95 GIT binary patch literal 6686 zcmd5heOw#Yk#8lTl|d{5yRjS#y0Vj&HU(DS(g6t{jzbz>OTO;hp7RsC+Lcj2LKXsK zl3w|8M9%bzbG{U}$psQ$uK8-QllGj}Nm#_$;9!UN5}z+|9I)|Miha~}5;wJv&Rgx; z3MRkg{=4}x``*l(d2im#?7XMNT*5|twYR1h(Vqt2q6NY%!4fv zHXIgsufHkeL#Sx}l#0R^w05^LP?KIC;JBs`UoY?ljp6!0v{0rBoeq}aY*tHwZ+%lC zQy9TbLlKrQj0A-!E3f%Q);sNXX%U;%EsNBo|M>Pbt5pPSKn4Qcinnte^k!URl}X() zl!i1Y($p9QQj1XfcMX{E(UwA|y^ty3g=SIR80Ez)AD+5!_R3)Y14xx!;N&!-&4_tf8DdsyD#a`S!%>-1aP ztY8;4;Bue19#lom(S+1xOh?P^RM>?{Nj#xF1`QWsoi@Mk{H7>7MsOx^ScDA%O=>wj9?%X zX!SP40=yvpe$$~BezmE4Fd{AN)@0whlQL5nueI|H%HXZTpiBvin(%18d!^#pC8!hq$PgZLH-Y4J{#Y z)04+8ckS5mykxT5?R2^!0<4R%a6Z;Areo*xLR9cY#qs@*k3F^L!o?RPQGxM$>@FX8 z++}k)9GplcP3DCl8(Lp4i2DZ4j6Sku_Kh(~+~c=9T{hOk`FV@YE_lR6EYC-*^?{He zp6GvfdhEXk-g{b-wA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w8bjl kG@Y@{pF+$&d!kfTe~$t~6kH(l=#AocRpPM7l#b2+4V)>0bpQYW literal 0 HcmV?d00001 From 6a368f5a90cc556a776ac459583838138be8e13f Mon Sep 17 00:00:00 2001 From: Bryanskiy Date: Thu, 28 Jul 2022 16:20:28 +0300 Subject: [PATCH 10/13] delete unused files --- .../native-link-modifier-bundle/libbundled-split | Bin 6686 -> 0 bytes .../libbundled-split.bundle.native-staticlib.a | Bin 1552 -> 0 bytes 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/test/run-make/native-link-modifier-bundle/libbundled-split delete mode 100644 src/test/run-make/native-link-modifier-bundle/libbundled-split.bundle.native-staticlib.a diff --git a/src/test/run-make/native-link-modifier-bundle/libbundled-split b/src/test/run-make/native-link-modifier-bundle/libbundled-split deleted file mode 100644 index f0e00e3600b3795d81e56b2f21daa0c631c3ab95..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6686 zcmd5heOw#Yk#8lTl|d{5yRjS#y0Vj&HU(DS(g6t{jzbz>OTO;hp7RsC+Lcj2LKXsK zl3w|8M9%bzbG{U}$psQ$uK8-QllGj}Nm#_$;9!UN5}z+|9I)|Miha~}5;wJv&Rgx; z3MRkg{=4}x``*l(d2im#?7XMNT*5|twYR1h(Vqt2q6NY%!4fv zHXIgsufHkeL#Sx}l#0R^w05^LP?KIC;JBs`UoY?ljp6!0v{0rBoeq}aY*tHwZ+%lC zQy9TbLlKrQj0A-!E3f%Q);sNXX%U;%EsNBo|M>Pbt5pPSKn4Qcinnte^k!URl}X() zl!i1Y($p9QQj1XfcMX{E(UwA|y^ty3g=SIR80Ez)AD+5!_R3)Y14xx!;N&!-&4_tf8DdsyD#a`S!%>-1aP ztY8;4;Bue19#lom(S+1xOh?P^RM>?{Nj#xF1`QWsoi@Mk{H7>7MsOx^ScDA%O=>wj9?%X zX!SP40=yvpe$$~BezmE4Fd{AN)@0whlQL5nueI|H%HXZTpiBvin(%18d!^#pC8!hq$PgZLH-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7-1hj-JVfuV^UZ5Sz+Wg13 zPv`ru{Ab9enzzkgoG<2(*!}AYtBT#5WmCB{pDCKJZ4)=OZ{}rYVEA_KN8Fo4rF&({ zKn0!&qHn*26fvr4^S>+J3uU#j`TMv*uO!e3%Dz{FE~uFP^oXnZ8Xwi0C>OM#w8bjl kG@Y@{pF+$&d!kfTe~$t~6kH(l=#AocRpPM7l#b2+4V)>0bpQYW From 5ac82d23a7a6ada82f00c18421a8c0f48259981c Mon Sep 17 00:00:00 2001 From: Bryanskiy Date: Thu, 28 Jul 2022 16:30:49 +0300 Subject: [PATCH 11/13] cleanup --- compiler/rustc_interface/src/tests.rs | 1 + src/test/rustdoc-ui/z-help.stdout | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 9c0b534798e39..34676ee120707 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -783,6 +783,7 @@ fn test_unstable_options_tracking_hash() { tracked!(share_generics, Some(true)); tracked!(show_span, Some(String::from("abc"))); tracked!(simulate_remapped_rust_src_base, Some(PathBuf::from("/rustc/abc"))); + tracked!(split_bundled_libs, true); tracked!(src_hash_algorithm, Some(SourceFileHashAlgorithm::Sha1)); tracked!(stack_protector, StackProtector::All); tracked!(symbol_mangling_version, Some(SymbolManglingVersion::V0)); diff --git a/src/test/rustdoc-ui/z-help.stdout b/src/test/rustdoc-ui/z-help.stdout index eee47ecefb82e..0e6121458911b 100644 --- a/src/test/rustdoc-ui/z-help.stdout +++ b/src/test/rustdoc-ui/z-help.stdout @@ -141,10 +141,6 @@ -Z show-span=val -- show spans for compiler debugging (expr|pat|ty) -Z span-debug=val -- forward proc_macro::Span's `Debug` impl to `Span` -Z span-free-formats=val -- exclude spans when debug-printing compiler state (default: no) - -Z src-hash-algorithm=val -- hash algorithm of source files in debug info (`md5`, `sha1`, or `sha256`) - -Z stack-protector=val -- control stack smash protection strategy (`rustc --print stack-protector-strategies` for details) - -Z strict-init-checks=val -- control if mem::uninitialized and mem::zeroed panic on more UB - -Z strip=val -- tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`) -Z split-bundled-libs=val -- if libfoo.rlib is the rlib, then libfoo.rlib.bundle.* are the corresponding bundled static libraries -Z split-dwarf-kind=val -- split dwarf variant (only if -Csplit-debuginfo is enabled and on relevant platform) (default: `split`) @@ -154,6 +150,10 @@ `single`: sections which do not require relocation are written into object file but ignored by the linker -Z split-dwarf-inlining=val -- provide minimal debug info in the object/executable to facilitate online symbolication/stack traces in the absence of .dwo/.dwp files when using Split DWARF + -Z src-hash-algorithm=val -- hash algorithm of source files in debug info (`md5`, `sha1`, or `sha256`) + -Z stack-protector=val -- control stack smash protection strategy (`rustc --print stack-protector-strategies` for details) + -Z strict-init-checks=val -- control if mem::uninitialized and mem::zeroed panic on more UB + -Z strip=val -- tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`) -Z symbol-mangling-version=val -- which mangling version to use for symbol names ('legacy' (default) or 'v0') -Z teach=val -- show extended diagnostic help (default: no) -Z temps-dir=val -- the directory the intermediate files are written to From 8d09ef9b97563c345b28f1de928fedb47b753f67 Mon Sep 17 00:00:00 2001 From: Bryanskiy Date: Thu, 28 Jul 2022 17:45:23 +0300 Subject: [PATCH 12/13] cleanup --- compiler/rustc_session/src/options.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 697c35259d187..09962bdd3c301 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1520,7 +1520,7 @@ options! { span_free_formats: bool = (false, parse_bool, [UNTRACKED], "exclude spans when debug-printing compiler state (default: no)"), split_bundled_libs: bool = (false, parse_bool, [TRACKED], - "if libfoo.rlib is the rlib, then libfoo.rlib.bundle.* are the corresponding bundled static libraries"), + "if libfoo.rlib is the rlib, then libfoo.rlib.bundle.* are the corresponding bundled static libraries"), split_dwarf_kind: SplitDwarfKind = (SplitDwarfKind::Split, parse_split_dwarf_kind, [TRACKED], "split dwarf variant (only if -Csplit-debuginfo is enabled and on relevant platform) (default: `split`) From 1215ea4849a47694ebacd288c1584b603c323bad Mon Sep 17 00:00:00 2001 From: Bryanskiy Date: Fri, 29 Jul 2022 12:00:14 +0300 Subject: [PATCH 13/13] add cdylib-bundled-split test --- src/test/run-make/native-link-modifier-bundle/Makefile | 8 ++++---- .../native-link-modifier-bundle/cdylib-bundled-split.rs | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 src/test/run-make/native-link-modifier-bundle/cdylib-bundled-split.rs diff --git a/src/test/run-make/native-link-modifier-bundle/Makefile b/src/test/run-make/native-link-modifier-bundle/Makefile index b7ee56ff52ec3..b9340457b34dc 100644 --- a/src/test/run-make/native-link-modifier-bundle/Makefile +++ b/src/test/run-make/native-link-modifier-bundle/Makefile @@ -7,7 +7,7 @@ # with the LLVM bitcode generated by rustc. NM = "$(LLVM_BIN_DIR)"/llvm-nm SPLIT = "-Zsplit-bundled-libs" -BUNDLED_LIB = "libbundled.rlib.bundle.native-staticlib.a" +BUNDLED_LIB = "libbundled_split.rlib.bundle.native-staticlib.a" all: $(call NATIVE_STATICLIB,native-staticlib) @@ -42,7 +42,7 @@ all: $(call NATIVE_STATICLIB,native-staticlib) $(NM) $(TMPDIR)/libbundled_split.rlib | $(CGREP) -ve "T _*native_func" $(NM) $(TMPDIR)/libbundled_split.rlib | $(CGREP) -e "U _*native_func" - # Build a cdylib, `native-staticlib` will appear on the linker line because it was not bundled previously + # Build a cdylib, 'BUNDLED_LIB' will appear on the linker line # The cdylib will contain the `native_func` symbol in the end - $(RUSTC) cdylib-non-bundled.rs --crate-type=cdylib --print link-args $(SPLIT) --crate-name=cdylib_non_bundled_split | $(CGREP) -e '-l[" ]*native-staticlib' - $(NM) $(call DYLIB,cdylib_non_bundled_split) | $(CGREP) -e "[Tt] _*native_func" \ No newline at end of file + $(RUSTC) cdylib-bundled-split.rs --crate-type=cdylib --print link-args $(SPLIT) | $(CGREP) -e $(BUNDLED_LIB) + $(NM) $(call DYLIB,cdylib_bundled_split) | $(CGREP) -e "[Tt] _*native_func" \ No newline at end of file diff --git a/src/test/run-make/native-link-modifier-bundle/cdylib-bundled-split.rs b/src/test/run-make/native-link-modifier-bundle/cdylib-bundled-split.rs new file mode 100644 index 0000000000000..f586f701cc5ba --- /dev/null +++ b/src/test/run-make/native-link-modifier-bundle/cdylib-bundled-split.rs @@ -0,0 +1 @@ +extern crate bundled_split;