@@ -90,7 +90,7 @@ func TestAnyTypesByName(t *testing.T) {
9090 testutils .Files (t , testutils .Glob (t , "testdata/relocs-*.elf" ), func (t * testing.T , file string ) {
9191 spec := parseELFBTF (t , file )
9292
93- types , err := spec .AnyTypesByName ("ambiguous" )
93+ types , err := spec .AnyTypesByName ("ambiguous" , true )
9494 if err != nil {
9595 t .Fatal (err )
9696 }
@@ -99,7 +99,7 @@ func TestAnyTypesByName(t *testing.T) {
9999 t .Fatalf ("expected to receive exactly 1 types from querying ambiguous type, got: %v" , types )
100100 }
101101
102- types , err = spec .AnyTypesByName ("ambiguous___flavour" )
102+ types , err = spec .AnyTypesByName ("ambiguous___flavour" , true )
103103 if err != nil {
104104 t .Fatal (err )
105105 }
@@ -115,15 +115,15 @@ func TestTypeByNameAmbiguous(t *testing.T) {
115115 spec := parseELFBTF (t , file )
116116
117117 var typ * Struct
118- if err := spec .TypeByName ("ambiguous" , & typ ); err != nil {
118+ if err := spec .TypeByName ("ambiguous" , true , & typ ); err != nil {
119119 t .Fatal (err )
120120 }
121121
122122 if name := typ .TypeName (); name != "ambiguous" {
123123 t .Fatal ("expected type name 'ambiguous', got:" , name )
124124 }
125125
126- if err := spec .TypeByName ("ambiguous___flavour" , & typ ); err != nil {
126+ if err := spec .TypeByName ("ambiguous___flavour" , true , & typ ); err != nil {
127127 t .Fatal (err )
128128 }
129129
@@ -150,18 +150,18 @@ func TestTypeByName(t *testing.T) {
150150 } {
151151 t .Run (fmt .Sprintf ("%T" , typ ), func (t * testing.T ) {
152152 // spec.TypeByName MUST fail if typ is a nil btf.Type.
153- if err := spec .TypeByName ("iphdr" , typ ); err == nil {
153+ if err := spec .TypeByName ("iphdr" , true , typ ); err == nil {
154154 t .Fatalf ("TypeByName does not fail with type %T" , typ )
155155 }
156156 })
157157 }
158158
159159 // spec.TypeByName MUST return the same address for multiple calls with the same type name.
160160 var iphdr1 , iphdr2 * Struct
161- if err := spec .TypeByName ("iphdr" , & iphdr1 ); err != nil {
161+ if err := spec .TypeByName ("iphdr" , true , & iphdr1 ); err != nil {
162162 t .Fatal (err )
163163 }
164- if err := spec .TypeByName ("iphdr" , & iphdr2 ); err != nil {
164+ if err := spec .TypeByName ("iphdr" , true , & iphdr2 ); err != nil {
165165 t .Fatal (err )
166166 }
167167
@@ -171,12 +171,12 @@ func TestTypeByName(t *testing.T) {
171171
172172 // It's valid to pass a *Type to TypeByName.
173173 typ := Type (iphdr2 )
174- if err := spec .TypeByName ("iphdr" , & typ ); err != nil {
174+ if err := spec .TypeByName ("iphdr" , true , & typ ); err != nil {
175175 t .Fatal ("Can't look up using *Type:" , err )
176176 }
177177
178178 var nt Type
179- qt .Assert (t , qt .IsNotNil (spec .TypeByName ("a" , & nt )))
179+ qt .Assert (t , qt .IsNotNil (spec .TypeByName ("a" , true , & nt )))
180180
181181 // Excerpt from linux/ip.h, https://elixir.bootlin.com/linux/latest/A/ident/iphdr
182182 //
@@ -278,17 +278,17 @@ func TestLoadSpecFromElf(t *testing.T) {
278278 }
279279
280280 var bpfMapDef * Struct
281- if err := spec .TypeByName ("bpf_map_def" , & bpfMapDef ); err != nil {
281+ if err := spec .TypeByName ("bpf_map_def" , true , & bpfMapDef ); err != nil {
282282 t .Error ("Can't find bpf_map_def:" , err )
283283 }
284284
285285 var tmp * Void
286- if err := spec .TypeByName ("totally_bogus_type" , & tmp ); ! errors .Is (err , ErrNotFound ) {
286+ if err := spec .TypeByName ("totally_bogus_type" , true , & tmp ); ! errors .Is (err , ErrNotFound ) {
287287 t .Error ("TypeByName doesn't return ErrNotFound:" , err )
288288 }
289289
290290 var fn * Func
291- if err := spec .TypeByName ("global_fn" , & fn ); err != nil {
291+ if err := spec .TypeByName ("global_fn" , true , & fn ); err != nil {
292292 t .Error ("Can't find global_fn():" , err )
293293 } else {
294294 if fn .Linkage != GlobalFunc {
@@ -297,7 +297,7 @@ func TestLoadSpecFromElf(t *testing.T) {
297297 }
298298
299299 var v * Var
300- if err := spec .TypeByName ("key3" , & v ); err != nil {
300+ if err := spec .TypeByName ("key3" , true , & v ); err != nil {
301301 t .Error ("Can't find key3:" , err )
302302 } else {
303303 if v .Linkage != GlobalVar {
@@ -383,7 +383,7 @@ func ExampleSpec_TypeByName() {
383383 // Declare a variable of the desired type
384384 var foo * Struct
385385
386- if err := spec .TypeByName ("foo" , & foo ); err != nil {
386+ if err := spec .TypeByName ("foo" , true , & foo ); err != nil {
387387 // There is no struct with name foo, or there
388388 // are multiple possibilities.
389389 }
@@ -431,7 +431,7 @@ func TestLoadSplitSpec(t *testing.T) {
431431 }
432432
433433 var fnType * Func
434- qt .Assert (t , qt .IsNil (splitSpec .TypeByName ("bpf_testmod_init" , & fnType )))
434+ qt .Assert (t , qt .IsNil (splitSpec .TypeByName ("bpf_testmod_init" , true , & fnType )))
435435 typeID , err := splitSpec .TypeID (fnType )
436436 qt .Assert (t , qt .IsNil (err ))
437437
@@ -441,11 +441,11 @@ func TestLoadSplitSpec(t *testing.T) {
441441
442442 fnProto := fnType .Type .(* FuncProto )
443443 // 'int' is defined in the base BTF...
444- intType , err := spec .AnyTypeByName ("int" )
444+ intType , err := spec .AnyTypeByName ("int" , true )
445445 qt .Assert (t , qt .IsNil (err ))
446446
447447 // ... but not in the split BTF
448- _ , err = splitSpec .AnyTypeByName ("int" )
448+ _ , err = splitSpec .AnyTypeByName ("int" , true )
449449 qt .Assert (t , qt .ErrorIs (err , ErrNotFound ))
450450
451451 qt .Assert (t , qt .Equals (fnProto .Return , intType ),
@@ -466,13 +466,13 @@ func TestLoadSplitSpec(t *testing.T) {
466466 splitSpecCopy := splitSpec .Copy ()
467467
468468 var fnCopyType * Func
469- qt .Assert (t , qt .IsNil (splitSpecCopy .TypeByName ("bpf_testmod_init" , & fnCopyType )))
469+ qt .Assert (t , qt .IsNil (splitSpecCopy .TypeByName ("bpf_testmod_init" , true , & fnCopyType )))
470470 qt .Assert (t , testutils .IsDeepCopy (fnCopyType , fnType ))
471471
472472 // Pull out a second type which refers to "int" in the base, but which hasn't
473473 // been inflated yet. This forces inflating int from the base.
474474 var str * Struct
475- qt .Assert (t , qt .IsNil (splitSpecCopy .TypeByName ("bpf_testmod_struct_arg_1" , & str )))
475+ qt .Assert (t , qt .IsNil (splitSpecCopy .TypeByName ("bpf_testmod_struct_arg_1" , true , & str )))
476476
477477 // Ensure that the int types are indeed the same.
478478 qt .Assert (t , qt .Equals (str .Members [0 ].Type , fnCopyType .Type .(* FuncProto ).Return ))
@@ -525,7 +525,7 @@ func TestSpecConcurrentAccess(t *testing.T) {
525525 }
526526
527527 if n % 2 == 0 {
528- _ , _ = spec .AnyTypeByName ("gov_update_cpu_data" )
528+ _ , _ = spec .AnyTypeByName ("gov_update_cpu_data" , true )
529529 } else {
530530 _ = spec .Copy ()
531531 }
@@ -619,7 +619,7 @@ func BenchmarkInspektorGadget(b *testing.B) {
619619
620620 var s * Struct
621621 for _ , name := range types {
622- if err := spec .TypeByName (name , & s ); err != nil {
622+ if err := spec .TypeByName (name , true , & s ); err != nil {
623623 b .Fatal (name , err )
624624 }
625625 }
0 commit comments