[RFC/PATCH 2/3] btf_encoder: Put function generation code to generate_func

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We will use generate_func from another place in following change.

Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
 btf_encoder.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/btf_encoder.c b/btf_encoder.c
index d531651b1e9e..efc4f48dbc5a 100644
--- a/btf_encoder.c
+++ b/btf_encoder.c
@@ -351,6 +351,23 @@ static struct btf_elf *btfe;
 static uint32_t array_index_id;
 static bool has_index_type;
 
+static int generate_func(struct btf_elf *btfe, struct cu *cu,
+			 struct function *fn, uint32_t type_id_off)
+{
+	int btf_fnproto_id, btf_fn_id, err = 0;
+	const char *name;
+
+	btf_fnproto_id = btf_elf__add_func_proto(btfe, cu, &fn->proto, type_id_off);
+	name = dwarves__active_loader->strings__ptr(cu, fn->name);
+	btf_fn_id = btf_elf__add_ref_type(btfe, BTF_KIND_FUNC, btf_fnproto_id, name, false);
+	if (btf_fnproto_id < 0 || btf_fn_id < 0) {
+		err = -1;
+		printf("error: failed to encode function '%s'\n", function__name(fn, cu));
+	}
+
+	return err;
+}
+
 int btf_encoder__encode()
 {
 	int err;
@@ -608,9 +625,6 @@ int cu__encode_btf(struct cu *cu, int verbose, bool force,
 	}
 
 	cu__for_each_function(cu, core_id, fn) {
-		int btf_fnproto_id, btf_fn_id;
-		const char *name;
-
 		/*
 		 * The functions_cnt != 0 means we parsed all necessary
 		 * kernel symbols and we are using ftrace location filter
@@ -634,14 +648,8 @@ int cu__encode_btf(struct cu *cu, int verbose, bool force,
 				continue;
 		}
 
-		btf_fnproto_id = btf_elf__add_func_proto(btfe, cu, &fn->proto, type_id_off);
-		name = dwarves__active_loader->strings__ptr(cu, fn->name);
-		btf_fn_id = btf_elf__add_ref_type(btfe, BTF_KIND_FUNC, btf_fnproto_id, name, false);
-		if (btf_fnproto_id < 0 || btf_fn_id < 0) {
-			err = -1;
-			printf("error: failed to encode function '%s'\n", function__name(fn, cu));
+		if (generate_func(btfe, cu, fn, type_id_off))
 			goto out;
-		}
 	}
 
 	if (skip_encoding_vars)
-- 
2.26.2




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux