github.com/cilium/ebpf@v0.15.1-0.20240517100537-8079b37aa138/internal/cmd/gensections.awk (about)

     1  #!/usr/bin/gawk -f
     2  # This script expects tools/lib/bpf/libbpf.c as input.
     3  
     4  function trim(str, left, right) {
     5  	str = gensub("^[\t ]*" left, "", "g", str)
     6  	return gensub(right "$", "", "g", str)
     7  }
     8  
     9  BEGIN {
    10  	print "// Code generated by internal/cmd/gensections.awk; DO NOT EDIT."
    11  	print ""
    12  	print "package ebpf"
    13  	print ""
    14  	print "// Code in this file is derived from libbpf, available under BSD-2-Clause."
    15  	print ""
    16  	print "import \"github.com/cilium/ebpf/internal/sys\""
    17  	print ""
    18  	print "var elfSectionDefs = []libbpfElfSectionDef{"
    19  
    20  	FS=","
    21  }
    22  
    23  /\tSEC_DEF/ {
    24  	pattern = trim(substr($1, 10))
    25  	prog_type = "sys.BPF_PROG_TYPE_" trim($2)
    26  	attach_type = trim($3)
    27  	attach_type = attach_type == "0" ? "0" : "sys." attach_type
    28  	flags = trim($4, "", ")")
    29  	flags = gensub("SEC_", "_SEC_", "g", flags)
    30  	printf "\t{%s, %s, %s, %s},\n", pattern, prog_type, attach_type, flags;
    31  }
    32  
    33  END {
    34  	print "}"
    35  	print ""
    36  }