MCPcopy Index your code
hub / github.com/cilium/ebpf / loadProgramSections

Method loadProgramSections

elf_reader.go:370–434  ·  view source on GitHub ↗

loadProgramSections iterates ec's sections and emits a ProgramSpec for each function it finds. The resulting map is indexed by function name.

()

Source from the content-addressed store, hash-verified

368//
369// The resulting map is indexed by function name.
370func (ec *elfCode) loadProgramSections() (map[string]*ProgramSpec, error) {
371
372 progs := make(map[string]*ProgramSpec)
373
374 // Generate a ProgramSpec for each function found in each program section.
375 var export []string
376 for _, sec := range ec.sections {
377 if sec.kind != programSection {
378 continue
379 }
380
381 if len(sec.symbols) == 0 {
382 return nil, fmt.Errorf("section %v: missing symbols", sec.Name)
383 }
384
385 if sec.ReaderAt == nil {
386 return nil, fmt.Errorf("compressed program section is not supported")
387 }
388
389 funcs, err := ec.loadFunctions(sec)
390 if err != nil {
391 return nil, fmt.Errorf("section %v: %w", sec.Name, err)
392 }
393
394 progType, attachType, progFlags, attachTo := getProgType(sec.Name)
395
396 for name, insns := range funcs {
397 spec := &ProgramSpec{
398 Name: name,
399 Type: progType,
400 Flags: progFlags,
401 AttachType: attachType,
402 AttachTo: attachTo,
403 SectionName: sec.Name,
404 License: ec.license,
405 KernelVersion: ec.version,
406 Instructions: insns,
407 ByteOrder: ec.ByteOrder,
408 }
409
410 // Function names must be unique within a single ELF blob.
411 if progs[name] != nil {
412 return nil, fmt.Errorf("duplicate program name %s", name)
413 }
414 progs[name] = spec
415
416 if spec.SectionName != ".text" {
417 export = append(export, name)
418 }
419 }
420 }
421
422 flattenPrograms(progs, export)
423
424 // Hide programs (e.g. library functions) that were not explicitly emitted
425 // to an ELF section. These could be exposed in a separate CollectionSpec
426 // field later to allow them to be modified.
427 for n, p := range progs {

Callers 1

Calls 3

loadFunctionsMethod · 0.95
getProgTypeFunction · 0.85
flattenProgramsFunction · 0.85

Tested by

no test coverage detected