@@ -468,23 +468,74 @@ impl fmt::Display for LinkOutputKind {
468
468
469
469
pub type LinkArgs = BTreeMap < LinkerFlavor , Vec < StaticCow < str > > > ;
470
470
471
- #[ derive( Clone , Copy , Hash , Debug , PartialEq , Eq ) ]
471
+ /// Which kind of debuginfo does the target use?
472
+ ///
473
+ /// Useful in determining whether a target supports Split DWARF (a target with
474
+ /// `DebuginfoKind::Dwarf` and supporting `SplitDebuginfo::Unpacked` for example).
475
+ #[ derive( Clone , Copy , Debug , Default , Eq , Hash , PartialEq ) ]
476
+ pub enum DebuginfoKind {
477
+ /// DWARF debuginfo (such as that used on `x86_64_unknown_linux_gnu`).
478
+ #[ default]
479
+ Dwarf ,
480
+ /// DWARF debuginfo in dSYM files (such as on Apple platforms).
481
+ DwarfDsym ,
482
+ /// Program database files (such as on Windows).
483
+ Pdb ,
484
+ }
485
+
486
+ impl DebuginfoKind {
487
+ fn as_str ( & self ) -> & ' static str {
488
+ match self {
489
+ DebuginfoKind :: Dwarf => "dwarf" ,
490
+ DebuginfoKind :: DwarfDsym => "dwarf-dsym" ,
491
+ DebuginfoKind :: Pdb => "pdb" ,
492
+ }
493
+ }
494
+ }
495
+
496
+ impl FromStr for DebuginfoKind {
497
+ type Err = ( ) ;
498
+
499
+ fn from_str ( s : & str ) -> Result < Self , ( ) > {
500
+ Ok ( match s {
501
+ "dwarf" => DebuginfoKind :: Dwarf ,
502
+ "dwarf-dsym" => DebuginfoKind :: DwarfDsym ,
503
+ "pdb" => DebuginfoKind :: Pdb ,
504
+ _ => return Err ( ( ) ) ,
505
+ } )
506
+ }
507
+ }
508
+
509
+ impl ToJson for DebuginfoKind {
510
+ fn to_json ( & self ) -> Json {
511
+ self . as_str ( ) . to_json ( )
512
+ }
513
+ }
514
+
515
+ impl fmt:: Display for DebuginfoKind {
516
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
517
+ f. write_str ( self . as_str ( ) )
518
+ }
519
+ }
520
+
521
+ #[ derive( Clone , Copy , Debug , Default , Eq , Hash , PartialEq ) ]
472
522
pub enum SplitDebuginfo {
473
523
/// Split debug-information is disabled, meaning that on supported platforms
474
524
/// you can find all debug information in the executable itself. This is
475
525
/// only supported for ELF effectively.
476
526
///
477
527
/// * Windows - not supported
478
528
/// * macOS - don't run `dsymutil`
479
- /// * ELF - `.dwarf_*` sections
529
+ /// * ELF - `.debug_*` sections
530
+ #[ default]
480
531
Off ,
481
532
482
533
/// Split debug-information can be found in a "packed" location separate
483
534
/// from the final artifact. This is supported on all platforms.
484
535
///
485
536
/// * Windows - `*.pdb`
486
537
/// * macOS - `*.dSYM` (run `dsymutil`)
487
- /// * ELF - `*.dwp` (run `rust-llvm-dwp `)
538
+ /// * ELF - `*.dwp` (run `thorin `)
488
539
Packed ,
489
540
490
541
/// Split debug-information can be found in individual object files on the
@@ -509,7 +560,7 @@ impl SplitDebuginfo {
509
560
impl FromStr for SplitDebuginfo {
510
561
type Err = ( ) ;
511
562
512
- fn from_str ( s : & str ) -> Result < SplitDebuginfo , ( ) > {
563
+ fn from_str ( s : & str ) -> Result < Self , ( ) > {
513
564
Ok ( match s {
514
565
"off" => SplitDebuginfo :: Off ,
515
566
"unpacked" => SplitDebuginfo :: Unpacked ,
@@ -1435,9 +1486,13 @@ pub struct TargetOptions {
1435
1486
/// thumb and arm interworking.
1436
1487
pub has_thumb_interworking : bool ,
1437
1488
1489
+ /// Which kind of debuginfo is used by this target?
1490
+ pub debuginfo_kind : DebuginfoKind ,
1438
1491
/// How to handle split debug information, if at all. Specifying `None` has
1439
1492
/// target-specific meaning.
1440
1493
pub split_debuginfo : SplitDebuginfo ,
1494
+ /// Which kinds of split debuginfo are supported by the target?
1495
+ pub supported_split_debuginfo : StaticCow < [ SplitDebuginfo ] > ,
1441
1496
1442
1497
/// The sanitizers supported by this target
1443
1498
///
@@ -1595,7 +1650,10 @@ impl Default for TargetOptions {
1595
1650
use_ctors_section : false ,
1596
1651
eh_frame_header : true ,
1597
1652
has_thumb_interworking : false ,
1598
- split_debuginfo : SplitDebuginfo :: Off ,
1653
+ debuginfo_kind : Default :: default ( ) ,
1654
+ split_debuginfo : Default :: default ( ) ,
1655
+ // `Off` is supported by default, but targets can remove this manually, e.g. Windows.
1656
+ supported_split_debuginfo : Cow :: Borrowed ( & [ SplitDebuginfo :: Off ] ) ,
1599
1657
supported_sanitizers : SanitizerSet :: empty ( ) ,
1600
1658
default_adjusted_cabi : None ,
1601
1659
c_enum_min_bits : 32 ,
@@ -1868,6 +1926,19 @@ impl Target {
1868
1926
Some ( Ok ( ( ) ) )
1869
1927
} ) ) . unwrap_or( Ok ( ( ) ) )
1870
1928
} ) ;
1929
+ ( $key_name: ident, DebuginfoKind ) => ( {
1930
+ let name = ( stringify!( $key_name) ) . replace( "_" , "-" ) ;
1931
+ obj. remove( & name) . and_then( |o| o. as_str( ) . and_then( |s| {
1932
+ match s. parse:: <DebuginfoKind >( ) {
1933
+ Ok ( level) => base. $key_name = level,
1934
+ _ => return Some ( Err (
1935
+ format!( "'{s}' is not a valid value for debuginfo-kind. Use 'dwarf', \
1936
+ 'dwarf-dsym' or 'pdb'.")
1937
+ ) ) ,
1938
+ }
1939
+ Some ( Ok ( ( ) ) )
1940
+ } ) ) . unwrap_or( Ok ( ( ) ) )
1941
+ } ) ;
1871
1942
( $key_name: ident, SplitDebuginfo ) => ( {
1872
1943
let name = ( stringify!( $key_name) ) . replace( "_" , "-" ) ;
1873
1944
obj. remove( & name) . and_then( |o| o. as_str( ) . and_then( |s| {
@@ -1904,6 +1975,25 @@ impl Target {
1904
1975
}
1905
1976
}
1906
1977
} ) ;
1978
+ ( $key_name: ident, falliable_list) => ( {
1979
+ let name = ( stringify!( $key_name) ) . replace( "_" , "-" ) ;
1980
+ obj. remove( & name) . and_then( |j| {
1981
+ if let Some ( v) = j. as_array( ) {
1982
+ match v. iter( ) . map( |a| FromStr :: from_str( a. as_str( ) . unwrap( ) ) ) . collect( ) {
1983
+ Ok ( l) => { base. $key_name = l } ,
1984
+ // FIXME: `falliable_list` can't re-use the `key!` macro for list
1985
+ // elements and the error messages from that macro, so it has a bad
1986
+ // generic message instead
1987
+ Err ( _) => return Some ( Err (
1988
+ format!( "`{:?}` is not a valid value for `{}`" , j, name)
1989
+ ) ) ,
1990
+ }
1991
+ } else {
1992
+ incorrect_type. push( name)
1993
+ }
1994
+ Some ( Ok ( ( ) ) )
1995
+ } ) . unwrap_or( Ok ( ( ) ) )
1996
+ } ) ;
1907
1997
( $key_name: ident, optional) => ( {
1908
1998
let name = ( stringify!( $key_name) ) . replace( "_" , "-" ) ;
1909
1999
if let Some ( o) = obj. remove( & name) {
@@ -2190,7 +2280,9 @@ impl Target {
2190
2280
key ! ( use_ctors_section, bool ) ;
2191
2281
key ! ( eh_frame_header, bool ) ;
2192
2282
key ! ( has_thumb_interworking, bool ) ;
2283
+ key ! ( debuginfo_kind, DebuginfoKind ) ?;
2193
2284
key ! ( split_debuginfo, SplitDebuginfo ) ?;
2285
+ key ! ( supported_split_debuginfo, falliable_list) ?;
2194
2286
key ! ( supported_sanitizers, SanitizerSet ) ?;
2195
2287
key ! ( default_adjusted_cabi, Option <Abi >) ?;
2196
2288
key ! ( c_enum_min_bits, u64 ) ;
@@ -2434,7 +2526,9 @@ impl ToJson for Target {
2434
2526
target_option_val ! ( use_ctors_section) ;
2435
2527
target_option_val ! ( eh_frame_header) ;
2436
2528
target_option_val ! ( has_thumb_interworking) ;
2529
+ target_option_val ! ( debuginfo_kind) ;
2437
2530
target_option_val ! ( split_debuginfo) ;
2531
+ target_option_val ! ( supported_split_debuginfo) ;
2438
2532
target_option_val ! ( supported_sanitizers) ;
2439
2533
target_option_val ! ( c_enum_min_bits) ;
2440
2534
target_option_val ! ( generate_arange_section) ;
0 commit comments