MCPcopy
hub / github.com/cilium/ebpf / loadSectionRelocations

Method loadSectionRelocations

elf_reader.go:1685–1711  ·  view source on GitHub ↗
(sec *elf.Section, symbols []elf.Symbol)

Source from the content-addressed store, hash-verified

1683}
1684
1685func (ec *elfCode) loadSectionRelocations(sec *elf.Section, symbols []elf.Symbol) (map[uint64]elf.Symbol, error) {
1686 rels := make(map[uint64]elf.Symbol)
1687
1688 if sec.Entsize < 16 {
1689 return nil, fmt.Errorf("section %s: relocations are less than 16 bytes", sec.Name)
1690 }
1691
1692 r := bufio.NewReader(sec.Open())
1693 for off := uint64(0); off < sec.Size; off += sec.Entsize {
1694 ent := io.LimitReader(r, int64(sec.Entsize))
1695
1696 var rel elf.Rel64
1697 if binary.Read(ent, ec.ByteOrder, &rel) != nil {
1698 return nil, fmt.Errorf("can't parse relocation at offset %v", off)
1699 }
1700
1701 symNo := int(elf.R_SYM64(rel.Info) - 1)
1702 if symNo >= len(symbols) {
1703 return nil, fmt.Errorf("offset %d: symbol %d doesn't exist", off, symNo)
1704 }
1705
1706 symbol := symbols[symNo]
1707 rels[rel.Off] = symbol
1708 }
1709
1710 return rels, nil
1711}

Callers 1

loadRelocationsMethod · 0.95

Calls 2

OpenMethod · 0.80
ReadMethod · 0.65

Tested by

no test coverage detected