Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helpers: Added dynamic symbol resolver #128

Merged
merged 5 commits into from Feb 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
}