@@ -453,33 +453,65 @@ fn diagnostics_works() {
453
453
}
454
454
455
455
#[ 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 > {
459
460
std:: process:: Command :: new ( "nm" )
460
461
. arg ( "-pa" )
461
462
. arg ( path)
462
463
. output ( )
463
464
. expect ( "nm works" )
464
465
. 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 ( "packed" , inspect_debuginfo) ;
481
+ }
466
482
}
467
483
468
484
#[ 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 > {
472
489
std:: process:: Command :: new ( "readelf" )
473
490
. arg ( "-wi" )
474
491
. arg ( path)
475
492
. output ( )
476
493
. expect ( "readelf works" )
477
494
. stdout
478
- } )
495
+ }
496
+
497
+ #[ cargo_test( requires_readelf, nightly, reason = "-Zremap-path-scope is unstable" ) ]
498
+ fn with_split_debuginfo_off ( ) {
499
+ object_works_helper ( "off" , inspect_debuginfo) ;
500
+ }
501
+
502
+ #[ cargo_test( requires_readelf, nightly, reason = "-Zremap-path-scope is unstable" ) ]
503
+ fn with_split_debuginfo_packed ( ) {
504
+ object_works_helper ( "packed" , inspect_debuginfo) ;
505
+ }
506
+
507
+ #[ cargo_test( requires_readelf, nightly, reason = "-Zremap-path-scope is unstable" ) ]
508
+ fn with_split_debuginfo_unpacked ( ) {
509
+ object_works_helper ( "packed" , inspect_debuginfo) ;
510
+ }
479
511
}
480
512
481
513
#[ cfg( unix) ]
482
- fn object_works_helper ( run : impl Fn ( & std:: path:: Path ) -> Vec < u8 > ) {
514
+ fn object_works_helper ( split_debuginfo : & str , run : impl Fn ( & std:: path:: Path ) -> Vec < u8 > ) {
483
515
use std:: os:: unix:: ffi:: OsStrExt ;
484
516
485
517
let registry_src = paths:: home ( ) . join ( ".cargo/registry/src" ) ;
@@ -495,14 +527,19 @@ fn object_works_helper(run: impl Fn(&std::path::Path) -> Vec<u8>) {
495
527
let p = project ( )
496
528
. file (
497
529
"Cargo.toml" ,
498
- r#"
530
+ & format ! (
531
+ r#"
499
532
[package]
500
533
name = "foo"
501
534
version = "0.0.1"
502
535
503
536
[dependencies]
504
537
bar = "0.0.1"
505
- "# ,
538
+
539
+ [profile.dev]
540
+ split-debuginfo = "{split_debuginfo}"
541
+ "#
542
+ ) ,
506
543
)
507
544
. file ( "src/main.rs" , "fn main() { bar::f(); }" )
508
545
. build ( ) ;
@@ -530,14 +567,14 @@ fn object_works_helper(run: impl Fn(&std::path::Path) -> Vec<u8>) {
530
567
. with_stderr ( & format ! (
531
568
"\
532
569
[COMPILING] bar v0.0.1
533
- [RUNNING] `rustc [..]\
570
+ [RUNNING] `rustc [..]-C split-debuginfo={split_debuginfo} [..] \
534
571
-Zremap-path-scope=object \
535
572
--remap-path-prefix={pkg_remap} \
536
573
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
537
574
[COMPILING] foo v0.0.1 ([CWD])
538
- [RUNNING] `rustc [..]\
575
+ [RUNNING] `rustc [..]-C split-debuginfo={split_debuginfo} [..] \
539
576
-Zremap-path-scope=object \
540
- --remap-path-prefix=[CWD]= \
577
+ --remap-path-prefix=[CWD]=. \
541
578
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
542
579
[FINISHED] dev [..]" ,
543
580
) )
@@ -547,31 +584,44 @@ fn object_works_helper(run: impl Fn(&std::path::Path) -> Vec<u8>) {
547
584
assert ! ( bin_path. is_file( ) ) ;
548
585
let stdout = run ( & bin_path) ;
549
586
assert ! ( memchr:: memmem:: find( & stdout, rust_src) . is_none( ) ) ;
550
- if cfg ! ( target_os = "macos" ) {
551
- for line in stdout. split ( |c| c == & b'\n' ) {
552
- let registry = memchr:: memmem:: find ( line, registry_src_bytes) . is_none ( ) ;
553
- let local = memchr:: memmem:: find ( line, pkg_root) . is_none ( ) ;
554
- if registry && local {
555
- continue ;
556
- }
587
+ for line in stdout. split ( |c| c == & b'\n' ) {
588
+ let registry = memchr:: memmem:: find ( line, registry_src_bytes) . is_none ( ) ;
589
+ let local = memchr:: memmem:: find ( line, pkg_root) . is_none ( ) ;
590
+ if registry && local {
591
+ continue ;
592
+ }
557
593
594
+ #[ cfg( target_os = "macos" ) ]
595
+ {
596
+ // `OSO` symbols can't be trimmed at this moment.
597
+ // See <https://github.com/rust-lang/rust/issues/116948#issuecomment-1793617018>
558
598
if memchr:: memmem:: find ( line, b" OSO " ) . is_some ( ) {
559
- // `OSO` symbols can't be trimmed at this moment.
560
- // See <https://github.com/rust-lang/rust/issues/116948#issuecomment-1793617018>
561
- // TODO: Change to `is_none()` once the issue is resolved.
562
599
continue ;
563
600
}
564
601
565
602
// on macOS `SO` symbols are embedded in final binaries and should be trimmed.
566
603
// See rust-lang/rust#117652.
567
- assert ! (
568
- memchr:: memmem:: find( line, b" SO " ) . is_some( ) ,
569
- "untrimmed `SO` symbol found"
570
- )
604
+ if memchr:: memmem:: find ( line, b" SO " ) . is_some ( ) {
605
+ continue ;
606
+ }
607
+ }
608
+
609
+ #[ cfg( target_os = "linux" ) ]
610
+ {
611
+ // There is a bug in rustc `-Zremap-path-scope`.
612
+ // See rust-lang/rust/pull/118518
613
+ if memchr:: memmem:: find ( line, b"DW_AT_comp_dir" ) . is_some ( ) {
614
+ continue ;
615
+ }
616
+ if memchr:: memmem:: find ( line, b"DW_AT_GNU_dwo_name" ) . is_some ( ) {
617
+ continue ;
618
+ }
571
619
}
572
- } else {
573
- assert ! ( memchr:: memmem:: find( & stdout, registry_src_bytes) . is_none( ) ) ;
574
- assert ! ( memchr:: memmem:: find( & stdout, pkg_root) . is_none( ) ) ;
620
+
621
+ panic ! (
622
+ "unexpected untrimmed symbol: {}" ,
623
+ String :: from_utf8( line. into( ) ) . unwrap( )
624
+ ) ;
575
625
}
576
626
}
577
627
0 commit comments