| 1 | //go:build !windows |
| 2 | |
| 3 | package genscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/ |
| 4 | |
| 5 | import ( |
| 6 | "bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/" |
| 7 | _ "embedscip-go gomod github.com/golang/go/src go1.24.0 embed/" |
| 8 | "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 9 | "go/build/constraintscip-go gomod github.com/golang/go/src go1.24.0 `go/build/constraint`/" |
| 10 | "go/tokenscip-go gomod github.com/golang/go/src go1.24.0 `go/token`/" |
| 11 | "ioscip-go gomod github.com/golang/go/src go1.24.0 io/" |
| 12 | "sortscip-go gomod github.com/golang/go/src go1.24.0 sort/" |
| 13 | "stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/" |
| 14 | "text/templatescip-go gomod github.com/golang/go/src go1.24.0 `text/template`/" |
| 15 | "unicodescip-go gomod github.com/golang/go/src go1.24.0 unicode/" |
| 16 | "unicode/utf8scip-go gomod github.com/golang/go/src go1.24.0 `unicode/utf8`/" |
| 17 | |
| 18 | "github.com/cilium/ebpf/btfscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/btf`/" |
| 19 | b2gIntscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/internal`/ "github.com/cilium/ebpf/cmd/bpf2go/internalscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/internal`/" |
| 20 | "github.com/cilium/ebpf/internalscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/internal`/" |
| 21 | ) |
| 22 | |
| 23 | //go:embed output.tpl |
| 24 | var commonRawscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/commonRaw. string |
| 25 | |
| 26 | var commonTemplatescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/commonTemplate. = templatescip-go gomod github.com/golang/go/src go1.24.0 `text/template`/.Mustscip-go gomod github.com/golang/go/src go1.24.0 `text/template`/Must().(templatescip-go gomod github.com/golang/go/src go1.24.0 `text/template`/.Newscip-go gomod github.com/golang/go/src go1.24.0 `text/template`/New().("common").Parsescip-go gomod github.com/golang/go/src go1.24.0 `text/template`/Template#Parse().(commonRawscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/commonRaw.)) |
| 27 | |
| 28 | type templateNamescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName# string |
| 29 | |
| 30 | func (n templateNamescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#) maybeExportscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#maybeExport().(str string) string { |
| 31 | if tokenscip-go gomod github.com/golang/go/src go1.24.0 `go/token`/.IsExportedscip-go gomod github.com/golang/go/src go1.24.0 `go/token`/IsExported().(string(n)) { |
| 32 | return toUpperFirstscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/toUpperFirst().(str) |
| 33 | } |
| 34 | |
| 35 | return str |
| 36 | } |
| 37 | |
| 38 | func (n templateNamescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#) Bytesscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#Bytes().() string { |
| 39 | return "_" + toUpperFirstscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/toUpperFirst().(string(n)) + "Bytes" |
| 40 | } |
| 41 | |
| 42 | func (n templateNamescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#) Specsscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#Specs().() string { |
| 43 | return string(n) + "Specs" |
| 44 | } |
| 45 | |
| 46 | func (n templateNamescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#) ProgramSpecsscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#ProgramSpecs().() string { |
| 47 | return string(n) + "ProgramSpecs" |
| 48 | } |
| 49 | |
| 50 | func (n templateNamescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#) MapSpecsscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#MapSpecs().() string { |
| 51 | return string(n) + "MapSpecs" |
| 52 | } |
| 53 | |
| 54 | func (n templateNamescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#) VariableSpecsscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#VariableSpecs().() string { |
| 55 | return string(n) + "VariableSpecs" |
| 56 | } |
| 57 | |
| 58 | func (n templateNamescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#) Loadscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#Load().() string { |
| 59 | return n.maybeExportscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#maybeExport().("load" + toUpperFirstscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/toUpperFirst().(string(n))) |
| 60 | } |
| 61 | |
| 62 | func (n templateNamescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#) LoadObjectsscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#LoadObjects().() string { |
| 63 | return n.maybeExportscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#maybeExport().("load" + toUpperFirstscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/toUpperFirst().(string(n)) + "Objects") |
| 64 | } |
| 65 | |
| 66 | func (n templateNamescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#) Objectsscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#Objects().() string { |
| 67 | return string(n) + "Objects" |
| 68 | } |
| 69 | |
| 70 | func (n templateNamescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#) Mapsscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#Maps().() string { |
| 71 | return string(n) + "Maps" |
| 72 | } |
| 73 | |
| 74 | func (n templateNamescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#) Variablesscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#Variables().() string { |
| 75 | return string(n) + "Variables" |
| 76 | } |
| 77 | |
| 78 | func (n templateNamescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#) Programsscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#Programs().() string { |
| 79 | return string(n) + "Programs" |
| 80 | } |
| 81 | |
| 82 | func (n templateNamescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#) CloseHelperscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#CloseHelper().() string { |
| 83 | return "_" + toUpperFirstscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/toUpperFirst().(string(n)) + "Close" |
| 84 | } |
| 85 | |
| 86 | type GenerateArgsscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs# struct { |
| 87 | // Package of the resulting file. |
| 88 | Packagescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Package. string |
| 89 | // The prefix of all names declared at the top-level. |
| 90 | Stemscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Stem. string |
| 91 | // Build Constraints included in the resulting file. |
| 92 | Constraintsscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Constraints. constraintscip-go gomod github.com/golang/go/src go1.24.0 `go/build/constraint`/.Exprscip-go gomod github.com/golang/go/src go1.24.0 `go/build/constraint`/Expr# |
| 93 | // Maps to be emitted. |
| 94 | Mapsscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Maps. []string |
| 95 | // Variables to be emitted. |
| 96 | Variablesscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Variables. []string |
| 97 | // Programs to be emitted. |
| 98 | Programsscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Programs. []string |
| 99 | // Types to be emitted. |
| 100 | Typesscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Types. []btfscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/btf`/.Typescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/btf`/Type# |
| 101 | // Filename of the object to embed. |
| 102 | ObjectFilescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#ObjectFile. string |
| 103 | // Output to write template to. |
| 104 | Outputscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Output. ioscip-go gomod github.com/golang/go/src go1.24.0 io/.Writerscip-go gomod github.com/golang/go/src go1.24.0 io/Writer# |
| 105 | // Function which transforms the input into a valid go identifier. Uses the default behaviour if nil |
| 106 | Identifierscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Identifier. func(string) string |
| 107 | } |
| 108 | |
| 109 | // Generate bindings for a BPF ELF file. |
| 110 | func Generatescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/Generate().(args GenerateArgsscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#) error { |
| 111 | if args.Identifierscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Identifier. == nil { |
| 112 | args.Identifierscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Identifier. = internalscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/internal`/.Identifierscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/internal`/Identifier(). |
| 113 | } |
| 114 | if !tokenscip-go gomod github.com/golang/go/src go1.24.0 `go/token`/.IsIdentifierscip-go gomod github.com/golang/go/src go1.24.0 `go/token`/IsIdentifier().(args.Stemscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Stem.) { |
| 115 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("%q is not a valid identifier", args.Stemscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Stem.) |
| 116 | } |
| 117 | |
| 118 | if stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.ContainsAnyscip-go gomod github.com/golang/go/src go1.24.0 strings/ContainsAny().(args.ObjectFilescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#ObjectFile., "\n") { |
| 119 | // Prevent injecting newlines into the template. |
| 120 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("file %q contains an invalid character", args.ObjectFilescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#ObjectFile.) |
| 121 | } |
| 122 | |
| 123 | for _, typ := range args.Typesscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Types. { |
| 124 | if _, ok := btfscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/btf`/.Asscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/btf`/As().[*btfscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/btf`/.Datasecscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/btf`/Datasec#](typ); ok { |
| 125 | // Avoid emitting .rodata, .bss, etc. for now. We might want to |
| 126 | // name these types differently, etc. |
| 127 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("can't output btf.Datasec: %s", typ) |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | maps := make(map[string]string) |
| 132 | for _, name := range args.Mapsscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Maps. { |
| 133 | maps[name] = args.Identifierscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Identifier.(name) |
| 134 | } |
| 135 | |
| 136 | variables := make(map[string]string) |
| 137 | for _, name := range args.Variablesscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Variables. { |
| 138 | variables[name] = args.Identifierscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Identifier.(name) |
| 139 | } |
| 140 | |
| 141 | programs := make(map[string]string) |
| 142 | for _, name := range args.Programsscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Programs. { |
| 143 | programs[name] = args.Identifierscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Identifier.(name) |
| 144 | } |
| 145 | |
| 146 | typeNames := make(map[btfscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/btf`/.Typescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/btf`/Type#]string) |
| 147 | for _, typ := range args.Typesscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Types. { |
| 148 | // NB: This also deduplicates types. |
| 149 | typeNames[typ] = args.Stemscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Stem. + args.Identifierscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Identifier.(typ.TypeNamescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/btf`/Type#TypeName.()) |
| 150 | } |
| 151 | |
| 152 | // Ensure we don't have conflicting names and generate a sorted list of |
| 153 | // named types so that the output is stable. |
| 154 | types, err := sortTypesscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/sortTypes().(typeNames) |
| 155 | if err != nil { |
| 156 | return err |
| 157 | } |
| 158 | |
| 159 | gf := &btfscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/btf`/.GoFormatterscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/btf`/GoFormatter#{ |
| 160 | Namesscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/btf`/GoFormatter#Names.: typeNames, |
| 161 | Identifierscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/btf`/GoFormatter#Identifier.: args.Identifierscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Identifier., |
| 162 | } |
| 163 | |
| 164 | var typeDecls []string |
| 165 | needsStructsPkg := false |
| 166 | for _, typ := range types { |
| 167 | name := typeNames[typ] |
| 168 | decl, err := gf.TypeDeclarationscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/btf`/GoFormatter#TypeDeclaration().(name, typ) |
| 169 | if err != nil { |
| 170 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("generating %s: %w", name, err) |
| 171 | } |
| 172 | _, ok := btfscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/btf`/.Asscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/btf`/As().[*btfscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/btf`/.Structscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/btf`/Struct#](typ) |
| 173 | needsStructsPkg = needsStructsPkg || ok |
| 174 | typeDecls = append(typeDecls, decl) |
| 175 | } |
| 176 | |
| 177 | ctx := struct { |
| 178 | Module string |
| 179 | Package string |
| 180 | Constraints constraintscip-go gomod github.com/golang/go/src go1.24.0 `go/build/constraint`/.Exprscip-go gomod github.com/golang/go/src go1.24.0 `go/build/constraint`/Expr# |
| 181 | Name templateNamescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName# |
| 182 | Maps map[string]string |
| 183 | Variables map[string]string |
| 184 | Programs map[string]string |
| 185 | TypeDeclarations []string |
| 186 | File string |
| 187 | NeedsStructsPkg bool |
| 188 | }{ |
| 189 | b2gIntscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/internal`/.CurrentModulescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/internal`/CurrentModule., |
| 190 | args.Packagescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Package., |
| 191 | args.Constraintsscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Constraints., |
| 192 | templateNamescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/templateName#(args.Stemscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Stem.), |
| 193 | maps, |
| 194 | variables, |
| 195 | programs, |
| 196 | typeDecls, |
| 197 | args.ObjectFilescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#ObjectFile., |
| 198 | needsStructsPkg, |
| 199 | } |
| 200 | |
| 201 | var buf bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer# |
| 202 | if err := commonTemplatescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/commonTemplate..Executescip-go gomod github.com/golang/go/src go1.24.0 `text/template`/Template#Execute().(&buf, &ctx); err != nil { |
| 203 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("can't generate types: %s", err) |
| 204 | } |
| 205 | |
| 206 | return internalscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/internal`/.WriteFormattedscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/internal`/WriteFormatted().(buf.Bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#Bytes().(), args.Outputscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/GenerateArgs#Output.) |
| 207 | } |
| 208 | |
| 209 | // sortTypes returns a list of types sorted by their (generated) Go type name. |
| 210 | // |
| 211 | // Duplicate Go type names are rejected. |
| 212 | func sortTypesscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/sortTypes().(typeNames map[btfscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/btf`/.Typescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/btf`/Type#]string) ([]btfscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/btf`/.Typescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/btf`/Type#, error) { |
| 213 | var types []btfscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/btf`/.Typescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/btf`/Type# |
| 214 | var names []string |
| 215 | for typ, name := range typeNames { |
| 216 | i := sortscip-go gomod github.com/golang/go/src go1.24.0 sort/.SearchStringsscip-go gomod github.com/golang/go/src go1.24.0 sort/SearchStrings().(names, name) |
| 217 | if i >= len(names) { |
| 218 | types = append(types, typ) |
| 219 | names = append(names, name) |
| 220 | continue |
| 221 | } |
| 222 | |
| 223 | if names[i] == name { |
| 224 | return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("type name %q is used multiple times", name) |
| 225 | } |
| 226 | |
| 227 | types = append(types[:i], append([]btfscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/btf`/.Typescip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/btf`/Type#{typ}, types[i:]...)...) |
| 228 | names = append(names[:i], append([]string{name}, names[i:]...)...) |
| 229 | } |
| 230 | |
| 231 | return types, nil |
| 232 | } |
| 233 | |
| 234 | func toUpperFirstscip-go gomod github.com/cilium/ebpf . `github.com/cilium/ebpf/cmd/bpf2go/gen`/toUpperFirst().(str string) string { |
| 235 | first, n := utf8scip-go gomod github.com/golang/go/src go1.24.0 `unicode/utf8`/.DecodeRuneInStringscip-go gomod github.com/golang/go/src go1.24.0 `unicode/utf8`/DecodeRuneInString().(str) |
| 236 | return string(unicodescip-go gomod github.com/golang/go/src go1.24.0 unicode/.ToUpperscip-go gomod github.com/golang/go/src go1.24.0 unicode/ToUpper().(first)) + str[n:] |
| 237 | } |