Skip to content

Commit

Permalink
Update should_use_metadata function
Browse files Browse the repository at this point in the history
* Correct the reason for not renaming dylibs
* Add todo for -install-name/-soname usage
* Limit wasm32 executable metadata omission to emscripten. Wasm files
  don't contain any filename themself.
* Don't omit metadata for executables on macOS. backtrace-rs is now able
  to load debuginfo for renamed .dSYM files.
* Mention another reason to include the metadata hash for libstd.
  • Loading branch information
bjorn3 committed Jul 5, 2021
1 parent 3ebb5f1 commit 283bafc
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/cargo/core/compiler/context/compilation_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,19 +626,13 @@ fn should_use_metadata(bcx: &BuildContext<'_, '_>, unit: &Unit) -> bool {
// No metadata in these cases:
//
// - dylibs:
// - macOS encodes the dylib name in the executable, so it can't be renamed.
// - TODO: Are there other good reasons? If not, maybe this should be macos specific?
// - if any dylib names are encoded in executables, so they can't be renamed.
// - TODO: Maybe use `-install-name` on macOS or `-soname` on other UNIX systems
// to specify the dylib name to be used by the linker instead of the filename.
// - Windows MSVC executables: The path to the PDB is embedded in the
// executable, and we don't want the PDB path to include the hash in it.
// - wasm32 executables: When using emscripten, the path to the .wasm file
// is embedded in the .js file, so we don't want the hash in there.
// TODO: Is this necessary for wasm32-unknown-unknown?
// - apple executables: The executable name is used in the dSYM directory
// (such as `target/debug/foo.dSYM/Contents/Resources/DWARF/foo-64db4e4bf99c12dd`).
// Unfortunately this causes problems with our current backtrace
// implementation which looks for a file matching the exe name exactly.
// See https://github.com/rust-lang/rust/issues/72550#issuecomment-638501691
// for more details.
// - wasm32-unknown-emscripten executables: When using emscripten, the path to the
// .wasm file is embedded in the .js file, so we don't want the hash in there.
//
// This is only done for local packages, as we don't expect to export
// dependencies.
Expand All @@ -647,14 +641,14 @@ fn should_use_metadata(bcx: &BuildContext<'_, '_>, unit: &Unit) -> bool {
// force metadata in the hash. This is only used for building libstd. For
// example, if libstd is placed in a common location, we don't want a file
// named /usr/lib/libstd.so which could conflict with other rustc
// installs. TODO: Is this still a realistic concern?
// installs. In addition it prevents accidentally loading a libstd of a
// different compiler at runtime.
// See https://github.com/rust-lang/cargo/issues/3005
let short_name = bcx.target_data.short_name(&unit.kind);
if (unit.target.is_dylib()
|| unit.target.is_cdylib()
|| (unit.target.is_executable() && short_name.starts_with("wasm32-"))
|| (unit.target.is_executable() && short_name.contains("msvc"))
|| (unit.target.is_executable() && short_name.contains("-apple-")))
|| (unit.target.is_executable() && short_name == "wasm32-unknown-emscripten")
|| (unit.target.is_executable() && short_name.contains("msvc")))
&& unit.pkg.package_id().source_id().is_path()
&& env::var("__CARGO_DEFAULT_LIB_METADATA").is_err()
{
Expand Down

0 comments on commit 283bafc

Please sign in to comment.