@@ -83,7 +83,7 @@ fn release_profile_default_to_object() {
8383 [COMPILING] foo v0.0.1 ([CWD])
8484[RUNNING] `rustc [..]\
8585 -Zremap-path-scope=object \
86- --remap-path-prefix=[CWD]= \
86+ --remap-path-prefix=[CWD]=. \
8787 --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
8888[FINISHED] release [..]" ,
8989 )
@@ -121,7 +121,7 @@ fn one_option() {
121121 [COMPILING] foo v0.0.1 ([CWD])
122122[RUNNING] `rustc [..]\
123123 -Zremap-path-scope={option} \
124- --remap-path-prefix=[CWD]= \
124+ --remap-path-prefix=[CWD]=. \
125125 --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
126126[FINISHED] dev [..]" ,
127127 ) )
@@ -158,7 +158,7 @@ fn multiple_options() {
158158 [COMPILING] foo v0.0.1 ([CWD])
159159[RUNNING] `rustc [..]\
160160 -Zremap-path-scope=diagnostics,macro,object \
161- --remap-path-prefix=[CWD]= \
161+ --remap-path-prefix=[CWD]=. \
162162 --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
163163[FINISHED] dev [..]" ,
164164 )
@@ -193,7 +193,7 @@ fn profile_merge_works() {
193193 [COMPILING] foo v0.0.1 ([CWD])
194194[RUNNING] `rustc [..]\
195195 -Zremap-path-scope=diagnostics \
196- --remap-path-prefix=[CWD]= \
196+ --remap-path-prefix=[CWD]=. \
197197 --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
198198[FINISHED] custom [..]" ,
199199 )
@@ -243,7 +243,7 @@ fn registry_dependency() {
243243[COMPILING] foo v0.0.1 ([CWD])
244244[RUNNING] `rustc [..]\
245245 -Zremap-path-scope=object \
246- --remap-path-prefix=[CWD]= \
246+ --remap-path-prefix=[CWD]=. \
247247 --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
248248[FINISHED] dev [..]
249249[RUNNING] `target/debug/foo[EXE]`"
@@ -297,7 +297,7 @@ fn git_dependency() {
297297[COMPILING] foo v0.0.1 ([CWD])
298298[RUNNING] `rustc [..]\
299299 -Zremap-path-scope=object \
300- --remap-path-prefix=[CWD]= \
300+ --remap-path-prefix=[CWD]=. \
301301 --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
302302[FINISHED] dev [..]
303303[RUNNING] `target/debug/foo[EXE]`"
@@ -338,12 +338,12 @@ fn path_dependency() {
338338 [COMPILING] bar v0.0.1 ([..]/cocktail-bar)
339339[RUNNING] `rustc [..]\
340340 -Zremap-path-scope=object \
341- --remap-path-prefix=[CWD]= \
341+ --remap-path-prefix=[CWD]=. \
342342 --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
343343[COMPILING] foo v0.0.1 ([CWD])
344344[RUNNING] `rustc [..]\
345345 -Zremap-path-scope=object \
346- --remap-path-prefix=[CWD]= \
346+ --remap-path-prefix=[CWD]=. \
347347 --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
348348[FINISHED] dev [..]
349349[RUNNING] `target/debug/foo[EXE]`"
@@ -392,7 +392,7 @@ fn path_dependency_outside_workspace() {
392392[COMPILING] foo v0.0.1 ([CWD])
393393[RUNNING] `rustc [..]\
394394 -Zremap-path-scope=object \
395- --remap-path-prefix=[CWD]= \
395+ --remap-path-prefix=[CWD]=. \
396396 --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
397397[FINISHED] dev [..]
398398[RUNNING] `target/debug/foo[EXE]`"
@@ -446,40 +446,73 @@ fn diagnostics_works() {
446446 "\
447447 [RUNNING] [..]rustc [..]\
448448 -Zremap-path-scope=diagnostics \
449- --remap-path-prefix=[CWD]= \
449+ --remap-path-prefix=[CWD]=. \
450450 --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]",
451451 )
452452 . run ( ) ;
453453}
454454
455455#[ cfg( target_os = "macos" ) ]
456- #[ cargo_test( requires_nm, nightly, reason = "-Zremap-path-scope is unstable" ) ]
457- fn object_works ( ) {
458- object_works_helper ( |path| {
456+ mod object_works {
457+ use super :: * ;
458+
459+ fn inspect_debuginfo ( path : & std:: path:: Path ) -> Vec < u8 > {
459460 std:: process:: Command :: new ( "nm" )
460461 . arg ( "-pa" )
461462 . arg ( path)
462463 . output ( )
463464 . expect ( "nm works" )
464465 . stdout
465- } )
466+ }
467+
468+ #[ cargo_test( requires_nm, nightly, reason = "-Zremap-path-scope is unstable" ) ]
469+ fn with_split_debuginfo_off ( ) {
470+ object_works_helper ( "off" , inspect_debuginfo) ;
471+ }
472+
473+ #[ cargo_test( requires_nm, nightly, reason = "-Zremap-path-scope is unstable" ) ]
474+ fn with_split_debuginfo_packed ( ) {
475+ object_works_helper ( "packed" , inspect_debuginfo) ;
476+ }
477+
478+ #[ cargo_test( requires_nm, nightly, reason = "-Zremap-path-scope is unstable" ) ]
479+ fn with_split_debuginfo_unpacked ( ) {
480+ object_works_helper ( "unpacked" , inspect_debuginfo) ;
481+ }
466482}
467483
468484#[ cfg( target_os = "linux" ) ]
469- #[ cargo_test( requires_readelf, nightly, reason = "-Zremap-path-scope is unstable" ) ]
470- fn object_works ( ) {
471- object_works_helper ( |path| {
485+ mod object_works {
486+ use super :: * ;
487+
488+ fn inspect_debuginfo ( path : & std:: path:: Path ) -> Vec < u8 > {
472489 std:: process:: Command :: new ( "readelf" )
473- . arg ( "-wi" )
490+ . arg ( "--debug-dump=info" )
491+ . arg ( "--debug-dump=no-follow-links" ) // older version can't recognized but just a warning
474492 . arg ( path)
475493 . output ( )
476494 . expect ( "readelf works" )
477495 . stdout
478- } )
496+ }
497+
498+ #[ cargo_test( requires_readelf, nightly, reason = "-Zremap-path-scope is unstable" ) ]
499+ fn with_split_debuginfo_off ( ) {
500+ object_works_helper ( "off" , inspect_debuginfo) ;
501+ }
502+
503+ #[ cargo_test( requires_readelf, nightly, reason = "-Zremap-path-scope is unstable" ) ]
504+ fn with_split_debuginfo_packed ( ) {
505+ object_works_helper ( "packed" , inspect_debuginfo) ;
506+ }
507+
508+ #[ cargo_test( requires_readelf, nightly, reason = "-Zremap-path-scope is unstable" ) ]
509+ fn with_split_debuginfo_unpacked ( ) {
510+ object_works_helper ( "unpacked" , inspect_debuginfo) ;
511+ }
479512}
480513
481514#[ cfg( unix) ]
482- fn object_works_helper ( run : impl Fn ( & std:: path:: Path ) -> Vec < u8 > ) {
515+ fn object_works_helper ( split_debuginfo : & str , run : impl Fn ( & std:: path:: Path ) -> Vec < u8 > ) {
483516 use std:: os:: unix:: ffi:: OsStrExt ;
484517
485518 let registry_src = paths:: home ( ) . join ( ".cargo/registry/src" ) ;
@@ -495,14 +528,19 @@ fn object_works_helper(run: impl Fn(&std::path::Path) -> Vec<u8>) {
495528 let p = project ( )
496529 . file (
497530 "Cargo.toml" ,
498- r#"
531+ & format ! (
532+ r#"
499533 [package]
500534 name = "foo"
501535 version = "0.0.1"
502536
503537 [dependencies]
504538 bar = "0.0.1"
505- "# ,
539+
540+ [profile.dev]
541+ split-debuginfo = "{split_debuginfo}"
542+ "#
543+ ) ,
506544 )
507545 . file ( "src/main.rs" , "fn main() { bar::f(); }" )
508546 . build ( ) ;
@@ -523,34 +561,21 @@ fn object_works_helper(run: impl Fn(&std::path::Path) -> Vec<u8>) {
523561
524562 p. cargo ( "clean" ) . run ( ) ;
525563
526- p. change_file (
527- "Cargo.toml" ,
528- r#"
529- [package]
530- name = "foo"
531- version = "0.0.1"
532-
533- [dependencies]
534- bar = "0.0.1"
535-
536- [profile.dev]
537- trim-paths = "object"
538- "# ,
539- ) ;
540-
541564 p. cargo ( "build --verbose -Ztrim-paths" )
565+ . arg ( "--config" )
566+ . arg ( r#"profile.dev.trim-paths="object""# )
542567 . masquerade_as_nightly_cargo ( & [ "-Ztrim-paths" ] )
543568 . with_stderr ( & format ! (
544569 "\
545570 [COMPILING] bar v0.0.1
546- [RUNNING] `rustc [..]\
571+ [RUNNING] `rustc [..]-C split-debuginfo={split_debuginfo} [..] \
547572 -Zremap-path-scope=object \
548573 --remap-path-prefix={pkg_remap} \
549574 --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
550575[COMPILING] foo v0.0.1 ([CWD])
551- [RUNNING] `rustc [..]\
576+ [RUNNING] `rustc [..]-C split-debuginfo={split_debuginfo} [..] \
552577 -Zremap-path-scope=object \
553- --remap-path-prefix=[CWD]= \
578+ --remap-path-prefix=[CWD]=. \
554579 --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
555580[FINISHED] dev [..]" ,
556581 ) )
@@ -560,31 +585,44 @@ fn object_works_helper(run: impl Fn(&std::path::Path) -> Vec<u8>) {
560585 assert ! ( bin_path. is_file( ) ) ;
561586 let stdout = run ( & bin_path) ;
562587 assert ! ( memchr:: memmem:: find( & stdout, rust_src) . is_none( ) ) ;
563- if cfg ! ( target_os = "macos" ) {
564- for line in stdout. split ( |c| c == & b'\n' ) {
565- let registry = memchr:: memmem:: find ( line, registry_src_bytes) . is_none ( ) ;
566- let local = memchr:: memmem:: find ( line, pkg_root) . is_none ( ) ;
567- if registry && local {
568- continue ;
569- }
588+ for line in stdout. split ( |c| c == & b'\n' ) {
589+ let registry = memchr:: memmem:: find ( line, registry_src_bytes) . is_none ( ) ;
590+ let local = memchr:: memmem:: find ( line, pkg_root) . is_none ( ) ;
591+ if registry && local {
592+ continue ;
593+ }
570594
595+ #[ cfg( target_os = "macos" ) ]
596+ {
597+ // `OSO` symbols can't be trimmed at this moment.
598+ // See <https://github.com/rust-lang/rust/issues/116948#issuecomment-1793617018>
571599 if memchr:: memmem:: find ( line, b" OSO " ) . is_some ( ) {
572- // `OSO` symbols can't be trimmed at this moment.
573- // See <https://github.com/rust-lang/rust/issues/116948#issuecomment-1793617018>
574- // TODO: Change to `is_none()` once the issue is resolved.
575600 continue ;
576601 }
577602
578603 // on macOS `SO` symbols are embedded in final binaries and should be trimmed.
579604 // See rust-lang/rust#117652.
580- assert ! (
581- memchr:: memmem:: find( line, b" SO " ) . is_some( ) ,
582- "untrimmed `SO` symbol found"
583- )
605+ if memchr:: memmem:: find ( line, b" SO " ) . is_some ( ) {
606+ continue ;
607+ }
608+ }
609+
610+ #[ cfg( target_os = "linux" ) ]
611+ {
612+ // There is a bug in rustc `-Zremap-path-scope`.
613+ // See rust-lang/rust/pull/118518
614+ if memchr:: memmem:: find ( line, b"DW_AT_comp_dir" ) . is_some ( ) {
615+ continue ;
616+ }
617+ if memchr:: memmem:: find ( line, b"DW_AT_GNU_dwo_name" ) . is_some ( ) {
618+ continue ;
619+ }
584620 }
585- } else {
586- assert ! ( memchr:: memmem:: find( & stdout, registry_src_bytes) . is_none( ) ) ;
587- assert ! ( memchr:: memmem:: find( & stdout, pkg_root) . is_none( ) ) ;
621+
622+ panic ! (
623+ "unexpected untrimmed symbol: {}" ,
624+ String :: from_utf8( line. into( ) ) . unwrap( )
625+ ) ;
588626 }
589627}
590628
@@ -700,7 +738,7 @@ fn lldb_works_after_trimmed() {
700738 "\
701739 [RUNNING] `rustc [..]\
702740 -Zremap-path-scope=object \
703- --remap-path-prefix=[CWD]= \
741+ --remap-path-prefix=[CWD]=. \
704742 --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]",
705743 )
706744 . run ( ) ;
0 commit comments