@@ -10,7 +10,6 @@ use std::sync::Arc;
1010use bitvec:: { bitvec, prelude:: BitVec } ;
1111use debugid:: DebugId ;
1212use object:: read:: ReadRef ;
13- use object:: FileFlags ;
1413use samply_debugid:: { CodeId , ElfBuildId } ;
1514
1615use crate :: symbol_map:: SymbolMapTrait ;
@@ -364,61 +363,6 @@ pub trait FileLocation: Clone + Display {
364363 fn location_for_dwp ( & self ) -> Option < Self > ;
365364}
366365
367- /// The "relative address base" is the base address which [`LookupAddress::Relative`]
368- /// addresses are relative to. You start with an SVMA (a stated virtual memory address),
369- /// you subtract the relative address base, and out comes a relative address.
370- ///
371- /// This function computes that base address. It is defined as follows:
372- ///
373- /// - For Windows binaries, the base address is the "image base address".
374- /// - For mach-O binaries, the base address is the vmaddr of the __TEXT segment.
375- /// - For ELF binaries, the base address is the vmaddr of the *first* segment,
376- /// i.e. the vmaddr of the first "LOAD" ELF command.
377- ///
378- /// In many cases, this base address is simply zero:
379- ///
380- /// - ELF images of dynamic libraries (i.e. not executables) usually have a
381- /// base address of zero.
382- /// - Stand-alone mach-O dylibs usually have a base address of zero because their
383- /// __TEXT segment is at address zero.
384- /// - In PDBs, "RVAs" are relative addresses which are already relative to the
385- /// image base.
386- ///
387- /// However, in the following cases, the base address is usually non-zero:
388- ///
389- /// - The "image base address" of Windows binaries is usually non-zero.
390- /// - mach-O executable files (not dylibs) usually have their __TEXT segment at
391- /// address 0x100000000.
392- /// - mach-O libraries in the dyld shared cache have a __TEXT segment at some
393- /// non-zero address in the cache.
394- /// - ELF executables can have non-zero base addresses, e.g. 0x200000 or 0x400000.
395- /// - Kernel ELF binaries ("vmlinux") have a large base address such as
396- /// 0xffffffff81000000. Moreover, the base address seems to coincide with the
397- /// vmaddr of the .text section, which is readily-available in perf.data files
398- /// (in a synthetic mapping called "[kernel.kallsyms]_text").
399- pub fn relative_address_base < ' data > ( object_file : & impl object:: Object < ' data > ) -> u64 {
400- use object:: read:: ObjectSegment ;
401- if let Some ( text_segment) = object_file
402- . segments ( )
403- . find ( |s| s. name ( ) == Ok ( Some ( "__TEXT" ) ) )
404- {
405- // This is a mach-O image. "Relative addresses" are relative to the
406- // vmaddr of the __TEXT segment.
407- return text_segment. address ( ) ;
408- }
409-
410- if let FileFlags :: Elf { .. } = object_file. flags ( ) {
411- // This is an ELF image. "Relative addresses" are relative to the
412- // vmaddr of the first segment (the first LOAD command).
413- if let Some ( first_segment) = object_file. segments ( ) . next ( ) {
414- return first_segment. address ( ) ;
415- }
416- }
417-
418- // For PE binaries, relative_address_base() returns the image base address.
419- object_file. relative_address_base ( )
420- }
421-
422366/// The symbol for a function.
423367#[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
424368pub struct SymbolInfo {
0 commit comments