loadMaps iterates over all ELF sections marked as map sections (like .maps) and parses each symbol into a MapSpec.
()
| 805 | // loadMaps iterates over all ELF sections marked as map sections (like .maps) |
| 806 | // and parses each symbol into a MapSpec. |
| 807 | func (ec *elfCode) loadMaps() error { |
| 808 | for _, sec := range ec.sections { |
| 809 | if sec.kind != mapSection { |
| 810 | continue |
| 811 | } |
| 812 | |
| 813 | if len(sec.symbols) == 0 { |
| 814 | return fmt.Errorf("section %v: no symbols", sec.Name) |
| 815 | } |
| 816 | |
| 817 | if sec.ReaderAt == nil { |
| 818 | return fmt.Errorf("compressed map section is not supported") |
| 819 | } |
| 820 | |
| 821 | vars, err := ec.sectionVars(ec.btf, sec.Name) |
| 822 | if err != nil { |
| 823 | return fmt.Errorf("section %v: loading map variable BTF: %w", sec.Name, err) |
| 824 | } |
| 825 | |
| 826 | for _, sym := range sec.symbols { |
| 827 | name := sym.Name |
| 828 | if ec.maps[name] != nil { |
| 829 | return fmt.Errorf("duplicate symbol %s in section %s", name, sec.Name) |
| 830 | } |
| 831 | |
| 832 | if sym.Value > math.MaxUint32 || sym.Size > math.MaxUint32 { |
| 833 | return fmt.Errorf("symbol %s: offset or size exceeds 32 bits in section %s", sym.Name, sec.Name) |
| 834 | } |
| 835 | if sym.Value+sym.Size > sec.Size { |
| 836 | return fmt.Errorf("symbol %s: size goes out of bounds of section %s", name, sec.Name) |
| 837 | } |
| 838 | |
| 839 | sr := internal.NewBufferedSectionReader(sec, int64(sym.Value), int64(sym.Size)) |
| 840 | |
| 841 | spec := MapSpec{ |
| 842 | Name: sanitizeName(name, -1), |
| 843 | } |
| 844 | switch { |
| 845 | case binary.Read(sr, ec.ByteOrder, &spec.Type) != nil: |
| 846 | return fmt.Errorf("map %s: missing type", name) |
| 847 | case binary.Read(sr, ec.ByteOrder, &spec.KeySize) != nil: |
| 848 | return fmt.Errorf("map %s: missing key size", name) |
| 849 | case binary.Read(sr, ec.ByteOrder, &spec.ValueSize) != nil: |
| 850 | return fmt.Errorf("map %s: missing value size", name) |
| 851 | case binary.Read(sr, ec.ByteOrder, &spec.MaxEntries) != nil: |
| 852 | return fmt.Errorf("map %s: missing max entries", name) |
| 853 | case binary.Read(sr, ec.ByteOrder, &spec.Flags) != nil: |
| 854 | return fmt.Errorf("map %s: missing flags", name) |
| 855 | } |
| 856 | |
| 857 | extra, err := io.ReadAll(sr) |
| 858 | if err != nil { |
| 859 | return fmt.Errorf("map %s: reading map tail: %w", name, err) |
| 860 | } |
| 861 | if len(extra) > 0 { |
| 862 | spec.Extra = bytes.NewReader(extra) |
| 863 | } |
| 864 |
no test coverage detected