From 3e739cf4269a6d7160b9e98d89b61f7f0bdcc1c8 Mon Sep 17 00:00:00 2001 From: Connor O'Brien Date: Wed, 17 Aug 2022 15:45:52 -0700 Subject: [PATCH] bpf: use relative source file path in debug info Enabling BTF leads clang to generate debug line info that includes the absolute path to the source file. For C++ modules the -fdebug-prefix-map flag is used to convert these to relative paths. Do the same for BPF programs when BTF is enabled. Test: build timeInState.c; strings shows only relative path to source file Bug: 238165437 Signed-off-by: Connor O'Brien Change-Id: Ie4ebc8f9a7d115baeddde5c7ac3ae710335ddf13 --- bpf/bpf.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bpf/bpf.go b/bpf/bpf.go index dbbce505e..1eceeeb53 100644 --- a/bpf/bpf.go +++ b/bpf/bpf.go @@ -18,6 +18,7 @@ import ( "fmt" "io" "path/filepath" + "runtime" "strings" "android/soong/android" @@ -30,6 +31,9 @@ import ( func init() { registerBpfBuildComponents(android.InitRegistrationContext) pctx.Import("android/soong/cc/config") + if runtime.GOOS != "darwin" { + pctx.StaticVariable("relPwd", "PWD=/proc/self/cwd") + } } var ( @@ -39,7 +43,7 @@ var ( blueprint.RuleParams{ Depfile: "${out}.d", Deps: blueprint.DepsGCC, - Command: "$ccCmd --target=bpf -c $cFlags -MD -MF ${out}.d -o $out $in", + Command: "$relPwd $ccCmd --target=bpf -c $cFlags -MD -MF ${out}.d -o $out $in", CommandDeps: []string{"$ccCmd"}, }, "ccCmd", "cFlags") @@ -163,6 +167,9 @@ func (bpf *bpf) GenerateAndroidBuildActions(ctx android.ModuleContext) { if proptools.Bool(bpf.properties.Btf) { cflags = append(cflags, "-g") + if runtime.GOOS != "darwin" { + cflags = append(cflags, "-fdebug-prefix-map=/proc/self/cwd=") + } } srcs := android.PathsForModuleSrc(ctx, bpf.properties.Srcs)