@@ -286,6 +286,13 @@ fn decompress_xz(data: &[u8]) -> Result<Vec<u8>> {
286286 Ok ( decompressed)
287287}
288288
289+ #[ cfg( not( feature = "xz" ) ) ]
290+ fn decompress_xz ( _data : & [ u8 ] ) -> Result < Vec < u8 > > {
291+ Err ( Error :: with_unsupported (
292+ "ELF section is xz compressed but xz compression support is not enabled" ,
293+ ) )
294+ }
295+
289296
290297#[ derive( Debug ) ]
291298struct EhdrExt < ' elf > {
@@ -823,26 +830,18 @@ where
823830 Ok ( syms)
824831 }
825832
826- #[ cfg( feature = "xz" ) ]
827833 fn parse_debugdata ( & self ) -> Result < Vec < u8 > > {
828834 if let Some ( idx) = self . find_section ( ".gnu_debugdata" ) ? {
829- let data = self . section_data_raw ( idx) ?;
830- if !data. is_empty ( ) {
831- decompress_xz ( & data)
832- } else {
833- Ok ( Vec :: new ( ) )
834- }
835+ // NB: We assume here that `.gnu_debugdata` will never be
836+ // of type `SHT_NOBITS`, which just logically doesn't
837+ // make sense to be used.
838+ self . section_data_raw ( idx)
839+ . and_then ( |data| decompress_xz ( & data) )
835840 } else {
836841 Ok ( Vec :: new ( ) )
837842 }
838843 }
839844
840- #[ cfg( not( feature = "xz" ) ) ]
841- fn parse_debugdata ( & self ) -> Result < Vec < u8 > > {
842- // We don't have the means to decompress it, fake an empty one.
843- return Ok ( Vec :: new ( ) )
844- }
845-
846845 fn ensure_symtab_cache ( & self ) -> Result < & SymbolTableCache < ' _ > > {
847846 self . symtab . get_or_try_init_ ( move || {
848847 let mut syms = self . parse_syms ( ".symtab" ) ? as ElfN_Syms < ' _ > ;
@@ -2215,21 +2214,6 @@ mod tests {
22152214 assert_eq ! ( new_data, data) ;
22162215 }
22172216
2218- /// Make sure that we can look up a symbol residing in `.gnu_debugdata`.
2219- #[ test]
2220- fn lookup_from_gnu_debugdata ( ) {
2221- let bin_name = Path :: new ( & env ! ( "CARGO_MANIFEST_DIR" ) )
2222- . join ( "data" )
2223- . join ( "test-debugdata.bin" ) ;
2224-
2225- let parser = ElfParser :: open ( bin_name. as_path ( ) ) . unwrap ( ) ;
2226- let opts = FindAddrOpts :: default ( ) ;
2227- let addr = parser. find_addr ( "fibonacci" , & opts) . unwrap ( ) ;
2228- assert_eq ! ( addr. len( ) , 1 ) ;
2229- let sym = & addr[ 0 ] ;
2230- assert_eq ! ( sym. name, "fibonacci" ) ;
2231- }
2232-
22332217 /// Benchmark creation of our "str2symtab" table.
22342218 ///
22352219 /// Creating this table exercises a lot of the parser code paths and
0 commit comments