Skip to content

Commit ef32c67

Browse files
committed
Remove dladdr fallback and implementation
This has been present for a very long time but I believe this has never actually been that necessary. Non-MSVC platforms all use libbacktrace by default, and libbacktrace will consult symbol tables of object files to do what `dladdr` does, just inside of libbacktrace. Additionally gimli implements the same logic. I believe that this means that `dladdr` isn't necessary for resolving any symbols since our other strategies should already be doing everything for us. This commit makes the feature defunkt and otherwise removes the various forms of fallback to dladdr.
1 parent df444be commit ef32c67

8 files changed

Lines changed: 29 additions & 275 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ winapi = { version = "0.3.3", optional = true }
4949
# Note that not all features are available on all platforms, so even though a
5050
# feature is enabled some other feature may be used instead.
5151
[features]
52-
default = ["std", "libunwind", "libbacktrace", "dladdr", "dbghelp"]
52+
default = ["std", "libunwind", "libbacktrace", "dbghelp"]
5353

5454
# Include std support.
5555
std = []
@@ -81,16 +81,12 @@ kernel32 = []
8181
# can also provide filename/line number information if debuginfo is
8282
# compiled in. This library currently only primarily works on unixes that
8383
# are not OSX, however.
84-
# - dladdr: this feature uses the dladdr(3) function (a glibc extension) to
85-
# resolve symbol names. This is fairly unreliable on linux, but works well
86-
# enough on OSX.
8784
# - gimli-symbolize: use the `gimli-rs/addr2line` crate to symbolicate
8885
# addresses into file, line, and name using DWARF debug information. At
8986
# the moment, this is only possible when targetting Linux, since macOS
9087
# splits DWARF out into a separate object file. Enabling this feature
9188
# means one less C dependency.
9289
libbacktrace = ["backtrace-sys/backtrace-sys"]
93-
dladdr = []
9490
gimli-symbolize = ["addr2line", "goblin"]
9591

9692
#=======================================
@@ -105,6 +101,7 @@ serialize-serde = ["serde"]
105101
#
106102
# Only here for backwards compatibility purposes, they do nothing now.
107103
coresymbolication = []
104+
dladdr = []
108105

109106
#=======================================
110107
# Internal features for testing and such.

crates/without_debuginfo/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ features = [
1212
'libunwind',
1313
'dbghelp',
1414

15-
# Allow fallback to dladdr
16-
'dladdr',
17-
1815
# Yes, we have `std`
1916
'std',
2017
]

src/symbolize/dladdr.rs

Lines changed: 0 additions & 112 deletions
This file was deleted.

src/symbolize/dladdr_resolve.rs

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/symbolize/gimli.rs

