Skip to content

Commit

Permalink
helpers: Added dynamic symbol resolver (#128)
Browse files Browse the repository at this point in the history
* helpers: Added dynamic symbol resolver
Dynamic symbols are very important to attach u(ret)probe on common libraries such as openssl, libc, etc.
  • Loading branch information
guyarb committed Feb 16, 2022
1 parent 51cb51e commit d2980ae
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions helpers/elf.go
Expand Up @@ -14,11 +14,18 @@ func SymbolToOffset(path, symbol string) (uint32, error) {
return 0, fmt.Errorf("could not open elf file to resolve symbol offset: %w", err)
}

syms, err := f.Symbols()
if err != nil {
return 0, fmt.Errorf("could not open symbol section to resolve symbol offset: %w", err)
regularSymbols, regularSymbolsErr := f.Symbols()
dynamicSymbols, dynamicSymbolsErr := f.DynamicSymbols()

// Only if we failed getting both regular and dynamic symbols - then we abort.
if regularSymbolsErr != nil && dynamicSymbolsErr != nil {
return 0, fmt.Errorf("could not open symbol sections to resolve symbol offset: %w, %w", regularSymbolsErr, dynamicSymbolsErr)
}

// Concatenating into a single list.
// The list can have duplications, but we will find the first occurrence which is sufficient.
syms := append(regularSymbols, dynamicSymbols...)

sectionsToSearchForSymbol := []*elf.Section{}

for i := range f.Sections {
Expand Down Expand Up @@ -48,5 +55,5 @@ func SymbolToOffset(path, symbol string) (uint32, error) {
}
}

return 0, fmt.Errorf("symbol not found")
return 0, fmt.Errorf("symbol %s not found in %s", symbol, path)
}

0 comments on commit d2980ae

Please sign in to comment.