diff --git a/elf_reader.go b/elf_reader.go index b80043d97..d471f0e27 100644 --- a/elf_reader.go +++ b/elf_reader.go @@ -51,6 +51,12 @@ func LoadCollectionSpecFromReader(rd io.ReaderAt) (*CollectionSpec, error) { return nil, err } + // Checks if the ELF file is for BPF data. + // Old LLVM versions set e_machine to EM_NONE. + if f.File.Machine != unix.EM_NONE && f.File.Machine != elf.EM_BPF { + return nil, fmt.Errorf("unexpected machine type for BPF ELF: %s", f.File.Machine) + } + var ( licenseSection *elf.Section versionSection *elf.Section diff --git a/internal/unix/types_linux.go b/internal/unix/types_linux.go index 7113cd434..04b828b4c 100644 --- a/internal/unix/types_linux.go +++ b/internal/unix/types_linux.go @@ -75,6 +75,8 @@ const ( SIGPROF = linux.SIGPROF SIG_BLOCK = linux.SIG_BLOCK SIG_UNBLOCK = linux.SIG_UNBLOCK + EM_NONE = linux.EM_NONE + EM_BPF = linux.EM_BPF ) type Statfs_t = linux.Statfs_t diff --git a/internal/unix/types_other.go b/internal/unix/types_other.go index 6e2b98169..e87bf830a 100644 --- a/internal/unix/types_other.go +++ b/internal/unix/types_other.go @@ -79,6 +79,8 @@ const ( SIGPROF SIG_BLOCK SIG_UNBLOCK + EM_NONE + EM_BPF ) type Statfs_t struct {