[PATCH dwarves 2/6] btf_encoder: split btf_encoder__collect_symbols()

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

 



btf_encoder__collect_symbols() collects information on percpu
variables and functions from ELF symbols. Factor out these steps into
separate functions.

This makes sense for subsequent changes making functions table not
btf_encoder-specific. Also percpu vars will not be collected after
global variables support is merged [1].

[1]: https://lore.kernel.org/dwarves/df3c21d4-9f42-4681-b7bb-78134f430f1c@xxxxxxxxxx/T/#mf945ef7ecefe3915930c78358c03918ba28f0a05

Signed-off-by: Ihor Solodrai <ihor.solodrai@xxxxx>
---
 btf_encoder.c | 52 +++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 42 insertions(+), 10 deletions(-)

diff --git a/btf_encoder.c b/btf_encoder.c
index 51cd7bf..6e7d2e7 100644
--- a/btf_encoder.c
+++ b/btf_encoder.c
@@ -2178,7 +2178,7 @@ static int btf_encoder__collect_percpu_var(struct btf_encoder *encoder, GElf_Sym
 	return 0;
 }
 
-static int btf_encoder__collect_symbols(struct btf_encoder *encoder, bool collect_percpu_vars)
+static int btf_encoder__collect_percpu_vars(struct btf_encoder *encoder)
 {
 	Elf32_Word sym_sec_idx;
 	uint32_t core_id;
@@ -2189,22 +2189,37 @@ static int btf_encoder__collect_symbols(struct btf_encoder *encoder, bool collec
 
 	/* search within symtab for percpu variables */
 	elf_symtab__for_each_symbol_index(encoder->symtab, core_id, sym, sym_sec_idx) {
-		if (collect_percpu_vars && btf_encoder__collect_percpu_var(encoder, &sym, sym_sec_idx))
-			return -1;
-		if (btf_encoder__collect_function(encoder, &sym))
+		if (btf_encoder__collect_percpu_var(encoder, &sym, sym_sec_idx))
 			return -1;
 	}
 
-	if (collect_percpu_vars) {
-		if (encoder->percpu.var_cnt)
-			qsort(encoder->percpu.vars, encoder->percpu.var_cnt, sizeof(encoder->percpu.vars[0]), percpu_var_cmp);
+	if (encoder->percpu.var_cnt)
+		qsort(encoder->percpu.vars,
+		      encoder->percpu.var_cnt,
+		      sizeof(encoder->percpu.vars[0]),
+		      percpu_var_cmp);
 
-		if (encoder->verbose)
-			printf("Found %d per-CPU variables!\n", encoder->percpu.var_cnt);
+	if (encoder->verbose)
+		printf("Found %d per-CPU variables!\n", encoder->percpu.var_cnt);
+
+	return 0;
+}
+
+static int btf_encoder__collect_functions(struct btf_encoder *encoder)
+{
+	Elf32_Word sym_sec_idx;
+	uint32_t core_id;
+	GElf_Sym sym;
+
+	elf_symtab__for_each_symbol_index(encoder->symtab, core_id, sym, sym_sec_idx) {;
+		if (btf_encoder__collect_function(encoder, &sym))
+			return -1;
 	}
 
 	if (encoder->functions.cnt) {
-		qsort(encoder->functions.entries, encoder->functions.cnt, sizeof(encoder->functions.entries[0]),
+		qsort(encoder->functions.entries,
+		      encoder->functions.cnt,
+		      sizeof(encoder->functions.entries[0]),
 		      functions_cmp);
 		if (encoder->verbose)
 			printf("Found %d functions!\n", encoder->functions.cnt);
@@ -2213,6 +2228,23 @@ static int btf_encoder__collect_symbols(struct btf_encoder *encoder, bool collec
 	return 0;
 }
 
+static int btf_encoder__collect_symbols(struct btf_encoder *encoder, bool collect_percpu_vars)
+{
+	int err;
+
+	err = btf_encoder__collect_functions(encoder);
+	if (err)
+		return err;
+
+	if (collect_percpu_vars) {
+		err = btf_encoder__collect_percpu_vars(encoder);
+		if (err)
+			return err;
+	}
+
+	return 0;
+}
+
 static bool ftype__has_arg_names(const struct ftype *ftype)
 {
 	struct parameter *param;
-- 
2.34.1







[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux