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

Native Image SBOM: support extracting symbols in .dynsym section #3647

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions syft/pkg/cataloger/java/graalvm_native_image_cataloger.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,11 @@ func (ni nativeImageElf) fetchPkgs() (pkgs []pkg.Package, relationships []artifa
var sbomLength elf.Symbol
var svmVersion elf.Symbol

si, err := bi.Symbols()
si, err := ni.getSymbols()
if err != nil {
return nil, nil, fmt.Errorf("no symbols found in binary: %w", err)
return nil, nil, err
}
if si == nil {
if len(si) == 0 {
return nil, nil, errors.New(nativeImageMissingSymbolsError)
}
for _, s := range si {
Expand Down Expand Up @@ -286,6 +286,31 @@ func (ni nativeImageElf) fetchPkgs() (pkgs []pkg.Package, relationships []artifa
return decompressSbom(data, sbomLocation, lengthLocation)
}

// getSymbols obtains the union of the symbols in the .symtab and .dynsym sections of the ELF file
func (ni nativeImageElf) getSymbols() ([]elf.Symbol, error) {
var symbols []elf.Symbol
symsErr := error(nil)
dynErr := error(nil)

if syms, err := ni.file.Symbols(); err == nil {
symbols = append(symbols, syms...)
} else {
symsErr = err
}

if dynSyms, err := ni.file.DynamicSymbols(); err == nil {
symbols = append(symbols, dynSyms...)
} else {
dynErr = err
}

if symsErr != nil && dynErr != nil {
return nil, fmt.Errorf("could not retrieve symbols from binary: SHT_SYMTAB error: %v, SHT_DYNSYM error: %v", symsErr, dynErr)
}

return symbols, nil
}

// fetchPkgs obtains the packages from a Native Image given as a Mach O file.
func (ni nativeImageMachO) fetchPkgs() (pkgs []pkg.Package, relationships []artifact.Relationship, retErr error) {
defer func() {
Expand Down
Loading