Lines changed: 11 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use self::gimli::read::EndianSlice;
88
use self::gimli::LittleEndian as Endian;
99
use self::mmap::Mmap;
10-
use crate::symbolize::dladdr;
1110
use crate::symbolize::ResolveWhat;
1211
use crate::types::BytesOrWideString;
1312
use crate::SymbolName;
@@ -632,10 +631,12 @@ impl Cache {
632631

633632
pub unsafe fn resolve(what: ResolveWhat, cb: &mut FnMut(&super::Symbol)) {
634633
let addr = what.address_or_ip();
635-
let mut cb = DladdrFallback {
636-
cb,
637-
addr,
638-
called: false,
634+
let mut call = |sym: Symbol| {
635+
// Extend the lifetime of `sym` to `'static` since we are unfortunately
636+
// required to here, but it's ony ever going out as a reference so no
637+
// reference to it should be persisted beyond this frame anyway.
638+
let sym = mem::transmute::<Symbol, Symbol<'static>>(sym);
639+
(cb)(&super::Symbol { inner: sym });
639640
};
640641

641642
Cache::with_global(|cache| {
@@ -650,60 +651,27 @@ pub unsafe fn resolve(what: ResolveWhat, cb: &mut FnMut(&super::Symbol)) {
650651
Some(cx) => cx,
651652
None => return,
652653
};
654+
let mut any_frames = false;
653655
if let Ok(mut frames) = cx.dwarf.find_frames(addr as u64) {
654656
while let Ok(Some(frame)) = frames.next() {
655-
cb.call(Symbol::Frame {
657+
any_frames = true;
658+
call(Symbol::Frame {
656659
addr: addr as *mut c_void,
657660
location: frame.location,
658661
name: frame.function.map(|f| f.name.slice()),
659662
});
660663
}
661664
}
662665

663-
if !cb.called {
666+
if !any_frames {
664667
if let Some(name) = cx.object.search_symtab(addr as u64) {
665-
cb.call(Symbol::Symtab {
668+
call(Symbol::Symtab {
666669
addr: addr as *mut c_void,
667670
name,
668671
});
669672
}
670673
}
671674
});
672-
673-
drop(cb);
674-
}
675-
676-
struct DladdrFallback<'a, 'b> {
677-
addr: *mut c_void,
678-
called: bool,
679-
cb: &'a mut (FnMut(&super::Symbol) + 'b),
680-
}
681-
682-
impl DladdrFallback<'_, '_> {
683-
fn call(&mut self, sym: Symbol) {
684-
self.called = true;
685-
686-
// Extend the lifetime of `sym` to `'static` since we are unfortunately
687-
// required to here, but it's ony ever going out as a reference so no
688-
// reference to it should be persisted beyond this frame anyway.
689-
let sym = unsafe { mem::transmute::<Symbol, Symbol<'static>>(sym) };
690-
(self.cb)(&super::Symbol { inner: sym });
691-
}
692-
}
693-
694-
impl Drop for DladdrFallback<'_, '_> {
695-
fn drop(&mut self) {
696-
if self.called {
697-
return;
698-
}
699-
unsafe {
700-
dladdr::resolve(self.addr, &mut |sym| {
701-
(self.cb)(&super::Symbol {
702-
inner: Symbol::Dladdr(sym),
703-
})
704-
});
705-
}
706-
}
707675
}
708676

709677
pub enum Symbol<'a> {
@@ -717,15 +685,11 @@ pub enum Symbol<'a> {
717685
/// Couldn't find debug information, but we found it in the symbol table of
718686
/// the elf executable.
719687
Symtab { addr: *mut c_void, name: &'a [u8] },
720-
/// We weren't able to find anything in the original file, so we had to fall
721-
/// back to using `dladdr` which had a hit.
722-
Dladdr(dladdr::Symbol<'a>),
723688
}
724689

725690
impl Symbol<'_> {
726691
pub fn name(&self) -> Option<SymbolName> {
727692
match self {
728-
Symbol::Dladdr(s) => s.name(),
729693
Symbol::Frame { name, .. } => {
730694
let name = name.as_ref()?;
731695
Some(SymbolName::new(name))
@@ -736,15 +700,13 @@ impl Symbol<'_> {
736700

737701
pub fn addr(&self) -> Option<*mut c_void> {
738702
match self {
739-
Symbol::Dladdr(s) => s.addr(),
740703
Symbol::Frame { addr, .. } => Some(*addr),
741704
Symbol::Symtab { .. } => None,
742705
}
743706
}
744707

745708
pub fn filename_raw(&self) -> Option<BytesOrWideString> {
746709
match self {
747-
Symbol::Dladdr(s) => return s.filename_raw(),
748710
Symbol::Frame { location, .. } => {
749711
let file = location.as_ref()?.file?;
750712
Some(BytesOrWideString::Bytes(file.as_bytes()))
@@ -755,7 +717,6 @@ impl Symbol<'_> {
755717

756718
pub fn filename(&self) -> Option<&Path> {
757719
match self {
758-
Symbol::Dladdr(s) => return s.filename(),
759720
Symbol::Frame { location, .. } => {
760721
let file = location.as_ref()?.file?;
761722
Some(Path::new(file))
@@ -766,7 +727,6 @@ impl Symbol<'_> {
766727

767728
pub fn lineno(&self) -> Option<u32> {
768729
match self {
769-
Symbol::Dladdr(s) => return s.lineno(),
770730
Symbol::Frame { location, .. } => location.as_ref()?.line,
771731
Symbol::Symtab { .. } => None,
772732
}

0 commit comments

Comments
 (0)