Skip to content

Commit b3a6126

Browse files
committed
btf/cmd/genbtftypes: a generator that generates btf_types.go structs.
Signed-off-by: OmarTariq612 <[email protected]>
1 parent bfbacc1 commit b3a6126

File tree

5 files changed

+341
-76
lines changed

5 files changed

+341
-76
lines changed

Diff for: btf/btf_gen_types.go

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

Diff for: btf/btf_types.go

-76
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,6 @@ const (
7474

7575
var btfHeaderLen = binary.Size(&btfHeader{})
7676

77-
type btfHeader struct {
78-
Magic uint16
79-
Version uint8
80-
Flags uint8
81-
HdrLen uint32
82-
83-
TypeOff uint32
84-
TypeLen uint32
85-
StringOff uint32
86-
StringLen uint32
87-
}
88-
8977
// typeStart returns the offset from the beginning of the .BTF section
9078
// to the start of its type entries.
9179
func (h *btfHeader) typeStart() int64 {
@@ -131,28 +119,6 @@ func parseBTFHeader(r io.Reader, bo binary.ByteOrder) (*btfHeader, error) {
131119

132120
var btfTypeLen = binary.Size(btfType{})
133121

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-
156122
var btfTypeSize = int(unsafe.Sizeof(btfType{}))
157123

158124
func unmarshalBtfType(bt *btfType, b []byte, bo binary.ByteOrder) (int, error) {
@@ -348,12 +314,6 @@ func (bi *btfInt) SetBits(bits byte) {
348314
bi.Raw = writeBits(bi.Raw, btfIntBitsLen, btfIntBitsShift, uint32(bits))
349315
}
350316

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

359319
func unmarshalBtfArray(ba *btfArray, b []byte, bo binary.ByteOrder) (int, error) {
@@ -367,12 +327,6 @@ func unmarshalBtfArray(ba *btfArray, b []byte, bo binary.ByteOrder) (int, error)
367327
return btfArrayLen, nil
368328
}
369329

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

378332
func unmarshalBtfMembers(members []btfMember, b []byte, bo binary.ByteOrder) (int, error) {
@@ -392,12 +346,6 @@ func unmarshalBtfMembers(members []btfMember, b []byte, bo binary.ByteOrder) (in
392346
return off, nil
393347
}
394348

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

403351
func unmarshalBtfVarSecInfos(secinfos []btfVarSecinfo, b []byte, bo binary.ByteOrder) (int, error) {
@@ -417,10 +365,6 @@ func unmarshalBtfVarSecInfos(secinfos []btfVarSecinfo, b []byte, bo binary.ByteO
417365
return off, nil
418366
}
419367

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

426370
func unmarshalBtfVariable(bv *btfVariable, b []byte, bo binary.ByteOrder) (int, error) {
@@ -432,11 +376,6 @@ func unmarshalBtfVariable(bv *btfVariable, b []byte, bo binary.ByteOrder) (int,
432376
return btfVariableLen, nil
433377
}
434378

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

442381
func unmarshalBtfEnums(enums []btfEnum, b []byte, bo binary.ByteOrder) (int, error) {
@@ -455,12 +394,6 @@ func unmarshalBtfEnums(enums []btfEnum, b []byte, bo binary.ByteOrder) (int, err
455394
return off, nil
456395
}
457396

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

466399
func unmarshalBtfEnums64(enums []btfEnum64, b []byte, bo binary.ByteOrder) (int, error) {
@@ -480,11 +413,6 @@ func unmarshalBtfEnums64(enums []btfEnum64, b []byte, bo binary.ByteOrder) (int,
480413
return off, nil
481414
}
482415

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

490418
func unmarshalBtfParams(params []btfParam, b []byte, bo binary.ByteOrder) (int, error) {
@@ -503,10 +431,6 @@ func unmarshalBtfParams(params []btfParam, b []byte, bo binary.ByteOrder) (int,
503431
return off, nil
504432
}
505433

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

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

Diff for: btf/cmd/genbtftypes/.gitignore

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

0 commit comments

Comments
 (0)