summaryrefslogtreecommitdiff
path: root/bpf/bpf.go
diff options
context:
space:
mode:
Diffstat (limited to 'bpf/bpf.go')
-rw-r--r--bpf/bpf.go79
1 files changed, 75 insertions, 4 deletions
diff --git a/bpf/bpf.go b/bpf/bpf.go
index 187b4db61..14b2d84c5 100644
--- a/bpf/bpf.go
+++ b/bpf/bpf.go
@@ -20,9 +20,9 @@ import (
"strings"
"android/soong/android"
- _ "android/soong/cc/config"
"github.com/google/blueprint"
+ "github.com/google/blueprint/proptools"
)
func init() {
@@ -41,6 +41,14 @@ var (
CommandDeps: []string{"$ccCmd"},
},
"ccCmd", "cFlags")
+
+ stripRule = pctx.AndroidStaticRule("stripRule",
+ blueprint.RuleParams{
+ Command: `$stripCmd --strip-unneeded --remove-section=.rel.BTF ` +
+ `--remove-section=.rel.BTF.ext --remove-section=.BTF.ext $in -o $out`,
+ CommandDeps: []string{"$stripCmd"},
+ },
+ "stripCmd")
)
func registerBpfBuildComponents(ctx android.RegistrationContext) {
@@ -64,6 +72,11 @@ type BpfProperties struct {
Cflags []string
Include_dirs []string
Sub_dir string
+ // If set to true, generate BTF debug info for maps & programs
+ Btf *bool
+ Vendor *bool
+
+ VendorInternal bool `blueprint:"mutated"`
}
type bpf struct {
@@ -74,6 +87,41 @@ type bpf struct {
objs android.Paths
}
+var _ android.ImageInterface = (*bpf)(nil)
+
+func (bpf *bpf) ImageMutatorBegin(ctx android.BaseModuleContext) {}
+
+func (bpf *bpf) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
+ return !proptools.Bool(bpf.properties.Vendor)
+}
+
+func (bpf *bpf) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
+ return false
+}
+
+func (bpf *bpf) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
+ return false
+}
+
+func (bpf *bpf) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
+ return false
+}
+
+func (bpf *bpf) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
+ return false
+}
+
+func (bpf *bpf) ExtraImageVariations(ctx android.BaseModuleContext) []string {
+ if proptools.Bool(bpf.properties.Vendor) {
+ return []string{"vendor"}
+ }
+ return nil
+}
+
+func (bpf *bpf) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
+ bpf.properties.VendorInternal = variation == "vendor"
+}
+
func (bpf *bpf) GenerateAndroidBuildActions(ctx android.ModuleContext) {
cflags := []string{
"-nostdlibinc",
@@ -99,10 +147,14 @@ func (bpf *bpf) GenerateAndroidBuildActions(ctx android.ModuleContext) {
cflags = append(cflags, bpf.properties.Cflags...)
+ if proptools.Bool(bpf.properties.Btf) {
+ cflags = append(cflags, "-g")
+ }
+
srcs := android.PathsForModuleSrc(ctx, bpf.properties.Srcs)
for _, src := range srcs {
- obj := android.ObjPathWithExt(ctx, "", src, "o")
+ obj := android.ObjPathWithExt(ctx, "unstripped", src, "o")
ctx.Build(pctx, android.BuildParams{
Rule: ccRule,
@@ -114,7 +166,21 @@ func (bpf *bpf) GenerateAndroidBuildActions(ctx android.ModuleContext) {
},
})
- bpf.objs = append(bpf.objs, obj.WithoutRel())
+ if proptools.Bool(bpf.properties.Btf) {
+ objStripped := android.ObjPathWithExt(ctx, "", src, "o")
+ ctx.Build(pctx, android.BuildParams{
+ Rule: stripRule,
+ Input: obj,
+ Output: objStripped,
+ Args: map[string]string{
+ "stripCmd": "${config.ClangBin}/llvm-strip",
+ },
+ })
+ bpf.objs = append(bpf.objs, objStripped.WithoutRel())
+ } else {
+ bpf.objs = append(bpf.objs, obj.WithoutRel())
+ }
+
}
}
@@ -125,7 +191,12 @@ func (bpf *bpf) AndroidMk() android.AndroidMkData {
fmt.Fprintln(w)
fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
fmt.Fprintln(w)
- localModulePath := "LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/bpf"
+ var localModulePath string
+ if bpf.properties.VendorInternal {
+ localModulePath = "LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_ETC)/bpf"
+ } else {
+ localModulePath = "LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/bpf"
+ }
if len(bpf.properties.Sub_dir) > 0 {
localModulePath += "/" + bpf.properties.Sub_dir
}