Skip to content

Commit 644f800

Browse files
committed
btf/cmd/genbtftypes: (cilium#1218) a generator that generates btf_types.go structs.
This is guaranteed to match the kernel struct defenitions.
1 parent 87531ae commit 644f800

File tree

5 files changed

+324
-64
lines changed

5 files changed

+324
-64
lines changed

btf/btf_gen_types.go

+47
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

btf/btf_types.go

-64
Original file line numberDiff line numberDiff line change
@@ -131,28 +131,6 @@ func parseBTFHeader(r io.Reader, bo binary.ByteOrder) (*btfHeader, error) {
131131

132132
var btfTypeLen = binary.Size(btfType{})
133133

134-
// btfType is equivalent to struct btf_type in Documentation/bpf/btf.rst.
135-
type btfType struct {
136-
NameOff uint32
137-
/* "info" bits arrangement
138-
* bits 0-15: vlen (e.g. # of struct's members), linkage
139-
* bits 16-23: unused
140-
* bits 24-28: kind (e.g. int, ptr, array...etc)
141-
* bits 29-30: unused
142-
* bit 31: kind_flag, currently used by
143-
* struct, union and fwd
144-
*/
145-
Info uint32
146-
/* "size" is used by INT, ENUM, STRUCT and UNION.
147-
* "size" tells the size of the type it is describing.
148-
*
149-
* "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT,
150-
* FUNC and FUNC_PROTO.
151-
* "type" is a type_id referring to another type.
152-
*/
153-
SizeType uint32
154-
}
155-
156134
var btfTypeSize = int(unsafe.Sizeof(btfType{}))
157135

158136
func unmarshalBtfType(bt *btfType, b []byte, bo binary.ByteOrder) (int, error) {
@@ -348,12 +326,6 @@ func (bi *btfInt) SetBits(bits byte) {
348326
bi.Raw = writeBits(bi.Raw, btfIntBitsLen, btfIntBitsShift, uint32(bits))
349327
}
350328

351-
type btfArray struct {
352-
Type TypeID
353-
IndexType TypeID
354-
Nelems uint32
355-
}
356-
357329
var btfArrayLen = int(unsafe.Sizeof(btfArray{}))
358330

359331
func unmarshalBtfArray(ba *btfArray, b []byte, bo binary.ByteOrder) (int, error) {
@@ -367,12 +339,6 @@ func unmarshalBtfArray(ba *btfArray, b []byte, bo binary.ByteOrder) (int, error)
367339
return btfArrayLen, nil
368340
}
369341

370-
type btfMember struct {
371-
NameOff uint32
372-
Type TypeID
373-
Offset uint32
374-
}
375-
376342
var btfMemberLen = int(unsafe.Sizeof(btfMember{}))
377343

378344
func unmarshalBtfMembers(members []btfMember, b []byte, bo binary.ByteOrder) (int, error) {
@@ -392,12 +358,6 @@ func unmarshalBtfMembers(members []btfMember, b []byte, bo binary.ByteOrder) (in
392358
return off, nil
393359
}
394360

395-
type btfVarSecinfo struct {
396-
Type TypeID
397-
Offset uint32
398-
Size uint32
399-
}
400-
401361
var btfVarSecinfoLen = int(unsafe.Sizeof(btfVarSecinfo{}))
402362

403363
func unmarshalBtfVarSecInfos(secinfos []btfVarSecinfo, b []byte, bo binary.ByteOrder) (int, error) {
@@ -417,10 +377,6 @@ func unmarshalBtfVarSecInfos(secinfos []btfVarSecinfo, b []byte, bo binary.ByteO
417377
return off, nil
418378
}
419379

420-
type btfVariable struct {
421-
Linkage uint32
422-
}
423-
424380
var btfVariableLen = int(unsafe.Sizeof(btfVariable{}))
425381

426382
func unmarshalBtfVariable(bv *btfVariable, b []byte, bo binary.ByteOrder) (int, error) {
@@ -432,11 +388,6 @@ func unmarshalBtfVariable(bv *btfVariable, b []byte, bo binary.ByteOrder) (int,
432388
return btfVariableLen, nil
433389
}
434390

435-
type btfEnum struct {
436-
NameOff uint32
437-
Val uint32
438-
}
439-
440391
var btfEnumLen = int(unsafe.Sizeof(btfEnum{}))
441392

442393
func unmarshalBtfEnums(enums []btfEnum, b []byte, bo binary.ByteOrder) (int, error) {
@@ -455,12 +406,6 @@ func unmarshalBtfEnums(enums []btfEnum, b []byte, bo binary.ByteOrder) (int, err
455406
return off, nil
456407
}
457408

458-
type btfEnum64 struct {
459-
NameOff uint32
460-
ValLo32 uint32
461-
ValHi32 uint32
462-
}
463-
464409
var btfEnum64Len = int(unsafe.Sizeof(btfEnum64{}))
465410

466411
func unmarshalBtfEnums64(enums []btfEnum64, b []byte, bo binary.ByteOrder) (int, error) {
@@ -480,11 +425,6 @@ func unmarshalBtfEnums64(enums []btfEnum64, b []byte, bo binary.ByteOrder) (int,
480425
return off, nil
481426
}
482427

483-
type btfParam struct {
484-
NameOff uint32
485-
Type TypeID
486-
}
487-
488428
var btfParamLen = int(unsafe.Sizeof(btfParam{}))
489429

490430
func unmarshalBtfParams(params []btfParam, b []byte, bo binary.ByteOrder) (int, error) {
@@ -503,10 +443,6 @@ func unmarshalBtfParams(params []btfParam, b []byte, bo binary.ByteOrder) (int,
503443
return off, nil
504444
}
505445

506-
type btfDeclTag struct {
507-
ComponentIdx uint32
508-
}
509-
510446
var btfDeclTagLen = int(unsafe.Sizeof(btfDeclTag{}))
511447

512448
func unmarshalBtfDeclTag(bdt *btfDeclTag, b []byte, bo binary.ByteOrder) (int, error) {

btf/cmd/genbtftypes/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
genbtftypes

0 commit comments

Comments
 (0)